@dp-bohrium/widget-sdk 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  本文件只记录影响使用者的变更:运行时 API、事件订阅、Manifest 要求。
4
4
 
5
+ ## 0.4.1
6
+
7
+ ### 修复
8
+
9
+ **1. 解除已释放监听与资源的强引用**
10
+
11
+ - 手动释放 render、event 或第三方资源登记后,生命周期不再持续强引用原资源及其闭包;调用方继续持有释放句柄时,也不会因此保留已释放资源,避免长期运行的 Widget 反复切换监听器后累积内存。
12
+ - 重复登记和重复释放继续保持幂等,活动资源仍在 Widget 停用时清理;公开 API、回调与释放语义不变。
13
+
14
+ **2. 对齐 Panel 文件保存指南与授权边界**
15
+
16
+ - npm 包首页指向官方文档站,便于从包元数据发现教程与 API 参考。
17
+ - README 与 Agent 索引明确:file-preview 使用当前文件引用,获独立 `files.write` grant 的 Panel 使用 Host 签发的工作区文件引用;SDK 仍通过既有 `context.files.read/write` 接口传递字节,不新增文件操作。
18
+ - [文件能力指南](https://dev.dp.tech/bohrium-widget-sdk/guides/capabilities/files) 补充 Panel 编辑示例,覆盖同文件 render 保留草稿、Session 切换、保存快照与冲突/未知结果;缺少授权、完整内容或读取版本时保持只读。
19
+ - SDK 与 contracts 同步为 `0.4.1`,保持文件请求、回执与公开类型兼容。
20
+
5
21
  ## 0.4.0
6
22
 
7
23
  ### 新增
package/README.md CHANGED
@@ -236,8 +236,9 @@ if (result.ok) {
236
236
  ### 读取和保存当前文件
237
237
 
238
238
  作者 Manifest 申请 `"capabilities": { "files": { "read": true, "write": true } }`,Host 仍需独立
239
- 授权两个能力。`files.write` 对当前 `file-preview` 绑定的已有文件作整文件条件替换;引用来自
240
- `request.content.file`,不能传路径、URL、别的文件 id 或指定另存位置。Host 校验引用、作用域、
239
+ 授权两个能力。`files.write` 对 Host 签发引用指向的已有文件作整文件条件替换:在 `file-preview`
240
+ 中引用来自 `request.content.file`;在获得写 grant 的 Panel 中引用来自 `data.root` 或 `files.list`
241
+ 的结果。不能传路径、URL、自造的文件 id 或指定另存位置。Host 校验引用、作用域、
241
242
  写权限和实际字节预算,成功回执表示执行端已确认持久化。SDK 不负责 ASE、晶格或文件格式转换,
242
243
  插件应使用自己的序列化器生成最终字节。
243
244
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-8ppcE14g.js";
1
+ import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-RyAEhkyn.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) {
@@ -46,7 +46,8 @@ function compileWidgetPluginManifest(manifest, options = {}) {
46
46
  //#region src/lifetime.ts
47
47
  function createWidgetLifetime(onError) {
48
48
  const controller = new AbortController();
49
- const resources = /* @__PURE__ */ new Map();
49
+ const registrations = /* @__PURE__ */ new WeakMap();
50
+ const resources = /* @__PURE__ */ new Set();
50
51
  const pending = /* @__PURE__ */ new Set();
51
52
  let closePromise;
52
53
  function run(callback) {
@@ -60,15 +61,20 @@ function createWidgetLifetime(onError) {
60
61
  return task;
61
62
  }
62
63
  function add(resource) {
63
- const existing = resources.get(resource);
64
+ const existing = registrations.get(resource);
64
65
  if (existing) return existing;
66
+ let retained = resource;
65
67
  let disposed;
66
68
  const handle = { dispose() {
67
69
  if (disposed) return disposed;
68
- disposed = run(() => typeof resource === "function" ? resource() : resource.dispose());
70
+ const current = retained;
71
+ retained = void 0;
72
+ resources.delete(handle);
73
+ disposed = run(() => typeof current === "function" ? current() : current?.dispose());
69
74
  return disposed;
70
75
  } };
71
- resources.set(resource, handle);
76
+ registrations.set(resource, handle);
77
+ resources.add(handle);
72
78
  if (controller.signal.aborted) handle.dispose();
73
79
  return handle;
74
80
  }
@@ -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-8ppcE14g.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-RyAEhkyn.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.0";
5
+ const WIDGET_SDK_VERSION = "0.4.1";
6
6
  //#endregion
7
7
  //#region src/runtime/network.ts
8
8
  const failureReasons = /* @__PURE__ */ new Set([
package/llms.txt CHANGED
@@ -21,8 +21,9 @@
21
21
  - 先在 Manifest 声明 capability,再等待 Host grant。
22
22
  - 用 `WidgetError` 的 `code/phase/retryable/correlationId` 诊断启动、渲染和能力失败。
23
23
  - `ok=false` 的能力结果是可处理状态,不要直接重试或绕过 Host。
24
- - 当前文件读写使用 `context.files.read(input, options)` / `write(input, options)`;Manifest
25
- 分别申请 `files.read` / `files.write`,文件引用来自当前 file-preview。SDK 只传字节,不负责 ASE
24
+ - 文件读写使用 `context.files.read(input, options)` / `write(input, options)`;Manifest
25
+ 分别申请 `files.read` / `files.write`。file-preview 的引用来自当前文件;Panel 只有获得
26
+ `files.write` grant 时才能保存 `data.root` / `files.list` 取得的已有文件。SDK 只传字节,不负责 ASE
26
27
  或其他格式序列化。完整保存示例见 README「读取和保存当前文件」。
27
28
  - read 兼容仅含 content/encoding 的旧响应,可选 offset/bytesRead/nextOffset/eof/truncated/revision
28
29
  只验证已提供值并原样返回,不补造版本或游标。无 revision 仍可展示,但不能保存。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dp-bohrium/widget-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Bohrium Widget 开发者 SDK:在 Widget Bundle 内与 Host 建立 Bridge,并暴露生命周期与能力协议。",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  "runtime"
19
19
  ],
20
20
  "author": "Bohrium",
21
- "homepage": "https://www.npmjs.com/package/@dp-bohrium/widget-sdk",
21
+ "homepage": "https://dev.dp.tech/bohrium-widget-sdk/",
22
22
  "types": "./dist/index.d.ts",
23
23
  "exports": {
24
24
  ".": {
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@dp-bohrium/widget-contracts": "0.4.0"
51
+ "@dp-bohrium/widget-contracts": "0.4.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@biomejs/biome": "^2.2.0",