@coda-console/protocol 6.0.0 → 6.2.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 +13 -0
- package/README.md +4 -2
- package/docs/agent-protocol.md +36 -4
- package/package.json +1 -1
- package/schemas/agent/failure.json +42 -9
- package/workflow/actions.json +7 -6
- package/workflow/fields.json +73 -3
- package/workflow/keywords.mjs +29 -1
- package/workflow/moddle.json +1 -0
- package/workflow/structure.json +3 -2
- package/workflow/values.json +2 -2
- package/workflow.mjs +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 6.2.0 — 2026-11-14
|
|
6
|
+
|
|
7
|
+
- Agent 的执行失败类别(`schemas/agent/failure.json`)加 `kind: auth_required`:Agent 的登录凭据失效(OAuth 令牌过期或被撤销),须用户重新登录才能继续;可带可选的 `login`(1 到 200 字,指出要重新登录的账号或登录方式),不带 `input`、`retryAfterMs`、`resetAt`,带了也不检查。`docs/agent-protocol.md` 的「执行失败」写清三类的用途:`service_unavailable` 会自己好,Coda 退避后在同一会话续;`quota_exhausted` 到恢复时间再续;`auth_required` 提醒用户重新登录,登录后续;额度不足与要重新登录两类本轮内不即时重试、也不进入服务故障重试,之后的续跑由 Coda 在同一会话里决定;并写明什么时候该报它、什么时候不该报(API key 配错、权限不足仍是普通错误)。握手阶段回 -32000 的「未登录」不变。新增类别与可选字段,旧插件不受影响(Coda #2642)。
|
|
8
|
+
- 额度不足(`kind: quota_exhausted`)可带可选的 `input`(`accepted` 或 `not_accepted`),含义与何时报同 `service_unavailable`(`accepted` 是输入已经进入原生会话,`not_accepted` 是明确拒绝、输入尚未进入原生会话,无法确定就省略);写了就校验取值,写别的值校验不过。Coda 只用它决定续跑时发什么(`not_accepted` 重发原输入,`accepted` 接着做,没报按不确定处理:带上原输入、先核对再接着做),不会因它进入服务故障重试;`retryAfterMs` 仍不采用。可选字段,旧发送端可不写、旧接收端可忽略。
|
|
9
|
+
- 动作 `send-session` 加可选参数 `resumes`(要续跑的那条输入的 ID,须是 `session` 指定的会话、不写就是运行所属的会话里的输入)与 `how`(`original` 原样重发那条输入的完整内容,`verify` 先核对已经做了什么、再接着做,同样带上完整内容;只写 `resumes` 时按 `original`):写了 `resumes` 时 `text` 只是存在会话里给人看的一句短说明,发给 Agent 的是那条输入的完整内容(附件、引用都在),不再抄成一条新消息的文字(Coda quota-resume 流程)。`actions.json` 的动作加两种约束:`requires`(写了某参数就须写它列出的参数)与 `enum`(某参数写成文字时的取值,表达式与 `{{ … }}` 不查),读流程时检查:`how` 须与 `resumes` 一起写,且只能是 `original` 或 `verify`;`resumes` 是否这个会话里的输入由实现方在运行时检查。只加参数与约束,已有流程不变。
|
|
10
|
+
|
|
11
|
+
## 6.1.0 — 2026-11-14
|
|
12
|
+
|
|
13
|
+
- 卡片字段加多选 `choices`(输入字段,须有 `id`、`label`,`required` 默认 true,表示至少勾一项):`options` 是选项表,`default` 是初始勾上的选项 id,两者都是内容属性,可写表达式在任务打开时读,读出(或写下)的是 JSON 数组或它的文字。选项 `{ id, label, detail?, disabled? }`:`id` 一行、1–64 个字、前后不带空白、表中不重复,`label` 一行、1–80 个字、前后不带空白,`detail` 一行不超过 200 字,`disabled` 为 true 的列出但不能勾;1–32 项,至少一项能勾。`default` 的 id 不重复,每个须是 options 里能勾的一项(两者都已知时读流程就查)。答复是勾中项的 id 组成的数组,按 options 的顺序,在 `answer.values.<id>` 里交来,流程读 `=<任务>.values.<id>`(FEEL 列表),`filled.<id>` 为勾了至少一项。choices 是输入字段:答复的 `fields` 可以引用它,带它的任务只交给用户(`structure.json` 的 `inputFields` 加上它)。moddle 的 `coda:field` 加属性 `options`。
|
|
14
|
+
- 值的关键字加 `x-among`(`{ property, key, match? }`):数组的每一项是同一对象里 `property`(数组或它的 JSON 文字)某一项的 `key`,且那一项合乎 `match`;`property` 还没读出(定义里的表达式)时不查。
|
|
15
|
+
- 动作 `check-setting` 加参数 `machines`(建议写入的机器:空间里机器的 ID 或名字,JSON 数组或逗号分隔;不写时是空间里装了这个插件的每一台,不在空间里时是本机,写了 `project` 时只有目录所在的那台);`valid` 加输出 `machines`(choices 字段的 options:各台,`id` 为机器 ID,离线、不合法的在 `detail` 写明,不合法的 `disabled`)与 `selected`(choices 字段的 default),`before` 改为各台这一层的现值,值相同的合成一份,`after` 仍是一个。`apply-setting` 写到卡片最后一个 choices 字段勾中的各台(卡片没有 choices 字段时同 6.0,只写本机或目录所在的那台),逐台写、部分成功保留、不重试,加输出 `results`(逐台 `machine`、`name`、`result` 为 `written`、`offline`、`not-installed`、`refused` 或 `failed`,以及 `reason` 或 `layer`、`value`)、`written`、`failed`;`layer`、`value` 照旧,为第一台写成的那台的。参数与输出都只加不改,已有流程不变(Coda 内置能力 change-setting 写到多台)。
|
|
16
|
+
- 有输入字段的任务只交给用户这条报错的末尾加「(choices 字段也是输入字段)」,前面的说法不变。
|
|
17
|
+
|
|
5
18
|
## 6.0.0 — 2026-11-14
|
|
6
19
|
|
|
7
20
|
- 不兼容:流程方言删去流程种类,流程只靠挂点(`<coda:join hook=…/>`)互相找到,「只运行已合并的提交」只由 `coda:mergedOnly` 声明。删去流程属性 `coda:kind` 与 `coda:deploy`(moddle 与 `values.json` 里都没有了,写了的流程读时按认不出的属性拒绝);`dialect.json` 删去 `kinds` 与 `deploying`,`workflow.mjs` 不再导出 `WORKFLOW_KINDS`、`DEPLOYING_KINDS`;删去动作 `workflow-kinds`;`run-workflows` 删去参数 `kind`,`hook` 必写(`actions.json` 的动作加 `required`,读流程时没写的报「须写参数」);设置的 `items.anyOf` 选项删去 `workflowKind`,写了的清单校验不过(Coda #2521 第 5 步)。
|
package/README.md
CHANGED
|
@@ -18,11 +18,13 @@ 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`
|
|
21
|
+
流程方言的 **卡片字段**由 `workflow/fields.json` 定义:八种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项、多选的选项表;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
|
|
22
|
+
|
|
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`)。
|
|
22
24
|
|
|
23
25
|
脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在本机跑就在那个目录里就地跑,不检出提交;交给别的执行环境时,由调用方给这个目录所在的工作副本拍快照(含未提交、未跟踪的改动,不含忽略的文件),对方检出快照、在对应的子目录里跑。协议里 `coda/executor@1` 的 `execute` 输入已有 `source.snapshot` 与 `workingDirectory`,交给别台时就用这两项,执行器协议本身不改。
|
|
24
26
|
|
|
25
|
-
定义和运行时共用这一份 schema。`x-deferred` 包住一个 schema:读定义时,文字先检查 FEEL,表达式或含 `{{ … }}` 的模板留到打开任务后查;运行时只按包住的 schema 严格检查,不再把结果当表达式。只有内容属性使用它,`type`、`id`、布尔值、枚举和 `maxLength` 不放宽。另有 `x-length`(沿用 Coda 的 UTF-16 长度,可用 `{ "property": "maxLength" }` 读取同一对象的上限)、`x-json`(解析 JSON 文字或检查 JSON 值,按序列化后的 UTF-8
|
|
27
|
+
定义和运行时共用这一份 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`(逐个检查分隔后的名字)。这些操作都不改写输入。
|
|
26
28
|
|
|
27
29
|
`fieldProblem(field, where)` 检查一个已求值的字段;`fieldsProblem(fields, where)` 检查展开并应用 `host`/`dir` 后的数组,复用同一份字段 schema、数量和唯一性规则。两者合法时返回 `null`,否则返回「位置:说明」;`where` 是调用方给出的完整位置。schema 的 `default` 仅作标注:默认值填充、去空白、域名转小写、`args` 解析后的保留、表达式求值、动态字段展开和用户答复的处理仍由 Coda 完成。`coda:fields` 的 `host`/`dir` 是可能被覆盖或忽略的备用值,定义时只检查 FEEL,合并后才检查实际字段。动态字段展开后,答复的输入引用仍须由 Coda 检查。
|
|
28
30
|
|
package/docs/agent-protocol.md
CHANGED
|
@@ -44,7 +44,7 @@ Coda 过去静默丢弃的值,契约检查现在可得到具体位置;过去
|
|
|
44
44
|
不把原始输入拼入错误(避免巨大值或深层对象导致报错本身失败)。
|
|
45
45
|
|
|
46
46
|
**校验不是整理或运行状态判断**:审核未知 `risk` 不影响整条审核有效,宿主仍只保存 `$defs/risk` 接受的值;
|
|
47
|
-
额度不足按 `kind` 判断,可选的 `resetAt` 须符合下文的 UTC
|
|
47
|
+
额度不足按 `kind` 判断,可选的 `resetAt` 须符合下文的 UTC 时间格式,可选的 `input` 须是 `accepted` 或 `not_accepted`,不校验也不采用它附带的 `retryAfterMs`;压缩答复的未知字段照样允许,
|
|
48
48
|
宿主仍只保存已知字段、裁剪原因,畸形答复仍按原有兜底处理,不应把整个答复的校验失败改成执行失败。
|
|
49
49
|
压缩的 `before`/`after` 沿用有限数要求,不新增整数或非负限制。能力声明 schema 描述对象声明,
|
|
50
50
|
不代替能力探测:未声明、不合法的声明仍按宿主原有方式处理(旧 `supportsRemote` 还把数组视为声明,不能直接用 schema 替换该谓词)。
|
|
@@ -155,16 +155,30 @@ Coda 使用的形状见 [steering.json](../schemas/agent/steering.json);`promp
|
|
|
155
155
|
`session/prompt` 的 JSON-RPC 错误通过 `error.data._meta.coda.failure` 报告类别。标准 `error.message` 保留可读的失败原因;
|
|
156
156
|
其他 ACP 客户端可以忽略扩展。未标记、未知或不合格式的类别按普通错误处理,不自动重试。
|
|
157
157
|
|
|
158
|
+
三个类别说的是故障的性质,Coda 据此决定怎么恢复:
|
|
159
|
+
|
|
160
|
+
| 类别 | 性质 | Coda 的恢复 |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| `service_unavailable` | 服务端暂时故障,会自己好 | 退避后在同一会话续 |
|
|
163
|
+
| `quota_exhausted` | 额度用尽,要等重置或补额度 | 到恢复时间再续 |
|
|
164
|
+
| `auth_required` | 登录凭据失效,要用户重新登录 | 提醒用户重新登录,登录后续 |
|
|
165
|
+
|
|
166
|
+
责任分两段。本轮内:插件报类别并结束本轮;额度不足、要重新登录两类不即时重试,也不进入服务故障重试,服务暂不可用才按下文在本轮内即时重试。
|
|
167
|
+
之后:由 Coda(发起这次工作的一方)决定什么时候续、怎么续,在同一会话里续;服务暂不可用重试用尽后同样如此。协议只约定插件报什么、本轮怎么结束。
|
|
168
|
+
|
|
158
169
|
### 额度不足
|
|
159
170
|
|
|
160
171
|
`kind: quota_exhausted` 表示可用额度已耗尽,例如订阅用量窗口已满或余额不足。插件须有明确的上游原因,不能仅凭 HTTP 403、
|
|
161
|
-
HTTP 429
|
|
172
|
+
HTTP 429 或上游的认证错误分类判断。认证失败按[需要重新登录](#需要重新登录)或握手阶段的 ACP `auth_required` 报告,不得报为额度不足。
|
|
162
173
|
|
|
163
174
|
```json
|
|
164
175
|
{"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"当前用量窗口的额度已耗尽,<t:2026-10-24T18:10:00.000Z> 重置","data":{"_meta":{"coda":{"failure":{"kind":"quota_exhausted","resetAt":"2026-10-24T18:10:00.000Z"}}}}}}
|
|
165
176
|
```
|
|
166
177
|
|
|
167
|
-
Coda
|
|
178
|
+
Coda 按该类别显示「额度不足」,保留完整原因;本轮内不即时重试,也不进入服务故障重试,之后由 Coda 到 `resetAt` 在同一会话续(没有 `resetAt` 时按 Coda 自己的间隔再试)。
|
|
179
|
+
可选 `input`(`accepted` 或 `not_accepted`)含义与何时报沿用[服务暂不可用](#服务暂不可用)里 `input: accepted`、`input: not_accepted` 的定义:`accepted` 是输入已经进入原生会话;`not_accepted` 是明确拒绝,输入尚未进入原生会话;无法确定就省略。
|
|
180
|
+
Coda 只用它决定续跑时发什么——`not_accepted` 重发原输入,`accepted` 从已有进度接着做,没报则按「不确定」处理,带上原输入、先核对已经做了什么再接着做;
|
|
181
|
+
它不会让额度不足进入服务故障重试。`retryAfterMs` 不采用。
|
|
168
182
|
该回执确认本轮因额度不足而结束,轮次记为 `ended`、`stopReason: quota_exhausted` 并保留 `error`,操作记为 `completed`;
|
|
169
183
|
操作已结算不代表任务成功,子会话向调用方交回 `failed`。两端同一原因只显示一次,不再标作「执行结果未知」。
|
|
170
184
|
交回 `failed` 的状态文案为「失败」,涵盖准备与执行阶段。调用结清前,后续轮次的额度错误仍连同原因算进这次调用的结果,即使没有正文或还有其他活动在等;结清后不再另交。
|
|
@@ -174,6 +188,24 @@ Coda 按该类别显示「额度不足」,保留完整原因,不安排自动
|
|
|
174
188
|
上游没有给出确切时间时省略,不推算时间。该字段是兼容扩展:旧发送端可不写,旧接收端可忽略;不改变失败类别或服务故障重试语义。
|
|
175
189
|
恢复条件(等待窗口重置、补充额度等)仍由插件放在原因中,重置时刻按[文字里的时刻](#文字里的时刻)写。
|
|
176
190
|
|
|
191
|
+
### 需要重新登录
|
|
192
|
+
|
|
193
|
+
`kind: auth_required` 表示 Agent 的登录凭据已失效,须用户重新登录才能继续,例如 OAuth 令牌过期或被撤销、会话被上游登出。
|
|
194
|
+
这是 `session/prompt` 执行中的失败,与握手阶段的「未登录」(`initialize`、`session/new`、`session/load` 回 -32000)不同:
|
|
195
|
+
后者是还没登录,这里是执行中途登录失效。插件以普通执行错误返回(例如 -32603),不要回 -32000。
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"登录已过期,请重新登录","data":{"_meta":{"coda":{"failure":{"kind":"auth_required","login":"ChatGPT 账号"}}}}}}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
- 插件**该**报它:上游明确表明登录凭据过期或被撤销,重新登录能解决(如刷新令牌失效、令牌被撤销)。
|
|
202
|
+
- 插件**不该**报它:API key 配错或缺失、权限不足、套餐或模型无权使用这类配置错误,重新登录解决不了,仍按未标记的普通错误报告;
|
|
203
|
+
额度耗尽按[额度不足](#额度不足)、服务故障按[服务暂不可用](#服务暂不可用)报告。不能仅凭 HTTP 401 或 403 判断,须有上游明确的凭据失效原因。
|
|
204
|
+
- 可选 `login`:1 到 200 字的文本,指出要重新登录的账号或登录方式,例如 `ChatGPT 账号`、`Anthropic OAuth`;不知道时省略。
|
|
205
|
+
只作显示,Coda 不据此选择登录方式。
|
|
206
|
+
- 不带 `input`、`retryAfterMs`、`resetAt`:带了也不检查,不影响处理。本轮内不即时重试,也不进入服务故障重试;之后由 Coda 提醒用户重新登录,登录后在同一会话续。
|
|
207
|
+
- 错误文字始终放在标准 `error.message`,写明失效的原因;其他 ACP 客户端可以忽略扩展。
|
|
208
|
+
|
|
177
209
|
### 服务暂不可用
|
|
178
210
|
|
|
179
211
|
插件负责识别服务端临时故障;**重试策略归 Coda**,不依赖 Agent 名字、错误文字或私有上游错误码。
|
|
@@ -183,7 +215,7 @@ Coda 按该类别显示「额度不足」,保留完整原因,不安排自动
|
|
|
183
215
|
{"jsonrpc":"2.0","id":"prompt-1","error":{"code":-32603,"message":"服务暂不可用","data":{"_meta":{"coda":{"failure":{"kind":"service_unavailable","input":"accepted"}}}}}}
|
|
184
216
|
```
|
|
185
217
|
|
|
186
|
-
- `kind: service_unavailable
|
|
218
|
+
- `kind: service_unavailable`:服务端暂时无法处理;额度耗尽、需要重新登录、配置或参数错误不得这样报告。
|
|
187
219
|
- `input: accepted`:输入已经进入原生会话;故障回执确认本次原生执行已结束。Coda 在同一会话发送从已有进度继续的指令。
|
|
188
220
|
- `input: not_accepted`:明确拒绝,输入尚未进入原生会话,也没有执行它的操作。仅当原输入从未被接收时重投相同内容与附件;已有接收证据(包括已保存的 `delivered`)时只续跑。
|
|
189
221
|
- 可选 `retryAfterMs`:上游要求或原生 Agent 实际安排的剩余等待,单位毫秒,须为非负有限数;不是预计恢复时间。
|
package/package.json
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
"kind": {
|
|
8
8
|
"enum": [
|
|
9
9
|
"quota_exhausted",
|
|
10
|
-
"service_unavailable"
|
|
10
|
+
"service_unavailable",
|
|
11
|
+
"auth_required"
|
|
11
12
|
],
|
|
12
|
-
"description": "kind 只能是 quota_exhausted 或
|
|
13
|
+
"description": "kind 只能是 quota_exhausted、service_unavailable 或 auth_required"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"required": [
|
|
@@ -49,14 +50,46 @@
|
|
|
49
50
|
},
|
|
50
51
|
"else": {
|
|
51
52
|
"type": "object",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
"if": {
|
|
54
|
+
"properties": {
|
|
55
|
+
"kind": {
|
|
56
|
+
"const": "auth_required"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"required": [
|
|
60
|
+
"kind"
|
|
61
|
+
],
|
|
62
|
+
"type": "object"
|
|
63
|
+
},
|
|
64
|
+
"then": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"login": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"minLength": 1,
|
|
70
|
+
"x-length": 200,
|
|
71
|
+
"description": "login 须为 1 到 200 字的文本,说明要重新登录的账号或登录方式"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"else": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"input": {
|
|
79
|
+
"enum": [
|
|
80
|
+
"accepted",
|
|
81
|
+
"not_accepted"
|
|
82
|
+
],
|
|
83
|
+
"description": "input 只能是 accepted 或 not_accepted"
|
|
84
|
+
},
|
|
85
|
+
"resetAt": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"format": "date-parse",
|
|
88
|
+
"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{1,9})?Z$(?![\\s\\S])",
|
|
89
|
+
"description": "resetAt 须为 UTC ISO 8601 时间字符串(以 Z 结尾),表示上游给出的额度预计重置时间;没有确切时间时不写"
|
|
90
|
+
}
|
|
58
91
|
}
|
|
59
92
|
}
|
|
60
93
|
},
|
|
61
|
-
"$comment": "quota_exhausted
|
|
94
|
+
"$comment": "quota_exhausted 的 input 可选,写了就须是 accepted 或 not_accepted,不检查 retryAfterMs 或 login;service_unavailable 不检查 resetAt 或 login;auth_required 只检查可选的 login,不检查 input、retryAfterMs 或 resetAt。"
|
|
62
95
|
}
|
package/workflow/actions.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required
|
|
2
|
+
"description": "coda:action:serviceTask 上写它,就是 Coda 在后端里做的一步,不写脚本。参数写成 <coda:param name value>,只认 params 列出的,required 列出的必须写;requires 写了某参数就必须同时写它列出的参数;enum 限定某参数写成文字(不是表达式、不含 {{ … }})时的取值",
|
|
3
3
|
"actions": {
|
|
4
4
|
"publish-stage": {"params": ["stage", "detail"],
|
|
5
5
|
"description": "发布运行主体的会话此刻在流程里的阶段(stage)和放在状态旁的说明(detail),两者都空就是清掉;只用于由会话事件启动的运行"},
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"description": "把会话在内存里保管的密码(value:句柄)键入系统的身份验证并提交"},
|
|
34
34
|
"run-command": {"params": ["command", "cwd", "approval"],
|
|
35
35
|
"description": "用户在本运行人工任务 approval 的卡片上批准过这条命令后,以用户的身份在会话的工作副本(或 cwd)里执行它;result 是 exited、stopped 或 unknown"},
|
|
36
|
-
"check-setting": {"params": ["plugin", "setting", "value", "project"],
|
|
37
|
-
"description": "检查对一项插件设置的修改,规则同设置接口的写入,不写入:value 是新值的 JSON 文本(null 清除这一层),project 是目录 ID 或根路径(不写就是本机插件设置);result 是 valid
|
|
36
|
+
"check-setting": {"params": ["plugin", "setting", "value", "project", "machines"],
|
|
37
|
+
"description": "检查对一项插件设置的修改,规则同设置接口的写入,不写入:value 是新值的 JSON 文本(null 清除这一层),project 是目录 ID 或根路径(不写就是本机插件设置);machines 是建议写入的机器,空间里机器的 ID 或名字(JSON 数组或逗号分隔),不写时是空间里装了这个插件的每一台,不在空间里时是本机,写了 project 时只有目录所在的那台(machines 写了别的台就是 invalid)。逐台检查,result 是 valid(至少一台在线且合法)时带卡片显示用的 plugin、setting、layer、before(在线且合法的各台这一层的现值,值相同的台合成一份,多于一份时每份前一行写是哪几台;没设的写明没有设)、after(改后的值,各台相同,某台算出的不同时那台不合法)、machines(choices 字段的 options:空间里装了这个插件的各台,加上 machines 写到的各台;id 是机器 ID,label 是名字,离线的 detail 写离线,这台不合法的 disabled 为 true、detail 写原因)与 selected(choices 字段的 default:建议的各台里在线且合法的那几台,按 machines 的顺序);没有一台在线且合法,或 machines 写了空间里没有的机器时是 invalid(reason);不给 value 时是 current(当前值,密文只说设在哪层;只读一台:machines 只写了一台时是它,否则是本机或目录所在的那台)"},
|
|
38
38
|
"apply-setting": {"params": ["plugin", "setting", "value", "project", "approval"],
|
|
39
|
-
"description": "同 check-setting 的修改,在用户于本运行人工任务 approval 的卡片上按了主按钮、卡片最后一个 code
|
|
39
|
+
"description": "同 check-setting 的修改,在用户于本运行人工任务 approval 的卡片上按了主按钮、卡片最后一个 code 字段与改后的值逐字相同之后写入;写到的机器是主按钮发送的、卡片最后一个 choices 字段勾中的项(选项 id 是机器 ID,即 check-setting 给的 machines),卡片没有 choices 字段时只写本机(写了 project 时是目录所在的那台);流程须来自已装的插件或默认分支。批准核对没过,或卡片有 choices 字段而主按钮没有发送它、一台也没勾,就一台也不写,这一步失败;否则逐台写,一台没写成不影响别台,写成的保留,不重试。输出 results(逐台,按卡片上的顺序:machine 为机器 ID,name 为名字,result 是 written、offline(离线)、not-installed(那台没装这个插件)、refused(那台不接受这次写入,如值不合它的设置声明)或 failed(其他原因),没写成的带 reason,写成的带 layer 与 value:这一层写后的值和那台解析后的值,都是 JSON 文本)、written 与 failed(写成与没写成的台数);layer 与 value 也照旧给出,为第一台写成的那台的,一台也没写成时没有"},
|
|
40
40
|
"tell-overdue": {"params": [],
|
|
41
41
|
"description": "告知运行主体的会话里过了期限的等待项,像结果一样叫醒 Agent;根会话的同时告诉用户;同一项的同一个期限只说一次"},
|
|
42
42
|
"publish-event": {"params": ["name", "subject", "payload", "commit", "project", "session"],
|
|
@@ -47,8 +47,9 @@
|
|
|
47
47
|
"description": "从仓库地址添加项目:本机已有就是它,没有就克隆;新项目没有 Tag 时带上运行所属项目的 Tag"},
|
|
48
48
|
"tell-session": {"params": ["text", "key", "session"],
|
|
49
49
|
"description": "告诉一个会话(不写就是运行所属的)一句话,像结果一样叫醒它的 Agent;同一个 key(或同样的话)只说一次,已归档就不说"},
|
|
50
|
-
"send-session": {"params": ["text", "key", "session"],
|
|
51
|
-
"
|
|
50
|
+
"send-session": {"params": ["text", "key", "session", "resumes", "how"],
|
|
51
|
+
"requires": {"how": ["resumes"]}, "enum": {"how": ["original", "verify"]},
|
|
52
|
+
"description": "在一个会话(不写就是运行所属的)里提交一条普通消息,和用户发的一样开始一轮;同一个 key 只发一次;已归档就不发。resumes 是要续跑的那条输入的 ID,须是 session 指定的会话(不写是运行所属的)里的输入;写了 resumes 时,text 只是存在会话里给人看的一句短说明,发给 Agent 的是那条输入的完整内容(附件、引用都在),how 为 original(默认)是原样重发,为 verify 是先核对已经做了什么、再接着做,加上核对说明。how 须与 resumes 一起写,只能是 original 或 verify(写成文字时读流程就查);resumes 不是这个会话里的输入由实现方在运行时检查"},
|
|
52
53
|
"session-state": {"params": ["session"],
|
|
53
54
|
"description": "一个会话(不写就是运行所属的)现在的样子:它或它的根会话是否已归档"}
|
|
54
55
|
}
|
package/workflow/fields.json
CHANGED
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
"description": "字段须为对象",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"allOf": [
|
|
8
|
-
{"required": ["type"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view"},
|
|
9
|
-
{"properties": {"type": {"enum": ["markdown", "code", "image", "text", "secret", "link", "view"], "description": "字段的 type 只能是 markdown、code、image、text、secret、link、view"}}},
|
|
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"}}},
|
|
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"}},
|
|
13
13
|
{"if": {"properties": {"type": {"const": "text"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/text"}},
|
|
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
|
-
{"if": {"properties": {"type": {"const": "view"}}, "required": ["type"]}, "then": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/view"}}
|
|
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
18
|
],
|
|
18
19
|
"$defs": {
|
|
19
20
|
"markdown": {
|
|
@@ -203,6 +204,75 @@
|
|
|
203
204
|
{"required": ["view"], "description": "须写 view"}
|
|
204
205
|
]
|
|
205
206
|
},
|
|
207
|
+
"choices": {
|
|
208
|
+
"$comment": "多选:卡片列出 options,用户勾其中几项;答复是勾中项的 id 组成的数组,按 options 的顺序(流程读 =<任务>.values.<id>)。required 为 true(默认)时至少勾一项。",
|
|
209
|
+
"allOf": [
|
|
210
|
+
{
|
|
211
|
+
"type": "object",
|
|
212
|
+
"properties": {
|
|
213
|
+
"type": {"const": "choices"},
|
|
214
|
+
"id": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/id"},
|
|
215
|
+
"label": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/label"},
|
|
216
|
+
"required": {"$ref": "https://coda.pub/schema/bpmn/1.0/fields.json#/$defs/required"},
|
|
217
|
+
"options": {
|
|
218
|
+
"x-deferred": {
|
|
219
|
+
"x-json": {
|
|
220
|
+
"schema": {
|
|
221
|
+
"description": "options 须为不超过 65536 字节的 JSON 数组",
|
|
222
|
+
"allOf": [
|
|
223
|
+
{"type": "array", "description": "options 须为选项的 JSON 数组"},
|
|
224
|
+
{"minItems": 1, "maxItems": 32, "description": "options 须有 1–32 个选项"},
|
|
225
|
+
{
|
|
226
|
+
"items": {
|
|
227
|
+
"type": "object",
|
|
228
|
+
"properties": {
|
|
229
|
+
"id": {"type": "string", "pattern": "^\\S(?:[^\\r\\n]*\\S)?$", "x-length": 64, "description": "选项的 id 须为一行、1–64 个字,前后不带空白"},
|
|
230
|
+
"label": {"type": "string", "pattern": "^\\S(?:[^\\r\\n]*\\S)?$", "x-length": 80, "description": "选项的 label 须为一行、1–80 个字,前后不带空白"},
|
|
231
|
+
"detail": {"type": "string", "pattern": "^[^\\r\\n]*$", "x-length": 200, "description": "选项的 detail 须为一行、不超过 200 个字"},
|
|
232
|
+
"disabled": {"type": "boolean", "description": "选项的 disabled 须为 true 或 false"}
|
|
233
|
+
},
|
|
234
|
+
"required": ["id", "label"],
|
|
235
|
+
"additionalProperties": false,
|
|
236
|
+
"description": "选项须为对象,有 id 与 label,可有 detail 与 disabled"
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
{"x-unique-by": ["id"]},
|
|
240
|
+
{"contains": {"not": {"required": ["disabled"], "properties": {"disabled": {"const": true}}}}, "description": "options 里至少要有一项能勾(不是 disabled)"}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
"maxBytes": 65536
|
|
244
|
+
},
|
|
245
|
+
"description": "options 须为选项的 JSON 数组"
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
"default": {
|
|
249
|
+
"x-deferred": {
|
|
250
|
+
"x-json": {
|
|
251
|
+
"schema": {
|
|
252
|
+
"description": "default 须为不超过 8192 字节的 JSON 数组",
|
|
253
|
+
"allOf": [
|
|
254
|
+
{"type": "array", "items": {"type": "string", "description": "default 须为选项 id 的 JSON 数组"}, "description": "default 须为选项 id 的 JSON 数组"},
|
|
255
|
+
{"uniqueItems": true, "description": "default 里的 id 不能重复"},
|
|
256
|
+
{"x-among": {"property": "options", "key": "id"}, "description": "default 里的 {value} 不在 options 里"},
|
|
257
|
+
{
|
|
258
|
+
"x-among": {"property": "options", "key": "id", "match": {"not": {"required": ["disabled"], "properties": {"disabled": {"const": true}}}}},
|
|
259
|
+
"description": "default 里的 {value} 是不能勾的选项(disabled)"
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
},
|
|
263
|
+
"maxBytes": 8192
|
|
264
|
+
},
|
|
265
|
+
"description": "default 须为选项 id 的 JSON 数组"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
"additionalProperties": false
|
|
270
|
+
},
|
|
271
|
+
{"required": ["id"], "description": "须有 id(字母或数字开头的字母、数字、「_」「-」,最长 40 个字符)"},
|
|
272
|
+
{"required": ["label"], "description": "须写 label"},
|
|
273
|
+
{"required": ["options"], "description": "须写 options"}
|
|
274
|
+
]
|
|
275
|
+
},
|
|
206
276
|
"id": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$", "description": "须有 id(字母或数字开头的字母、数字、「_」「-」,最长 40 个字符)"},
|
|
207
277
|
"label": {"x-deferred": {"type": "string", "pattern": "^\\s*\\S(?:[^\\r\\n]*\\S)?\\s*$", "x-length": 40, "description": "label 须为一行、1–40 个字"}},
|
|
208
278
|
"required": {"type": "boolean", "description": "required 须为 true 或 false", "default": true},
|
package/workflow/keywords.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Value operations JSON Schema cannot express: defer checking an expression until it is read, measure UTF-16 text
|
|
2
|
-
// (with a limit optionally named by a sibling),
|
|
2
|
+
// (with a limit optionally named by a sibling), validate JSON supplied as text or as a value, bounded in UTF-8 bytes, and
|
|
3
|
+
// say that the items of an array are keys of a sibling array's items.
|
|
3
4
|
// None knows what a card field is. Schemas select the operations and their limits; validation never changes the input.
|
|
4
5
|
import { isAbsolute } from 'node:path';
|
|
5
6
|
|
|
@@ -88,6 +89,33 @@ export function valueKeywords(ajv, { feelProblem, isExpression }) {
|
|
|
88
89
|
};
|
|
89
90
|
},
|
|
90
91
|
});
|
|
92
|
+
// Each item of the array is the `key` of an item of a sibling's array (`property`: given as such or as its JSON text), one
|
|
93
|
+
// that satisfies `match` when that is given. A sibling not read yet (an expression in a definition), or not an array of
|
|
94
|
+
// its JSON, says nothing here: its own schema says what is wrong with it.
|
|
95
|
+
ajv.addKeyword({
|
|
96
|
+
keyword: 'x-among', type: 'array', schemaType: 'object', errors: true,
|
|
97
|
+
metaSchema: { type: 'object', properties: { property: { type: 'string' }, key: { type: 'string' }, match: { type: ['object', 'boolean'] } }, required: ['property', 'key'], additionalProperties: false },
|
|
98
|
+
compile(spec, parentSchema) {
|
|
99
|
+
const matches = spec.match === undefined ? null : ajv.compile(spec.match);
|
|
100
|
+
return function among(values, cxt) {
|
|
101
|
+
let list = cxt.parentData && Object.hasOwn(cxt.parentData, spec.property) ? cxt.parentData[spec.property] : undefined;
|
|
102
|
+
if (typeof list === 'string') {
|
|
103
|
+
if (this?.definition && (isExpression(list) || list.includes('{{'))) return true;
|
|
104
|
+
try { list = JSON.parse(list); } catch { return true; }
|
|
105
|
+
}
|
|
106
|
+
if (!Array.isArray(list)) return true;
|
|
107
|
+
const items = new Map();
|
|
108
|
+
for (const item of list) if (item !== null && typeof item === 'object' && Object.hasOwn(item, spec.key) && !items.has(item[spec.key])) items.set(item[spec.key], item);
|
|
109
|
+
for (const value of values) {
|
|
110
|
+
const item = items.get(value);
|
|
111
|
+
if (item !== undefined && (!matches || matches(item))) continue;
|
|
112
|
+
among.errors = [{ keyword: 'x-among', params: { value: typeof value === 'string' ? value : JSON.stringify(value) }, parentSchema, message: `不在 ${spec.property} 里` }];
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
});
|
|
91
119
|
ajv.addKeyword({
|
|
92
120
|
keyword: 'x-json', schemaType: 'object', errors: true,
|
|
93
121
|
metaSchema: { type: 'object', properties: { schema: { type: ['object', 'boolean'] }, maxBytes: { type: 'integer', minimum: 0 } }, required: ['schema', 'maxBytes'], additionalProperties: false },
|
package/workflow/moddle.json
CHANGED
|
@@ -238,6 +238,7 @@
|
|
|
238
238
|
{"name": "view", "isAttr": true, "type": "String"},
|
|
239
239
|
{"name": "args", "isAttr": true, "type": "String"},
|
|
240
240
|
{"name": "presentation", "isAttr": true, "type": "String"},
|
|
241
|
+
{"name": "options", "isAttr": true, "type": "String"},
|
|
241
242
|
{"name": "default", "isAttr": true, "type": "String"},
|
|
242
243
|
{"name": "autofill", "isAttr": true, "type": "String"},
|
|
243
244
|
{"name": "keep", "isAttr": true, "type": "String"},
|
package/workflow/structure.json
CHANGED
|
@@ -134,7 +134,8 @@
|
|
|
134
134
|
},
|
|
135
135
|
"inputFields": [
|
|
136
136
|
"text",
|
|
137
|
-
"secret"
|
|
137
|
+
"secret",
|
|
138
|
+
"choices"
|
|
138
139
|
],
|
|
139
140
|
"rules": [
|
|
140
141
|
{
|
|
@@ -478,7 +479,7 @@
|
|
|
478
479
|
]
|
|
479
480
|
},
|
|
480
481
|
{
|
|
481
|
-
"description": "有输入字段(text、secret 或 coda:fields)的任务只交给用户,写 coda:assignee=\"user\"",
|
|
482
|
+
"description": "有输入字段(text、secret 或 coda:fields)的任务只交给用户,写 coda:assignee=\"user\"(choices 字段也是输入字段)",
|
|
482
483
|
"schema": {
|
|
483
484
|
"required": [
|
|
484
485
|
"assignee"
|
package/workflow/values.json
CHANGED
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
"pointer": "/field",
|
|
239
239
|
"key": "id",
|
|
240
240
|
"split": "[\\s,]+",
|
|
241
|
-
"match": {"type": "object", "required": ["type"], "properties": {"type": {"enum": ["text", "secret"]}}}
|
|
241
|
+
"match": {"type": "object", "required": ["type"], "properties": {"type": {"enum": ["text", "secret", "choices"]}}}
|
|
242
242
|
},
|
|
243
243
|
"description": "fields 里的 {value} 不是这个任务的输入字段"
|
|
244
244
|
}
|
|
@@ -255,7 +255,7 @@
|
|
|
255
255
|
"pointer": "/field",
|
|
256
256
|
"key": "id",
|
|
257
257
|
"split": "[\\s,]+",
|
|
258
|
-
"match": {"type": "object", "required": ["type"], "properties": {"type": {"enum": ["text", "secret"]}}}
|
|
258
|
+
"match": {"type": "object", "required": ["type"], "properties": {"type": {"enum": ["text", "secret", "choices"]}}}
|
|
259
259
|
},
|
|
260
260
|
"description": "fields 里的 {value} 不是这个任务的输入字段"
|
|
261
261
|
}
|
package/workflow.mjs
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
// - `x-duration`: true — the value is an ISO 8601 duration, not negative;
|
|
13
13
|
// - `x-number`: true — the text, read as a number, is a finite one (`1e999` reads as none).
|
|
14
14
|
// workflow/keywords.mjs adds x-deferred (check FEEL now, the result later), x-length (UTF-16 text length, optionally
|
|
15
|
-
// limited by a sibling), x-json (a JSON value or its text, with a byte budget),
|
|
15
|
+
// limited by a sibling), x-json (a JSON value or its text, with a byte budget), x-among (each item names an item of a
|
|
16
|
+
// sibling array), and absolute-path / https-url formats.
|
|
16
17
|
import { parseDuration } from '@0dep/piso';
|
|
17
18
|
import { BpmnModdle } from 'bpmn-moddle';
|
|
18
19
|
import { parseExpression } from 'feelin';
|
|
@@ -36,6 +37,9 @@ export const CODA_OPTIONS = options;
|
|
|
36
37
|
export const CODA_ACTIONS = Object.fromEntries(Object.entries(actions.actions).map(([name, action]) => [name, action.params]));
|
|
37
38
|
// The parameters an action must be given, by its name; an action with none is not listed.
|
|
38
39
|
const REQUIRED_PARAMS = Object.fromEntries(Object.entries(actions.actions).filter(([, action]) => action.required).map(([name, action]) => [name, action.required]));
|
|
40
|
+
// What an action's parameters must keep to besides being named: the others one needs (`requires`, by parameter), and the
|
|
41
|
+
// values a parameter written as plain text may take (`enum`); an action with neither is not listed.
|
|
42
|
+
const PARAM_RULES = Object.fromEntries(Object.entries(actions.actions).filter(([, action]) => action.requires || action.enum).map(([name, action]) => [name, action]));
|
|
39
43
|
// The events Coda sends (dialect.json says what each is).
|
|
40
44
|
export const CODA_EVENTS = Object.keys(dialect.events);
|
|
41
45
|
export const { lifecycleStart: SESSION_OPENED, lifecycleFacts: SESSION_FACTS, dispatch: DISPATCH_EVENT, cancel: CANCEL_EVENT } = dialect.eventRoles;
|
|
@@ -158,11 +162,14 @@ const description = (error, object = {}) => (described(error, { schemas: [values
|
|
|
158
162
|
: object && Object.hasOwn(object, key) ? String(object[key]) : whole);
|
|
159
163
|
// Required values and allowed attributes come from the same schema as validation; none of the field types is named here.
|
|
160
164
|
function fieldSaid(error, at, field) {
|
|
161
|
-
|
|
165
|
+
// A key a field's type does not have; one inside a value (a choices field's option) is said by that value's schema.
|
|
166
|
+
if (error.keyword === 'additionalProperties' && error.parentSchema.properties?.type?.const) {
|
|
162
167
|
const allowed = Object.keys(error.parentSchema.properties), type = error.parentSchema.properties.type.const;
|
|
163
168
|
const extra = Object.keys(error.data).filter(key => !Object.hasOwn(error.parentSchema.properties, key));
|
|
164
169
|
return `${at}:${type} 字段没有 ${extra.join('、')},可写 ${allowed.join('、')}`;
|
|
165
170
|
}
|
|
171
|
+
// Items repeated in a value of the field (its options' ids): which value, then what is repeated.
|
|
172
|
+
if (error.keyword === 'x-unique-by') return `${at}:${error.instancePath.split('/')[1]} 里的 ${error.message}`;
|
|
166
173
|
return `${at}:${error.keyword === 'x-feel' ? error.message : description(error, field)}`;
|
|
167
174
|
}
|
|
168
175
|
// A resolved field, at task opening or when accepting an answer. No expression is evaluated and no default is inserted.
|
|
@@ -300,6 +307,14 @@ export async function readWorkflow(source, file = 'workflow') {
|
|
|
300
307
|
if (given.some(p => !params.includes(p.name))) return { problem: `${task.id}:coda:action ${task.action} 只接受参数 ${params.join('、')}` };
|
|
301
308
|
const missing = (REQUIRED_PARAMS[task.action] ?? []).filter(name => !given.some(p => p.name === name));
|
|
302
309
|
if (missing.length) return { problem: `${task.id}:coda:action ${task.action} 须写参数 ${missing.join('、')}` };
|
|
310
|
+
for (const [name, needs] of Object.entries(PARAM_RULES[task.action]?.requires ?? {}))
|
|
311
|
+
if (given.some(p => p.name === name) && needs.some(need => !given.some(p => p.name === need)))
|
|
312
|
+
return { problem: `${task.id}:coda:action ${task.action} 写了参数 ${name} 就须写参数 ${needs.join('、')}` };
|
|
313
|
+
for (const [name, values] of Object.entries(PARAM_RULES[task.action]?.enum ?? {})) {
|
|
314
|
+
const value = given.find(p => p.name === name)?.value;
|
|
315
|
+
if (value !== undefined && !isExpression(value) && !value.includes('{{') && !values.includes(value))
|
|
316
|
+
return { problem: `${task.id}:coda:action ${task.action} 的参数 ${name} 只能是 ${values.join('、')}` };
|
|
317
|
+
}
|
|
303
318
|
}
|
|
304
319
|
const problem = valuesProblem(root) ?? joinInputsProblem(root) ?? structureProblem(root, file);
|
|
305
320
|
return problem ? { problem } : { root };
|