# zidane-ui/views/headless

Import: `import { … } from 'zidane-ui/views/headless'`. Source: [ui/src/views/headless/index.ts](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/index.ts).

## Functions

### `canCopyImages`

Function.

Whether this browser can put an image on the clipboard.

```ts
function canCopyImages(): boolean
```

**Returns** `boolean`

Source: [ui/src/views/headless/copy-image.ts:10](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/copy-image.ts#L10)

### `copyViewImageInBrowser`

Function.

Puts a view on the clipboard as a PNG: its own content at its full size,
never the screen. The item is made at once with the image still drawing, so
the click that asked for it still counts (Safari).

```ts
function copyViewImageInBrowser(
  request: ViewImageRequest,
  options?: ViewImageOptions,
): Promise<void>
```

**Parameters**

- `request` (`ViewImageRequest`): The view's frame and its Custom parts' stored images.
- `options?` (`ViewImageOptions`, default `{}`): The running pages' images and the rasterizer.

**Returns** `Promise<void>`

Source: [ui/src/views/headless/copy-image.ts:26](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/copy-image.ts#L26)

### `createCustomSlots`

Function.

Creates a slot pool.

```ts
function createCustomSlots(max?: number): CustomSlots
```

**Parameters**

- `max?` (`number`, default `CUSTOM_FRAMES_MAX`): Most live frames. Default `CUSTOM_FRAMES_MAX`.

**Returns** `CustomSlots`

Source: [ui/src/views/headless/custom-slots.ts:37](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/custom-slots.ts#L37)

### `createViewRecords`

Function.

Creates the records cache of `host`.

```ts
function createViewRecords(host: ViewsHost): ViewRecords
```

**Parameters**

- `host` (`ViewsHost`): Where the records come from.

**Returns** `ViewRecords`

Source: [ui/src/views/headless/records.ts:87](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L87)

### `createViewsHost`

Function.

Creates a [`ViewsHost`](https://zidane.si/docs/reference/ui-views-headless.md#ViewsHost) over `backend`.

```ts
function createViewsHost(backend: ViewsBackend): ViewsHost
```

**Parameters**

- `backend` (`ViewsBackend`): What the transport offers.

**Returns** `ViewsHost`

Source: [ui/src/views/headless/store.ts:180](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/store.ts#L180)

### `createViewStateController`

Function.

The state of one view.

```ts
function createViewStateController(options: ViewStateOptions): ViewStateController
```

**Parameters**

- `options` (`ViewStateOptions`): The view, how to ask the host, and the quiet time.

**Returns** `ViewStateController`

Source: [dist/pure-ET4-8JZg.d.ts:19512](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19512)

### `downloadInBrowser`

Function.

Hands `file` to the window's download.

```ts
function downloadInBrowser(file: McpAppFile): Promise<void>
```

**Parameters**

- `file` (`McpAppFile`): The name, the type and the bytes as base64.

**Returns** `Promise<void>`

Source: [ui/src/views/headless/download.ts:15](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/download.ts#L15)

### `fenceViewOf`

Function.

The fence view at this anchor, or `undefined`.

```ts
function fenceViewOf(
  views: readonly ViewMeta[],
  turnId: string,
  fenceIndex: number,
): ViewMeta | undefined
```

**Parameters**

- `views` (`readonly ViewMeta[]`): The session's views.
- `turnId` (`string`): The turn of the reply.
- `fenceIndex` (`number`): The fence's index in the reply.

**Returns** `ViewMeta | undefined`

Source: [ui/src/views/headless/placement.ts:399](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L399)

### `fillThemeVars`

Function.

SVG markup with every `var(--name)` replaced by the theme's value, and
`currentColor` by the text color, so it draws the same as an image (an
image cannot read the page's CSS variables). Scripts and event handlers
are left in: an `<img>` never runs them.

```ts
function fillThemeVars(
  markup: string,
  read: (name: string) => string,
  color: string,
): string
```

**Parameters**

- `markup` (`string`): The `<svg>` markup.
- `read` (`(name: string) => string`): Reads a CSS variable's value (`getPropertyValue` on the root's computed style).
- `color` (`string`): The text color `currentColor` stands for.

**Returns** `string`

Source: [ui/src/views/headless/svg-theme.ts:18](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/svg-theme.ts#L18)

### `heightFor`

Function.

The stored height for this container width: the range it falls in, else
the range nearest to it. `undefined` when none is stored.

```ts
function heightFor(heights: readonly ViewHeight[], width: number): number | undefined
```

**Parameters**

- `heights` (`readonly ViewHeight[]`): The stored heights.
- `width` (`number`): The container width.

**Returns** `number | undefined`

Source: [ui/src/views/headless/placement.ts:331](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L331)

### `savedStoredView`

Function.

The view a saved version holds, as a stored view: its anchor is the turn
that made it.

```ts
function savedStoredView(record: SavedViewRecord): StoredView
```

**Parameters**

- `record` (`SavedViewRecord`): A saved version.

**Returns** `StoredView`

Source: [ui/src/views/headless/records.ts:74](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L74)

### `streamFence`

Function.

The fence at `key` parsed up to `source`. The parser for `key` is held
(at most [`VIEW_PARSERS_MAX`](https://zidane.si/docs/reference/ui-views-headless.md#VIEW_PARSERS_MAX)), so the next call reads only the new
text, and a fence that closes is finished by the parser that streamed it.
The result keeps its identity while its parts do.

```ts
function streamFence(
  key: string,
  source: string,
  done: boolean,
): StreamedFence & { readonly key: string }
```

**Parameters**

- `key` (`string`): Where the fence is (session, turn, fence index). Any stable string.
- `source` (`string`): The fence body so far.
- `done` (`boolean`): The fence is closed: `source` is complete.

**Returns** `StreamedFence & { readonly key: string }`

Source: [ui/src/views/headless/streaming.ts:182](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/streaming.ts#L182)

### `textlessExchanges`

Function.

The exchanges whose agent wrote no top-level reply text (a codemode run
that ends on its tool calls). [`viewPlacements`](https://zidane.si/docs/reference/ui-views-headless.md#viewPlacements) gives such an
exchange no reply row, so its unplaced codemode views need another place
(docs/VIEWS.md, Life of a view: a view the reply does not place shows
with the exchange).

```ts
function textlessExchanges(events: readonly ChatEvent[]): TextlessExchange[]
```

**Parameters**

- `events` (`readonly ChatEvent[]`): The session's events, oldest first.

**Returns** `TextlessExchange[]`

Source: [ui/src/views/headless/placement.ts:226](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L226)

### `unplacedCodemodeViews`

Function.

The codemode views of these turns that no reply placed, and their MCP
apps (docs/VIEWS.md, MCP Apps: drawn above the reply too), oldest first.

```ts
function unplacedCodemodeViews(
  views: readonly ViewMeta[],
  turns: readonly string[],
  options?: { mcpApps?: boolean },
): ViewMeta[]
```

**Parameters**

- `views` (`readonly ViewMeta[]`): The session's views.
- `turns` (`readonly string[]`): The turns' ids.
- `options?` (`{ mcpApps?: boolean }`, default `{}`): Whether MCP apps draw. Off (`viewsMcpApps`), they are left out: the reply has the tool's answer as text.

**Returns** `ViewMeta[]`

Source: [ui/src/views/headless/placement.ts:422](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L422)

### `viewAnswerKey`

Function.

`zidane-ui/views/headless`: the views host (`ViewsHost`), the builder
hosts use over their transport (`createViewsHost`), and the React-free
models the view components read: where views sit in a transcript, the
records cache, the streamed parse, the client's safety checks and the
labels.

```ts
function viewAnswerKey(viewId: string, path: readonly number[]): string
```

**Parameters**

- `viewId` (`string`): The view's id.
- `path` (`readonly number[]`): The input node's path in the view's tree.

**Returns** `string`

Source: [ui/src/views/headless/answers.ts:31](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/answers.ts#L31)

### `viewById`

Function.

The view with this id, or `undefined`.

```ts
function viewById(views: readonly ViewMeta[], id: string): ViewMeta | undefined
```

**Parameters**

- `views` (`readonly ViewMeta[]`): The session's views.
- `id` (`string`): The view's id.

**Returns** `ViewMeta | undefined`

Source: [ui/src/views/headless/placement.ts:409](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L409)

### `viewPlacements`

Function.

The reply rows of a transcript, keyed by row id (`m-<turnId>-<n>`, as the
transcript pipeline names them), with where their views go. A place that
did not change keeps its identity from `previous`, so a row reading it
does not draw again.

```ts
function viewPlacements(
  events: readonly ChatEvent[],
  previous?: ReadonlyMap<string, ReplyViewPlace>,
): Map<string, ReplyViewPlace>
```

**Parameters**

- `events` (`readonly ChatEvent[]`): The session's events, oldest first.
- `previous?` (`ReadonlyMap<string, ReplyViewPlace>`): The result of the last call, or `undefined`.

**Returns** `Map<string, ReplyViewPlace>`

Source: [ui/src/views/headless/placement.ts:55](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L55)

### `viewReadsRefs`

Function.

The view reads refs or data from codemode: Refresh can run it again with fresh values.

```ts
function viewReadsRefs(view: Pick<StoredView, 'data' | 'source'>): boolean
```

**Parameters**

- `view` (`Pick<StoredView, 'data' | 'source'>`): The stored view.

**Returns** `boolean`

Source: [ui/src/views/headless/refs.ts:18](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/refs.ts#L18)

### `viewRecordsOf`

Function.

The one records cache of `host`.

```ts
function viewRecordsOf(host: ViewsHost): ViewRecords
```

**Parameters**

- `host` (`ViewsHost`): The views host.

**Returns** `ViewRecords`

Source: [ui/src/views/headless/records.ts:247](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L247)

### `viewsError`

Function.

A typed error out of anything a call threw: a host that cannot refresh
views or a saved view (`data.reason`), refused params (JSON-RPC invalid params), else
`failed` with its message.

```ts
function viewsError(err: unknown): ViewsHostError
```

**Parameters**

- `err` (`unknown`): What the call threw.

**Returns** `ViewsHostError`

Source: [ui/src/views/headless/store.ts:155](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/store.ts#L155)

### `viewStateOf`

Function.

The state of view `ref` at `version`: one per view and
version, kept while the transcript scrolls (an LRU of
[`VIEW_STATES_MAX`](https://zidane.si/docs/reference/ui-views-headless.md#VIEW_STATES_MAX) views per host). A new version (an update, a
refresh) starts with the reader's values of the version before, when
they still fit it.

```ts
function viewStateOf(
  host: ViewsHost | null,
  ref: ViewRef,
  view: Pick<StoredView, 'tree' | 'states'>,
  version: number,
): ViewStateController
```

**Parameters**

- `host` (`ViewsHost | null`): The views host, or `null` (only the trees drawn ahead).
- `ref` (`ViewRef`): The view.
- `view` (`Pick<StoredView, 'tree' | 'states'>`): The stored view.
- `version` (`number`): Its version (`viewVersion`).

**Returns** `ViewStateController`

Source: [ui/src/views/headless/view-state.ts:50](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/view-state.ts#L50)

### `viewVersion`

Function.

A view's version: it changes when the stored tree changes (a refresh, or a script's `view.update`).

```ts
function viewVersion(
  meta: Pick<ViewMeta, 'createdAt' | 'refreshedAt' | 'updatedAt'>,
): number
```

**Parameters**

- `meta` (`Pick<ViewMeta, 'createdAt' | 'refreshedAt' | 'updatedAt'>`): The view's times.

**Returns** `number`

Source: [ui/src/views/headless/placement.ts:372](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L372)

### `widthRange`

Function.

The width range a container width falls in.

```ts
function widthRange(width: number): { maxWidth?: number; minWidth: number }
```

**Parameters**

- `width` (`number`): The container width.

**Returns** `{ maxWidth?: number; minWidth: number }`

Source: [ui/src/views/headless/placement.ts:314](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L314)

### `withHeight`

Function.

The stored heights with this width's range set to `height`, or `null`
when that range already holds it (within a pixel).

```ts
function withHeight(
  heights: readonly ViewHeight[],
  width: number,
  height: number,
): ViewHeight[] | null
```

**Parameters**

- `heights` (`readonly ViewHeight[]`): The stored heights.
- `width` (`number`): The container width the height was measured at.
- `height` (`number`): The measured height.

**Returns** `ViewHeight[] | null`

Source: [ui/src/views/headless/placement.ts:355](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L355)

## Classes

### `ViewAnswers`

Class.

The answers of one transcript, per input.

```ts
class ViewAnswers
```

**Constructor**

```ts
new ViewAnswers()
```

**Returns** `ViewAnswers`

**Properties**

- `listenerCount` (`number`, readonly): Number of keys with a listener, for leak tests.
- `size` (`number`, readonly): Number of answers held.

**Methods**

#### `flush()`

```ts
flush(): void
```

Tells the controls whose answer changed since the last flush.

#### `get()`

```ts
get(key: string): ViewAnswer | undefined
```

The answer of one input, or `undefined`.

**Parameters**

- `key` (`string`): The input's key, from [`viewAnswerKey`](https://zidane.si/docs/reference/ui-views-headless.md#viewAnswerKey).

**Returns** `ViewAnswer | undefined`

#### `subscribe()`

```ts
subscribe(key: string, onChange: () => void): () => void
```

Calls `onChange` when the answer of `key` changes. Returns the function that stops it.

**Parameters**

- `key` (`string`): The input's key, from [`viewAnswerKey`](https://zidane.si/docs/reference/ui-views-headless.md#viewAnswerKey).
- `onChange` (`() => void`): Called when the answer changes.

**Returns** `() => void`

#### `update()`

```ts
update(events: readonly ChatEvent[] | TranscriptEvents<ChatEvent>): void
```

Reads the events. Call `flush` after to tell the controls whose answer changed.

**Parameters**

- `events` (`readonly ChatEvent[] | TranscriptEvents<ChatEvent>`): The session's events, oldest first, or its transcript store (its settled exchanges are read once).

Source: [ui/src/views/headless/answers.ts:52](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/answers.ts#L52)

## Constants

### `customSlots`

Constant.

The app's one pool: every Custom frame of every view shares it.

```ts
const customSlots: CustomSlots
```

Source: [ui/src/views/headless/custom-slots.ts:84](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/custom-slots.ts#L84)

### `DEFAULT_VIEWS_LABELS`

Constant.

The default English strings of the view components. Override any of them through `LabelsProvider`.

```ts
const DEFAULT_VIEWS_LABELS: { cancel: string; copiedShort: string; retry: string; viewActionDenied: string; viewActionFailed: string; viewActionRuns: (tool: string) => string; viewActions: string; viewActionSends: (text: string) => string; viewActionWaiting: string; viewChoiceOptions: string; viewCloseTab: string; viewCopyFailed: string; viewCopyImage: string; viewCopyText: string; viewCustomConsoleError: string; viewCustomEmpty: string; viewCustomFailed: string; viewCustomFrame: (title: string) => string; viewCustomImage: (title: string) => string; viewCustomOff: string; viewCustomOverflow: string; viewCustomRun: string; viewCustomSnapshot: (title: string) => string; viewCustomUnsupported: string; viewCustomWaiting: string; viewDeleteFailed: string; viewDrawing: string; viewErrors: string; viewExpand: string; viewFormNo: string; viewFormYes: string; viewFrame: (title: string) => string; viewImageHidden: (alt: string) => string; viewInPanel: string; viewInputsFailed: string; viewInputsOff: string; viewInputsPending: string; viewInputsSend: string; viewInputsSending: string; viewInputsSent: string; viewInputsUnsupported: string; viewInvalid: (name: string) => string; viewLinkDomain: (domain: string) => string; viewLive: (seconds: number) => string; viewLoadFailed: string; viewLoading: string; viewMcpAppAllow: string; viewMcpAppAllowed: (names: string) => string; viewMcpAppAsks: (names: string) => string; viewMcpAppDownloadBody: (server: string, size: string) => string; viewMcpAppDownloadSave: string; viewMcpAppDownloadTitle: (name: string) => string; viewMcpAppFailed: string; viewMcpAppFrame: (server: string, title: string) => string; viewMcpAppFrom: (server: string) => string; viewMcpAppOff: string; viewMcpAppPermission: (name: 'camera' | 'microphone' | 'geolocation' | 'clipboardWrite') => string; viewMcpAppRefused: string; viewMcpAppRun: string; viewMcpAppUiOff: string; viewMcpAppUnsupported: string; viewMcpAppWaiting: string; viewMissingRef: (ref: string) => string; viewNewerVersion: string; viewNo: string; viewOpenChat: string; viewOpenInArtifacts: string; viewOpenInChat: string; viewOpenPanel: string; viewPending: string; viewPin: string; viewPinFailed: string; viewPinnedHomeOff: string; viewRefresh: string; viewRefreshedAgo: (age: string) => string; viewRefreshedAt: (when: string) => string; viewRefreshFailed: string; viewRefreshing: string; viewRefreshUnsupported: string; viewRename: string; viewRenameFailed: string; viewRenameTitle: (title: string) => string; viewSave: string; viewSaved: string; viewSavedDelete: string; viewSaveFailed: string; viewSessionAgent: string; viewSessionAgentDefault: string; viewSessionAlways: string; viewSessionAnother: string; viewSessionArtifacts: string; viewSessionAsk: (verb: 'start' | 'send' | 'schedule' | 'command') => string; viewSessionChip: (status: string, title: string) => string; viewSessionCommand: string; viewSessionDraft: string; viewSessionFailed: string; viewSessionMore: string; viewSessionOnce: (verb: 'start' | 'send' | 'schedule' | 'command') => 'Start once' | 'Run once'; viewSessionOpen: string; viewSessionOpenToast: string; viewSessionPrompt: string; viewSessionRan: string; viewSessionScheduled: string; viewSessionSent: string; viewSessionStarted: (title: string) => string; viewSessionStartedDefault: (title: string, agent: string) => string; viewSessionStatus: (status: 'done' | 'failed' | 'running' | 'blocked') => string; viewSessionWhen: string; viewSessionWhere: string; viewSessionWhereBranch: (branch: string) => string; viewSessionWhereProject: string; viewShowLatest: string; viewShowOriginal: string; viewSourceAgo: (age: string) => string; viewSourceAllow: string; viewSourceAllowMenu: string; viewSourceAllowOnce: string; viewSourceAllowTool: string; viewSourceAllowView: string; viewSourceAskBar: string; viewSourceAskTitle: string; viewSourceDetail: (target: string, state: string) => string; viewSourceDetails: string; viewSourceError: (reason: string, message: string) => string; viewSourceFailed: (name: string) => string; viewSourceFetched: (age: string) => string; viewSourceMore: (count: number) => string; viewSourceNeedsSignIn: (server: string) => string; viewSourceNoArgs: string; viewSourceNotNow: string; viewSourceOld: (age: string) => string; viewSourceReadOnly: string; viewSourceReason: (reason: ViewSourceFailure) => string; viewSourceSignIn: string; viewSourcesMenu: string; viewSourcesOff: string; viewSourceToolChanged: (server: string) => string; viewSourceToolNotAllowed: string; viewSourceWantMany: (count: number) => string; viewSourceWantsAccess: (server: string) => string; viewSourceWantsRun: string; viewSourceWantsSessions: string; viewStateControl: string; viewStateFailed: string; viewStateSearch: string; viewStateUnsupported: string; viewTitleField: string; viewTurnFailed: string; viewTurnIntoBlock: string; viewTurnIntoPanel: string; viewTurnOnHome: string; viewUnknown: (name: string) => string; viewUnpin: string; viewUnsave: string; viewUnsaveConfirm: string; viewUnsaveConfirmAction: string; viewUnsaveConfirmBody: string; viewUntitled: string; viewVersionOf: (version: number, latest: number) => string; viewVersionPick: string; viewYes: string }
```

Source: [ui/src/views/headless/labels.ts:9](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/labels.ts#L9)

### `VIEW_PARSERS_MAX`

Constant.

Most fences whose parser stays held between renders.

```ts
const VIEW_PARSERS_MAX = 16
```

Source: [ui/src/views/headless/streaming.ts:35](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/streaming.ts#L35)

### `VIEW_PROBLEM_REPORTS_MAX`

Constant.

Most problems one view sends to the host.

```ts
const VIEW_PROBLEM_REPORTS_MAX = 5
```

Source: [ui/src/views/headless/store.ts:136](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/store.ts#L136)

### `VIEW_RECORDS_MAX`

Constant.

Most records one host's cache keeps.

```ts
const VIEW_RECORDS_MAX = 64
```

Source: [ui/src/views/headless/records.ts:21](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L21)

### `VIEW_STATE_DEBOUNCE_MS`

Constant.

Quiet time after the last change before a tree is asked of the host.

```ts
const VIEW_STATE_DEBOUNCE_MS = 250
```

Source: [dist/pure-ET4-8JZg.d.ts:19447](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19447)

### `VIEW_STATE_TREES_MAX`

Constant.

Trees one view keeps that the host ran on demand.

```ts
const VIEW_STATE_TREES_MAX = 16
```

Source: [dist/pure-ET4-8JZg.d.ts:19449](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19449)

### `VIEW_STATES_MAX`

Constant.

Views whose state one host keeps.

```ts
const VIEW_STATES_MAX = 64
```

Source: [ui/src/views/headless/view-state.ts:22](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/view-state.ts#L22)

### `VIEW_WIDTH_STEPS`

Constant.

Container widths where a view's stored height changes, in CSS pixels.

```ts
const VIEW_WIDTH_STEPS: readonly [480, 720, 960]
```

Source: [ui/src/views/headless/placement.ts:307](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L307)

## Interfaces

### `CustomFrame`

Interface.

One live Custom page, in its own sandboxed process (desktop: a
`<webview>`; web: an iframe with `sandbox="allow-scripts"` from a ticket
route). The caller puts `element` in the view and calls `dispose` once.

```ts
interface CustomFrame
```

**Properties**

- `dispose` (`() => void`): Stops the page and frees its process.
- `element` (`HTMLElement`): The frame element. It fills its container.
- `kind?` (`'mcp-app'`): `mcp-app`: an MCP app's page (docs/VIEWS.md, MCP Apps). It speaks
  JSON-RPC: its messages arrive as `rpc` events and `postRpc`
  answers. Absent: a Custom page.
- `listen` (`(onEvent: (event: CustomFrameEvent) => void) => () => void`): Calls `onEvent` with each checked message of this page only. Returns the function that stops it.
- `permissions?` (`readonly McpAppPermission[]`): An MCP app's permissions the host granted the page (allowed by the user and declared by the app).
- `postRpc?` (`(message: unknown) => void`): Sends one JSON-RPC message to an MCP app's page. A message over the bridge's limit is not sent.
- `setData?` (`(data: JsonValue$1 | undefined) => void`): Sends the `<Custom data>` of the tree drawn now to the running page (a new
  state, a refresh, live data): `window.zidane.data` changes and a
  `zidane:data` event fires, with no reload. Data over the limit is not
  sent. Absent: the page keeps the data it was made with.
- `setTheme?` (`(theme: Readonly<Record<string, string>>) => void`): Sends the app's `--zg-*` theme variables to the running page, after a theme change. Absent: the page keeps the theme it was made with.
- `snapshot?` (`() => Promise<string | null>`): An image of the page as a `data:image/…` URL, or `null`. Absent: the host cannot take one (the web).

Source: [ui/src/views/headless/host.ts:137](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L137)

### `CustomFrameRequest`

Interface.

What a Custom frame is asked for: one `<Custom>` node of a stored view.

```ts
interface CustomFrameRequest
```

**Properties**

- `original` (`boolean`): The node is in the view's original result, not the latest.
- `path` (`readonly number[]`): The node's path in the tree (child indexes from the top).
- `permissions?` (`readonly McpAppPermission[]`): An MCP app only (docs/VIEWS.md, MCP Apps): the permissions the user
  allowed. The host keeps those the app declared. Absent: none.
- `ref` (`ViewRef`): The view.
- `state?` (`Readonly<ViewState>`): The state values of the tree the node is in, when it is not the view's
  first tree: the host mints the page of that state's tree, so a state
  that changes the page's HTML shows its own page. Absent: the stored tree.
- `theme` (`Readonly<Record<string, string>>`): The app's `--zg-*` theme variables, for the page.
- `title` (`string`): The node's title, for the frame's accessible name.

Source: [ui/src/views/headless/host.ts:56](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L56)

### `CustomSlotHolder`

Interface.

What holds or waits for a slot.

```ts
interface CustomSlotHolder
```

**Properties**

- `grant` (`() => void`): The slot is yours: start the frame.
- `revoke` (`() => void`): The slot was taken back: park the frame. You wait for the next free slot.

Source: [ui/src/views/headless/custom-slots.ts:12](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/custom-slots.ts#L12)

### `CustomSlots`

Interface.

The slot pool.

```ts
interface CustomSlots
```

**Properties**

- `counts` (`() => { live: number; waiting: number }`): Live and waiting holders, for leak tests.
- `request` (`(holder: CustomSlotHolder, options?: { priority?: boolean }) => () => void`): Asks for a slot. Returns the function that gives it back (or stops waiting).

Source: [ui/src/views/headless/custom-slots.ts:20](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/custom-slots.ts#L20)

### `McpAppFile`

Interface.

A file an MCP app asks to save (`ViewsHost.downloadFile`).

```ts
interface McpAppFile
```

**Properties**

- `data` (`string`): The bytes, base64.
- `mimeType` (`string`): The file's media type, such as `text/csv`.
- `name` (`string`): A file name with no folders.

Source: [ui/src/views/headless/host.ts:96](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L96)

### `ReplyViewPlace`

Interface.

What one reply row needs to find its views.

```ts
interface ReplyViewPlace
```

**Properties**

- `codemodeTurns?` (`readonly string[]`): Set on an exchange's final reply: the turns whose unplaced codemode views it draws above itself.
- `fenceBase` (`number`): The index of the row's first `view` fence in its turn's text.
- `turnId` (`string`): The turn of the reply.

Source: [ui/src/views/headless/placement.ts:16](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L16)

### `SavedViewMeta`

Interface.

A saved view's meta: what lists and pins read without a record.

```ts
interface SavedViewMeta
```

**Properties**

- `artifact` (`boolean`): The saved view records a `view` artifact on the session that saves it.
- `createdAt` (`number`): When the view was first saved, in epoch milliseconds.
- `heights?` (`ViewHeight[]`): The stored heights of the latest version, one per range of widths: a
  pin block reserves them before it reads the record. Absent: none stored.
- `key` (`string`): The saved key.
- `latest` (`number`): The latest version.
- `originSessionId?` (`string`): The session that saved the latest version.
- `panel?` (`true`): A side panel tab of its project (`views.turnInto` `panel`): every session of the project and its folder offer
  it. A panel is never pinned. Absent: not a panel.
- `pinned` (`boolean`): Pinned to the home.
- `pinOrder?` (`number`): The place among pinned views, from 0.
- `scope` (`string`): The project root, or `""` for the global scope.
- `title` (`string`): The title lists, pins and artifacts show: the person's when they gave one, else the agent's latest.
- `titleSetByUser?` (`true`): The person gave the title (`views.rename`): later saves keep it.
- `updatedAt` (`number`): When the view was last changed, in epoch milliseconds.
- `versions` (`number`): The versions kept.

Source: [dist/index-CM_SslFj.d.ts:9926](https://github.com/Tahul/zidane/blob/main/dist/index-CM_SslFj.d.ts#L9926)

### `SavedViewRecord`

Interface.

One version of a saved view: a full record (docs/VIEWS-SAVED.md, Identity and storage).

```ts
interface SavedViewRecord
```

**Properties**

- `basedOn?` (`number`): The version the update started from.
- `format` (`number`): Record format, `SAVED_VIEW_FORMAT`.
- `key` (`string`): The saved key.
- `origin` (`SavedViewOrigin`): The session, turn and view that saved it.
- `savedAt` (`number`): When this version was saved, in epoch milliseconds.
- `scope` (`string`): The project root, or `""` for the global scope.
- `sources?` (`SavedViewSourceState[]`): The view's live sources with their fetch times and status.
- `staleBase?` (`true`): Set when `basedOn` was not the latest version: another save came between.
- `title` (`string`): The frame title.
- `version` (`number`): This version, from 1.
- `view` (`ViewRecord`): The view as it was saved: source, frozen data, images, Custom snapshots, state trees and heights.

Source: [dist/index-CM_SslFj.d.ts:9901](https://github.com/Tahul/zidane/blob/main/dist/index-CM_SslFj.d.ts#L9901)

### `SavedViewVersion`

Interface.

One kept version, without its record (`views.savedVersions`).

```ts
interface SavedViewVersion
```

**Properties**

- `basedOn?` (`number`): The version the update started from.
- `origin` (`SavedViewOrigin`): The session, turn and view that saved it.
- `savedAt` (`number`): When this version was saved, in epoch milliseconds.
- `staleBase?` (`true`): Set when `basedOn` was not the latest version: another save came between.
- `version` (`number`): This version, from 1.

Source: [dist/index-CM_SslFj.d.ts:9965](https://github.com/Tahul/zidane/blob/main/dist/index-CM_SslFj.d.ts#L9965)

### `StoredView`

Interface.

A stored view plus its anchor.

```ts
interface StoredView extends ViewRecord
```

**Properties**

- `alt` (`string`, from `ViewRecord`): Text that stands in for the view where it cannot be drawn.
- `anchor` (`ViewAnchor`): Where the view sits in the transcript.
- `componentVersions?` (`Record<string, number>`, from `ViewRecord`): Props version of each component the tree uses, for `migrate`.
- `createdAt` (`number`, from `ViewRecord`): Epoch milliseconds.
- `customShots?` (`Record<string, ViewCustomShot>`, from `ViewRecord`): A stored image of each `<Custom>` part of `tree`, taken offscreen when
  the view was made (docs/VIEWS.md, Custom snapshots), by the node's path
  (child indexes joined with `.`). One `data:image/png` or
  `data:image/webp` URL per appearance. Absent: no renderer, or custom
  code off.
- `data` (`Record<string, JsonValue$1>`, from `ViewRecord`): Frozen values of the refs the view read, by ref name.
- `errors` (`ViewError[]`, from `ViewRecord`): The problems found while the view was made or refreshed.
- `heights` (`ViewHeight[]`, from `ViewRecord`): Drawn heights, one per range of container widths.
- `id` (`string`, from `ViewRecord`): `v3`
- `images?` (`Record<string, string>`, from `ViewRecord`): The local and attachment images the trees show, inlined when the view
  was made (docs/VIEWS.md, Images): `data:image/…` URLs by the source the
  view wrote (`./plot.png`, `attachment://…`). Every surface reads them
  here, so none asks the host. Absent: no such image, or a view stored
  before images were inlined (the client then asks `views.image`).
- `origin` (`'codemode' | 'fence' | 'mcp-app'`, from `ViewRecord`): `mcp-app`: the app of an MCP tool call (docs/VIEWS.md, MCP Apps), stored by the host, never by the model.
- `original` (`ViewTree`, from `ViewRecord`): The result from the turn that made the view.
- `placed?` (`boolean`): Set when the reply placed this codemode view with `<View ref="…" />`.
- `placedViews?` (`Record<string, ViewRecord>`, from `ViewRecord`): A saved version only (docs/VIEWS-SAVED.md, Saving and surfaces): frozen
  copies of the codemode views its `<View ref>` nodes place, by id, taken
  when it was saved. The apps draw them from here, without reading the
  session that made them. Absent: none, or saved before they were kept.
- `refreshedAt?` (`number`, from `ViewRecord`): Epoch milliseconds of the last refresh. Absent: never refreshed.
- `runId?` (`string`, from `ViewRecord`): The run that made the view.
- `saved?` (`SavedViewStamp`, from `ViewRecord`): The saved version this view made (docs/VIEWS-SAVED.md). Absent: not saved.
- `sessionApprovals?` (`string[]`, from `ViewRecord`): The template keys of this view's session actions the person allowed for
  good (docs/VIEWS-ORCHESTRATION.md, "Always for this view"). A changed template asks again.
- `sessionId` (`string`, from `ViewRecord`): The session that holds the view.
- `sessionSchedules?` (`string[]`, from `ViewRecord`): The schedules this view's session actions made, by id (at most 20 live at once).
- `source` (`string`, from `ViewRecord`): The fence source, or the codemode spec as JSX. An MCP app: its resource URI.
- `sourceApprovals?` (`ViewSourceApproval[]`, from `ViewRecord`): The person's approvals of this view's MCP sources (docs/VIEWS-SAVED.md,
  MCP sources): each a tool with its exact args. Changed args ask again.
- `sources?` (`ViewSourceStatus[]`, from `ViewRecord`): The view's live sources (docs/VIEWS-SAVED.md, Sources): one status per
  `<Source>`, with its fetch time. Their data is in `data`, by name.
  Absent: the view declares none.
- `states?` (`ViewStates`, from `ViewRecord`): The view's `<State>` declarations and the trees drawn ahead for them
  (docs/VIEWS.md, State). `tree` is the initial state. Absent: no state.
- `title` (`string`, from `ViewRecord`): The frame title. Empty when the view has no Heading and its title comes
  from an element that draws that title itself (`viewFrameTitle`). The
  model's one-line summary then falls back to `viewTitle`.
- `tree` (`ViewTree`, from `ViewRecord`): The latest result. Equal to `original` until a refresh.
- `turnId?` (`string`, from `ViewRecord`): The turn that made the view.
- `updatedAt?` (`number`, from `ViewRecord`): Epoch milliseconds of the last `view.update` of a codemode view. Absent: never updated.
- `version` (`number`, from `ViewRecord`): Record format version, `VIEW_RECORD_VERSION`.

Source: [dist/index-CM_SslFj.d.ts:10229](https://github.com/Tahul/zidane/blob/main/dist/index-CM_SslFj.d.ts#L10229)

### `StreamedFence`

Interface.

A fence parsed so far.

```ts
interface StreamedFence
```

**Properties**

- `done` (`boolean`): The source is complete.
- `parts` (`readonly StreamedPart[]`): The top-level parts, in order. A closed part keeps its identity across updates.

Source: [ui/src/views/headless/streaming.ts:27](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/streaming.ts#L27)

### `TextlessExchange`

Interface.

An exchange with no reply text: its codemode views draw after its last row.

```ts
interface TextlessExchange
```

**Properties**

- `closed` (`boolean`): A later prompt closed it: no reply text can come any more.
- `turns` (`readonly string[]`): The exchange's top-level turns, oldest first.

Source: [ui/src/views/headless/placement.ts:210](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/placement.ts#L210)

### `ViewAnswer`

Interface.

An answer the user sent from a view's input.

```ts
interface ViewAnswer
```

**Properties**

- `text` (`string`): The text the message showed.
- `value` (`unknown`): What was picked: an option's value, the form's values, or the action's tool and arguments.

Source: [ui/src/views/headless/answers.ts:18](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/answers.ts#L18)

### `ViewImageOptions`

Interface.

How a view becomes an image (`copyViewImageInBrowser`).

```ts
interface ViewImageOptions
```

**Properties**

- `frameImage?` (`FrameImage`): The image of each running page. Absent: its stored image, else its name.
- `rasterize?` (`RasterizeSvg`): Turns the markup into a PNG. Default: a canvas.

Source: [ui/src/views/headless/capture.ts:34](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/capture.ts#L34)

### `ViewImageRequest`

Interface.

One view to copy as an image (`ViewsHost.copyImage`), exactly as it shows now.

```ts
interface ViewImageRequest
```

**Properties**

- `customShots?` (`Readonly<Record<string, string>>`): The stored image of each Custom part, by node path (child indexes joined
  with `.`), for the theme shown: a host that cannot draw a running page
  (the web) shows it in the page's place.
- `element` (`HTMLElement`): The view's frame, as drawn now: its tab, its state, the theme and the width.
- `padding?` (`number`): Space around the content, in CSS pixels, in the color it shows on, with
  rounded corners: for an element with no frame of its own (the full-screen view).

Source: [ui/src/views/headless/host.ts:106](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L106)

### `ViewRecords`

Interface.

The records cache of one host.

```ts
interface ViewRecords
```

**Properties**

- `counts` (`() => { listeners: number; records: number }`): Records held and keys listened to, for leak tests.
- `latest` (`(ref: ViewRef) => { version: number; view: StoredView } | undefined`): The newest record of this view read so far, of any version, and its version. A view whose
  version moved on (a refresh, a script's `view.update`) draws it until the new one loads, so it
  does not unmount and lose its scroll and open tabs.
- `load` (`(ref: ViewRef, version: number) => void`): Reads the record unless it is held or on its way.
- `loadSaved` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => void`): Reads the saved record a ref with a version names, unless it is held or on its way.
- `peek` (`(ref: ViewRef, version: number) => ViewRecordState | undefined`): What the cache holds for this record, or `undefined` before a read.
- `peekSaved` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => SavedRecordState | undefined`): What the cache holds for the saved record a ref with a version names, or `undefined` before a read.
- `seedSaved` (`(record: SavedViewRecord) => void`): Holds a saved record read elsewhere (the latest version): its ref with that version, and the view
  a block draws of it, read nothing more.
- `subscribe` (`(ref: ViewRef, version: number, onChange: () => void) => () => void`): Calls `onChange` when this record's state changes. Returns the function that stops it.
- `subscribeSaved` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }, onChange: () => void) => () => void`): Calls `onChange` when that saved record's state changes. Returns the function that stops it.

Source: [ui/src/views/headless/records.ts:38](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L38)

### `ViewsBackend`

Interface.

What a transport offers. Each member left out leaves the host member that needs it out. A
member about one view gets a session ref only: the host refuses a saved one before it. A
backend with `getSaved` also gets saved refs in `setHeights`, `setState` and `customFrame`.

```ts
interface ViewsBackend
```

**Properties**

- `appRequest?` (`(ref: { id: string; kind: 'session'; sessionId: string }, method: McpAppRequestMethod, params: Record<string, unknown>) => Promise<unknown>`): An MCP app's request to its own server (`views.appRequest`).
- `approveSource?` (`(ref: ViewRef, name: string, as: ViewSourceApprove) => Promise<StoredView | null>`): Allows one MCP source of a view, then fetches its sources again (`views.approveSource`). A saved ref only with `getSaved`.
- `copyImage?` (`(request: ViewImageRequest) => Promise<void>`): Puts a view on the clipboard as a PNG (`copyViewImageInBrowser` on the web).
- `customFrame?` (`(request: CustomFrameRequest) => Promise<CustomFrame>`): Starts a Custom page. Throws when it cannot. A saved ref only with `getSaved`.
- `deleteSaved?` (`(scope: string, key: string) => Promise<boolean>`): Deletes a saved view (`views.savedDelete`).
- `downloadFile?` (`(file: McpAppFile) => Promise<void>`): Saves a file an MCP app asked to download, after the person confirmed (`downloadInBrowser`).
- `get?` (`(sessionId: string, ids: string[]) => Promise<StoredView[]>`): At most `VIEWS_GET_MAX` stored views.
- `getSaved?` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => Promise<SavedViewRecord | null>`): One saved version (`views.savedGet`). With it, saved refs reach the members about one view that take them.
- `image?` (`(sessionId: string, source: string) => Promise<string | null>`): An image of a view as a URL (`views.image`), or `null`.
- `listSaved?` (`(scope?: string) => Promise<SavedViewMeta[]>`): The saved views (`views.savedList`).
- `meta?` (`(sessionId: string) => Promise<ViewMeta[]>`): Every view meta of a session, oldest first.
- `onChanged?` (`(listener: (signal: ViewsChangedSignal) => void) => () => void`): Listens to `views:changed`. Returns the function that stops it.
- `onData?` (`(listener: (components: readonly string[]) => void) => () => void`): Listens to `views:data`. Returns the function that stops it.
- `pin?` (`(ref: ViewRef) => Promise<SavedViewMeta | null>`): Pins a view to the home (`views.pin`).
- `pinOrder?` (`(scope: string, keys: string[]) => Promise<boolean>`): Orders the pinned views of a scope (`views.pinOrder`).
- `refresh?` (`(ref: { id: string; kind: 'session'; sessionId: string }) => Promise<StoredView | null>`): Refreshes one view.
- `refreshSaved?` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => Promise<StoredView | null>`): Fetches the sources of a saved view again (`views.refresh` with a saved ref). Without it, refresh refuses saved refs.
- `renameSaved?` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }, title: string) => Promise<SavedViewMeta | null>`): Renames a saved view (`views.rename`); `""` gives back the agent's title.
- `reportProblem?` (`(ref: { id: string; kind: 'session'; sessionId: string }, problem: ViewProblem, path?: number[]) => Promise<boolean>`): Sends one problem a Custom page reported. `false`: the host did not store it.
- `resolve?` (`(sessionId: string, nodes: ViewResolveNode[]) => Promise<(ViewResolvedData | null)[]>`): Live data of at most `VIEWS_RESOLVE_MAX` extension nodes of one session (`views.resolve`).
- `runAction?` (`(ref: { id: string; kind: 'session'; sessionId: string }, path: number[], original: boolean) => Promise<ViewActionOutcome>`): Runs a view's Action with a tool (`views.runAction`).
- `save?` (`(ref: { id: string; kind: 'session'; sessionId: string }) => Promise<SavedViewMeta | null>`): Saves a session view (`views.save`).
- `savedVersions?` (`(scope: string, key: string) => Promise<SavedViewVersion[]>`): The kept versions of a saved view (`views.savedVersions`).
- `sessionAction?` (`(ref: ViewRef, path: number[], options: ViewSessionActionOptions) => Promise<ViewSessionActionOutcome>`): Runs a view's session action (`views.sessionAction`, docs/VIEWS-ORCHESTRATION.md). A saved ref only with `getSaved`.
- `sessionLinks?` (`(ref: ViewRef, keys: string[], scope?: string) => Promise<ViewSessionLink[]>`): The newest session of each key (`views.sessionLinks`).
- `setHeights?` (`(ref: ViewRef, heights: ViewHeight[]) => Promise<boolean>`): Stores heights; `false` when the store has no view support. A saved ref only with `getSaved`.
- `setState?` (`(ref: ViewRef, state: ViewState) => Promise<ViewStateResult | null>`): The tree of a view for a new state (`views.setState`). A saved ref only with `getSaved`.
- `signInSource?` (`(ref: { id: string; kind: 'session'; sessionId: string }, server: string, open: (url: string) => void) => Promise<void>`): Starts the MCP sign-in of a source's server. `open` opens its page as a sign-in link (`ViewsHost.signInSource`).
- `toError?` (`(err: unknown) => ViewsHostError`): Turns what a call threw into a typed error. Default: `failed` with its message.
- `turnInto?` (`(scope: string, key: string, into: SavedViewSurface) => Promise<SavedViewMeta | null>`): Turns a saved view into a side panel of its project, or back into a home block (`views.turnInto`).
- `unpin?` (`(scope: string, key: string) => Promise<boolean>`): Unpins a saved view (`views.unpin`).
- `unsave?` (`(ref: { id: string; kind: 'session'; sessionId: string }) => Promise<boolean>`): Deletes the saved view a session view saved (`views.unsave`).

Source: [ui/src/views/headless/store.ts:65](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/store.ts#L65)

### `ViewSessionActionOptions`

Interface.

How a session action runs (`ViewsHost.sessionAction`, docs/VIEWS-ORCHESTRATION.md).

```ts
interface ViewSessionActionOptions
```

**Properties**

- `another?` (`boolean`): "Start another": start even when the key has a session.
- `approve?` (`'view' | 'once'`): The person's answer to `needs-approval`: this click ("Start once") or the view's template ("Always for this view").
- `mode` (`'run' | 'draft'`): `draft`: a new chat with the filled prompt and context, not sent ("Open as draft").
- `rowIndex?` (`number`): The row of a Table's `rowAction`, from 0.

Source: [ui/src/views/headless/host.ts:84](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L84)

### `ViewsHost`

Interface.

The views host.

```ts
interface ViewsHost
```

**Properties**

- `appRequest?` (`(ref: ViewRef, method: McpAppRequestMethod, params: Readonly<Record<string, unknown>>) => Promise<ViewsResult<unknown>>`): A request of an MCP app (docs/VIEWS.md, MCP Apps) to its own server: the
  host reads the server from the stored view, and a tool call goes through
  its approval gate first. Answers the server's result. Absent: the app's
  tool calls and reads are refused. Fails while custom code is off.
- `approveSource?` (`(ref: ViewRef, name: string, as: ViewSourceApprove) => Promise<ViewsResult<StoredView | null>>`): Allows one MCP source of a view (docs/VIEWS-SAVED.md, MCP sources): for
  this fetch, for this view with its args, or for every view (the
  `viewsMcpAllowed` setting), then fetches its sources again. `null`: no
  such view or source. Absent: no Allow.
- `copyImage?` (`(request: ViewImageRequest) => Promise<ViewsResult<void>>`): Puts one view on the clipboard as a PNG, as it shows now (docs/VIEWS.md,
  Share and export): the view's own content at its full size, never the
  screen, so nothing drawn over it shows (`copyViewImageInBrowser`). The
  desktop app draws each running page from its own image; the web shows its
  stored image.
  Absent: no "Copy as image".
- `customFrame?` (`(request: CustomFrameRequest) => Promise<ViewsResult<CustomFrame>>`): Starts the page of one `<Custom>` node in its own sandboxed process.
  Absent: `<Custom>` shows its title and alt text. Fails while the host's
  `viewsCustomCode` is off.
- `deleteSaved?` (`(scope: string, key: string) => Promise<ViewsResult<boolean>>`): Deletes a saved view and every version. Ask the person first (`useConfirm`). Absent: no Delete.
- `downloadFile?` (`(file: McpAppFile) => Promise<ViewsResult<void>>`): Saves a file an MCP app asked to download (docs/VIEWS.md, MCP Apps),
  once the person confirmed: the app's own download path (the desktop's
  save dialog, a browser download; `downloadInBrowser` does it for both).
  Absent: apps cannot save files.
- `get?` (`(sessionId: string, ids: readonly string[]) => Promise<ViewsResult<StoredView[]>>`): The full stored views with these ids, in the order asked; unknown ids are left out. Any number of ids.
- `getSaved?` (`(ref: { key: string; kind: 'saved'; scope: string; version?: number }) => Promise<ViewsResult<SavedViewRecord | null>>`): One version of a saved view (no version: the latest). `null`: none. Absent: saved views do not draw.
- `image?` (`(ref: ViewRef, source: string) => Promise<string | null>`): An image a view shows from an `attachment://` handle or a path in the
  session's folder, as a URL an `<img>` loads; `null` when it cannot be
  shown. Remote images are never asked for. Absent: such images show
  their alt text.
- `listSaved?` (`(scope?: string) => Promise<ViewsResult<SavedViewMeta[]>>`): The saved views, newest first; with `scope`, of that scope only.
- `meta?` (`(sessionId: string) => Readable<ViewsMetaState>`): The view meta of a session, read on the first subscribe and again when
  the session's views change. The same session gives the same store.
- `pin?` (`(ref: ViewRef) => Promise<ViewsResult<SavedViewMeta | null>>`): Pins a view to the home after the others; a session view is saved first. `null`: no such view. Absent: no Pin to home.
- `pinOrder?` (`(scope: string, keys: readonly string[]) => Promise<ViewsResult<boolean>>`): Orders the pinned views of a scope as `keys` lists them.
- `refresh?` (`(ref: ViewRef) => Promise<ViewsResult<StoredView | null>>`): Reads the refs of one view again and runs its code again. `null`: no such view.
- `renameSaved?` (`(scope: string, key: string, title: string) => Promise<ViewsResult<SavedViewMeta | null>>`): Renames a saved view (`views.rename`): the key and the versions stay, and later saves keep
  the title. `""` gives back the agent's title. `null`: there was none. Absent: no Rename.
- `reportProblem?` (`(ref: ViewRef, problem: ViewProblem, path?: readonly number[]) => Promise<ViewsResult<void>>`): Tells the host a Custom page has a problem: it stores it with the view and
  tells the model at the start of its next turn. Bounded: the same problem,
  or more than 5 per view, is not sent again.
- `resolve?` (`(ref: ViewRef, node: ViewNodeAddress) => Promise<ViewsResult<ViewResolvedData | null>>`): Fresh data for one extension component node (`views.resolve`), batched
  with the other nodes asked in the same tick. `null`: no live data for it.
  Fails while the host's `viewsLiveData` is off: the node keeps its stored snapshot.
- `runAction?` (`(ref: ViewRef, path: readonly number[], original: boolean) => Promise<ViewsResult<ViewActionOutcome>>`): Runs a view's `Action` that has a tool (docs/VIEWS.md, Inputs): the host
  reads the tool and its arguments from the stored view at `path`, always
  asks the person with them shown, and on approval sends the button's
  label as the user's answer. Absent: such a button stays static. Fails
  while `viewsInputs` is off.
- `save?` (`(ref: ViewRef) => Promise<ViewsResult<SavedViewMeta | null>>`): Saves a session view (docs/VIEWS-SAVED.md, Saving and surfaces): a new
  version in its project's scope, with a key made from its title. `null`:
  no such view. Fails while the host's `viewsSave` is off. Absent: no Save.
- `savedVersions?` (`(scope: string, key: string) => Promise<ViewsResult<SavedViewVersion[]>>`): The kept versions of a saved view, oldest first. Absent: no version picker.
- `sessionAction?` (`(ref: ViewRef, path: readonly number[], options: ViewSessionActionOptions) => Promise<ViewsResult<ViewSessionActionOutcome>>`): Runs the session action at `path` of a view (docs/VIEWS-ORCHESTRATION.md): an `<Action session>`,
  or the `rowIndex` row of a Table's `rowAction`. The host reads the action from the stored view and
  applies `viewsOrchestration`: the outcome is started, sent, scheduled, ran, exists, needs-approval
  (answer with `approve`), draft (open a new chat with its prompt), refused or failed. Absent: no session actions.
- `sessionLinks?` (`(ref: ViewRef, keys: readonly string[], scope?: string) => Promise<ViewsResult<readonly ViewSessionLink[]>>`): The newest session of each key (a row's status chip), in `scope` (a project root) or every project. Absent: no chips.
- `setHeights?` (`(ref: ViewRef, heights: readonly ViewHeight[]) => Promise<ViewsResult<void>>`): Stores the drawn heights of one view (at most 16 width ranges, heights from 0 to 20,000 px).
- `setState?` (`(ref: ViewRef, state: Readonly<ViewState>) => Promise<ViewsResult<ViewStateResult | null>>`): The tree of a view with `<State>` for a new state (docs/VIEWS.md,
  State): the host runs the view's code again with its frozen data and
  `state`. The stored view does not change. `null`: no such view.
  Absent: a view switches only between the trees its host drew ahead.
- `signInSource?` (`(ref: ViewRef, server: string, open: (url: string) => void) => Promise<ViewsResult<void>>`): Starts the MCP sign-in of a source's server (the Settings flow). Absent: no Sign in. A host
  that needs the page opened calls `open` with its URL: the view opens it as a sign-in link
  (`useLinkRouter().open(url, { source: 'auth' })`), the app's own way. A host whose app opens
  the page itself ignores it.
- `subscribe?` (`(sessionId: string, onChange: (ids: readonly string[]) => void) => () => void`): Calls `onChange` with the ids that were added or changed in the session. Returns the function that stops it.
- `subscribeData?` (`(onData: (components: readonly string[]) => void) => () => void`): Calls `onData` with the extension components whose data changed (`views:data`). Returns the function that stops it.
- `turnInto?` (`(scope: string, key: string, into: SavedViewSurface) => Promise<ViewsResult<SavedViewMeta | null>>`): Turns a saved view into a side panel of its project (`panel`: unpinned, a tab of every session of the project) or
  back into a home block (`block`: pinned, last). `null`: there was none. Absent: neither is offered.
- `unpin?` (`(scope: string, key: string) => Promise<ViewsResult<boolean>>`): Unpins a saved view. `false`: there was none. Absent: no Unpin.
- `unsave?` (`(ref: ViewRef) => Promise<ViewsResult<boolean>>`): Deletes the saved view a session view saved, with every version. Ask the
  person first (`useConfirm`). `false`: it was not saved. Absent: no Unsave.

Source: [ui/src/views/headless/host.ts:201](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L201)

### `ViewsMetaState`

Interface.

The view meta of one session, as a store holds it.

```ts
interface ViewsMetaState
```

**Properties**

- `error?` (`ViewsHostError`): The last read failed. `views` keeps what the read before it gave.
- `loaded` (`boolean`): The first read finished (with or without an error).
- `views` (`readonly ViewMeta[]`): Every view of the session, oldest first. Empty until loaded.

Source: [ui/src/views/headless/host.ts:180](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L180)

### `ViewStateController`

Interface.

The state of one view.

```ts
interface ViewStateController
```

**Properties**

- `dispose` (`() => void`): Stops a pending ask.
- `get` (`() => ViewStateSnapshot`): Returns the current snapshot.
- `set` (`(name: string, value: JsonValue$1) => void`): Sets one value. A name the view does not declare is ignored.
- `subscribe` (`(onChange: () => void) => () => void`): Calls `onChange` when the snapshot changes. Returns the function that stops it.

Source: [dist/pure-ET4-8JZg.d.ts:19479](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19479)

### `ViewStateOptions`

Interface.

What a controller needs.

```ts
interface ViewStateOptions
```

**Properties**

- `debounceMs?` (`number`): Default [`VIEW_STATE_DEBOUNCE_MS`](https://zidane.si/docs/reference/ui-views-headless.md#VIEW_STATE_DEBOUNCE_MS).
- `run?` (`(state: ViewState) => Promise<ViewStateAnswer>`): Asks the host for the tree of a state. Absent: only the trees drawn ahead.
- `values?` (`Readonly<ViewState>`): The values of the version before (an update or a refresh). The ones
  that still fit the view (`carriedViewState`) are kept, and the
  tree for them is drawn ahead or asked of the host at once.
- `view` (`{ states?: ViewStates; tree: ViewTree }`): The stored view.

Source: [dist/pure-ET4-8JZg.d.ts:19490](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19490)

### `ViewStateSnapshot`

Interface.

What a view with state draws now.

```ts
interface ViewStateSnapshot
```

**Properties**

- `error?` (`ViewStateError`): The last tree could not be had. The old tree stays.
- `live` (`boolean`): The controls can change the view: the host runs states, or it drew them ahead.
- `tree` (`ViewTree`): The tree to draw: the tree of the current state, or the last one while the next loads.
- `values` (`Readonly<ViewState>`): The current values, by name.
- `waiting` (`boolean`): A tree for the current values is on its way.

Source: [dist/pure-ET4-8JZg.d.ts:19466](https://github.com/Tahul/zidane/blob/main/dist/pure-ET4-8JZg.d.ts#L19466)

## Types

### `CustomFrameEvent`

Type.

What a Custom page tells its frame, each message checked: its content
height, a problem, and on real input a link to open, an image for the
lightbox, or a chord for the app's shortcuts.

```ts
type CustomFrameEvent = CustomFrameMessage | McpAppFrameMessage
```

Source: [ui/src/views/headless/host.ts:130](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L130)

### `FrameImage`

Type.

The image of a running page the DOM cannot draw (a desktop `<webview>`, an
iframe), as a data URL, or `null` to show its stored image instead.

```ts
type FrameImage = (frame: HTMLElement) => Promise<string | null>
```

Source: [ui/src/views/headless/capture.ts:31](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/capture.ts#L31)

### `McpAppRequestMethod`

Type.

What an MCP app may ask its own server through its host (`ViewsHost.appRequest`).

```ts
type McpAppRequestMethod = 'tools/call' | 'resources/read' | 'ui/update-model-context'
```

Source: [ui/src/views/headless/host.ts:123](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L123)

### `RasterizeSvg`

Type.

Turns the SVG markup of a capture into a PNG. Replaced in tests.

```ts
type RasterizeSvg = (svg: string, width: number, height: number, scale: number) => Promise<Blob>
```

Source: [ui/src/views/headless/capture.ts:25](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/capture.ts#L25)

### `SessionCustomFrameRequest`

Type.

A Custom frame request of a session view: what a backend gets.

```ts
type SessionCustomFrameRequest = CustomFrameRequest & { ref: SessionViewRef }
```

Source: [ui/src/views/headless/store.ts:58](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/store.ts#L58)

### `StreamedPart`

Type.

One top-level part of a streamed fence.

```ts
type StreamedPart =
  | { kind: 'node'; node: ViewNode | string }
  | { kind: 'pending'; name: string; open: boolean; rows?: number }
```

Source: [ui/src/views/headless/streaming.ts:14](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/streaming.ts#L14)

### `ViewActionOutcome`

Type.

What a view's Action with a tool came to (`ViewsHost.runAction`).

```ts
type ViewActionOutcome = 'approved' | 'denied' | 'missing' | 'pending'
```

Source: [ui/src/views/headless/host.ts:190](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L190)

### `ViewNodeAddress`

Type.

One extension node of a view that `ViewsHost.resolve` asks live data for.

```ts
type ViewNodeAddress = Omit<ViewResolveNode, 'viewId'>
```

Source: [ui/src/views/headless/host.ts:81](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L81)

### `ViewRecordState`

Type.

What the cache knows about one record.

```ts
type ViewRecordState =
  | { status: 'loading' }
  | { status: 'ready'; view: StoredView }
  | { status: 'missing' }
  | { error: ViewsHostError; status: 'failed' }
```

Source: [ui/src/views/headless/records.ts:24](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/records.ts#L24)

### `ViewRef`

Type.

One view: a view of a session, or a saved view (no `version`: the latest).

```ts
type ViewRef =
  | { id: string; kind: 'session'; sessionId: string }
  | { key: string; kind: 'saved'; scope: string; version?: number }
```

Source: [dist/index-CM_SslFj.d.ts:9785](https://github.com/Tahul/zidane/blob/main/dist/index-CM_SslFj.d.ts#L9785)

### `ViewsHostError`

Type.

Why a views call failed, for the UI to word through its labels.

```ts
type ViewsHostError =
  | { code: 'unsupported' }
  | { code: 'invalid'; message: string }
  | { code: 'failed'; message: string }
```

Source: [ui/src/views/headless/host.ts:168](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L168)

### `ViewsLabels`

Type.

The strings of the view components.

```ts
type ViewsLabels = typeof DEFAULT_VIEWS_LABELS
```

Source: [ui/src/views/headless/labels.ts:343](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/labels.ts#L343)

### `ViewsResult`

Type.

What a views call answered.

```ts
type ViewsResult<T> = { ok: true; value: T } | { error: ViewsHostError; ok: false }
```

**Type parameters**

- `T`

Source: [ui/src/views/headless/host.ts:177](https://github.com/Tahul/zidane/blob/main/ui/src/views/headless/host.ts#L177)
