@dp-bohrium/widget-sdk 0.5.0 → 0.7.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 (188) hide show
  1. package/AGENTS.md +13 -4
  2. package/CHANGELOG.md +39 -1
  3. package/README.md +33 -20
  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 +2874 -0
  15. package/assets/toolchain.json +28 -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 +15618 -0
  156. package/dist/contracts.d.ts +2 -0
  157. package/dist/contracts.js +2 -0
  158. package/dist/index.d.ts +2 -2
  159. package/dist/index.js +17 -11
  160. package/dist/manifest.d.ts +1 -1
  161. package/dist/protocol/generated-host-runtime-config.d.ts +551 -0
  162. package/dist/protocol/generated-manifest.d.ts +192 -0
  163. package/dist/protocol/generated-plugin-manifest.d.ts +176 -0
  164. package/dist/protocol/generated-runtime-contracts.d.ts +1224 -0
  165. package/dist/protocol/index.d.ts +43 -0
  166. package/dist/protocol/plugin-manifest.d.ts +30 -0
  167. package/dist/protocol/widget-events.d.ts +13 -0
  168. package/dist/runtime/bootstrap.d.ts +1 -1
  169. package/dist/runtime/client.d.ts +1 -1
  170. package/dist/runtime/event-validation.d.ts +1 -1
  171. package/dist/runtime/events.d.ts +1 -1
  172. package/dist/runtime/files.d.ts +1 -1
  173. package/dist/runtime/index.d.ts +1 -1
  174. package/dist/runtime/index.js +1 -1
  175. package/dist/runtime/mock-host.d.ts +1 -1
  176. package/dist/runtime/network.d.ts +1 -1
  177. package/dist/runtime/protocol-endpoint.d.ts +1 -1
  178. package/dist/runtime/service.d.ts +2 -2
  179. package/dist/runtime/transport.d.ts +1 -1
  180. package/dist/{runtime-DVFTv55x.js → runtime-DZA7Gqzl.js} +1 -1
  181. package/dist/widget-events-BT0QxR-H.js +65 -0
  182. package/dist/widget.d.ts +2 -2
  183. package/llms.txt +8 -1
  184. package/package.json +18 -6
  185. package/schemas/host-runtime-config.schema.json +305 -0
  186. package/schemas/widget-manifest.schema.json +361 -0
  187. package/schemas/widget-plugin-manifest.schema.json +162 -0
  188. package/schemas/widget-runtime-contracts.schema.json +2874 -0
@@ -0,0 +1,43 @@
1
+ /** Public Widget contract surface. Runtime host/client APIs are deferred. */
2
+ import type { FallbackBinding, LoadableBinding } from "./generated-host-runtime-config.js";
3
+ import type { BridgeEnvelopeBase, GrantedCapability, HostToWidgetMessage, RenderRequest, WidgetError, WidgetToHostMessage } from "./generated-runtime-contracts.js";
4
+ /**
5
+ * Every type is re-exported from the module generated out of the schema that
6
+ * owns it. The Host Config module also contains inlined `$ref` copies of
7
+ * Manifest and Runtime definitions; re-exporting those copies would let the
8
+ * public surface drift from the canonical contract.
9
+ */
10
+ export type { FallbackBinding, HostServiceAuthorization, HostServiceAuthorizationGranted, HostServiceAuthorizationRequired, LoadableBinding, NetworkAuthority, RuntimeAuthority, WidgetHostRuntimeConfig, WidgetServiceAccess, } from "./generated-host-runtime-config.js";
11
+ export type { ActivationEvents, HostUserPermission, HostUserPermissions, RequestedPresentationCapability, RequestedRegionCapability, StateCapabilityRequest, TasksCapabilityRequest, WidgetContributionConfig, WidgetManifest, } from "./generated-manifest.js";
12
+ export type { WidgetContribution, WidgetFilePreviewContribution, WidgetPanelContribution, WidgetPluginContributions, } from "./generated-plugin-manifest.js";
13
+ export type { BridgeEnvelopeBase, CapabilityRequest, CapabilityRequestMessage, CapabilityResult, CapabilityResultMessage, ComputeReviewRequestedPublicWidgetEvent, ComputeReviewRequestedPublicWidgetEventPayload, DisposeMessage, EmptyPublicWidgetEventPayload, ErrorMessage, FileDownloadResult, FileMutationId, FilePreviewContent, FilePreviewRenderRequest, FileReadInput, FileReadResult, FileReference, FileRevision, FileWriteInput, FileWriteResult, FocusBoundaryPresentationCapabilityRequest, GrantedCapability, GrantedPresentationCapability, GrantedRegionCapability, HostToWidgetMessage, HostUserAction, HostUserEmailReadInput, HostUserEmailReadOutput, HostUserProfileReadInput, HostUserProfileReadOutput, HostUserService, HostUserServiceRequest, InitMessage, InitPayload, JsonValue, PanelContent, PanelRenderRequest, PresentationCapabilityOutput, PresentationCapabilityRequest, PresentationCapabilityResult, PublicWidgetEvent, PublicWidgetEventBase, PublicWidgetEventId, PublicWidgetEventOccurredAt, PublicWidgetEventTopic, PublicWidgetSessionId, PublicWidgetWorkflowId, ReadyMessage, RegionCapabilityRequest, RegionCapabilityResult, RenderMessage, RenderRequest, RenderRequestBase, RenderState, ResizeMessage, ResourceBudget, SandboxApprovalRequestedPublicWidgetEvent, SandboxApprovalRequestedPublicWidgetEventPayload, SandboxApprovedPublicWidgetEvent, SandboxApprovedPublicWidgetEventPayload, SandboxDeniedPublicWidgetEvent, TaskListField, TaskListItem, TaskListPage, TaskObservationBatch, TaskObservationEvent, TaskObservationSnapshot, TaskStatus, Theme, ThemeMode, ToolCallPublicWidgetEvent, ToolCallPublicWidgetEventPayload, ToolLifecycleEvent, ToolResultArtifact, ToolResultContent, ToolResultEnvelope, ToolResultMetric, ToolResultNotice, ToolResultProvenance, ToolResultPublicWidgetEvent, ToolResultPublicWidgetEventPayload, ToolResultRenderRequest, UiStateResult, UiStateWriteResult, UserInputRequestedPublicWidgetEvent, UserInputRequestedPublicWidgetEventPayload, WidgetContributionKind, WidgetError, WidgetEvent, WidgetEventBatch, WidgetEventMessage, WidgetLiveEvent, WidgetNetworkFetchInput, WidgetNetworkFetchOutput, WidgetNetworkLimits, WidgetRenderContext, WidgetServicePermission, WidgetServicePermissions, WidgetToHostMessage, WorkflowDonePublicWidgetEvent, WorkflowDonePublicWidgetEventPayload, WorkflowErrorPublicWidgetEvent, WorkflowErrorPublicWidgetEventPayload, WorkflowStartedPublicWidgetEvent, WorkflowStartedPublicWidgetEventPayload, } from "./generated-runtime-contracts.js";
14
+ export type { WidgetActivationEvent, WidgetActivationEvents, WidgetPluginManifest, WidgetToolPhase, } from "./plugin-manifest.js";
15
+ export { isWidgetActivationEvent, WIDGET_ACTIVATION_EVENTS, } from "./plugin-manifest.js";
16
+ export type { WidgetEventName } from "./widget-events.js";
17
+ export { isWidgetEventName, WIDGET_EVENT_NAMES } from "./widget-events.js";
18
+ /**
19
+ * Host API 协议版本,当前固定为 `1`,由各 Schema 的 `hostApiVersion`(`const: 1`)
20
+ * 唯一决定。它与包 SemVer 正交,不要用 `2` 之类不存在的值。
21
+ */
22
+ export type HostApiVersion = 1;
23
+ /** `RenderRequest` 的等价别名;用 `request.contribution` 收窄后访问对应 `content`。 */
24
+ export type WidgetRenderRequest = RenderRequest;
25
+ /** Host → Widget 与 Widget → Host 双向 Bridge 消息的联合。 */
26
+ export type WidgetProtocolMessage = HostToWidgetMessage | WidgetToHostMessage;
27
+ /**
28
+ * `GrantedCapability` 中只读文件能力名的联合:
29
+ * `files.list` / `files.metadata` / `files.read` / `files.download`;不包含 `files.write`。
30
+ */
31
+ export type ReadonlyFileCapability = Extract<GrantedCapability["name"], "files.list" | "files.metadata" | "files.read" | "files.download">;
32
+ /** `WidgetError.code` 的字符串字面量联合。 */
33
+ export type WidgetErrorCode = WidgetError["code"];
34
+ /**
35
+ * 带泛型 `type` / `payload` 的 Bridge 信封;默认 `type` 为 string、`payload` 为
36
+ * unknown。具体消息建议直接用 `HostToWidgetMessage` / `WidgetToHostMessage` 的成员。
37
+ */
38
+ export type BridgeEnvelope<TType extends string = string, TPayload = unknown> = BridgeEnvelopeBase & {
39
+ type: TType;
40
+ payload: TPayload;
41
+ };
42
+ /** 可加载绑定与降级绑定的联合,即 Host Runtime Config 中一条 binding 的两种结果。 */
43
+ export type ResolvedWidgetBinding = LoadableBinding | FallbackBinding;
@@ -0,0 +1,30 @@
1
+ import type { WidgetPluginManifest as GeneratedWidgetPluginManifest } from "./generated-plugin-manifest.js";
2
+ /** 工具调用事件阶段;用于拼出 `tool-call-<phase>:<toolName>` 形式的激活事件。 */
3
+ export type WidgetToolPhase = "generating" | "waiting" | "running" | "result" | "error";
4
+ /**
5
+ * Widget Host 公开的固定激活事件。数组同时作为清单编辑器文档和 Host
6
+ * 运行时校验的单一事实源;带工具名的事件使用下方的动态形式。
7
+ */
8
+ export declare const WIDGET_ACTIVATION_EVENTS: readonly ["session.start", "turn-start", "turn-end", "step-start", "step-end", "tool-call-generating", "tool-call-waiting", "tool-call-running", "tool-call-result", "tool-call-error", "workspace-file-changed", "workspace-tree-refresh", "workspace-file-opened", "ui-tool-opened", "ui-panel-focused", "host-surface-changed"];
9
+ type WidgetFixedActivationEvent = (typeof WIDGET_ACTIVATION_EVENTS)[number];
10
+ /**
11
+ * `activationEvents` 可声明的值:固定事件,或按工具名筛选的
12
+ * `tool-call-<phase>:<toolName>` 动态形式。
13
+ */
14
+ export type WidgetActivationEvent = WidgetFixedActivationEvent | `tool-call-${WidgetToolPhase}:${string}`;
15
+ /** 至少一个元素、按声明顺序的只读激活事件元组(作者侧清单使用)。 */
16
+ export type WidgetActivationEvents = readonly [
17
+ WidgetActivationEvent,
18
+ ...WidgetActivationEvent[]
19
+ ];
20
+ /**
21
+ * 判断一个字符串是否为合法激活事件(固定事件或带工具名的动态形式)。
22
+ * @param value 待检查的字符串。
23
+ * @returns 若命中固定目录或工具事件模式则收窄为 `WidgetActivationEvent`。
24
+ */
25
+ export declare function isWidgetActivationEvent(value: unknown): value is WidgetActivationEvent;
26
+ /** 作者侧 Manifest 类型;激活事件类型与 JSON Schema 共用同一事实源。 */
27
+ export type WidgetPluginManifest = Omit<GeneratedWidgetPluginManifest, "activationEvents"> & {
28
+ readonly activationEvents?: WidgetActivationEvents;
29
+ };
30
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Host 主动推送给已激活 Widget 的实时事件。`session.start` 只用于激活索引,
3
+ * 不属于这组运行期事件;激活后首个可用快照通过 `context.render` 交付。
4
+ */
5
+ export declare const WIDGET_EVENT_NAMES: readonly ["turn-start", "turn-end", "step-start", "step-end", "tool-call-generating", "tool-call-waiting", "tool-call-running", "tool-call-result", "tool-call-error", "workspace-file-changed", "workspace-tree-refresh", "workspace-file-opened", "ui-tool-opened", "ui-panel-focused", "host-surface-changed"];
6
+ /** `context.events.on` 可监听的实时事件名;不含仅用于激活的 `session.start`。 */
7
+ export type WidgetEventName = (typeof WIDGET_EVENT_NAMES)[number];
8
+ /**
9
+ * 判断一个字符串是否为合法的实时事件名。
10
+ * @param value 待检查的字符串。
11
+ * @returns 若 `value` 命中 `WIDGET_EVENT_NAMES` 则收窄为 `WidgetEventName`。
12
+ */
13
+ export declare function isWidgetEventName(value: unknown): value is WidgetEventName;
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, InitPayload, PresentationCapabilityResult, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, InitPayload, PresentationCapabilityResult, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "../protocol/index.js";
2
2
  import { type PresentationFocusDirection, type PresentationSurface, type RegionName, type WidgetCapabilityRequestOptions, type WidgetClientEvents, type WidgetClientState } from "./client.js";
3
3
  import { type SubscribeWidgetEventsOptions, type WidgetEventSubscription, type WidgetToolHooks } from "./events.js";
4
4
  import type { WidgetNetworkClient } from "./network.js";
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, GrantedCapability, InitPayload, PresentationCapabilityRequest, PresentationCapabilityResult, RegionCapabilityRequest, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, GrantedCapability, InitPayload, PresentationCapabilityRequest, PresentationCapabilityResult, RegionCapabilityRequest, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "../protocol/index.js";
2
2
  import { type WidgetNetworkClient } from "./network.js";
3
3
  import type { WidgetTransport } from "./transport.js";
4
4
  export type WidgetClientState = "created" | "waiting-ready" | "ready" | "disposed";
@@ -1,3 +1,3 @@
1
- import type { ToolLifecycleEvent, WidgetEventBatch } from "@dp-bohrium/widget-contracts";
1
+ import type { ToolLifecycleEvent, WidgetEventBatch } from "../protocol/index.js";
2
2
  export declare function parseWidgetEventBatch(value: unknown): WidgetEventBatch;
3
3
  export declare function parseToolLifecycleEvent(value: unknown): ToolLifecycleEvent;
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, GrantedCapability, ToolLifecycleEvent, WidgetEventBatch } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, GrantedCapability, ToolLifecycleEvent, WidgetEventBatch } from "../protocol/index.js";
2
2
  export interface WidgetEventSubscription {
3
3
  readonly cursor: string | undefined;
4
4
  readonly closed: Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, FileReadInput, FileReadResult, FileWriteInput, FileWriteResult } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, FileReadInput, FileReadResult, FileWriteInput, FileWriteResult } from "../protocol/index.js";
2
2
  import type { WidgetCapabilityRequestOptions, WidgetClientState } from "./client.js";
3
3
  type Failure = Extract<CapabilityResult, {
4
4
  ok: false;
@@ -1,4 +1,4 @@
1
- export type { RegionCapabilityResult } from "@dp-bohrium/widget-contracts";
1
+ export type { RegionCapabilityResult } from "../protocol/index.js";
2
2
  export type { CreateWidgetClientOptions, WidgetClientFactoryOptions, WidgetDisposeEvent, WidgetHostConnectMessage, WidgetLiveEventContext, WidgetLiveEventHandler, WidgetLiveEventName, WidgetRuntimeWindow, WidgetSize, } from "./bootstrap.js";
3
3
  export { createWidgetClient, isWidgetHostConnectMessage, WIDGET_BOOTSTRAP_READY, WIDGET_HOST_CONNECT, WIDGET_SDK_VERSION, WidgetRuntimeClient, } from "./bootstrap.js";
4
4
  export type { PresentationFocusDirection, PresentationSurface, RegionName, WidgetCapabilityRequestOptions, WidgetClientEvents, WidgetClientOptions, WidgetClientState, } from "./client.js";
@@ -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-DVFTv55x.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-DZA7Gqzl.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 };
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, InitPayload, RenderRequest, WidgetError } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, InitPayload, RenderRequest, WidgetError } from "../protocol/index.js";
2
2
  import type { WidgetTransport } from "./transport.js";
3
3
  export type MockWidgetHostState = "created" | "waiting-ready" | "ready" | "disposed";
4
4
  export interface MockWidgetHostOptions {
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, WidgetNetworkFetchInput, WidgetNetworkFetchOutput } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, WidgetNetworkFetchInput, WidgetNetworkFetchOutput } from "../protocol/index.js";
2
2
  import type { WidgetCapabilityRequestOptions, WidgetClientState } from "./client.js";
3
3
  export type WidgetNetworkFetchResult = Readonly<{
4
4
  ok: true;
@@ -1,4 +1,4 @@
1
- import type { WidgetProtocolMessage } from "@dp-bohrium/widget-contracts";
1
+ import type { WidgetProtocolMessage } from "../protocol/index.js";
2
2
  import { type WidgetTransport } from "./transport.js";
3
3
  declare const envelopeFields: readonly ["protocolVersion", "channelId", "messageId", "sequence"];
4
4
  type EnvelopeField = (typeof envelopeFields)[number];
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, JsonValue } from "@dp-bohrium/widget-contracts";
1
+ import type { CapabilityRequest, CapabilityResult, JsonValue } from "../protocol/index.js";
2
2
  import type { WidgetCapabilityRequestOptions, WidgetClientState } from "./client.js";
3
3
  export type WidgetServiceInvokeInput = Extract<CapabilityRequest, {
4
4
  operation: "service.invoke";
@@ -37,7 +37,7 @@ export interface WidgetHostUserClient {
37
37
  }
38
38
  interface Dependencies {
39
39
  readonly state: () => WidgetClientState;
40
- readonly grant: () => Extract<import("@dp-bohrium/widget-contracts").GrantedCapability, {
40
+ readonly grant: () => Extract<import("../protocol/index.js").GrantedCapability, {
41
41
  name: "service.invoke";
42
42
  }> | undefined;
43
43
  readonly request: (request: CapabilityRequest, options?: WidgetCapabilityRequestOptions) => Promise<CapabilityResult>;
@@ -1,4 +1,4 @@
1
- import type { WidgetProtocolMessage } from "@dp-bohrium/widget-contracts";
1
+ import type { WidgetProtocolMessage } from "../protocol/index.js";
2
2
  export interface WidgetTransport {
3
3
  send(message: WidgetProtocolMessage): void;
4
4
  onMessage(listener: (message: WidgetProtocolMessage) => void): () => void;
@@ -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.5.0";
5
+ const WIDGET_SDK_VERSION = "0.7.0";
6
6
  //#endregion
7
7
  //#region src/runtime/network.ts
8
8
  const failureReasons = /* @__PURE__ */ new Set([
@@ -0,0 +1,65 @@
1
+ //#region ../contracts/src/plugin-manifest.ts
2
+ /**
3
+ * Widget Host 公开的固定激活事件。数组同时作为清单编辑器文档和 Host
4
+ * 运行时校验的单一事实源;带工具名的事件使用下方的动态形式。
5
+ */
6
+ const WIDGET_ACTIVATION_EVENTS = [
7
+ "session.start",
8
+ "turn-start",
9
+ "turn-end",
10
+ "step-start",
11
+ "step-end",
12
+ "tool-call-generating",
13
+ "tool-call-waiting",
14
+ "tool-call-running",
15
+ "tool-call-result",
16
+ "tool-call-error",
17
+ "workspace-file-changed",
18
+ "workspace-tree-refresh",
19
+ "workspace-file-opened",
20
+ "ui-tool-opened",
21
+ "ui-panel-focused",
22
+ "host-surface-changed"
23
+ ];
24
+ const TOOL_EVENT_PATTERN = /^(?:tool-call-(?:generating|waiting|running|result|error)):[A-Za-z0-9_.:-]+$/u;
25
+ /**
26
+ * 判断一个字符串是否为合法激活事件(固定事件或带工具名的动态形式)。
27
+ * @param value 待检查的字符串。
28
+ * @returns 若命中固定目录或工具事件模式则收窄为 `WidgetActivationEvent`。
29
+ */
30
+ function isWidgetActivationEvent(value) {
31
+ return typeof value === "string" && (WIDGET_ACTIVATION_EVENTS.includes(value) || TOOL_EVENT_PATTERN.test(value));
32
+ }
33
+ //#endregion
34
+ //#region ../contracts/src/widget-events.ts
35
+ /**
36
+ * Host 主动推送给已激活 Widget 的实时事件。`session.start` 只用于激活索引,
37
+ * 不属于这组运行期事件;激活后首个可用快照通过 `context.render` 交付。
38
+ */
39
+ const WIDGET_EVENT_NAMES = [
40
+ "turn-start",
41
+ "turn-end",
42
+ "step-start",
43
+ "step-end",
44
+ "tool-call-generating",
45
+ "tool-call-waiting",
46
+ "tool-call-running",
47
+ "tool-call-result",
48
+ "tool-call-error",
49
+ "workspace-file-changed",
50
+ "workspace-tree-refresh",
51
+ "workspace-file-opened",
52
+ "ui-tool-opened",
53
+ "ui-panel-focused",
54
+ "host-surface-changed"
55
+ ];
56
+ /**
57
+ * 判断一个字符串是否为合法的实时事件名。
58
+ * @param value 待检查的字符串。
59
+ * @returns 若 `value` 命中 `WIDGET_EVENT_NAMES` 则收窄为 `WidgetEventName`。
60
+ */
61
+ function isWidgetEventName(value) {
62
+ return typeof value === "string" && WIDGET_EVENT_NAMES.includes(value);
63
+ }
64
+ //#endregion
65
+ export { isWidgetActivationEvent as i, isWidgetEventName as n, WIDGET_ACTIVATION_EVENTS as r, WIDGET_EVENT_NAMES as t };
package/dist/widget.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileReadInput, FileReference, FileWriteInput, GrantedCapability, RegionCapabilityResult, RenderRequest, TaskListPage, 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 "./protocol/index.js";
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";
@@ -96,7 +96,7 @@ export interface WidgetUiStateApi {
96
96
  readonly timeoutMs?: number;
97
97
  readonly signal?: AbortSignal;
98
98
  }): Promise<UiStateReadCapabilityResult>;
99
- write(key: string, value: import("@dp-bohrium/widget-contracts").JsonValue, options?: {
99
+ write(key: string, value: import("./protocol/index.js").JsonValue, options?: {
100
100
  readonly timeoutMs?: number;
101
101
  readonly signal?: AbortSignal;
102
102
  }): Promise<UiStateWriteCapabilityResult>;
package/llms.txt CHANGED
@@ -14,7 +14,14 @@
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
+ 作者工程使用精确 SDK 版本,通过上述入口获取运行时、协议、测试工具与工程命令。
24
+ 升级旧工程时,按迁移指南准备候选并重新构建,不复用不匹配的执行器或旧 receipt。
18
25
 
19
26
  ## 使用原则
20
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dp-bohrium/widget-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.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",
@@ -47,9 +59,6 @@
47
59
  "publishConfig": {
48
60
  "access": "public"
49
61
  },
50
- "dependencies": {
51
- "@dp-bohrium/widget-contracts": "0.5.0"
52
- },
53
62
  "devDependencies": {
54
63
  "@biomejs/biome": "^2.2.0",
55
64
  "@vitest/coverage-v8": "^3.2.4",
@@ -57,10 +66,13 @@
57
66
  "tsdown": "0.22.14",
58
67
  "typescript": "^5.8.3",
59
68
  "vitest": "^3.2.4",
69
+ "@dp-bohrium/widget-contracts": "0.7.0",
60
70
  "@dp-bohrium/widget-contract-testing": "0.1.0-alpha.0"
61
71
  },
62
72
  "scripts": {
63
- "build": "tsdown && tsc -b tsconfig.build.json --force --pretty false",
73
+ "build:runtime": "pnpm --filter @dp-bohrium/widget-contracts run build && tsdown && tsc -b tsconfig.build.json --force --pretty false && node ../../scripts/schema/build-sdk-assets.mjs",
74
+ "build:cli": "node ../../scripts/schema/build-sdk-cli-assets.mjs && tsdown --config widget-cli.tsdown.config.ts && node --check dist/cli.mjs",
75
+ "build": "pnpm build:runtime && pnpm --filter @dp-bohrium/widget-contract-testing build && pnpm build:cli",
64
76
  "typecheck": "tsc --noEmit",
65
77
  "test": "vitest run",
66
78
  "test:coverage": "vitest run --coverage --coverage.thresholds.lines=80 --coverage.thresholds.functions=80 --coverage.thresholds.statements=80 --coverage.thresholds.branches=70",
@@ -72,7 +84,7 @@
72
84
  "lint": "biome check src test",
73
85
  "format:check": "biome check --linter-enabled=false src test",
74
86
  "package:contents": "node ../../scripts/quality/check-sdk-package-contents.mjs ../../.artifacts/dp-bohrium-widget-sdk-*.tgz",
75
- "consumer:canary": "CONSUMER_PACKAGE_NAME=@dp-bohrium/widget-sdk node ../../scripts/consumer/consumer-install.mjs ../../.artifacts/dp-bohrium-widget-sdk-*.tgz ../../.artifacts/dp-bohrium-widget-contracts-*.tgz",
87
+ "consumer:canary": "node ../../scripts/consumer/consumer-sdk-install.mjs ../../.artifacts/dp-bohrium-widget-sdk-*.tgz",
76
88
  "release:check-version": "WIDGET_PACKAGE_NAME=@dp-bohrium/widget-sdk node ../../scripts/release/check-registry-version.mjs",
77
89
  "check": "pnpm typecheck && pnpm test && pnpm fixture:build && pnpm fixture:pack:test && pnpm lint && pnpm format:check && pnpm --filter @dp-bohrium/widget-contract-testing build && pnpm build && pnpm fixture:pack && pnpm fixture:check"
78
90
  }