@dp-bohrium/widget-sdk 0.4.1 → 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 (168) hide show
  1. package/AGENTS.md +10 -4
  2. package/CHANGELOG.md +34 -1
  3. package/README.md +61 -19
  4. package/assets/licenses/ajv@8.20.0/LICENSE +22 -0
  5. package/assets/licenses/fast-deep-equal@3.1.3/LICENSE +21 -0
  6. package/assets/licenses/fast-uri@3.1.6/LICENSE +30 -0
  7. package/assets/licenses/json-schema-traverse@1.0.0/LICENSE +21 -0
  8. package/assets/licenses/require-from-string@2.0.2/license +21 -0
  9. package/assets/licenses/widget-contracts.LICENSE +21 -0
  10. package/assets/licenses/widget-sdk.LICENSE +21 -0
  11. package/assets/schemas/host-runtime-config.schema.json +305 -0
  12. package/assets/schemas/widget-manifest.schema.json +361 -0
  13. package/assets/schemas/widget-plugin-manifest.schema.json +162 -0
  14. package/assets/schemas/widget-runtime-contracts.schema.json +2870 -0
  15. package/assets/toolchain.json +24 -0
  16. package/conformance/bridge/capability-request.json +23 -0
  17. package/conformance/bridge/files-download-request.json +23 -0
  18. package/conformance/bridge/files-read-versioned-request.json +25 -0
  19. package/conformance/bridge/files-write-request.json +25 -0
  20. package/conformance/bridge/files-write-success.json +25 -0
  21. package/conformance/bridge/network-fetch-denied.json +16 -0
  22. package/conformance/bridge/network-fetch-request.json +19 -0
  23. package/conformance/bridge/network-fetch-success.json +22 -0
  24. package/conformance/bridge/presentation-change-surface-request.json +14 -0
  25. package/conformance/bridge/presentation-close-request.json +14 -0
  26. package/conformance/bridge/presentation-close-success.json +11 -0
  27. package/conformance/bridge/presentation-downgrade-success.json +14 -0
  28. package/conformance/bridge/presentation-focus-backward-request.json +14 -0
  29. package/conformance/bridge/presentation-focus-boundary-success.json +14 -0
  30. package/conformance/bridge/presentation-focus-forward-request.json +14 -0
  31. package/conformance/bridge/presentation-init.json +70 -0
  32. package/conformance/bridge/presentation-policy-denied.json +16 -0
  33. package/conformance/bridge/presentation-present-request.json +14 -0
  34. package/conformance/bridge/presentation-user-denied.json +16 -0
  35. package/conformance/bridge/ready.json +11 -0
  36. package/conformance/bridge/region-acquire-request.json +14 -0
  37. package/conformance/bridge/tasks-list-request.json +17 -0
  38. package/conformance/bridge/tasks-watch-request.json +18 -0
  39. package/conformance/bridge/ui-state-write-request.json +18 -0
  40. package/conformance/bundles/minimal-file-preview/entry.js +1 -0
  41. package/conformance/bundles/minimal-file-preview/manifest.json +12 -0
  42. package/conformance/bundles/minimal-file-preview/samples/file-preview.json +1 -0
  43. package/conformance/bundles/minimal-panel/entry.js +1 -0
  44. package/conformance/bundles/minimal-panel/manifest.json +11 -0
  45. package/conformance/bundles/minimal-panel/samples/panel.json +1 -0
  46. package/conformance/bundles/minimal-tool-result/entry.js +1 -0
  47. package/conformance/bundles/minimal-tool-result/manifest.json +11 -0
  48. package/conformance/bundles/minimal-tool-result/samples/tool-result.json +1 -0
  49. package/conformance/file-grants/write.json +8 -0
  50. package/conformance/file-responses/list.json +1 -0
  51. package/conformance/file-responses/metadata.json +11 -0
  52. package/conformance/file-responses/mutation-conflict.json +6 -0
  53. package/conformance/file-responses/permission-denied.json +6 -0
  54. package/conformance/file-responses/read-revision-only.json +8 -0
  55. package/conformance/file-responses/read-unversioned-range.json +12 -0
  56. package/conformance/file-responses/read-versioned.json +12 -0
  57. package/conformance/file-responses/resource-limit.json +1 -0
  58. package/conformance/file-responses/revision-conflict.json +6 -0
  59. package/conformance/file-responses/text-content.json +7 -0
  60. package/conformance/file-responses/write-outcome-unknown.json +6 -0
  61. package/conformance/file-responses/write-success.json +15 -0
  62. package/conformance/host-runtime-config/invalid-host-service-expiry.json +85 -0
  63. package/conformance/host-runtime-config/invalid-host-service-identity.json +85 -0
  64. package/conformance/host-runtime-config/invalid-host-service-permission.json +85 -0
  65. package/conformance/host-runtime-config/invalid-host-service-status.json +65 -0
  66. package/conformance/host-runtime-config/invalid-missing-manifest-fields.json +55 -0
  67. package/conformance/host-runtime-config/invalid-static-origins.json +60 -0
  68. package/conformance/host-runtime-config/valid-host-service-authorization-required.json +65 -0
  69. package/conformance/host-runtime-config/valid-host-service-authorization.json +85 -0
  70. package/conformance/host-runtime-config/valid-no-requested-permissions.json +52 -0
  71. package/conformance/host-runtime-config/valid.json +85 -0
  72. package/conformance/invalid-bridge-messages/network-fetch-mixed-case-forbidden-header.json +21 -0
  73. package/conformance/invalid-file-grants/extra-file-scope.json +9 -0
  74. package/conformance/invalid-file-grants/missing-write-limits.json +4 -0
  75. package/conformance/invalid-file-requests/arbitrary-path.json +16 -0
  76. package/conformance/invalid-file-requests/missing-expected-revision.json +14 -0
  77. package/conformance/invalid-file-requests/missing-mutation-id.json +14 -0
  78. package/conformance/invalid-file-requests/path-in-reference.json +16 -0
  79. package/conformance/invalid-file-results/read-empty-revision.json +5 -0
  80. package/conformance/invalid-file-results/read-null-revision.json +5 -0
  81. package/conformance/invalid-file-results/write-missing-mutation-id.json +11 -0
  82. package/conformance/invalid-manifests/missing-target.json +11 -0
  83. package/conformance/invalid-manifests/presentation-duplicate-surfaces.json +16 -0
  84. package/conformance/invalid-manifests/presentation-empty-surfaces.json +14 -0
  85. package/conformance/invalid-manifests/presentation-unknown-surface.json +16 -0
  86. package/conformance/invalid-manifests/unknown-field.json +12 -0
  87. package/conformance/invalid-network-requests/mixed-case-forbidden-header.json +11 -0
  88. package/conformance/invalid-presentation-grants/duplicate-surfaces.json +5 -0
  89. package/conformance/invalid-presentation-grants/empty-surfaces.json +5 -0
  90. package/conformance/invalid-presentation-grants/false-confirmation.json +5 -0
  91. package/conformance/invalid-presentation-grants/missing-confirmation.json +4 -0
  92. package/conformance/invalid-presentation-grants/unknown-surface.json +5 -0
  93. package/conformance/invalid-presentation-requests/change-surface-missing-surface.json +4 -0
  94. package/conformance/invalid-presentation-requests/close-with-surface.json +4 -0
  95. package/conformance/invalid-presentation-requests/focus-boundary-missing-direction.json +4 -0
  96. package/conformance/invalid-presentation-requests/focus-boundary-unknown-direction.json +4 -0
  97. package/conformance/invalid-presentation-requests/focus-boundary-with-coordinates.json +9 -0
  98. package/conformance/invalid-presentation-requests/focus-boundary-with-event-provenance.json +8 -0
  99. package/conformance/invalid-presentation-requests/focus-boundary-with-generation.json +8 -0
  100. package/conformance/invalid-presentation-requests/focus-boundary-with-identity.json +12 -0
  101. package/conformance/invalid-presentation-requests/focus-boundary-with-key.json +8 -0
  102. package/conformance/invalid-presentation-requests/focus-boundary-with-modifiers.json +11 -0
  103. package/conformance/invalid-presentation-requests/focus-boundary-with-selector.json +8 -0
  104. package/conformance/invalid-presentation-requests/focus-boundary-with-surface.json +8 -0
  105. package/conformance/invalid-presentation-requests/focus-boundary-with-target.json +8 -0
  106. package/conformance/invalid-presentation-requests/focus-boundary-with-timestamp.json +8 -0
  107. package/conformance/invalid-presentation-requests/focus-boundary-with-z-index.json +8 -0
  108. package/conformance/invalid-presentation-requests/present-missing-surface.json +4 -0
  109. package/conformance/invalid-presentation-requests/unknown-surface.json +4 -0
  110. package/conformance/invalid-presentation-requests/widget-controls-coordinates.json +9 -0
  111. package/conformance/invalid-presentation-requests/widget-controls-geometry.json +8 -0
  112. package/conformance/invalid-presentation-requests/widget-controls-instance-id.json +8 -0
  113. package/conformance/invalid-presentation-requests/widget-controls-principal.json +8 -0
  114. package/conformance/invalid-presentation-requests/widget-controls-run-id.json +4 -0
  115. package/conformance/invalid-presentation-requests/widget-controls-widget-id.json +8 -0
  116. package/conformance/invalid-presentation-requests/widget-controls-widget-version-id.json +8 -0
  117. package/conformance/invalid-presentation-requests/widget-controls-z-index.json +4 -0
  118. package/conformance/invalid-render-inputs/malformed.json +17 -0
  119. package/conformance/manifests/valid-file-preview.json +12 -0
  120. package/conformance/manifests/valid-file-write-preview.json +30 -0
  121. package/conformance/manifests/valid-network.json +15 -0
  122. package/conformance/manifests/valid-panel.json +11 -0
  123. package/conformance/manifests/valid-presentation-panel.json +21 -0
  124. package/conformance/manifests/valid-region-panel.json +18 -0
  125. package/conformance/manifests/valid-tool-result.json +14 -0
  126. package/conformance/render-inputs/compatibility/literature-search-paper-results.json +75 -0
  127. package/conformance/render-inputs/compatibility/scientific-bibliography-bibtex.json +10 -0
  128. package/conformance/render-inputs/compatibility/scientific-dataset-csv.json +10 -0
  129. package/conformance/render-inputs/compatibility/scientific-manuscript-latex.json +10 -0
  130. package/conformance/render-inputs/compatibility/scientific-manuscript-markdown.json +10 -0
  131. package/conformance/render-inputs/compatibility/scientific-molecule-mol.json +10 -0
  132. package/conformance/render-inputs/compatibility/scientific-molecule-mol2.json +10 -0
  133. package/conformance/render-inputs/compatibility/scientific-notebook-ipynb.json +10 -0
  134. package/conformance/render-inputs/compatibility/scientific-paper-pdf.json +10 -0
  135. package/conformance/render-inputs/compatibility/scientific-protein-pdb.json +10 -0
  136. package/conformance/render-inputs/compatibility/scientific-source-python.json +10 -0
  137. package/conformance/render-inputs/compatibility/scientific-structure-cif.json +47 -0
  138. package/conformance/render-inputs/compatibility/scientific-structure-poscar.json +10 -0
  139. package/conformance/render-inputs/compatibility/scientific-structure-stru.json +10 -0
  140. package/conformance/render-inputs/compatibility/scientific-trajectory-xyz.json +10 -0
  141. package/conformance/render-inputs/compatibility/thinking-process-paper-search.json +25 -0
  142. package/conformance/render-inputs/compatibility/thinking-process-scholar-search.json +25 -0
  143. package/conformance/render-inputs/compatibility/thinking-process-web-search.json +25 -0
  144. package/conformance/render-inputs/compatibility/workspace-file-search.json +24 -0
  145. package/conformance/render-inputs/compatibility/workspace-file-tree.json +24 -0
  146. package/conformance/render-inputs/empty.json +10 -0
  147. package/conformance/render-inputs/file-preview.json +10 -0
  148. package/conformance/render-inputs/incremental-update.json +10 -0
  149. package/conformance/render-inputs/large.json +10 -0
  150. package/conformance/render-inputs/malformed.json +1 -0
  151. package/conformance/render-inputs/panel.json +10 -0
  152. package/conformance/render-inputs/partial-state-full-snapshot.json +40 -0
  153. package/conformance/render-inputs/tool-result.json +10 -0
  154. package/conformance/resource-budgets/corpus.json +431 -0
  155. package/dist/cli.mjs +15577 -0
  156. package/dist/contracts.d.ts +2 -0
  157. package/dist/contracts.js +1 -0
  158. package/dist/index.d.ts +2 -2
  159. package/dist/index.js +42 -8
  160. package/dist/runtime/index.js +1 -1
  161. package/dist/{runtime-RyAEhkyn.js → runtime-D7KxTtdu.js} +1 -1
  162. package/dist/widget.d.ts +20 -1
  163. package/llms.txt +11 -1
  164. package/package.json +17 -3
  165. package/schemas/host-runtime-config.schema.json +305 -0
  166. package/schemas/widget-manifest.schema.json +361 -0
  167. package/schemas/widget-plugin-manifest.schema.json +162 -0
  168. package/schemas/widget-runtime-contracts.schema.json +2870 -0
@@ -0,0 +1,2 @@
1
+ /** 完整协议保持独立子入口,避免与作者接口的同名类型混用。 */
2
+ export * from "@dp-bohrium/widget-contracts";
@@ -0,0 +1 @@
1
+ export * from "@dp-bohrium/widget-contracts";
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type { FileMutationId, FileReadInput, FileReadResult, FileRevision, FileWriteInput, FileWriteResult, WidgetActivationEvent, WidgetActivationEvents, WidgetContribution, WidgetEventName, WidgetFilePreviewContribution, WidgetPanelContribution, WidgetPluginContributions, WidgetPluginManifest, WidgetToolPhase, } from "@dp-bohrium/widget-contracts";
1
+ export type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileMutationId, FilePreviewContent, FilePreviewRenderRequest, FileReadInput, FileReadResult, FileReference, FileRevision, FileWriteInput, FileWriteResult, GrantedCapability, JsonValue, PanelContent, PanelRenderRequest, RenderRequest, RenderState, TaskObservationBatch, TaskObservationEvent, TaskObservationSnapshot, Theme, ThemeMode, WidgetActivationEvent, WidgetActivationEvents, WidgetContribution, WidgetError, WidgetErrorCode, WidgetEventName, WidgetFilePreviewContribution, WidgetLiveEvent, WidgetNetworkFetchInput, WidgetNetworkFetchOutput, WidgetPanelContribution, WidgetPluginContributions, WidgetPluginManifest, WidgetToolPhase, } from "@dp-bohrium/widget-contracts";
2
2
  export { isWidgetActivationEvent, isWidgetEventName, WIDGET_ACTIVATION_EVENTS, WIDGET_EVENT_NAMES, } from "@dp-bohrium/widget-contracts";
3
3
  export type { CompileWidgetPluginManifestOptions } from "./manifest.js";
4
4
  export { compileWidgetPluginManifest } from "./manifest.js";
5
5
  export type { HostUserEmail, HostUserEmailResult, HostUserProfile, HostUserProfileResult, WidgetHostUserClient, } from "./runtime/service.js";
6
- export type { FileDownloadCapabilityResult, FileReadCapabilityResult, FileWriteCapabilityResult, TaskWatchCapabilityResult, UiStateReadCapabilityResult, UiStateWriteCapabilityResult, WidgetActivation, WidgetCapabilityApi, WidgetContext, WidgetDisposable, WidgetEventApi, WidgetFileApi, WidgetHandle, WidgetHostOptions, WidgetModule, WidgetRenderContext, WidgetRenderHandler, WidgetTaskApi, WidgetUiApi, WidgetUiStateApi, } from "./widget.js";
6
+ export type { FileDownloadCapabilityResult, FileReadCapabilityResult, FileWriteCapabilityResult, TaskListCapabilityResult, TaskWatchCapabilityResult, UiStateReadCapabilityResult, UiStateWriteCapabilityResult, WidgetActivation, WidgetCapabilityApi, WidgetContext, WidgetDisposable, WidgetEventApi, WidgetFileApi, WidgetHandle, WidgetHostOptions, WidgetModule, WidgetRenderContext, WidgetRenderHandler, WidgetTaskApi, WidgetUiApi, WidgetUiStateApi, } from "./widget.js";
7
7
  export { runWidgetHost } from "./widget.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-RyAEhkyn.js";
1
+ import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-D7KxTtdu.js";
2
2
  import { WIDGET_ACTIVATION_EVENTS, WIDGET_EVENT_NAMES, isWidgetActivationEvent, isWidgetEventName } from "@dp-bohrium/widget-contracts";
3
3
  //#region src/manifest.ts
4
4
  function compiledContribution(contribution) {
@@ -315,10 +315,16 @@ function createContext(client, payload, renderHandlers, lifetime) {
315
315
  input
316
316
  }, options)
317
317
  },
318
- tasks: { watch: (input, options) => client.requestCapability({
319
- operation: "tasks.watch",
320
- input
321
- }, options) },
318
+ tasks: {
319
+ list: (input = {}, options) => client.requestCapability({
320
+ operation: "tasks.list",
321
+ input
322
+ }, options),
323
+ watch: (input, options) => client.requestCapability({
324
+ operation: "tasks.watch",
325
+ input
326
+ }, options)
327
+ },
322
328
  network: client.network,
323
329
  services: client.services,
324
330
  hostUser: client.hostUser,
@@ -373,6 +379,29 @@ function createWidgetRuntime(module, options = {}) {
373
379
  const disposedPromise = new Promise((resolve) => {
374
380
  resolveDisposed = resolve;
375
381
  });
382
+ function writeLocalDiagnostic(...details) {
383
+ try {
384
+ console.error(...details);
385
+ } catch {}
386
+ }
387
+ function reportRenderFailure(error, request, update) {
388
+ if (lifetime.signal.aborted) return;
389
+ const failure = {
390
+ code: update ? "UPDATE_FAILED" : "RENDER_FAILED",
391
+ phase: update ? "update" : "render",
392
+ message: "Widget render handler failed",
393
+ retryable: false,
394
+ correlationId: request.requestId
395
+ };
396
+ writeLocalDiagnostic("[Widget 渲染失败]", failure, error);
397
+ for (const observer of [options.events?.onError, options.onError]) try {
398
+ Promise.resolve(observer?.(failure)).catch((observerError) => {
399
+ writeLocalDiagnostic("[Widget 诊断回调失败]", observerError);
400
+ });
401
+ } catch (observerError) {
402
+ writeLocalDiagnostic("[Widget 诊断回调失败]", observerError);
403
+ }
404
+ }
376
405
  function runDeactivation() {
377
406
  if (deactivation) return deactivation;
378
407
  deactivation = Promise.resolve().then(() => module.deactivate?.()).catch((error) => {
@@ -413,9 +442,14 @@ function createWidgetRuntime(module, options = {}) {
413
442
  phase: update ? "update" : "initial",
414
443
  signal: lifetime.signal
415
444
  };
416
- for (const handler of [...renderHandlers]) try {
417
- Promise.resolve(handler(request, renderContext)).catch(() => {});
418
- } catch {}
445
+ for (const handler of [...renderHandlers]) {
446
+ if (lifetime.signal.aborted) break;
447
+ try {
448
+ Promise.resolve(handler(request, renderContext)).catch((error) => reportRenderFailure(error, request, update));
449
+ } catch (error) {
450
+ reportRenderFailure(error, request, update);
451
+ }
452
+ }
419
453
  },
420
454
  onDispose: dispose
421
455
  }
@@ -1,3 +1,3 @@
1
- import { a as isWidgetHostConnectMessage, c as WidgetClient, i as createWidgetClient, l as WIDGET_SDK_VERSION, n as WIDGET_HOST_CONNECT, o as PRESENTATION_CONFIRMATION_TIMEOUT_MS, r as WidgetRuntimeClient, s as REGION_CONFIRMATION_TIMEOUT_MS, t as WIDGET_BOOTSTRAP_READY } from "../runtime-RyAEhkyn.js";
1
+ import { a as isWidgetHostConnectMessage, c as WidgetClient, i as createWidgetClient, l as WIDGET_SDK_VERSION, n as WIDGET_HOST_CONNECT, o as PRESENTATION_CONFIRMATION_TIMEOUT_MS, r as WidgetRuntimeClient, s as REGION_CONFIRMATION_TIMEOUT_MS, t as WIDGET_BOOTSTRAP_READY } from "../runtime-D7KxTtdu.js";
2
2
  import { i as isWidgetProtocolMessage, r as MessagePortTransport } from "../protocol-endpoint-CDz-YDGT.js";
3
3
  export { MessagePortTransport, PRESENTATION_CONFIRMATION_TIMEOUT_MS, REGION_CONFIRMATION_TIMEOUT_MS, WIDGET_BOOTSTRAP_READY, WIDGET_HOST_CONNECT, WIDGET_SDK_VERSION, WidgetClient, WidgetRuntimeClient, createWidgetClient, isWidgetHostConnectMessage, isWidgetProtocolMessage };
@@ -2,7 +2,7 @@ import { r as MessagePortTransport, t as ProtocolEndpoint } from "./protocol-end
2
2
  //#endregion
3
3
  //#region src/runtime/version.ts
4
4
  /** 从当前安装的 SDK package.json 读取版本,插件作者不需要重复填写。 */
5
- const WIDGET_SDK_VERSION = "0.4.1";
5
+ const WIDGET_SDK_VERSION = "0.6.0";
6
6
  //#endregion
7
7
  //#region src/runtime/network.ts
8
8
  const failureReasons = /* @__PURE__ */ new Set([
package/dist/widget.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileReadInput, FileReference, FileWriteInput, GrantedCapability, RegionCapabilityResult, RenderRequest, TaskObservationBatch, Theme, UiStateResult, UiStateWriteResult, WidgetEventName, WidgetLiveEvent } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileReadInput, FileReference, FileWriteInput, GrantedCapability, RegionCapabilityResult, RenderRequest, TaskListPage, TaskObservationBatch, Theme, UiStateResult, UiStateWriteResult, WidgetEventName, WidgetLiveEvent } from "@dp-bohrium/widget-contracts";
2
2
  import { type FileReadCapabilityResult, type FileWriteCapabilityResult } from "./runtime/files.js";
3
3
  import { type CreateWidgetClientOptions, type RegionName, type WidgetClientFactoryOptions, type WidgetClientState, type WidgetLiveEventContext, type WidgetLiveEventHandler } from "./runtime/index.js";
4
4
  import type { WidgetNetworkClient } from "./runtime/network.js";
@@ -53,6 +53,17 @@ export type FileDownloadCapabilityResult = {
53
53
  readonly ok: false;
54
54
  }>;
55
55
  export interface WidgetTaskApi {
56
+ /**
57
+ * 读取一次受 Host 限制的任务摘要页。返回的 taskId 可继续用于 tasks.watch;
58
+ * 此 API 只发现任务,不创建、调度或取消任务。
59
+ */
60
+ list(input?: {
61
+ readonly cursor?: string;
62
+ readonly limit?: number;
63
+ }, options?: {
64
+ readonly timeoutMs?: number;
65
+ readonly signal?: AbortSignal;
66
+ }): Promise<TaskListCapabilityResult>;
56
67
  /**
57
68
  * 读取一次受 Host 限制的任务快照和事件页。调用方使用返回的 cursor
58
69
  * 继续轮询;此 API 不创建、调度或取消任务。
@@ -66,6 +77,14 @@ export interface WidgetTaskApi {
66
77
  readonly signal?: AbortSignal;
67
78
  }): Promise<TaskWatchCapabilityResult>;
68
79
  }
80
+ /** tasks.list 的类型化能力结果。 */
81
+ export type TaskListCapabilityResult = {
82
+ readonly ok: true;
83
+ readonly data: TaskListPage;
84
+ } | Extract<CapabilityResult, {
85
+ readonly ok: false;
86
+ }>;
87
+ /** tasks.watch 的类型化能力结果。 */
69
88
  export type TaskWatchCapabilityResult = {
70
89
  readonly ok: true;
71
90
  readonly data: TaskObservationBatch;
package/llms.txt CHANGED
@@ -14,12 +14,22 @@
14
14
  - 生产 Widget:`@dp-bohrium/widget-sdk`
15
15
  - 单元测试:`@dp-bohrium/widget-sdk/testing`
16
16
  - 协议级集成:`@dp-bohrium/widget-sdk/runtime`
17
- - 配套类型和 Schema:`@dp-bohrium/widget-contracts`
17
+ - 常用作者类型:`@dp-bohrium/widget-sdk`
18
+ - 完整协议类型:`@dp-bohrium/widget-sdk/contracts`
19
+ - Manifest 与协议 Schema:`@dp-bohrium/widget-sdk/schemas/*.json`
20
+ - Host 协议校验语料:`@dp-bohrium/widget-sdk/conformance/*`
21
+ - 工程命令:SDK 包内 `bohr-widget`(首次创建可用 `pnpm dlx @dp-bohrium/widget-sdk create ...`)
22
+
23
+ 消费方直接声明或导入 contracts 的旧用法已废弃;统一入口切换发布 R1 前迁到 SDK 子入口。
24
+ contracts 仍维护内部唯一源,不恢复旧作者执行器来支持历史工程。
25
+ 新工程只直接声明精确 SDK 版本;`@dp-bohrium/widget-cli` 只按现行发布治理保留过渡分发、历史审计和废弃诊断,不由 SDK 回选。
18
26
 
19
27
  ## 使用原则
20
28
 
21
29
  - 先在 Manifest 声明 capability,再等待 Host grant。
22
30
  - 用 `WidgetError` 的 `code/phase/retryable/correlationId` 诊断启动、渲染和能力失败。
31
+ - `context.render` 异常通过 `runWidgetHost` 的既有 `onError` / `events.onError` 和 Guest console
32
+ 本地报告,不自动终止或重试;不要改成向旧 Host 发送致命协议 `error`。
23
33
  - `ok=false` 的能力结果是可处理状态,不要直接重试或绕过 Host。
24
34
  - 文件读写使用 `context.files.read(input, options)` / `write(input, options)`;Manifest
25
35
  分别申请 `files.read` / `files.write`。file-preview 的引用来自当前文件;Panel 只有获得
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dp-bohrium/widget-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "Bohrium Widget 开发者 SDK:在 Widget Bundle 内与 Host 建立 Bridge,并暴露生命周期与能力协议。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,6 +20,9 @@
20
20
  "author": "Bohrium",
21
21
  "homepage": "https://dev.dp.tech/bohrium-widget-sdk/",
22
22
  "types": "./dist/index.d.ts",
23
+ "bin": {
24
+ "bohr-widget": "./dist/cli.mjs"
25
+ },
23
26
  "exports": {
24
27
  ".": {
25
28
  "types": "./dist/index.d.ts",
@@ -33,10 +36,19 @@
33
36
  "types": "./dist/runtime/index.d.ts",
34
37
  "import": "./dist/runtime/index.js"
35
38
  },
39
+ "./contracts": {
40
+ "types": "./dist/contracts.d.ts",
41
+ "import": "./dist/contracts.js"
42
+ },
43
+ "./schemas/*.json": "./schemas/*.json",
44
+ "./conformance/*": "./conformance/*",
36
45
  "./package.json": "./package.json"
37
46
  },
38
47
  "files": [
39
48
  "dist",
49
+ "assets",
50
+ "schemas",
51
+ "conformance",
40
52
  "README.md",
41
53
  "AGENTS.md",
42
54
  "llms.txt",
@@ -48,7 +60,7 @@
48
60
  "access": "public"
49
61
  },
50
62
  "dependencies": {
51
- "@dp-bohrium/widget-contracts": "0.4.1"
63
+ "@dp-bohrium/widget-contracts": "0.6.0"
52
64
  },
53
65
  "devDependencies": {
54
66
  "@biomejs/biome": "^2.2.0",
@@ -60,7 +72,9 @@
60
72
  "@dp-bohrium/widget-contract-testing": "0.1.0-alpha.0"
61
73
  },
62
74
  "scripts": {
63
- "build": "tsdown && tsc -b tsconfig.build.json --force --pretty false",
75
+ "build:runtime": "tsdown && tsc -b tsconfig.build.json --force --pretty false && node ../../scripts/schema/build-sdk-assets.mjs",
76
+ "build:cli": "node ../../scripts/schema/build-sdk-cli-assets.mjs && tsdown --config widget-cli.tsdown.config.ts && node --check dist/cli.mjs",
77
+ "build": "pnpm build:runtime && pnpm --filter @dp-bohrium/widget-contract-testing build && pnpm build:cli",
64
78
  "typecheck": "tsc --noEmit",
65
79
  "test": "vitest run",
66
80
  "test:coverage": "vitest run --coverage --coverage.thresholds.lines=80 --coverage.thresholds.functions=80 --coverage.thresholds.statements=80 --coverage.thresholds.branches=70",
@@ -0,0 +1,305 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "host-runtime-config.schema.json",
4
+ "description": "Host 为一次 Widget 运行签发并下发给 agent-widget 的运行时配置,不直接发给 Widget。",
5
+ "title": "Widget Host Runtime Config",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "schemaVersion",
10
+ "hostApiVersion",
11
+ "configId",
12
+ "runId",
13
+ "mode",
14
+ "issuedAt",
15
+ "expiresAt",
16
+ "recheckAt",
17
+ "securityProfile",
18
+ "resourceBudget",
19
+ "runtime",
20
+ "network",
21
+ "bindings"
22
+ ],
23
+ "properties": {
24
+ "schemaVersion": { "const": 1 },
25
+ "hostApiVersion": { "const": 1 },
26
+ "configId": { "$ref": "#/$defs/Identifier" },
27
+ "hostId": { "$ref": "#/$defs/Identifier" },
28
+ "runId": { "$ref": "#/$defs/Identifier" },
29
+ "mode": { "$ref": "#/$defs/Mode" },
30
+ "issuedAt": { "$ref": "#/$defs/Timestamp" },
31
+ "expiresAt": { "$ref": "#/$defs/Timestamp" },
32
+ "recheckAt": { "$ref": "#/$defs/Timestamp" },
33
+ "securityProfile": { "const": "runtime-security-profile-v1" },
34
+ "resourceBudget": {
35
+ "$ref": "widget-runtime-contracts.schema.json#/$defs/ResourceBudget"
36
+ },
37
+ "runtime": { "$ref": "#/$defs/RuntimeAuthority" },
38
+ "network": { "$ref": "#/$defs/NetworkAuthority" },
39
+ "bindings": {
40
+ "type": "array",
41
+ "items": {
42
+ "oneOf": [
43
+ { "$ref": "#/$defs/LoadableBinding" },
44
+ { "$ref": "#/$defs/FallbackBinding" }
45
+ ]
46
+ }
47
+ }
48
+ },
49
+ "$defs": {
50
+ "LoadableBinding": {
51
+ "description": "可加载绑定:状态为 loadable,携带冻结版本、摘要、Manifest、启动地址与能力授权。",
52
+ "title": "LoadableBinding",
53
+ "type": "object",
54
+ "additionalProperties": false,
55
+ "required": [
56
+ "status",
57
+ "bindingId",
58
+ "widgetId",
59
+ "widgetVersionId",
60
+ "digest",
61
+ "manifest",
62
+ "launch",
63
+ "grantedCapabilities"
64
+ ],
65
+ "properties": {
66
+ "status": { "const": "loadable" },
67
+ "bindingId": { "$ref": "#/$defs/Identifier" },
68
+ "widgetId": { "$ref": "#/$defs/Identifier" },
69
+ "widgetVersionId": { "$ref": "#/$defs/Identifier" },
70
+ "digest": { "$ref": "#/$defs/Digest" },
71
+ "trustClass": {
72
+ "description": "控制面确认的信任等级;作者不能自行声明。",
73
+ "enum": ["external", "first-party"]
74
+ },
75
+ "runtimeProfile": {
76
+ "description": "控制面选择的部署配置;不授予 Cookie 或 Token 读取权限。",
77
+ "enum": ["public-isolated", "first-party-private"]
78
+ },
79
+ "manifest": {
80
+ "$ref": "widget-manifest.schema.json"
81
+ },
82
+ "launch": { "$ref": "#/$defs/Launch" },
83
+ "grantedCapabilities": { "$ref": "#/$defs/GrantedCapabilities" },
84
+ "serviceAccess": { "$ref": "#/$defs/WidgetServiceAccess" },
85
+ "serviceAuthorization": { "$ref": "#/$defs/HostServiceAuthorization" }
86
+ }
87
+ },
88
+ "HostServiceAuthorization": {
89
+ "title": "HostServiceAuthorization",
90
+ "description": "Host-only evidence bound to the exact reviewed Widget bundle and current user grant.",
91
+ "oneOf": [
92
+ { "$ref": "#/$defs/HostServiceAuthorizationRequired" },
93
+ { "$ref": "#/$defs/HostServiceAuthorizationGranted" }
94
+ ]
95
+ },
96
+ "HostServiceAuthorizationRequired": {
97
+ "description": "需用户授权的 Host 服务证据:状态为 authorization-required。",
98
+ "title": "HostServiceAuthorizationRequired",
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": [
102
+ "kind",
103
+ "policy",
104
+ "status",
105
+ "hostId",
106
+ "widgetVersionId",
107
+ "bundleDigest",
108
+ "reviewRevision",
109
+ "reviewedPermissions",
110
+ "grantedPermissions",
111
+ "expiresAt"
112
+ ],
113
+ "properties": {
114
+ "kind": { "const": "host-service-authorization" },
115
+ "policy": { "const": "host-user-data-v1" },
116
+ "status": { "const": "authorization-required" },
117
+ "hostId": { "$ref": "#/$defs/Identifier" },
118
+ "widgetVersionId": { "$ref": "#/$defs/Identifier" },
119
+ "bundleDigest": { "$ref": "#/$defs/Digest" },
120
+ "reviewRevision": { "$ref": "#/$defs/Identifier" },
121
+ "reviewedPermissions": {
122
+ "$ref": "widget-manifest.schema.json#/$defs/HostUserPermissions"
123
+ },
124
+ "grantedPermissions": {
125
+ "type": "array",
126
+ "maxItems": 0
127
+ },
128
+ "expiresAt": { "$ref": "#/$defs/Timestamp" }
129
+ }
130
+ },
131
+ "HostServiceAuthorizationGranted": {
132
+ "description": "已授予的 Host 服务证据:状态为 granted。",
133
+ "title": "HostServiceAuthorizationGranted",
134
+ "type": "object",
135
+ "additionalProperties": false,
136
+ "required": [
137
+ "kind",
138
+ "policy",
139
+ "status",
140
+ "hostId",
141
+ "widgetVersionId",
142
+ "bundleDigest",
143
+ "reviewRevision",
144
+ "grantRevision",
145
+ "reviewedPermissions",
146
+ "grantedPermissions",
147
+ "expiresAt"
148
+ ],
149
+ "properties": {
150
+ "kind": { "const": "host-service-authorization" },
151
+ "policy": { "const": "host-user-data-v1" },
152
+ "status": { "const": "granted" },
153
+ "hostId": { "$ref": "#/$defs/Identifier" },
154
+ "widgetVersionId": { "$ref": "#/$defs/Identifier" },
155
+ "bundleDigest": { "$ref": "#/$defs/Digest" },
156
+ "reviewRevision": { "$ref": "#/$defs/Identifier" },
157
+ "grantRevision": { "$ref": "#/$defs/Identifier" },
158
+ "reviewedPermissions": {
159
+ "$ref": "widget-manifest.schema.json#/$defs/HostUserPermissions"
160
+ },
161
+ "grantedPermissions": {
162
+ "$ref": "widget-manifest.schema.json#/$defs/HostUserPermissions"
163
+ },
164
+ "expiresAt": { "$ref": "#/$defs/Timestamp" }
165
+ }
166
+ },
167
+ "FallbackBinding": {
168
+ "description": "降级绑定:状态为 fallback,不含 Bundle 地址、摘要、Manifest 或能力授权。",
169
+ "title": "FallbackBinding",
170
+ "type": "object",
171
+ "additionalProperties": false,
172
+ "required": [
173
+ "status",
174
+ "bindingId",
175
+ "widgetId",
176
+ "widgetVersionId",
177
+ "contribution",
178
+ "reason"
179
+ ],
180
+ "properties": {
181
+ "status": { "const": "fallback" },
182
+ "bindingId": { "$ref": "#/$defs/Identifier" },
183
+ "widgetId": { "$ref": "#/$defs/Identifier" },
184
+ "widgetVersionId": { "$ref": "#/$defs/Identifier" },
185
+ "contribution": {
186
+ "$ref": "widget-manifest.schema.json#/$defs/WidgetContributionConfig"
187
+ },
188
+ "reason": { "$ref": "#/$defs/FallbackReason" }
189
+ }
190
+ },
191
+ "RuntimeAuthority": {
192
+ "description": "运行域授权:origin 与 catalogRevision。",
193
+ "title": "RuntimeAuthority",
194
+ "type": "object",
195
+ "additionalProperties": false,
196
+ "required": ["origin", "catalogRevision"],
197
+ "properties": {
198
+ "origin": { "$ref": "#/$defs/RuntimeOrigin" },
199
+ "catalogRevision": {
200
+ "type": "string",
201
+ "minLength": 1,
202
+ "maxLength": 128,
203
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
204
+ },
205
+ "profile": {
206
+ "enum": ["public-isolated", "first-party-private"]
207
+ }
208
+ }
209
+ },
210
+ "NetworkAuthority": {
211
+ "description": "网络授权:mode、policyVersion 与限制。",
212
+ "title": "NetworkAuthority",
213
+ "type": "object",
214
+ "additionalProperties": false,
215
+ "required": ["mode", "policyVersion", "limits"],
216
+ "properties": {
217
+ "mode": { "enum": ["runtime-consent", "unavailable"] },
218
+ "policyVersion": {
219
+ "type": "string",
220
+ "minLength": 1,
221
+ "maxLength": 128,
222
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
223
+ },
224
+ "limits": {
225
+ "$ref": "widget-runtime-contracts.schema.json#/$defs/WidgetNetworkLimits"
226
+ }
227
+ }
228
+ },
229
+ "GrantedCapabilities": {
230
+ "description": "已授予能力列表。",
231
+ "title": "GrantedCapabilities",
232
+ "type": "array",
233
+ "items": {
234
+ "$ref": "widget-runtime-contracts.schema.json#/$defs/GrantedCapability"
235
+ }
236
+ },
237
+ "Launch": {
238
+ "description": "一次性启动地址与有效期。",
239
+ "title": "Launch",
240
+ "type": "object",
241
+ "additionalProperties": false,
242
+ "required": ["url", "expiresAt"],
243
+ "properties": {
244
+ "url": { "type": "string", "pattern": "^https?://" },
245
+ "expiresAt": { "$ref": "#/$defs/Timestamp" }
246
+ }
247
+ },
248
+ "RuntimeOrigin": {
249
+ "description": "隔离域运行源地址。",
250
+ "title": "RuntimeOrigin",
251
+ "type": "string",
252
+ "maxLength": 253,
253
+ "pattern": "^(?:https://[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::[0-9]{1,5})?|http://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])(?::[0-9]{1,5})?)$"
254
+ },
255
+ "FallbackReason": {
256
+ "description": "降级原因枚举。",
257
+ "title": "FallbackReason",
258
+ "enum": [
259
+ "not-authorized",
260
+ "not-approved",
261
+ "delisted-for-new-use",
262
+ "revoked",
263
+ "host-api-unsupported",
264
+ "preview-not-allowed"
265
+ ]
266
+ },
267
+ "Digest": {
268
+ "description": "内容摘要;形如 sha256:<hex>。",
269
+ "title": "Digest",
270
+ "type": "string",
271
+ "pattern": "^sha256:[0-9a-f]{64}$"
272
+ },
273
+ "Identifier": {
274
+ "description": "不透明标识符。",
275
+ "title": "Identifier",
276
+ "type": "string",
277
+ "minLength": 1
278
+ },
279
+ "Mode": {
280
+ "description": "运行模式:preview 或 published。",
281
+ "title": "Mode",
282
+ "enum": ["preview", "published"]
283
+ },
284
+ "Timestamp": {
285
+ "description": "UTC 时间戳:YYYY-MM-DD + T + 非空格字符,以 Z 结尾。",
286
+ "title": "Timestamp",
287
+ "type": "string",
288
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}T[^ ]+Z$"
289
+ },
290
+ "WidgetServiceAccess": {
291
+ "title": "WidgetServiceAccess",
292
+ "description": "绑定当前不可变版本与摘要的审核投影;服务端每次调用仍须复核撤销和用户权限。",
293
+ "type": "object",
294
+ "additionalProperties": false,
295
+ "required": ["approvalId", "revision", "appId", "policyVersion", "expiresAt"],
296
+ "properties": {
297
+ "approvalId": { "$ref": "#/$defs/Identifier" },
298
+ "revision": { "$ref": "#/$defs/Identifier" },
299
+ "appId": { "$ref": "#/$defs/Identifier" },
300
+ "policyVersion": { "$ref": "#/$defs/Identifier" },
301
+ "expiresAt": { "$ref": "#/$defs/Timestamp" }
302
+ }
303
+ }
304
+ }
305
+ }