The file an agent hands back: a card in the conversation, and a viewer with page thumbnails, zoom, sheets, download and expand.
Halden-Account-Plan.pptxSlides · PPTX · 4 slides
Halden account plan
PPTX4 / 4
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { DeliverableCard, DeliverableViewer } from "./ui/uicontext/components/kit/Deliverable.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"import { deck } from "./files.ts"const Message = UiSchema.TaggedEnum({ ClickedOpen: {}, ClickedDownload: {}, RequestedClose: {}, RequestedExpand: { expanded: Schema.Boolean } })const styles = stylex.create({ frame: { display: "flex", flexDirection: "column", gap: space.lg, width: "100%" }, viewer: { height: 460, borderRadius: radius.lg, overflow: "hidden", borderWidth: 1, borderStyle: "solid", borderColor: color.line }, tall: { height: 620 }, note: { margin: 0, color: color.muted },})export const UpdatedDeck = Html.component({ name: "UpdatedDeckExample", model: Schema.Struct({ open: Schema.Boolean, expanded: Schema.Boolean, downloads: Schema.Number }), message: Message,}).make({ init: () => ({ open: true, expanded: false, downloads: 0 }), update: { ClickedOpen: ($) => $.evolve({ open: true }), ClickedDownload: ($) => $.evolve({ downloads: (n) => n + 1 }), RequestedClose: ($) => $.evolve({ open: false, expanded: false }), RequestedExpand: ($, { expanded }) => $.evolve({ expanded }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( DeliverableCard(h, { name: "Halden-Account-Plan.pptx", content: deck, open: model.open, onOpen: Message.ClickedOpen(), onDownload: Message.ClickedDownload() }), model.downloads > 0 && h.p.attrs({ role: "status", ...sx(styles.note) }).children(`Downloaded ${model.downloads === 1 ? "once" : `${model.downloads} times`}.`), model.open && h.div.attrs(sx(styles.viewer, model.expanded && styles.tall)).children(DeliverableViewer(h, { props: { id: "deck", name: "Halden-Account-Plan.pptx", title: "Halden account plan", content: deck, initialPage: 3, changed: [3], expanded: model.expanded }, onEmit: { RequestedClose: () => Message.RequestedClose(), RequestedDownload: () => Message.ClickedDownload(), RequestedExpand: ({ expanded }) => Message.RequestedExpand({ expanded }) }, })), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/deliverableUsage
import { DeliverableCard, type DeliverableContent, DeliverableViewer } from "./ui/uicontext/components/kit/Deliverable.ts"const Message = UiSchema.TaggedEnum({ ClickedOpen: { id: Schema.String }, ClickedDownload: { id: Schema.String }, ClosedViewer: {} })const content: DeliverableContent = { _tag: "Slides", slides: [{ cover: true, title: "Q3 review" }, { title: "Revenue", bullets: ["Up 18% on Q2"] }] }// the card in the conversation; the viewer where the app shows it, opened on the slide the agent addedexport const Deck = (h: Html.H<typeof Message.Type>, open: boolean) => [ DeliverableCard(h, { name: "Q3-Review.pptx", content, open, onOpen: Message.ClickedOpen({ id: "q3" }), onDownload: Message.ClickedDownload({ id: "q3" }) }), open && DeliverableViewer(h, { props: { id: "q3", name: "Q3-Review.pptx", content, initialPage: 1, changed: [1] }, onEmit: { RequestedClose: () => Message.ClosedViewer(), RequestedDownload: ({ id }) => Message.ClickedDownload({ id }), RequestedExpand: () => undefined, }, }),]Examples
A spreadsheet
Column letters, row numbers and a frozen header, the agent's best pick marked, and the sheets as tabs. Zoom scales the grid.
Vendor-Comparison
XLSX| Vendor | Per seat / mo | 40 seats / yr | SSO | Fit |
|---|---|---|---|---|
| Fernway | $14 | $6,720 | Yes | Best fit, under budget |
| Orbitly | $25 | $12,000 | Yes | Over budget |
| Quillstack | $18 | $8,640 | Yes | No audit log below Enterprise |
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { DeliverableViewer } from "./ui/uicontext/components/kit/Deliverable.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius } from "./ui/uicontext/components/tokens.stylex.ts"import { comparison } from "./files.ts"const styles = stylex.create({ frame: { width: "100%", height: 360, borderRadius: radius.lg, overflow: "hidden", borderWidth: 1, borderStyle: "solid", borderColor: color.line } })export const Comparison = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children(DeliverableViewer(h, { props: { id: "vendors", name: "Vendor-Comparison.xlsx", content: comparison, closable: false }, onEmit: { RequestedClose: () => undefined, RequestedDownload: () => undefined, RequestedExpand: () => undefined }, }))A document
Pages fit the width, as a reader does, with a page rail beside them.
Q4-Board-Update
DOCX1 / 2
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { DeliverableViewer } from "./ui/uicontext/components/kit/Deliverable.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius } from "./ui/uicontext/components/tokens.stylex.ts"import { memo } from "./files.ts"const styles = stylex.create({ frame: { width: "100%", height: 520, borderRadius: radius.lg, overflow: "hidden", borderWidth: 1, borderStyle: "solid", borderColor: color.line } })export const BoardMemo = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children(DeliverableViewer(h, { props: { id: "memo", name: "Q4-Board-Update.docx", content: memo, closable: false }, onEmit: { RequestedClose: () => undefined, RequestedDownload: () => undefined, RequestedExpand: () => undefined }, }))API reference
DeliverableViewerComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | The id agents see this viewer by; deliverable:<id> when left out |
idrequired | string | — | Identifies the file in the events it sends |
namerequired | string | — | The file's name, with its extension |
title | string | — | What people call it, as the heading: "Halden account plan"; the name without its extension by default |
contentrequired | DeliverableContent | — | — |
initialPage | number | — | The page it opens on, from 0: the slide the agent added. Read once, as it mounts. |
changed | number[] | — | Pages the agent added or changed, from 0: their thumbnails are marked New |
expanded | boolean | — | The viewer fills the app: the Expand button reads Collapse |
closable | boolean | on | Show Close; on by default |
expandable | boolean | on | Show Expand; on by default. Leave it off where the viewer already fills the screen, as on a phone. |
Events
| Event | Payload | Description |
|---|---|---|
RequestedDownload | { id: string } | — |
RequestedExpand | { id: string; expanded: boolean } | Expand or Collapse: the app gives the viewer the whole frame, or its place back |
RequestedClose | { id: string } | — |
DeliverableCardView function
Options
| Name | Type | Description |
|---|---|---|
namerequired | string | The file's name, with its extension: "Account-Plan.pptx" |
contentrequired | DeliverableContent | — |
open | boolean | The file is open in the viewer now: Open reads "Opened" |
generating | boolean | Still being made: no Open yet |
onOpenrequired | Message | — |
onDownload | Message | — |
locale | string | — |
style | Style | — |