@coda-console/protocol 6.9.0 → 6.11.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 +15 -0
- package/README.md +3 -3
- package/docs/protocol.md +73 -0
- package/package.json +1 -1
- package/protocol.mjs +23 -0
- package/schemas/plugin/plugin.json +13 -0
- package/schemas/protocol/v1/agent.json +4 -0
- package/schemas/protocol/v1/definition.json +39 -2
- package/schemas/protocol/v1/environment.json +3 -0
- package/schemas/protocol/v1/run.json +4 -0
- package/schemas/protocol/v1/session.json +4 -0
- package/stable/manifest.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.11.0 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
- 这是在 6.10.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本;`stable/` 不动,`stable/manifest.json` 与 `stable/view.json` 没有任何协议定义的字段,清单与页面接口都没变,旧清单、旧定义照旧通过(Coda 宿主设计 coda#2749 第 12 节,只读记录流)。
|
|
8
|
+
- 协议定义加可选的顶层 `streams`:流名(写法同操作名,复用 `operationName`)→ `{ description?, input }`,不许别的键,至多 50 条。流是挂在记录 `{ kind, id }` 上的只读字节流入口,和查询、操作并列;`input` 是参数的 JSON Schema(与操作的 `input` 同一写法),参数都来自查询串,是字符串。`definitionProblem` 还查每条流的 `input` 能编译。
|
|
9
|
+
- 权限组加可选的 `streams: [流名…]`(不重复)。`definitionProblem` 的规则与操作同构:每条流最多属于一组;组里列的流必须在 `streams` 里;「每组至少管一样东西」把 `streams` 算进去(有操作、有流,或 `read` 为 true),所以只管流的组合法。不在任何组里的流不对插件开放,只有 Coda 自己和它的客户端读;不写 `streams` 的定义照旧合法。
|
|
10
|
+
- 本包只管声明的形状;路由、放行与出流由 Coda 实现。核心协议的定义本版不声明流,由 Coda 后续随实现一起加。
|
|
11
|
+
|
|
12
|
+
## 6.10.0 — 2026-11-18
|
|
13
|
+
|
|
14
|
+
- 这是在 6.9.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,新增可选字段升次版本;清单新增可选根键 `uses`,旧清单照旧通过(Coda 宿主设计 coda#2749 H3)。
|
|
15
|
+
- 协议定义加可选的顶层 `permissions`:权限组名(写法同操作名)→ `{ title, trial?, operations?, read? }`,不许别的键。`title` 是给用户看的一句话;`trial` 标试行;`operations` 是归这组管的操作(不重复);`read` 管读这个协议的记录(get、list、watch);写记录只许实现方,不分给插件,所以没有 `write`。写了 `permissions` 的定义,`definitionProblem` 还查:每个操作最多属于一组;组里列的操作都存在;每组至少管一样东西(有操作,或 `read` 为 true)。不在任何组里的操作不对插件开放,只有 Coda 自己和它的客户端调;不写的定义照旧合法,整个协议都不对插件开放。
|
|
16
|
+
- 插件清单根加可选的 `uses`:键是带大版本的协议名,值是权限组名的数组,至少一项、不重复;组名与操作名共用 `definition.json` 的 `operationName`。放在根上而不是 `contributes` 里:Coda 把不认识的 `contributes` 键当扩展点,旧版本会因此拒装;根上的未知键旧版本会忽略。本包只管形状,协议和组在不在目录里由 Coda 校验。`stable/manifest.json` 加 `uses.*[]`,`revision` 加到 2。
|
|
17
|
+
- `coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1` 写上权限组,全部标 `trial: true`(它们都不在 `stable/` 的稳定面里):`coda/run@1` 的 `read`、`cancel`;`coda/agent@1` 的 `read`、`spawn`;`coda/session@1` 的 `read`、`post`(`draft` 是客户端输入框的击键流,不分组,不对插件开放);`coda/environment@1` 的 `read`。分组与说明见 `docs/protocol.md`「权限组」。`coda/card@1` 不动(`coda/executor@1` 已在 6.9.0 删除)。
|
|
18
|
+
- 定义的 `permissions` 不入稳定面:协议定义本来就是内部面,`stable/` 里没有任何定义的字段;只有清单的 `uses` 是第三方会写的正式键。
|
|
19
|
+
|
|
5
20
|
## 6.9.0 — 2026-11-18
|
|
6
21
|
|
|
7
22
|
- 这是在 6.8.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,删改升次版本,先例见 6.4.0(删去 `coda/run@1` 的 `answer`)。
|
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`
|
|
7
|
+
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `streams` 声明只读记录流,可写 `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` 负责跨节点检查。
|
|
9
9
|
- **Agent 接入扩展**(`schemas/agent/`、`agent.mjs`、`docs/agent-protocol.md`):Coda 怎样用 ACP 接 Agent,以及 Coda 加的扩展(会话指令、插话、`_coda/wait`、执行失败、工具调用的审核、配置探测)。
|
|
10
10
|
|
|
@@ -127,7 +127,7 @@ agentValueProblem('review.json', review, '工具的审核');
|
|
|
127
127
|
## 协议定义与核心协议
|
|
128
128
|
|
|
129
129
|
从 3.0.0 起,协议是 `命名空间/名字@大版本` + 记录格式(spec、status 的 JSON Schema)+ 操作,见[协议正文](docs/protocol.md)。
|
|
130
|
-
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations`
|
|
130
|
+
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组;
|
|
131
131
|
命名空间 `coda` 保留给核心协议。
|
|
132
132
|
|
|
133
133
|
- **`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`。
|
|
@@ -156,7 +156,7 @@ Coda 与检查包都钉一个确切版本。对第三方的兼容承诺只覆盖
|
|
|
156
156
|
三道检查分别守住:
|
|
157
157
|
|
|
158
158
|
- `scripts/stable-grows.mjs <基线>`:两份数据的旧条目及其取值必须全部保留,有新增时对应文件的 revision 必须增大,不能倒退。基线可为 git 提交、解包目录或 `npm:latest`。PR 和目标分支比较,发布前下载并解包 npm latest 比较;基线还没有 stable 文件时通过。
|
|
159
|
-
- `test/stable.test.mjs`:
|
|
159
|
+
- `test/stable.test.mjs`:54 条路径仍在 schema 中可达,承诺的取值仍被接受。使用固定样本选择条件分支,支持 `$ref`、`allOf`、`anyOf`、`if/then/else`、`not`、`properties`、`items`、`additionalProperties` 及布尔 schema;未知写法失败,不推测其含义。`agents`、`commands`、`skills` 从各自的业务 schema 起步。
|
|
160
160
|
- `test/third-party.test.mjs`:两版 pi、一版 resource-manager 原文与 company 合成样本,分别跑整份清单和每个贡献键的校验,防止样本用到的约束被收紧。不检查磁盘文件与页面桥行为。这个仓库只守页面接口清单只增不减;页面接口的实现在 Coda 的客户端里,这里不核对。
|
|
161
161
|
|
|
162
162
|
增加稳定面一项时,先补 schema 或页面实现,再把路径、取值或页面条目加进对应 JSON;每加一项,该文件 revision 加一。补充能覆盖新路径和条件分支的测试样本,运行三道检查,并更新次版本与 CHANGELOG。
|
package/docs/protocol.md
CHANGED
|
@@ -74,6 +74,8 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
|
|
|
74
74
|
| `spec` | 记录的 spec 的 JSON Schema,必填 |
|
|
75
75
|
| `status` | 记录的 status 的 JSON Schema,必填 |
|
|
76
76
|
| `operations` | 操作名 → `{ description?, input, result, safe?, idempotent?, timeout? }` 或 `{ description?, input, run: true, timeout? }`,必填;不定义操作写 `{}` |
|
|
77
|
+
| `streams` | 流名 → `{ description?, input }`,可选(见「只读记录流」) |
|
|
78
|
+
| `permissions` | 权限组名 → `{ title, trial?, operations?, streams?, read? }`,可选(见「权限组」) |
|
|
77
79
|
|
|
78
80
|
`spec`、`status`、`input`、`result` 都是 JSON Schema draft 2020-12,只引用自己文档里的 `#/$defs/...`,不引用别的文件。`input` 必有。操作的输出二选一:
|
|
79
81
|
|
|
@@ -173,6 +175,66 @@ invocationRequestProblem(request); // null 或说明
|
|
|
173
175
|
invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
174
176
|
```
|
|
175
177
|
|
|
178
|
+
### 只读记录流
|
|
179
|
+
|
|
180
|
+
流是协议记录上的第三种入口,和查询、操作并列:按记录 `{ kind, id }` 寻址、只读、返回字节流(而不是一个 JSON 结果)。定义用顶层 `streams` 声明,键是流名(写法同操作名:小写字母开头,只用小写字母、数字和「-」,至多 64 个字符,至多 50 条),值是:
|
|
181
|
+
|
|
182
|
+
| 字段 | 含义 |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `description` | 可选,一句话说明 |
|
|
185
|
+
| `input` | 必填,参数的 JSON Schema(draft 2020-12,和操作的 `input` 同一写法,`definitionProblem` 查它能编译) |
|
|
186
|
+
|
|
187
|
+
参数都来自查询串,取值都是字符串,所以 `input` 里的属性按字符串写约束。流名可以和操作名相同,两者各管各的。定义里不写 `streams` 就是没有流。本包只管声明的形状;怎样寻址、怎样出字节是宿主的事。
|
|
188
|
+
|
|
189
|
+
```json
|
|
190
|
+
"streams": {
|
|
191
|
+
"log": {
|
|
192
|
+
"description": "一个步骤的日志,可从字节偏移取起",
|
|
193
|
+
"input": {
|
|
194
|
+
"type": "object",
|
|
195
|
+
"properties": {"job": {"type": "string"}, "after": {"type": "string", "pattern": "^[0-9]+$"}},
|
|
196
|
+
"required": ["job"],
|
|
197
|
+
"additionalProperties": false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 权限组
|
|
204
|
+
|
|
205
|
+
一切对插件开放的能力都以协议提供,权限挂在协议上:定义用 `permissions` 把自己的操作、流与记录的读取分成组,插件在清单的 `uses` 里声明用到哪些组,没声明的调用被宿主拒绝。组名的写法同操作名(小写字母开头,只用小写字母、数字和「-」,至多 64 个字符)。每组:
|
|
206
|
+
|
|
207
|
+
| 字段 | 含义 |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| `title` | 必填,给用户看的一句话,说这组让插件能做什么,如「读取会话的标题与状态」 |
|
|
210
|
+
| `trial` | 可选,布尔,这组是否试行;只影响展示,不影响能否调用 |
|
|
211
|
+
| `operations` | 可选,不重复的操作名数组,归这组管的操作 |
|
|
212
|
+
| `streams` | 可选,不重复的流名数组,归这组管的流 |
|
|
213
|
+
| `read` | 可选,布尔,管不管读这个协议的记录(get、list、watch)。写记录只许实现方,不分给插件 |
|
|
214
|
+
|
|
215
|
+
不许有别的键。写了 `permissions` 的定义还要满足(`definitionProblem` 查):每个操作、每条流最多属于一组;组里列的操作都在 `operations` 里,列的流都在 `streams` 里;每组至少管一样东西(有操作、有流,或 `read` 为 true)。**不在任何组里的操作和流不对插件开放**,只有 Coda 自己和它的客户端调;不写 `permissions` 的定义照旧合法,那时整个协议都不对插件开放。
|
|
216
|
+
|
|
217
|
+
```json
|
|
218
|
+
"permissions": {
|
|
219
|
+
"read": {"title": "读取任务的标题与状态", "read": true, "operations": ["peek"]},
|
|
220
|
+
"start": {"title": "开始一个任务", "operations": ["start"]}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`coda/run@1`、`coda/agent@1`、`coda/session@1`、`coda/environment@1` 的分组如下,都标 `trial`(还不在稳定面里)。`coda/session@1` 的 `draft` 是客户端输入框的击键流,不分组,不对插件开放:
|
|
225
|
+
|
|
226
|
+
| 协议 | 组 | 说明 | 管什么 |
|
|
227
|
+
| --- | --- | --- | --- |
|
|
228
|
+
| `coda/run@1` | `read` | 查看运行的状态与结果 | 读记录 |
|
|
229
|
+
| | `cancel` | 取消正在进行的运行 | `cancel` |
|
|
230
|
+
| `coda/agent@1` | `read` | 查看机器上装着哪些 Agent,以及它们的模型与模式 | 读记录 |
|
|
231
|
+
| | `spawn` | 用 Agent 开一个新会话并交给它任务 | `spawn` |
|
|
232
|
+
| `coda/session@1` | `read` | 读取外部会话的标题、参与者与消息 | 读记录、`read` |
|
|
233
|
+
| | `post` | 以你的身份往外部会话里发消息 | `post` |
|
|
234
|
+
| `coda/environment@1` | `read` | 浏览并读取外部环境里的目录与文件 | 读记录、`list`、`read` |
|
|
235
|
+
|
|
236
|
+
插件申请权限写在清单根的 `uses`(见「插件清单」)。
|
|
237
|
+
|
|
176
238
|
## 插件清单
|
|
177
239
|
|
|
178
240
|
```json
|
|
@@ -201,6 +263,17 @@ invocationResponseProblem(response); // 恰好有 result 或 run 之一
|
|
|
201
263
|
|
|
202
264
|
同一个协议在数组里只能出现一次,写成文本还是对象都算。
|
|
203
265
|
|
|
266
|
+
插件用到别的协议的权限,写在清单根的 `uses`,不放进 `contributes`(Coda 把不认识的 `contributes` 键当扩展点,旧版本会因此拒装)。键是带大版本的协议名,值是权限组名的数组,至少一项、不重复:
|
|
267
|
+
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"id": "my-plugin",
|
|
271
|
+
"uses": {"coda/session@1": ["read"], "coda/environment@1": ["read"]}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
协议名与组名只查写法;协议和组在不在目录里,由 Coda 校验。实现一个协议不用在 `uses` 里申请它。
|
|
276
|
+
|
|
204
277
|
`manifestProblem` 校验清单的外壳与通用键(这两个键在其中);别的键由 Coda 的贡献点登记表或某个插件的扩展点声明,按声明方的 schema 校验,本包不管它们的形状。命名空间约束需要插件 ID,单独用:
|
|
205
278
|
|
|
206
279
|
```js
|
package/package.json
CHANGED
package/protocol.mjs
CHANGED
|
@@ -74,6 +74,26 @@ function schemaProblem(schema, where) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// Permission groups, when written: every group names real operations and streams and covers something, every operation and
|
|
78
|
+
// stream sits in at most one group. An operation or stream in no group is not open to plugins.
|
|
79
|
+
function permissionsProblem({ operations, streams = {}, permissions }, where) {
|
|
80
|
+
if (permissions === undefined) return null;
|
|
81
|
+
const owner = { operations: new Map(), streams: new Map() };
|
|
82
|
+
const things = { operations: ['操作', operations], streams: ['流', streams] };
|
|
83
|
+
for (const [group, entry] of Object.entries(permissions)) {
|
|
84
|
+
for (const key of ['operations', 'streams']) {
|
|
85
|
+
const [label, defined] = things[key];
|
|
86
|
+
for (const name of entry[key] ?? []) {
|
|
87
|
+
if (!Object.hasOwn(defined, name)) return `${where}.permissions.${group}.${key}:没有${label}「${name}」`;
|
|
88
|
+
if (owner[key].has(name)) return `${where}.permissions.${group}.${key}:${label}「${name}」已经属于权限组「${owner[key].get(name)}」,一个${label}只能属于一组`;
|
|
89
|
+
owner[key].set(name, group);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!entry.operations?.length && !entry.streams?.length && entry.read !== true) return `${where}.permissions.${group}:至少管一样东西:写 operations 或 streams,或 read 为 true`;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
// `namespace`: the plugin ID a manifest owns definitions under; omitted for core definitions and standalone checks.
|
|
78
98
|
export function definitionProblem(definition, { namespace = null, where = '协议定义' } = {}) {
|
|
79
99
|
if (!definitionCheck(definition))
|
|
@@ -83,11 +103,14 @@ export function definitionProblem(definition, { namespace = null, where = '协
|
|
|
83
103
|
if (!parsed) return `${where}.name:${NAME_PROBLEM}`;
|
|
84
104
|
if (namespace !== null && parsed.namespace !== namespace)
|
|
85
105
|
return `${where}.name:命名空间须为「${namespace}」,不能在自己的命名空间之外定义协议`;
|
|
106
|
+
const grouping = permissionsProblem(definition, where);
|
|
107
|
+
if (grouping) return grouping;
|
|
86
108
|
const parts = [['spec', definition.spec], ['status', definition.status]];
|
|
87
109
|
for (const [operation, value] of Object.entries(definition.operations)) {
|
|
88
110
|
parts.push([`operations.${operation}.input`, value.input]);
|
|
89
111
|
if (value.result !== undefined) parts.push([`operations.${operation}.result`, value.result]);
|
|
90
112
|
}
|
|
113
|
+
for (const [stream, value] of Object.entries(definition.streams ?? {})) parts.push([`streams.${stream}.input`, value.input]);
|
|
91
114
|
for (const [key, schema] of parts) {
|
|
92
115
|
const problem = schemaProblem(schema, `${where}.${key}`);
|
|
93
116
|
if (problem) return problem;
|
|
@@ -29,6 +29,19 @@
|
|
|
29
29
|
"main": {"description": "插件宿主运行的模块:插件目录里的 .js 或 .mjs 文件", "type": "string", "pattern": "\\.m?js$", "x-file": {"type": "file"}},
|
|
30
30
|
"activationEvents": {"description": "宿主什么时候加载 main:onStartupFinished(后端一启动),不重复", "type": "array", "items": {"enum": ["onStartupFinished"]}, "uniqueItems": true},
|
|
31
31
|
"extensionDependencies": {"description": "需要先装的插件的 ID,不重复", "type": "array", "items": {"$ref": "common.json#/$defs/id"}, "uniqueItems": true},
|
|
32
|
+
"uses": {
|
|
33
|
+
"description": "插件用到的别的协议的权限:协议名(带大版本,如 coda/thread@1)→ 权限组名的数组,至少一项、不重复。没声明的调用被宿主拒绝。放在清单根上而不是 contributes 里:Coda 把 contributes 里不认识的键当扩展点,旧版本会因此拒装。组在不在该协议的定义里由 Coda 对照目录查,这里只管形状",
|
|
34
|
+
"type": "object",
|
|
35
|
+
"maxProperties": 100,
|
|
36
|
+
"propertyNames": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"},
|
|
37
|
+
"additionalProperties": {
|
|
38
|
+
"type": "array",
|
|
39
|
+
"minItems": 1,
|
|
40
|
+
"maxItems": 50,
|
|
41
|
+
"uniqueItems": true,
|
|
42
|
+
"items": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/operationName"}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
32
45
|
"contributes": {
|
|
33
46
|
"description": "插件带来的东西:每个键一种类型。这里只列通用键;其余键由 Coda 的贡献点登记表或某个插件的扩展点声明",
|
|
34
47
|
"type": "object",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://coda.pub/schemas/protocol/v1/definition.json",
|
|
4
4
|
"title": "协议定义",
|
|
5
|
-
"description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。操作可写 timeout
|
|
5
|
+
"description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。操作可写 timeout 给出默认期限。可写 streams 声明只读的记录流;可写 permissions 把操作、流与记录的读取分成权限组,供插件在清单里按组申请。",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"name": {"$ref": "#/$defs/name"},
|
|
@@ -17,6 +17,20 @@
|
|
|
17
17
|
"maxProperties": 50,
|
|
18
18
|
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
19
19
|
"additionalProperties": {"$ref": "#/$defs/operation"}
|
|
20
|
+
},
|
|
21
|
+
"streams": {
|
|
22
|
+
"description": "只读记录流:流名 → 说明与参数。流和操作并列:按记录寻址、只读,返回字节流;参数来自查询串",
|
|
23
|
+
"type": "object",
|
|
24
|
+
"maxProperties": 50,
|
|
25
|
+
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
26
|
+
"additionalProperties": {"$ref": "#/$defs/stream"}
|
|
27
|
+
},
|
|
28
|
+
"permissions": {
|
|
29
|
+
"description": "权限组:组名 → 一组对插件开放的能力。插件在清单的 uses 里按组申请,没申请的调用被宿主拒绝。每个操作、每条流最多属于一组,组里列的操作与流都存在,每组至少管一样东西(有操作、有流,或 read 为真);这些由 definitionProblem 查。不在任何组里的操作和流不对插件开放,只有 Coda 自己和它的客户端调;不写 permissions 就是整个协议都不分组",
|
|
30
|
+
"type": "object",
|
|
31
|
+
"maxProperties": 50,
|
|
32
|
+
"propertyNames": {"$ref": "#/$defs/operationName"},
|
|
33
|
+
"additionalProperties": {"$ref": "#/$defs/permissionGroup"}
|
|
20
34
|
}
|
|
21
35
|
},
|
|
22
36
|
"required": ["name", "spec", "status", "operations"],
|
|
@@ -34,7 +48,7 @@
|
|
|
34
48
|
"pattern": "^[a-z][a-z0-9-]{0,62}$"
|
|
35
49
|
},
|
|
36
50
|
"operationName": {
|
|
37
|
-
"description": "
|
|
51
|
+
"description": "操作名,也是流名与权限组名(协议定义的 streams、permissions 的键、清单 uses 里的组名):小写字母开头,只用小写字母、数字和「-」,不超过 64 个字符",
|
|
38
52
|
"type": "string",
|
|
39
53
|
"pattern": "^[a-z][a-z0-9-]{0,63}$"
|
|
40
54
|
},
|
|
@@ -44,6 +58,29 @@
|
|
|
44
58
|
},
|
|
45
59
|
"title": {"description": "给人看的名字", "type": "string", "maxLength": 100, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
|
|
46
60
|
"description": {"description": "一句话说明", "type": "string", "maxLength": 1000, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
|
|
61
|
+
"permissionGroup": {
|
|
62
|
+
"description": "一个权限组:title 是给用户看的一句话,说这组让插件能做什么;trial 标这组是试行的;operations 是归这组管的操作;streams 是归这组管的流;read 管不管读这个协议的记录(get、list、watch);写记录只许实现方,不分给插件",
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"title": {"$ref": "#/$defs/title"},
|
|
66
|
+
"trial": {"type": "boolean", "description": "是否试行:只影响展示,不影响能否调用"},
|
|
67
|
+
"operations": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的操作名,不重复"},
|
|
68
|
+
"streams": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的流名,不重复"},
|
|
69
|
+
"read": {"type": "boolean", "description": "管不管读这个协议的记录(get、list、watch)"}
|
|
70
|
+
},
|
|
71
|
+
"required": ["title"],
|
|
72
|
+
"additionalProperties": false
|
|
73
|
+
},
|
|
74
|
+
"stream": {
|
|
75
|
+
"description": "只读记录流:input 是参数的 JSON Schema,参数都来自查询串,取值都是字符串;description 是一句话说明",
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"description": {"$ref": "#/$defs/description"},
|
|
79
|
+
"input": {"$ref": "#/$defs/schema"}
|
|
80
|
+
},
|
|
81
|
+
"required": ["input"],
|
|
82
|
+
"additionalProperties": false
|
|
83
|
+
},
|
|
47
84
|
"operation": {
|
|
48
85
|
"description": "操作:input 必有;result 是立即结果的 schema,或写 run: true 表示返回运行引用。两者恰写一个。safe: true、idempotent: true 只能与 result 一起写,两者不同时写(safe 已含 idempotent)。",
|
|
49
86
|
"type": "object",
|
|
@@ -71,5 +71,9 @@
|
|
|
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
73
|
}
|
|
74
|
+
},
|
|
75
|
+
"permissions": {
|
|
76
|
+
"read": {"title": "查看运行的状态与结果", "trial": true, "read": true},
|
|
77
|
+
"cancel": {"title": "取消正在进行的运行", "trial": true, "operations": ["cancel"]}
|
|
74
78
|
}
|
|
75
79
|
}
|