@coda-console/protocol 4.2.0 → 5.1.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  按 semver。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 5.1.0 — 2026-11-09
6
+
7
+ - `coda/session@1` 的媒体 part(`read` 的消息与 `post` 的输入)加可选的 `preview`:同一个 `service` 里预览图的服务内路径(1 到 2048 字符,须和 `service` 一起出现),图片是长边一般不超过约 1280 像素的静图,视频是封面帧。文档把媒体写成三档:内嵌的 `thumb`(只限至多 8192 字符,自己生成时长边取 64 像素左右,Provider 已有的小缩略图可原样放)、会话里画的 `preview`、打开时才取的原文件 `path`;取 `path` 回 404 而有 `preview` 时显示预览图并注明原图不在持有方,不当成文件已清理,`preview` 也取不到时退回 `thumb`,都没有时显示文件卡(Coda #2342)。
8
+
9
+ ## 5.0.0 — 2026-11-09
10
+
11
+ 不兼容变更:
12
+
13
+ - `coda/session@1` 的 `post` 从立即结果改为开运行(`run: true`),输入不变:发一条消息可能要十几秒到几十秒(排队、按真人节奏输入、发出后确认)。发送者固定是 `self`,重发同一个 `requestId` 得到同一个运行、只发一次;`completed` 的 `result` 是 `{ message: { id, cursor } }`,即以后 `read` 读到的那条;`failed` 的 `result` 是 `{ code, message }`,不确定发没发出去时 `code` 为 `unknown`,调用方显示「结果未知」、不自动重发;取消沿用 `coda/run@1`。协议名仍是 `coda/session@1`,不升大版本:目前还没有第三方实现 `post`。
14
+
15
+ 新增:
16
+
17
+ - 操作定义的 `idempotent: true`:可以改状态、但重发做的是同一件事的立即结果操作;调用双方和 `safe` 一样,都不按 `requestId` 留请求和回答。只能与 `result` 一起写,不能与 `run` 同时出现;`safe` 已含 `idempotent`,两者不同时写。
18
+ - `coda/session@1` 的操作 `draft`(`idempotent`):设定 `self` 还没发出去的草稿,结果 `{}`。输入 `{ text, version, steps? }`:`text` 是全文(空串为清空),`version` 是非负整数、比大小,Provider 丢掉不大于已见最大版本的,建议用毫秒时间;`steps` 是从上一版到这一版的中间状态 `{ text, delayMs }`,可照节奏回放,最后一步等于 `text`。用户发出时仍调 `post`,全文在 `post` 的输入里,没写过草稿的 `post` 也照常发。
19
+
5
20
  ## 4.2.0 — 2026-11-09
6
21
 
7
22
  - `coda/session@1` 的媒体 part(`read` 的消息与 `post` 的输入)加可选的 `width`、`height`(像素,已按拍摄方向转正)、`duration`(秒)、`thumb`(内嵌 JPEG 的 base64,长边不超过 64 像素,至多 8192 字符)与 `path`(服务内路径,须和 `service` 一起出现);文档写清原文件在记录持有方的 `/v1/plugins/<provider 插件>/services/<service>/<path>`,Range 与流中断沿用本机流式服务,以及缺尺寸、缩略图、`service` 时怎么显示(Coda #2342 第 1 步)。
package/README.md CHANGED
@@ -127,7 +127,7 @@ agentValueProblem('review.json', review, '工具的审核');
127
127
  - **`coda/run@1`**:被调用方自己的运行记录。spec 记录调用的记录、操作、输入、请求 ID、父引用和是否被等待;status 是 `working`、`input-required`、`completed`、`failed`、`canceled`,后三个是终态。`completed`/`failed` 必带 `result`,`failed` 的 `result` 约定为 `{ code, message }`(`code: "unknown"` 表示结局不明),`canceled` 可带取消前的话和留下的东西;另有可选的 `progress` 和等输入时的 `awaiting`。操作是 `cancel`。
128
128
  - **`coda/executor@1`**:执行器。操作 `execute` 接一份执行工作并返回运行引用,运行记录在执行器那边;没有 `target`、`executor` 或 `assignmentId` 绑定,也不回写调用方的记录。
129
129
  - **`coda/agent@1`**:Agent 资源,复数名 `agents`;spec 照 Coda 的 Agent 资源(`agent`、`title`、`plugin?`、`defaultModel`、`models`、`modes` 等),`plugin` 是提供 Agent 程序的插件、不是记录的 provider;status 为空对象;操作 `spawn`(`run: true`)开一个子会话。
130
- - **`coda/session@1`**:插件提供的外部会话。spec 是标题、容器和可选的环境引用;status 是 `head` 游标与参与者;操作 `read`、`post` 都是立即结果,撤回、编辑、表情是用 `about` 指向旧消息的新消息。
130
+ - **`coda/session@1`**:插件提供的外部会话。spec 是标题、容器和可选的环境引用;status 是 `head` 游标与参与者;操作 `read`(`safe`)与 `draft`(`idempotent`)是立即结果,`post` 开运行;撤回、编辑、表情是用 `about` 指向旧消息的新消息。
131
131
  - **`coda/environment@1`**:插件提供的只读外部环境。spec 带 `actions`;操作 `list` 列目录、`read` 读文件(一次至多 1 MiB)。
132
132
 
133
133
  统一调用是 `{ record: {kind,id}, operation, input, requestId, parent: {kind,id}, awaited }`,回答恰为 `{ result }` 或 `{ run: {kind,id} }` 之一。同一 `requestId` 重发只做一次;慢操作返回运行引用,调用方 watch 运行记录取结果,没有推送或回写。
package/docs/protocol.md CHANGED
@@ -73,7 +73,7 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
73
73
  | `plural` | 复数名(见「复数名」),可选;不写就是短名 |
74
74
  | `spec` | 记录的 spec 的 JSON Schema,必填 |
75
75
  | `status` | 记录的 status 的 JSON Schema,必填 |
76
- | `operations` | 操作名 → `{ description?, input, result, safe? }` 或 `{ description?, input, run: true }`,必填;不定义操作写 `{}` |
76
+ | `operations` | 操作名 → `{ description?, input, result, safe?, idempotent? }` 或 `{ description?, input, run: true }`,必填;不定义操作写 `{}` |
77
77
 
78
78
  `spec`、`status`、`input`、`result` 都是 JSON Schema draft 2020-12,只引用自己文档里的 `#/$defs/...`,不引用别的文件。`input` 必有。操作的输出二选一:
79
79
 
@@ -82,6 +82,8 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
82
82
 
83
83
  `safe: true` 只能和 `result` 一起写,不能和 `run` 一起写,表示只读、没有副作用、立即给结果的操作;调用方和被调用方都不按 `requestId` 留它的请求和回答(见「调用信封」)。
84
84
 
85
+ `idempotent: true` 也只能和 `result` 一起写,不能和 `run` 一起写,表示可以改状态、但重发做的是同一件事的立即结果操作,比如把草稿设成某一段:调用双方和 `safe` 一样,都不按 `requestId` 留请求和回答。两者是 HTTP 的 safe 与 idempotent 之分:`safe` 只读,`idempotent` 可以改状态。`safe` 已含 `idempotent`,两个不同时写。
86
+
85
87
  ```json
86
88
  {
87
89
  "name": "my-plugin/task@1",
@@ -158,7 +160,7 @@ definitionProblem(definition, { namespace: 'my-plugin' }); // 同时核对命名
158
160
  {"run": {"kind": "coda/run@1", "id": "run-1"}}
159
161
  ```
160
162
 
161
- `requestId` 由调用方给,重发同一个请求只做一次。`safe` 的操作例外:调用双方都不按 `requestId` 留请求和回答,重发就再读一次。读回来的是对方的数据,比如群消息、环境里的文件内容,留在调用双方的库里就成了镜像。立即结果用 `result`;慢的操作用 `run` 指向被调用方自己的 `coda/run@1` 记录,调用方 watch 这条记录取结果,被调用方不推送。取消也是一次调用(`coda/run@1` 的 `cancel` 操作),不是写别人的记录。
163
+ `requestId` 由调用方给,重发同一个请求只做一次。`safe` 与 `idempotent` 的操作例外:调用双方都不按 `requestId` 留请求和回答,重发就再做一次。`safe` 读回来的是对方的数据,比如群消息、环境里的文件内容,留在调用双方的库里就成了镜像;`idempotent` 重做一遍结果相同,留着也没用。立即结果用 `result`;慢的操作用 `run` 指向被调用方自己的 `coda/run@1` 记录,调用方 watch 这条记录取结果,被调用方不推送。取消也是一次调用(`coda/run@1` 的 `cancel` 操作),不是写别人的记录。
162
164
 
163
165
  ```js
164
166
  import { invocationRequestProblem, invocationResponseProblem } from '@coda-console/protocol/protocol';
@@ -283,7 +285,7 @@ status:
283
285
 
284
286
  ## coda/session@1
285
287
 
286
- 插件提供的外部会话,比如一个微信群:参与者、消息和发消息。
288
+ 插件提供的外部会话,比如一个微信群:参与者、消息、草稿和发消息。
287
289
 
288
290
  spec:
289
291
 
@@ -302,14 +304,24 @@ status:
302
304
  | `state` | 可选,`active` 或 `unreachable` |
303
305
  | `reason` | 可选,状态说明 |
304
306
 
305
- 观察方 watch 这条记录,`head` 变了就用 `read` 读游标之后的消息。两个操作都是立即结果,不开运行;`read` 是 `safe` 的:
307
+ 观察方 watch 这条记录,`head` 变了就用 `read` 读游标之后的消息。`read` 与 `draft` 是立即结果,`read` 是 `safe` 的,`draft` 是 `idempotent` 的;`post` 开运行:
306
308
 
307
309
  - `read`:输入 `{ after?, before?, limit? }`,`after`、`before` 是游标,`limit` 为 1 到 100;结果 `{ messages, cursor, more }`,没有消息时 `cursor` 为 `null`。`messages` 总按先后排,旧的在前:
308
310
  - 都不带游标:最新的 `limit` 条,`more` 表示更早还有没有;客户端打开会话时先读这一页;
309
311
  - 只带 `after`:这个游标之后的,`more` 表示之后还有没有;
310
312
  - 只带 `before`:这个游标之前最新的 `limit` 条,`more` 表示更早还有没有;往前翻页就拿这一页第一条的 `cursor` 作下一次的 `before`;
311
313
  - `after` 与 `before` 不能同时带。
312
- - `post`:输入 `{ text, parts?, replyTo?, mentions? }`;结果 `{ message: { id, cursor } }`。发送者固定是 `self`;Provider 按调用的 `requestId` 只发一次,发送失败就报错。
314
+ - `post`(`run: true`):输入 `{ text, parts?, replyTo?, mentions? }`,以 `self` 发一条消息。发一条可能要十几秒到几十秒(排队、按真人节奏输入、发出后确认),所以开运行:
315
+ - 发送者固定是 `self`;重发同一个 `requestId`,得到的是同一个运行,只发一次;
316
+ - 运行 `completed` 时,`result` 是 `{ message: { id, cursor } }`,就是以后 `read` 会读到的那条消息;
317
+ - 发送失败时运行为 `failed`,`result` 是 `{ code, message }`;不确定发没发出去时(例如输入到一半进程没了)`code` 为 `unknown`,调用方显示「结果未知」,不自动重发;
318
+ - 取消沿用 `coda/run@1` 的 `cancel`:还没开始发的停下,得到 `canceled`;已经开始发的,Provider 可以不停,是否停下看 status;
319
+ - 全文总在 `post` 的输入里;没有先写过草稿的 `post` 也照常发出去。
320
+ - `draft`(`idempotent`):设定 `self` 在这个会话里还没发出去的文字,结果 `{}`。输入 `{ text, version, steps? }`:
321
+ - `text` 是当前草稿的全文,至多 65536 个字符;空串表示清空或放弃;
322
+ - `version` 是调用方给的非负整数版本号,比大小:Provider 收到不大于已见最大版本的直接丢掉,多台设备都在写时后写的为准;建议用毫秒时间;
323
+ - `steps` 可选,至多 1000 项,是从上一版到这一版之间按先后排的中间状态 `{ text, delayMs }`:每一步的全文,以及距上一步的间隔(毫秒,0 到 600000);Provider 可以照这个节奏回放,最后一步等于 `text`;
324
+ - Provider 可以把草稿同步到对方平台的输入框,用户发出时那边基本已经打完;用不上草稿的 Provider 直接答 `{}`。
313
325
 
314
326
  消息是 `{ id, cursor, sender, senderName?, text, parts?, replyTo?, mentions?, about?, createdAt? }`:
315
327
 
@@ -323,7 +335,7 @@ status:
323
335
  `parts` 的每一项是下面之一:
324
336
 
325
337
  - `{ type: "text", text }`;
326
- - `{ type: "image"|"video"|"file", name, size?, mime?, width?, height?, duration?, thumb?, service?, path? }`:媒体,大文件只给引用,字段见下;
338
+ - `{ type: "image"|"video"|"file", name, size?, mime?, width?, height?, duration?, thumb?, service?, path?, preview? }`:媒体,大文件只给引用,字段见下;
327
339
  - `{ type: "thinking"|"tool", text }`。
328
340
 
329
341
  媒体 part 在 `read` 的消息和 `post` 的输入里是同一种形状,`type`、`name` 以外都可选:
@@ -333,25 +345,40 @@ status:
333
345
  | `name`、`size`、`mime` | 文件名、字节数、MIME 类型 |
334
346
  | `width`、`height` | 像素,整数,至少 1,已按拍摄方向转正;图片和视频用 |
335
347
  | `duration` | 时长,秒,不为负;视频用 |
336
- | `thumb` | 内嵌 JPEG 的 base64(不带 `data:` 前缀),长边不超过 64 像素,至多 8192 个字符;视频用封面帧 |
348
+ | `thumb` | 内嵌 JPEG 的 base64(不带 `data:` 前缀),至多 8192 个字符;视频用封面帧 |
337
349
  | `service` | provider 插件登记的本机流式服务 ID |
338
- | `path` | 服务内路径,1 到 2048 个字符;有 `path` 就必须有 `service` |
350
+ | `path` | 原文件的服务内路径,1 到 2048 个字符 |
351
+ | `preview` | 预览图的服务内路径,在同一个 `service` 里,1 到 2048 个字符 |
352
+
353
+ 有 `path` 或 `preview` 就必须有 `service`。
354
+
355
+ 一个媒体分三档,从小到大:
339
356
 
340
- 尺寸和缩略图让框在原图到达前就是最终大小:先显示放大、模糊的 `thumb`,原图到了在原地换上。
341
- 原文件:观察方读记录持有方的 `/v1/plugins/<provider 插件>/services/<service>/<path>`(别的机器经空间到达持有方);`path` 原样接在后面,Provider 写它时就按 URL 路径编码好,不以 `/` 开头。
357
+ - **`thumb`**:内嵌在消息里,框一出现就能画。约束只是至多 8192 个字符:自己生成时长边取 64 像素左右;Provider 手上已有的小缩略图,只要在上限以内,可以原样放进来。
358
+ - **`preview`**:持有方本地就有的较小版本。图片是一张静图,长边一般不超过约 1280 像素;视频是封面帧。观察方在会话里画它,原图只在打开时取。
359
+ - **`path`**:原文件。
360
+
361
+ 尺寸和 `thumb` 让框在图到达前就是最终大小:先显示放大、模糊的 `thumb`,`preview` 到了在原地换上;没有 `preview` 的,照旧换上原图。
362
+ 观察方读记录持有方的 `/v1/plugins/<provider 插件>/services/<service>/<preview 或 path>`(别的机器经空间到达持有方);路径原样接在后面,Provider 写它时就按 URL 路径编码好,不以 `/` 开头。
342
363
  字节、Range 和流中断语义沿用 Coda 的本机流式服务。
343
364
 
365
+ 取不到时这样降级:
366
+
367
+ - 取 `path` 回 404 而有 `preview`:显示预览图,并注明原图不在持有方(比如微信还没下载),不当成「文件已清理」;
368
+ - 没有 `preview` 或 `preview` 也取不到:退回 `thumb`;
369
+ - 三档都没有或都取不到:显示文件卡。
370
+
344
371
  缺字段时这样降级,旧消息不补算:
345
372
 
346
373
  - 缺 `width`、`height`:按默认比例占位;
347
- - 缺 `thumb`:空框;
348
- - 缺 `service`(或有 `service` 没有 `path`):只显示文件卡,不能打开原文件。
374
+ - 缺 `thumb`:图到之前是空框;
375
+ - 缺 `service`(或有 `service`,`path` 和 `preview` 都没有):只显示文件卡,不能打开原文件。
349
376
 
350
377
  一个图片 part:
351
378
 
352
379
  ```json
353
380
  {"type": "image", "name": "IMG_0412.jpg", "size": 2310144, "mime": "image/jpeg", "width": 3024, "height": 4032,
354
- "thumb": "/9j/4AAQSkZJRgABAQ…", "service": "media", "path": "msg/m7/IMG_0412.jpg"}
381
+ "thumb": "/9j/4AAQSkZJRgABAQ…", "service": "media", "path": "msg/m7/IMG_0412.jpg", "preview": "msg/m7/IMG_0412.preview.jpg"}
355
382
  ```
356
383
 
357
384
  一条记录:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "4.2.0",
3
+ "version": "5.1.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://coda.pub/schemas/protocol/v1/definition.json",
4
4
  "title": "协议定义",
5
- "description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true。",
5
+ "description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "name": {"$ref": "#/$defs/name"},
@@ -45,19 +45,21 @@
45
45
  "title": {"description": "给人看的名字", "type": "string", "maxLength": 100, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
46
46
  "description": {"description": "一句话说明", "type": "string", "maxLength": 1000, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
47
47
  "operation": {
48
- "description": "操作:input 必有;result 是立即结果的 schema,或写 run: true 表示返回运行引用。两者恰写一个。safe: true 只能与 result 一起写。",
48
+ "description": "操作:input 必有;result 是立即结果的 schema,或写 run: true 表示返回运行引用。两者恰写一个。safe: true、idempotent: true 只能与 result 一起写,两者不同时写(safe 已含 idempotent)。",
49
49
  "type": "object",
50
50
  "properties": {
51
51
  "description": {"$ref": "#/$defs/description"},
52
52
  "input": {"$ref": "#/$defs/schema"},
53
53
  "result": {"$ref": "#/$defs/schema"},
54
54
  "run": {"const": true, "description": "返回运行引用,而不是立即结果"},
55
- "safe": {"const": true, "description": "只读、没有副作用:调用双方都不按 requestId 留请求和回答,重发就再做一次"}
55
+ "safe": {"const": true, "description": "只读、没有副作用:调用双方都不按 requestId 留请求和回答,重发就再做一次"},
56
+ "idempotent": {"const": true, "description": "可改状态,但重发做的是同一件事:调用双方都不按 requestId 留请求和回答,重发就再做一次"}
56
57
  },
57
58
  "required": ["input"],
58
59
  "additionalProperties": false,
59
60
  "oneOf": [{"required": ["result"]}, {"required": ["run"]}],
60
- "dependentRequired": {"safe": ["result"]}
61
+ "dependentRequired": {"safe": ["result"], "idempotent": ["result"]},
62
+ "not": {"required": ["safe", "idempotent"]}
61
63
  }
62
64
  }
63
65
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coda/session@1",
3
3
  "title": "会话",
4
- "description": "插件提供的外部会话:参与者、消息与发消息。Provider 每追加一条消息就推进 status.head,观察方 watch 记录后用 read 读游标之后的消息;撤回、编辑、表情回应都是一条用 about 指向旧消息的新消息。",
4
+ "description": "插件提供的外部会话:参与者、消息、草稿与发消息。Provider 每追加一条消息就推进 status.head,观察方 watch 记录后用 read 读游标之后的消息;撤回、编辑、表情回应都是一条用 about 指向旧消息的新消息。",
5
5
  "spec": {
6
6
  "$schema": "https://json-schema.org/draft/2020-12/schema",
7
7
  "type": "object",
@@ -94,12 +94,13 @@
94
94
  "width": {"type": "integer", "minimum": 1, "description": "像素宽,已按拍摄方向转正;图片和视频用"},
95
95
  "height": {"type": "integer", "minimum": 1, "description": "像素高,已按拍摄方向转正;图片和视频用"},
96
96
  "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频用"},
97
- "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀,长边不超过 64 像素;视频用封面帧"},
97
+ "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀;自己生成时长边取 64 像素左右,已有的小缩略图在上限内可原样放;视频用封面帧"},
98
98
  "service": {"type": "string", "minLength": 1, "maxLength": 200, "description": "provider 插件登记的本机流式服务 ID"},
99
- "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"}
99
+ "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "原文件的服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"},
100
+ "preview": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "预览图在同一个 service 里的服务内路径:图片是长边一般不超过约 1280 像素的静图,视频是封面帧"}
100
101
  },
101
102
  "required": ["type", "name"],
102
- "dependentRequired": {"path": ["service"]},
103
+ "dependentRequired": {"path": ["service"], "preview": ["service"]},
103
104
  "additionalProperties": false
104
105
  },
105
106
  {
@@ -148,7 +149,7 @@
148
149
  }
149
150
  },
150
151
  "post": {
151
- "description": "以 self 发一条消息;Provider 按 requestId 只发一次,立即结果。",
152
+ "description": "以 self 发一条消息,开运行;重发同一个 requestId 得到同一个运行,只发一次。completed 的 result 是 { message: { id, cursor } },即以后 read 读到的那条;failed 的 result 是 { code, message },不确定发没发出去时 code 为 unknown,调用方显示结果未知、不自动重发。还没开始发时取消得到 canceled,已开始的看 status。没先写草稿也照常发。",
152
153
  "input": {
153
154
  "$schema": "https://json-schema.org/draft/2020-12/schema",
154
155
  "type": "object",
@@ -172,12 +173,13 @@
172
173
  "width": {"type": "integer", "minimum": 1, "description": "像素宽,已按拍摄方向转正;图片和视频用"},
173
174
  "height": {"type": "integer", "minimum": 1, "description": "像素高,已按拍摄方向转正;图片和视频用"},
174
175
  "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频用"},
175
- "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀,长边不超过 64 像素;视频用封面帧"},
176
+ "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀;自己生成时长边取 64 像素左右,已有的小缩略图在上限内可原样放;视频用封面帧"},
176
177
  "service": {"type": "string", "minLength": 1, "maxLength": 200, "description": "provider 插件登记的本机流式服务 ID"},
177
- "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"}
178
+ "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "原文件的服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"},
179
+ "preview": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "预览图在同一个 service 里的服务内路径:图片是长边一般不超过约 1280 像素的静图,视频是封面帧"}
178
180
  },
179
181
  "required": ["type", "name"],
180
- "dependentRequired": {"path": ["service"]},
182
+ "dependentRequired": {"path": ["service"], "preview": ["service"]},
181
183
  "additionalProperties": false
182
184
  },
183
185
  {
@@ -198,22 +200,39 @@
198
200
  "required": ["text"],
199
201
  "additionalProperties": false
200
202
  },
201
- "result": {
203
+ "run": true
204
+ },
205
+ "draft": {
206
+ "description": "设定 self 在这个会话里还没发出去的草稿,立即结果。text 是全文,空串为清空;version 只增,Provider 丢掉不大于已见最大版本的;steps 是从上一版到这一版的中间状态,可照 delayMs 回放,最后一步等于 text。用不上草稿的 Provider 直接答 {}。",
207
+ "idempotent": true,
208
+ "input": {
202
209
  "$schema": "https://json-schema.org/draft/2020-12/schema",
203
210
  "type": "object",
204
211
  "properties": {
205
- "message": {
206
- "type": "object",
207
- "properties": {
208
- "id": {"type": "string", "minLength": 1, "maxLength": 2048},
209
- "cursor": {"type": "string", "minLength": 1, "maxLength": 2048}
210
- },
211
- "required": ["id", "cursor"],
212
- "additionalProperties": false
212
+ "text": {"type": "string", "maxLength": 65536, "description": "草稿全文;空串表示清空或放弃"},
213
+ "version": {"type": "integer", "minimum": 0, "maximum": 9007199254740991, "description": "调用方给的版本号,比大小,后写的为准;建议用毫秒时间"},
214
+ "steps": {
215
+ "type": "array",
216
+ "maxItems": 1000,
217
+ "description": "从上一版到这一版的中间状态,按先后排;最后一步等于 text",
218
+ "items": {
219
+ "type": "object",
220
+ "properties": {
221
+ "text": {"type": "string", "maxLength": 65536, "description": "这一步的全文"},
222
+ "delayMs": {"type": "integer", "minimum": 0, "maximum": 600000, "description": "距上一步的间隔(毫秒)"}
223
+ },
224
+ "required": ["text", "delayMs"],
225
+ "additionalProperties": false
226
+ }
213
227
  }
214
228
  },
215
- "required": ["message"],
229
+ "required": ["text", "version"],
216
230
  "additionalProperties": false
231
+ },
232
+ "result": {
233
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
234
+ "type": "object",
235
+ "maxProperties": 0
217
236
  }
218
237
  }
219
238
  }