@webskill/sdk 0.0.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.
@@ -0,0 +1,955 @@
1
+ //#region ../core/dist/index.d.ts
2
+ //#region src/errors.d.ts
3
+ type WebSkillErrorCode = 'FS_NOT_FOUND' | 'FS_PATH_OUTSIDE_ROOT' | 'SKILL_NOT_FOUND' | 'SKILL_INVALID_METADATA' | 'SKILL_INVALID_NAME' | 'SKILL_DUPLICATE_NAME' | 'SKILL_UNSUPPORTED_SCRIPT' | 'VALIDATION_FAILED' | 'TOOL_NOT_FOUND' | 'TOOL_EXECUTION_FAILED' | 'TOOL_UNSUPPORTED' | 'TOOL_SCHEMA_UNAVAILABLE' | 'RUN_TIMEOUT' | 'RUN_MAX_TURNS_EXCEEDED' | 'RUN_FAILED' | 'RUN_CANCELLED' | 'RUN_INTERACTION_TIMEOUT' | 'UI_UNAVAILABLE' | 'LLM_UNAVAILABLE' | 'LLM_REQUEST_FAILED' | 'INSTALL_FAILED' | 'UNINSTALL_FAILED' | 'EXPORT_FAILED' | 'INTEGRITY_FAILED' | 'FS_PERMISSION_DENIED' | 'MCP_ENDPOINT_UNAVAILABLE' | 'MCP_TOOL_NOT_FOUND' | 'CANDIDATE_INVALID' | 'APPROVAL_REQUIRED' | 'SKILL_QUARANTINED' | 'SKILL_DISABLED' | 'GOVERNANCE_FAILED';
4
+ /** 所有公开 API 抛出的结构化错误,code 供上层可编程处理 */
5
+ declare class WebSkillError extends Error {
6
+ readonly code: WebSkillErrorCode;
7
+ readonly details?: unknown;
8
+ constructor(code: WebSkillErrorCode, message: string, details?: unknown);
9
+ }
10
+ //#endregion
11
+ //#region src/contracts/jsonSchema.d.ts
12
+ /**
13
+ * 宽松 JSON Schema:覆盖工具 inputSchema 的常见字段,
14
+ * 索引签名允许透传规范内的其他关键字。供 tools 与后续 UI 复用。
15
+ */
16
+ interface JsonSchema {
17
+ type?: string;
18
+ properties?: Record<string, JsonSchema>;
19
+ required?: string[];
20
+ items?: JsonSchema;
21
+ enum?: unknown[];
22
+ description?: string;
23
+ default?: unknown;
24
+ [key: string]: unknown;
25
+ }
26
+ //#endregion
27
+ //#region src/fs/types.d.ts
28
+ interface FileStat {
29
+ path: string;
30
+ type: 'file' | 'directory';
31
+ size?: number;
32
+ mtimeMs?: number;
33
+ }
34
+ /**
35
+ * 文件系统抽象:core 只依赖此接口,Node/浏览器各自提供实现。
36
+ * 路径一律使用 `/` 分隔的 POSIX 风格。
37
+ */
38
+ interface FileSystemProvider {
39
+ readonly kind: string;
40
+ readText(path: string): Promise<string>;
41
+ writeText(path: string, content: string): Promise<void>;
42
+ readBinary(path: string): Promise<Uint8Array>;
43
+ writeBinary(path: string, content: Uint8Array): Promise<void>;
44
+ exists(path: string): Promise<boolean>;
45
+ stat(path: string): Promise<FileStat>;
46
+ list(path: string): Promise<FileStat[]>;
47
+ mkdir(path: string): Promise<void>;
48
+ remove(path: string, options?: {
49
+ recursive?: boolean;
50
+ }): Promise<void>;
51
+ }
52
+ //#endregion
53
+ //#region src/fs/memoryFs.d.ts
54
+ /** 内存文件系统:路径一律规范化为 `/` 分隔,写入自动创建父目录 */
55
+ declare class MemoryFS implements FileSystemProvider {
56
+ #private;
57
+ readonly kind = "memory";
58
+ constructor();
59
+ readText(path: string): Promise<string>;
60
+ writeText(path: string, content: string): Promise<void>;
61
+ readBinary(path: string): Promise<Uint8Array>;
62
+ writeBinary(path: string, content: Uint8Array): Promise<void>;
63
+ exists(path: string): Promise<boolean>;
64
+ stat(path: string): Promise<FileStat>;
65
+ list(path: string): Promise<FileStat[]>;
66
+ mkdir(path: string): Promise<void>;
67
+ remove(path: string, options?: {
68
+ recursive?: boolean;
69
+ }): Promise<void>;
70
+ }
71
+ //#endregion
72
+ //#region src/fs/pathSecurity.d.ts
73
+ /** 统一分隔符为 `/`,去除 `.` 段与重复分隔符(不解析 `..`) */
74
+ declare function normalizePath(path: string): string;
75
+ /**
76
+ * 将相对路径安全地解析到 root 之内。
77
+ * 拒绝空路径、绝对路径(`/`、`\\`、`C:\` 形式)与任何 `..` 段。
78
+ */
79
+ declare function resolveInsideRoot(root: string, relativePath: string): string;
80
+ //#endregion
81
+ //#region src/skill/types.d.ts
82
+ type SkillSource = 'local' | 'mcp' | 'generated' | 'installed';
83
+ /** SKILL.md frontmatter 元数据;未知字段原样透传 */
84
+ interface SkillMetadata {
85
+ name: string;
86
+ description: string;
87
+ license?: string;
88
+ version?: string;
89
+ [key: string]: unknown;
90
+ }
91
+ interface SkillLocation {
92
+ skillRoot: string;
93
+ skillMdPath: string;
94
+ source: SkillSource;
95
+ }
96
+ interface SkillDocument {
97
+ metadata: SkillMetadata;
98
+ body: string;
99
+ location: SkillLocation;
100
+ }
101
+ /** Catalog 条目:渐进披露第一层,只含元数据摘要与标记位 */
102
+ interface SkillCatalogEntry {
103
+ name: string;
104
+ description: string;
105
+ version?: string;
106
+ license?: string;
107
+ root: string;
108
+ source: SkillSource;
109
+ hasScripts: boolean;
110
+ hasReferences: boolean;
111
+ hasAssets: boolean;
112
+ }
113
+ interface SkillCatalog {
114
+ skills: SkillCatalogEntry[];
115
+ }
116
+ //#endregion
117
+ //#region src/skill/parser.d.ts
118
+ declare function parseSkillMarkdown(raw: string): {
119
+ metadata: SkillMetadata;
120
+ body: string;
121
+ };
122
+ //#endregion
123
+ //#region src/skill/naming.d.ts
124
+ declare const SKILL_NAME_MAX_LENGTH = 64;
125
+ /** Agent Skills 官方命名规范:小写字母/数字/连字符,不允许首尾或连续连字符 */
126
+ declare const SKILL_NAME_PATTERN: RegExp;
127
+ declare function isValidSkillName(name: string): boolean;
128
+ //#endregion
129
+ //#region src/skill/rules.d.ts
130
+ interface SkillIssue {
131
+ /** 与 WebSkillErrorCode 对齐 */
132
+ code: string;
133
+ severity: 'info' | 'warning' | 'error';
134
+ message: string;
135
+ path?: string;
136
+ }
137
+ /**
138
+ * 技能合规规则的唯一实现。SkillDiscovery 与 validateSkills 都必须调用本函数,
139
+ * 禁止各自重复实现规则(避免两套规则漂移)。
140
+ */
141
+ declare function checkSkillRules(input: {
142
+ dirName: string;
143
+ hasSkillMd: boolean;
144
+ metadata?: SkillMetadata;
145
+ parseError?: WebSkillError;
146
+ scriptFileNames?: string[];
147
+ existingNames?: Set<string>;
148
+ }): SkillIssue[];
149
+ //#endregion
150
+ //#region src/skill/discovery.d.ts
151
+ interface DiscoveryResult {
152
+ entries: SkillCatalogEntry[];
153
+ issues: SkillIssue[];
154
+ }
155
+ declare class SkillDiscovery {
156
+ #private;
157
+ constructor(fs: FileSystemProvider, roots: string[]);
158
+ discover(): Promise<DiscoveryResult>;
159
+ catalog(): Promise<{
160
+ catalog: SkillCatalog;
161
+ issues: SkillIssue[];
162
+ }>;
163
+ /** 按需加载技能完整文档;技能不存在时抛 SKILL_NOT_FOUND */
164
+ loadDocument(skillName: string): Promise<SkillDocument>;
165
+ }
166
+ //#endregion
167
+ //#region src/skill/validator.d.ts
168
+ interface ValidationReport {
169
+ /** 无 error 级 issue 即 true */
170
+ ok: boolean;
171
+ issues: SkillIssue[];
172
+ }
173
+ /**
174
+ * 合规校验。内部直接复用 SkillDiscovery 的扫描逻辑,
175
+ * 规则判定同样落在 checkSkillRules 单一来源上。
176
+ */
177
+ declare function validateSkills(fs: FileSystemProvider, roots: string[]): Promise<ValidationReport>;
178
+ //#endregion
179
+ //#region src/skill/reader.d.ts
180
+ /** 按技能名读取技能根目录内的文件,全部读取强制经过路径安全检查 */
181
+ declare class SkillReader {
182
+ #private;
183
+ constructor(fs: FileSystemProvider, index: Map<string, string>);
184
+ readSkillMarkdown(skillName: string): Promise<string>;
185
+ readSkillFile(skillName: string, relativePath: string): Promise<string>;
186
+ readSkillBinary(skillName: string, relativePath: string): Promise<Uint8Array>;
187
+ }
188
+ //#endregion
189
+ //#region src/skill/catalog.d.ts
190
+ /** 由条目列表构建 Catalog,保证按名称排序 */
191
+ declare function buildCatalog(entries: SkillCatalogEntry[]): SkillCatalog;
192
+ //#endregion
193
+ //#region src/render/types.d.ts
194
+ /** 可插拔的 Catalog 渲染器 */
195
+ interface CatalogRenderer {
196
+ readonly format: string;
197
+ render(catalog: SkillCatalog): string;
198
+ }
199
+ //#endregion
200
+ //#region src/render/jsonRenderer.d.ts
201
+ declare function renderCatalogJson(catalog: SkillCatalog): string;
202
+ declare const jsonRenderer: CatalogRenderer;
203
+ //#endregion
204
+ //#region src/render/xmlRenderer.d.ts
205
+ /** 转义 XML 五个特殊字符:& < > " ' */
206
+ declare function escapeXml(text: string): string;
207
+ declare function renderAvailableSkillsXml(catalog: SkillCatalog): string;
208
+ declare const xmlRenderer: CatalogRenderer;
209
+ //#endregion
210
+ //#region ../runtime/dist/index.d.ts
211
+ //#region src/llm/streamTypes.d.ts
212
+ /** 流式 LLM 事件(OpenAI SSE / Vercel fullStream 统一映射) */
213
+ type LlmStreamEvent = {
214
+ type: 'text-delta';
215
+ delta: string;
216
+ } | {
217
+ type: 'tool-calls';
218
+ toolCalls: LlmToolCall[];
219
+ } | {
220
+ type: 'done';
221
+ content?: string;
222
+ };
223
+ //#endregion
224
+ //#region src/llm/types.d.ts
225
+ interface LlmMessage {
226
+ role: 'system' | 'user' | 'assistant' | 'tool';
227
+ content: string;
228
+ /** role=tool 时必填 */
229
+ toolCallId?: string;
230
+ /** role=assistant 发起工具调用时携带 */
231
+ toolCalls?: LlmToolCall[];
232
+ }
233
+ interface LlmToolSpec {
234
+ name: string;
235
+ description?: string;
236
+ inputSchema: JsonSchema;
237
+ }
238
+ interface LlmToolCall {
239
+ id: string;
240
+ name: string;
241
+ arguments: Record<string, unknown>;
242
+ }
243
+ interface LlmResponse {
244
+ content?: string;
245
+ toolCalls?: LlmToolCall[];
246
+ raw?: unknown;
247
+ }
248
+ interface LlmCompleteInput {
249
+ model?: string;
250
+ messages: LlmMessage[];
251
+ tools?: LlmToolSpec[];
252
+ temperature?: number;
253
+ signal?: AbortSignal;
254
+ }
255
+ interface LlmClient {
256
+ complete(input: LlmCompleteInput): Promise<LlmResponse>;
257
+ /** 可选流式接口;实现后 AgentLoop 默认走流式(text-delta 增量 + 最终组装) */
258
+ stream?(input: LlmCompleteInput): AsyncIterable<LlmStreamEvent>;
259
+ }
260
+ //#endregion
261
+ //#region src/llm/mockLlmClient.d.ts
262
+ type MockLlmHandler = (input: LlmCompleteInput) => LlmResponse | Promise<LlmResponse>;
263
+ type MockLlmQueueItem = LlmResponse | MockLlmHandler | {
264
+ stream: LlmStreamEvent[] | ((input: LlmCompleteInput) => LlmStreamEvent[]);
265
+ };
266
+ /**
267
+ * 预设响应序列的确定性 LlmClient;handler 形式可按会话状态动态应答。
268
+ * 默认不含 stream(存量行为);构造传 { streaming: true } 启用流式:
269
+ * 队列项 { stream: [...] } 按预设 delta 序列产出,LlmResponse 项自动合成增量。
270
+ */
271
+ declare class MockLlmClient implements LlmClient {
272
+ #private;
273
+ readonly calls: LlmCompleteInput[];
274
+ readonly stream?: (input: LlmCompleteInput) => AsyncIterable<LlmStreamEvent>;
275
+ constructor(responses: MockLlmQueueItem[], options?: {
276
+ streaming?: boolean;
277
+ });
278
+ complete(input: LlmCompleteInput): Promise<LlmResponse>;
279
+ }
280
+ //#endregion
281
+ //#region src/llm/openAiCompatibleClient.d.ts
282
+ interface OpenAiCompatibleClientConfig {
283
+ baseUrl?: string;
284
+ apiKey?: string;
285
+ model?: string;
286
+ /** 可注入 fetch(测试用 mock);缺省用全局 fetch */
287
+ fetchImpl?: typeof fetch;
288
+ /** 单次请求超时(覆盖 fetch 默认 300s;生成大输出的本地模型需要更长时间) */
289
+ requestTimeoutMs?: number;
290
+ }
291
+ /** OpenAI chat completions 协议客户端(兼容端点通用) */
292
+ declare class OpenAiCompatibleClient implements LlmClient {
293
+ #private;
294
+ constructor(config: OpenAiCompatibleClientConfig);
295
+ complete(input: LlmCompleteInput): Promise<LlmResponse>;
296
+ /** SSE 流式:fetch + ReadableStream 按行解析 data: 帧(Node/浏览器通用) */
297
+ stream(input: LlmCompleteInput): AsyncIterable<LlmStreamEvent>;
298
+ /** 轻量探测(GET /models),集成测试据此决定 skip */
299
+ checkAvailability(): Promise<boolean>;
300
+ }
301
+ //#endregion
302
+ //#region src/llm/vercelAiAdapter.d.ts
303
+ /**
304
+ * Vercel AI SDK 适配层:纯数据转换,不 import SDK。
305
+ * duck-type 兼容 SDK 各版本字段差异(inputSchema/parameters、input/args)。
306
+ */
307
+ interface VercelToolSpec {
308
+ description?: string;
309
+ inputSchema: JsonSchema;
310
+ }
311
+ declare function toVercelToolSpecs(tools: LlmToolSpec[]): Record<string, VercelToolSpec>;
312
+ /** 接受 generateText 的返回值形状:{ text?, toolCalls?: [{ toolCallId, toolName, input|args }] } */
313
+ declare function fromVercelResult(result: unknown): LlmResponse;
314
+ /**
315
+ * Vercel streamText fullStream 片段 → LlmStreamEvent 映射。
316
+ * 未知片段类型返回 undefined(调用方跳过)。
317
+ */
318
+ declare function fromVercelStreamPart(part: unknown): LlmStreamEvent | undefined;
319
+ //#endregion
320
+ //#region src/routing/types.d.ts
321
+ interface RouteResult {
322
+ strategy: 'progressive' | 'full-disclosure' | string;
323
+ catalog: SkillCatalog;
324
+ systemPrompt: string;
325
+ }
326
+ interface SkillRouter {
327
+ route(catalog: SkillCatalog): Promise<RouteResult>;
328
+ }
329
+ //#endregion
330
+ //#region src/routing/progressiveRouter.d.ts
331
+ /** 渐进披露路由(默认):system prompt 只注入 Catalog 元数据 + 工具使用说明 */
332
+ declare class ProgressiveRouter implements SkillRouter {
333
+ route(catalog: SkillCatalog): Promise<RouteResult>;
334
+ }
335
+ //#endregion
336
+ //#region src/routing/fullDisclosureRouter.d.ts
337
+ /** 全量披露路由(对照用):注入每个技能的完整 SKILL.md 正文 */
338
+ declare class FullDisclosureRouter implements SkillRouter {
339
+ #private;
340
+ constructor(discovery: SkillDiscovery);
341
+ route(catalog: SkillCatalog): Promise<RouteResult>;
342
+ }
343
+ //#endregion
344
+ //#region src/artifacts/types.d.ts
345
+ interface Artifact {
346
+ id: string;
347
+ runId: string;
348
+ path: string;
349
+ type: 'text' | 'binary';
350
+ mimeType?: string;
351
+ size: number;
352
+ createdAt: string;
353
+ metadata?: Record<string, unknown>;
354
+ }
355
+ interface ArtifactStore {
356
+ createTextArtifact(input: {
357
+ runId: string;
358
+ path: string;
359
+ content: string;
360
+ mimeType?: string;
361
+ metadata?: Record<string, unknown>;
362
+ }): Promise<Artifact>;
363
+ createBinaryArtifact(input: {
364
+ runId: string;
365
+ path: string;
366
+ content: Uint8Array;
367
+ mimeType?: string;
368
+ metadata?: Record<string, unknown>;
369
+ }): Promise<Artifact>;
370
+ listArtifacts(runId: string): Promise<Artifact[]>;
371
+ }
372
+ //#endregion
373
+ //#region src/tools/types.d.ts
374
+ interface ToolDefinition {
375
+ /** LLM 可见名:脚本工具为 `${skillName}__${scriptName}` */
376
+ name: string;
377
+ description?: string;
378
+ /** 缺省即 schemaUnavailable 标记(推导见 deferred-items D2) */
379
+ inputSchema?: JsonSchema;
380
+ source: 'script' | 'mcp' | 'webmcp' | 'builtin';
381
+ skillName?: string;
382
+ }
383
+ interface ToolResult {
384
+ ok: boolean;
385
+ content: Array<{
386
+ type: 'text' | 'json';
387
+ text?: string;
388
+ data?: unknown;
389
+ }>;
390
+ error?: {
391
+ code: string;
392
+ message: string;
393
+ };
394
+ artifacts?: Artifact[];
395
+ }
396
+ interface ScriptExecutionContext {
397
+ skillName: string;
398
+ runId: string;
399
+ readReference(relativePath: string): Promise<string>;
400
+ writeArtifact(path: string, content: string | Uint8Array, options?: {
401
+ mimeType?: string;
402
+ }): Promise<Artifact>;
403
+ /** 脚本主动请求人在环确认;策略见 InteractionPolicy.confirmations */
404
+ confirm?(message: string): Promise<boolean>;
405
+ }
406
+ interface ScriptExecutor {
407
+ loadDefinition(skillRoot: string, scriptName: string): Promise<ToolDefinition>;
408
+ execute(input: {
409
+ skillRoot: string;
410
+ scriptName: string;
411
+ args: Record<string, unknown>;
412
+ context: ScriptExecutionContext;
413
+ timeoutMs: number;
414
+ }): Promise<ToolResult>;
415
+ }
416
+ //#endregion
417
+ //#region src/tools/toolResolver.d.ts
418
+ type ToolResolution = {
419
+ kind: 'script';
420
+ skillName: string;
421
+ scriptName: string;
422
+ } | {
423
+ kind: 'unsupported';
424
+ code: 'TOOL_UNSUPPORTED';
425
+ message: string;
426
+ } | {
427
+ kind: 'not-found';
428
+ code: 'TOOL_NOT_FOUND';
429
+ message: string;
430
+ };
431
+ /**
432
+ * 工具名解析规则(单一实现,Agent 循环使用):
433
+ * 1. `<skillName>__<scriptName>` 且前缀是已激活技能 → 本地脚本
434
+ * 2. `endpoint:` 前缀 → TOOL_UNSUPPORTED(MCP 阶段实现)
435
+ * 3. `mcp#` 前缀 → TOOL_UNSUPPORTED(WebMCP 阶段实现)
436
+ * 4. 其余 → TOOL_NOT_FOUND
437
+ */
438
+ declare function resolveToolName(name: string, activatedSkills: ReadonlySet<string>): ToolResolution;
439
+ /** ToolDefinition → LLM 工具 spec;缺 schema 时用宽松 object 兜底并在描述中标记 */
440
+ declare function toLlmToolSpec(tool: ToolDefinition): LlmToolSpec;
441
+ //#endregion
442
+ //#region src/tools/normalizeContent.d.ts
443
+ /**
444
+ * 脚本返回值归一到 MCP content 格式:数组沿用(逐项归一),
445
+ * 字符串包装为 text,其他值序列化包装。Node/浏览器执行器共享。
446
+ */
447
+ declare function normalizeToolContent(value: unknown): ToolResult['content'];
448
+ //#endregion
449
+ //#region src/tools/readSkillFileTool.d.ts
450
+ declare const READ_SKILL_FILE_TOOL_NAME = "read_skill_file";
451
+ declare const READ_SKILL_FILE_INPUT_SCHEMA: JsonSchema;
452
+ /** 内置工具:读取技能文件(读 SKILL.md 是技能激活的入口) */
453
+ declare const READ_SKILL_FILE_TOOL: ToolDefinition;
454
+ //#endregion
455
+ //#region src/tools/askUserTool.d.ts
456
+ declare const ASK_USER_TOOL_NAME = "ask_user";
457
+ declare const ASK_USER_INPUT_SCHEMA: JsonSchema;
458
+ /** 内建工具:LLM 信息不足时主动向用户提问;仅当配置了 UiBridge 时注册 */
459
+ declare const ASK_USER_TOOL: ToolDefinition;
460
+ //#endregion
461
+ //#region src/tools/scriptContext.d.ts
462
+ /**
463
+ * 脚本执行上下文:只暴露 readReference / writeArtifact 两个显式能力,
464
+ * 不暴露 fs 本体(沙箱语义,对齐 deferred-items D1)。
465
+ */
466
+ declare function createScriptContext(deps: {
467
+ fs: FileSystemProvider;
468
+ artifactStore: ArtifactStore;
469
+ skillName: string;
470
+ skillRoot: string;
471
+ runId: string;
472
+ /** 提供时暴露 context.confirm(由引擎按交互策略实现) */
473
+ confirm?: (message: string) => Promise<boolean>;
474
+ }): ScriptExecutionContext;
475
+ //#endregion
476
+ //#region src/interaction/types.d.ts
477
+ type InteractionRequest = {
478
+ type: 'ask';
479
+ id: string;
480
+ message: string;
481
+ schema?: JsonSchema;
482
+ } | {
483
+ type: 'confirm';
484
+ id: string;
485
+ message: string;
486
+ defaultValue?: boolean;
487
+ } | {
488
+ type: 'form';
489
+ id: string;
490
+ title?: string;
491
+ fields: FormField[];
492
+ } | {
493
+ type: 'select';
494
+ id: string;
495
+ message: string;
496
+ options: Array<{
497
+ label: string;
498
+ value: unknown;
499
+ }>;
500
+ };
501
+ interface InteractionResponse {
502
+ id: string;
503
+ value?: unknown;
504
+ cancelled?: boolean;
505
+ }
506
+ type RenderBlock = {
507
+ type: 'markdown';
508
+ text: string;
509
+ } | {
510
+ type: 'json';
511
+ data: unknown;
512
+ } | {
513
+ type: 'table';
514
+ columns: string[];
515
+ rows: unknown[][];
516
+ } | {
517
+ type: 'image';
518
+ url: string;
519
+ alt?: string;
520
+ } | {
521
+ type: 'file';
522
+ path: string;
523
+ mimeType?: string;
524
+ size?: number;
525
+ };
526
+ interface RenderResultRequest {
527
+ runId: string;
528
+ title?: string;
529
+ summary?: string;
530
+ blocks: RenderBlock[];
531
+ artifacts?: Artifact[];
532
+ }
533
+ interface UiBridge {
534
+ request(input: InteractionRequest): Promise<InteractionResponse>;
535
+ progress?(input: {
536
+ runId: string;
537
+ message: string;
538
+ value?: number;
539
+ }): Promise<void>;
540
+ /** 定义即可,阶段 7 消费 */
541
+ renderResult?(input: RenderResultRequest): Promise<void>;
542
+ /** 流式文本增量(流式 LLM 路径下由 AgentLoop 转发) */
543
+ onTextDelta?(runId: string, delta: string): Promise<void> | void;
544
+ }
545
+ interface FormField {
546
+ name: string;
547
+ label: string;
548
+ type: 'text' | 'number' | 'boolean' | 'select' | 'textarea';
549
+ required?: boolean;
550
+ description?: string;
551
+ defaultValue?: unknown;
552
+ options?: Array<{
553
+ label: string;
554
+ value: unknown;
555
+ }>;
556
+ }
557
+ interface InteractionPolicy {
558
+ /** 缺必填参数策略:默认 'user'(表单问用户),'llm' 回喂自愈 */
559
+ missingParams?: 'user' | 'llm';
560
+ /** context.confirm 策略:默认 'required'(真实询问) */
561
+ confirmations?: 'required' | 'auto-approve';
562
+ /** 交互超时,默认 300_000ms */
563
+ interactionTimeoutMs?: number;
564
+ }
565
+ //#endregion
566
+ //#region src/lifecycle/types.d.ts
567
+ type RuntimePhase = 'discover' | 'route' | 'activate' | 'prepare' | 'execute' | 'observe' | 'interact' | 'complete' | 'fail';
568
+ interface LifecycleEvent {
569
+ phase: RuntimePhase;
570
+ runId: string;
571
+ sessionId: string;
572
+ ts: string;
573
+ data?: Record<string, unknown>;
574
+ }
575
+ interface LifecycleHookContext {
576
+ event: LifecycleEvent;
577
+ run: RuntimeRun;
578
+ }
579
+ type LifecycleHook = (ctx: LifecycleHookContext) => Promise<void | {
580
+ metadata?: Record<string, unknown>;
581
+ }>;
582
+ //#endregion
583
+ //#region src/trace/types.d.ts
584
+ type TraceEventType = 'skill.routed' | 'skill.activated' | 'llm.request' | 'llm.response' | 'tool.started' | 'tool.completed' | 'tool.failed' | 'artifact.created' | 'ui.requested' | 'ui.resumed' | 'ui.rendered' | 'run.warning' | 'run.completed' | 'run.cancelled' | 'run.failed';
585
+ interface TraceEvent {
586
+ id: string;
587
+ runId: string;
588
+ ts: string;
589
+ type: TraceEventType;
590
+ message?: string;
591
+ data?: Record<string, unknown>;
592
+ }
593
+ //#endregion
594
+ //#region src/engine/types.d.ts
595
+ interface AgentLoopConfig {
596
+ /** 默认 10 */
597
+ maxTurns?: number;
598
+ /** 默认 120_000 */
599
+ totalTimeoutMs?: number;
600
+ /** 默认 30_000 */
601
+ toolTimeoutMs?: number;
602
+ temperature?: number;
603
+ /** 设为 'off' 时完成 run 不调用 uiBridge.renderResult */
604
+ renderResult?: 'off';
605
+ }
606
+ interface RuntimeSession {
607
+ id: string;
608
+ createdAt: string;
609
+ }
610
+ type RunTerminationReason = 'final-answer' | 'max-turns' | 'timeout' | 'llm-error' | 'interaction-timeout' | 'user-cancelled' | 'hook-error';
611
+ interface RuntimeRun {
612
+ id: string;
613
+ sessionId: string;
614
+ status: 'running' | 'interrupted' | 'completed' | 'failed' | 'cancelled';
615
+ phase: RuntimePhase;
616
+ userPrompt: string;
617
+ startedAt: string;
618
+ endedAt?: string;
619
+ terminationReason?: RunTerminationReason;
620
+ /** interrupted 状态下的交互过期时间 */
621
+ interruptExpiresAt?: string;
622
+ activeSkillNames: string[];
623
+ artifacts: Artifact[];
624
+ trace: TraceEvent[];
625
+ }
626
+ interface RunResult {
627
+ output: string;
628
+ run: RuntimeRun;
629
+ }
630
+ //#endregion
631
+ //#region src/interaction/renderResult.d.ts
632
+ /**
633
+ * 默认的结果渲染构造:LLM 最终输出 → markdown block,
634
+ * run.artifacts → file blocks;summary 取 terminationReason。
635
+ */
636
+ declare function buildRenderResult(run: RuntimeRun, output: string): RenderResultRequest;
637
+ //#endregion
638
+ //#region src/interaction/schemaToForm.d.ts
639
+ /**
640
+ * JsonSchema → 表单模型:按 properties 生成字段,required 标记必填;
641
+ * providedArgs 已有的值作为 defaultValue 预填(表单只为补齐缺失项服务)。
642
+ * type 映射:string→text、number/integer→number、boolean→boolean、enum→select、其余→textarea。
643
+ */
644
+ declare function schemaToForm(schema: JsonSchema, providedArgs?: Record<string, unknown>): FormField[];
645
+ //#endregion
646
+ //#region src/interaction/mockUiBridge.d.ts
647
+ type MockUiAnswer = InteractionResponse | ((request: InteractionRequest) => InteractionResponse | Promise<InteractionResponse>);
648
+ /**
649
+ * 测试用 UiBridge:按请求 id 或类型预设应答(永不 resolve 的 handler 可模拟超时);
650
+ * 记录全部请求供断言。
651
+ */
652
+ declare class MockUiBridge implements UiBridge {
653
+ #private;
654
+ readonly requests: InteractionRequest[];
655
+ /** key 为请求 id 或请求类型('ask' | 'confirm' | 'form' | 'select') */
656
+ respondTo(key: string, answer: MockUiAnswer): this;
657
+ setFallback(answer: MockUiAnswer): this;
658
+ request(input: InteractionRequest): Promise<InteractionResponse>;
659
+ }
660
+ //#endregion
661
+ //#region src/lifecycle/eventBus.d.ts
662
+ type LifecycleListener = (event: LifecycleEvent) => void;
663
+ /** 生命周期事件总线:只读观测,支持按阶段或通配订阅 */
664
+ declare class EventBus {
665
+ #private;
666
+ /** 返回取消订阅函数 */
667
+ on(phase: RuntimePhase | '*', listener: LifecycleListener): () => void;
668
+ /** 当前订阅者数量(流式 delta 零订阅零开销判断用) */
669
+ listenerCount(): number;
670
+ emit(event: LifecycleEvent): void;
671
+ }
672
+ //#endregion
673
+ //#region src/lifecycle/hooks.d.ts
674
+ interface HookRunnerOptions {
675
+ /** 单钩子超时,默认 5000ms;超时降级为 warning 继续 */
676
+ timeoutMs?: number;
677
+ /** true 时钩子异常终止 run(RUN_FAILED);默认隔离记 warning */
678
+ failOnHookError?: boolean;
679
+ /** 降级 warning 出口(引擎接线到 trace) */
680
+ onWarning?: (message: string) => void;
681
+ }
682
+ /** 受控钩子执行器:逐个执行,超时/异常默认降级为 warning,可切严格模式 */
683
+ declare class HookRunner {
684
+ #private;
685
+ readonly timeoutMs: number;
686
+ readonly failOnHookError: boolean;
687
+ onWarning?: (message: string) => void;
688
+ constructor(options?: HookRunnerOptions);
689
+ register(phase: RuntimePhase | '*', hook: LifecycleHook): this;
690
+ run(phase: RuntimePhase, ctx: LifecycleHookContext): Promise<void>;
691
+ }
692
+ //#endregion
693
+ //#region src/memory/types.d.ts
694
+ /** scope/key 两级记忆存储;scope 约定:session:{id} / skill:{name} / user:{id} */
695
+ interface MemoryStore {
696
+ get(scope: string, key: string): Promise<unknown>;
697
+ set(scope: string, key: string, value: unknown): Promise<void>;
698
+ delete(scope: string, key: string): Promise<void>;
699
+ list(scope: string): Promise<Array<{
700
+ key: string;
701
+ value: unknown;
702
+ }>>;
703
+ clear(scope?: string): Promise<void>;
704
+ }
705
+ //#endregion
706
+ //#region src/memory/inMemoryStore.d.ts
707
+ /** 内存 MemoryStore:测试与浏览器降级用 */
708
+ declare class InMemoryStore implements MemoryStore {
709
+ #private;
710
+ get(scope: string, key: string): Promise<unknown>;
711
+ set(scope: string, key: string, value: unknown): Promise<void>;
712
+ delete(scope: string, key: string): Promise<void>;
713
+ list(scope: string): Promise<Array<{
714
+ key: string;
715
+ value: unknown;
716
+ }>>;
717
+ clear(scope?: string): Promise<void>;
718
+ }
719
+ //#endregion
720
+ //#region src/memory/fsMemoryStore.d.ts
721
+ /**
722
+ * 基于 FileSystemProvider 的 MemoryStore:
723
+ * <root>/<encodeURIComponent(scope)>/<encodeURIComponent(key)>.json
724
+ * scope/key 全部编码防路径穿越;环境无关,构造必须显式传 fs。
725
+ */
726
+ declare class FsMemoryStore implements MemoryStore {
727
+ #private;
728
+ constructor(deps: {
729
+ root: string;
730
+ fs: FileSystemProvider;
731
+ });
732
+ get(scope: string, key: string): Promise<unknown>;
733
+ set(scope: string, key: string, value: unknown): Promise<void>;
734
+ delete(scope: string, key: string): Promise<void>;
735
+ list(scope: string): Promise<Array<{
736
+ key: string;
737
+ value: unknown;
738
+ }>>;
739
+ clear(scope?: string): Promise<void>;
740
+ }
741
+ //#endregion
742
+ //#region src/artifacts/memoryArtifactStore.d.ts
743
+ /** 内存 ArtifactStore:测试与浏览器降级用;索引随进程生命周期存在 */
744
+ declare class MemoryArtifactStore implements ArtifactStore {
745
+ #private;
746
+ createTextArtifact(input: {
747
+ runId: string;
748
+ path: string;
749
+ content: string;
750
+ mimeType?: string;
751
+ metadata?: Record<string, unknown>;
752
+ }): Promise<Artifact>;
753
+ createBinaryArtifact(input: {
754
+ runId: string;
755
+ path: string;
756
+ content: Uint8Array;
757
+ mimeType?: string;
758
+ metadata?: Record<string, unknown>;
759
+ }): Promise<Artifact>;
760
+ listArtifacts(runId: string): Promise<Artifact[]>;
761
+ }
762
+ //#endregion
763
+ //#region src/artifacts/fsArtifactStore.d.ts
764
+ /**
765
+ * 基于 FileSystemProvider 的 ArtifactStore:产物落盘 <root>/<runId>/<path>,
766
+ * 每次写入同步更新 <root>/<runId>/index.json,新实例可凭索引恢复列表。
767
+ * 环境无关(OPFS/Node 均可),构造必须显式传 fs。
768
+ */
769
+ declare class FsArtifactStore implements ArtifactStore {
770
+ #private;
771
+ constructor(deps: {
772
+ root: string;
773
+ fs: FileSystemProvider;
774
+ });
775
+ createTextArtifact(input: {
776
+ runId: string;
777
+ path: string;
778
+ content: string;
779
+ mimeType?: string;
780
+ metadata?: Record<string, unknown>;
781
+ }): Promise<Artifact>;
782
+ createBinaryArtifact(input: {
783
+ runId: string;
784
+ path: string;
785
+ content: Uint8Array;
786
+ mimeType?: string;
787
+ metadata?: Record<string, unknown>;
788
+ }): Promise<Artifact>;
789
+ listArtifacts(runId: string): Promise<Artifact[]>;
790
+ }
791
+ //#endregion
792
+ //#region src/sandbox/bridgeProtocol.d.ts
793
+ /** 能力桥 RPC 消息类型 + 入站校验(Worker 沙箱 ↔ 宿主;browser/node 共用单一来源) */
794
+ type BridgeRequest = {
795
+ kind: 'readReference';
796
+ id: string;
797
+ path: string;
798
+ } | {
799
+ kind: 'writeArtifact';
800
+ id: string;
801
+ path: string;
802
+ content: string | number[];
803
+ mimeType?: string;
804
+ } | {
805
+ kind: 'confirm';
806
+ id: string;
807
+ message: string;
808
+ };
809
+ interface BridgeResponse {
810
+ id: string;
811
+ ok: boolean;
812
+ value?: unknown;
813
+ error?: {
814
+ code: string;
815
+ message: string;
816
+ };
817
+ }
818
+ /** 三能力独立开关;缺省全开,显式 false 即关闭(TOOL_UNSUPPORTED) */
819
+ interface BridgeCapabilities {
820
+ readReference?: boolean;
821
+ writeArtifact?: boolean;
822
+ confirm?: boolean;
823
+ }
824
+ /** 入站校验:非法 kind / 缺 id / 缺字段 → undefined(调用方忽略并记 warning) */
825
+ declare function parseBridgeRequest(data: unknown): BridgeRequest | undefined;
826
+ declare function bridgeError(id: string, code: string, message: string): BridgeResponse;
827
+ //#endregion
828
+ //#region src/trace/traceRecorder.d.ts
829
+ interface TraceClock {
830
+ now?: () => string;
831
+ createId?: () => string;
832
+ }
833
+ /** 结构化 trace 记录器;时钟与 id 工厂可注入(golden trace 用固定值保证确定性) */
834
+ declare class TraceRecorder {
835
+ #private;
836
+ constructor(runId: string, clock?: TraceClock);
837
+ record(type: TraceEventType, opts?: {
838
+ message?: string;
839
+ data?: Record<string, unknown>;
840
+ }): TraceEvent;
841
+ list(): TraceEvent[];
842
+ }
843
+ //#endregion
844
+ //#region src/engine/external.d.ts
845
+ /**
846
+ * 外部工具来源(runtime 扩展点,mcp 包实现并插入)。
847
+ * LLM 可见名为已消毒名(如 endpoint__greet / mcp__search)。
848
+ */
849
+ interface ExternalToolSource {
850
+ readonly kind: string;
851
+ listToolSpecs(): Promise<LlmToolSpec[]>;
852
+ canHandle(llmToolName: string): boolean;
853
+ call(llmToolName: string, args: Record<string, unknown>): Promise<ToolResult>;
854
+ }
855
+ /** 外部技能提供者(页面动态技能等;技能随来源生灭,不持久化) */
856
+ interface ExternalSkillProvider {
857
+ listSkills(): Promise<SkillCatalogEntry[]>;
858
+ loadSkill(name: string): Promise<SkillDocument>;
859
+ readFile?(name: string, relativePath: string): Promise<string>;
860
+ }
861
+ /**
862
+ * Catalog 合并:同名本地优先;外部条目的 mcp:// 根 URI 保留,
863
+ * 调用方可凭 URI 强制选择外部技能(绕过本地优先)。
864
+ */
865
+ declare function mergeCatalogEntries(localEntries: SkillCatalogEntry[], providerEntries: SkillCatalogEntry[]): SkillCatalogEntry[];
866
+ //#endregion
867
+ //#region src/engine/agentLoop.d.ts
868
+ interface AgentLoopDeps {
869
+ llm: LlmClient;
870
+ executor: ScriptExecutor;
871
+ artifactStore: ArtifactStore;
872
+ fs: FileSystemProvider;
873
+ /** name → skillRoot(来自发现结果) */
874
+ skillIndex: Map<string, string>;
875
+ model?: string;
876
+ /** 时钟与 id 工厂注入点(golden trace 用固定值) */
877
+ clock?: TraceClock;
878
+ uiBridge?: UiBridge;
879
+ interaction?: InteractionPolicy;
880
+ memory?: MemoryStore;
881
+ hooks?: HookRunner;
882
+ eventBus?: EventBus;
883
+ /** 长期记忆(user scope);默认关闭,关闭时零持久化写入 */
884
+ longTerm?: {
885
+ enabled: true;
886
+ userId: string;
887
+ };
888
+ /** 外部工具来源(mcp 插件等);specs 在 run 开始时并入每轮 tools */
889
+ externalTools?: ExternalToolSource[];
890
+ /** 外部技能提供者(页面动态技能等) */
891
+ skillProviders?: ExternalSkillProvider[];
892
+ /** Catalog 过滤钩子(治理状态拦截路由,如 quarantined/deprecated 过滤) */
893
+ catalogFilter?: (entries: SkillCatalogEntry[]) => SkillCatalogEntry[] | Promise<SkillCatalogEntry[]>;
894
+ }
895
+ /**
896
+ * 多轮 Agent 循环。
897
+ * 工具失败一律转为 ToolResult{ok:false} 回喂 LLM 继续循环;
898
+ * 缺参/确认/提问经 UiBridge 行内 await 暂停恢复;取消/超时/LLM 异常/护栏超限才终止 run。
899
+ */
900
+ declare class AgentLoop {
901
+ #private;
902
+ constructor(deps: AgentLoopDeps, config?: AgentLoopConfig);
903
+ run(input: {
904
+ sessionId: string;
905
+ userPrompt: string;
906
+ route: RouteResult;
907
+ runId?: string;
908
+ }): Promise<RunResult>;
909
+ }
910
+ //#endregion
911
+ //#region src/engine/runtime.d.ts
912
+ interface WebSkillRuntimeDeps {
913
+ fs: FileSystemProvider;
914
+ roots: string[];
915
+ llm: LlmClient;
916
+ /** 缺省 ProgressiveRouter */
917
+ router?: SkillRouter;
918
+ executor: ScriptExecutor;
919
+ artifactStore: ArtifactStore;
920
+ config?: AgentLoopConfig;
921
+ model?: string;
922
+ uiBridge?: UiBridge;
923
+ interaction?: InteractionPolicy;
924
+ memory?: MemoryStore;
925
+ hooks?: HookRunner;
926
+ eventBus?: EventBus;
927
+ /** 长期记忆(user scope);默认关闭 */
928
+ longTerm?: {
929
+ enabled: true;
930
+ userId: string;
931
+ };
932
+ /** 外部工具来源(mcp 插件等) */
933
+ externalTools?: ExternalToolSource[];
934
+ /** 外部技能提供者(页面动态技能等);Catalog 合并同名本地优先 */
935
+ skillProviders?: ExternalSkillProvider[];
936
+ /** Catalog 过滤钩子(治理状态拦截路由) */
937
+ catalogFilter?: (entries: SkillCatalogEntry[]) => SkillCatalogEntry[] | Promise<SkillCatalogEntry[]>;
938
+ /** opt-in:run 完成且未激活任何技能时回调(默认关闭,fire-and-forget) */
939
+ onSkillMiss?: (input: {
940
+ prompt: string;
941
+ run: RunResult['run'];
942
+ }) => Promise<void>;
943
+ }
944
+ /** runtime 门面:组合 discovery / router / agent loop / lifecycle */
945
+ declare class WebSkillRuntime {
946
+ #private;
947
+ constructor(deps: WebSkillRuntimeDeps);
948
+ get session(): RuntimeSession;
949
+ /** 生命周期事件总线(只读观测) */
950
+ get events(): EventBus;
951
+ discover(): Promise<DiscoveryResult>;
952
+ run(userPrompt: string): Promise<RunResult>;
953
+ }
954
+ //#endregion
955
+ export { RunTerminationReason as $, jsonRenderer as $t, LlmCompleteInput as A, DiscoveryResult as At, MockLlmQueueItem as B, SkillDocument as Bt, InteractionRequest as C, normalizeToolContent as Ct, LifecycleHookContext as D, toLlmToolSpec as Dt, LifecycleHook as E, schemaToForm as Et, LlmToolSpec as F, SKILL_NAME_MAX_LENGTH as Ft, ProgressiveRouter as G, SkillSource as Gt, MockUiBridge as H, SkillLocation as Ht, MemoryArtifactStore as I, SKILL_NAME_PATTERN as It, READ_SKILL_FILE_TOOL_NAME as J, WebSkillErrorCode as Jt, READ_SKILL_FILE_INPUT_SCHEMA as K, ValidationReport as Kt, MemoryStore as L, SkillCatalog as Lt, LlmResponse as M, FileSystemProvider as Mt, LlmStreamEvent as N, JsonSchema as Nt, LifecycleListener as O, toVercelToolSpecs as Ot, LlmToolCall as P, MemoryFS as Pt, RunResult as Q, isValidSkillName as Qt, MockLlmClient as R, SkillCatalogEntry as Rt, InteractionPolicy as S, mergeCatalogEntries as St, LifecycleEvent as T, resolveToolName as Tt, OpenAiCompatibleClient as U, SkillMetadata as Ut, MockUiAnswer as V, SkillIssue as Vt, OpenAiCompatibleClientConfig as W, SkillReader as Wt, RenderResultRequest as X, checkSkillRules as Xt, RenderBlock as Y, buildCatalog as Yt, RouteResult as Z, escapeXml as Zt, FsMemoryStore as _, bridgeError as _t, AgentLoopConfig as a, validateSkills as an, SkillRouter as at, HookRunnerOptions as b, fromVercelResult as bt, ArtifactStore as c, ToolResult as ct, BridgeResponse as d, TraceEventType as dt, normalizePath as en, RuntimePhase as et, EventBus as f, TraceRecorder as ft, FsArtifactStore as g, WebSkillRuntimeDeps as gt, FormField as h, WebSkillRuntime as ht, AgentLoop as i, resolveInsideRoot as in, ScriptExecutor as it, LlmMessage as j, FileStat as jt, LlmClient as k, CatalogRenderer as kt, BridgeCapabilities as l, TraceClock as lt, ExternalToolSource as m, VercelToolSpec as mt, ASK_USER_TOOL as n, renderAvailableSkillsXml as nn, RuntimeSession as nt, AgentLoopDeps as o, xmlRenderer as on, ToolDefinition as ot, ExternalSkillProvider as p, UiBridge as pt, READ_SKILL_FILE_TOOL as q, WebSkillError as qt, ASK_USER_TOOL_NAME as r, renderCatalogJson as rn, ScriptExecutionContext as rt, Artifact as s, ToolResolution as st, ASK_USER_INPUT_SCHEMA as t, parseSkillMarkdown as tn, RuntimeRun as tt, BridgeRequest as u, TraceEvent as ut, FullDisclosureRouter as v, buildRenderResult as vt, InteractionResponse as w, parseBridgeRequest as wt, InMemoryStore as x, fromVercelStreamPart as xt, HookRunner as y, createScriptContext as yt, MockLlmHandler as z, SkillDiscovery as zt };