@coda-console/protocol 6.15.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 +11 -0
- package/README.md +2 -1
- package/agent.mjs +21 -0
- package/docs/agent-protocol.md +21 -2
- package/docs/protocol.md +47 -2
- package/package.json +1 -1
- package/protocol.mjs +2 -1
- package/schemas/agent/prompt-usage.json +183 -0
- package/schemas/protocol/v1/resource.json +138 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
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
|
+
|
|
9
|
+
## 6.16.0 — 2026-11-20
|
|
10
|
+
|
|
11
|
+
- 这是在 6.15.0 之上的次版本。依据 README「版本」一节:Agent 接入协议是内部面,新增 schema 与文档小节升次版本;`stable/` 不动,`stable-grows` 与 `test/stable.test.mjs` 不受影响(每轮 Token 用量采集,coda#1824)。
|
|
12
|
+
- 新增 `schemas/agent/prompt-usage.json`:`session/prompt` 成功答复顶层 `result.usage` 的形状。`inputTokens`(未缓存输入)、`outputTokens`、`cachedReadTokens`、`cachedWriteTokens`、`totalTokens`、`thoughtTokens` 都是 0 到 9007199254740991 的整数,缺失或 `null` 即未报告;顶层须至少有一个非 `null` 的前四项计数,或带 `breakdown`;只有 `totalTokens`、`thoughtTokens` 不算。可选 `breakdown` 非空,每项须有 `model`(1 到 200 个 UTF-16 字符,用 `x-length` 按 `string.length` 计,不含 NUL,不全是空白)和至少一个非 `null` 的前四项计数;同一 `model` 的多项按四个核心计数(`inputTokens`、`outputTokens`、`cachedReadTokens`、`cachedWriteTokens`)分别相加,各自合计不得超过 9007199254740991,`totalTokens`、`thoughtTokens` 与其他键不参与(`agent.mjs` 的 `x-sum-max` 关键字检查)。未知键照旧允许。`agentValueProblem('prompt-usage.json', …)` 即可校验,`AGENT_SCHEMAS` 自动收录。
|
|
13
|
+
- `docs/agent-protocol.md` 加「每轮的用量」一节,写明位置(`result.usage`,不放 `_meta`)、`inputTokens` 不含缓存、只报本轮增量、`breakdown` 为分模型的唯一来源,同一模型分项的合并规则与安全整数上限,顶层汇总只供支持本约定、不处理 `breakdown` 的读取方使用(与 ACP 实验版按累计口径的 `usage` 不互通),以及不许带提示词、路径、代码和费用。
|
|
14
|
+
- `session/prompt` 仍由 ACP SDK 校验,不进 `AGENT_METHODS`;`usage.json`(`usage_update._meta.coda`)、`messages.json`、清单 schema 与 `stable/` 都没动。
|
|
15
|
+
|
|
5
16
|
## 6.15.0 — 2026-11-19
|
|
6
17
|
|
|
7
18
|
- 这是在 6.14.0 之上的次版本(页面绑定需求二,协议包成员)。依据 README「版本」一节:`contributes.endpoints`、`records`、`self` 都不在 `stable/manifest.json`,是内部面,新增可选键、删内部键升次版本;`stable-grows` 与 `test/stable.test.mjs` 不受影响。H6 的协议成员(6.14.0)先合,本成员顺延为 6.15.0。
|
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/agent.mjs
CHANGED
|
@@ -13,6 +13,27 @@ export const AGENT_SCHEMAS = Object.fromEntries(readdirSync(dir).filter(file =>
|
|
|
13
13
|
const schemas = Object.values(AGENT_SCHEMAS), ajv = newAjv({ ownProperties: true });
|
|
14
14
|
valueKeywords(ajv, {});
|
|
15
15
|
ajv.addFormat('date-parse', value => Number.isFinite(Date.parse(value)));
|
|
16
|
+
// Entries of one model are merged by adding the four core counts; each sum must stay a safe integer.
|
|
17
|
+
const CORE_COUNTS = ['inputTokens', 'outputTokens', 'cachedReadTokens', 'cachedWriteTokens'];
|
|
18
|
+
ajv.addKeyword({
|
|
19
|
+
keyword: 'x-sum-max', type: 'array', schemaType: 'number', errors: true,
|
|
20
|
+
compile(limit, parentSchema) {
|
|
21
|
+
return function sum(entries) {
|
|
22
|
+
const totals = new Map();
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
if (typeof entry?.model !== 'string') continue;
|
|
25
|
+
const counts = totals.get(entry.model) ?? totals.set(entry.model, {}).get(entry.model);
|
|
26
|
+
for (const name of CORE_COUNTS) {
|
|
27
|
+
const count = entry[name];
|
|
28
|
+
if (!Number.isInteger(count)) continue;
|
|
29
|
+
counts[name] = (counts[name] ?? 0) + count;
|
|
30
|
+
if (counts[name] > limit) { sum.errors = [{ keyword: 'x-sum-max', params: { limit }, parentSchema, message: '合计过大' }]; return false; }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
16
37
|
for (const schema of schemas) ajv.addSchema(schema);
|
|
17
38
|
|
|
18
39
|
// A reference is relative to schemas/agent/, optionally with a JSON Pointer fragment.
|
package/docs/agent-protocol.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Agent 接入协议
|
|
2
2
|
|
|
3
3
|
Coda 用 [ACP](https://agentclientprotocol.com)(Agent Client Protocol)接 Agent,把[会话指令](#会话指令)交给 Agent(ACP 的 `systemPrompt`;不收它的由 Coda 在第一轮送入),
|
|
4
|
-
可选支持[插话](#插话)(`_session/steering`),另收 Agent 活动报告(`_coda/wait`)、入口[没适配的东西](#没适配的东西)(`_coda/unrecognized`)、[执行失败事实](#执行失败)(ACP 错误数据里的 `_meta.coda.failure
|
|
4
|
+
可选支持[插话](#插话)(`_session/steering`),另收 Agent 活动报告(`_coda/wait`)、入口[没适配的东西](#没适配的东西)(`_coda/unrecognized`)、[执行失败事实](#执行失败)(ACP 错误数据里的 `_meta.coda.failure`)、[工具调用的审核](#工具调用的审核)(`_meta.coda.review`)和[每轮的用量](#每轮的用量)(`session/prompt` 答复的 `usage`)。本文是这份协议的唯一正文,写给要让一个 Agent(比如 Cursor 的)接入 Coda 的人:照它实现,
|
|
5
5
|
Coda 就知道这个 Agent 在一轮之外还在做什么,如实显示、不回收它的进程,把它处理这些东西时的输出、审批和提问放进正确的一轮,
|
|
6
6
|
并在这次调用结清时把结果只交回一次。产品上这些规则的来由见会话行为契约(Coda 的 docs/session-contracts.md)与完成唤醒契约(Coda 的 docs/subagent-design.md「完成唤醒契约」)。
|
|
7
7
|
|
|
@@ -28,6 +28,7 @@ ACP 的消息、内容块、会话指令和能力由 ACP SDK 校验,这里只
|
|
|
28
28
|
| `error.data._meta.coda.failure` | [failure.json](../schemas/agent/failure.json) |
|
|
29
29
|
| 工具更新的 `_meta.coda.review` | [review.json](../schemas/agent/review.json);已知风险值见 `$defs/risk` |
|
|
30
30
|
| 用量更新的 `_meta.coda` | [usage.json](../schemas/agent/usage.json) |
|
|
31
|
+
| `session/prompt` 答复的 `usage` | [prompt-usage.json](../schemas/agent/prompt-usage.json) |
|
|
31
32
|
| 配置选项的 `_meta.coda.default` | [default.json](../schemas/agent/default.json)(传入 `_meta.coda` 对象) |
|
|
32
33
|
| 模型、模式、配置项及其选项的 `_meta.coda.shortName` | [display.json](../schemas/agent/display.json)(传入 `_meta.coda` 对象) |
|
|
33
34
|
|
|
@@ -60,7 +61,7 @@ Coda 是 ACP 的客户端。每个会话的 Agent 进程由一个会话托管进
|
|
|
60
61
|
| --- | --- | --- |
|
|
61
62
|
| `initialize` | Coda → Agent | 握手。`clientCapabilities` 带 `elicitation.form`、`elicitation.url`、`session.compaction`、`session.configOptions.boolean`、`_meta.coda.waits`(见[能力协商](#能力协商))、`_meta.coda.unrecognized`(见[没适配的东西](#没适配的东西))与 `_meta.coda.remote`(见[远端入口](#远端入口)) |
|
|
62
63
|
| `session/new`、`session/load` | Coda → Agent | 新建或恢复原生会话,会话 ID 由 Agent 给;Agent 声明 `loadSession` 才会被要求恢复。Agent 声明了才带 `systemPrompt`([会话指令](#会话指令))。带 `_meta.coda.probe: true` 时改为连接内虚拟会话,见[配置探测](#配置探测)。结果里要报出当前模型(见下)。恢复期间重放的历史 Coda 不收(它有自己的),只收命令与标题 |
|
|
63
|
-
| `session/prompt` | Coda → Agent | 一轮:Coda 送出用户的消息或它自己合成的输入(子会话结果等),Agent 回复 `stopReason`
|
|
64
|
+
| `session/prompt` | Coda → Agent | 一轮:Coda 送出用户的消息或它自己合成的输入(子会话结果等),Agent 回复 `stopReason` 即本轮结束;答复可带本轮的 `usage`,见[每轮的用量](#每轮的用量) |
|
|
64
65
|
| `_session/steering` | Coda → Agent | [插话](#插话):把用户的消息加进正在进行的一轮;只对声明支持的 Agent 发 |
|
|
65
66
|
| `session/cancel` | Coda → Agent | 停止:本轮在进行时取消本轮;Agent 在一轮之外处理活动(`handling`)时,停止处理 |
|
|
66
67
|
| `_coda/session/compact` | Coda → Agent | [压缩上下文](#压缩上下文):请 Agent 压缩这个会话的上下文;只对声明支持的 Agent 发,两轮之间也发 |
|
|
@@ -297,6 +298,24 @@ Agent 在 `session/update` 的 `usage_update` 里可以带 `_meta.coda`:一个
|
|
|
297
298
|
`lastRequestAt`(主线程最后一次请求模型的时刻,提示词缓存从这一刻起算;比一轮结束早一段输出的时间)、`contextTokens`(那次请求带的上下文 token 数)、
|
|
298
299
|
`cacheTtl`(缓存时长,`PT1H` 或 `PT5M`)、`compactedAt`(最近一次压缩的时刻)。
|
|
299
300
|
|
|
301
|
+
## 每轮的用量
|
|
302
|
+
|
|
303
|
+
`session/prompt` 答复里 `usage` 的形状见 [prompt-usage.json](../schemas/agent/prompt-usage.json)。
|
|
304
|
+
|
|
305
|
+
Agent 在 `session/prompt` 成功答复的 `result.usage` 里报这一轮新用掉的 token(增量),Coda 据此按轮、按模型统计用量。`usage` 在 `result` 顶层,不放 `_meta`:`_meta` 留给各客户端的私有扩展,Coda 不解析 `_meta.usage`。
|
|
306
|
+
|
|
307
|
+
```json
|
|
308
|
+
{"jsonrpc":"2.0","id":7,"result":{"stopReason":"end_turn","usage":{"inputTokens":1200,"outputTokens":480,"cachedReadTokens":53000,"cachedWriteTokens":null,"totalTokens":54680,"thoughtTokens":150,"breakdown":[{"model":"claude-sonnet-5-5","inputTokens":1000,"outputTokens":400,"cachedReadTokens":50000},{"model":"claude-haiku-5-5","inputTokens":200,"outputTokens":80,"cachedReadTokens":3000}]}}}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
- 计数都是 0 到 9007199254740991(安全整数上限)的整数;缺失或 `null` 表示没报告,不代表 0。顶层须至少有一个非 `null` 的 `inputTokens`、`outputTokens`、`cachedReadTokens`、`cachedWriteTokens`,或带 `breakdown`;只有 `totalTokens`、`thoughtTokens` 不算。
|
|
312
|
+
- `inputTokens` 是未缓存的输入,不含 `cachedReadTokens`、`cachedWriteTokens`;`outputTokens` 若来源已含思考 token,不再另加 `thoughtTokens`。`totalTokens` 与 `thoughtTokens` 只作同一轮的展示,Coda 不拿 `totalTokens` 求和。
|
|
313
|
+
- 只报本轮增量,绝不传会话累计的总量。失败或没有 `result` 的轮次不计入。
|
|
314
|
+
- `breakdown` 可选,非空数组,每项是 `model`(模型 ID,1 到 200 个 UTF-16 字符,即 JS 的 `string.length`,不含 NUL,不全是空白)加上述计数,且至少有一个非 `null` 的 `inputTokens`、`outputTokens`、`cachedReadTokens`、`cachedWriteTokens`。有 `breakdown` 时它是分模型的唯一来源,Coda 绝不把它与顶层相加。
|
|
315
|
+
- 同一 `model` 可以出现在多项里,Coda 把它们的 `inputTokens`、`outputTokens`、`cachedReadTokens`、`cachedWriteTokens` 分别相加;这四个核心计数同模型的合计各自不得超过 9007199254740991,超过即整份 `usage` 不合法。`totalTokens`、`thoughtTokens` 与其他键不参与合并,也不检查合计。
|
|
316
|
+
- 顶层汇总写不写都行:它供支持本节每轮增量约定、但不处理 `breakdown` 的读取方使用,建议填各模型之和。它不与 ACP 实验版的 `usage`(要求三项同时存在,按累计口径)互通,不要当成通用 ACP 客户端能读的字段。
|
|
317
|
+
- 不许带提示词、文件路径、项目名、代码或费用,只许模型 ID。未知键照旧允许、不改写,Coda 只读本节列出的字段。
|
|
318
|
+
|
|
300
319
|
## 工具调用的审核
|
|
301
320
|
|
|
302
321
|
审核的形状与已知风险值见 [review.json](../schemas/agent/review.json)。
|
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,183 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/agent/v1/prompt-usage.json",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"description": "usage 须为对象,并至少带一个非 null 的 inputTokens、outputTokens、cachedReadTokens、cachedWriteTokens 或一份 breakdown;只记本轮增量",
|
|
6
|
+
"$defs": {
|
|
7
|
+
"count": {
|
|
8
|
+
"type": [
|
|
9
|
+
"integer",
|
|
10
|
+
"null"
|
|
11
|
+
],
|
|
12
|
+
"minimum": 0,
|
|
13
|
+
"maximum": 9007199254740991,
|
|
14
|
+
"description": "token 计数须为 0 到 9007199254740991 的整数,或省略、null 表示未报告"
|
|
15
|
+
},
|
|
16
|
+
"model": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"pattern": "^(?!\\s+$)[^\\u0000]+$",
|
|
19
|
+
"x-length": 200,
|
|
20
|
+
"description": "model 须为 1 到 200 个 UTF-16 字符、不含 NUL、不全是空白的模型 ID"
|
|
21
|
+
},
|
|
22
|
+
"counts": {
|
|
23
|
+
"properties": {
|
|
24
|
+
"inputTokens": {
|
|
25
|
+
"$ref": "#/$defs/count"
|
|
26
|
+
},
|
|
27
|
+
"outputTokens": {
|
|
28
|
+
"$ref": "#/$defs/count"
|
|
29
|
+
},
|
|
30
|
+
"cachedReadTokens": {
|
|
31
|
+
"$ref": "#/$defs/count"
|
|
32
|
+
},
|
|
33
|
+
"cachedWriteTokens": {
|
|
34
|
+
"$ref": "#/$defs/count"
|
|
35
|
+
},
|
|
36
|
+
"totalTokens": {
|
|
37
|
+
"$ref": "#/$defs/count"
|
|
38
|
+
},
|
|
39
|
+
"thoughtTokens": {
|
|
40
|
+
"$ref": "#/$defs/count"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"entry": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"description": "breakdown 的每一项须为对象,带 model 和至少一个非 null 的 inputTokens、outputTokens、cachedReadTokens 或 cachedWriteTokens",
|
|
47
|
+
"allOf": [
|
|
48
|
+
{
|
|
49
|
+
"$ref": "#/$defs/counts"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"properties": {
|
|
53
|
+
"model": {
|
|
54
|
+
"$ref": "#/$defs/model"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"required": [
|
|
58
|
+
"model"
|
|
59
|
+
],
|
|
60
|
+
"anyOf": [
|
|
61
|
+
{
|
|
62
|
+
"properties": {
|
|
63
|
+
"inputTokens": {
|
|
64
|
+
"not": {
|
|
65
|
+
"type": "null"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"required": [
|
|
70
|
+
"inputTokens"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"properties": {
|
|
75
|
+
"outputTokens": {
|
|
76
|
+
"not": {
|
|
77
|
+
"type": "null"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"required": [
|
|
82
|
+
"outputTokens"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"properties": {
|
|
87
|
+
"cachedReadTokens": {
|
|
88
|
+
"not": {
|
|
89
|
+
"type": "null"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"required": [
|
|
94
|
+
"cachedReadTokens"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"properties": {
|
|
99
|
+
"cachedWriteTokens": {
|
|
100
|
+
"not": {
|
|
101
|
+
"type": "null"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"required": [
|
|
106
|
+
"cachedWriteTokens"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"allOf": [
|
|
113
|
+
{
|
|
114
|
+
"$ref": "#/$defs/counts"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"properties": {
|
|
118
|
+
"breakdown": {
|
|
119
|
+
"type": "array",
|
|
120
|
+
"minItems": 1,
|
|
121
|
+
"description": "breakdown 须为至少一项的数组,同一 model 的 inputTokens、outputTokens、cachedReadTokens、cachedWriteTokens 各自合计不超过 9007199254740991",
|
|
122
|
+
"items": {
|
|
123
|
+
"$ref": "#/$defs/entry"
|
|
124
|
+
},
|
|
125
|
+
"x-sum-max": 9007199254740991
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"anyOf": [
|
|
129
|
+
{
|
|
130
|
+
"required": [
|
|
131
|
+
"breakdown"
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"properties": {
|
|
136
|
+
"inputTokens": {
|
|
137
|
+
"not": {
|
|
138
|
+
"type": "null"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"required": [
|
|
143
|
+
"inputTokens"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"properties": {
|
|
148
|
+
"outputTokens": {
|
|
149
|
+
"not": {
|
|
150
|
+
"type": "null"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"required": [
|
|
155
|
+
"outputTokens"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"properties": {
|
|
160
|
+
"cachedReadTokens": {
|
|
161
|
+
"not": {
|
|
162
|
+
"type": "null"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"required": [
|
|
167
|
+
"cachedReadTokens"
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"properties": {
|
|
172
|
+
"cachedWriteTokens": {
|
|
173
|
+
"not": {
|
|
174
|
+
"type": "null"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"required": [
|
|
179
|
+
"cachedWriteTokens"
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
@@ -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
|
+
}
|