Skip to content

zidane/views

The views preset and the host side of views. Needs zod.

import { … } from 'zidane/views'src/views/index.ts

Functions#

createViewsPresetFunction#

zidane/views (docs/VIEWS.md): the views preset, its builder, and the host side of live data and view state.

Its own entry, so zidane and zidane/presets never load the view registry: it needs zod, an optional peer dependency. Import this entry only when you turn views on, and install zod with it.

TypeScript
function createViewsPreset(base?: ViewRegistry, options?: ViewsPresetOptions): Preset
Parameters
NameTypeDefaultDescription
base?ViewRegistry

The components the model may use. Default: the core components.

options?ViewsPresetOptions{}

The host's renderer, when it has one.

src/views/preset.ts:224

loadViewHostLiveFunction#

Loads the host side of extension view components (views.get migration, views.resolve) on first need.

TypeScript
function loadViewHostLive(): Promise<__module>
Promise<__module>

src/views/index.ts:19

loadViewStateRunnerFunction#

Loads the host side of view state (views.setState) on first need.

TypeScript
function loadViewStateRunner(): Promise<__module>
Promise<__module>

src/views/index.ts:22

viewSessionFunction#

The view methods of session, over its store's view port.

TypeScript
function viewSession(session: ViewSessionSource | undefined): ViewSession | undefined
Parameters
NameTypeDescription
sessionViewSessionSource | undefined

Any session (or undefined for a sessionless run).

ViewSession | undefined

src/views/session.ts:40

Constants#

viewsPresetConstant#

Preset that turns views on (docs/VIEWS.md): the prompt block, describe_view_components, codemode view() and the turn-end fence pass.

TypeScript
const viewsPreset: Preset

src/views/preset.ts:249

Interfaces#

SavedViewStorePortInterface#

What a session store offers for saved views. Every member is optional.

TypeScript
interface SavedViewStorePort
SavedViewStorePort properties
NameTypeDescription
deleteSavedView?(scope: string, key: string) => Promise<boolean>

Deletes a saved view and every version. false when there was none.

getSavedView?(scope: string, key: string, version?: number) => Promise<SavedViewRecord | null>

One version of a saved view, migrated; no version: the latest. null when there is none.

getSavedViewMeta?(scope: string, key: string) => Promise<SavedViewMeta | null>

One saved view's meta, or null. Absent: readSavedViewMeta finds it in listSavedViews.

listPanelSavedViews?(scope: string) => Promise<SavedViewMeta[]>

The panel views of a scope, by key, read without the others. Absent: readPanelSavedViews filters listSavedViews.

listPinnedSavedViews?(scope: string) => Promise<SavedViewMeta[]>

The pinned views of a scope, in pin order, read without the others. Absent: readPinnedSavedViews filters listSavedViews.

listSavedViews?(filter?: { scope?: string }) => Promise<SavedViewMeta[]>

The saved views, newest first; with scope, of that scope only.

pruneSavedViews?(keep: number) => Promise<number>

Deletes every saved view's versions but its newest keep. Resolves to how many versions went.

savedViewCreator?(scope: string, key: string) => Promise<string | null | undefined>

Who saved a saved view first (created_by): a user id, null when none was recorded, undefined when there is no such view.

savedViewVersions?(scope: string, key: string) => Promise<SavedViewVersion[]>

The kept versions of a saved view, oldest first.

saveView?(input: SaveViewInput) => Promise<SavedViewRecord>

Saves a new version (the next number) and keeps the newest input.keep (default 20).

setSavedViewHeights?(scope: string, key: string, version: number, heights: readonly ViewHeight[]) => Promise<void>

Replaces the stored heights of one version. Unknown versions do nothing.

setSavedViewPinned?(scope: string, key: string, pinned: boolean) => Promise<boolean>

Pins (last) or unpins a saved view. false when there is none.

setSavedViewPinOrder?(scope: string, keys: readonly string[]) => Promise<void>

Orders the pinned views of a scope as keys lists them; the others keep their order after them.

setSavedViewRecordView?(scope: string, key: string, version: number, view: ViewRecord) => Promise<void>

Replaces the view of one version in place (a source fetch that changed no data). Unknown versions do nothing.

setSavedViewSurface?(scope: string, key: string, into: SavedViewSurface) => Promise<boolean>

Turns a saved view into a side panel (unpinned) or back into a home block (pinned, last), in one write. false when there is none.

setSavedViewTitle?(scope: string, key: string, title: string) => Promise<SavedViewMeta | null>

Gives a saved view the person's title (titleSetByUser), kept by later saves; "" gives back the latest version's title. No new version. null when there is none; throws for a title savedViewTitleOf refuses.

src/views/saved.ts:295

ViewHostLiveDepsInterface#

What createViewHostLive reads.

TypeScript
interface ViewHostLiveDeps
ViewHostLiveDeps properties
NameTypeDescription
broadcast(signal: { components: string[]; kind: 'views:data' }) => void

Sends views:data to every client.

liveData() => boolean

Whether views and viewsLiveData are on.

storePick<ViewStorePort, 'getViews'>

The store that holds the views.

viewComponents(sessionId: string) => Promise<ViewComponentsSource | undefined>

The view components of a session's folder.

src/views/host-live.ts:38

ViewSessionInterface#

A session as the views feature sees it.

TypeScript
interface ViewSession
ViewSession properties
NameTypeDescription
addView(view: Omit<StoredView, 'sessionId'>) => Promise<StoredView | undefined>

Store a view under this session's id. undefined when the store keeps no views.

canStoreboolean

Whether the session's store keeps views.

getViews(ids: readonly string[]) => Promise<StoredView[]>

The stored views with these ids, in the order asked. Empty when unsupported.

idstring

The session's id: every view stored through this object is filed under it.

listViewMeta() => Promise<ViewMeta[]>

Every view of the session as ViewMeta, oldest first. Empty when unsupported.

nextViewId() => Promise<string | undefined>

The next free view id (v1, v2, …), never reused. undefined when unsupported.

setViewHeights(id: string, heights: readonly ViewHeight[]) => Promise<void>

Replaces the stored heights of one view. Does nothing when unsupported.

src/views/session.ts:12

ViewsPresetOptionsInterface#

Options of createViewsPreset.

TypeScript
interface ViewsPresetOptions
ViewsPresetOptions properties
NameTypeDescription
cache?ViewSourceCache

The host's source cache (ViewHost.cache): with URL, MCP or sessions sources on, every source of this agent's views is fetched through it, with the host's fetchers. Absent: each fetch has its own, with the URL fetcher alone.

mcpApps?boolean

MCP Apps (docs/VIEWS.md, MCP Apps): store the app of an MCP tool that declares one. Hosts pass viewsCustomCode and viewsMcpApps.

render?() => ViewRender | undefined

The host's view renderer. With one, the preset adds view_preview and the repair pass gets a screenshot of a view with problems.

save?{ artifacts: boolean; keep?: number | 'all' }

Saved views (docs/VIEWS-SAVED.md): the model can save views. artifacts: a save records a view artifact. keep: the versions each saved view keeps (viewsVersionsKept). Hosts pass it while viewsSave is on.

sessionActions?boolean

Session actions (docs/VIEWS-ORCHESTRATION.md): the prompt names them. Hosts pass it while viewsOrchestration is draft, approve or trusted, with a registry that shows the session props.

sessionsSource?boolean

The sessions source (docs/VIEWS-ORCHESTRATION.md): hosts pass it while viewsOrchestration is not off. Absent, the prompt and the catalog are as before.

sources?{ mcp?: { allowed: readonly string[]; mode: ViewsMcpMode }; network: CustomNetwork }

Live sources (docs/VIEWS-SAVED.md, Sources): the viewsNetwork they follow, and viewsMcp with viewsMcpAllowed for MCP sources. Absent, blocked and MCP off: every source is off and the prompt is as before.

src/views/preset.ts:187

ViewStateRunnerDepsInterface#

What createViewStateRunner reads.

TypeScript
interface ViewStateRunnerDeps
ViewStateRunnerDeps properties
NameTypeDescription
now?() => number

The clock of the rate limit. Default Date.now.

registry?(sessionId: string, view: StoredView) => ViewRegistry | Promise<ViewRegistry>

The registry a view runs against. Default: the core components, plus ViewStateRunnerDeps.viewComponents for a view that names one.

runner?ViewRunner

Where the view's code runs. Default: the shared worker pool.

storePick<ViewStorePort, 'getViews'>

Where the stored views are read.

viewComponents?(sessionId: string) => Promise<ViewComponentsSource | undefined>

The view components of a session's folder. A view that names one runs against them too.

src/views/state-run.ts:148

ViewStorePortInterface#

What a session store offers for views. Every member is optional.

TypeScript
interface ViewStorePort
ViewStorePort properties
NameTypeDescription
getViews?(sessionId: string, ids: readonly string[]) => Promise<StoredView[]>

The full records of these ids, in the order asked. Unknown ids are left out.

listViewMeta?(sessionId: string) => Promise<ViewMeta[]>

Every view of the session, as ViewMeta, oldest first.

nextViewId?(sessionId: string) => Promise<string>

The next free view id of the session: v1, v2, … Never reused.

setViewHeights?(sessionId: string, id: string, heights: readonly ViewHeight[]) => Promise<void>

Replaces the stored heights of one view. Unknown ids do nothing.

upsertView?(view: StoredView) => Promise<StoredView | null>

Inserts or replaces the view (sessionId, id). Resolves null for an unknown session.

src/views/store-types.ts:58

Types#

ViewComponentsSourceType#

The view components of a session's folder: the extension runtime's UI registry.

TypeScript
type ViewComponentsSource = Pick<UiRegistry, 'viewComponents' | 'subscribe'>

src/views/host-live.ts:26

ViewHostLiveType#

One host's live data and migration.

TypeScript
type ViewHostLive = ReturnType<typeof createViewHostLive>

src/views/host-live.ts:138

ViewsSessionStoreType#

A session store with the ports of the views feature it may implement beside the core: views and saved views.

TypeScript
type ViewsSessionStore = SessionStore & ViewStorePort & SavedViewStorePort

src/views/store-types.ts:72

ViewStateRunnerType#

One host's views.setState.

TypeScript
type ViewStateRunner = ReturnType<typeof createViewStateRunner>

src/views/state-run.ts:237