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.
function createViewsPreset(base?: ViewRegistry, options?: ViewsPresetOptions): PresetParameters
| Name | Type | Default | Description |
|---|---|---|---|
| base? | ViewRegistry | The components the model may use. Default: the core components. | |
| options? | ViewsPresetOptions | {} | The host's renderer, when it has one. |
Returns
loadViewHostLiveFunction#
Loads the host side of extension view components (views.get migration, views.resolve) on first need.
function loadViewHostLive(): Promise<__module>Returns
Promise<__module>loadViewStateRunnerFunction#
Loads the host side of view state (views.setState) on first need.
function loadViewStateRunner(): Promise<__module>Returns
Promise<__module>viewSessionFunction#
The view methods of session, over its store's view port.
function viewSession(session: ViewSessionSource | undefined): ViewSession | undefinedParameters
| Name | Type | Description |
|---|---|---|
| session | ViewSessionSource | undefined | Any session (or |
Returns
ViewSession | undefinedConstants#
viewsPresetConstant#
Preset that turns views on (docs/VIEWS.md): the prompt block, describe_view_components, codemode view() and the turn-end fence pass.
const viewsPreset: PresetInterfaces#
SavedViewStorePortInterface#
What a session store offers for saved views. Every member is optional.
interface SavedViewStorePortProperties
| Name | Type | Description |
|---|---|---|
| deleteSavedView? | (scope: string, key: string) => Promise<boolean> | Deletes a saved view and every version. |
| getSavedView? | (scope: string, key: string, version?: number) => Promise<SavedViewRecord | null> | One version of a saved view, migrated; no |
| getSavedViewMeta? | (scope: string, key: string) => Promise<SavedViewMeta | null> | One saved view's meta, or |
| listPanelSavedViews? | (scope: string) => Promise<SavedViewMeta[]> | The panel views of a scope, by key, read without the others. Absent: |
| listPinnedSavedViews? | (scope: string) => Promise<SavedViewMeta[]> | The pinned views of a scope, in pin order, read without the others. Absent: |
| listSavedViews? | (filter?: { scope?: string }) => Promise<SavedViewMeta[]> | The saved views, newest first; with |
| pruneSavedViews? | (keep: number) => Promise<number> | Deletes every saved view's versions but its newest |
| savedViewCreator? | (scope: string, key: string) => Promise<string | null | undefined> | Who saved a saved view first ( |
| 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 |
| 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. |
| setSavedViewPinOrder? | (scope: string, keys: readonly string[]) => Promise<void> | Orders the pinned views of a scope as |
| 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.
|
| setSavedViewTitle? | (scope: string, key: string, title: string) => Promise<SavedViewMeta | null> | Gives a saved view the person's title ( |
ViewHostLiveDepsInterface#
What createViewHostLive reads.
interface ViewHostLiveDepsProperties
| Name | Type | Description |
|---|---|---|
| broadcast | (signal: { components: string[]; kind: 'views:data' }) => void | Sends |
| liveData | () => boolean | Whether |
| store | Pick<ViewStorePort, 'getViews'> | The store that holds the views. |
| viewComponents | (sessionId: string) => Promise<ViewComponentsSource | undefined> | The view components of a session's folder. |
ViewSessionInterface#
A session as the views feature sees it.
interface ViewSessionProperties
| Name | Type | Description |
|---|---|---|
| addView | (view: Omit<StoredView, 'sessionId'>) => Promise<StoredView | undefined> | Store a view under this session's id. |
| canStore | boolean | 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. |
| id | string | The session's id: every view stored through this object is filed under it. |
| listViewMeta | () => Promise<ViewMeta[]> | Every view of the session as |
| nextViewId | () => Promise<string | undefined> | The next free view id ( |
| setViewHeights | (id: string, heights: readonly ViewHeight[]) => Promise<void> | Replaces the stored heights of one view. Does nothing when unsupported. |
ViewsPresetOptionsInterface#
Options of createViewsPreset.
interface ViewsPresetOptionsProperties
| Name | Type | Description |
|---|---|---|
| cache? | ViewSourceCache | The host's source cache ( |
| mcpApps? | boolean | MCP Apps (docs/VIEWS.md, MCP Apps): store the app of an MCP tool that declares one. Hosts pass |
| render? | () => ViewRender | undefined | The host's view renderer. With one, the preset adds |
| save? | { artifacts: boolean; keep?: number | 'all' } | Saved views (docs/VIEWS-SAVED.md): the model can save views. |
| sessionActions? | boolean | Session actions (docs/VIEWS-ORCHESTRATION.md): the prompt names them. Hosts pass it while |
| sessionsSource? | boolean | The sessions source (docs/VIEWS-ORCHESTRATION.md): hosts pass it while |
| sources? | { mcp?: { allowed: readonly string[]; mode: ViewsMcpMode }; network: CustomNetwork } | Live sources (docs/VIEWS-SAVED.md, Sources): the |
ViewStateRunnerDepsInterface#
What createViewStateRunner reads.
interface ViewStateRunnerDepsProperties
| Name | Type | Description |
|---|---|---|
| now? | () => number | The clock of the rate limit. Default |
| registry? | (sessionId: string, view: StoredView) => ViewRegistry | Promise<ViewRegistry> | The registry a view runs against. Default: the core components, plus |
| runner? | ViewRunner | Where the view's code runs. Default: the shared worker pool. |
| store | Pick<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. |
ViewStorePortInterface#
What a session store offers for views. Every member is optional.
interface ViewStorePortProperties
| Name | Type | Description |
|---|---|---|
| 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 |
| nextViewId? | (sessionId: string) => Promise<string> | The next free view id of the session: |
| 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 |
Types#
ViewComponentsSourceType#
The view components of a session's folder: the extension runtime's UI registry.
type ViewComponentsSource = Pick<UiRegistry, 'viewComponents' | 'subscribe'>ViewHostLiveType#
One host's live data and migration.
type ViewHostLive = ReturnType<typeof createViewHostLive>ViewsSessionStoreType#
A session store with the ports of the views feature it may implement beside the core: views and saved views.
type ViewsSessionStore = SessionStore & ViewStorePort & SavedViewStorePortViewStateRunnerType#
One host's views.setState.
type ViewStateRunner = ReturnType<typeof createViewStateRunner>