@xemahq/ui-kernel 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/biome-host/biome-registry.d.ts.map +1 -1
- package/dist/lib/biome-host/biome-registry.js +14 -9
- package/dist/lib/biome-host/biome-registry.js.map +1 -1
- package/dist/lib/contribution-registry/contribution-registry.d.ts +24 -0
- package/dist/lib/contribution-registry/contribution-registry.d.ts.map +1 -0
- package/dist/lib/contribution-registry/contribution-registry.js +67 -0
- package/dist/lib/contribution-registry/contribution-registry.js.map +1 -0
- package/dist/lib/contribution-registry/index.d.ts +3 -0
- package/dist/lib/contribution-registry/index.d.ts.map +1 -0
- package/dist/lib/contribution-registry/index.js +3 -0
- package/dist/lib/contribution-registry/index.js.map +1 -0
- package/dist/lib/contribution-registry/renderable-registry.d.ts +33 -0
- package/dist/lib/contribution-registry/renderable-registry.d.ts.map +1 -0
- package/dist/lib/contribution-registry/renderable-registry.js +51 -0
- package/dist/lib/contribution-registry/renderable-registry.js.map +1 -0
- package/dist/ui/capture/field-spec-to-zod.d.ts +1 -0
- package/dist/ui/capture/field-spec-to-zod.d.ts.map +1 -1
- package/dist/ui/capture/field-spec-to-zod.js +19 -0
- package/dist/ui/capture/field-spec-to-zod.js.map +1 -1
- package/dist/ui/capture/field-spec-validate.d.ts +4 -0
- package/dist/ui/capture/field-spec-validate.d.ts.map +1 -0
- package/dist/ui/capture/field-spec-validate.js +129 -0
- package/dist/ui/capture/field-spec-validate.js.map +1 -0
- package/dist/ui/capture/field-spec.d.ts +13 -1
- package/dist/ui/capture/field-spec.d.ts.map +1 -1
- package/dist/ui/capture/field-spec.js +25 -0
- package/dist/ui/capture/field-spec.js.map +1 -1
- package/dist/ui/capture/index.d.ts +4 -2
- package/dist/ui/capture/index.d.ts.map +1 -1
- package/dist/ui/capture/index.js +4 -2
- package/dist/ui/capture/index.js.map +1 -1
- package/dist/ui/capture/schema-field-input.d.ts.map +1 -1
- package/dist/ui/capture/schema-field-input.js +39 -12
- package/dist/ui/capture/schema-field-input.js.map +1 -1
- package/dist/ui/capture/submit-values.d.ts +6 -0
- package/dist/ui/capture/submit-values.d.ts.map +1 -0
- package/dist/ui/capture/submit-values.js +28 -0
- package/dist/ui/capture/submit-values.js.map +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/primitives/overflow-tabs.d.ts +5 -0
- package/dist/ui/primitives/overflow-tabs.d.ts.map +1 -1
- package/dist/ui/primitives/overflow-tabs.js +4 -4
- package/dist/ui/primitives/overflow-tabs.js.map +1 -1
- package/dist/ui/primitives/url-preview-chrome.d.ts +8 -0
- package/dist/ui/primitives/url-preview-chrome.d.ts.map +1 -0
- package/dist/ui/primitives/url-preview-chrome.js +40 -0
- package/dist/ui/primitives/url-preview-chrome.js.map +1 -0
- package/dist/vista/GenericCatalogueSurface.d.ts +10 -0
- package/dist/vista/GenericCatalogueSurface.d.ts.map +1 -0
- package/dist/vista/GenericCatalogueSurface.js +80 -0
- package/dist/vista/GenericCatalogueSurface.js.map +1 -0
- package/dist/vista/SurfaceFallbackCard.d.ts +9 -0
- package/dist/vista/SurfaceFallbackCard.d.ts.map +1 -0
- package/dist/vista/SurfaceFallbackCard.js +44 -0
- package/dist/vista/SurfaceFallbackCard.js.map +1 -0
- package/dist/vista/VistaPanel.d.ts +21 -0
- package/dist/vista/VistaPanel.d.ts.map +1 -0
- package/dist/vista/VistaPanel.js +31 -0
- package/dist/vista/VistaPanel.js.map +1 -0
- package/dist/vista/html/CustomUiFrame.d.ts +20 -0
- package/dist/vista/html/CustomUiFrame.d.ts.map +1 -0
- package/dist/vista/html/CustomUiFrame.js +69 -0
- package/dist/vista/html/CustomUiFrame.js.map +1 -0
- package/dist/vista/html/custom-ui-frame-bridge.d.ts +13 -0
- package/dist/vista/html/custom-ui-frame-bridge.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-frame-bridge.js +30 -0
- package/dist/vista/html/custom-ui-frame-bridge.js.map +1 -0
- package/dist/vista/html/custom-ui-frame-contract.d.ts +29 -0
- package/dist/vista/html/custom-ui-frame-contract.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-frame-contract.js +16 -0
- package/dist/vista/html/custom-ui-frame-contract.js.map +1 -0
- package/dist/vista/html/custom-ui-intents.d.ts +20 -0
- package/dist/vista/html/custom-ui-intents.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-intents.js +57 -0
- package/dist/vista/html/custom-ui-intents.js.map +1 -0
- package/dist/vista/html/custom-ui-srcdoc.d.ts +17 -0
- package/dist/vista/html/custom-ui-srcdoc.d.ts.map +1 -0
- package/dist/vista/html/custom-ui-srcdoc.js +70 -0
- package/dist/vista/html/custom-ui-srcdoc.js.map +1 -0
- package/dist/vista/html/index.d.ts +6 -0
- package/dist/vista/html/index.d.ts.map +1 -0
- package/dist/vista/html/index.js +6 -0
- package/dist/vista/html/index.js.map +1 -0
- package/dist/vista/index.d.ts +18 -0
- package/dist/vista/index.d.ts.map +1 -0
- package/dist/vista/index.js +18 -0
- package/dist/vista/index.js.map +1 -0
- package/dist/vista/surface-catalogue.d.ts +5 -0
- package/dist/vista/surface-catalogue.d.ts.map +1 -0
- package/dist/vista/surface-catalogue.js +30 -0
- package/dist/vista/surface-catalogue.js.map +1 -0
- package/dist/vista/surface-icons.d.ts +7 -0
- package/dist/vista/surface-icons.d.ts.map +1 -0
- package/dist/vista/surface-icons.js +26 -0
- package/dist/vista/surface-icons.js.map +1 -0
- package/dist/vista/surface-registry.d.ts +7 -0
- package/dist/vista/surface-registry.d.ts.map +1 -0
- package/dist/vista/surface-registry.js +7 -0
- package/dist/vista/surface-registry.js.map +1 -0
- package/dist/vista/surfaces/ChartSurface.d.ts +4 -0
- package/dist/vista/surfaces/ChartSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/ChartSurface.js +17 -0
- package/dist/vista/surfaces/ChartSurface.js.map +1 -0
- package/dist/vista/surfaces/FilesSurface.d.ts +15 -0
- package/dist/vista/surfaces/FilesSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/FilesSurface.js +121 -0
- package/dist/vista/surfaces/FilesSurface.js.map +1 -0
- package/dist/vista/surfaces/FormSurface.d.ts +4 -0
- package/dist/vista/surfaces/FormSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/FormSurface.js +97 -0
- package/dist/vista/surfaces/FormSurface.js.map +1 -0
- package/dist/vista/surfaces/HtmlSurface.d.ts +4 -0
- package/dist/vista/surfaces/HtmlSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/HtmlSurface.js +11 -0
- package/dist/vista/surfaces/HtmlSurface.js.map +1 -0
- package/dist/vista/surfaces/TableSurface.d.ts +4 -0
- package/dist/vista/surfaces/TableSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/TableSurface.js +42 -0
- package/dist/vista/surfaces/TableSurface.js.map +1 -0
- package/dist/vista/surfaces/UrlSurface.d.ts +4 -0
- package/dist/vista/surfaces/UrlSurface.d.ts.map +1 -0
- package/dist/vista/surfaces/UrlSurface.js +7 -0
- package/dist/vista/surfaces/UrlSurface.js.map +1 -0
- package/dist/vista/surfaces/blob-surfaces.d.ts +6 -0
- package/dist/vista/surfaces/blob-surfaces.d.ts.map +1 -0
- package/dist/vista/surfaces/blob-surfaces.js +38 -0
- package/dist/vista/surfaces/blob-surfaces.js.map +1 -0
- package/dist/vista/surfaces/elicitation-transport.d.ts +18 -0
- package/dist/vista/surfaces/elicitation-transport.d.ts.map +1 -0
- package/dist/vista/surfaces/elicitation-transport.js +100 -0
- package/dist/vista/surfaces/elicitation-transport.js.map +1 -0
- package/dist/vista/surfaces/index.d.ts +11 -0
- package/dist/vista/surfaces/index.d.ts.map +1 -0
- package/dist/vista/surfaces/index.js +89 -0
- package/dist/vista/surfaces/index.js.map +1 -0
- package/dist/vista/surfaces/text-surfaces.d.ts +8 -0
- package/dist/vista/surfaces/text-surfaces.d.ts.map +1 -0
- package/dist/vista/surfaces/text-surfaces.js +54 -0
- package/dist/vista/surfaces/text-surfaces.js.map +1 -0
- package/dist/vista/use-vista-tabs.d.ts +30 -0
- package/dist/vista/use-vista-tabs.d.ts.map +1 -0
- package/dist/vista/use-vista-tabs.js +77 -0
- package/dist/vista/use-vista-tabs.js.map +1 -0
- package/dist/vista/vista-code-renderer.d.ts +12 -0
- package/dist/vista/vista-code-renderer.d.ts.map +1 -0
- package/dist/vista/vista-code-renderer.js +10 -0
- package/dist/vista/vista-code-renderer.js.map +1 -0
- package/dist/vista/vista-file-source.d.ts +20 -0
- package/dist/vista/vista-file-source.d.ts.map +1 -0
- package/dist/vista/vista-file-source.js +69 -0
- package/dist/vista/vista-file-source.js.map +1 -0
- package/dist/vista/vista-form-host.d.ts +16 -0
- package/dist/vista/vista-form-host.d.ts.map +1 -0
- package/dist/vista/vista-form-host.js +10 -0
- package/dist/vista/vista-form-host.js.map +1 -0
- package/dist/vista/vista-model.d.ts +12 -0
- package/dist/vista/vista-model.d.ts.map +1 -0
- package/dist/vista/vista-model.js +72 -0
- package/dist/vista/vista-model.js.map +1 -0
- package/dist/vista/vista-open-context.d.ts +9 -0
- package/dist/vista/vista-open-context.d.ts.map +1 -0
- package/dist/vista/vista-open-context.js +10 -0
- package/dist/vista/vista-open-context.js.map +1 -0
- package/dist/vista/vista-payloads.d.ts +107 -0
- package/dist/vista/vista-payloads.d.ts.map +1 -0
- package/dist/vista/vista-payloads.js +305 -0
- package/dist/vista/vista-payloads.js.map +1 -0
- package/dist/vista/vista-tabs-manifest.d.ts +17 -0
- package/dist/vista/vista-tabs-manifest.d.ts.map +1 -0
- package/dist/vista/vista-tabs-manifest.js +60 -0
- package/dist/vista/vista-tabs-manifest.js.map +1 -0
- package/dist/vista/vista-tools.d.ts +41 -0
- package/dist/vista/vista-tools.d.ts.map +1 -0
- package/dist/vista/vista-tools.js +113 -0
- package/dist/vista/vista-tools.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +5 -0
- package/src/lib/biome-host/biome-registry.ts +31 -11
- package/src/lib/contribution-registry/contribution-registry.spec.ts +141 -0
- package/src/lib/contribution-registry/contribution-registry.ts +202 -0
- package/src/lib/contribution-registry/index.ts +9 -0
- package/src/lib/contribution-registry/renderable-registry.ts +142 -0
- package/src/ui/capture/field-spec-to-zod.ts +22 -0
- package/src/ui/capture/field-spec-validate.ts +147 -0
- package/src/ui/capture/field-spec.ts +62 -0
- package/src/ui/capture/index.ts +9 -1
- package/src/ui/capture/schema-field-input.tsx +134 -14
- package/src/ui/capture/submit-values.test.ts +70 -0
- package/src/ui/capture/submit-values.ts +63 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/primitives/overflow-tabs.tsx +24 -4
- package/src/ui/primitives/url-preview-chrome.tsx +102 -0
- package/src/vista/GenericCatalogueSurface.tsx +177 -0
- package/src/vista/SurfaceFallbackCard.tsx +109 -0
- package/src/vista/VistaPanel.tsx +155 -0
- package/src/vista/form-payload.spec.ts +93 -0
- package/src/vista/html/CustomUiFrame.spec.tsx +125 -0
- package/src/vista/html/CustomUiFrame.tsx +204 -0
- package/src/vista/html/custom-ui-frame-bridge.spec.ts +191 -0
- package/src/vista/html/custom-ui-frame-bridge.ts +92 -0
- package/src/vista/html/custom-ui-frame-contract.ts +88 -0
- package/src/vista/html/custom-ui-intents.spec.ts +133 -0
- package/src/vista/html/custom-ui-intents.ts +151 -0
- package/src/vista/html/custom-ui-srcdoc.spec.ts +151 -0
- package/src/vista/html/custom-ui-srcdoc.ts +193 -0
- package/src/vista/html/index.ts +13 -0
- package/src/vista/index.ts +48 -0
- package/src/vista/surface-catalogue.spec.ts +140 -0
- package/src/vista/surface-catalogue.ts +84 -0
- package/src/vista/surface-icons.ts +57 -0
- package/src/vista/surface-registry.ts +56 -0
- package/src/vista/surfaces/ChartSurface.tsx +34 -0
- package/src/vista/surfaces/FilesSurface.tsx +268 -0
- package/src/vista/surfaces/FormSurface.tsx +264 -0
- package/src/vista/surfaces/HtmlSurface.tsx +43 -0
- package/src/vista/surfaces/TableSurface.tsx +99 -0
- package/src/vista/surfaces/UrlSurface.tsx +40 -0
- package/src/vista/surfaces/blob-surfaces.tsx +129 -0
- package/src/vista/surfaces/elicitation-transport.spec.ts +187 -0
- package/src/vista/surfaces/elicitation-transport.ts +175 -0
- package/src/vista/surfaces/index.tsx +157 -0
- package/src/vista/surfaces/text-surfaces.tsx +119 -0
- package/src/vista/use-vista-tabs.ts +188 -0
- package/src/vista/vista-code-renderer.tsx +46 -0
- package/src/vista/vista-file-source.tsx +163 -0
- package/src/vista/vista-form-host.tsx +78 -0
- package/src/vista/vista-model.ts +130 -0
- package/src/vista/vista-open-context.tsx +42 -0
- package/src/vista/vista-payloads.ts +514 -0
- package/src/vista/vista-tabs-manifest.ts +123 -0
- package/src/vista/vista-tools.ts +220 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent-facing Vista tool contract — `vista_open` / `vista_update` /
|
|
3
|
+
* `vista_close` / `vista_list` (Canopy §8.2).
|
|
4
|
+
*
|
|
5
|
+
* This module is the BROWSER-side definition of those four calls: their names,
|
|
6
|
+
* their argument shapes, their result shapes, and the dispatcher that performs
|
|
7
|
+
* them against a {@link VistaTabsController}.
|
|
8
|
+
*
|
|
9
|
+
* ── One wire contract, two projections ──────────────────────────────────────
|
|
10
|
+
* The server half lives in `canopy-api`'s `vista/vista-tool.contract.ts`. The
|
|
11
|
+
* two files are VALUE-IDENTICAL by construction — same tool names, same
|
|
12
|
+
* argument shapes, same {@link VistaToolError} members, same result envelope —
|
|
13
|
+
* and both derive the `vista_open` argument from the kernel's
|
|
14
|
+
* `VistaSurfaceSchema`, which is the single structural source of truth. They
|
|
15
|
+
* are two projections rather than one import because this package is a React
|
|
16
|
+
* UI package (a NestJS service must not depend on it) and the kernel contracts
|
|
17
|
+
* package does not yet carry the three tiny argument schemas. Consolidating
|
|
18
|
+
* them into `@xemahq/kernel-contracts/surface` is the correct end state; until
|
|
19
|
+
* then, a change to either file MUST be mirrored in the other in the same
|
|
20
|
+
* change-set, exactly like the curated `ConnectorKind` parity rule.
|
|
21
|
+
*
|
|
22
|
+
* ── How a call gets here ────────────────────────────────────────────────────
|
|
23
|
+
* Vista is a BROWSER surface: no server can render a tab. So the backend never
|
|
24
|
+
* "performs" these tools — it VALIDATES, applies its own tab projection,
|
|
25
|
+
* RELAYS the call to the browser over the EXISTING agent-session realtime
|
|
26
|
+
* channel, and returns the browser's {@link VistaToolResult} to the model
|
|
27
|
+
* verbatim. A session where no panel answers returns
|
|
28
|
+
* `{ ok: false, error: 'no-panel' }` — an explicit refusal, never a silent
|
|
29
|
+
* success.
|
|
30
|
+
*
|
|
31
|
+
* The host binds `dispatchVistaTool` to its panel's controller and feeds it the
|
|
32
|
+
* relayed `{ tool, args }`; see the host's `use-vista-tool-bridge`.
|
|
33
|
+
*/
|
|
34
|
+
import { VistaSurfaceSchema } from '@xemahq/kernel-contracts/surface';
|
|
35
|
+
import { z } from 'zod';
|
|
36
|
+
|
|
37
|
+
import type { VistaSurfacePatch, VistaTabsController } from './use-vista-tabs';
|
|
38
|
+
|
|
39
|
+
/** The closed set of Vista tools. Values are the wire tool names. */
|
|
40
|
+
export enum VistaToolName {
|
|
41
|
+
Open = 'vista_open',
|
|
42
|
+
Update = 'vista_update',
|
|
43
|
+
Close = 'vista_close',
|
|
44
|
+
List = 'vista_list',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `vista_open(surface) -> { tabId }`.
|
|
49
|
+
*
|
|
50
|
+
* The argument IS the kernel tab envelope — not a wrapper around it — so the
|
|
51
|
+
* JSON Schema the model is shown is exactly `VistaSurface`. `kind` is an open
|
|
52
|
+
* string on purpose: an unrecognised kind is NOT an error, it opens a tab that
|
|
53
|
+
* renders the fallback card.
|
|
54
|
+
*/
|
|
55
|
+
export const VistaOpenArgsSchema = VistaSurfaceSchema;
|
|
56
|
+
export type VistaOpenArgs = z.infer<typeof VistaOpenArgsSchema>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `vista_update(tabId, …) -> { updated: true }`.
|
|
60
|
+
*
|
|
61
|
+
* Flat, and deliberately narrower than {@link VistaSurfacePatch}: `kind` and
|
|
62
|
+
* `version` are NOT patchable, because the browser has already resolved a
|
|
63
|
+
* renderer for the live tab and swapping the kind under it would strand that
|
|
64
|
+
* renderer. Close and re-open instead. Every remaining field is optional; an
|
|
65
|
+
* empty patch is a no-op, not an error.
|
|
66
|
+
*/
|
|
67
|
+
export const VistaUpdateArgsSchema = z.object({
|
|
68
|
+
tabId: z.string().min(1),
|
|
69
|
+
title: z.string().min(1).optional(),
|
|
70
|
+
payload: z.unknown().optional(),
|
|
71
|
+
pinned: z.boolean().optional(),
|
|
72
|
+
});
|
|
73
|
+
export type VistaUpdateArgs = z.infer<typeof VistaUpdateArgsSchema>;
|
|
74
|
+
|
|
75
|
+
/** `vista_close(tabId) -> { closed: true }`. A pinned tab refuses to close. */
|
|
76
|
+
export const VistaCloseArgsSchema = z.object({ tabId: z.string().min(1) });
|
|
77
|
+
export type VistaCloseArgs = z.infer<typeof VistaCloseArgsSchema>;
|
|
78
|
+
|
|
79
|
+
/** `vista_list() -> { tabs }`. No arguments. */
|
|
80
|
+
export const VistaListArgsSchema = z.object({});
|
|
81
|
+
export type VistaListArgs = z.infer<typeof VistaListArgsSchema>;
|
|
82
|
+
|
|
83
|
+
/** Why a Vista tool call could not be performed. Closed set. */
|
|
84
|
+
export enum VistaToolError {
|
|
85
|
+
/** No Vista panel answered the relay — nothing is on screen to drive. */
|
|
86
|
+
NoPanel = 'no-panel',
|
|
87
|
+
/** The arguments failed schema validation at a wire boundary. */
|
|
88
|
+
InvalidArgs = 'invalid-args',
|
|
89
|
+
/** The tool name is not a member of {@link VistaToolName}. */
|
|
90
|
+
UnknownTool = 'unknown-tool',
|
|
91
|
+
/** `tabId` names a tab that is not open. */
|
|
92
|
+
UnknownTab = 'unknown-tab',
|
|
93
|
+
/**
|
|
94
|
+
* The tab exists but refuses the operation — it is pinned (close), or it is
|
|
95
|
+
* a HOST tab whose content the host's own data flow owns (update). `detail`
|
|
96
|
+
* names which.
|
|
97
|
+
*/
|
|
98
|
+
TabRefused = 'tab-refused',
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The result envelope every Vista tool returns. */
|
|
102
|
+
export type VistaToolResult<TValue = unknown> =
|
|
103
|
+
| { readonly ok: true; readonly value: TValue }
|
|
104
|
+
| {
|
|
105
|
+
readonly ok: false;
|
|
106
|
+
readonly error: VistaToolError;
|
|
107
|
+
readonly detail?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Wire validator for {@link VistaToolResult}. The browser's answer crosses back
|
|
112
|
+
* into the server and then into the model's context, so the server validates
|
|
113
|
+
* the ENVELOPE with this shape before relaying it on — a browser cannot inject
|
|
114
|
+
* an arbitrary object where a typed result is expected.
|
|
115
|
+
*/
|
|
116
|
+
export const VistaToolResultSchema: z.ZodType<VistaToolResult> = z.union([
|
|
117
|
+
z.object({ ok: z.literal(true), value: z.unknown() }),
|
|
118
|
+
z.object({
|
|
119
|
+
ok: z.literal(false),
|
|
120
|
+
error: z.nativeEnum(VistaToolError),
|
|
121
|
+
detail: z.string().optional(),
|
|
122
|
+
}),
|
|
123
|
+
]) as z.ZodType<VistaToolResult>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Perform a relayed Vista tool call against a mounted panel's controller.
|
|
127
|
+
*
|
|
128
|
+
* Fail-fast on bad input: arguments are re-validated here (the frontend never
|
|
129
|
+
* trusts that the backend validated), and a violation returns
|
|
130
|
+
* {@link VistaToolError.InvalidArgs} naming the offending path rather than a
|
|
131
|
+
* partially-applied change. Pass `controller: null` for a document with no
|
|
132
|
+
* mounted panel — that returns {@link VistaToolError.NoPanel}.
|
|
133
|
+
*/
|
|
134
|
+
export function dispatchVistaTool(
|
|
135
|
+
controller: VistaTabsController | null,
|
|
136
|
+
tool: string,
|
|
137
|
+
args: unknown,
|
|
138
|
+
): VistaToolResult {
|
|
139
|
+
if (controller === null) {
|
|
140
|
+
return { ok: false, error: VistaToolError.NoPanel };
|
|
141
|
+
}
|
|
142
|
+
switch (tool) {
|
|
143
|
+
case VistaToolName.Open: {
|
|
144
|
+
const parsed = VistaOpenArgsSchema.safeParse(args);
|
|
145
|
+
if (!parsed.success) return invalid(parsed.error);
|
|
146
|
+
return { ok: true, value: { tabId: controller.open(parsed.data) } };
|
|
147
|
+
}
|
|
148
|
+
case VistaToolName.Update: {
|
|
149
|
+
const parsed = VistaUpdateArgsSchema.safeParse(args);
|
|
150
|
+
if (!parsed.success) return invalid(parsed.error);
|
|
151
|
+
const { tabId, ...patch } = parsed.data;
|
|
152
|
+
const refusal = refusalFor(controller, tabId);
|
|
153
|
+
if (refusal !== null) return refusal;
|
|
154
|
+
if (!controller.update(tabId, patch as VistaSurfacePatch)) {
|
|
155
|
+
// The tab is listed but not opened-tab-owned: it is a HOST tab, and a
|
|
156
|
+
// patch to it would be overwritten by the host's next reconcile.
|
|
157
|
+
return {
|
|
158
|
+
ok: false,
|
|
159
|
+
error: VistaToolError.TabRefused,
|
|
160
|
+
detail: `Tab "${tabId}" is host-owned; its content is driven by the host, not by vista_update.`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, value: { updated: true } };
|
|
164
|
+
}
|
|
165
|
+
case VistaToolName.Close: {
|
|
166
|
+
const parsed = VistaCloseArgsSchema.safeParse(args);
|
|
167
|
+
if (!parsed.success) return invalid(parsed.error);
|
|
168
|
+
const { tabId } = parsed.data;
|
|
169
|
+
const refusal = refusalFor(controller, tabId);
|
|
170
|
+
if (refusal !== null) return refusal;
|
|
171
|
+
if (!controller.close(tabId)) {
|
|
172
|
+
return {
|
|
173
|
+
ok: false,
|
|
174
|
+
error: VistaToolError.TabRefused,
|
|
175
|
+
detail: `Tab "${tabId}" is pinned and cannot be closed.`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return { ok: true, value: { closed: true } };
|
|
179
|
+
}
|
|
180
|
+
case VistaToolName.List: {
|
|
181
|
+
const parsed = VistaListArgsSchema.safeParse(args ?? {});
|
|
182
|
+
if (!parsed.success) return invalid(parsed.error);
|
|
183
|
+
return { ok: true, value: { tabs: controller.list() } };
|
|
184
|
+
}
|
|
185
|
+
default:
|
|
186
|
+
return {
|
|
187
|
+
ok: false,
|
|
188
|
+
error: VistaToolError.UnknownTool,
|
|
189
|
+
detail: `'${tool}' is not a Vista tool.`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* `unknown-tab` when the panel does not hold `tabId` at all. Returning `null`
|
|
196
|
+
* means the tab exists and the operation may proceed.
|
|
197
|
+
*/
|
|
198
|
+
function refusalFor(
|
|
199
|
+
controller: VistaTabsController,
|
|
200
|
+
tabId: string,
|
|
201
|
+
): VistaToolResult | null {
|
|
202
|
+
if (controller.list().some((tab) => tab.tabId === tabId)) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
ok: false,
|
|
207
|
+
error: VistaToolError.UnknownTab,
|
|
208
|
+
detail: `No tab "${tabId}" is open.`,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function invalid(error: z.ZodError): VistaToolResult {
|
|
213
|
+
return {
|
|
214
|
+
ok: false,
|
|
215
|
+
error: VistaToolError.InvalidArgs,
|
|
216
|
+
detail: error.issues
|
|
217
|
+
.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`)
|
|
218
|
+
.join('; '),
|
|
219
|
+
};
|
|
220
|
+
}
|