@coda-console/protocol 5.1.0 → 5.3.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,18 @@
2
2
 
3
3
  按 semver。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 5.3.0 — 2026-11-09
6
+
7
+ - `coda/session@1` 的媒体 part(`read` 的消息与 `post` 的输入)加 `type: "audio"`:一段语音消息(对方平台的「语音条」),不是任意音频文件;用 `name`、`size`、`mime`、`duration`、`service`、`path`,`width`、`height`、`thumb`、`preview` 不用。`path` 给的文件应是常见播放器能直接播放的格式(如 AAC/M4A、MP3、WAV),`mime` 写实际格式,原始编码不能直接播时由 Provider 转换;Provider 给语音消息写可读的 `text` 兜底(例如「[语音] 5″」)。`duration` 改为视频和语音用。
8
+ - `post` 输入里的媒体 part 加 `upload`:持有这条记录的机器上 Coda 上传的 ID(`POST /v1/uploads` 返回的,1 到 200 字符),与 `service`、`path`、`preview` 互斥;`read` 的消息里没有。调用方先把文件传到持有方再引用,持有方的 Coda 把上传交给 Provider 读取,Provider 不经网络取;本版本只要求 Provider 对 `audio` 支持。
9
+ - status 加可选的 `accepts`:`post` 除文字以外还收哪些媒体 part,形状是 `{ audio?: { maxDuration? } }`,本版本只有 `audio` 一个键,`maxDuration` 是语音最长秒数(大于 0);不写就是只收文字,客户端据此显示录音入口并到时自动停止。`post` 收到没声明的媒体 part 或超出限制时运行 `failed`,`code` 为 `unsupported`(Coda #2364)。
10
+
11
+ ## 5.2.0 — 2026-11-09
12
+
13
+ - 新核心协议 `coda/card@1`(复数名 `cards`,`CARD_PROTOCOL`,在 `CORE_PROTOCOLS` 里):会话向用户或上层 Agent 要的一个输入,由提出它的会话所在的后端持有,可按持有方自己的表读穿给出、不另存。spec 是 `{ kind, title, thread, location?, answers: "user"|"any", shown? }`,不带答案的 schema;status 是 `{ state: "pending"|"submitting"|"answered"|"expired"|"unknown", holder?, reason?, note?, toldAlong?, setAside? }`,`holder` 是字符串(`user` 或会话 ID),不是引用;没有操作。
14
+ - `coda/run@1` 加操作 `answer`(立即结果 `{ state? }`,`idempotent`):回答运行在等的卡片,输入 `{ card, answer, answeredBy?, attachments? }`,`card` 须等于 `status.awaiting`。答案里可能有密钥原文,调用双方都不按 `requestId` 保存这次调用,重复提交由持有者按卡片挡住。`answer` 和 `cancel` 一样按 `spec.record.kind` 交给运行的持有者;`status.awaiting` 指向 `coda/card@1`(Coda S2)。
15
+ - `coda/agent@1` 的说明补上:`spawn` 的 `parent` 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。
16
+
5
17
  ## 5.1.0 — 2026-11-09
6
18
 
7
19
  - `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)。
package/README.md CHANGED
@@ -4,7 +4,7 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
4
4
 
5
5
  - **插件清单的类型**(`schemas/plugin/`):插件目录 `package.json` 里 `contributes` 的每个键是一种类型,各有一份 JSON Schema(draft 2020-12,`$id` 为 `https://coda.pub/schemas/plugin/v2/<文件>`)。`plugin.json` 是整份清单,只列通用键(`configuration`、`extensionPoints`、`extensions`、`services`、`setup`、`environment`、`path`、`endpoints`、`views`、`protocols`、`protocolImplementations`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表或某个插件的扩展点声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;扩展点可以带自己的 schema(`extensionPoints.<名>.schema`,声明它的插件目录里的一个文件),写给它的东西合乎那份 schema 才对。
6
6
  - **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema。
7
- - **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议。调用是 `{ record, operation, input, requestId, parent, awaited }`,回答是 `{ result }` 或 `{ run }`;`coda/run@1`、`coda/executor@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1` 是五个核心协议。
7
+ - **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议。调用是 `{ record, operation, input, requestId, parent, awaited }`,回答是 `{ result }` 或 `{ run }`;`coda/run@1`、`coda/executor@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/card@1` 是六个核心协议。
8
8
  - **流程方言**(`workflow/`):项目和插件的流程(`.coda/workflows/*.bpmn`,BPMN 2.0)在 Coda 的命名空间 `https://coda.pub/schema/bpmn/1.0` 里能写什么。`moddle.json` 是 `coda:` 属性与元素(bpmn-moddle 的描述格式),`values.json` 是每个值能写什么(每个 `coda:` 类型的属性组成的对象的 JSON Schema,一个元素里同种 `coda:` 元素成组的 schema),`actions.json` 是 `coda:action` 的各个动作和它们接受的参数,`dialect.json` 是流程种类、Coda 自己发的事件、步骤失败的错误码、表达式能读的运行变量和运行的输入能是哪些类型。`workflow.mjs` 用它们读一份流程:方言里没有的、值不合 schema 的都拒绝,说法是「位置:schema 对那里的说明」。值的 schema 用清单的那几个关键字,另加三个:`x-feel`(是 FEEL:「=」开头是表达式,否则文字里的 `{{ … }}` 是,按这份流程里的名字读得通)、`x-duration`(ISO 8601 时长,不为负)、`x-number`(文字换算成数字是个有限的数)。`structure.json` 声明流程结构规则,`structure.mjs` 负责跨节点检查。
9
9
  - **Agent 接入扩展**(`schemas/agent/`、`agent.mjs`、`docs/agent-protocol.md`):Coda 怎样用 ACP 接 Agent,以及 Coda 加的扩展(会话指令、插话、`_coda/wait`、执行失败、工具调用的审核)。
10
10
 
@@ -42,7 +42,7 @@ pointProblem(panelsSchema, manifest.contributes.panels, 'contributes.panels', 'p
42
42
 
43
43
  ```js
44
44
  import {
45
- RUN_PROTOCOL, EXECUTOR_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CORE_PROTOCOLS,
45
+ RUN_PROTOCOL, EXECUTOR_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL, CORE_PROTOCOLS,
46
46
  definitionProblem, ownedProtocolsProblem, runStatusProblem,
47
47
  invocationRequestProblem, invocationResponseProblem,
48
48
  parseProtocolName, formatProtocolName, protocolShortName,
@@ -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`(`safe`)与 `draft`(`idempotent`)是立即结果,`post` 开运行;撤回、编辑、表情是用 `about` 指向旧消息的新消息。
130
+ - **`coda/session@1`**:插件提供的外部会话。spec 是标题、容器和可选的环境引用;status 是 `head` 游标、参与者与 `post` 收不收语音(`accepts`);操作 `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
@@ -6,7 +6,7 @@
6
6
 
7
7
  - 协议定义文档的 JSON Schema 与校验:`schemas/protocol/v1/definition.json`、`@coda-console/protocol/protocol`;
8
8
  - 统一调用信封:`schemas/protocol/v1/request.json`、`response.json`;
9
- - 五个核心协议:`coda/run@1`、`coda/executor@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`;
9
+ - 六个核心协议:`coda/run@1`、`coda/executor@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/card@1`;
10
10
  - 插件清单里的 `contributes.protocols` 与 `contributes.protocolImplementations`。
11
11
 
12
12
  `executor` 与 `execution` 两个旧对象协议和 `@coda-console/protocol/executor` 在 3.0.0 删除;`execution` 的输入并入 `coda/executor@1` 的 `execute` 操作,运行由 `coda/run@1` 表达。
@@ -217,7 +217,7 @@ status:
217
217
  | `state` | `working`、`input-required`、`completed`、`failed`、`canceled`;后三个是终态 |
218
218
  | `result` | 完成、失败或取消时的结果:`completed`/`failed` 必带;`canceled` 可带取消前说过的话和留下的东西;`working`/`input-required` 不带 |
219
219
  | `progress` | 进展说明,可选 |
220
- | `awaiting` | 等输入时那张卡片的引用;`input-required` 必填,其他状态不写 |
220
+ | `awaiting` | 等输入时那张卡片的引用,指向一条 `coda/card@1`;`input-required` 必填,其他状态不写 |
221
221
 
222
222
  `failed` 的 `result` 约定为 `{ code, message }`。`code: "unknown"` 表示结局不明(例如执行连接中断),调用方据此显示「结果未知」,不当作失败。
223
223
 
@@ -225,6 +225,10 @@ status:
225
225
 
226
226
  操作 `cancel` 的输入是空对象,立即返回空结果;是否真的停下看 status。
227
227
 
228
+ 操作 `answer` 回答运行在等的那张卡片,立即返回 `{ state? }`,运行接着怎样看 status。输入是 `{ card, answer, answeredBy?, attachments? }`:`card` 须等于 `status.awaiting`;`answer` 是对象,形状由卡片种类定;`answeredBy` 是代答的会话,用户答时不写;`attachments` 是随答案带的上传文件 ID(至多 20 个)。它标 `idempotent`:答案里可能有密钥原文,调用双方都不按 `requestId` 保存这次调用;重复提交由持有者按卡片挡住。
229
+
230
+ `cancel` 和 `answer` 都交给运行的持有者处理:被调用方按 `spec.record.kind` 找到持有这条运行的一方。
231
+
228
232
  ```json
229
233
  {
230
234
  "spec": {
@@ -267,7 +271,7 @@ status:
267
271
 
268
272
  `models[].efforts` 是 `[{ id, name?, shortName? }]`;`models[].options` 是 `{ id, name?, shortName?, type: "boolean"|"select", choices? }`,`select` 带 `choices`,`boolean` 不带。status 是空对象。
269
273
 
270
- 操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended` 说发起方是否无人值守。子会话为谁工作由调用信封的 `parent` 说,不写在输入里。
274
+ 操作 `spawn`(`run: true`):在这台机器上用这个 Agent 开一个子会话,返回运行引用。输入是 `{ projectId, threadId, title, text, settings?, checkout?, parentTitle, parentUnattended }`:子会话所在的项目与工作树(`checkout`)、Agent 的设置(`settings`,如模型与推理强度)、标题与第一条任务(`text`);`threadId` 是调用方给的子会话 ID,重试找到的是同一个;`parentTitle` 是发起方在这里显示的名字,`parentUnattended` 说发起方是否无人值守。子会话为谁工作由调用信封的 `parent` 说,不写在输入里;`parent` 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。
271
275
 
272
276
  ```json
273
277
  {
@@ -303,6 +307,19 @@ status:
303
307
  | `participants` | `[{ id, name, kind: "person"\|"agent"\|"bot", self? }]`;`self: true` 是这个 Provider 登录的账号,即 Coda 的 Bot |
304
308
  | `state` | 可选,`active` 或 `unreachable` |
305
309
  | `reason` | 可选,状态说明 |
310
+ | `accepts` | 可选,`post` 除文字以外还收哪些媒体 part,见下 |
311
+
312
+ `accepts` 是一个对象,键是媒体 part 的 `type`,值是这一类型的限制,没有限制就写 `{}`。本版本只有 `audio` 一个键,以后要收别的类型再加键:
313
+
314
+ | 键 | 值 |
315
+ | --- | --- |
316
+ | `audio` | `{ maxDuration? }`:收 `upload` 引用的语音;`maxDuration` 是一条语音最长多少秒,大于 0 |
317
+
318
+ 不写 `accepts` 就是只收文字。客户端据此决定显示不显示录音入口,录音时到 `maxDuration` 自动停止。放在 status 而不在 spec,是因为 Provider 的能力可能随状态变化,例如手机上的麦克风权限被收回。
319
+
320
+ ```json
321
+ {"participants": [], "accepts": {"audio": {"maxDuration": 60}}}
322
+ ```
306
323
 
307
324
  观察方 watch 这条记录,`head` 变了就用 `read` 读游标之后的消息。`read` 与 `draft` 是立即结果,`read` 是 `safe` 的,`draft` 是 `idempotent` 的;`post` 开运行:
308
325
 
@@ -315,6 +332,8 @@ status:
315
332
  - 发送者固定是 `self`;重发同一个 `requestId`,得到的是同一个运行,只发一次;
316
333
  - 运行 `completed` 时,`result` 是 `{ message: { id, cursor } }`,就是以后 `read` 会读到的那条消息;
317
334
  - 发送失败时运行为 `failed`,`result` 是 `{ code, message }`;不确定发没发出去时(例如输入到一半进程没了)`code` 为 `unknown`,调用方显示「结果未知」,不自动重发;
335
+ - 输入里有 `status.accepts` 没声明的媒体 part,或超出它声明的限制(比如语音长过 `maxDuration`)时,运行 `failed`,`code` 为 `unsupported`;
336
+ - 输入里的媒体 part 可以用 `upload` 引用记录持有方的上传,见下;
318
337
  - 取消沿用 `coda/run@1` 的 `cancel`:还没开始发的停下,得到 `canceled`;已经开始发的,Provider 可以不停,是否停下看 status;
319
338
  - 全文总在 `post` 的输入里;没有先写过草稿的 `post` 也照常发出去。
320
339
  - `draft`(`idempotent`):设定 `self` 在这个会话里还没发出去的文字,结果 `{}`。输入 `{ text, version, steps? }`:
@@ -335,22 +354,31 @@ status:
335
354
  `parts` 的每一项是下面之一:
336
355
 
337
356
  - `{ type: "text", text }`;
338
- - `{ type: "image"|"video"|"file", name, size?, mime?, width?, height?, duration?, thumb?, service?, path?, preview? }`:媒体,大文件只给引用,字段见下;
357
+ - `{ type: "image"|"video"|"file"|"audio", name, size?, mime?, width?, height?, duration?, thumb?, service?, path?, preview?, upload? }`:媒体,大文件只给引用,字段见下;
339
358
  - `{ type: "thinking"|"tool", text }`。
340
359
 
341
- 媒体 part 在 `read` 的消息和 `post` 的输入里是同一种形状,`type`、`name` 以外都可选:
360
+ 媒体 part 在 `read` 的消息和 `post` 的输入里是同一种形状,只有 `upload` 只在 `post` 的输入里有;`type`、`name` 以外都可选:
342
361
 
343
362
  | 字段 | 含义 |
344
363
  | --- | --- |
345
364
  | `name`、`size`、`mime` | 文件名、字节数、MIME 类型 |
346
365
  | `width`、`height` | 像素,整数,至少 1,已按拍摄方向转正;图片和视频用 |
347
- | `duration` | 时长,秒,不为负;视频用 |
366
+ | `duration` | 时长,秒,不为负;视频和语音用 |
348
367
  | `thumb` | 内嵌 JPEG 的 base64(不带 `data:` 前缀),至多 8192 个字符;视频用封面帧 |
349
368
  | `service` | provider 插件登记的本机流式服务 ID |
350
369
  | `path` | 原文件的服务内路径,1 到 2048 个字符 |
351
370
  | `preview` | 预览图的服务内路径,在同一个 `service` 里,1 到 2048 个字符 |
371
+ | `upload` | 只在 `post` 的输入里:持有这条记录的机器上 Coda 上传的 ID(那台机器 `POST /v1/uploads` 返回、`GET /v1/uploads/<id>` 能读回的),1 到 200 个字符 |
352
372
 
353
- 有 `path` 或 `preview` 就必须有 `service`。
373
+ 有 `path` 或 `preview` 就必须有 `service`。`upload` 与 `service`、`path`、`preview` 互斥:一个媒体 part 要么引用 Provider 自己的服务,要么引用持有方的上传。
374
+
375
+ `audio` 是一段语音消息,即对方平台的「语音条」,不是任意音频文件:
376
+
377
+ - 用 `name`、`size`、`mime`、`duration`、`service`、`path`(`post` 里也可以是 `upload`);`width`、`height`、`thumb`、`preview` 对它没有意义,不用;
378
+ - `path` 给出的文件应当是常见播放器能直接播放的格式(如 AAC/M4A、MP3、WAV),`mime` 写实际给出的格式;对方平台的原始编码不能直接播时,由 Provider 转换;
379
+ - 观察方看不懂 `audio` 时照常退回 `text`:Provider 给语音消息写一个可读的 `text` 兜底,例如「[语音] 5″」,具体写法由 Provider 定。
380
+
381
+ 发语音时,调用方先把录好的文件传到记录的持有方(`POST /v1/uploads`),再在 `post` 里用 `upload` 引用;持有方的 Coda 负责把上传交给 Provider 读取,Provider 不经网络取。本版本 `upload` 只要求 Provider 对 `audio` 支持,其他类型以后再说。
354
382
 
355
383
  一个媒体分三档,从小到大:
356
384
 
@@ -381,6 +409,12 @@ status:
381
409
  "thumb": "/9j/4AAQSkZJRgABAQ…", "service": "media", "path": "msg/m7/IMG_0412.jpg", "preview": "msg/m7/IMG_0412.preview.jpg"}
382
410
  ```
383
411
 
412
+ `post` 发一条语音:
413
+
414
+ ```json
415
+ {"text": "[语音] 5″", "parts": [{"type": "audio", "name": "voice.m4a", "mime": "audio/mp4", "duration": 5, "upload": "up_1"}]}
416
+ ```
417
+
384
418
  一条记录:
385
419
 
386
420
  ```json
@@ -429,6 +463,43 @@ status 是 `{ state: "available"|"unreachable", reason? }`。
429
463
  }
430
464
  ```
431
465
 
466
+ ## coda/card@1
467
+
468
+ 会话向用户或上层 Agent 要的一个输入。复数名是 `cards`。由提出它的会话所在的后端持有;持有方可以按自己的表读穿给出,不另存。运行等它时,`coda/run@1` 的 `status.awaiting` 指向这条记录,回答走那条运行的 `answer`。卡片自己没有操作。
469
+
470
+ spec:
471
+
472
+ | 字段 | 含义 |
473
+ | --- | --- |
474
+ | `kind` | 卡片种类,如 `permission`、`form`、`workflow_task` |
475
+ | `title` | 一行标题 |
476
+ | `thread` | 提出它的会话,持有方给的 ID |
477
+ | `location` | 提出它的会话在哪台机器,给人看;本机的不写 |
478
+ | `answers` | 谁能答:`user` 只有用户,`any` 上层 Agent 也能代答 |
479
+ | `shown` | 代答的 Agent 要看的内容,对象;`answers` 为 `user` 时不写 |
480
+
481
+ spec 不带答案的 schema:答案的形状由卡片种类定,持有者在 `answer` 里校验。
482
+
483
+ status:
484
+
485
+ | 字段 | 含义 |
486
+ | --- | --- |
487
+ | `state` | `pending`、`submitting`、`answered`、`expired`、`unknown` |
488
+ | `holder` | `pending` 时在谁手上:`user`,或持有它的会话 ID(持有方给的) |
489
+ | `reason` | 到这个持有者手上的原因 |
490
+ | `note` | 说明 |
491
+ | `toldAlong` | `true`:持有它的会话还没被告知,下一条输入时才告诉它 |
492
+ | `setAside` | `true`:用户把它搁置了,仍在等,不再要人处理 |
493
+
494
+ `holder` 是字符串,不是 `{ kind, id }` 引用:镜像发布时会改写 status 里的引用,而持有者可能是别台的会话,本机不一定认得它的持有方。
495
+
496
+ ```json
497
+ {
498
+ "spec": {"kind": "workflow_task", "title": "确认发布", "thread": "t1", "answers": "any", "shown": {"text": "要发布 5.2.0 吗?"}},
499
+ "status": {"state": "pending", "holder": "t1", "reason": "assigned", "toldAlong": true}
500
+ }
501
+ ```
502
+
432
503
  ## 版本
433
504
 
434
505
  - 协议名里的大版本是协议自己的版本,和 npm 包版本、插件清单的 v2 独立。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "5.1.0",
3
+ "version": "5.3.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/protocol.mjs CHANGED
@@ -15,8 +15,9 @@ export const EXECUTOR_PROTOCOL = read('executor.json');
15
15
  export const AGENT_PROTOCOL = read('agent.json');
16
16
  export const SESSION_PROTOCOL = read('session.json');
17
17
  export const ENVIRONMENT_PROTOCOL = read('environment.json');
18
+ export const CARD_PROTOCOL = read('card.json');
18
19
  export const CORE_PROTOCOLS = Object.freeze(Object.fromEntries(
19
- [RUN_PROTOCOL, EXECUTOR_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL].map(protocol => [protocol.name, protocol])));
20
+ [RUN_PROTOCOL, EXECUTOR_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL].map(protocol => [protocol.name, protocol])));
20
21
 
21
22
  const ajv = newAjv({ ownProperties: true, addUsedSchema: false, strict: false });
22
23
  const definitionCheck = ajv.compile(PROTOCOL_DEFINITION);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coda/agent@1",
3
3
  "title": "Agent",
4
- "description": "一台机器上装着的 Agent 程序及其模型与审批模式,照 Coda 的 Agent 资源 spec。记录的 provider 是写记录的一方(编排),提供 Agent 程序的插件写在 spec.plugin;spawn 在那台机器上用它开一个子会话。",
4
+ "description": "一台机器上装着的 Agent 程序及其模型与审批模式,照 Coda 的 Agent 资源 spec。记录的 provider 是写记录的一方(编排),提供 Agent 程序的插件写在 spec.plugin;spawn 在那台机器上用它开一个子会话;parent 不是会话、是登记过的调用方记录时,开的是顶层会话,不是子会话。",
5
5
  "plural": "agents",
6
6
  "spec": {
7
7
  "$schema": "https://json-schema.org/draft/2020-12/schema",
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "coda/card@1",
3
+ "title": "卡片",
4
+ "description": "会话向用户或上层 Agent 要的一个输入。由提出它的会话所在的后端持有;运行等它时,status.awaiting 指向这条记录,回答走那条运行的 answer。持有方可以按自己的表读穿给出,不另存。",
5
+ "plural": "cards",
6
+ "spec": {
7
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
8
+ "type": "object",
9
+ "properties": {
10
+ "kind": {"type": "string", "minLength": 1, "maxLength": 64, "description": "卡片种类,如 permission、form、workflow_task"},
11
+ "title": {"type": "string", "maxLength": 200, "description": "一行标题"},
12
+ "thread": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "提出它的会话,持有方给的 ID"},
13
+ "location": {"type": "string", "maxLength": 200, "description": "提出它的会话在哪台机器,给人看;本机的不写"},
14
+ "answers": {"enum": ["user", "any"], "description": "谁能答:只有用户,或者上层 Agent 也能代答"},
15
+ "shown": {"type": "object", "description": "代答的 Agent 要看的内容;answers 为 user 时不写"}
16
+ },
17
+ "required": ["kind", "title", "thread", "answers"],
18
+ "additionalProperties": false
19
+ },
20
+ "status": {
21
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
22
+ "type": "object",
23
+ "properties": {
24
+ "state": {"enum": ["pending", "submitting", "answered", "expired", "unknown"]},
25
+ "holder": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "pending 时在谁手上:user,或持有它的会话 ID(持有方给的);不用引用,镜像发布时不改写它"},
26
+ "reason": {"type": "string", "maxLength": 64, "description": "到这个持有者手上的原因"},
27
+ "note": {"type": "string", "maxLength": 2000},
28
+ "toldAlong": {"const": true, "description": "持有它的会话还没被告知,下一条输入时才告诉它"},
29
+ "setAside": {"const": true, "description": "用户把它搁置了:仍在等,不再要人处理"}
30
+ },
31
+ "required": ["state"],
32
+ "additionalProperties": false
33
+ },
34
+ "operations": {}
35
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coda/run@1",
3
3
  "title": "运行",
4
- "description": "被调用方为一次调用开出的运行记录,由被调用方持有和写入。调用方 watch 这条记录取结果;状态到 completed、failed、canceled 后不再改变。",
4
+ "description": "被调用方为一次调用开出的运行记录,由被调用方持有和写入。调用方 watch 这条记录取结果;状态到 completed、failed、canceled 后不再改变。等输入时 status.awaiting 指向一条 coda/card@1;answer 和 cancel 一样,按 spec.record.kind 交给运行的持有者。",
5
5
  "spec": {
6
6
  "$schema": "https://json-schema.org/draft/2020-12/schema",
7
7
  "type": "object",
@@ -70,6 +70,34 @@
70
70
  "description": "请求取消;立即回答空结果,实际是否停止看状态。",
71
71
  "input": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "maxProperties": 0, "additionalProperties": false},
72
72
  "result": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "maxProperties": 0, "additionalProperties": false}
73
+ },
74
+ "answer": {
75
+ "description": "回答运行在等的那张卡片(status.awaiting),交给运行的持有者处理;立即回答,运行接着怎样看 status。答案里可能有密钥原文,所以标 idempotent:调用双方都不按 requestId 保存这次调用,重复提交由持有者按卡片挡住。",
76
+ "idempotent": true,
77
+ "input": {
78
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
79
+ "type": "object",
80
+ "$defs": {
81
+ "reference": {
82
+ "type": "object",
83
+ "properties": {
84
+ "kind": {"type": "string", "minLength": 1, "maxLength": 128},
85
+ "id": {"type": "string", "minLength": 1, "maxLength": 2048}
86
+ },
87
+ "required": ["kind", "id"],
88
+ "additionalProperties": false
89
+ }
90
+ },
91
+ "properties": {
92
+ "card": {"$ref": "#/$defs/reference", "description": "须等于 status.awaiting"},
93
+ "answer": {"type": "object", "description": "回答卡片时提交的内容,形状由卡片种类定"},
94
+ "answeredBy": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "代答的会话;用户答时不写"},
95
+ "attachments": {"type": "array", "maxItems": 20, "items": {"type": "string", "minLength": 1, "maxLength": 100}, "description": "随答案带的上传文件 ID"}
96
+ },
97
+ "required": ["card", "answer"],
98
+ "additionalProperties": false
99
+ },
100
+ "result": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": {"state": {"type": "string"}}, "additionalProperties": false}
73
101
  }
74
102
  }
75
103
  }
@@ -51,7 +51,20 @@
51
51
  }
52
52
  },
53
53
  "state": {"enum": ["active", "unreachable"]},
54
- "reason": {"type": "string", "maxLength": 4096, "description": "状态说明,可选"}
54
+ "reason": {"type": "string", "maxLength": 4096, "description": "状态说明,可选"},
55
+ "accepts": {
56
+ "type": "object",
57
+ "description": "post 除文字以外还收哪些媒体 part,键是 part 的 type,值是这一类型的限制;不写就是只收文字。能力可能随状态变化,所以放在 status",
58
+ "properties": {
59
+ "audio": {
60
+ "type": "object",
61
+ "description": "收 upload 引用的语音",
62
+ "properties": {"maxDuration": {"type": "number", "exclusiveMinimum": 0, "description": "一条语音最长多少秒"}},
63
+ "additionalProperties": false
64
+ }
65
+ },
66
+ "additionalProperties": false
67
+ }
55
68
  },
56
69
  "required": ["participants"],
57
70
  "additionalProperties": false
@@ -87,13 +100,13 @@
87
100
  {
88
101
  "type": "object",
89
102
  "properties": {
90
- "type": {"enum": ["image", "video", "file"]},
103
+ "type": {"enum": ["image", "video", "file", "audio"]},
91
104
  "name": {"type": "string", "maxLength": 1024},
92
105
  "size": {"type": "integer", "minimum": 0},
93
106
  "mime": {"type": "string", "maxLength": 255},
94
107
  "width": {"type": "integer", "minimum": 1, "description": "像素宽,已按拍摄方向转正;图片和视频用"},
95
108
  "height": {"type": "integer", "minimum": 1, "description": "像素高,已按拍摄方向转正;图片和视频用"},
96
- "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频用"},
109
+ "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频和语音用"},
97
110
  "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀;自己生成时长边取 64 像素左右,已有的小缩略图在上限内可原样放;视频用封面帧"},
98
111
  "service": {"type": "string", "minLength": 1, "maxLength": 200, "description": "provider 插件登记的本机流式服务 ID"},
99
112
  "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "原文件的服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"},
@@ -149,7 +162,7 @@
149
162
  }
150
163
  },
151
164
  "post": {
152
- "description": "以 self 发一条消息,开运行;重发同一个 requestId 得到同一个运行,只发一次。completed 的 result 是 { message: { id, cursor } },即以后 read 读到的那条;failed 的 result 是 { code, message },不确定发没发出去时 code 为 unknown,调用方显示结果未知、不自动重发。还没开始发时取消得到 canceled,已开始的看 status。没先写草稿也照常发。",
165
+ "description": "以 self 发一条消息,开运行;重发同一个 requestId 得到同一个运行,只发一次。completed 的 result 是 { message: { id, cursor } },即以后 read 读到的那条;failed 的 result 是 { code, message },不确定发没发出去时 code 为 unknown,收到 status.accepts 没声明的媒体 part 或超出它的限制时 code 为 unsupported;不确定时调用方显示结果未知、不自动重发。还没开始发时取消得到 canceled,已开始的看 status。没先写草稿也照常发。",
153
166
  "input": {
154
167
  "$schema": "https://json-schema.org/draft/2020-12/schema",
155
168
  "type": "object",
@@ -166,20 +179,22 @@
166
179
  {
167
180
  "type": "object",
168
181
  "properties": {
169
- "type": {"enum": ["image", "video", "file"]},
182
+ "type": {"enum": ["image", "video", "file", "audio"]},
170
183
  "name": {"type": "string", "maxLength": 1024},
171
184
  "size": {"type": "integer", "minimum": 0},
172
185
  "mime": {"type": "string", "maxLength": 255},
173
186
  "width": {"type": "integer", "minimum": 1, "description": "像素宽,已按拍摄方向转正;图片和视频用"},
174
187
  "height": {"type": "integer", "minimum": 1, "description": "像素高,已按拍摄方向转正;图片和视频用"},
175
- "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频用"},
188
+ "duration": {"type": "number", "minimum": 0, "description": "时长,秒;视频和语音用"},
176
189
  "thumb": {"type": "string", "maxLength": 8192, "description": "内嵌 JPEG 的 base64,不带 data: 前缀;自己生成时长边取 64 像素左右,已有的小缩略图在上限内可原样放;视频用封面帧"},
177
190
  "service": {"type": "string", "minLength": 1, "maxLength": 200, "description": "provider 插件登记的本机流式服务 ID"},
178
191
  "path": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "原文件的服务内路径,原样接在 /v1/plugins/<provider 插件>/services/<service>/ 之后"},
179
- "preview": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "预览图在同一个 service 里的服务内路径:图片是长边一般不超过约 1280 像素的静图,视频是封面帧"}
192
+ "preview": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "预览图在同一个 service 里的服务内路径:图片是长边一般不超过约 1280 像素的静图,视频是封面帧"},
193
+ "upload": {"type": "string", "minLength": 1, "maxLength": 200, "description": "持有这条记录的机器上 Coda 上传的 ID(POST /v1/uploads 返回的);与 service、path、preview 互斥"}
180
194
  },
181
195
  "required": ["type", "name"],
182
196
  "dependentRequired": {"path": ["service"], "preview": ["service"]},
197
+ "dependentSchemas": {"upload": {"properties": {"service": false, "path": false, "preview": false}}},
183
198
  "additionalProperties": false
184
199
  },
185
200
  {