# Deliverable Viewer

> The file an agent hands back. It shows as a card in the chat and opens in a viewer to page through and download.

Page: https://uicontext.com/docs/components/deliverable-viewer

Group: Agents.

## When to use

The file an agent hands back. It shows as a card in the chat and opens in a viewer to page through and download. Use [Files](https://uicontext.com/docs/components/files.md) instead when the agent made several files.

## Usage

```ts
import { DeliverableCard, type DeliverableContent, DeliverableViewer } from "./ui/uicontext/components/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 added
export 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

Each example is a complete file. Its imports point where the CLI installs the source.

### A deck the agent updated

Open the card and the deck opens on the slide the agent added, marked New in the thumbnails. Page with the arrows or the keys, zoom, or download; Close puts the card back.

```ts title="src/demo.ts" source="www/src/examples/deliverable-viewer/demo.ts"
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/Deliverable.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, 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: corner.card, 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 }) },
		})),
	),
})
```

### 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.

```ts title="src/sheet.ts" source="www/src/examples/deliverable-viewer/sheet.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { DeliverableViewer } from "./ui/uicontext/components/Deliverable.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner } from "./ui/uicontext/components/tokens.stylex.ts"
import { comparison } from "./files.ts"

const styles = stylex.create({ frame: { width: "100%", height: 360, borderRadius: corner.card, 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.

```ts title="src/document.ts" source="www/src/examples/deliverable-viewer/document.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { DeliverableViewer } from "./ui/uicontext/components/Deliverable.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner } from "./ui/uicontext/components/tokens.stylex.ts"
import { memo } from "./files.ts"

const styles = stylex.create({ frame: { width: "100%", height: 520, borderRadius: corner.card, 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 },
	}))
```

### Sample data

The examples above import these files.

```ts title="src/files.ts" source="www/src/examples/deliverable-viewer/files.ts"
import type { DeliverableContent } from "./ui/uicontext/components/Deliverable.ts"

// Sample files for the deliverable examples: a short account deck whose last slide the agent added,
// a two-page memo, and a vendor comparison with two sheets.

export const deck: DeliverableContent = { _tag: "Slides", slides: [
	{ cover: true, eyebrow: "Account plan · Q1 2027", title: "Halden Health", subtitle: "Strategic account plan for the Dec 9 review" },
	{ eyebrow: "Executive summary", title: "Halden is ready to grow past the pilot",
		stats: [{ value: "$2.4M", label: "Current ARR" }, { value: "94%", label: "Weekly active seats" }, { value: "+42%", label: "Workflows since January" }],
		bullets: ["Two executive sponsors", "Forecasting is the next team to onboard", "CISO review due Jan 15"] },
	{ eyebrow: "Adoption", title: "Usage keeps climbing", chart: { label: "Workflows per month (thousands)", bars: [
		{ label: "Aug", value: 7.4, display: "7.4k" }, { label: "Sep", value: 8, display: "8.0k" }, { label: "Oct", value: 8.9, display: "8.9k" }, { label: "Nov", value: 9.1, display: "9.1k", highlight: true },
	] } },
	{ eyebrow: "Forecast", title: "$1.2M upside if governance clears by Jan 15",
		chart: { label: "Forecast ARR ($M)", bars: [
			{ label: "Today", value: 2.4, display: "$2.4M" }, { label: "FY27 base", value: 2.9, display: "$2.9M" }, { label: "With expansion", value: 3.6, display: "$3.6M", highlight: true },
		] },
		notes: [
			{ label: "Risks", text: "CISO needs audit-log and data-boundary evidence" },
			{ label: "Next steps", text: "Dec 9 review → Jan 15 sign-off → Feb 1 pilot" },
		],
		source: "Source: data room and #acct-halden" },
] }

export const memo: DeliverableContent = { _tag: "Document", pages: [
	{ blocks: [
		{ _tag: "Heading", level: 1, text: "Q4 board update" },
		{ _tag: "Paragraph", text: "We closed the quarter ahead of plan: revenue grew 18% to $4.12M and retention stayed above 120%." },
		{ _tag: "Callout", text: "Decision needed: approve the FY27 hiring plan." },
		{ _tag: "Bullets", items: ["Net retention 121%", "Two enterprise logos", "Forecasting is generally available"] },
	] },
	{ blocks: [
		{ _tag: "Heading", level: 2, text: "Financials" },
		{ _tag: "Table", table: { columns: ["", "Q3", "Q4"], rows: [["Revenue", "$3.49M", "$4.12M"], ["Burn", "$455k", "$410k"], ["Runway", "22 mo", "26 mo"]] } },
	] },
] }

export const comparison: DeliverableContent = { _tag: "Sheet", sheets: [
	{ name: "Comparison", columns: [
		{ label: "Vendor", width: 12 }, { label: "Per seat / mo", align: "end", width: 13 }, { label: "40 seats / yr", align: "end", width: 13 }, { label: "SSO", width: 6 }, { label: "Fit", width: 30 },
	], rows: [
		["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"],
	], marks: [{ row: 0, tone: "success" }] },
	{ name: "Sources", columns: [{ label: "Vendor", width: 12 }, { label: "Page", width: 30 }], rows: [["Fernway", "fernway.example/pricing"], ["Orbitly", "orbitly.example/pricing"]] },
] }
```

## API reference

### DeliverableViewer (component)

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `agentId` | `string` | — | The id agents see this viewer by; `deliverable:<id>` when left out |
| `id` (required) | `string` | — | Identifies the file in the events it sends |
| `name` (required) | `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 |
| `content` (required) | `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 }` | — |

### DeliverableCard (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `name` (required) | `string` | The file's name, with its extension: "Account-Plan.pptx" |
| `content` (required) | `DeliverableContent` | — |
| `open` | `boolean` | The file is open in the viewer now: Open reads "Opened" |
| `generating` | `boolean` | Still being made: no Open yet |
| `onOpen` (required) | `Message` | — |
| `onDownload` | `Message` | — |
| `locale` | `string` | — |
| `style` | `Style` | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/deliverable-viewer
```

With npm: `npx shadcn@latest add checkfu/uicontext/deliverable-viewer`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/deliverable-viewer`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/deliverable-viewer`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Deliverable.ts`
- `src/ui/uicontext/components/Direction.ts`
- `src/ui/uicontext/components/FileList.ts`
- `src/ui/uicontext/components/Spoken.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Upload.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Deliverable.ts](https://github.com/checkfu/uicontext/blob/main/src/Deliverable.ts)

## Used in

- [Work](https://uicontext.com/blocks/work.md)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
