@webskill/sdk 0.4.0 → 0.6.0

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.
Files changed (35) hide show
  1. package/dist/agent.d.ts +2 -0
  2. package/dist/agent.js +909 -0
  3. package/dist/browser.d.ts +233 -4
  4. package/dist/browser.js +869 -19
  5. package/dist/{catalogComponents-KsujmL4b-Clx1kCnU.js → catalogComponents-Dr5dFMAb-Dacibl1e.js} +372 -126
  6. package/dist/{dist-D9Lcn5Pp.js → dist-DnYG2-eY.js} +642 -39
  7. package/dist/{dist-C-Sh0MDU.js → dist-DusANsrn.js} +1035 -99
  8. package/dist/{env--jJB-TSX-04klhTYi.js → env-8cY40DXB-CGnEVZby.js} +7 -6
  9. package/dist/{env-BPUBZCwJ-4jat_SVG.d.ts → env-AK3cSMEA-Dli6QU5E.d.ts} +4 -3
  10. package/dist/governance.d.ts +46 -4
  11. package/dist/governance.js +45 -2
  12. package/dist/{index-CHXxDccV.d.ts → index-BMocOEi0.d.ts} +106 -10
  13. package/dist/index-BuTpBMzr.d.ts +474 -0
  14. package/dist/{index-DLfR2Y6I.d.ts → index-C-KFAZoF.d.ts} +337 -18
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +3 -3
  17. package/dist/mcp.d.ts +39 -8
  18. package/dist/mcp.js +53 -19
  19. package/dist/{memoryArtifactStore-BtOeB_hm-tj3fC5ip.js → memoryArtifactStore-52Zn9npI-BMPYwvoy.js} +10 -2
  20. package/dist/node.d.ts +4 -4
  21. package/dist/node.js +9 -2
  22. package/dist/{openUiLibrary-YLS-cxyT-C96jWDQq.js → openUiLibrary-Bdrji9qK-DzAxRlTY.js} +3 -3
  23. package/dist/{skillVersionStore-uyefLPR1-DXOzbksv.d.ts → skillVersionStore-BzLbzFOL-CxdAFWO2.d.ts} +4 -3
  24. package/dist/{testing-DDCJWvgA.js → testing-CYTFqkDm.js} +1 -1
  25. package/dist/testing.d.ts +2 -2
  26. package/dist/testing.js +3 -3
  27. package/dist/{types-7Wcg--Vh-1YlQ4jF9.d.ts → types-4pg-qp_I-Gq63X8Oa.d.ts} +55 -5
  28. package/dist/ui-react.d.ts +26 -5
  29. package/dist/ui-react.js +147 -29
  30. package/dist/ui-vue.d.ts +1 -1
  31. package/dist/ui-vue.js +30 -6
  32. package/dist/ui.d.ts +4 -4
  33. package/dist/ui.js +3 -3
  34. package/dist/{webskillLitCatalog-CSTbhBe_-CYIs5BX8.js → webskillLitCatalog-_mugzRHx-B_54vxum.js} +88 -2
  35. package/package.json +6 -1
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { D as ArchiveLimits, M as FileStat, N as FileSystemProvider, a as InteractionPolicy, c as LlmClient, et as SkillInstallSource, f as LlmResponse, gt as VerifyResult, it as SkillManifest, o as InteractionRequest, p as LlmStreamEvent, s as InteractionResponse, ut as SkillsLockfile, v as RenderResultRequest, y as UiBridge } from "./types-7Wcg--Vh-1YlQ4jF9.js";
2
- import { Dt as ToolDefinition, It as WebSkillApi, V as NetworkPolicy, b as ExternalSkillProvider, d as ApprovalScope, f as BridgeCapabilities, gt as ScriptExecutor, h as BridgeResponse, ht as ScriptExecutionContext, kt as ToolResult, m as BridgeRequest, tn as parseBridgeRequest, x as ExternalToolSource, zt as bridgeError } from "./index-DLfR2Y6I.js";
1
+ import { N as FileStat, O as ArchiveLimits, P as FileSystemProvider, _ as MemoryStore, _t as VerifyResult, at as SkillManifest, b as UiBridge, c as InteractionResponse, dt as SkillsLockfile, ht as UnsignedPolicy, l as LlmClient, m as LlmStreamEvent, o as InteractionPolicy, p as LlmResponse, pt as TrustedKeyStore, s as InteractionRequest, tt as SkillInstallSource, u as LlmCompleteInput, vt as WebSkillError, y as RenderResultRequest } from "./types-4pg-qp_I-Gq63X8Oa.js";
2
+ import { Ct as ScriptExecutionContext, D as ExternalSkillProvider, J as NetworkPolicy, Mn as parseBridgeRequest, O as ExternalToolSource, Ut as ToolResult, Vt as ToolDefinition, _ as BridgeCapabilities, an as WebSkillApi, b as BridgeResponse, f as ApprovalScope, un as bridgeError, wt as ScriptExecutor, y as BridgeRequest } from "./index-C-KFAZoF.js";
3
+ import { C as PerceptionCaptureOptions, E as PerceptionScope, T as PerceptionResult, _ as PagePerceptionReader, x as PerceivedNode } from "./index-BuTpBMzr.js";
3
4
  //#region ../browser/dist/index.d.ts
4
5
  //#region src/fs/featureDetection.d.ts
5
6
  /** 检测当前环境是否可用 OPFS(navigator.storage.getDirectory) */
@@ -69,7 +70,7 @@ declare class TsTranspiler {
69
70
  options: TypeScriptSupportOptions;
70
71
  cacheDir?: string;
71
72
  });
72
- /** 返回 JS 源码;转译失败TOOL_EXECUTION_FAILED(带 esbuild 诊断) */
73
+ /** 返回 JS 源码;转译器不可用TS_TRANSPILER_UNAVAILABLE,语法错 TS_TRANSPILE_FAILED */
73
74
  transpile(scriptPath: string, source: string): Promise<string>;
74
75
  }
75
76
  //#endregion
@@ -90,6 +91,23 @@ declare class BrowserSkillManager {
90
91
  archiveLimits?: ArchiveLimits;
91
92
  /** install/uninstall 成功后的变更回调(宿主接线缓存失效,如 WebSkillRuntime.invalidate) */
92
93
  onChanged?: () => void;
94
+ /**
95
+ * 供应链信任,与 Node 侧 `SkillManager` 同形状。未注入时仍然验签,
96
+ * 只是信任库为空:未签名包按 `unsigned` 处置,带不受信公钥的包装不上。
97
+ */
98
+ signature?: {
99
+ trustedKeys?: TrustedKeyStore;
100
+ /**
101
+ * 未签名包的处置,默认 `warn`。收成 `deny` 必须同时注入 `trustedKeys`:
102
+ * 空信任库 + deny 的接受集为空,任何包都装不上。
103
+ */
104
+ unsigned?: UnsignedPolicy;
105
+ };
106
+ /** 安装期告警(当前仅未签名放行);宿主接线日志/UI */
107
+ onWarning?: (warning: {
108
+ skill: string;
109
+ message: string;
110
+ }) => void;
93
111
  });
94
112
  install(source: SkillInstallSource, options?: {
95
113
  expectedSha256?: string;
@@ -217,6 +235,182 @@ declare function installWebSkillNavigator(config: {
217
235
  };
218
236
  }): WebSkillApi;
219
237
  //#endregion
238
+ //#region src/llm/chromeBuiltinClient.d.ts
239
+ /**
240
+ * Chrome 内置模型(Prompt API)的可用性。`reason` 直接进 UI 文案——
241
+ * FR-4.7 要求「选之前就知道为什么不能选」,所以不可用必须带具体原因。
242
+ */
243
+ type ChromeBuiltinAvailability = {
244
+ available: true;
245
+ } | {
246
+ available: false;
247
+ reason: 'api-missing' | 'model-not-ready' | 'unsupported-browser';
248
+ };
249
+ /**
250
+ * 进入模型配置界面时调用(FR-4.7):不可用时给出具体原因,禁止「选了之后才失败」。
251
+ * 模型还在下载也算不可用——这一轮对话等不到它。
252
+ */
253
+ declare function probeChromeBuiltinAvailability(): Promise<ChromeBuiltinAvailability>;
254
+ /**
255
+ * 浏览器内置模型客户端(Prompt API)。**不支持工具调用**——`input.tools` 被忽略,
256
+ * 模型只会产出文本,因此技能里的脚本步骤在这一档跑不起来(FR-4.8 要求 UI 标注该限制)。
257
+ * @experimental
258
+ */
259
+ declare class ChromeBuiltinLlmClient implements LlmClient {
260
+ #private;
261
+ constructor(options?: {
262
+ temperature?: number;
263
+ });
264
+ complete(input: LlmCompleteInput): Promise<LlmResponse>;
265
+ stream(input: LlmCompleteInput): AsyncIterable<LlmStreamEvent>;
266
+ checkAvailability(): Promise<boolean>;
267
+ }
268
+ //#endregion
269
+ //#region src/llm/createLlmClient.d.ts
270
+ /**
271
+ * 构造客户端所需的最小配置。刻意声明成结构而不是 import `@webskill/ui-kit` 的
272
+ * `RuntimeLlmEntry`:ui-kit 是 React 层,运行时包不该反向依赖它。两者结构兼容。
273
+ */
274
+ interface LlmEntryConfig {
275
+ provider: 'openai-compatible' | 'anthropic' | 'google' | 'chrome-builtin';
276
+ baseUrl?: string;
277
+ apiKey?: string;
278
+ model: string;
279
+ requestTimeoutMs?: number;
280
+ }
281
+ /** 四档客户端都能自查可达性,所以工厂的返回类型直接把探测能力算进契约 */
282
+ type ConfiguredLlmClient = LlmClient & {
283
+ checkAvailability(): Promise<boolean>;
284
+ };
285
+ /**
286
+ * 配置 → `LlmClient`。收在 SDK 里是为了让下游只跟 `RuntimeConfigStore` 打交道,
287
+ * 不必自己维护「provider → client 类」的映射(设计 04 §5)。
288
+ */
289
+ declare function createLlmClient(config: LlmEntryConfig): ConfiguredLlmClient;
290
+ //#endregion
291
+ //#region src/media/dictation.d.ts
292
+ /**
293
+ * 语音识别的可用性(FR-7.2)。`reason` 直接进 UI 文案:
294
+ * 按钮必须在**渲染期**就知道自己能不能用,不允许「点了才失败」。
295
+ * @experimental
296
+ */
297
+ type DictationAvailability = {
298
+ available: true;
299
+ } | {
300
+ available: false;
301
+ reason: 'api-missing' | 'insecure-context';
302
+ };
303
+ /** 一次录音的句柄;`stop()` 后不再回调任何结果(FR-7.5) @experimental */
304
+ interface DictationSession {
305
+ stop(): void;
306
+ }
307
+ /** @experimental */
308
+ interface DictationOptions {
309
+ /** BCP-47 识别语言(FR-7.7),例如 `en-US` / `zh-CN` */
310
+ lang: string;
311
+ /** 尚未定稿的片段,用于录音中的实时回显(FR-7.4) */
312
+ onInterim(text: string): void;
313
+ /** 定稿片段;同一次录音可能触发多次 */
314
+ onFinal(text: string): void;
315
+ onError(error: WebSkillError): void;
316
+ }
317
+ /**
318
+ * 渲染期调用(FR-7.2):不可用时按钮置灰并说明原因,禁止呈现为可用后才失败。
319
+ *
320
+ * 顺序是刻意的——构造器都不存在时谈安全上下文没有意义;
321
+ * 构造器在但站点是 http,识别一定会被浏览器拒绝,这条原因用户能自己解决。
322
+ * @experimental
323
+ */
324
+ declare function checkDictationAvailability(): DictationAvailability;
325
+ /**
326
+ * 开始一次语音识别(FR-7.1)。
327
+ *
328
+ * **只能由用户手势调用**(FR-7.3)。设计上的保证是它不进工具列表:
329
+ * agent 拿不到「开始录音」这个动作,因此不存在自主开麦的路径。
330
+ * @experimental
331
+ */
332
+ declare function startDictation(options: DictationOptions): DictationSession;
333
+ //#endregion
334
+ //#region src/media/compressImage.d.ts
335
+ /** 图片压缩结果;`originalBytes`/`compressedBytes` 供 UI 显示「3.2 MB → 1.8 MB」(FR-11.3 可见性) */
336
+ interface CompressResult {
337
+ blob: Blob;
338
+ originalBytes: number;
339
+ compressedBytes: number;
340
+ /** 是否发生过缩放(仅降质未缩放时为 false) */
341
+ scaled: boolean;
342
+ /** 实际输出所用的 JPEG 质量;未经压缩管线时为 undefined */
343
+ quality?: number;
344
+ }
345
+ /**
346
+ * 把图片压到字节预算内(0.6.0 FR-11.3)。
347
+ * 先逐级降质,仍超限则按长边逐步缩放,最多 5 轮;仍超限抛 `ATTACHMENT_TOO_LARGE`。
348
+ *
349
+ * 编码一律交给平台(`OffscreenCanvas.convertToBlob`),不手写编码器(AGENTS.md §6)。
350
+ * 因此本函数只能在浏览器里用,落在 `@webskill/browser` 而不是 core/runtime(AC-G6)。
351
+ */
352
+ declare function compressImageToBudget(file: Blob, maxBytes: number): Promise<CompressResult>;
353
+ //#endregion
354
+ //#region src/dom/perception.d.ts
355
+ interface DomPerceptionReaderOptions {
356
+ /** 选择器求值的根;缺省 `globalThis.document` */
357
+ document?: Document;
358
+ }
359
+ /** DOM 遍历是同步的;不取像时比 `PagePerceptionReader` 窄,调用方无需 await @experimental */
360
+ interface DomPerceptionReader extends PagePerceptionReader {
361
+ read(scope: PerceptionScope): readonly PerceivedNode[];
362
+ read(scope: PerceptionScope, capture: PerceptionCaptureOptions): Promise<PerceptionResult>;
363
+ }
364
+ /**
365
+ * DOM 遍历实现(设计 09 §2 的「实现层」)。产出只有角色 / 名称 / 值,
366
+ * **不含任何 HTML 标记、class、data 属性或注释**(FR-10.4)。
367
+ *
368
+ * 判定顺序是先 `include` 取子树再 `exclude` 剪枝:`exclude` 命中的元素连同
369
+ * 其整棵后代一起消失,而不是只去掉那一个节点。
370
+ * @experimental
371
+ */
372
+ declare function createDomPerceptionReader(options?: DomPerceptionReaderOptions): DomPerceptionReader;
373
+ //#endregion
374
+ //#region src/dom/imageCapture.d.ts
375
+ /**
376
+ * 取像级别(0.6.0 FR-12.1)。裁决 D-3 已取消 L3 栅格化,只剩两级。
377
+ * @experimental
378
+ */
379
+ type CaptureLevel = 'src' | 'canvas';
380
+ /** @experimental */
381
+ interface CapturedImage {
382
+ id: string;
383
+ mimeType: string;
384
+ /** base64,不含 `data:` 前缀 */
385
+ data: string;
386
+ level: CaptureLevel;
387
+ originalBytes: number;
388
+ /** 压缩后字节数;未压缩时与 `originalBytes` 相同 */
389
+ bytes: number;
390
+ }
391
+ /** @experimental */
392
+ interface CaptureFailure {
393
+ id: string;
394
+ /** 必须说明是哪一级、为什么;只写 "image unavailable" 不足以让用户判断该怎么办 */
395
+ reason: string;
396
+ triedLevels: readonly CaptureLevel[];
397
+ }
398
+ /** @experimental */
399
+ declare function isCaptureFailure(result: CapturedImage | CaptureFailure): result is CaptureFailure;
400
+ /** 只有这三种标签能取像;其余元素连取像入口都不进(FR-12.1,由 T-02-15 守门) @experimental */
401
+ declare function isCapturableElement(element: Element): boolean;
402
+ /**
403
+ * 取一个元素的图像(0.6.0 FR-12.1)。
404
+ *
405
+ * 按元素类型分派,不做无意义的尝试:`<img>` 只走 L1,`<canvas>` / `<svg>` 只走 L2,
406
+ * 两者互不兜底。失败返回 `CaptureFailure` 而不是抛错——一张图抓不到不该让整次感知失败。
407
+ * @experimental
408
+ */
409
+ declare function captureElementImage(element: Element, options: {
410
+ id: string;
411
+ maxBytes: number;
412
+ }): Promise<CapturedImage | CaptureFailure>;
413
+ //#endregion
220
414
  //#region src/host/protocol.d.ts
221
415
  /** 主线程 → Worker 的 LLM 配置;mockResponses 供 E2E/测试注入确定性 Mock */
222
416
  interface LlmClientConfig {
@@ -388,4 +582,39 @@ declare class WorkerUiBridge implements UiBridge {
388
582
  onTextDelta(runId: string, delta: string): Promise<void>;
389
583
  }
390
584
  //#endregion
391
- export { type BridgeCapabilities, type BridgeRequest, type BridgeResponse, BrowserSkillManager, BrowserWorkerScriptExecutor, IframeWorkerLike, type LlmClientConfig, type MainToWorkerMessage, OpfsProvider, type SandboxMode, type SerializedError, TsTranspiler, type TypeScriptSupportOptions, WORKER_BOOTSTRAP_SOURCE, type WorkerEvent, type WorkerFactory, type WorkerLike, type WorkerRequest, WorkerRuntimeClient, type WorkerRuntimeClientDeps, type WorkerRuntimeHostOverrides, type WorkerScopeLike, WorkerUiBridge, bridgeError, createIframeWorker, extractZipWeb, installWebSkillNavigator, isOpfsAvailable, parseBridgeRequest, parseMainMessage, parseWorkerEvent, sha256HexWeb, startWorkerRuntimeHost };
585
+ //#region src/memory/encryptedMemoryStore.d.ts
586
+ /**
587
+ * 某条已读出的记忆值是否是密文信封。观测方(如 console)据此决定要不要去取密钥:
588
+ * 加密关着的时候不该为了读一条明文而凭空建出一把密钥。
589
+ * @experimental
590
+ */
591
+ declare function isEncryptedMemoryValue(value: unknown): boolean;
592
+ /**
593
+ * 用 AES-GCM 包装一个 MemoryStore:值加密后再交给 `inner`,读取时解密。
594
+ * 密钥不可用(未解锁 / 无 Web Crypto)时**拒绝读写并抛结构化错误**,
595
+ * 不静默降级成明文——那会让「已加密」的承诺失效而用户无从察觉。
596
+ *
597
+ * `scopes` 限定加密范围。默认全加密;宿主通常只加密存放个人数据的
598
+ * `user:` 作用域,把运行观测(会话参数历史、技能统计)留作明文供 console 读取。
599
+ * @experimental
600
+ */
601
+ declare function createEncryptedMemoryStore(inner: MemoryStore, key: CryptoKey | undefined, options?: {
602
+ scopes?: (scope: string) => boolean;
603
+ }): MemoryStore;
604
+ /**
605
+ * 生成一把不可导出的 AES-GCM 256 密钥(FR-19.5)。不可导出意味着页面脚本
606
+ * 拿不到原始字节,只能通过 Web Crypto 使用它;宿主负责持久化这个句柄(如 IndexedDB)。
607
+ * @experimental
608
+ */
609
+ declare function generateMemoryEncryptionKey(): Promise<CryptoKey>;
610
+ /**
611
+ * 取(必要时生成)本地数据加密密钥并持久化在 IndexedDB(FR-19.5)。
612
+ * 存的是 `CryptoKey` 句柄本身而不是密钥字节:结构化克隆能存它,
613
+ * 而它是 non-extractable 的,页面脚本与扩展都读不出原始字节。
614
+ * @experimental
615
+ */
616
+ declare function openMemoryEncryptionKey(name?: string): Promise<CryptoKey>;
617
+ /** 删除本地数据加密密钥;清除画像与记录时一并调用,避免留下解不开的旧密文 @experimental */
618
+ declare function deleteMemoryEncryptionKey(name?: string): Promise<void>;
619
+ //#endregion
620
+ export { type BridgeCapabilities, type BridgeRequest, type BridgeResponse, BrowserSkillManager, BrowserWorkerScriptExecutor, type CaptureFailure, type CaptureLevel, type CapturedImage, type ChromeBuiltinAvailability, ChromeBuiltinLlmClient, type CompressResult, type ConfiguredLlmClient, type DictationAvailability, type DictationOptions, type DictationSession, type DomPerceptionReader, type DomPerceptionReaderOptions, IframeWorkerLike, type LlmClientConfig, type LlmEntryConfig, type MainToWorkerMessage, OpfsProvider, type SandboxMode, type SerializedError, TsTranspiler, type TypeScriptSupportOptions, WORKER_BOOTSTRAP_SOURCE, type WorkerEvent, type WorkerFactory, type WorkerLike, type WorkerRequest, WorkerRuntimeClient, type WorkerRuntimeClientDeps, type WorkerRuntimeHostOverrides, type WorkerScopeLike, WorkerUiBridge, bridgeError, captureElementImage, checkDictationAvailability, compressImageToBudget, createDomPerceptionReader, createEncryptedMemoryStore, createIframeWorker, createLlmClient, deleteMemoryEncryptionKey, extractZipWeb, generateMemoryEncryptionKey, installWebSkillNavigator, isCapturableElement, isCaptureFailure, isEncryptedMemoryValue, isOpfsAvailable, openMemoryEncryptionKey, parseBridgeRequest, parseMainMessage, parseWorkerEvent, probeChromeBuiltinAvailability, sha256HexWeb, startDictation, startWorkerRuntimeHost };