@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,1224 @@
1
+ /** GENERATED FILE. Do not edit directly. */
2
+ /**
3
+ * Runtime 内部枚举;Forge 外部 Manifest 可声明的 Surface 仅为 file-preview 与 panel。tool-result 仅供受信任的内部 Host、Agent 事件与协议验证,不得作为外部作者 Contribution。
4
+ */
5
+ export type WidgetContributionKind = ("tool-result" | "file-preview" | "panel");
6
+ /**
7
+ * 完整渲染请求联合:tool-result(内部)/ file-preview / panel。
8
+ */
9
+ export type RenderRequest = (ToolResultRenderRequest | FilePreviewRenderRequest | PanelRenderRequest);
10
+ /**
11
+ * 历史 Host 投影类型;仅供受信任的内部 Host 与协议验证。Forge 新插件不得声明或挂载 tool-result,工具结果应由 Runtime 逻辑映射到自定义 Panel。
12
+ */
13
+ export type ToolResultRenderRequest = (RenderRequestBase & {
14
+ contribution: "tool-result";
15
+ content: ToolResultContent;
16
+ });
17
+ /**
18
+ * 渲染状态:loading / partial / complete / error。
19
+ */
20
+ export type RenderState = ("loading" | "partial" | "complete" | "error");
21
+ /**
22
+ * 主题模式:light 或 dark。
23
+ */
24
+ export type ThemeMode = ("light" | "dark");
25
+ /**
26
+ * Host 已授予的能力;多数分支附带调用与预算限制(ui.presentation / ui.region 除外)。
27
+ */
28
+ export type GrantedCapability = ({
29
+ name: "service.invoke";
30
+ services: WidgetServicePermissions;
31
+ limits: {
32
+ callsPerMinute: number;
33
+ requestBytes: number;
34
+ responseBytes: number;
35
+ };
36
+ } | {
37
+ name: "files.list";
38
+ limits: {
39
+ pageSize: number;
40
+ callsPerMinute: number;
41
+ };
42
+ } | {
43
+ name: "files.download";
44
+ limits: {
45
+ bytesPerRun: number;
46
+ callsPerMinute: number;
47
+ };
48
+ } | {
49
+ name: "files.metadata";
50
+ limits: {
51
+ callsPerMinute: number;
52
+ };
53
+ } | {
54
+ name: "files.read";
55
+ limits: {
56
+ bytesPerRequest: number;
57
+ /**
58
+ * @deprecated
59
+ * 历史读取累计额度字段,仅为兼容旧配置保留;当前 files.read 不累计或执行此额度,新宿主不再下发。
60
+ */
61
+ bytesPerRun?: number;
62
+ callsPerMinute: number;
63
+ };
64
+ } | {
65
+ name: "files.write";
66
+ limits: {
67
+ bytesPerRequest: number;
68
+ bytesPerRun: number;
69
+ callsPerMinute: number;
70
+ };
71
+ } | {
72
+ name: "events.read";
73
+ /**
74
+ * @minItems 1
75
+ * @maxItems 32
76
+ */
77
+ topics: [string, ...(string)[]];
78
+ limits: {
79
+ callsPerMinute: number;
80
+ pageSize: number;
81
+ minPollMs: number;
82
+ };
83
+ } | {
84
+ name: "tasks.list";
85
+ limits: {
86
+ callsPerMinute: number;
87
+ pageSize: number;
88
+ minPollMs: number;
89
+ };
90
+ } | {
91
+ name: "tasks.watch";
92
+ limits: {
93
+ callsPerMinute: number;
94
+ pageSize: number;
95
+ minPollMs: number;
96
+ };
97
+ } | {
98
+ name: "ui.state";
99
+ limits: {
100
+ callsPerMinute: number;
101
+ bytesPerRun: number;
102
+ maxValueBytes: number;
103
+ };
104
+ } | {
105
+ name: "actions.invoke";
106
+ /**
107
+ * @minItems 1
108
+ * @maxItems 32
109
+ */
110
+ actions: [string, ...(string)[]];
111
+ limits: {
112
+ callsPerMinute: number;
113
+ };
114
+ } | {
115
+ name: "network.fetch";
116
+ limits: WidgetNetworkLimits;
117
+ } | GrantedPresentationCapability | GrantedRegionCapability);
118
+ /**
119
+ * 服务权限列表。
120
+ *
121
+ * @minItems 1
122
+ * @maxItems 32
123
+ */
124
+ export type WidgetServicePermissions = [WidgetServicePermission, ...(WidgetServicePermission)[]];
125
+ /**
126
+ * 正整数。
127
+ */
128
+ export type PositiveInteger = number;
129
+ /**
130
+ * 可序列化为 JSON 的任意值;null / boolean / number / string / 数组 / 对象的递归联合。
131
+ */
132
+ export type JsonValue = (null | boolean | number | string | JsonValue[] | {
133
+ [k: string]: JsonValue;
134
+ });
135
+ /**
136
+ * 文件预览渲染请求:公共字段 + contribution=file-preview + content。
137
+ */
138
+ export type FilePreviewRenderRequest = (RenderRequestBase & {
139
+ contribution: "file-preview";
140
+ content: FilePreviewContent;
141
+ });
142
+ /**
143
+ * 由存储执行端签发的文件内容版本,用于条件读取和保存;不是 RenderRequest.revision。
144
+ */
145
+ export type FileRevision = string;
146
+ /**
147
+ * 面板渲染请求:公共字段 + contribution=panel + content。
148
+ */
149
+ export type PanelRenderRequest = (RenderRequestBase & {
150
+ contribution: "panel";
151
+ content: PanelContent;
152
+ });
153
+ /**
154
+ * Host → Widget 的 Bridge 消息联合。
155
+ */
156
+ export type HostToWidgetMessage = (InitMessage | RenderMessage | WidgetEventMessage | CapabilityResultMessage | ErrorMessage | DisposeMessage);
157
+ /**
158
+ * Host 下发初始上下文的 Bridge 消息。
159
+ */
160
+ export type InitMessage = (BridgeEnvelopeBase & {
161
+ type: "init";
162
+ payload: InitPayload;
163
+ });
164
+ /**
165
+ * Host 下发完整渲染快照的 Bridge 消息;type 为 render 或 update。
166
+ */
167
+ export type RenderMessage = (BridgeEnvelopeBase & {
168
+ type: ("render" | "update");
169
+ payload: RenderRequest;
170
+ });
171
+ /**
172
+ * Host 通过当前 Widget MessageChannel 主动推送的 Workflow 事件。
173
+ */
174
+ export type WidgetEventMessage = (BridgeEnvelopeBase & {
175
+ type: "event";
176
+ payload: WidgetLiveEvent;
177
+ });
178
+ /**
179
+ * 已激活 Widget 可监听的实时事件;session.start 只用于激活,不在此列。
180
+ */
181
+ export type WidgetEventName = ("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");
182
+ /**
183
+ * Host 返回能力请求结果的 Bridge 消息。
184
+ */
185
+ export type CapabilityResultMessage = (BridgeEnvelopeBase & {
186
+ type: "capability-result";
187
+ payload: {
188
+ requestId: string;
189
+ result: CapabilityResult;
190
+ };
191
+ });
192
+ /**
193
+ * 能力请求结果:成功时带 data,失败时带 reason / message / retryable。
194
+ */
195
+ export type CapabilityResult = ({
196
+ ok: true;
197
+ data: JsonValue;
198
+ } | {
199
+ ok: false;
200
+ reason: ("unsupported" | "permission-denied" | "resource-limit" | "invalid-reference" | "timeout" | "internal-error" | "network-consent-denied" | "network-policy-denied" | "network-transport-unavailable" | "network-request-too-large" | "network-response-too-large" | "network-rate-limited" | "network-redirect-denied" | "network-credential-unavailable" | "network-scope-invalid" | "network-dns-denied" | "network-error" | "revision-conflict" | "mutation-conflict" | "write-outcome-unknown");
201
+ message: string;
202
+ retryable: boolean;
203
+ });
204
+ /**
205
+ * 任一方向的结构化错误 Bridge 消息。
206
+ */
207
+ export type ErrorMessage = (BridgeEnvelopeBase & {
208
+ type: "error";
209
+ payload: WidgetError;
210
+ });
211
+ /**
212
+ * Host 通知销毁实例的终态 Bridge 消息。
213
+ */
214
+ export type DisposeMessage = (BridgeEnvelopeBase & {
215
+ type: "dispose";
216
+ payload: {
217
+ reason: string;
218
+ deadlineMs: number;
219
+ };
220
+ });
221
+ /**
222
+ * Widget → Host 的 Bridge 消息联合。
223
+ */
224
+ export type WidgetToHostMessage = (ReadyMessage | ResizeMessage | CapabilityRequestMessage | ErrorMessage);
225
+ /**
226
+ * Widget 向 Host 上报就绪的 Bridge 消息;含 SDK 与 Host API 版本。
227
+ */
228
+ export type ReadyMessage = (BridgeEnvelopeBase & {
229
+ type: "ready";
230
+ payload: {
231
+ widgetSdkVersion: string;
232
+ hostApiVersion: 1;
233
+ };
234
+ });
235
+ /**
236
+ * Widget 请求调整视口尺寸的 Bridge 消息。
237
+ */
238
+ export type ResizeMessage = (BridgeEnvelopeBase & {
239
+ type: "resize";
240
+ payload: {
241
+ width: number;
242
+ height: number;
243
+ };
244
+ });
245
+ /**
246
+ * Widget 发起能力请求的 Bridge 消息。
247
+ */
248
+ export type CapabilityRequestMessage = (BridgeEnvelopeBase & {
249
+ type: "capability-request";
250
+ payload: {
251
+ requestId: string;
252
+ request: CapabilityRequest;
253
+ };
254
+ });
255
+ /**
256
+ * Widget 发起的能力请求;以 operation 判别语义与 input。
257
+ */
258
+ export type CapabilityRequest = ({
259
+ operation: "service.invoke";
260
+ input: {
261
+ service: string;
262
+ action: string;
263
+ payload: JsonValue;
264
+ };
265
+ } | {
266
+ operation: "files.list";
267
+ input: {
268
+ directory: FileReference;
269
+ cursor?: string;
270
+ limit?: number;
271
+ };
272
+ } | {
273
+ operation: "files.metadata";
274
+ input: {
275
+ reference: FileReference;
276
+ };
277
+ } | {
278
+ operation: "files.read";
279
+ input: FileReadInput;
280
+ } | {
281
+ operation: "files.write";
282
+ input: FileWriteInput;
283
+ } | {
284
+ operation: "files.download";
285
+ input: {
286
+ file: FileReference;
287
+ suggestedName: string;
288
+ };
289
+ } | {
290
+ operation: "tasks.list";
291
+ input: {
292
+ cursor?: string;
293
+ limit?: number;
294
+ };
295
+ } | {
296
+ operation: "tasks.watch";
297
+ input: {
298
+ taskId: string;
299
+ cursor?: string;
300
+ limit?: number;
301
+ };
302
+ } | {
303
+ operation: "ui.state";
304
+ input: ({
305
+ action: "read";
306
+ key: string;
307
+ } | {
308
+ action: "write";
309
+ key: string;
310
+ value: JsonValue;
311
+ });
312
+ } | {
313
+ operation: "events.read";
314
+ input: {
315
+ topic: string;
316
+ cursor?: string;
317
+ limit: number;
318
+ };
319
+ } | {
320
+ operation: "actions.invoke";
321
+ input: {
322
+ action: string;
323
+ idempotencyKey: string;
324
+ arguments: JsonValue;
325
+ };
326
+ } | {
327
+ operation: "network.fetch";
328
+ input: WidgetNetworkFetchInput;
329
+ } | PresentationCapabilityRequest | RegionCapabilityRequest);
330
+ /**
331
+ * 一次逻辑保存的稳定标识;重试或确认结果时必须复用,相同标识不得提交不同内容。
332
+ */
333
+ export type FileMutationId = string;
334
+ /**
335
+ * 呈现能力请求:present / change-surface、close,或 focus-boundary。
336
+ */
337
+ export type PresentationCapabilityRequest = ({
338
+ operation: "ui.presentation";
339
+ input: ({
340
+ action: ("present" | "change-surface");
341
+ surface: ("workspace" | "floating" | "overlay");
342
+ } | {
343
+ action: "close";
344
+ });
345
+ } | FocusBoundaryPresentationCapabilityRequest);
346
+ /**
347
+ * 呈现焦点边界请求:forward 或 backward。
348
+ */
349
+ export type FocusBoundaryPresentationCapabilityRequest = {
350
+ operation: "ui.presentation";
351
+ input: {
352
+ action: "focus-boundary";
353
+ direction: ("forward" | "backward");
354
+ };
355
+ };
356
+ /**
357
+ * 区域能力请求:acquire 或 release。
358
+ */
359
+ export type RegionCapabilityRequest = ({
360
+ operation: "ui.region";
361
+ input: {
362
+ action: "acquire";
363
+ region: "session.rightRail";
364
+ };
365
+ } | {
366
+ operation: "ui.region";
367
+ input: {
368
+ action: "release";
369
+ };
370
+ });
371
+ /**
372
+ * Agent Widget 从已解析 Workflow 事件构造并向 Widget Runtime 推送的事件联合。
373
+ */
374
+ export type PublicWidgetEvent = (WorkflowStartedPublicWidgetEvent | WorkflowDonePublicWidgetEvent | WorkflowErrorPublicWidgetEvent | ToolCallPublicWidgetEvent | ToolResultPublicWidgetEvent | SandboxApprovalRequestedPublicWidgetEvent | SandboxApprovedPublicWidgetEvent | SandboxDeniedPublicWidgetEvent | UserInputRequestedPublicWidgetEvent | ComputeReviewRequestedPublicWidgetEvent);
375
+ /**
376
+ * Workflow 流建立事件。
377
+ */
378
+ export type WorkflowStartedPublicWidgetEvent = (PublicWidgetEventBase & {
379
+ topic: "workflow.lifecycle";
380
+ type: "connected";
381
+ payload: WorkflowStartedPublicWidgetEventPayload;
382
+ });
383
+ /**
384
+ * 用于同一 Agent Widget Runtime 内去重的稳定事件标识。
385
+ */
386
+ export type PublicWidgetEventId = string;
387
+ /**
388
+ * 事件产生时间:YYYY-MM-DD + T + 非空格字符,以 Z 结尾。
389
+ */
390
+ export type PublicWidgetEventOccurredAt = string;
391
+ /**
392
+ * 事件所属的 Session 标识。
393
+ */
394
+ export type PublicWidgetSessionId = string;
395
+ /**
396
+ * 事件所属的 Workflow 标识。
397
+ */
398
+ export type PublicWidgetWorkflowId = string;
399
+ /**
400
+ * Workflow 正常终态事件。
401
+ */
402
+ export type WorkflowDonePublicWidgetEvent = (PublicWidgetEventBase & {
403
+ topic: "workflow.lifecycle";
404
+ type: "done";
405
+ payload: WorkflowDonePublicWidgetEventPayload;
406
+ });
407
+ /**
408
+ * Workflow 错误事件。
409
+ */
410
+ export type WorkflowErrorPublicWidgetEvent = (PublicWidgetEventBase & {
411
+ topic: "workflow.lifecycle";
412
+ type: "error";
413
+ payload: WorkflowErrorPublicWidgetEventPayload;
414
+ });
415
+ /**
416
+ * tool-call 事件。
417
+ */
418
+ export type ToolCallPublicWidgetEvent = (PublicWidgetEventBase & {
419
+ topic: "tools.lifecycle";
420
+ type: "tool-call";
421
+ payload: ToolCallPublicWidgetEventPayload;
422
+ });
423
+ /**
424
+ * tool-result 事件。
425
+ */
426
+ export type ToolResultPublicWidgetEvent = (PublicWidgetEventBase & {
427
+ topic: "tools.lifecycle";
428
+ type: "tool-result";
429
+ payload: ToolResultPublicWidgetEventPayload;
430
+ });
431
+ /**
432
+ * sandbox-approval-requested 事件。
433
+ */
434
+ export type SandboxApprovalRequestedPublicWidgetEvent = (PublicWidgetEventBase & {
435
+ topic: "approval.lifecycle";
436
+ type: "sandbox-approval-requested";
437
+ payload: SandboxApprovalRequestedPublicWidgetEventPayload;
438
+ });
439
+ /**
440
+ * sandbox-approved 事件。
441
+ */
442
+ export type SandboxApprovedPublicWidgetEvent = (PublicWidgetEventBase & {
443
+ topic: "approval.lifecycle";
444
+ type: "sandbox-approved";
445
+ payload: SandboxApprovedPublicWidgetEventPayload;
446
+ });
447
+ /**
448
+ * sandbox-denied 事件。
449
+ */
450
+ export type SandboxDeniedPublicWidgetEvent = (PublicWidgetEventBase & {
451
+ topic: "approval.lifecycle";
452
+ type: "sandbox-denied";
453
+ payload: EmptyPublicWidgetEventPayload;
454
+ });
455
+ /**
456
+ * user-input-requested 事件。
457
+ */
458
+ export type UserInputRequestedPublicWidgetEvent = (PublicWidgetEventBase & {
459
+ topic: "interaction.lifecycle";
460
+ type: "user-input-requested";
461
+ payload: UserInputRequestedPublicWidgetEventPayload;
462
+ });
463
+ /**
464
+ * compute-review-requested 事件。
465
+ */
466
+ export type ComputeReviewRequestedPublicWidgetEvent = (PublicWidgetEventBase & {
467
+ topic: "interaction.lifecycle";
468
+ type: "compute-review-requested";
469
+ payload: ComputeReviewRequestedPublicWidgetEventPayload;
470
+ });
471
+ /**
472
+ * Agent Widget 从当前 Workflow 流公开的事件主题。
473
+ */
474
+ export type PublicWidgetEventTopic = ("workflow.lifecycle" | "tools.lifecycle" | "approval.lifecycle" | "interaction.lifecycle");
475
+ /**
476
+ * 呈现能力输出:present / change-surface / focus-boundary / close。
477
+ */
478
+ export type PresentationCapabilityOutput = ({
479
+ action: ("present" | "change-surface");
480
+ surface: ("workspace" | "floating" | "overlay");
481
+ } | {
482
+ action: "close";
483
+ } | {
484
+ action: "focus-boundary";
485
+ direction: ("forward" | "backward");
486
+ });
487
+ /**
488
+ * 呈现能力请求的结果。
489
+ */
490
+ export type PresentationCapabilityResult = ({
491
+ ok: true;
492
+ data: PresentationCapabilityOutput;
493
+ } | {
494
+ ok: false;
495
+ reason: ("unsupported" | "permission-denied" | "resource-limit" | "invalid-reference" | "timeout" | "internal-error" | "network-consent-denied" | "network-policy-denied" | "network-transport-unavailable" | "network-request-too-large" | "network-response-too-large" | "network-rate-limited" | "network-redirect-denied" | "network-credential-unavailable" | "network-scope-invalid" | "network-dns-denied" | "network-error");
496
+ message: string;
497
+ retryable: boolean;
498
+ });
499
+ /**
500
+ * 区域能力请求的结果;成功时含不透明 leaseId。
501
+ */
502
+ export type RegionCapabilityResult = ({
503
+ ok: true;
504
+ data: {
505
+ action: ("acquire" | "release");
506
+ region: "session.rightRail";
507
+ mode: "replace";
508
+ leaseId?: string;
509
+ };
510
+ } | {
511
+ ok: false;
512
+ reason: ("unsupported" | "permission-denied" | "resource-limit" | "invalid-reference" | "timeout" | "internal-error");
513
+ message: string;
514
+ retryable: boolean;
515
+ });
516
+ /**
517
+ * Host 投影给 Widget 的统一任务状态。
518
+ */
519
+ export type TaskStatus = ("queued" | "running" | "succeeded" | "failed" | "cancelled" | "expired");
520
+ /**
521
+ * Host 用户服务标识;固定为 host.user。
522
+ */
523
+ export type HostUserService = "host.user";
524
+ /**
525
+ * Host 用户服务下的具体动作:个人资料或邮箱读取。
526
+ */
527
+ export type HostUserAction = ("profile.read" | "email.read");
528
+ /**
529
+ * 读取用户资料的请求输入;当前无需额外参数(null)。
530
+ */
531
+ export type HostUserProfileReadInput = null;
532
+ /**
533
+ * 读取用户邮箱的请求输入;当前无需额外参数(null)。
534
+ */
535
+ export type HostUserEmailReadInput = null;
536
+ /**
537
+ * Host 用户服务请求;以 action 判别资料或邮箱读取。
538
+ */
539
+ export type HostUserServiceRequest = ({
540
+ service: HostUserService;
541
+ action: "profile.read";
542
+ payload: HostUserProfileReadInput;
543
+ } | {
544
+ service: HostUserService;
545
+ action: "email.read";
546
+ payload: HostUserEmailReadInput;
547
+ });
548
+ /**
549
+ * Runtime 契约的汇总根容器;仅用于代码生成与符合性校验,不直接对外签发。
550
+ */
551
+ export interface WidgetRuntimeContracts {
552
+ widgetContributionKind: WidgetContributionKind;
553
+ renderRequest: RenderRequest;
554
+ hostToWidgetMessage: HostToWidgetMessage;
555
+ widgetToHostMessage: WidgetToHostMessage;
556
+ capabilityRequest: CapabilityRequest;
557
+ capabilityResult: CapabilityResult;
558
+ widgetError: WidgetError;
559
+ resourceBudget: ResourceBudget;
560
+ widgetEventBatch?: WidgetEventBatch;
561
+ toolLifecycleEvent?: ToolLifecycleEvent;
562
+ publicWidgetEvent?: PublicWidgetEvent;
563
+ widgetLiveEvent?: WidgetLiveEvent;
564
+ publicWidgetEventTopic?: PublicWidgetEventTopic;
565
+ widgetNetworkFetchOutput?: WidgetNetworkFetchOutput;
566
+ presentationCapabilityOutput?: PresentationCapabilityOutput;
567
+ presentationCapabilityResult?: PresentationCapabilityResult;
568
+ regionCapabilityResult?: RegionCapabilityResult;
569
+ fileDownloadResult?: FileDownloadResult;
570
+ fileReadResult?: FileReadResult;
571
+ fileWriteResult?: FileWriteResult;
572
+ taskObservationSnapshot?: TaskObservationSnapshot;
573
+ taskObservationEvent?: TaskObservationEvent;
574
+ taskObservationBatch?: TaskObservationBatch;
575
+ taskListField?: TaskListField;
576
+ taskListItem?: TaskListItem;
577
+ taskListPage?: TaskListPage;
578
+ toolResultEnvelope?: ToolResultEnvelope;
579
+ uiStateResult?: UiStateResult;
580
+ uiStateWriteResult?: UiStateWriteResult;
581
+ hostUserService?: HostUserService;
582
+ hostUserAction?: HostUserAction;
583
+ hostUserProfileReadInput?: HostUserProfileReadInput;
584
+ hostUserProfileReadOutput?: HostUserProfileReadOutput;
585
+ hostUserEmailReadInput?: HostUserEmailReadInput;
586
+ hostUserEmailReadOutput?: HostUserEmailReadOutput;
587
+ hostUserServiceRequest?: HostUserServiceRequest;
588
+ }
589
+ /**
590
+ * 渲染请求公共字段:schemaVersion、requestId、instanceId、revision、state、context。
591
+ */
592
+ export interface RenderRequestBase {
593
+ schemaVersion: 1;
594
+ requestId: string;
595
+ instanceId: string;
596
+ revision: number;
597
+ state: RenderState;
598
+ context: WidgetRenderContext;
599
+ }
600
+ /**
601
+ * 渲染上下文:locale、theme、viewport、能力与关联 id。
602
+ */
603
+ export interface WidgetRenderContext {
604
+ locale: string;
605
+ theme: Theme;
606
+ viewport: {
607
+ width: number;
608
+ height: number;
609
+ };
610
+ capabilities: GrantedCapability[];
611
+ correlationId: string;
612
+ }
613
+ /**
614
+ * 渲染上下文中的主题:mode 与设计令牌表。
615
+ */
616
+ export interface Theme {
617
+ mode: ThemeMode;
618
+ tokens: {
619
+ background: string;
620
+ foreground: string;
621
+ muted: string;
622
+ mutedForeground: string;
623
+ border: string;
624
+ primary: string;
625
+ danger: string;
626
+ };
627
+ }
628
+ /**
629
+ * 单条服务权限:服务名 + 允许的动作列表。
630
+ */
631
+ export interface WidgetServicePermission {
632
+ service: string;
633
+ /**
634
+ * @minItems 1
635
+ * @maxItems 32
636
+ */
637
+ actions: [string, ...(string)[]];
638
+ }
639
+ /**
640
+ * Host 托管网络的限制项:超时、并发、频率与字节数。
641
+ */
642
+ export interface WidgetNetworkLimits {
643
+ timeoutMs: PositiveInteger;
644
+ maxRedirects: PositiveInteger;
645
+ maxConcurrentRequests: PositiveInteger;
646
+ callsPerMinute: PositiveInteger;
647
+ requestHeaderBytes: PositiveInteger;
648
+ responseHeaderBytes: PositiveInteger;
649
+ requestBodyBytes: PositiveInteger;
650
+ responseBodyBytes: PositiveInteger;
651
+ }
652
+ /**
653
+ * 已授予的呈现能力;含 surfaces,requiresHostConfirmation 恒为 true。
654
+ */
655
+ export interface GrantedPresentationCapability {
656
+ name: "ui.presentation";
657
+ /**
658
+ * @minItems 1
659
+ * @maxItems 2
660
+ */
661
+ surfaces: [("floating" | "overlay")] | [("floating" | "overlay"), ("floating" | "overlay")];
662
+ requiresHostConfirmation: true;
663
+ }
664
+ /**
665
+ * 已授予的会话右侧区域替换能力。
666
+ */
667
+ export interface GrantedRegionCapability {
668
+ name: "ui.region";
669
+ /**
670
+ * @minItems 1
671
+ * @maxItems 1
672
+ */
673
+ regions: ["session.rightRail"];
674
+ mode: "replace";
675
+ requiresHostConfirmation: true;
676
+ }
677
+ /**
678
+ * tool-result 渲染内容;仅内部通道使用,外部作者不挂载。
679
+ */
680
+ export interface ToolResultContent {
681
+ contribution: "tool-result";
682
+ tool: {
683
+ name: string;
684
+ callId: string;
685
+ status: ("running" | "succeeded" | "failed" | "cancelled");
686
+ };
687
+ input: JsonValue;
688
+ result?: JsonValue;
689
+ envelope?: ToolResultEnvelope;
690
+ error?: {
691
+ code: string;
692
+ message: string;
693
+ };
694
+ }
695
+ /**
696
+ * 工具执行结果信封;仅供受信任的内部 Host 与 Agent 事件,不进入作者 Contribution。
697
+ */
698
+ export interface ToolResultEnvelope {
699
+ schemaVersion: 1;
700
+ status: ("running" | "succeeded" | "failed" | "cancelled");
701
+ summary?: string;
702
+ data?: JsonValue;
703
+ /**
704
+ * @maxItems 64
705
+ */
706
+ metrics?: ToolResultMetric[];
707
+ /**
708
+ * @maxItems 64
709
+ */
710
+ artifacts?: ToolResultArtifact[];
711
+ /**
712
+ * @maxItems 32
713
+ */
714
+ provenance?: ToolResultProvenance[];
715
+ /**
716
+ * @maxItems 32
717
+ */
718
+ warnings?: ToolResultNotice[];
719
+ /**
720
+ * @maxItems 32
721
+ */
722
+ missing?: ToolResultNotice[];
723
+ }
724
+ /**
725
+ * 工具结果中的单个指标。
726
+ */
727
+ export interface ToolResultMetric {
728
+ name: string;
729
+ value: number;
730
+ unit?: string;
731
+ label?: string;
732
+ }
733
+ /**
734
+ * 工具结果中的产物元数据,不含内容本身。
735
+ */
736
+ export interface ToolResultArtifact {
737
+ id: string;
738
+ name: string;
739
+ kind?: ("file" | "directory");
740
+ mimeType?: string;
741
+ size?: number;
742
+ downloadable?: boolean;
743
+ }
744
+ /**
745
+ * 工具结果的来源信息。
746
+ */
747
+ export interface ToolResultProvenance {
748
+ source: string;
749
+ kind?: string;
750
+ label?: string;
751
+ }
752
+ /**
753
+ * 工具结果中的提示或警告。
754
+ */
755
+ export interface ToolResultNotice {
756
+ code: string;
757
+ message: string;
758
+ }
759
+ /**
760
+ * 文件预览内容;contribution 必须为 file-preview。
761
+ */
762
+ export interface FilePreviewContent {
763
+ contribution: "file-preview";
764
+ file: FileReference;
765
+ preview?: JsonValue;
766
+ }
767
+ /**
768
+ * Host 签发的文件引用;仅含不透明 id、可选内容版本和展示元数据。引用本身不授予写权限,不含路径或 URL。
769
+ */
770
+ export interface FileReference {
771
+ id: string;
772
+ kind: ("file" | "directory");
773
+ name: string;
774
+ extension?: string;
775
+ mimeType?: string;
776
+ size?: number;
777
+ revision?: FileRevision;
778
+ }
779
+ /**
780
+ * 面板内容;contribution 必须为 panel。
781
+ */
782
+ export interface PanelContent {
783
+ contribution: "panel";
784
+ id: string;
785
+ title?: string;
786
+ data: JsonValue;
787
+ }
788
+ /**
789
+ * Bridge 信封公共字段:protocolVersion、channelId、messageId、sequence。
790
+ */
791
+ export interface BridgeEnvelopeBase {
792
+ protocolVersion: 1;
793
+ channelId: string;
794
+ messageId: string;
795
+ sequence: number;
796
+ }
797
+ /**
798
+ * init 消息负载:实例、locale、theme、能力与资源预算。
799
+ */
800
+ export interface InitPayload {
801
+ instanceId: string;
802
+ locale: string;
803
+ theme: Theme;
804
+ capabilities: GrantedCapability[];
805
+ resourceBudget: ResourceBudget;
806
+ }
807
+ /**
808
+ * Host 为当前运行签发的资源预算:包、Bridge、文件、超时、并发、重试与失败。
809
+ */
810
+ export interface ResourceBudget {
811
+ version: 1;
812
+ bundle: {
813
+ compressedBytes: number;
814
+ expandedBytes: number;
815
+ fileCount: number;
816
+ singleFileBytes: number;
817
+ };
818
+ bridge: {
819
+ messageBytes: number;
820
+ messagesPerSecond: number;
821
+ pendingRequests: number;
822
+ };
823
+ files: {
824
+ readBytesPerRequest: number;
825
+ /**
826
+ * @deprecated
827
+ * 历史读取累计额度字段,仅为兼容旧配置保留;当前 files.read 不累计或执行此额度,新宿主不再下发。
828
+ */
829
+ readBytesPerRun?: number;
830
+ callsPerMinute: number;
831
+ listPageSize: number;
832
+ /**
833
+ * 写入单次原始字节上限;未签发时不得授权 files.write。
834
+ */
835
+ writeBytesPerRequest?: number;
836
+ /**
837
+ * 当前运行的累计写入原始字节上限;未签发时不得授权 files.write。
838
+ */
839
+ writeBytesPerRun?: number;
840
+ };
841
+ timeouts: {
842
+ bundleLoadMs: number;
843
+ handshakeMs: number;
844
+ firstRenderMs: number;
845
+ updateMs: number;
846
+ capabilityMs: number;
847
+ disposeGraceMs: number;
848
+ };
849
+ concurrency: {
850
+ activeIframesPerPage: number;
851
+ activeIframesPerRun: number;
852
+ hiddenRecycleMs: number;
853
+ };
854
+ retry: {
855
+ maxAttempts: number;
856
+ initialDelayMs: number;
857
+ maxDelayMs: number;
858
+ totalMs: number;
859
+ };
860
+ failure: {
861
+ consecutiveFailures: number;
862
+ windowMs: number;
863
+ };
864
+ }
865
+ /**
866
+ * Host 从当前 Runtime 向 iframe 主动推送的聚合事件;事件由 type 唯一标识。
867
+ */
868
+ export interface WidgetLiveEvent {
869
+ type: WidgetEventName;
870
+ payload: {
871
+ [k: string]: JsonValue;
872
+ };
873
+ }
874
+ /**
875
+ * 结构化稳定错误:code + phase + message + retryable + correlationId。
876
+ */
877
+ export interface WidgetError {
878
+ code: ("BUNDLE_LOAD_FAILED" | "DIGEST_MISMATCH" | "RUNTIME_CONFIG_EXPIRED" | "WIDGET_VERSION_REVOKED" | "HOST_API_UNSUPPORTED" | "HANDSHAKE_TIMEOUT" | "MESSAGE_INVALID" | "CHANNEL_MISMATCH" | "MESSAGE_TOO_LARGE" | "MESSAGE_RATE_LIMITED" | "TOO_MANY_PENDING_REQUESTS" | "CAPABILITY_UNDECLARED" | "CAPABILITY_DENIED" | "CAPABILITY_UNSUPPORTED" | "CAPABILITY_TIMEOUT" | "FILE_REFERENCE_INVALID" | "FILE_PERMISSION_DENIED" | "RESOURCE_LIMIT" | "RENDER_FAILED" | "UPDATE_FAILED" | "WIDGET_CRASHED" | "INSTANCE_DISPOSED");
879
+ phase: ("load" | "handshake" | "render" | "update" | "capability" | "dispose");
880
+ message: string;
881
+ retryable: boolean;
882
+ correlationId: string;
883
+ }
884
+ /**
885
+ * 分块读取已授权文件;后续分块应携带首块返回的 expectedRevision,防止拼接不同版本。
886
+ */
887
+ export interface FileReadInput {
888
+ file: FileReference;
889
+ offset: number;
890
+ length: number;
891
+ encoding: ("utf8" | "base64");
892
+ expectedRevision?: FileRevision;
893
+ }
894
+ /**
895
+ * 按 Host 授权范围对已有文件作整文件条件替换;Host 校验引用、作用域、权限和实际字节预算。超时不表示未写入,使用同一 mutationId 核对结果。
896
+ */
897
+ export interface FileWriteInput {
898
+ file: FileReference;
899
+ content: string;
900
+ encoding: ("utf8" | "base64");
901
+ expectedRevision: FileRevision;
902
+ mutationId: FileMutationId;
903
+ }
904
+ /**
905
+ * Host 托管网络请求输入;url 由 Host 校验,auth 声明凭据需求。
906
+ */
907
+ export interface WidgetNetworkFetchInput {
908
+ url: string;
909
+ auth: ("none" | "optional" | "required");
910
+ method?: ("GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE");
911
+ headers?: WidgetNetworkRequestHeaders;
912
+ body?: string;
913
+ bodyEncoding?: ("utf8" | "base64");
914
+ redirect?: ("follow" | "manual" | "error");
915
+ }
916
+ /**
917
+ * Widget 发起网络请求时附加的请求头集合。
918
+ */
919
+ export interface WidgetNetworkRequestHeaders {
920
+ [k: string]: string;
921
+ }
922
+ /**
923
+ * 低层 events.read 的一页事件:topic、cursor、reset、hasMore 与事件列表。
924
+ */
925
+ export interface WidgetEventBatch {
926
+ schemaVersion: 1;
927
+ topic: string;
928
+ cursor: string;
929
+ reset: boolean;
930
+ hasMore: boolean;
931
+ /**
932
+ * @maxItems 100
933
+ */
934
+ events: WidgetEvent[];
935
+ snapshot?: JsonValue;
936
+ }
937
+ /**
938
+ * 低层 events.read 事件页中的单条原始事件;type 为受限标识、payload 为 JSON。
939
+ */
940
+ export interface WidgetEvent {
941
+ id: string;
942
+ type: string;
943
+ payload: JsonValue;
944
+ }
945
+ /**
946
+ * 工具生命周期事件:started / completed / failed / cancelled。
947
+ */
948
+ export interface ToolLifecycleEvent {
949
+ toolCallId: string;
950
+ toolName: string;
951
+ phase: ("started" | "completed" | "failed" | "cancelled");
952
+ }
953
+ /**
954
+ * 公开事件公共字段:schemaVersion、id、occurredAt、sessionId、workflowId。
955
+ */
956
+ export interface PublicWidgetEventBase {
957
+ schemaVersion: 1;
958
+ id: PublicWidgetEventId;
959
+ occurredAt: PublicWidgetEventOccurredAt;
960
+ sessionId: PublicWidgetSessionId;
961
+ workflowId: PublicWidgetWorkflowId;
962
+ }
963
+ /**
964
+ * Workflow 流已建立时公开的数据。
965
+ */
966
+ export interface WorkflowStartedPublicWidgetEventPayload {
967
+ protocolVersion: number;
968
+ }
969
+ /**
970
+ * Workflow 正常结束时公开的数据。
971
+ */
972
+ export interface WorkflowDonePublicWidgetEventPayload {
973
+ status: ("completed" | "failed" | "cancelled" | "expired");
974
+ durationMs?: number;
975
+ error?: string;
976
+ }
977
+ /**
978
+ * Workflow 错误事件公开的数据。
979
+ */
980
+ export interface WorkflowErrorPublicWidgetEventPayload {
981
+ terminal: boolean;
982
+ error?: string;
983
+ }
984
+ /**
985
+ * tool-call 原始语义对应的公开数据。
986
+ */
987
+ export interface ToolCallPublicWidgetEventPayload {
988
+ toolCallId: string;
989
+ toolName: string;
990
+ args?: JsonValue;
991
+ executionState?: ("waiting" | "running");
992
+ }
993
+ /**
994
+ * tool-result 原始语义对应的公开数据。
995
+ */
996
+ export interface ToolResultPublicWidgetEventPayload {
997
+ toolCallId: string;
998
+ toolName?: string;
999
+ output: JsonValue;
1000
+ durationMs?: number;
1001
+ }
1002
+ /**
1003
+ * 沙盒审批请求公开的数据。
1004
+ */
1005
+ export interface SandboxApprovalRequestedPublicWidgetEventPayload {
1006
+ approvalId: string;
1007
+ mode: ("create" | "reuse");
1008
+ sandboxName?: string;
1009
+ resource?: JsonValue;
1010
+ existingSandboxes?: {
1011
+ id: string;
1012
+ name: string;
1013
+ }[];
1014
+ proxyAgentName?: string;
1015
+ }
1016
+ /**
1017
+ * 沙盒审批通过时公开的数据。
1018
+ */
1019
+ export interface SandboxApprovedPublicWidgetEventPayload {
1020
+ sandboxId: string;
1021
+ }
1022
+ /**
1023
+ * 没有额外业务字段的事件负载。
1024
+ */
1025
+ export interface EmptyPublicWidgetEventPayload {
1026
+ }
1027
+ /**
1028
+ * 用户输入请求公开的数据。
1029
+ */
1030
+ export interface UserInputRequestedPublicWidgetEventPayload {
1031
+ toolCallId?: string;
1032
+ requestId?: string;
1033
+ request?: JsonValue;
1034
+ schema?: JsonValue;
1035
+ title?: string;
1036
+ description?: string;
1037
+ retryAttempt?: number;
1038
+ retryMessage?: string;
1039
+ cancellable?: boolean;
1040
+ timeoutSeconds?: number;
1041
+ proxyWorkflowId?: string;
1042
+ proxyAgentName?: string;
1043
+ }
1044
+ /**
1045
+ * 计算任务审批请求公开的数据。
1046
+ */
1047
+ export interface ComputeReviewRequestedPublicWidgetEventPayload {
1048
+ draftId: string;
1049
+ toolCallId: string;
1050
+ }
1051
+ /**
1052
+ * Host 托管网络请求结果;body 按 bodyEncoding 解释。
1053
+ */
1054
+ export interface WidgetNetworkFetchOutput {
1055
+ status: number;
1056
+ statusText: string;
1057
+ headers: NetworkHeaders;
1058
+ body: string;
1059
+ bodyEncoding: ("utf8" | "base64");
1060
+ finalUrl: string;
1061
+ redirected: boolean;
1062
+ }
1063
+ /**
1064
+ * HTTP 响应头集合。
1065
+ */
1066
+ export interface NetworkHeaders {
1067
+ [k: string]: string;
1068
+ }
1069
+ /**
1070
+ * 文件下载保存意图的结果:saved / started / cancelled。
1071
+ */
1072
+ export interface FileDownloadResult {
1073
+ status: ("saved" | "started" | "cancelled");
1074
+ }
1075
+ /**
1076
+ * 文件读取结果;普通读取只要求内容与编码,原有游标和截断信息按 Host 能力返回。revision 可选且必须与本次读取的内容属于同一快照;请求 expectedRevision 时必须返回匹配版本。缺少 revision 的结果仅用于只读展示,不能据此条件保存。提供字节游标时 nextOffset 等于请求 offset + bytesRead,不按字符串长度计数。
1077
+ */
1078
+ export interface FileReadResult {
1079
+ content: string;
1080
+ encoding: ("utf8" | "base64");
1081
+ offset?: number;
1082
+ bytesRead?: number;
1083
+ nextOffset?: number;
1084
+ eof?: boolean;
1085
+ truncated?: boolean;
1086
+ revision?: FileRevision;
1087
+ }
1088
+ /**
1089
+ * 执行端已确认持久化的保存回执;file.id 保持原文件引用身份,revision 是新内容版本。
1090
+ */
1091
+ export interface FileWriteResult {
1092
+ file: FileReference;
1093
+ revision: FileRevision;
1094
+ bytesWritten: number;
1095
+ mutationId: FileMutationId;
1096
+ }
1097
+ /**
1098
+ * 任务观察的当前快照:taskId、status 与 updatedAt;progress、message 可选。
1099
+ */
1100
+ export interface TaskObservationSnapshot {
1101
+ taskId: string;
1102
+ status: TaskStatus;
1103
+ progress?: number;
1104
+ message?: string;
1105
+ updatedAt: string;
1106
+ }
1107
+ /**
1108
+ * 任务观察流中的单条事件;payload 由服务端裁剪。
1109
+ */
1110
+ export interface TaskObservationEvent {
1111
+ id: string;
1112
+ type: ("started" | "progress" | "succeeded" | "failed" | "cancelled" | "expired");
1113
+ occurredAt: string;
1114
+ payload: JsonValue;
1115
+ }
1116
+ /**
1117
+ * 任务观察的一页结果:快照 + 有限事件页 + 游标。
1118
+ */
1119
+ export interface TaskObservationBatch {
1120
+ schemaVersion: 1;
1121
+ taskId: string;
1122
+ cursor: string;
1123
+ reset: boolean;
1124
+ hasMore: boolean;
1125
+ snapshot: TaskObservationSnapshot;
1126
+ /**
1127
+ * @maxItems 100
1128
+ */
1129
+ events: TaskObservationEvent[];
1130
+ }
1131
+ /**
1132
+ * 任务列表中的受限展示字段;key 是稳定机器键,value 是 Host 裁剪后的展示文本。
1133
+ */
1134
+ export interface TaskListField {
1135
+ /**
1136
+ * 展示字段的稳定机器键,例如 machine 或 command。
1137
+ */
1138
+ key: string;
1139
+ /**
1140
+ * Host 完成授权与裁剪后的展示文本。
1141
+ */
1142
+ value: string;
1143
+ }
1144
+ /**
1145
+ * Host 已授权发现的任务摘要;taskId 是可继续传给 tasks.watch 的不透明引用。
1146
+ */
1147
+ export interface TaskListItem {
1148
+ /**
1149
+ * 可继续传给 tasks.watch 的 Host 不透明任务引用。
1150
+ */
1151
+ taskId: string;
1152
+ /**
1153
+ * 任务来源类型的稳定机器键。
1154
+ */
1155
+ kind: string;
1156
+ /**
1157
+ * 任务的安全展示名称。
1158
+ */
1159
+ name: string;
1160
+ status: TaskStatus;
1161
+ /**
1162
+ * 可选执行进度,取值范围为 0 到 1。
1163
+ */
1164
+ progress?: number;
1165
+ /**
1166
+ * Host 裁剪后的可选状态说明。
1167
+ */
1168
+ message?: string;
1169
+ /**
1170
+ * 任务摘要最后更新时间,使用 UTC ISO 8601 字符串。
1171
+ */
1172
+ updatedAt: string;
1173
+ /**
1174
+ * 任务面板可展示的受限附加字段。
1175
+ *
1176
+ * @maxItems 32
1177
+ */
1178
+ fields: TaskListField[];
1179
+ }
1180
+ /**
1181
+ * Host 已授权任务摘要的一页结果;nextCursor 缺失表示当前页已到末尾。
1182
+ */
1183
+ export interface TaskListPage {
1184
+ /**
1185
+ * 任务列表页结构版本,当前固定为 1。
1186
+ */
1187
+ schemaVersion: 1;
1188
+ /**
1189
+ * 当前页中 Host 已授权的任务摘要。
1190
+ *
1191
+ * @maxItems 100
1192
+ */
1193
+ tasks: TaskListItem[];
1194
+ /**
1195
+ * 下一页的不透明游标;缺失表示当前列表已到末尾。
1196
+ */
1197
+ nextCursor?: string;
1198
+ }
1199
+ /**
1200
+ * 受限 UI 状态读取结果。
1201
+ */
1202
+ export interface UiStateResult {
1203
+ found: boolean;
1204
+ value?: JsonValue;
1205
+ }
1206
+ /**
1207
+ * 受限 UI 状态写入结果。
1208
+ */
1209
+ export interface UiStateWriteResult {
1210
+ status: "saved";
1211
+ }
1212
+ /**
1213
+ * 读取用户资料的结果;含稳定 userId 与展示名。
1214
+ */
1215
+ export interface HostUserProfileReadOutput {
1216
+ userId: string;
1217
+ displayName: string;
1218
+ }
1219
+ /**
1220
+ * 读取用户邮箱的结果;email 为地址或 null。
1221
+ */
1222
+ export interface HostUserEmailReadOutput {
1223
+ email: (string | null);
1224
+ }