@coda-console/protocol 6.14.0 → 6.16.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 +14 -0
- package/README.md +1 -1
- package/agent.mjs +21 -0
- package/docs/agent-protocol.md +21 -2
- package/docs/protocol.md +20 -1
- package/package.json +1 -1
- package/schemas/agent/prompt-usage.json +183 -0
- package/schemas/plugin/extension-points.json +3 -1
- package/schemas/plugin/plugin.json +3 -2
- package/schemas/plugin/records.json +23 -0
- package/schemas/plugin/self.json +10 -0
- package/schemas/plugin/endpoints.json +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.16.0 — 2026-11-20
|
|
6
|
+
|
|
7
|
+
- 这是在 6.15.0 之上的次版本。依据 README「版本」一节:Agent 接入协议是内部面,新增 schema 与文档小节升次版本;`stable/` 不动,`stable-grows` 与 `test/stable.test.mjs` 不受影响(每轮 Token 用量采集,coda#1824)。
|
|
8
|
+
- 新增 `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` 自动收录。
|
|
9
|
+
- `docs/agent-protocol.md` 加「每轮的用量」一节,写明位置(`result.usage`,不放 `_meta`)、`inputTokens` 不含缓存、只报本轮增量、`breakdown` 为分模型的唯一来源,同一模型分项的合并规则与安全整数上限,顶层汇总只供支持本约定、不处理 `breakdown` 的读取方使用(与 ACP 实验版按累计口径的 `usage` 不互通),以及不许带提示词、路径、代码和费用。
|
|
10
|
+
- `session/prompt` 仍由 ACP SDK 校验,不进 `AGENT_METHODS`;`usage.json`(`usage_update._meta.coda`)、`messages.json`、清单 schema 与 `stable/` 都没动。
|
|
11
|
+
|
|
12
|
+
## 6.15.0 — 2026-11-19
|
|
13
|
+
|
|
14
|
+
- 这是在 6.14.0 之上的次版本(页面绑定需求二,协议包成员)。依据 README「版本」一节:`contributes.endpoints`、`records`、`self` 都不在 `stable/manifest.json`,是内部面,新增可选键、删内部键升次版本;`stable-grows` 与 `test/stable.test.mjs` 不受影响。H6 的协议成员(6.14.0)先合,本成员顺延为 6.15.0。
|
|
15
|
+
- 清单 `contributes` 加可选的 `records`:数组,每种记录一项 `{ kind, command, every? }`,不许别的键,至多 20 项,按 `kind` 去重。`kind` 是协议名(复用 `definition.json` 的 `name`);`command` 是插件目录里的文件(`x-file`,写法同 `protocolImplementations` 的 `commands`);`every` 可选,写法与 Coda 资源面板的 `maxAge` 同一套(ISO 8601 风格:周 `W`、天 `D`、时 `H`、分 `M`、秒 `S`,只有秒能带小数点,不收年、月,如 `PT5M`、`PT90S`、`P1W1D`),以后资源面板迁成记录时 `maxAge` 就对应 `every`。`every` 不短于 `PT1M` 的下限 schema 表达不了,由 Coda 判,schema 只查时长的写法。`kind` 是不是这个插件 `protocolImplementations` 里的种类,也由 Coda 装载时查。
|
|
16
|
+
- 清单 `contributes` 加可选的 `self`:对象,名字(复用 `operationName`)→ 插件目录里的文件(`x-file`),至多 50 个。
|
|
17
|
+
- 不兼容:删掉 `contributes.endpoints`:删去 `schemas/plugin/endpoints.json` 与 `plugin.json` 里的引用。`extension-points.json` 里保留键名单的 `endpoints` 留着,第三方仍不能把它当扩展点的键;保留名单另加 `records`、`self`。清单里再写 `contributes.endpoints` 的结果与别的不认识的键一样:不查形状,`manifestProblem` 通过;旧清单判不判兼容由 Coda 定。
|
|
18
|
+
|
|
5
19
|
## 6.14.0 — 2026-11-19
|
|
6
20
|
|
|
7
21
|
- 这是在 6.13.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本;`contributes.events` 是试行面,不在 `stable/` 里,删它不动稳定面(先例见 6.12.0 删 `contributes.groups`),`stable-grows` 与 `test/stable.test.mjs` 不受影响(Coda 宿主设计 coda#2749 H6)。
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
|
|
4
4
|
|
|
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`、`
|
|
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`、`views`、`protocols`、`protocolImplementations`、`records`、`self`);`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
7
|
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `streams` 声明只读记录流,可写 `events` 声明事件(载荷格式与 `starts`、`ends`;只有事件的协议可以不写 `spec`、`status`、`operations`,`protocolHasRecords` 判断一份定义有没有记录),可写 `permissions` 把操作、流、事件与记录的读取分成权限组,插件在清单根的 `uses` 里按组申请。调用是 `{ record, operation, input, requestId, parent, awaited }`,回答是 `{ result }` 或 `{ run }`;`coda/run@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` 负责跨节点检查。
|
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
|
@@ -7,7 +7,7 @@
|
|
|
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`;
|
|
10
|
-
- 插件清单里的 `contributes.protocols` 与 `contributes.
|
|
10
|
+
- 插件清单里的 `contributes.protocols`、`contributes.protocolImplementations`、`contributes.records` 与 `contributes.self`。
|
|
11
11
|
|
|
12
12
|
`executor` 与 `execution` 两个旧对象协议和 `@coda-console/protocol/executor` 在 3.0.0 删除。
|
|
13
13
|
|
|
@@ -293,6 +293,25 @@ invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
|
293
293
|
|
|
294
294
|
同一个协议在数组里只能出现一次,写成文本还是对象都算。
|
|
295
295
|
|
|
296
|
+
`contributes.records` 声明哪些种类的记录由命令给出,每种一项,至多 20 项:
|
|
297
|
+
|
|
298
|
+
```json
|
|
299
|
+
"records": [
|
|
300
|
+
{"kind": "my-plugin/task@1", "command": "bin/tasks.sh", "every": "PT5M"}
|
|
301
|
+
]
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
- `kind`:协议名;同一种类只能出现一次。须是这个插件 `protocolImplementations` 里的种类,由 Coda 装载时查。
|
|
305
|
+
- `command`:插件目录里的文件(相对路径,不离开插件目录),写法同 `commands`。
|
|
306
|
+
- `every`:可选,定时重跑的间隔,ISO 8601 风格:周 `W`、天 `D`、时 `H`、分 `M`、秒 `S`(如 `PT5M`、`PT90S`、`P1W1D`),只有秒能带小数点,不收年、月;不短于 `PT1M`;不写就不定时。下限 schema 表达不了,由 Coda 判。
|
|
307
|
+
- 不许别的键。命令怎么跑、打印什么由 Coda 的文档讲,这里不重述。
|
|
308
|
+
|
|
309
|
+
`contributes.self` 声明由命令回答的「只给自己用的查询」:名字(格式同操作名)→ 插件目录里的文件(相对路径,不离开插件目录),至多 50 个。
|
|
310
|
+
|
|
311
|
+
```json
|
|
312
|
+
"self": {"operation": "bin/self-operation.sh"}
|
|
313
|
+
```
|
|
314
|
+
|
|
296
315
|
插件用到别的协议的权限,写在清单根的 `uses`,不放进 `contributes`(Coda 把不认识的 `contributes` 键当扩展点,旧版本会因此拒装)。键是带大版本的协议名,值是权限组名的数组,至少一项、不重复:
|
|
297
316
|
|
|
298
317
|
```json
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
|
@@ -59,10 +59,11 @@
|
|
|
59
59
|
"setup": {"$ref": "setup.json"},
|
|
60
60
|
"environment": {"$ref": "environment.json"},
|
|
61
61
|
"path": {"$ref": "path.json"},
|
|
62
|
-
"endpoints": {"$ref": "endpoints.json"},
|
|
63
62
|
"views": {"$ref": "views.json"},
|
|
64
63
|
"protocols": {"$ref": "protocols.json"},
|
|
65
|
-
"protocolImplementations": {"$ref": "protocol-implementations.json"}
|
|
64
|
+
"protocolImplementations": {"$ref": "protocol-implementations.json"},
|
|
65
|
+
"records": {"$ref": "records.json"},
|
|
66
|
+
"self": {"$ref": "self.json"}
|
|
66
67
|
},
|
|
67
68
|
"propertyNames": {"description": "contributes 的键:字母和数字,以小写字母开头", "pattern": "^[a-z][A-Za-z0-9]{0,39}$"}
|
|
68
69
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/records.json",
|
|
4
|
+
"title": "contributes.records:由命令给出的记录",
|
|
5
|
+
"description": "每种记录一项 { kind, command, every? }:kind 是协议名,须是这个插件 protocolImplementations 里的种类(装载时由 Coda 查),同一种类只能出现一次;command 是插件目录里的文件(写法同 protocolImplementations 的 commands),Coda 以插件身份运行它,打印的全集是这种记录的全部记录;every 是定时重跑的间隔,写法与资源面板的 maxAge 相同(ISO 8601 风格:周 W、天 D、时 H、分 M、秒 S,只有秒能带小数点,不收年、月),不短于 PT1M(下限 schema 表达不了,由 Coda 判),不写就不定时。",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"maxItems": 20,
|
|
8
|
+
"x-unique-by": ["kind"],
|
|
9
|
+
"items": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"kind": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"},
|
|
13
|
+
"command": {"description": "插件目录里的文件(相对路径,不离开插件目录)", "type": "string", "x-file": {"type": "file"}},
|
|
14
|
+
"every": {
|
|
15
|
+
"description": "ISO 8601 风格的时长,如 PT5M、P1W1D:周 W、天 D、时 H、分 M、秒 S,只有秒能带小数点,不收年、月;不短于 PT1M,下限由 Coda 判",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"pattern": "^P(?!$)(?:\\d+W)?(?:\\d+D)?(?:T(?=\\d)(?:\\d+H)?(?:\\d+M)?(?:\\d+(?:\\.\\d+)?S)?)?$"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"required": ["kind", "command"],
|
|
21
|
+
"additionalProperties": false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/self.json",
|
|
4
|
+
"title": "contributes.self:只给自己用的查询",
|
|
5
|
+
"description": "名字 → 插件目录里的文件(相对路径,不离开插件目录),由命令回答插件自己的页面与进程的 self 查询;同一个名字写了命令就交给命令,没有再找模块。至多 50 个。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"maxProperties": 50,
|
|
8
|
+
"propertyNames": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/operationName"},
|
|
9
|
+
"additionalProperties": {"type": "string", "x-file": {"type": "file"}}
|
|
10
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://coda.pub/schemas/plugin/v2/endpoints.json",
|
|
4
|
-
"title": "contributes.endpoints:客户端发给插件的请求",
|
|
5
|
-
"description": "id → 回答它的一行命令(请求从标准输入给)。",
|
|
6
|
-
"type": "array",
|
|
7
|
-
"maxItems": 20,
|
|
8
|
-
"items": {
|
|
9
|
-
"type": "object",
|
|
10
|
-
"properties": {
|
|
11
|
-
"id": {"$ref": "common.json#/$defs/id"},
|
|
12
|
-
"command": {"$ref": "common.json#/$defs/command"}
|
|
13
|
-
},
|
|
14
|
-
"required": ["id", "command"],
|
|
15
|
-
"additionalProperties": false
|
|
16
|
-
},
|
|
17
|
-
"x-unique-by": ["id"]
|
|
18
|
-
}
|