@coda-console/protocol 6.26.0 → 6.27.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 +8 -0
- package/README.md +3 -3
- package/docs/protocol.md +6 -0
- package/package.json +1 -1
- package/plugin.d.mts +11 -0
- package/schemas/plugin/optional-protocol-implementations.json +10 -0
- package/schemas/plugin/plugin.json +2 -0
- package/schemas/plugin/reserved-accord-kinds.json +13 -0
- package/validate.mjs +18 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.27.0 — 2026-11-24
|
|
6
|
+
|
|
7
|
+
- 这是在 6.26.0 之上的次版本。依据 README「版本」一节:新增可选的清单键升次版本;这两个键暂不进稳定面,`stable/` 不动,旧清单不受影响(没写这两个键的清单照旧合法)。
|
|
8
|
+
- `contributes` 加两个可选键,各有一份 schema:`optionalProtocolImplementations`(`schemas/plugin/optional-protocol-implementations.json`)是可选实现的协议名数组,每项同 `protocolImplementations` 的文本项,不收 `{ kind, commands }`,至多 100 项、不重复;协议本机没有时插件照常运行、这一项不生效。`reservedAccordKinds`(`schemas/plugin/reserved-accord-kinds.json`)是只归本插件的 Accord 签名记录种类数组,每项匹配 `^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$`(命名空间必带),至多 32 项、不重复;只有本插件能直接发布、撤回、读这些种类。
|
|
9
|
+
- 两条跨键规则,由 `validate.mjs` 的 `manifestProblem` 在整份清单的 schema 通过后用代码查(没有新增 schema 关键字,两个键的 schema 文件单独用时只校验形状):`optionalProtocolImplementations` 的每项不能已在 `protocolImplementations` 里(文本项或对象项的 `kind` 都算);`reservedAccordKinds` 每项的命名空间须等于清单的 `id`(没写 `id` 用 `name`)。报错说明是哪个键、哪一项。`TYPES` 随之多这两个键。
|
|
10
|
+
- `./types`(`plugin.d.mts`)新增导出 `ManifestContributions`,只含这两个可选键;清单的其余键还没有类型。
|
|
11
|
+
- 协议包只校验形状;协议在不在、这一项生不生效、谁被拒绝由 Coda 宿主判定。
|
|
12
|
+
|
|
5
13
|
## 6.26.0 — 2026-11-24
|
|
6
14
|
|
|
7
15
|
- 这是在 6.25.0 之上的次版本。依据 README「版本」一节:流程方言与 Agent 接入协议是内部面,只加可选属性与约定,升次版本;`stable/` 不动,清单 schema 没改。6.25.0 下合法的流程仍合法。
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
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`、`services`、`setup`、`environment`、`path`、`views`、`protocols`、`protocolImplementations`、`records`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
|
|
6
|
-
- **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema
|
|
5
|
+
- **插件清单的类型**(`schemas/plugin/`):插件目录 `package.json` 里 `contributes` 的每个键是一种类型,各有一份 JSON Schema(draft 2020-12,`$id` 为 `https://coda.pub/schemas/plugin/v2/<文件>`)。`plugin.json` 是整份清单,只列通用键(`configuration`、`services`、`setup`、`environment`、`path`、`views`、`protocols`、`protocolImplementations`、`optionalProtocolImplementations`、`reservedAccordKinds`、`records`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
|
|
6
|
+
- **通用校验器**(`validate.mjs`):用 Ajv 对清单做 schema 校验。JSON Schema 说不了的只用五个通用关键字(`x-unique-by`、`x-max-contains`、`x-ref`、`x-placeholders`、`x-file`,照 Kubernetes 的 `x-kubernetes-*`),每个在哪里写都是同一个意思,写法见文件开头。校验器不随功能变长:类型加字段就是改 schema。例外是清单级的两条跨字段约束:`manifestProblem` 在 schema 通过后还会检查,同一协议不能既是必需实现(`protocolImplementations`)又是可选实现(`optionalProtocolImplementations`),保留种类(`reservedAccordKinds`)的命名空间须等于插件 ID;只拿 `plugin.json` 校验,只查形状,这两条不在内。
|
|
7
7
|
- **协议定义与调用**(`schemas/protocol/`、`protocol.mjs`、`docs/protocol.md`):协议是 `命名空间/名字@大版本` + spec/status 的 JSON Schema + 操作;插件在 `contributes.protocols` 里定义自己命名空间下的协议,在 `contributes.protocolImplementations` 里声明实现哪些协议;定义可写 `streams` 声明记录流(读、写、原样 HTTP 三种形状,字节或帧),可写 `events` 声明事件(载荷格式与 `starts`、`ends`;只有事件的协议可以不写 `spec`、`status`、`operations`,`protocolHasRecords` 判断一份定义有没有记录),可写 `permissions` 把操作、流、事件与记录的读取分成权限组,插件在清单根的 `uses`(必需)或 `optionalUses`(可选)里按组申请。调用是 `{ 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`、执行失败、工具调用的审核、配置探测)。
|
|
@@ -170,7 +170,7 @@ agentValueProblem('review.json', review, '工具的审核');
|
|
|
170
170
|
## 协议定义与核心协议
|
|
171
171
|
|
|
172
172
|
从 3.0.0 起,协议是 `命名空间/名字@大版本` + 记录格式(spec、status 的 JSON Schema)+ 操作,见[协议正文](docs/protocol.md)。
|
|
173
|
-
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda
|
|
173
|
+
插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责);`contributes.optionalProtocolImplementations` 列可选实现的协议(本机没有这个协议时插件照常运行、这一项不生效),`contributes.reservedAccordKinds` 声明只归本插件的 Accord 签名记录种类(命名空间须是插件 ID);这两个键协议包只校验形状与两条跨键规则(可选实现不与 `protocolImplementations` 重复、保留种类的命名空间等于插件 ID),协议在不在、谁被拒绝由 Coda 宿主判定;
|
|
174
174
|
命名空间 `coda` 保留给核心协议。
|
|
175
175
|
|
|
176
176
|
- **`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`。
|
package/docs/protocol.md
CHANGED
|
@@ -358,6 +358,12 @@ const body = writeFrames(frames, { heartbeatMs: 15000 });
|
|
|
358
358
|
|
|
359
359
|
同一个协议在数组里只能出现一次,写成文本还是对象都算。
|
|
360
360
|
|
|
361
|
+
`contributes.optionalProtocolImplementations` 是插件可选实现的协议列表:协议名的数组,至多 100 项、不重复,只收文本,不收 `{ kind, commands }`。这些协议本机没有时,插件照常运行,只是这一项不生效;同一个协议不能既写在这里又写在 `protocolImplementations` 里(文本项、对象项的 `kind` 都算)。
|
|
362
|
+
|
|
363
|
+
`contributes.reservedAccordKinds` 声明哪几种 Accord 签名记录(AIP-01)的种类只归本插件:「命名空间/名字」的数组,至多 32 项、不重复,每项须匹配 `^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$`(比 Accord 的种类规则少了可选的命名空间:必须带),命名空间须等于插件 ID(没写 `id` 时用 `name`)。只有本插件能直接发布、撤回、读这些种类。
|
|
364
|
+
|
|
365
|
+
这两个键协议包只校验形状与上面两条跨键规则;协议在不在、这一项生不生效、谁被拒绝由 Coda 宿主判定。
|
|
366
|
+
|
|
361
367
|
`contributes.records` 声明哪些种类的记录由命令给出,每种一项,至多 20 项:
|
|
362
368
|
|
|
363
369
|
```json
|
package/package.json
CHANGED
package/plugin.d.mts
CHANGED
|
@@ -423,3 +423,14 @@ export interface ViewInstance {
|
|
|
423
423
|
onContext(fn: (context: ViewInstance['context']) => void): Disposable;
|
|
424
424
|
onClose(fn: () => void): Disposable;
|
|
425
425
|
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The keys of the manifest's `contributes` that are typed here: only these two so far, the rest of the manifest has no type
|
|
429
|
+
* here yet. Their shape is checked by `schemas/plugin/`; whether a protocol is on this machine and who is refused is the host's.
|
|
430
|
+
*/
|
|
431
|
+
export interface ManifestContributions {
|
|
432
|
+
/** Protocols the plugin implements if they are on this machine (`namespace/name@major`); with one absent the plugin still runs, only that implementation does not take effect. */
|
|
433
|
+
optionalProtocolImplementations?: string[];
|
|
434
|
+
/** Accord signature record kinds (`namespace/name`, the namespace the plugin's own ID) that only this plugin may publish, revoke or read. */
|
|
435
|
+
reservedAccordKinds?: string[];
|
|
436
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/optional-protocol-implementations.json",
|
|
4
|
+
"title": "contributes.optionalProtocolImplementations:插件可选实现的协议",
|
|
5
|
+
"description": "插件可选实现哪些协议,写协议名「命名空间/名字@大版本」的数组,至多 100 项,不重复,只收文本、不收 { kind, commands }。这些协议本机没有时,插件照常运行,只是这一项不生效;协议在不在、这一项生不生效由 Coda 宿主判定,这里只管清单形状。同一个协议不能同时写在 protocolImplementations 里,这条跨键规则由整份清单的校验(manifestProblem)查。",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"maxItems": 100,
|
|
8
|
+
"uniqueItems": true,
|
|
9
|
+
"items": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"}
|
|
10
|
+
}
|
|
@@ -73,6 +73,8 @@
|
|
|
73
73
|
"views": {"$ref": "views.json"},
|
|
74
74
|
"protocols": {"$ref": "protocols.json"},
|
|
75
75
|
"protocolImplementations": {"$ref": "protocol-implementations.json"},
|
|
76
|
+
"optionalProtocolImplementations": {"$ref": "optional-protocol-implementations.json"},
|
|
77
|
+
"reservedAccordKinds": {"$ref": "reserved-accord-kinds.json"},
|
|
76
78
|
"records": {"$ref": "records.json"}
|
|
77
79
|
},
|
|
78
80
|
"propertyNames": {"description": "contributes 的键:字母和数字,以小写字母开头", "pattern": "^[a-z][A-Za-z0-9]{0,39}$"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schemas/plugin/v2/reserved-accord-kinds.json",
|
|
4
|
+
"title": "contributes.reservedAccordKinds:只归本插件的 Accord 签名记录种类",
|
|
5
|
+
"description": "插件声明哪几种 Accord 签名记录(AIP-01)的种类只归自己,写「命名空间/名字」的数组,至多 32 项,不重复;命名空间必须带,名字与命名空间都是小写字母、数字和「-」,各至多 64 个字符。只有本插件能直接发布、撤回、读这些种类;谁被拒绝由 Coda 宿主判定,这里只管清单形状。命名空间须是本插件的 ID,这条跨键规则由整份清单的校验(manifestProblem)查。",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"maxItems": 32,
|
|
8
|
+
"uniqueItems": true,
|
|
9
|
+
"items": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"pattern": "^[a-z0-9-]{1,64}/[a-z0-9-]{1,64}$"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/validate.mjs
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// JSON Schema of its own. The manifest's schema names only the general ones (schemas/plugin/,
|
|
3
3
|
// `https://coda.pub/schemas/plugin/v2/…`); every other key is one Coda's registry of contribution points declares, with a
|
|
4
4
|
// schema of its provider's (those of Coda's own still kept here, by file). Checking one is checking it against those
|
|
5
|
-
// schemas, nothing else: a field joins a type by joining its schema, never by a rule here
|
|
5
|
+
// schemas, nothing else: a field joins a type by joining its schema, never by a rule here, but for two
|
|
6
|
+
// rules across a manifest's keys: after the schema, `manifestProblem` checks that a protocol is not both implemented and optionally
|
|
7
|
+
// implemented, and that a reserved Accord kind is in the plugin's own namespace, its ID; checked against plugin.json alone, a
|
|
8
|
+
// manifest is checked for its shape only. Coda checks a plugin with this
|
|
6
9
|
// module when it reads one, and coda-plugins' contract check does where a plugin is written.
|
|
7
10
|
// What JSON Schema cannot say of one value alone it says with five keywords, each meaning one thing wherever it is written,
|
|
8
11
|
// as Kubernetes extends its OpenAPI with `x-kubernetes-*`:
|
|
@@ -311,7 +314,20 @@ export function explain(errors, base = '', schemas = [], { style = 'keyword', re
|
|
|
311
314
|
// A manifest checked against its schema, the files it names in `dir` when given. Returns null, or what is wrong.
|
|
312
315
|
export function manifestProblem(manifest, dir = null) {
|
|
313
316
|
const validate = validator('plugin.json');
|
|
314
|
-
return validate.call({ dir }, manifest) ?
|
|
317
|
+
return validate.call({ dir }, manifest) ? crossKeyProblem(manifest) : explain(validate.errors, '', [PROTOCOL_DEFINITION]);
|
|
318
|
+
}
|
|
319
|
+
// What the manifest's schema cannot say of one key alone, as its keys stand to each other; the shapes are right by now.
|
|
320
|
+
// An optional implementation is none that is implemented already (a text, or the `kind` of an object); a reserved Accord kind
|
|
321
|
+
// is in the plugin's own namespace, the plugin's `id` (its `name` when it has none).
|
|
322
|
+
function crossKeyProblem({ id, name, contributes }) {
|
|
323
|
+
const { protocolImplementations = [], optionalProtocolImplementations = [], reservedAccordKinds = [] } = contributes ?? {};
|
|
324
|
+
const implemented = new Set(protocolImplementations.map(item => typeof item === 'string' ? item : item.kind));
|
|
325
|
+
const twice = optionalProtocolImplementations.findIndex(kind => implemented.has(kind));
|
|
326
|
+
if (twice !== -1) return `contributes.optionalProtocolImplementations[${twice}]:已写在 protocolImplementations 里,不能再写:${optionalProtocolImplementations[twice]}`;
|
|
327
|
+
const owner = id ?? name;
|
|
328
|
+
const other = reservedAccordKinds.findIndex(kind => kind.split('/')[0] !== owner);
|
|
329
|
+
if (other === -1) return null;
|
|
330
|
+
return `contributes.reservedAccordKinds[${other}]:${owner === undefined ? '须先写插件的 id 或 name' : `命名空间须是本插件的 ID「${owner}」`}:${reservedAccordKinds[other]}`;
|
|
315
331
|
}
|
|
316
332
|
// A value checked against one of the schemas (`ref`: a file, with a fragment, as `composer-modes.json#/$defs/parameters`),
|
|
317
333
|
// as a plugin gives it while it runs: null, or what is wrong, at `where`.
|