@webskill/sdk 0.2.6 → 0.2.8

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.
@@ -0,0 +1,597 @@
1
+ import { D as UiSurfaceSnapshot, P as JsonSchema, _ as RenderResultRequest, b as UiSurfaceAction, g as RenderBlock, o as InteractionRequest, r as ChartSpec, s as InteractionResponse, v as UiBridge, y as UiSurface } from "./types-AmKCKJn_-BogJPQHU.js";
2
+ import { y as ExternalToolSource } from "./index-QrHtAudz.js";
3
+ import { z } from "zod";
4
+ import { ComponentType, ReactNode } from "react";
5
+ //#region ../ui/dist/index.d.ts
6
+ //#region src/model/formModel.d.ts
7
+ interface FormModel {
8
+ kind: 'ask' | 'confirm' | 'form' | 'select' | 'authorize';
9
+ title?: string;
10
+ message?: string;
11
+ controls: ControlModel[];
12
+ submitLabel: string;
13
+ cancelLabel?: string;
14
+ }
15
+ interface ControlModel {
16
+ name: string;
17
+ label: string;
18
+ control: 'text' | 'number' | 'boolean' | 'select' | 'textarea';
19
+ required?: boolean;
20
+ description?: string;
21
+ defaultValue?: unknown;
22
+ options?: Array<{
23
+ label: string;
24
+ value: unknown;
25
+ }>;
26
+ }
27
+ /** 提交值按请求类型归形(WebFormBridge 与框架组件库共享单一来源) */
28
+ declare function shapeInteractionValue(model: FormModel, values: Record<string, unknown>): unknown;
29
+ /** 五类 InteractionRequest → 统一中间模型(框架无关) */
30
+ declare function interactionToFormModel(request: InteractionRequest): FormModel;
31
+ //#endregion
32
+ //#region src/model/collectValues.d.ts
33
+ interface CollectedValues {
34
+ values: Record<string, unknown>;
35
+ /** required 但为空的控件名(阻止提交) */
36
+ missingRequired: string[];
37
+ }
38
+ /**
39
+ * 严格类型化控件值收集:
40
+ * - number 空串 → undefined(非 0);非数值输入(NaN)按缺失处理(required 时入 missingRequired)
41
+ * - select 用 option 值本身经 JSON 编码比对命中(对象值可正确命中)
42
+ * - required 空值列入 missingRequired(由调用方阻止提交并标记)
43
+ */
44
+ declare function collectValues(controls: ControlModel[], container: ParentNode): CollectedValues;
45
+ //#endregion
46
+ //#region src/markdown/miniMarkdown.d.ts
47
+ /**
48
+ * 最小子集 markdown → DOM:标题(#..###)、无序列表、代码块(```)、加粗、链接。
49
+ * 全部内容经 textContent 写入,用户内容天然转义防 HTML 注入。
50
+ */
51
+ declare function renderMiniMarkdown(text: string, doc: Document): HTMLElement;
52
+ //#endregion
53
+ //#region src/chart/miniChart.d.ts
54
+ /** 固定 8 色循环调色板 */
55
+ declare const CHART_PALETTE: readonly ["#4e79a7", "#f28e2b", "#e15759", "#76b7b2", "#59a14f", "#edc948", "#b07aa1", "#ff9da7"];
56
+ /**
57
+ * ChartSpec → SVG(bar 等宽柱 + 值标签;line 折线 + 点;pie 扇形 + 图例;空数据容错)
58
+ * @stable
59
+ */
60
+ declare function renderMiniChart(chart: ChartSpec, doc: Document): SVGSVGElement;
61
+ /** A2UI/OpenUI 降级:chart → table(labels 为首列,series 各为一列) */
62
+ declare function chartToTable(chart: ChartSpec): {
63
+ type: 'table';
64
+ columns: string[];
65
+ rows: unknown[][];
66
+ };
67
+ //#endregion
68
+ //#region src/web/webFormBridge.d.ts
69
+ /**
70
+ * 框架无关原生 DOM 的 UiBridge:request 渲染表单并返回 Promise
71
+ * (提交 resolve / 取消 {cancelled:true}),完成后卸载 DOM。
72
+ * document 可注入(jsdom 测试);BEM class 样式可覆写。
73
+ */
74
+ declare class WebFormBridge implements UiBridge {
75
+ #private;
76
+ constructor(options: {
77
+ mount: HTMLElement;
78
+ document?: Document;
79
+ styles?: boolean;
80
+ });
81
+ request(input: InteractionRequest): Promise<InteractionResponse>;
82
+ /** 尽力取消等待中的 request(超时后清理遗留表单) */
83
+ cancel(id: string): void;
84
+ renderResult(input: RenderResultRequest): Promise<void>;
85
+ progress(input: {
86
+ runId: string;
87
+ message: string;
88
+ value?: number;
89
+ }): Promise<void>;
90
+ }
91
+ //#endregion
92
+ //#region src/web/resultRenderer.d.ts
93
+ /** RenderBlock → DOM(markdown/json/table/image/file/chart 六种) */
94
+ declare function renderBlocks(container: HTMLElement, blocks: RenderBlock[], doc: Document): void;
95
+ /** 完整 RenderResultRequest → DOM(summary 头 + blocks) */
96
+ declare function renderRenderResult(request: RenderResultRequest, doc: Document): HTMLElement;
97
+ //#endregion
98
+ //#region src/web/styles.d.ts
99
+ /** 最小样式(BEM class,应用可整体覆写) */
100
+ declare const WEBSKILL_STYLES_CSS = "\n.webskill-form { display: block; padding: 12px; border: 1px solid #d0d0d0; border-radius: 8px; font-family: system-ui, sans-serif; max-width: 420px; }\n.webskill-form__title { margin: 0 0 8px; font-size: 15px; font-weight: 600; }\n.webskill-form__message { margin: 0 0 10px; font-size: 14px; }\n.webskill-form__control { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }\n.webskill-form__control--invalid .webskill-form__input { border-color: #d33; }\n.webskill-form__label { font-size: 13px; font-weight: 500; }\n.webskill-form__label-required::after { content: ' *'; color: #d33; }\n.webskill-form__description { font-size: 12px; color: #666; }\n.webskill-form__error { font-size: 12px; color: #d33; display: none; }\n.webskill-form__control--invalid .webskill-form__error { display: block; }\n.webskill-form__input { padding: 6px 8px; border: 1px solid #bbb; border-radius: 4px; font-size: 14px; font-family: inherit; }\n.webskill-form__actions { display: flex; gap: 8px; margin-top: 12px; }\n.webskill-form__button { padding: 6px 14px; border-radius: 4px; border: 1px solid #bbb; background: #fff; cursor: pointer; font-size: 14px; }\n.webskill-form__button--primary { background: #2563eb; border-color: #2563eb; color: #fff; }\n.webskill-form__button--ghost { background: transparent; }\n.webskill-result { font-family: system-ui, sans-serif; font-size: 14px; }\n.webskill-result__summary { font-size: 12px; color: #666; margin-bottom: 6px; }\n.webskill-result__json { background: #f5f5f5; padding: 8px; border-radius: 4px; overflow-x: auto; }\n.webskill-result__file { padding: 4px 0; font-size: 13px; }\n.webskill-md pre { background: #f5f5f5; padding: 8px; border-radius: 4px; overflow-x: auto; }\n.webskill-md h1, .webskill-md h2, .webskill-md h3 { margin: 8px 0 4px; }\n.webskill-md p { margin: 4px 0; }\n.webskill-md ul { margin: 4px 0; padding-left: 20px; }\n";
101
+ /** 每个 document 只注入一次 */
102
+ declare function ensureStyles(doc: Document): void;
103
+ //#endregion
104
+ //#region src/catalog/types.d.ts
105
+ /** 声明式 UI 的节点:框架无关,技能脚本与 LLM 产出同一形状 */
106
+ interface UiSpecNode {
107
+ /** catalog 中声明过的组件名 */
108
+ component: string;
109
+ props?: Record<string, unknown>;
110
+ children?: UiSpecNode[];
111
+ /** 稳定 id(回放与 action 关联用) */
112
+ id?: string;
113
+ }
114
+ interface UiComponentDef {
115
+ /** 声明里使用的组件名(PascalCase,全局唯一) */
116
+ name: string;
117
+ /** 给模型看的用途描述:一句话说清"什么时候用它" */
118
+ description: string;
119
+ /** props 的 zod schema */
120
+ props: z.ZodType<Record<string, unknown>>;
121
+ /** 允许的子节点组件名;省略表示叶子节点 */
122
+ children?: readonly string[] | 'any';
123
+ group: 'layout' | 'content' | 'data' | 'input' | 'feedback';
124
+ /** 给模型的额外约束 */
125
+ constraints?: readonly string[];
126
+ /** 最小示例(进 prompt,显著提升生成质量) */
127
+ example?: UiSpecNode;
128
+ }
129
+ interface UiActionDef {
130
+ name: string;
131
+ description: string;
132
+ params?: z.ZodType<Record<string, unknown>>;
133
+ }
134
+ interface UiSpecIssue {
135
+ /** 形如 `root.children[1].props.value` */
136
+ path: string;
137
+ message: string;
138
+ }
139
+ type UiSpecValidation = {
140
+ ok: true;
141
+ } | {
142
+ ok: false;
143
+ issues: UiSpecIssue[];
144
+ };
145
+ interface UiCatalogPromptOptions {
146
+ /** tool-description 模式省略标题层级,直接作为工具描述使用 */
147
+ mode?: 'document' | 'tool-description';
148
+ }
149
+ interface UiCatalogInput {
150
+ id: string;
151
+ version: string;
152
+ title: string;
153
+ /** Markdown 设计准则,注入 prompt(对齐 A2UI catalog 的 instructions 字段) */
154
+ instructions: string;
155
+ components: readonly UiComponentDef[];
156
+ actions: readonly UiActionDef[];
157
+ }
158
+ interface UiCatalog extends UiCatalogInput {
159
+ readonly componentNames: readonly string[];
160
+ readonly actionNames: readonly string[];
161
+ component(name: string): UiComponentDef | undefined;
162
+ /** 整棵 spec 节点的 JSON Schema(组件按 `component` 判别) */
163
+ toJsonSchema(): JsonSchema;
164
+ /** Markdown 目录说明:组件签名 + 描述 + 约束 + 示例 */
165
+ toPrompt(options?: UiCatalogPromptOptions): string;
166
+ /** 运行时越界拒绝(安全边界) */
167
+ validate(spec: unknown): UiSpecValidation;
168
+ }
169
+ //#endregion
170
+ //#region src/catalog/defineCatalog.d.ts
171
+ /**
172
+ * 同一份定义派生出 JSON Schema / prompt / validator 三种投影,
173
+ * 不允许任何一方手写副本(21 号文档 §1)。
174
+ */
175
+ declare function defineUiCatalog(input: UiCatalogInput): UiCatalog;
176
+ //#endregion
177
+ //#region src/catalog/uiCatalog.d.ts
178
+ /**
179
+ * v3 首发 catalog:覆盖既有 `UiSurface` 六类的全部表达力,先窄后宽。
180
+ * 只依赖 zod —— 不 import 任何 UI framework(21 号文档 §5.1)。
181
+ */
182
+ declare const uiCatalog: UiCatalog;
183
+ /** prompt / 文档里引用的分组顺序(Console 展示同序) */
184
+ declare const UI_CATALOG_GROUPS: {
185
+ readonly content: readonly ["Stack", "Card", "Separator", "Heading", "Text", "Markdown", "Badge"];
186
+ readonly data: readonly ["Metric", "Table", "Chart", "FileLink"];
187
+ readonly input: readonly ["Form", "Field", "Button"];
188
+ };
189
+ //#endregion
190
+ //#region src/catalog/toSurface.d.ts
191
+ /**
192
+ * 保留的 custom 组件名:catalog 声明树整棵挂在这个 surface 上。
193
+ * `UiSurface` 的六类联合表达不了通用节点树,改造它属破坏性变更(21 号文档 §7 已备案),
194
+ * 因此本轮用一个保留 component 名承载,四档 registry 各自识别它。
195
+ */
196
+ declare const UI_SPEC_COMPONENT = "webskill.ui-spec";
197
+ interface UiSpecSurfaceProps {
198
+ catalogId: string;
199
+ catalogVersion: string;
200
+ spec: UiSpecNode;
201
+ /** 声明树里出现过的 action 名(renderer 据此生成按钮能力) */
202
+ actions: string[];
203
+ }
204
+ /** 声明树 → `UiSurface`。id 缺省时由调用方给(工具源用 runtime 生成的 id)。 */
205
+ declare function toSurface(catalog: UiCatalog, spec: UiSpecNode, id: string): UiSurface;
206
+ /** surface 是否承载 catalog 声明树(四档 renderer 的分派入口) */
207
+ declare function isUiSpecSurface(surface: UiSurface): boolean;
208
+ //#endregion
209
+ //#region src/catalog/toJsonRenderSpec.d.ts
210
+ /** json-render 的扁平 spec:`elements` 以 key 索引,`children` 只存 key */
211
+ interface JsonRenderSpec {
212
+ root: string;
213
+ elements: Record<string, {
214
+ type: string;
215
+ props: Record<string, unknown>;
216
+ children?: string[];
217
+ }>;
218
+ }
219
+ /**
220
+ * catalog 声明树 → json-render 扁平 spec。纯数据变换,不 import json-render
221
+ * (`@webskill/ui` 保持环境无关)。
222
+ */
223
+ declare function toJsonRenderSpec(spec: UiSpecNode): JsonRenderSpec;
224
+ //#endregion
225
+ //#region src/catalog/uiCatalogToolSource.d.ts
226
+ declare const RENDER_UI_TOOL = "render_ui";
227
+ interface UiCatalogToolSourceOptions {
228
+ /** 默认使用 v1 catalog */
229
+ catalog?: UiCatalog;
230
+ /** surface id 生成(默认时间戳 + 随机后缀) */
231
+ newSurfaceId?: () => string;
232
+ }
233
+ /**
234
+ * 把 catalog 变成一个工具的入参 Schema,让模型直接生成声明式 UI(21 号文档 §3):
235
+ * agentLoop / UiBridge / extractUiSurfaceEvents 全部零改动,装配处只多一个 externalTools 条目。
236
+ */
237
+ declare function createUiCatalogToolSource(options?: UiCatalogToolSourceOptions): ExternalToolSource;
238
+ //#endregion
239
+ //#region src/adapters/surface/surfaceDescriptor.d.ts
240
+ declare const WEBSKILL_SURFACE_ACTION = "webskill:surface-action";
241
+ type SurfaceRendererProvenance = 'a2ui-standard' | 'a2ui-extension' | 'openui-library' | 'openui-extension' | 'vercel-surface-host';
242
+ /** Serializable surface state consumed by a renderer-specific host. @experimental */
243
+ interface UiSurfaceDescriptor {
244
+ type: 'webskill-surface';
245
+ snapshot: UiSurfaceSnapshot;
246
+ provenance: SurfaceRendererProvenance;
247
+ }
248
+ /** Serializable renderer action. The Runtime validates nonce capability before resuming a run. @experimental */
249
+ interface UiSurfaceActionDispatch {
250
+ runId?: string;
251
+ surfaceId: string;
252
+ actionId: string;
253
+ intent: UiSurfaceAction['intent'];
254
+ nonce?: string;
255
+ value?: Record<string, unknown>;
256
+ cancelled?: boolean;
257
+ }
258
+ declare function toUiSurfaceDescriptor(snapshot: UiSurfaceSnapshot, provenance: SurfaceRendererProvenance): UiSurfaceDescriptor;
259
+ declare function toUiSurfaceActionDispatch(snapshot: UiSurfaceSnapshot, action: UiSurfaceAction, value?: Record<string, unknown>): UiSurfaceActionDispatch;
260
+ /** Returns undefined for malformed or non-WebSkill renderer events. @experimental */
261
+ declare function fromUiSurfaceActionDispatch(value: unknown): UiSurfaceActionDispatch | undefined;
262
+ //#endregion
263
+ //#region src/adapters/vercel/vercelPayload.d.ts
264
+ /** Vercel AI SDK v7 ToolCallPart 兼容结构 */
265
+ interface VercelToolInvocation {
266
+ type: 'tool-call';
267
+ toolCallId: string;
268
+ toolName: string;
269
+ input: unknown;
270
+ }
271
+ declare const VERCEL_INTERACTION_TOOL_NAME = "webskill_interaction";
272
+ declare const VERCEL_SURFACE_DATA_PART_TYPE = "data-webskill-surface";
273
+ declare const VERCEL_SURFACE_ACTION_DATA_PART_TYPE = "webskill:surface-action";
274
+ /** Vercel AI SDK-compatible data part consumed by a WebSkill SurfaceHost. @experimental */
275
+ interface VercelSurfaceDataPart {
276
+ type: typeof VERCEL_SURFACE_DATA_PART_TYPE;
277
+ id: string;
278
+ data: ReturnType<typeof toUiSurfaceDescriptor>;
279
+ }
280
+ /** InteractionRequest → SDK tool UI 结构(应用聊天 UI 直接消费) */
281
+ declare function toVercelToolInvocation(request: InteractionRequest): VercelToolInvocation;
282
+ /** SDK 回传(tool result / output)→ InteractionResponse */
283
+ declare function fromVercelToolResult(part: unknown): InteractionResponse;
284
+ /** UiSurfaceSnapshot → AI SDK data part; the SurfaceHost owns renderer selection. @experimental */
285
+ declare function toVercelSurfaceDataPart(snapshot: UiSurfaceSnapshot): VercelSurfaceDataPart;
286
+ /** Decodes a nonce-bound action data part emitted by a Vercel SurfaceHost. @experimental */
287
+ declare function fromVercelSurfaceAction(part: unknown): UiSurfaceActionDispatch | undefined;
288
+ //#endregion
289
+ //#region src/adapters/vercel/vercelUiBridge.d.ts
290
+ /**
291
+ * 薄桥接类:request → SDK tool UI 结构 → 应用的聊天 UI(sendInteraction 回调实现)
292
+ * → SDK 回传 → InteractionResponse。
293
+ */
294
+ declare class VercelUiBridge implements UiBridge {
295
+ #private;
296
+ constructor(deps: {
297
+ sendInteraction: (invocation: VercelToolInvocation) => Promise<unknown>;
298
+ });
299
+ request(input: InteractionRequest): Promise<InteractionResponse>;
300
+ }
301
+ //#endregion
302
+ //#region src/adapters/openui/openuiLang.d.ts
303
+ /**
304
+ * InteractionRequest ↔ openui-lang 双向转换。
305
+ * openui-lang 语法(@openuidev/react-lang 实测):
306
+ * - 每行一条语句 `identifier = Expression`,`root = Component(...)` 为入口
307
+ * - 组件调用参数为位置参数;字符串双引号反斜杠转义
308
+ * - 组件词汇(与应用 Library 约定):Form(title, children)、
309
+ * Text(content)(纯展示文本,authorize 的能力描述用)、
310
+ * TextField(name, label, required?, defaultValue?)、NumberField、BooleanField(name, label, default?)、
311
+ * SelectField(name, label, options)、SubmitButton(label, actionType, requestId)、
312
+ * CancelButton(label, actionType, requestId)
313
+ */
314
+ declare const OPENUI_SUBMIT_ACTION = "webskill:submit";
315
+ declare const OPENUI_CANCEL_ACTION = "webskill:cancel";
316
+ /** authorize 的 Allow 专用动作(提交即批准 → value:true;Deny 走 cancel → cancelled:true) */
317
+ declare const OPENUI_AUTHORIZE_ACTION = "webskill:authorize";
318
+ declare const OPENUI_SURFACE_ACTION = "webskill:surface-action";
319
+ /** @experimental */
320
+ declare function toOpenUiLang(request: InteractionRequest): string;
321
+ /**
322
+ * UiSurfaceSnapshot → OpenUI library program. OpenUI applications provide WebSkillSurfaceHost;
323
+ * its descriptor tells the host whether it is a native extension rather than an OpenUI-native component.
324
+ * @experimental
325
+ */
326
+ declare function toOpenUiSurfaceLang(snapshot: UiSurfaceSnapshot): string;
327
+ /** Decodes a nonce-bound action emitted by an OpenUI WebSkillSurfaceHost. @experimental */
328
+ declare function fromOpenUiSurfaceAction(action: unknown): UiSurfaceActionDispatch | undefined;
329
+ /**
330
+ * OpenUI ActionEvent → InteractionResponse(formState 优先,取消单独分支)
331
+ * @experimental
332
+ */
333
+ declare function fromOpenUiAction(action: unknown): InteractionResponse;
334
+ //#endregion
335
+ //#region src/adapters/openui/openUiSpecLang.d.ts
336
+ /**
337
+ * catalog 声明树 → openui-lang 文本。语法为每行一条 `id = Component(位置参数…)`,
338
+ * `root = …` 为入口;容器组件的子节点作为最后一个参数传 id 数组。
339
+ */
340
+ declare function toOpenUiSpecLang(spec: UiSpecNode, catalog?: UiCatalog): string;
341
+ //#endregion
342
+ //#region src/adapters/a2ui/a2uiMessages.d.ts
343
+ /**
344
+ * InteractionRequest → A2UI 协议消息(v0.9.1,Basic Catalog)。
345
+ * 依据 https://a2ui.org/specification/v0.9-a2ui/:
346
+ * - 信封 {version, createSurface|updateComponents|updateDataModel|deleteSurface}
347
+ * - 组件为扁平邻接表(id 引用),root 必需
348
+ * - 输入组件与数据模型经 JSON Pointer 双向绑定;action.context 回传
349
+ * - createSurface.sendDataModel: true → 客户端动作时携带完整数据模型
350
+ *
351
+ * action 约定:submit → {name: 'webskill:submit', context: {requestId}};
352
+ * cancel → {name: 'webskill:cancel', context: {requestId}}。
353
+ */
354
+ declare const A2UI_VERSION = "v0.9.1";
355
+ declare const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
356
+ declare const A2UI_SUBMIT_ACTION = "webskill:submit";
357
+ declare const A2UI_CANCEL_ACTION = "webskill:cancel";
358
+ declare const A2UI_SURFACE_ACTION = "webskill:surface-action";
359
+ interface A2uiMessage {
360
+ version: string;
361
+ [key: string]: unknown;
362
+ }
363
+ /** @experimental */
364
+ declare function toA2uiMessages(request: InteractionRequest): A2uiMessage[];
365
+ /**
366
+ * UiSurfaceSnapshot → A2UI extension-host messages.
367
+ * Basic Catalog has no chart/table vocabulary, so a labelled WebSkill host owns these controlled renderers.
368
+ * @experimental
369
+ */
370
+ declare function toA2uiSurfaceMessages(snapshot: UiSurfaceSnapshot): A2uiMessage[];
371
+ /** Decodes a nonce-bound action emitted by a WebSkill A2UI extension host. @experimental */
372
+ declare function fromA2uiSurfaceAction(event: unknown): UiSurfaceActionDispatch | undefined;
373
+ /** Builds the A2UI event payload an extension host sends after a user action. @experimental */
374
+ declare function toA2uiSurfaceAction(snapshot: UiSurfaceSnapshot, action: UiSurfaceAction, value?: Record<string, unknown>): {
375
+ name: string;
376
+ context: UiSurfaceActionDispatch;
377
+ };
378
+ /**
379
+ * 按 InteractionRequest.type 解码提交值(绑定模型原样回传的是表单对象):
380
+ * confirm 仅 confirmed===true 批准;select 还原原始 option 值(非字符串值经 JSON 编码比对);
381
+ * form 的 number 字段转 number(NaN 保留原值);ask 取 answer;authorize 提交即批准。
382
+ * 纯转换器:任何直接使用 fromA2uiAction 的消费者都应经此拿到正确类型。
383
+ * @experimental
384
+ */
385
+ declare function decodeInteractionResponse(request: InteractionRequest, response: InteractionResponse): InteractionResponse;
386
+ /**
387
+ * A2UI client→server action 事件 → InteractionResponse。
388
+ * 传入 request 时按类型解码提交值(见 decodeInteractionResponse)。
389
+ * @experimental
390
+ */
391
+ declare function fromA2uiAction(event: unknown, request?: InteractionRequest): InteractionResponse;
392
+ //#endregion
393
+ //#region src/adapters/a2ui/webskillCatalog.d.ts
394
+ /** 自定义 catalog 的协议 id(对齐 https://a2ui.org/specification/v1_0/catalog_definition.json) */
395
+ declare const WEBSKILL_A2UI_CATALOG_ID = "https://webskill.dev/a2ui/catalogs/v1/catalog.json";
396
+ interface A2uiCatalogDefinition {
397
+ catalogId: string;
398
+ title: string;
399
+ description: string;
400
+ /** Markdown 设计准则;A2UI 侧的模型据此生成 */
401
+ instructions: string;
402
+ /** 组件名 → 该组件 props 的 JSON Schema */
403
+ components: Record<string, JsonSchema>;
404
+ /** 可被组件 action 引用的函数名 */
405
+ functions: Record<string, {
406
+ description: string;
407
+ }>;
408
+ }
409
+ /**
410
+ * WebSkill catalog → A2UI `catalog_definition.json`。
411
+ * 组件 schema 由 catalog 的 JSON Schema 投影经 `a2uiComponentShapes` 改写成 A2UI 线上形状
412
+ * (嵌套变 id 引用、action 名变协议信封),不手写第二份词汇表——
413
+ * Lit 元素的 zod API 也由同一份 shape 派生。
414
+ */
415
+ declare function buildA2uiCatalogDefinition(catalog: UiCatalog): A2uiCatalogDefinition;
416
+ //#endregion
417
+ //#region src/adapters/a2ui/a2uiComponentShape.d.ts
418
+ /**
419
+ * 声明树与 A2UI 线上形状只差三处,且三处都能从 catalog 定义机械推出:
420
+ *
421
+ * 1. 嵌套:声明树把子节点内联在 `node.children`;A2UI 要求组件是扁平邻接表,
422
+ * 子节点以 id 引用出现在 props 的 `children` 字段里。
423
+ * 2. 动作:catalog 的 `Button.action` 是一个 action 名(字符串);
424
+ * A2UI 用 `{event:{name, context}}` 信封表达"点击时做什么"。
425
+ * 3. 取值:表单控件(group=input 且声明了 `name`)在 A2UI 里靠 JSON Pointer
426
+ * 与数据模型双向绑定,因此多出一个 `value` 字段。
427
+ *
428
+ * 这份描述是 JSON `catalog_definition` 与 Lit 元素 zod API 的共同来源——
429
+ * 两边各自手写就会漂移(用例断言两者派生自同一份 shape)。
430
+ */
431
+ interface A2uiComponentShape {
432
+ name: string;
433
+ description: string;
434
+ /** catalog 投影出的 props JSON Schema(未做 A2UI 改写) */
435
+ props: JsonSchema;
436
+ /** 原样透传的 props 字段名(键序取自 JSON Schema) */
437
+ staticProps: readonly string[];
438
+ /** 该组件接受子节点:props 里多出一个 A2UI ChildList 字段 */
439
+ childList: boolean;
440
+ /** children 字段的说明,承载 catalog 的子节点白名单约束 */
441
+ childListDescription?: string;
442
+ /** 需要换成 A2UI action 信封的 props 字段名 */
443
+ actionProps: readonly string[];
444
+ /** 与数据模型双向绑定的字段名(表单控件才有) */
445
+ valueProps: readonly string[];
446
+ /** 该组件自带提交按钮(props 里声明了提交标签) */
447
+ submitLabelProp?: string;
448
+ /** 该组件自带取消按钮 */
449
+ cancelLabelProp?: string;
450
+ }
451
+ /** A2UI 协议公共类型(与 @a2ui/web_core 的 common-types 同一套定义) */
452
+ declare const A2UI_COMMON_TYPES = "https://a2ui.org/specification/v0_9/common_types.json";
453
+ /** catalog → 每个组件的 A2UI 线上形状 */
454
+ declare function a2uiComponentShapes(catalog: UiCatalog): A2uiComponentShape[];
455
+ /** 单个组件的 A2UI props JSON Schema(协议要求每个组件是一份 schema) */
456
+ declare function a2uiComponentSchema(shape: A2uiComponentShape): JsonSchema;
457
+ //#endregion
458
+ //#region src/adapters/a2ui/specToA2ui.d.ts
459
+ /** 声明树里按钮触发的事件名(宿主据 context.actionId 回传 surface action) */
460
+ declare const A2UI_SPEC_ACTION = "webskill:spec-action";
461
+ /** 表单值在 A2UI 数据模型里的根路径 */
462
+ declare const A2UI_SPEC_FORM_PATH = "/form";
463
+ interface A2uiSpecMessageOptions {
464
+ surfaceId: string;
465
+ /** 缺省用 WebSkill BYOC catalog;传 Basic Catalog id 无意义(词汇表对不上) */
466
+ catalogId?: string;
467
+ /** 并入每个 action 的 context,宿主据此定位 surface */
468
+ context?: Record<string, unknown>;
469
+ }
470
+ /**
471
+ * catalog 声明树 → A2UI 消息序列。
472
+ *
473
+ * 协议要求组件是扁平邻接表且根节点 id 为 `root`,因此这里做树 → 邻接表的展开。
474
+ * 三处改写全部由 `a2uiComponentShapes` 决定,本函数不认识任何具体组件名:
475
+ * - 子节点变成 props.children 里的 id 引用
476
+ * - 表单控件的值经 JSON Pointer 与数据模型双向绑定
477
+ * - 自带提交/取消标签的组件(A2UI 没有表单提交事件)把按钮物化成 Button 子节点,
478
+ * 与 `toA2uiMessages` 对交互请求的处理同一手法
479
+ */
480
+ declare function toA2uiSpecMessages(catalog: UiCatalog, spec: UiSpecNode, options: A2uiSpecMessageOptions): A2uiMessage[];
481
+ interface A2uiSpecActionEvent {
482
+ actionId: string;
483
+ context: Record<string, unknown>;
484
+ }
485
+ /** A2UI action 事件 → 声明树 action(非本 catalog 的事件返回 undefined) */
486
+ declare function fromA2uiSpecAction(event: unknown): A2uiSpecActionEvent | undefined;
487
+ //#endregion
488
+ //#region src/a2uiRuntime/litRendererBridge.d.ts
489
+ /** @experimental */
490
+ declare class LitRendererBridge implements UiBridge {
491
+ #private;
492
+ constructor(deps: {
493
+ mount: HTMLElement;
494
+ document?: Document;
495
+ });
496
+ request(input: InteractionRequest): Promise<InteractionResponse>;
497
+ /** runtime 交互超时/取消:移除 surface 并以 cancelled resolve pending Promise(防悬挂 + DOM 残留) */
498
+ cancel(id: string): void;
499
+ }
500
+ //#endregion
501
+ //#region src/a2uiRuntime/loadLitCatalog.d.ts
502
+ /** catalog 里单个组件的最小可见面(A2UI `LitComponentApi` 的结构子集) */
503
+ interface A2uiCatalogComponent {
504
+ readonly name: string;
505
+ readonly tagName: string;
506
+ readonly schema: unknown;
507
+ }
508
+ /**
509
+ * A2UI catalog 句柄的最小结构契约。
510
+ *
511
+ * 与 optionalPeers/openUiRuntime.ts 同一约定:**不引用** `@a2ui/*` 的包类型。
512
+ * 它们是 optional peer,写进签名后会原样进入已发布的 `.d.ts`,
513
+ * 未安装 A2UI 的消费方 `tsc --noEmit` 会撞 TS2307(install-smoke 的类型探针实测)。
514
+ */
515
+ interface A2uiCatalogHandle {
516
+ readonly id: string;
517
+ readonly components: ReadonlyMap<string, A2uiCatalogComponent>;
518
+ }
519
+ /**
520
+ * BYOC Lit 元素的加载入口。
521
+ *
522
+ * 元素模块静态依赖 `lit` 与 `@a2ui/*`(三者都是 optional peer),
523
+ * 因此只能经动态 import 进来:未用 A2UI 档的应用不为这段体积买单,
524
+ * 缺依赖时给出带安装提示的 `UI_UNAVAILABLE`,而不是一个空白 surface。
525
+ */
526
+ declare function loadWebSkillLitCatalog(): Promise<A2uiCatalogHandle>;
527
+ //#endregion
528
+ //#region src/optionalPeers/openUiRuntime.d.ts
529
+ /**
530
+ * Minimal structural contracts for the optional OpenUI peers (0.2.7 B4).
531
+ *
532
+ * `@openuidev/react-lang` and `zod` are optional peers loaded via dynamic import.
533
+ * The contracts below deliberately do NOT reference the peers' package types:
534
+ * tracing the react-lang/lang-core/zod type graph OOMs the dts build under the
535
+ * default heap (see packages/chatbot/src/react/OpenUiInteraction.tsx history).
536
+ *
537
+ * The `as unknown as` narrowing lives ONLY here (repository-wide single point):
538
+ * callers receive typed handles and never re-assert.
539
+ */
540
+ interface OpenUiStateField<T> {
541
+ value: T;
542
+ setValue(value: T): void;
543
+ }
544
+ interface OpenUiRenderProps<P> {
545
+ props: P;
546
+ renderNode(value: unknown): ReactNode;
547
+ }
548
+ interface OpenUiRendererProps {
549
+ response: string | null;
550
+ library: unknown;
551
+ onAction?: (event: unknown) => void;
552
+ }
553
+ interface OpenUiRuntime {
554
+ /** The OpenUI Renderer component (structurally React's ComponentType). */
555
+ Renderer: ComponentType<OpenUiRendererProps>;
556
+ defineComponent<P>(config: {
557
+ name: string;
558
+ description: string;
559
+ props: unknown;
560
+ component: (renderProps: OpenUiRenderProps<P>) => ReactNode;
561
+ }): unknown;
562
+ createLibrary(definition: {
563
+ components: unknown[];
564
+ root?: string;
565
+ }): unknown;
566
+ useStateField<T>(name: string, value?: T): OpenUiStateField<T>;
567
+ useTriggerAction(): (userMessage: string, formName?: string, action?: {
568
+ type?: string;
569
+ params?: Record<string, unknown>;
570
+ }) => void | Promise<void>;
571
+ }
572
+ /** Minimal zod surface used to build OpenUI component props schemas at runtime. */
573
+ interface ZodSchemaBuilder {
574
+ optional(): ZodSchemaBuilder;
575
+ nullable(): ZodSchemaBuilder;
576
+ }
577
+ interface ZodRuntime {
578
+ object(shape: Record<string, unknown>): ZodSchemaBuilder;
579
+ string(): ZodSchemaBuilder;
580
+ boolean(): ZodSchemaBuilder;
581
+ any(): ZodSchemaBuilder;
582
+ unknown(): ZodSchemaBuilder;
583
+ array(item: unknown): ZodSchemaBuilder;
584
+ }
585
+ interface LoadedOpenUiPeers {
586
+ openui: OpenUiRuntime;
587
+ z: ZodRuntime;
588
+ }
589
+ /**
590
+ * Loads the optional OpenUI peers (@openuidev/react-lang and zod) for the OpenUI
591
+ * interaction/surface paths. Throws a WebSkillError with code UI_UNAVAILABLE and an
592
+ * install hint when either peer is missing, so callers can fall back to native
593
+ * rendering instead of leaving a blank surface.
594
+ */
595
+ declare function loadOpenUiPeers(): Promise<LoadedOpenUiPeers>;
596
+ //#endregion
597
+ export { WEBSKILL_SURFACE_ACTION as $, SurfaceRendererProvenance as A, toA2uiSurfaceAction as At, UiSpecNode as B, toVercelToolInvocation as Bt, OPENUI_AUTHORIZE_ACTION as C, renderBlocks as Ct, OpenUiRendererProps as D, shapeInteractionValue as Dt, OPENUI_SURFACE_ACTION as E, renderRenderResult as Et, UiCatalogInput as F, toOpenUiSurfaceLang as Ft, VERCEL_INTERACTION_TOOL_NAME as G, UiSpecValidation as H, UiCatalogPromptOptions as I, toSurface as It, VercelSurfaceDataPart as J, VERCEL_SURFACE_ACTION_DATA_PART_TYPE as K, UiCatalogToolSourceOptions as L, toUiSurfaceActionDispatch as Lt, UI_SPEC_COMPONENT as M, toJsonRenderSpec as Mt, UiActionDef as N, toOpenUiLang as Nt, OpenUiRuntime as O, toA2uiMessages as Ot, UiCatalog as P, toOpenUiSpecLang as Pt, WEBSKILL_STYLES_CSS as Q, UiComponentDef as R, toUiSurfaceDescriptor as Rt, LoadedOpenUiPeers as S, loadWebSkillLitCatalog as St, OPENUI_SUBMIT_ACTION as T, renderMiniMarkdown as Tt, UiSurfaceActionDispatch as U, UiSpecSurfaceProps as V, uiCatalog as Vt, UiSurfaceDescriptor as W, VercelUiBridge as X, VercelToolInvocation as Y, WEBSKILL_A2UI_CATALOG_ID as Z, CollectedValues as _, fromVercelSurfaceAction as _t, A2UI_SPEC_FORM_PATH as a, chartToTable as at, JsonRenderSpec as b, isUiSpecSurface as bt, A2UI_VERSION as c, decodeInteractionResponse as ct, A2uiCatalogHandle as d, fromA2uiAction as dt, WebFormBridge as et, A2uiComponentShape as f, fromA2uiSpecAction as ft, CHART_PALETTE as g, fromUiSurfaceActionDispatch as gt, A2uiSpecMessageOptions as h, fromOpenUiSurfaceAction as ht, A2UI_SPEC_ACTION as i, buildA2uiCatalogDefinition as it, UI_CATALOG_GROUPS as j, toA2uiSurfaceMessages as jt, RENDER_UI_TOOL as k, toA2uiSpecMessages as kt, A2uiCatalogComponent as l, defineUiCatalog as lt, A2uiSpecActionEvent as m, fromOpenUiAction as mt, A2UI_CANCEL_ACTION as n, a2uiComponentSchema as nt, A2UI_SUBMIT_ACTION as o, collectValues as ot, A2uiMessage as p, fromA2uiSurfaceAction as pt, VERCEL_SURFACE_DATA_PART_TYPE as q, A2UI_COMMON_TYPES as r, a2uiComponentShapes as rt, A2UI_SURFACE_ACTION as s, createUiCatalogToolSource as st, A2UI_BASIC_CATALOG_ID as t, ZodRuntime as tt, A2uiCatalogDefinition as u, ensureStyles as ut, ControlModel as v, fromVercelToolResult as vt, OPENUI_CANCEL_ACTION as w, renderMiniChart as wt, LitRendererBridge as x, loadOpenUiPeers as xt, FormModel as y, interactionToFormModel as yt, UiSpecIssue as z, toVercelSurfaceDataPart as zt };