@coda-console/protocol 6.16.0 → 6.17.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 +4 -0
- package/README.md +2 -1
- package/docs/protocol.md +47 -2
- package/package.json +1 -1
- package/protocol.mjs +2 -1
- package/schemas/protocol/v1/resource.json +138 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.17.0 — 2026-11-20
|
|
6
|
+
|
|
7
|
+
- 这是在 6.16.0 之上的次版本。依据 README「版本」一节:核心协议是内部面,新增协议升次版本;`stable/` 不动。新增核心协议 `coda/resource@1`(`schemas/protocol/v1/resource.json`,导出 `RESOURCE_PROTOCOL`,加入 `CORE_PROTOCOLS`,复数名 `resource-types`),插件用命令写这种记录,见 Coda 文档「资源」。
|
|
8
|
+
|
|
5
9
|
## 6.16.0 — 2026-11-20
|
|
6
10
|
|
|
7
11
|
- 这是在 6.15.0 之上的次版本。依据 README「版本」一节:Agent 接入协议是内部面,新增 schema 与文档小节升次版本;`stable/` 不动,`stable-grows` 与 `test/stable.test.mjs` 不受影响(每轮 Token 用量采集,coda#1824)。
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ pointProblem(panelsSchema, manifest.contributes.panels, 'contributes.panels', 'p
|
|
|
50
50
|
|
|
51
51
|
```js
|
|
52
52
|
import {
|
|
53
|
-
RUN_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL, CORE_PROTOCOLS,
|
|
53
|
+
RUN_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL, RESOURCE_PROTOCOL, CORE_PROTOCOLS,
|
|
54
54
|
definitionProblem, ownedProtocolsProblem, runStatusProblem,
|
|
55
55
|
invocationRequestProblem, invocationResponseProblem,
|
|
56
56
|
parseProtocolName, formatProtocolName, protocolShortName,
|
|
@@ -136,6 +136,7 @@ agentValueProblem('review.json', review, '工具的审核');
|
|
|
136
136
|
- **`coda/agent@1`**:Agent 资源,复数名 `agents`;spec 照 Coda 的 Agent 资源(`agent`、`title`、`plugin?`、`defaultModel`、`models`、`modes` 等),`plugin` 是提供 Agent 程序的插件、不是记录的 provider;status 为空对象;操作 `spawn`(`run: true`)开一个子会话。
|
|
137
137
|
- **`coda/session@1`**:插件提供的外部会话。spec 是标题、容器和可选的环境引用;status 是 `head` 游标、参与者(可带头像 `avatar`)与 `post` 收不收语音(`accepts`);操作 `read`(`safe`)与 `draft`(`idempotent`)是立即结果,`post` 开运行;撤回、编辑、表情是用 `about` 指向旧消息的新消息。
|
|
138
138
|
- **`coda/environment@1`**:插件提供的只读外部环境。spec 带 `actions`;操作 `list` 列目录、`read` 读文件(一次至多 1 MiB)。
|
|
139
|
+
- **`coda/resource@1`**:插件持有的一种资源类型在一台机器上的现状,复数名 `resource-types`;一条记录是一台机器上一个插件的一个资源类型,`key` 是类型 ID。spec 是 `{ type, title, resources, signIn? }`;status 是 `{}`;操作 `act`、`sign-in`、`install`。
|
|
139
140
|
|
|
140
141
|
统一调用是 `{ record: {kind,id}, operation, input, requestId, parent: {kind,id}, awaited }`,回答恰为 `{ result }` 或 `{ run: {kind,id} }` 之一。同一 `requestId` 重发只做一次;慢操作返回运行引用,调用方 watch 运行记录取结果,没有推送或回写。
|
|
141
142
|
|
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
|
-
-
|
|
9
|
+
- 六个核心协议:`coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/card@1`、`coda/resource@1`;
|
|
10
10
|
- 插件清单里的 `contributes.protocols`、`contributes.protocolImplementations`、`contributes.records` 与 `contributes.self`。
|
|
11
11
|
|
|
12
12
|
`executor` 与 `execution` 两个旧对象协议和 `@coda-console/protocol/executor` 在 3.0.0 删除。
|
|
@@ -251,7 +251,7 @@ invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
|
251
251
|
}
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
-
`coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1` 的分组如下,都标 `trial`(还不在稳定面里)。`coda/session@1` 的 `draft` 是客户端输入框的击键流,不分组,不对插件开放:
|
|
254
|
+
`coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1`、`coda/resource@1` 的分组如下,都标 `trial`(还不在稳定面里)。`coda/session@1` 的 `draft` 是客户端输入框的击键流,不分组,不对插件开放:
|
|
255
255
|
|
|
256
256
|
| 协议 | 组 | 说明 | 管什么 |
|
|
257
257
|
| --- | --- | --- | --- |
|
|
@@ -262,6 +262,8 @@ invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
|
262
262
|
| `coda/session@1` | `read` | 读取外部会话的标题、参与者与消息 | 读记录、`read` |
|
|
263
263
|
| | `post` | 以你的身份往外部会话里发消息 | `post` |
|
|
264
264
|
| `coda/environment@1` | `read` | 浏览并读取外部环境里的目录与文件 | 读记录、`list`、`read` |
|
|
265
|
+
| `coda/resource@1` | `read` | 查看资源类型与它们的读数 | 读记录 |
|
|
266
|
+
| | `act` | 做资源上的动作、登录和安装 | `act`、`sign-in`、`install` |
|
|
265
267
|
|
|
266
268
|
插件申请权限写在清单根的 `uses`(见「插件清单」)。
|
|
267
269
|
|
|
@@ -606,6 +608,49 @@ status 是 `{ state: "available"|"unreachable", reason? }`。
|
|
|
606
608
|
}
|
|
607
609
|
```
|
|
608
610
|
|
|
611
|
+
## coda/resource@1
|
|
612
|
+
|
|
613
|
+
插件持有的一种资源类型在一台机器上的现状,复数名是 `resource-types`。一条记录是一台机器上一个插件的一个资源类型,`key` 是类型 ID;记录由插件的记录命令写,资源页只读记录、调操作。整条记录编码后不超过 64 KiB,schema 不另设字节上限,由 Coda 在写入时查。`status` 是 `{}`,不用。
|
|
614
|
+
|
|
615
|
+
spec:
|
|
616
|
+
|
|
617
|
+
| 字段 | 含义 |
|
|
618
|
+
| --- | --- |
|
|
619
|
+
| `type` | 必填,类型 ID,和 `key` 相同(读别家记录的页面拿不到 `key`);schema 比不了两者,由 Coda 查 |
|
|
620
|
+
| `title` | 必填,类型名,一行,至多 40 字 |
|
|
621
|
+
| `resources` | 必填,至多 50 项;没登录的类型写空数组 |
|
|
622
|
+
| `signIn` | 可选,`{ installed, installable, input?, note? }`:没写就是不能从 Coda 登录;`installed` 是登录用的程序装好了没有,`installable` 是有没有 `install` 命令,`input` 只认 `authorizationCode`(登录页给出授权码要贴回来),`note` 是登录前的一句话,至多 200 字 |
|
|
623
|
+
|
|
624
|
+
`resources` 每项 `{ name?, identity?, values, error?, buttons }`:`name`(至多 80 字)与非空 `values` 至少有一样;`identity` 至多 200 字,只用来比较;`error` 一行,至多 80 字。
|
|
625
|
+
|
|
626
|
+
- `values` 至多 8 项,每项 `{ label?, value?, fraction?, time? }`:`value`(至多 80 字)与数值 `fraction`(0–1)至少有一样;`time` 是 ISO 8601 时间。
|
|
627
|
+
- `buttons` 至多 8 项,每项 `{ label, action | view | url, args?, confirm?, disabled? }`,`action`、`view`、`url` 三选一:`action` 调 `act` 操作,`view` 打开本插件的视图,`url` 只认 https(至多 2000 字),不带 `args` 与 `confirm`。`args` 是 JSON 对象,序列化后至多 4096 字节;JSON Schema 说不了字节数,schema 不查,由宿主在写记录和收 `act` 调用时检查。`action`、`view` 有没有对应的动作与视图 schema 查不了:不认识的动作由 `act` 失败,不认识的视图由页面打开时失败。
|
|
628
|
+
|
|
629
|
+
三个操作都是立即结果 `{}`,不分 `safe`:
|
|
630
|
+
|
|
631
|
+
| 操作 | 输入 | 期限 | 说明 |
|
|
632
|
+
| --- | --- | --- | --- |
|
|
633
|
+
| `act` | `{ action, args }` | 10 分钟 | 做按钮上的动作,由插件的命令按 `action` 分派;`args` 必填,没有参数的按钮传 `{}` |
|
|
634
|
+
| `sign-in` | `{}` | 15 分钟 | 进度 `{ url, code? }` 报登录链接(和设备码);`signIn.input` 为 `authorizationCode` 时提问 `{ input: "authorizationCode" }`,回答 `{ code }` |
|
|
635
|
+
| `install` | `{}` | 10 分钟 | 装上登录要用的程序 |
|
|
636
|
+
|
|
637
|
+
```json
|
|
638
|
+
{
|
|
639
|
+
"key": "claude",
|
|
640
|
+
"spec": {
|
|
641
|
+
"type": "claude",
|
|
642
|
+
"title": "Claude",
|
|
643
|
+
"resources": [{
|
|
644
|
+
"name": "leavan",
|
|
645
|
+
"values": [{"label": "5 小时", "value": "80%", "fraction": 0.8, "time": "2026-11-20T08:00:00.000Z"}],
|
|
646
|
+
"buttons": [{"label": "移除", "action": "remove", "args": {"id": "a1"}, "confirm": "确定移除?"}]
|
|
647
|
+
}],
|
|
648
|
+
"signIn": {"installed": true, "installable": false, "input": "authorizationCode"}
|
|
649
|
+
},
|
|
650
|
+
"status": {}
|
|
651
|
+
}
|
|
652
|
+
```
|
|
653
|
+
|
|
609
654
|
## coda/card@1
|
|
610
655
|
|
|
611
656
|
会话向用户或上层 Agent 要的一个输入。复数名是 `cards`。由提出它的会话所在的后端持有;持有方可以按自己的表读穿给出,不另存。运行等它时,`coda/run@1` 的 `status.awaiting` 指向这条记录。卡片自己没有操作。
|
package/package.json
CHANGED
package/protocol.mjs
CHANGED
|
@@ -15,8 +15,9 @@ export const AGENT_PROTOCOL = read('agent.json');
|
|
|
15
15
|
export const SESSION_PROTOCOL = read('session.json');
|
|
16
16
|
export const ENVIRONMENT_PROTOCOL = read('environment.json');
|
|
17
17
|
export const CARD_PROTOCOL = read('card.json');
|
|
18
|
+
export const RESOURCE_PROTOCOL = read('resource.json');
|
|
18
19
|
export const CORE_PROTOCOLS = Object.freeze(Object.fromEntries(
|
|
19
|
-
[RUN_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL].map(protocol => [protocol.name, protocol])));
|
|
20
|
+
[RUN_PROTOCOL, AGENT_PROTOCOL, SESSION_PROTOCOL, ENVIRONMENT_PROTOCOL, CARD_PROTOCOL, RESOURCE_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);
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "coda/resource@1",
|
|
3
|
+
"title": "资源",
|
|
4
|
+
"description": "插件持有的一种资源类型在一台机器上的现状:一条记录是一台机器上一个插件的一个资源类型,key 是类型 ID。记录由插件的记录命令写,资源页只读记录、调操作;资源上的动作、登录、安装是这条记录上的操作,由插件的命令实现。整条记录(编码后)不超过 64 KiB,由 Coda 在写入时查。",
|
|
5
|
+
"plural": "resource-types",
|
|
6
|
+
"spec": {
|
|
7
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"type": {"$ref": "#/$defs/name", "description": "类型 ID,必须和记录的 key 相同(读别家记录的页面拿不到 key,靠它认类型);schema 比不了两者,由 Coda 在写入时查"},
|
|
11
|
+
"title": {"type": "string", "$ref": "#/$defs/line", "maxLength": 40, "description": "类型名,如 Claude、GitHub:资源页上只写它,一行,不超过 40 字"},
|
|
12
|
+
"resources": {
|
|
13
|
+
"type": "array",
|
|
14
|
+
"maxItems": 50,
|
|
15
|
+
"items": {"$ref": "#/$defs/resource"},
|
|
16
|
+
"description": "这个类型下的资源,如账号;没登录的类型写空数组"
|
|
17
|
+
},
|
|
18
|
+
"signIn": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"description": "能从 Coda 登录:没写就是不能。登录是操作 sign-in,装上是操作 install",
|
|
21
|
+
"properties": {
|
|
22
|
+
"installed": {"type": "boolean", "description": "要登录的程序装好了没有"},
|
|
23
|
+
"installable": {"type": "boolean", "description": "Coda 能不能替它装上,即插件有没有 install 命令"},
|
|
24
|
+
"input": {"const": "authorizationCode", "description": "登录页给出授权码要贴回来时写 authorizationCode:登录命令会提问 { input: \"authorizationCode\" }"},
|
|
25
|
+
"note": {"$ref": "#/$defs/question", "description": "登录前给人看的一句话,不超过 200 字,可以分行"}
|
|
26
|
+
},
|
|
27
|
+
"required": ["installed", "installable"],
|
|
28
|
+
"additionalProperties": false
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"required": ["type", "title", "resources"],
|
|
32
|
+
"additionalProperties": false,
|
|
33
|
+
"$defs": {
|
|
34
|
+
"name": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$", "description": "小写字母、数字和「-」,以字母开头,至多 64 个字符"},
|
|
35
|
+
"line": {"type": "string", "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$", "description": "一行,不能只有空白"},
|
|
36
|
+
"question": {"type": "string", "maxLength": 200, "pattern": "^(?=[\\s\\S]*\\S)[^\\u0000]*$", "description": "不超过 200 字,可以分行"},
|
|
37
|
+
"resource": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"description": "一个资源,如一个账号:name 与非空 values 至少有一样",
|
|
40
|
+
"properties": {
|
|
41
|
+
"name": {"type": "string", "$ref": "#/$defs/line", "maxLength": 80, "description": "资源的名字,如账号名"},
|
|
42
|
+
"identity": {"type": "string", "$ref": "#/$defs/line", "maxLength": 200, "description": "它在外面是谁,如账号的 ID:只用来比较,同一台上相同的合成一行"},
|
|
43
|
+
"values": {"type": "array", "maxItems": 8, "items": {"$ref": "#/$defs/value"}, "description": "读数,至多 8 个"},
|
|
44
|
+
"error": {"type": "string", "$ref": "#/$defs/line", "maxLength": 80, "description": "这个资源哪里不对,一行"},
|
|
45
|
+
"buttons": {"type": "array", "maxItems": 8, "items": {"$ref": "#/$defs/button"}, "description": "按钮,至多 8 个"}
|
|
46
|
+
},
|
|
47
|
+
"required": ["values", "buttons"],
|
|
48
|
+
"anyOf": [
|
|
49
|
+
{"required": ["name"]},
|
|
50
|
+
{"properties": {"values": {"type": "array", "minItems": 1}}}
|
|
51
|
+
],
|
|
52
|
+
"additionalProperties": false
|
|
53
|
+
},
|
|
54
|
+
"value": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"description": "一个读数:叫什么、读出什么、还剩多少(0–1,不知道就不写,不画成空)、随读数来的时刻(如额度什么时候恢复);value 与 fraction 至少有一样",
|
|
57
|
+
"properties": {
|
|
58
|
+
"label": {"type": "string", "$ref": "#/$defs/line", "maxLength": 80},
|
|
59
|
+
"value": {"type": "string", "$ref": "#/$defs/line", "maxLength": 80},
|
|
60
|
+
"fraction": {"type": "number", "minimum": 0, "maximum": 1},
|
|
61
|
+
"time": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])(T([01]\\d|2[0-3]):[0-5]\\d(:[0-5]\\d(\\.\\d+)?)?(Z|[+-]([01]\\d|2[0-3]):[0-5]\\d)?)?$",
|
|
64
|
+
"description": "ISO 8601 时间"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"anyOf": [{"required": ["value"]}, {"required": ["fraction"]}],
|
|
68
|
+
"additionalProperties": false
|
|
69
|
+
},
|
|
70
|
+
"button": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"description": "一个按钮,action、view、url 三选一:action 是调 act 操作做这个动作;view 是打开本插件的一个视图;url 是在设备上打开一个网页,只认 https,不带 args 与 confirm。action 与 view 有没有对应的动作和视图,schema 查不了:不认识的 action 由 act 失败,不认识的 view 由页面打开时失败",
|
|
73
|
+
"properties": {
|
|
74
|
+
"label": {"type": "string", "$ref": "#/$defs/line", "maxLength": 80},
|
|
75
|
+
"action": {"$ref": "#/$defs/name"},
|
|
76
|
+
"view": {"$ref": "#/$defs/name"},
|
|
77
|
+
"url": {"type": "string", "maxLength": 2000, "pattern": "^https://\\S+$"},
|
|
78
|
+
"args": {"$ref": "#/$defs/args"},
|
|
79
|
+
"confirm": {"$ref": "#/$defs/question", "description": "执行前问的话"},
|
|
80
|
+
"disabled": {"type": "boolean"}
|
|
81
|
+
},
|
|
82
|
+
"required": ["label"],
|
|
83
|
+
"oneOf": [
|
|
84
|
+
{"required": ["action"], "not": {"anyOf": [{"required": ["view"]}, {"required": ["url"]}]}},
|
|
85
|
+
{"required": ["view"], "not": {"anyOf": [{"required": ["action"]}, {"required": ["url"]}]}},
|
|
86
|
+
{"required": ["url"], "not": {"anyOf": [{"required": ["action"]}, {"required": ["view"]}, {"required": ["args"]}, {"required": ["confirm"]}]}}
|
|
87
|
+
],
|
|
88
|
+
"additionalProperties": false
|
|
89
|
+
},
|
|
90
|
+
"args": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"description": "按钮带给动作或视图的参数:JSON 对象,序列化后不超过 4096 字节。JSON Schema 说不了字节数,由宿主在写记录时检查"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"status": {
|
|
97
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
98
|
+
"type": "object",
|
|
99
|
+
"additionalProperties": false,
|
|
100
|
+
"description": "不用,写空对象"
|
|
101
|
+
},
|
|
102
|
+
"operations": {
|
|
103
|
+
"act": {
|
|
104
|
+
"description": "做按钮上的一个动作:action 是动作名,args 是按钮带的参数(没有就传 {}),由插件的命令分派;不认识的动作让调用失败。期限 10 分钟。",
|
|
105
|
+
"input": {
|
|
106
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
107
|
+
"type": "object",
|
|
108
|
+
"properties": {
|
|
109
|
+
"action": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$"},
|
|
110
|
+
"args": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"description": "按钮带的参数,没有就传 {}:JSON 对象,序列化后不超过 4096 字节。JSON Schema 说不了字节数,由宿主在收调用时检查"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"required": ["action", "args"],
|
|
116
|
+
"additionalProperties": false
|
|
117
|
+
},
|
|
118
|
+
"result": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "additionalProperties": false},
|
|
119
|
+
"timeout": 600000
|
|
120
|
+
},
|
|
121
|
+
"sign-in": {
|
|
122
|
+
"description": "从 Coda 登录:命令起程序,用进度 { url, code? } 报登录链接(和设备码,有就带)。记录的 signIn.input 为 authorizationCode 时,用户在登录页拿到授权码要贴回来:命令提问 { input: \"authorizationCode\" },回答是 { code }。期限 15 分钟。",
|
|
123
|
+
"input": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "additionalProperties": false},
|
|
124
|
+
"result": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "additionalProperties": false},
|
|
125
|
+
"timeout": 900000
|
|
126
|
+
},
|
|
127
|
+
"install": {
|
|
128
|
+
"description": "装上登录要用的程序;记录的 signIn.installable 为 true 才有。期限 10 分钟。",
|
|
129
|
+
"input": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "additionalProperties": false},
|
|
130
|
+
"result": {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "additionalProperties": false},
|
|
131
|
+
"timeout": 600000
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"permissions": {
|
|
135
|
+
"read": {"title": "查看资源类型与它们的读数", "trial": true, "read": true},
|
|
136
|
+
"act": {"title": "做资源上的动作、登录和安装", "trial": true, "operations": ["act", "sign-in", "install"]}
|
|
137
|
+
}
|
|
138
|
+
}
|