@clipbus/plugin-sdk 0.8.7 → 0.9.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 本文档属于 @clipbus/plugin-sdk 开发文档 · 返回[文档地图](./README.md) · capability 真相源见 [API.md](../API.md)
4
4
 
5
- 每个 handler 的 `input` 都遵守 **ItemContext envelope**:
5
+ Detector / attachment renderer 的 `input` 遵守 **ItemContext envelope**:
6
6
 
7
7
  ```ts
8
8
  interface ItemContext {
@@ -12,7 +12,18 @@ interface ItemContext {
12
12
  }
13
13
  ```
14
14
 
15
- 各 handler 在此之上附加专属字段,详见 [entry.md](./entry.md)。
15
+ Action 使用对应的稳定 envelope:
16
+
17
+ ```ts
18
+ interface ActionInput {
19
+ sourceItem: PluginClipboardItem;
20
+ content: PluginContentEnvelope;
21
+ attachments: PluginAttachmentRef[];
22
+ }
23
+ ```
24
+
25
+ 其中 `sourceItem` 始终是打开 Action Panel 时的原始 item 身份,
26
+ `content` 是当前级联值。各 handler 的专属字段见 [entry.md](./entry.md)。
16
27
 
17
28
  ## `PluginContentEnvelope`:三种 kind,字段平铺在顶层
18
29
 
@@ -68,7 +79,8 @@ interface PluginClipboardItem {
68
79
 
69
80
  ## 图片懒副本机制
70
81
 
71
- `input.content`(image 情形)只携带元信息,不带像素。当 detector / action 需要读字节时:
82
+ `input.content`(image 情形)只携带元信息,不带像素。Detector/renderer
83
+ 读取原始 item 图片:
72
84
 
73
85
  ```ts
74
86
  const { path } = await ctx.host.item.materializeImagePath();
@@ -77,6 +89,15 @@ const { path } = await ctx.host.item.materializeImagePath();
77
89
 
78
90
  同一 invocation 多次调用幂等返回同一路径。
79
91
 
92
+ Action 读取的是当前级联图片值,必须使用:
93
+
94
+ ```ts
95
+ const { path } = await ctx.host.action.materializeInputImagePath();
96
+ ```
97
+
98
+ 当前值可能由上一步从 text/path_reference 生成,因此不能根据
99
+ `sourceItem.type` 决定是否可读取。
100
+
80
101
  ## Attachment 按需读
81
102
 
82
103
  ```ts
@@ -89,7 +110,10 @@ if (payloadJson) {
89
110
  }
90
111
  ```
91
112
 
92
- `input.attachments` 给出当前 item 已有的附件引用列表(`{attachmentType, attachmentKey}`)。`readAttachment` 按需拉取真正内容,避免把所有附件塞进入参。
113
+ Detector / attachment renderer 的 `input.attachments` 给出当前 item 已有的附件引用列表(`{attachmentType, attachmentKey}`)。`readAttachment` 按需拉取真正内容,避免把所有附件塞进入参。
114
+
115
+ Action envelope 为保持协议形状稳定也包含 `attachments`,但 SDK 0.9.0
116
+ 宿主当前固定传入 `[]`;Action 不应依赖这里枚举原始 item 的附件。
93
117
 
94
118
  ## Action 返回图片
95
119
 
@@ -105,8 +129,9 @@ module.exports = definePlugin({
105
129
  actions: {
106
130
  'generate-image': {
107
131
  async runAutoAction(input, ctx) {
132
+ const { path: sourcePath } = await ctx.host.action.materializeInputImagePath();
108
133
  const { path } = await ctx.host.action.allocateImageTempPath({ formatHint: 'png' });
109
- await fs.writeFile(path, await generateImageBytes(input));
134
+ await fs.copyFile(sourcePath, path);
110
135
  return actionResult.image(path, { imageFormatHint: 'png' });
111
136
  },
112
137
  },
@@ -126,6 +151,8 @@ WebView 沙箱禁止 `file://`,且 SDK **从不**把真实文件路径暴露
126
151
  |---|---|---|---|---|
127
152
  | `clipbus.asset.currentItemImageUrl()` | UI | `{}` | `{ url?: string }` | 当前 item **自身**的图(item 非 image kind → `url` 缺失) |
128
153
  | `clipbus.asset.pathReferenceImageUrl({ index })` | UI | `{ index }` | `{ url?: string }` | 当前 item 第 `index` 个 `path_reference` 条目的图(越界 / 非图片文件 → `url` 缺失) |
154
+ | `clipbus.asset.currentActionInputImageUrl()` | UI/action | `{}` | `{ url?: string }` | 当前 Action image 值,与原始 item type 无关 |
155
+ | `clipbus.asset.currentActionInputPathReferenceImageUrl({ index })` | UI/action | `{ index }` | `{ url?: string }` | 当前 Action path_reference 中第 `index` 张图 |
129
156
  | `host.asset.registerImage({ path })` | runtime | `{ path }` | `{ url: string }` | 把 **Node 产出 / 已有**的本地图注册进当前 session,签发 URL |
130
157
 
131
158
  capability 完整签名见 [API.md](../API.md)。
@@ -183,4 +210,7 @@ imageUrl.value = url; // <img :src="imageUrl">
183
210
  ```
184
211
 
185
212
  > **token 生命周期:** URL 绑定当前 session owner,invocation / WebView 释放时一并失效,且跨 owner 隔离——不要持久化或跨会话复用。
186
- > **何时用哪个:** 显示「当前剪贴板项的图」用 `currentItemImageUrl`;显示「`path_reference` 里的某张图」用 `pathReferenceImageUrl`;显示「插件自己算出来 / 从别处读来的图」用 runtime `registerImage`。
213
+ > **何时用哪个:** renderer 显示原始 item 用 `currentItemImageUrl` /
214
+ > `pathReferenceImageUrl`;Draft Action 显示当前级联值用
215
+ > `currentActionInputImageUrl` / `currentActionInputPathReferenceImageUrl`;
216
+ > 插件自己算出的图用 runtime `registerImage`。
package/docs/manifest.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  | 字段 | 类型 | 必填 | 说明 |
12
12
  |---|---|---|---|
13
- | `schemaVersion` | `number` | 是 | 固定 `2` |
13
+ | `schemaVersion` | `number` | 是 | 固定 `3` |
14
14
  | `plugin` | `object` | 是 | 插件身份信息 |
15
15
  | `install` | `object` | 否 | 安装期 hook 配置 |
16
16
  | `runtime` | `object` | 是 | runtime 与 UI 根目录 |
@@ -25,7 +25,7 @@
25
25
 
26
26
  | 字段 | 类型 | 必填 | 说明 |
27
27
  |---|---|---|---|
28
- | `plugin.id` | `string` | 是 | 稳定命名空间,建议反向域名(`plugin.example.demo`) |
28
+ | `plugin.id` | `string` | 是 | 稳定命名空间,建议反向域名(`plugin.example.demo`);仅允许小写字母、数字与 `-` `.` `_`,不含 `..`、不以 `.` 开头,长度 ≤128 |
29
29
  | `plugin.title` | `string` | 是 | 显示名称 |
30
30
  | `plugin.version` | `string` | 是 | 版本号;宿主按字符串处理 |
31
31
 
@@ -98,7 +98,7 @@
98
98
  |---|---|---|---|
99
99
  | `id` | `string` | 是 | 局部 ID |
100
100
  | `title` | `string` | 是 | 显示名称 |
101
- | `supportedItemTypes` | `string[]` | 是 | `'text' \| 'image' \| 'path_reference'`;非空 |
101
+ | `supportedInputKinds` | `string[]` | 是 | `'text' \| 'image' \| 'path_reference'`;非空;按当前级联值过滤 |
102
102
  | `lifecycle` | `'auto-run' \| 'draft'` | 是 | action 生命周期 |
103
103
  | `keywords` | `string[]` | 否 | Action catalog 搜索关键词 |
104
104
  | `uiEntry` | `string` | 否 | `lifecycle: 'draft'` 时必填 |
@@ -109,7 +109,7 @@
109
109
 
110
110
  ```json
111
111
  {
112
- "schemaVersion": 2,
112
+ "schemaVersion": 3,
113
113
  "plugin": {
114
114
  "id": "plugin.example.sample",
115
115
  "title": "Sample Plugin",
@@ -141,7 +141,7 @@
141
141
  {
142
142
  "id": "sample-apply",
143
143
  "title": "Apply Sample",
144
- "supportedItemTypes": ["text"],
144
+ "supportedInputKinds": ["text"],
145
145
  "lifecycle": "draft",
146
146
  "keywords": ["sample", "apply"],
147
147
  "uiEntry": "actions/sample/index.html"
@@ -149,3 +149,11 @@
149
149
  ]
150
150
  }
151
151
  ```
152
+
153
+ ## 从 schema v2 升级
154
+
155
+ schema v3 是有意的 breaking change。将每个 Action 的
156
+ `supportedItemTypes` 改为 `supportedInputKinds`,并移除
157
+ `inputConstraints`、`possibleResultKinds`(若曾自行添加)。宿主不会把
158
+ v2 Action 适配为 v3;已安装或开发插件会显示“需要更新”,直到 manifest
159
+ 和构建产物通过 v3 校验。
@@ -23,7 +23,7 @@
23
23
  | `setAttachment` | `host.item.setAttachments` |
24
24
  | `setSearchExtension` | `host.item.setSearchExtension` |
25
25
 
26
- **不受门控:** `host.clipboard.*`、`host.navigation.*`、`host.settings.*`(只读)、`host.console.log`、`host.action.allocateImageTempPath`、`host.item.materializeImagePath`、`host.item.readAttachment`、所有 `clipbus.*` 中的 UI 专属 verb(`window.*`、`action.setButtons`、`action.complete`、`attachmentRenderer.setButtons` 等)。
26
+ **不受门控:** `host.clipboard.*`、`host.navigation.*`、`host.settings.*`(只读)、`host.console.log`、`host.action.allocateImageTempPath`、`host.action.materializeInputImagePath`、`host.action.allocateOutputFilePath`、`host.item.materializeImagePath`、`host.item.readAttachment`、所有 `clipbus.*` 中的 UI 专属 verb(`window.*`、`action.setButtons`、`action.complete`、`attachmentRenderer.setButtons` 等)。
27
27
 
28
28
  各 verb 的完整签名见 [API.md](../API.md)。
29
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipbus/plugin-sdk",
3
- "version": "0.8.7",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "description": "Typed SDK for authoring Clipbus plugins — runtime (Node.js) and UI (WebView) helpers generated from the Clipbus plugin wire contract.",
6
6
  "keywords": [