@webskill/sdk 0.4.0 → 0.5.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.
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, _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-D_hoCri8-BnNPiZCi.js";
2
+ import { Bt as WebSkillApi, Nt as ToolResult, Ut as bridgeError, W as NetworkPolicy, b as ExternalSkillProvider, d as ApprovalScope, f as BridgeCapabilities, h as BridgeResponse, jt as ToolDefinition, ln as parseBridgeRequest, m as BridgeRequest, vt as ScriptExecutionContext, x as ExternalToolSource, yt as ScriptExecutor } from "./index-vBz_FC9w.js";
3
+ import { S as PerceptionScope, g as PagePerceptionReader, y as PerceivedNode } from "./index-D_7ZZjkl.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,121 @@ 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/dom/perception.d.ts
335
+ interface DomPerceptionReaderOptions {
336
+ /** 选择器求值的根;缺省 `globalThis.document` */
337
+ document?: Document;
338
+ }
339
+ /** DOM 遍历是同步的;比 `PagePerceptionReader` 窄,调用方无需 await @experimental */
340
+ interface DomPerceptionReader extends PagePerceptionReader {
341
+ read(scope: PerceptionScope): readonly PerceivedNode[];
342
+ }
343
+ /**
344
+ * DOM 遍历实现(设计 09 §2 的「实现层」)。产出只有角色 / 名称 / 值,
345
+ * **不含任何 HTML 标记、class、data 属性或注释**(FR-10.4)。
346
+ *
347
+ * 判定顺序是先 `include` 取子树再 `exclude` 剪枝:`exclude` 命中的元素连同
348
+ * 其整棵后代一起消失,而不是只去掉那一个节点。
349
+ * @experimental
350
+ */
351
+ declare function createDomPerceptionReader(options?: DomPerceptionReaderOptions): DomPerceptionReader;
352
+ //#endregion
220
353
  //#region src/host/protocol.d.ts
221
354
  /** 主线程 → Worker 的 LLM 配置;mockResponses 供 E2E/测试注入确定性 Mock */
222
355
  interface LlmClientConfig {
@@ -388,4 +521,4 @@ declare class WorkerUiBridge implements UiBridge {
388
521
  onTextDelta(runId: string, delta: string): Promise<void>;
389
522
  }
390
523
  //#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 };
524
+ export { type BridgeCapabilities, type BridgeRequest, type BridgeResponse, BrowserSkillManager, BrowserWorkerScriptExecutor, type ChromeBuiltinAvailability, ChromeBuiltinLlmClient, 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, checkDictationAvailability, createDomPerceptionReader, createIframeWorker, createLlmClient, extractZipWeb, installWebSkillNavigator, isOpfsAvailable, parseBridgeRequest, parseMainMessage, parseWorkerEvent, probeChromeBuiltinAvailability, sha256HexWeb, startDictation, startWorkerRuntimeHost };