@coda-console/protocol 6.18.0 → 6.19.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 CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.19.0 — 2026-11-21
6
+
7
+ - 这是在 6.18.0 之上的次版本。依据 README「版本」一节:流程方言是内部面,新增字段类型升次版本;`stable/` 不动。
8
+ - 卡片字段新增类型 `operations`(`workflow/fields.json`):一组客户端操作,用户点一下,客户端按顺序在本机执行。属性 `steps`(必写)、`label`(可选)、`id`;显示字段,不进答复,不能写 `required`、`default`。`steps` 是 1–20 项的 JSON 数组(或它的文字,可写表达式在任务打开时读,同 `options`),不超过 32768 字节;每项 `{ op, args?, into? }`,不许别的键。`op` 是小写点分名字,正则 `^[a-z][a-z0-9]*(\.[a-z][a-z0-9-]*)+$`,至多 64 个字符;`args` 是 JSON 对象,值只能是字符串、数字或布尔;`into` 是字段 id 的写法。操作有哪些、怎么执行不进协议,由客户端决定。
9
+ - `workflow/moddle.json` 的 `coda:Field` 加属性 `steps`(String,承载 JSON 文字,同 `view` 的 `args`)。
10
+ - `into` 须指向同一张卡上已声明的 `text` 或 `secret` 字段,且不能指向自己:由协议校验,复用 `x-ref`,写在 `values.json` 的 `UserTask.children`(整卡)里,没有新关键字。目标只认 `text`、`secret`,`operations` 字段自己是 `operations`,所以自然不能指向自己。`steps` 是数组或 JSON 文字都查;表达式或含 `{{ }}` 的 `steps` 定义时不查。读定义时查静态字段,卡上有 `coda:fields` 时留到展开后;`fieldsProblem` 查展开后的整张卡,错误说「ask 的字段 go:步骤的 into 里的 … 不是这个任务的 text 或 secret 字段」(`workflowProblem` 说「… 的 coda:field go:…」)。单独的 `fieldProblem` 只看一个字段,只查 `into` 的写法。
11
+ - `fieldsProblem` 改按整张卡(`{ field: 列表 }`)对 `UserTask.children` 校验,字段 id 重复的说法不变。
12
+ - 字段 `type` 的枚举与说明加上 `operations`。
13
+
5
14
  ## 6.18.0 — 2026-11-20
6
15
 
7
16
  - 这是在 6.17.0 之上的次版本。依据 README「版本」一节:这三个键都不在 `stable/manifest.json`,是内部面,删内部键升次版本;`stable-grows` 与 `test/stable.test.mjs` 不受影响(Coda 宿主设计 coda#2749 H9-C)。
package/README.md CHANGED
@@ -18,10 +18,12 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
18
18
 
19
19
  流程方言的 **勾选项**写在答复(外层的 `coda:choice`)里:`coda:option` 是一项,`coda:optionList` 的 `value` 是一个表达式,任务打开时读出一组勾选项(列表或它的 JSON),在它写的位置展开,两者按写的顺序排。`<coda:options>` 不是它的写法(那个名字是答复自己的勾选项集合)。定义里每个 `coda:optionList` 算一项;打开后的整组由 `workflow/options.json` 定义:每项是 `{ id, name, detail?, default?, inputs? }`(`default` 为布尔值,没有 `shown`),最多 12 项,id 不重复;`inputs` 是勾上这一项时卡片上出现的文字输入,每个 `{ id, label }`,一项最多 4 个、id 不重复,几项带同一个 id 时卡上只出一个。`optionsProblem(options, where)` 检查一个答复打开后的整组(静态项已求值、各组已展开),合法时返回 `null`,否则返回「位置:说明」;表达式求值与展开仍由 Coda 完成。
20
20
 
21
- 流程方言的 **卡片字段**由 `workflow/fields.json` 定义:八种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项、多选的选项表;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
21
+ 流程方言的 **卡片字段**由 `workflow/fields.json` 定义:九种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项、多选的选项表、一组客户端操作;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
22
22
 
23
23
  输入字段有 `text`、`secret` 与多选 `choices`。`choices` 的 `options` 是选项表,每项 `{ id, label, detail?, disabled? }`(`id` 一行、1–64 个字、前后不带空白、表中不重复,`label` 一行、1–80 个字、前后不带空白,`detail` 一行不超过 200 字,`disabled` 为 true 的列出但不能勾),1–32 项,至少一项能勾;`default` 是初始勾上的选项 id,每个须是 options 里能勾的一项,不写就是都不勾;两者都可写表达式在任务打开时读,读出(或直接写下)的是 JSON 数组或它的文字。`required`(默认 true)要求至少勾一项。答复是勾中项的 id 组成的数组,按 options 的顺序,在答复的 `values.<id>` 里(其余输入是文字,它是数组),流程读 `=<任务>.values.<id>`,是 FEEL 列表;它不认识机器或别的什么,选项的意思由给出它的步骤定(如 `check-setting` 的 `machines`)。
24
24
 
25
+ 显示字段(`markdown`、`code`、`image`、`link`、`view`、`operations`)不进答复,不能写 `required`、`default` 之类输入属性。`operations` 是一组客户端操作:卡片上点一下,客户端按顺序在本机执行。`steps` 必写,是 1–20 项的 JSON 数组(或它的文字,可写表达式在任务打开时读),每项 `{ op, args?, into? }`,不许别的键:`op` 是小写点分名字(至少两段,每段小写字母开头,只含小写字母、数字,第二段起可含「-」,如 `space.create`),最长 64 个字符;`args` 是 JSON 对象,值只能是字符串、数字或布尔,不能嵌套对象、数组或 null;`into` 是同一张卡上另一个字段的 id。`steps` 不超过 32768 字节;`label` 可选,是这组操作的标题。操作有哪些、怎么执行由客户端决定,协议只定形状。`into` 须指向同一张卡上已声明的 `text` 或 `secret` 字段,这个字段自己是 `operations`,所以也不会指到自己:用 `x-ref` 在整卡的校验(`values.json` 的 `UserTask.children`)里查,`steps` 是数组或 JSON 文字都一样。读定义时查静态字段(卡上有 `coda:fields` 时不查,那时整张卡还不知道);`fieldsProblem` 查展开后的整张卡,与 `workflowProblem` 说法相同。单独的 `fieldProblem` 只看一个字段,只查 `into` 是字段 id 的写法。
26
+
25
27
  脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在那个目录里就地跑,不检出提交。
26
28
 
27
29
  定义和运行时共用这一份 schema。`x-deferred` 包住一个 schema:读定义时,文字先检查 FEEL,表达式或含 `{{ … }}` 的模板留到打开任务后查;运行时只按包住的 schema 严格检查,不再把结果当表达式。只有内容属性使用它,`type`、`id`、布尔值、枚举和 `maxLength` 不放宽。另有 `x-length`(沿用 Coda 的 UTF-16 长度,可用 `{ "property": "maxLength" }` 读取同一对象的上限)、`x-json`(解析 JSON 文字或检查 JSON 值,按序列化后的 UTF-8 字节数限制大小)、`x-among`(`{ property, key, match? }`:数组的每一项是同一对象里 `property`(数组或它的 JSON 文字)某一项的 `key`,且那一项合乎 `match`;`property` 还是定义里的表达式时不查);`absolute-path`、`https-url`、`link-url` 三个 format 按本机路径与 URL 解析器检查;`link-url` 接受 https 网址或 `action=download-manifest` 且 `url` 解码后为 https 网址的 `itms-services:` 安装链接。已有的 `x-ref` 增加 `key`(按数组元素的属性引用)和 `split`(逐个检查分隔后的名字)。这些操作都不改写输入。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.18.0",
3
+ "version": "6.19.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -5,8 +5,8 @@
5
5
  "description": "字段须为对象",
6
6
  "type": "object",
7
7
  "allOf": [
8
- {"required": ["type"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view、choices"},
9
- {"properties": {"type": {"enum": ["markdown", "code", "image", "text", "secret", "link", "view", "choices"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view、choices"}}},
8
+ {"required": ["type"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view、choices、operations"},
9
+ {"properties": {"type": {"enum": ["markdown", "code", "image", "text", "secret", "link", "view", "choices", "operations"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view、choices、operations"}}},
10
10
  {"if": {"properties": {"type": {"const": "markdown"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/markdown"}},
11
11
  {"if": {"properties": {"type": {"const": "code"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/code"}},
12
12
  {"if": {"properties": {"type": {"const": "image"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/image"}},
@@ -14,7 +14,8 @@
14
14
  {"if": {"properties": {"type": {"const": "secret"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/secret"}},
15
15
  {"if": {"properties": {"type": {"const": "link"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/link"}},
16
16
  {"if": {"properties": {"type": {"const": "view"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/view"}},
17
- {"if": {"properties": {"type": {"const": "choices"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/choices"}}
17
+ {"if": {"properties": {"type": {"const": "choices"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/choices"}},
18
+ {"if": {"properties": {"type": {"const": "operations"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/operations"}}
18
19
  ],
19
20
  "$defs": {
20
21
  "markdown": {
@@ -273,6 +274,62 @@
273
274
  {"required": ["options"], "description": "须写 options"}
274
275
  ]
275
276
  },
277
+ "operations": {
278
+ "$comment": "一组客户端操作:卡片上显示为一个按钮,用户点一下,客户端按顺序在本机执行 steps。操作有哪些、怎么执行由客户端决定,协议只定形状;显示字段,不进答复。into 须是同一张卡上的 text 或 secret 字段的 id(也就不会是这个字段自己);单个字段读不到整张卡,这一条由 values.json 的 UserTask.children 查。",
279
+ "allOf": [
280
+ {
281
+ "type": "object",
282
+ "properties": {
283
+ "type": {"const": "operations"},
284
+ "id": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/id"},
285
+ "label": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/label"},
286
+ "steps": {
287
+ "x-deferred": {
288
+ "x-json": {
289
+ "schema": {
290
+ "description": "steps 须为不超过 32768 字节的 JSON 数组",
291
+ "allOf": [
292
+ {"type": "array", "description": "steps 须为步骤的 JSON 数组"},
293
+ {"minItems": 1, "maxItems": 20, "description": "steps 须有 1–20 个步骤"},
294
+ {
295
+ "items": {
296
+ "type": "object",
297
+ "properties": {
298
+ "op": {
299
+ "type": "string",
300
+ "pattern": "^[a-z][a-z0-9]*(\\.[a-z][a-z0-9-]*)+$",
301
+ "x-length": 64,
302
+ "description": "步骤的 op 须为小写点分名字(至少两段,每段小写字母开头,只含小写字母、数字,第二段起可含「-」),最长 64 个字符"
303
+ },
304
+ "args": {
305
+ "type": "object",
306
+ "additionalProperties": {"type": ["string", "number", "boolean"], "description": "步骤的 args 的值只能是字符串、数字或布尔"},
307
+ "description": "步骤的 args 须为 JSON 对象"
308
+ },
309
+ "into": {
310
+ "type": "string",
311
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$",
312
+ "description": "步骤的 into 须为字段 id(字母或数字开头的字母、数字、「_」「-」,最长 40 个字符)"
313
+ }
314
+ },
315
+ "required": ["op"],
316
+ "additionalProperties": false,
317
+ "description": "步骤须为对象,有 op,可有 args 与 into"
318
+ }
319
+ }
320
+ ]
321
+ },
322
+ "maxBytes": 32768
323
+ },
324
+ "description": "steps 须为步骤的 JSON 数组"
325
+ }
326
+ }
327
+ },
328
+ "additionalProperties": false
329
+ },
330
+ {"required": ["steps"], "description": "须写 steps"}
331
+ ]
332
+ },
276
333
  "id": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$", "description": "须有 id(字母或数字开头的字母、数字、「_」「-」,最长 40 个字符)"},
277
334
  "label": {"x-deferred": {"type": "string", "pattern": "^\\s*\\S(?:[^\\r\\n]*\\S)?\\s*$", "x-length": 40, "description": "label 须为一行、1–40 个字"}},
278
335
  "required": {"type": "boolean", "description": "required 须为 true 或 false", "default": true},
@@ -228,6 +228,7 @@
228
228
  {"name": "plugin", "isAttr": true, "type": "String"},
229
229
  {"name": "view", "isAttr": true, "type": "String"},
230
230
  {"name": "args", "isAttr": true, "type": "String"},
231
+ {"name": "steps", "isAttr": true, "type": "String"},
231
232
  {"name": "presentation", "isAttr": true, "type": "String"},
232
233
  {"name": "options", "isAttr": true, "type": "String"},
233
234
  {"name": "default", "isAttr": true, "type": "String"},
@@ -214,6 +214,42 @@
214
214
  "if": {"not": {"properties": {"fields": {"minItems": 1}}, "required": ["fields"]}},
215
215
  "then": {
216
216
  "properties": {
217
+ "field": {
218
+ "items": {
219
+ "if": {"properties": {"type": {"const": "operations"}}, "required": ["type"]},
220
+ "then": {
221
+ "if": {"properties": {"steps": {"x-json": {"schema": true, "maxBytes": 32768}}}, "required": ["steps"]},
222
+ "then": {
223
+ "properties": {
224
+ "steps": {
225
+ "x-deferred": {
226
+ "x-json": {
227
+ "schema": {
228
+ "items": {
229
+ "properties": {
230
+ "into": {
231
+ "if": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$"},
232
+ "then": {
233
+ "x-ref": {
234
+ "pointer": "4",
235
+ "key": "id",
236
+ "match": {"type": "object", "required": ["type"], "properties": {"type": {"enum": ["text", "secret"]}}}
237
+ },
238
+ "description": "步骤的 into 里的 {value} 不是这个任务的 text 或 secret 字段"
239
+ }
240
+ }
241
+ }
242
+ }
243
+ },
244
+ "maxBytes": 32768
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ },
217
253
  "choice": {
218
254
  "items": {
219
255
  "allOf": [
package/workflow.mjs CHANGED
@@ -191,8 +191,14 @@ export function fieldsProblem(list, where = '任务') {
191
191
  const problem = fieldProblem(field, `${where} 的字段 ${typeof field?.id === 'string' ? field.id : index + 1}`);
192
192
  if (problem) return problem;
193
193
  }
194
- const validate = ajv.getSchema(`${values.$id}#/$defs/UserTask.children/properties/field`);
195
- return validate(list) ? null : `${where}:字段 id 重复:${validate.errors[0].message.slice('id 不能重复:'.length)}`;
194
+ const validate = ajv.getSchema(`${values.$id}#/$defs/UserTask.children`);
195
+ if (validate({ field: list })) return null;
196
+ const error = validate.errors[0];
197
+ if (error.keyword === 'x-ref') {
198
+ const index = Number(error.instancePath.split('/')[2]), id = list[index].id;
199
+ return `${where} 的字段 ${typeof id === 'string' ? id : index + 1}:${description(error)}`;
200
+ }
201
+ return `${where}:字段 id 重复:${error.message.slice('id 不能重复:'.length)}`;
196
202
  }
197
203
  // One answer's options as the task opens: the static ones resolved and each coda:optionList read and put where it is
198
204
  // written, in order. Each is an object of id, name and optionally detail and a boolean default; at most 12, ids unique.
@@ -247,9 +253,14 @@ function valuesProblem(root) {
247
253
  let problem = failed(validate, grouped, at, false);
248
254
  if (problem && validate.errors[0].keyword === 'x-ref') {
249
255
  const error = validate.errors[0], path = error.instancePath.split('/').slice(1);
250
- let parent = grouped;
251
- for (const key of path.slice(0, -1)) parent = parent[key];
252
- problem = `${at} 的 coda:choice ${parent.id}:${description(error)}`;
256
+ if (path[0] === 'field') {
257
+ const id = grouped.field[path[1]].id;
258
+ problem = `${at} 的 coda:field${id ? ` ${id}` : ''}:${description(error)}`;
259
+ } else {
260
+ let parent = grouped;
261
+ for (const key of path.slice(0, -1)) parent = parent[key];
262
+ problem = `${at} 的 coda:choice ${parent.id}:${description(error)}`;
263
+ }
253
264
  }
254
265
  if (problem && validate.errors[0].keyword === 'x-unique-by' && validate.errors[0].instancePath === '/field')
255
266
  problem = `${at}:字段 id 重复:${validate.errors[0].message.slice('id 不能重复:'.length)}`;