@coda-console/protocol 6.24.0 → 6.26.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,20 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.26.0 — 2026-11-24
6
+
7
+ - 这是在 6.25.0 之上的次版本。依据 README「版本」一节:流程方言与 Agent 接入协议是内部面,只加可选属性与约定,升次版本;`stable/` 不动,清单 schema 没改。6.25.0 下合法的流程仍合法。
8
+ - 流程属性 `coda:questionDenial`(字符串):写了它,运行期间,持有这个运行或它的子运行里没结束的 agent 任务的会话向用户提问时,宿主当场拒绝,把这段文字回给 Agent;不写就不拦。权限审批、链接表单、密钥卡、请用户操作桌面、指给用户的流程任务都不拦。父子运行都声明时:从会话所持任务所在的运行开始往上找,用离它最近的一段;子运行没声明,就沿用祖先的声明。写了就须非空白,1–2000 个字符(以 `workflow/values.json` 里的定义为准),空串与全空白读流程时报错(不想拦就不写)。README 的流程方言补这条。
9
+ - Agent 接入协议:宿主因流程声明(`coda:questionDenial`)拦下轮内的 `elicitation/create` 表单时,回 `action: decline` 且必须带 `_meta.coda.reason`;Agent 插件见到 reason 就把这段文字原样交给模型。没带 reason 的 `decline` 语义不变,仍是用户拒绝;轮次限制无条件,拦截只适用于轮内 form,轮次之外的表单照旧回 `cancel`。`docs/agent-protocol.md` 补 `_meta.coda.reason`,新增 `schemas/agent/elicitation-denial.json`(`reason` 须为非空字符串,只出现在 `decline` 的表单结果里,不带 reason 的普通 `decline` 仍合法),登记在文中的 schema 索引表,`agentValueProblem('elicitation-denial.json', result)` 可校验。
10
+
11
+ ## 6.25.0 — 2026-11-24
12
+
13
+ - 这是在 6.24.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,只加可选的键和类型字段,升次版本;`stable/` 不动,清单 schema 没改。三处都是只增:6.24.0 下合法的定义仍合法。
14
+ - 协议定义顶层加可选键 `resource`:`{ columns, symbol? }`,展示声明。写了它的种类成为可列出、可引用的资源;`columns` 非空、不重复、至多 8 项,每项是 `spec` 的顶层字段名,列表里按此顺序显示,第一列是名字,所在机器那一列由宿主自己加;`symbol` 是客户端画的 SF Symbol 名。`definitionProblem` 另查:每一列须是 `spec.properties` 里声明的标量字段(`type` 为 string、number、integer、boolean 之一,数组形式去掉 `"null"` 后只剩一种标量也算;有 `enum` 而无 `type` 不算);没写 `spec` 的定义不能写 `resource`。
15
+ - 权限组加布尔键 `sessions`:为 true 表示这组里的操作与流开放给会话(会话经工具调用),不只是开放给插件。`definitionProblem` 另查两条:有 `events` 的组不能出现 `sessions`(写成 `false` 也不行);写了 `sessions` 的组(`true`、`false` 都算)须至少有一个操作或一条流,只有 `read` 不够。
16
+ - `./types`:`Caller` 与 `StreamCaller` 的各分支都可再带可选的 `machine`(发起调用的那台后端的 ID)、`plugin`(以哪个插件的身份发起)、`parent`(`{ kind, id }`,直接的发起方,不透明引用),共用新类型 `CallerOrigin`;已有字段与分支的形状不变。`machine` 由接收方按信封来源自己核验;`plugin`、`parent` 与页面打开者(`device`、`name`、`local`)是来源后端转述的,接收方无法独立核验;只给直接的调用方,不给整条父链。`Context.caller` 的注释同步:Coda 填写时,查询与插件、会话发起的调用也带。
17
+ - 需要你知道:`Caller`、`StreamCaller` 的收窄是类型层面的变化(运行时的形状只增不改)。`machine`、`plugin` 现在可能出现在任何分支上,用 `in` 判断分支的 TypeScript 代码要改成按值判断,`in` 收窄后这两个字段的类型是 `string | undefined`。改写示例分两件事。一,字段有没有值:`caller.machine !== undefined`、`s.plugin !== undefined`,这只是说有没有值,不等于原来的哪个分支。二,判断跨机来源:原来的 `'machine' in caller` 写成 `caller.machine !== undefined && caller.machine !== selfId`(`selfId` 是本机自己的 ID),它只说明「这次调用是别台后端发来的」,不说明是不是页面发起的:查询、插件与会话发起的调用也带 `machine`。现有调用方字段不能在所有情况下判定是不是页面发起的:别台本机客户端打开页面转来的调用只带 `machine`(不带 `local`),与别台没有 `plugin`、`parent` 的其他调用形状相同;要靠「是不是页面」做判断的插件不要只依赖这几个字段。有 `device`(或 `local: true`)时才说明调用前面有个页面打开者;原来的 `'plugin' in s`(`StreamCaller` 的插件分支:本机上的插件来问,本机按令牌核验过)写成 `s.plugin !== undefined && !('device' in s) && !('local' in s)`,因为别台转来的 `{ device, role: 'backend', plugin }` 的 `plugin` 是转述的,只看有没有值会把它当成本机核验过的(类型上联合没有公共的 `device`,所以写 `'device' in s`,不能写 `s.device === undefined`)。`'local' in caller`、`'device' in caller`、`'role' in caller` 照旧可用。两个字段在各分支上含义一致:`machine` 一律是发起调用的那台后端的 ID(接收方按信封核验);`StreamCaller` 的 `plugin` 是以哪个插件的身份来问,最后一跳是本机时由本机核验,最后一跳是别台后端(`role: 'backend'`)时是转述的、本机无法核验。
18
+
5
19
  ## 6.24.0 — 2026-11-23
6
20
 
7
21
  - 这是在 6.23.0 之上的次版本。依据 README「版本」一节:协议定义是内部面,放宽限制和新增路径种类,升次版本;`stable/` 不动,清单 schema 没改。`coda/session@1` 只加不删,协议名不变:6.23.0 里有效的记录和 `read` 结果照旧有效。
package/README.md CHANGED
@@ -16,6 +16,8 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
16
16
 
17
17
  流程方言的 **挂点**是流程之间互相找到的方式:被调用的流程在自己的 extensionElements 里写 `<coda:join hook name? detail? default? order?/>` 加入一个挂点(`hook` 是小写字母开头的名字,一个流程每个挂点只加入一次),`name`、`detail` 是它作为勾选项时的名字与说明,`default` 是否默认勾上(只写 true 或 false:挂点的列表在任何运行之外读出),`order` 是整数,小的在前;`inputs` 是它要从卡片拿的自己的文字参数(`coda:input`,type 为 string,逗号或空格分隔,最多 4 个,读流程时检查),`joinInputNames(join)` 读出这些名字。宿主用动作 `hook-joiners` 列出一个挂点的加入者(勾选项形状,带上各自的 `inputs`,可直接给 `coda:optionList`),用 `run-workflows` 的 `hook`(必写)调用它们,`only` 只调用勾中的几个。挂点名是普通字符串,传哪些参数、怎么选由声明它的宿主写在自己的说明里。流程属性 `coda:mergedOnly` 说它是否只运行已合并进默认分支的提交,不写为 false(任何提交都能跑)。
18
18
 
19
+ 流程方言的 **拦下提问**由流程属性 `coda:questionDenial` 声明(字符串):写了它,这个运行进行期间,持有这个运行或它的子运行里没结束的 agent 任务的会话,向用户提问时,宿主当场拒绝,把这段文字回给 Agent(表单回 `decline`,文字放在 `_meta.coda.reason`,见 [Agent 接入协议](docs/agent-protocol.md));不写就不拦。父子运行都声明时:从会话所持任务所在的运行开始往上找,用离它最近的一段;子运行没声明,就沿用祖先的声明。它自己的要求:非空白,1–2000 个字符(以 `workflow/values.json` 里的定义为准),空串或全空白读流程时报错,不想拦就别写。权限审批、链接表单、密钥卡、请用户操作桌面、指给用户的流程任务(`coda:assignee="user"`),都不拦。
20
+
19
21
  流程方言的 **勾选项**写在答复(外层的 `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
22
 
21
23
  流程方言的 **卡片字段**由 `workflow/fields.json` 定义:九种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项、多选的选项表、一组客户端操作;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
@@ -31,6 +31,7 @@ ACP 的消息、内容块、会话指令和能力由 ACP SDK 校验,这里只
31
31
  | `session/prompt` 答复的 `usage` | [prompt-usage.json](../schemas/agent/prompt-usage.json) |
32
32
  | 配置选项的 `_meta.coda.default` | [default.json](../schemas/agent/default.json)(传入 `_meta.coda` 对象) |
33
33
  | 模型、模式、配置项及其选项的 `_meta.coda.shortName` | [display.json](../schemas/agent/display.json)(传入 `_meta.coda` 对象) |
34
+ | `elicitation/create` 表单结果的 `_meta.coda.reason`(宿主拦下表单时) | [elicitation-denial.json](../schemas/agent/elicitation-denial.json)(传入整个结果对象,如 `{"action":"decline","_meta":…}`) |
34
35
 
35
36
  `@coda-console/protocol/agent` 导出 `agentMessageProblem(method, params)`、`agentResultProblem(method, result)`、
36
37
  `agentCapabilitiesProblem(meta, party = 'agent')` 和 `agentValueProblem(ref, value, where)`,合法返回 `null`,
@@ -67,7 +68,7 @@ Coda 是 ACP 的客户端。每个会话的 Agent 进程由一个会话托管进
67
68
  | `_coda/session/compact` | Coda → Agent | [压缩上下文](#压缩上下文):请 Agent 压缩这个会话的上下文;只对声明支持的 Agent 发,两轮之间也发 |
68
69
  | `session/set_config_option`、`session/set_mode`、`session/set_model` | Coda → Agent | 模型、推理强度与模式 |
69
70
  | `session/update` | Agent → Coda | 回复、思考、工具调用(可带它的[审核](#工具调用的审核))、计划、用量(可带给流程的[数据](#用量里的数据))、可用命令、会话信息;只收本会话与它的子会话的 |
70
- | `session/request_permission`、`elicitation/create`(`mode: form` 或 `mode: url`) | Agent → Coda | 审批与提问,作为卡片交给用户;只在一轮里受理(见[规则](#规则)第 3 条) |
71
+ | `session/request_permission`、`elicitation/create`(`mode: form` 或 `mode: url`) | Agent → Coda | 审批与提问,作为卡片交给用户;只在一轮里受理(轮次限制无条件,见[规则](#规则)第 3 条);拦截只适用于轮内 `mode: form` 表单:若被流程声明拦下(`coda:questionDenial`),不展示卡片,当场回 `decline` 并带 `_meta.coda.reason`(见下文「宿主当场拒绝表单」) |
71
72
  | `_coda/unrecognized` | Agent → Coda | [没适配的东西](#没适配的东西):入口报上游发来、它没按登记处理的输出,以及模型能用、它没登记的原生工具;用户因此没看到的在会话里记一条说明,都计入遥测 |
72
73
  | `_coda/remote/code`、`_coda/remote` | Agent → Coda、Coda → Agent | [远端入口](#远端入口):Agent 要绑定码;Coda 转交远端来的请求 |
73
74
  | `$/cancel_request` | Agent → Coda | 撤回它发出、还没得到回答的审批或提问:卡片失效,Coda 回 `cancelled`(表单回 `cancel`),之后用户的回答不再转交 |
@@ -79,6 +80,7 @@ ACP 只允许在一轮(`session/prompt`)进行时交互。Agent 在两轮之
79
80
  - **表单**:`requestedSchema` 是标准 JSON Schema,Coda 按它展示并校验回答;单选、多选用
80
81
  `enum` 或 `oneOf`/`anyOf` 的 `{const, title}`,不认私有键。
81
82
  - **链接**(`mode: url`):带 `url` 与 `elicitationId`,没有要填的字段;Coda 展示链接,用户打开、办完后确认,回 `{action}`(`accept`、`decline` 或 `cancel`)。
83
+ - **宿主当场拒绝表单**:流程可以声明运行期间拦下会话向用户的提问(流程属性 `coda:questionDenial`,见 README 的流程方言)。被拦的 `elicitation/create` 表单,Coda 不展示卡片,回 `{action: "decline"}`,且**必须**在结果的 `_meta.coda.reason` 里带一段文字(拦它的流程写的):`{"action":"decline","_meta":{"coda":{"reason":"……"}}}`。Agent 插件见到 `_meta.coda.reason` 就把这段文字原样交给模型(作为这次提问的结果),不改写、不丢弃;`reason` 须为非空字符串,只出现在 `action: "decline"` 的结果里([elicitation-denial.json](../schemas/agent/elicitation-denial.json));没有 `_meta.coda.reason` 的 `decline` 仍合法,语义不变,仍是用户拒绝。轮次之外的表单照旧回 `cancel`(见上文),不在此例。审批、链接(`mode: url`)不被这样拦。
82
84
  - **模型的分组**:`category: model` 的配置项可以按来源分组,用 ACP 选择型配置项的分组写法:`options` 是一组 `{ group, name, options }`,
83
85
  如 Agent 自己的模型一组、它接的每个模型服务一组(模型服务(Coda 的 docs/plugins.md「模型服务」))。Coda 记下每个模型所在组的 `name`,两端选模型时按组分段、
84
86
  以组名为段标题,组内与输入框上只写模型的 `name`;不分组的照旧列成一串。模型 ID 在各组之间不重复,设模型照旧按 ID。
package/docs/protocol.md CHANGED
@@ -76,7 +76,8 @@ protocolShortName('coda/run@1'); // 'coda-1run-21'
76
76
  | `operations` | 操作名 → `{ description?, input, result, safe?, idempotent?, timeout? }` 或 `{ description?, input, run: true, timeout? }`;没写 `events` 时必填,不定义操作写 `{}` |
77
77
  | `streams` | 流名 → `{ description?, input, shape?, frames?, subprotocol? }`,可选(见「记录流」) |
78
78
  | `events` | 事件名 → `{ description?, payload, starts?, ends? }`,可选(见「事件」) |
79
- | `permissions` | 权限组名 → `{ title, trial?, operations?, streams?, events?, read? }`,可选(见「权限组」) |
79
+ | `resource` | 展示声明 `{ columns, symbol? }`,可选(见「资源展示」) |
80
+ | `permissions` | 权限组名 → `{ title, trial?, operations?, streams?, events?, read?, sessions? }`,可选(见「权限组」) |
80
81
 
81
82
  `spec`、`status`、`input`、`result` 都是 JSON Schema draft 2020-12,只引用自己文档里的 `#/$defs/...`,不引用别的文件。`input` 必有。操作的输出二选一:
82
83
 
@@ -273,6 +274,23 @@ const body = writeFrames(frames, { heartbeatMs: 15000 });
273
274
  }
274
275
  ```
275
276
 
277
+ ### 资源展示
278
+
279
+ 定义可以写 `resource`,声明这个种类在资源列表里怎么展示:
280
+
281
+ ```json
282
+ "resource": {"columns": ["name", "region", "port"], "symbol": "server.rack"}
283
+ ```
284
+
285
+ | 字段 | 含义 |
286
+ | --- | --- |
287
+ | `columns` | 必填,非空、不重复、至多 8 项的字符串数组,每项是 `spec` 的顶层字段名(1–64 个字符) |
288
+ | `symbol` | 可选,客户端画的 SF Symbol 名,1–64 个字符 |
289
+
290
+ 不许有别的键。写了 `resource` 的种类成为可列出、可引用的资源:列表里每条按 `columns` 的顺序显示,第一列是名字;所在机器那一列由宿主自己加,不用写;列名取该字段 schema 的 `title`,没有就用字段名;只展示这些列与 `spec` 里带 `description` 的字段。不写就和没有这个声明一样。
291
+
292
+ `definitionProblem` 还查:每一列都必须是 `spec.properties` 里声明的字段,且该字段是标量:它的 schema 的 `type` 是 `string`、`number`、`integer` 或 `boolean` 之一(`type` 是数组时,去掉 `"null"` 后只剩一种标量也算;有 `enum` 而无 `type` 不算)。没写 `spec` 的定义(只有 `events` 的协议)不能写 `resource`。报错写明 `<位置>.resource.columns[i]` 与原因。
293
+
276
294
  ### 权限组
277
295
 
278
296
  一切对插件开放的能力都以协议提供,权限挂在协议上:定义用 `permissions` 把自己的操作、流、事件与记录的读取分成组,插件在清单的 `uses`(必需)或 `optionalUses`(可选)里声明用到哪些组,没声明的调用被宿主拒绝。组名的写法同操作名(小写字母开头,只用小写字母、数字和「-」,至多 64 个字符)。每组:
@@ -285,8 +303,9 @@ const body = writeFrames(frames, { heartbeatMs: 15000 });
285
303
  | `streams` | 可选,不重复的流名数组,归这组管的流 |
286
304
  | `events` | 可选,至少一项、不重复的事件名数组,归这组管的事件;插件在 `uses` 或 `optionalUses` 里写了这组,就是订了组里全部事件 |
287
305
  | `read` | 可选,布尔,管不管读这个协议的记录(get、list、watch)。写记录只许实现方,不分给插件 |
306
+ | `sessions` | 可选,布尔,为 true 表示这组里的操作与流开放给会话(会话经工具调用),不只是开放给插件 |
288
307
 
289
- 不许有别的键。写了 `permissions` 的定义还要满足(`definitionProblem` 查):每个操作、每条流、每个事件最多属于一组;组里列的操作都在 `operations` 里,列的流都在 `streams` 里,列的事件都在 `events` 里;每组至少管一样东西(有操作、有流、有事件,或 `read` 为 true);有 `events` 的组只放事件:`events` 至少一项,且不能再出现 `operations`、`streams`、`read` 这几个键,写成 `[]` 或 `false` 也不行。**不在任何组里的操作、流和事件不对插件开放**,只有 Coda 自己和它的客户端调;不写 `permissions` 的定义照旧合法,那时整个协议都不对插件开放。
308
+ 不许有别的键。写了 `permissions` 的定义还要满足(`definitionProblem` 查):每个操作、每条流、每个事件最多属于一组;组里列的操作都在 `operations` 里,列的流都在 `streams` 里,列的事件都在 `events` 里;每组至少管一样东西(有操作、有流、有事件,或 `read` 为 true);有 `events` 的组只放事件:`events` 至少一项,且不能再出现 `operations`、`streams`、`read`、`sessions` 这几个键,写成 `[]` 或 `false` 也不行;写了 `sessions` 的组(不论 true 还是 false)必须至少有一个操作或一条流,只有 `read` 不够。**不在任何组里的操作、流和事件不对插件开放**,只有 Coda 自己和它的客户端调;不写 `permissions` 的定义照旧合法,那时整个协议都不对插件开放。
290
309
 
291
310
  ```json
292
311
  "permissions": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.24.0",
3
+ "version": "6.26.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/plugin.d.mts CHANGED
@@ -61,11 +61,38 @@ export interface CallOptions {
61
61
  }
62
62
 
63
63
  /**
64
- * Who is before the page that made a doing call: Coda's own client on this machine, or a device, with its name if known.
65
- * A call forwarded to the backend that holds the record has no `local` but the `machine` it was made from (that one's ID),
66
- * a device kept as it is: so `{ machine }` or `{ machine, device, name? }`.
64
+ * What a call says of where it came from, beside who is before it. All optional, filled by Coda when it can; only the direct
65
+ * caller is given, never the whole chain of parents.
66
+ * - `machine`: the ID of the backend the call was made from. The receiver checks it itself against where the envelope came from.
67
+ * - `plugin`: the plugin the call is made as. Relayed by the originating backend: the receiver cannot check it on its own.
68
+ * - `parent`: whoever made the call directly, e.g. the session that did, an opaque reference. Relayed too, not checkable.
69
+ * The page's opener (`device`, `name`, `local`) is relayed by the originating backend as well.
70
+ *
71
+ * Read where a call came from by value, not by whether a property exists. Since 6.25.0 `machine` and `plugin` may be on any
72
+ * branch of `Caller` and `StreamCaller`, so `'machine' in caller` and `'plugin' in caller` no longer tell the branches apart,
73
+ * and TypeScript types the field as `string | undefined` after such a check. Tell this machine's own client (`local`), a
74
+ * device (`device`, and `role` of a `StreamCaller`) and a plugin by those fields and the values of `machine` and `plugin`.
75
+ * The two mean the same on every branch: `machine` is always the ID of the backend the call was made from, which the
76
+ * receiver checks against the envelope; a `StreamCaller`'s `plugin` is the plugin the call is made as, checked by this machine
77
+ * (by its token, or by Coda's own entry) when the last hop is this machine, relayed and not checkable by this machine when
78
+ * the last hop is another backend (`role: 'backend'`). So `s.plugin !== undefined` and `caller.machine !== undefined` say only
79
+ * that there is a value; the old branch of a plugin checked by this machine is `s.plugin !== undefined && !('device' in s) && !('local' in s)`,
80
+ * and a call relayed from another backend is `caller.machine !== undefined && caller.machine !== selfId`.
67
81
  */
68
- export type Caller = { local: true } | { device: string; name?: string } | { machine: string; device?: string; name?: string };
82
+ export interface CallerOrigin {
83
+ machine?: string;
84
+ plugin?: string;
85
+ parent?: { kind: string; id: string };
86
+ }
87
+
88
+ /**
89
+ * Who made a doing call or a query. When a page's opener is before it, `local: true` (Coda's own client on this machine) or
90
+ * `device` (with its `name` if known). A call forwarded from another backend has no `local` but the `machine` it was made from
91
+ * (that one's ID), a device kept as it is: so `{ machine }` or `{ machine, device, name? }`. A bare `{ machine }` may be a page
92
+ * opened by that machine's own client or any other call from that machine, so these fields alone do not tell whether a page
93
+ * made the call. Each form may also carry a `CallerOrigin`.
94
+ */
95
+ export type Caller = ({ local: true } | { device: string; name?: string } | { machine: string; device?: string; name?: string }) & CallerOrigin;
69
96
 
70
97
  /** What a handler of a call is given beside its input. A handler of a query, and `resume`, have no `progress` nor `ask`. */
71
98
  export interface Context {
@@ -98,8 +125,10 @@ export interface Context {
98
125
  */
99
126
  call?: Coda['call'];
100
127
  /**
101
- * A doing call's, made from a plugin's page: who is before that page, as Coda knows it, never as the page says. None
102
- * for a call a module (`coda.call`), a command (`coda call`) or a flow makes.
128
+ * Who made the call, as Coda knows it when it fills this in, never as the page says: who is before the page that made
129
+ * it, and for a query or a call a plugin or a session makes, where it came from (see `CallerOrigin`). `machine` is
130
+ * checked by the receiver against the envelope; `plugin`, `parent` and the page's opener are relayed by the originating
131
+ * backend and cannot be checked by the receiver. Only the direct caller, not the chain of parents.
103
132
  */
104
133
  caller?: Caller;
105
134
  }
@@ -110,7 +139,7 @@ export type Handler = (input: Json, ctx: Context) => Json | Promise<Json>;
110
139
  * Who asks a service or a stream: this machine's own client or tools, a device, another backend of the space (the last hop,
111
140
  * of one sent on), or a plugin (by its token, or from its page; a stream's only).
112
141
  */
113
- export type StreamCaller = { local: true } | { device: string; role: 'client' | 'backend'; name?: string } | { plugin: string };
142
+ export type StreamCaller = ({ local: true } | { device: string; role: 'client' | 'backend'; name?: string } | { plugin: string }) & CallerOrigin;
114
143
  /** What a handler of a service (`coda.serve`) is given beside its request. */
115
144
  export interface ServeContext {
116
145
  caller: StreamCaller;
package/protocol.mjs CHANGED
@@ -78,7 +78,7 @@ function schemaProblem(schema, where) {
78
78
 
79
79
  // Permission groups, when written: every group names real operations, streams and events and covers something, every
80
80
  // operation, stream and event sits in at most one group. One that is in no group is not open to plugins. A group with events
81
- // holds only events: subscribing to the group is subscribing to all of them.
81
+ // holds only events: subscribing to the group is subscribing to all of them. A group that writes sessions holds an operation or a stream.
82
82
  function permissionsProblem({ operations = {}, streams = {}, events = {}, permissions }, where) {
83
83
  if (permissions === undefined) return null;
84
84
  const owner = { operations: new Map(), streams: new Map(), events: new Map() };
@@ -92,8 +92,10 @@ function permissionsProblem({ operations = {}, streams = {}, events = {}, permis
92
92
  owner[key].set(name, group);
93
93
  }
94
94
  }
95
- if (entry.events !== undefined && ['operations', 'streams', 'read'].some(key => Object.hasOwn(entry, key)))
96
- return `${where}.permissions.${group}:有 events 的组只放事件,不能再写 operations、streams、read`;
95
+ if (entry.events !== undefined && ['operations', 'streams', 'read', 'sessions'].some(key => Object.hasOwn(entry, key)))
96
+ return `${where}.permissions.${group}:有 events 的组只放事件,不能再写 operations、streams、read、sessions`;
97
+ if (Object.hasOwn(entry, 'sessions') && !entry.operations?.length && !entry.streams?.length)
98
+ return `${where}.permissions.${group}.sessions:写了 sessions 的组至少要有一个操作或一条流,只有 read 不够`;
97
99
  if (!entry.operations?.length && !entry.streams?.length && !entry.events?.length && entry.read !== true)
98
100
  return `${where}.permissions.${group}:至少管一样东西:写 operations、streams 或 events,或 read 为 true`;
99
101
  }
@@ -128,6 +130,25 @@ function recordsProblem(definition, where) {
128
130
  return reading ? `${where}.permissions.${reading[0]}.read:${without}读记录的权限,要它须同时写 spec 和 status` : null;
129
131
  }
130
132
 
133
+ // `resource.columns`: each is a scalar top-level field of `spec` (a string, number, integer or boolean; `null` beside one is fine).
134
+ const SCALAR_TYPES = ['string', 'number', 'integer', 'boolean'];
135
+ function isScalarSchema(schema) {
136
+ if (schema === null || typeof schema !== 'object') return false;
137
+ const types = (Array.isArray(schema.type) ? schema.type : [schema.type]).filter(type => type !== 'null');
138
+ return types.length === 1 && SCALAR_TYPES.includes(types[0]);
139
+ }
140
+
141
+ function resourceProblem({ spec, resource }, where) {
142
+ if (resource === undefined) return null;
143
+ if (spec === undefined) return `${where}.resource:没有记录的协议(没写 spec)不能写 resource`;
144
+ const properties = spec?.properties ?? {};
145
+ for (const [index, column] of resource.columns.entries()) {
146
+ if (!Object.hasOwn(properties, column)) return `${where}.resource.columns[${index}]:spec 里没有字段「${column}」`;
147
+ if (!isScalarSchema(properties[column])) return `${where}.resource.columns[${index}]:字段「${column}」不是标量,须是 string、number、integer 或 boolean`;
148
+ }
149
+ return null;
150
+ }
151
+
131
152
  // `namespace`: the plugin ID a manifest owns definitions under; omitted for core definitions and standalone checks.
132
153
  export function definitionProblem(definition, { namespace = null, where = '协议定义' } = {}) {
133
154
  if (!definitionCheck(definition))
@@ -143,6 +164,8 @@ export function definitionProblem(definition, { namespace = null, where = '协
143
164
  if (recording) return recording;
144
165
  const grouping = permissionsProblem(definition, where);
145
166
  if (grouping) return grouping;
167
+ const resource = resourceProblem(definition, where);
168
+ if (resource) return resource;
146
169
  const parts = protocolHasRecords(definition) ? [['spec', definition.spec], ['status', definition.status]] : [];
147
170
  for (const [operation, value] of Object.entries(definition.operations ?? {})) {
148
171
  parts.push([`operations.${operation}.input`, value.input]);
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://coda.pub/schemas/agent/v1/elicitation-denial.json",
4
+ "type": "object",
5
+ "description": "表单结果须为对象",
6
+ "properties": {
7
+ "_meta": {
8
+ "type": "object",
9
+ "description": "_meta 须为对象",
10
+ "properties": {
11
+ "coda": {
12
+ "type": "object",
13
+ "description": "_meta.coda 须为对象",
14
+ "properties": {
15
+ "reason": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "description": "reason 须为非空字符串,只出现在 action 为 decline 的表单结果里;普通 decline 不带它"
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+ },
25
+ "if": {
26
+ "required": ["_meta"],
27
+ "properties": {"_meta": {"type": "object", "required": ["coda"], "properties": {"coda": {"type": "object", "required": ["reason"]}}}}
28
+ },
29
+ "then": {
30
+ "required": ["action"],
31
+ "properties": {"action": {"const": "decline", "description": "action 须为 decline:_meta.coda.reason 只出现在 decline 的表单结果里"}}
32
+ }
33
+ }
@@ -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 给出默认期限。可写 streams 声明记录流;可写 events 声明协议的事件;可写 permissions 把操作、流、事件与记录的读取分成权限组,供插件在清单里按组申请。写了 events 的定义可以不写 spec、status、operations(没有记录的协议;它不能有非空的 operations、streams,也不能有 read 为真的组);没写 events 时三者必填。",
5
+ "description": "一个协议的名字、记录格式与操作。名字是「命名空间/名字@大版本」;spec、status 与每个操作的输入、结果都是 JSON Schema(draft 2020-12),只引用定义自身的 $defs。操作要么立刻返回结果(result),要么返回运行引用(run: true);只读的立即结果可标 safe: true,可改状态但重发做同一件事的立即结果可标 idempotent: true。操作可写 timeout 给出默认期限。可写 streams 声明记录流;可写 events 声明协议的事件;可写 permissions 把操作、流、事件与记录的读取分成权限组,供插件在清单里按组申请。写了 events 的定义可以不写 spec、status、operations(没有记录的协议;它不能有非空的 operations、streams,也不能有 read 为真的组);没写 events 时三者必填。可写 resource 声明种类在资源列表里的展示(见 resource)。",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "name": {"$ref": "#/$defs/name"},
@@ -33,8 +33,9 @@
33
33
  "propertyNames": {"$ref": "#/$defs/eventName"},
34
34
  "additionalProperties": {"$ref": "#/$defs/event"}
35
35
  },
36
+ "resource": {"$ref": "#/$defs/resource"},
36
37
  "permissions": {
37
- "description": "权限组:组名 → 一组对插件开放的能力。插件在清单的 uses(必需)或 optionalUses(可选)里按组申请,没申请的调用被宿主拒绝;可选权限缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责。每个操作、每条流、每个事件最多属于一组,组里列的操作、流与事件都存在,每组至少管一样东西(有操作、有流、有事件,或 read 为真),有 events 的组不能再有 operations、streams、read 这几个键;没写 spec、status 的协议不能有非空的 operations、streams,也不能有 read 为真的组;这些由 definitionProblem 查。不在任何组里的操作、流和事件不对插件开放,只有 Coda 自己和它的客户端调;不写 permissions 就是整个协议都不分组",
38
+ "description": "权限组:组名 → 一组对插件开放的能力。插件在清单的 uses(必需)或 optionalUses(可选)里按组申请,没申请的调用被宿主拒绝;可选权限缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责。每个操作、每条流、每个事件最多属于一组,组里列的操作、流与事件都存在,每组至少管一样东西(有操作、有流、有事件,或 read 为真),有 events 的组不能再有 operations、streams、read、sessions 这几个键;写了 sessions 的组必须至少有一个操作或一条流(只有 read 不够);没写 spec、status 的协议不能有非空的 operations、streams,也不能有 read 为真的组;这些由 definitionProblem 查。不在任何组里的操作、流和事件不对插件开放,只有 Coda 自己和它的客户端调;不写 permissions 就是整个协议都不分组",
38
39
  "type": "object",
39
40
  "maxProperties": 50,
40
41
  "propertyNames": {"$ref": "#/$defs/operationName"},
@@ -79,16 +80,27 @@
79
80
  },
80
81
  "title": {"description": "给人看的名字", "type": "string", "maxLength": 100, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
81
82
  "description": {"description": "一句话说明", "type": "string", "maxLength": 1000, "pattern": "^(?=.*\\S)[^\\u0000\\r\\n]*$"},
83
+ "resource": {
84
+ "description": "展示声明:写了它的种类成为可列出、可引用的资源。列表里每条按 columns 的顺序显示,第一列是名字;所在机器那一列由宿主自己加,不用写;列名取该字段 schema 的 title,没有就用字段名;只展示这些列与 spec 里带 description 的字段。columns 的每一项都必须是 spec.properties 里声明的字段,且是标量(schema 的 type 是 string、number、integer 或 boolean 之一;type 是数组时去掉 \"null\" 后只剩一种标量也算;有 enum 而无 type 不算);没写 spec 的定义不能写 resource,这些由 definitionProblem 查。不写就和没有这个声明一样",
85
+ "type": "object",
86
+ "properties": {
87
+ "columns": {"type": "array", "minItems": 1, "maxItems": 8, "uniqueItems": true, "items": {"type": "string", "minLength": 1, "maxLength": 64}, "description": "列:spec 的顶层字段名,按显示顺序,第一列是名字;不重复"},
88
+ "symbol": {"type": "string", "minLength": 1, "maxLength": 64, "description": "客户端画的 SF Symbol 名"}
89
+ },
90
+ "required": ["columns"],
91
+ "additionalProperties": false
92
+ },
82
93
  "permissionGroup": {
83
- "description": "一个权限组:title 是给用户看的一句话,说这组让插件能做什么;trial 标这组是试行的;operations 是归这组管的操作;streams 是归这组管的流;events 是归这组管的事件,插件在 uses 或 optionalUses 里写了这组就是订了组里全部事件,有 events 的组只放事件(不能再写 operations、streams、read 这几个键);read 管不管读这个协议的记录(get、list、watch);写记录只许实现方,不分给插件",
94
+ "description": "一个权限组:title 是给用户看的一句话,说这组让插件能做什么;trial 标这组是试行的;operations 是归这组管的操作;streams 是归这组管的流;events 是归这组管的事件,插件在 uses 或 optionalUses 里写了这组就是订了组里全部事件,有 events 的组只放事件(不能再写 operations、streams、read、sessions 这几个键);read 管不管读这个协议的记录(get、list、watch);sessions 为 true 表示这组里的操作与流开放给会话(会话经工具调用),不只是开放给插件,写了 sessions 的组须至少有一个操作或一条流;写记录只许实现方,不分给插件",
84
95
  "type": "object",
85
96
  "properties": {
86
97
  "title": {"$ref": "#/$defs/title"},
87
98
  "trial": {"type": "boolean", "description": "是否试行:只影响展示,不影响能否调用"},
88
99
  "operations": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的操作名,不重复"},
89
100
  "streams": {"type": "array", "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/operationName"}, "description": "归这组管的流名,不重复"},
90
- "events": {"type": "array", "minItems": 1, "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/eventName"}, "description": "归这组管的事件名,不重复;有 events 的组不能再有 operations、streams、read 这几个键"},
91
- "read": {"type": "boolean", "description": "管不管读这个协议的记录(get、list、watch)"}
101
+ "events": {"type": "array", "minItems": 1, "maxItems": 50, "uniqueItems": true, "items": {"$ref": "#/$defs/eventName"}, "description": "归这组管的事件名,不重复;有 events 的组不能再有 operations、streams、read、sessions 这几个键"},
102
+ "read": {"type": "boolean", "description": "管不管读这个协议的记录(get、list、watch)"},
103
+ "sessions": {"type": "boolean", "description": "为 true 表示这组里的操作与流开放给会话(会话经工具调用),不只是开放给插件;写了这个键的组须至少有一个操作或一条流(只有 read 不够),有 events 的组不能写这个键"}
92
104
  },
93
105
  "required": ["title"],
94
106
  "additionalProperties": false
@@ -10,7 +10,7 @@
10
10
  "name": "ProcessProperties",
11
11
  "isAbstract": true,
12
12
  "extends": ["bpmn:Process"],
13
- "description": "流程本身:concurrency 并发、key 未结束运行的业务键、title 运行在卡片上的名字(同 GitHub 的 run-name)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars.<插件>.<设置>(不写为起)、mergedOnly 只运行已合并进默认分支的提交(不写为 false:任何提交都能跑)",
13
+ "description": "流程本身:concurrency 并发、key 未结束运行的业务键、title 运行在卡片上的名字(同 GitHub 的 run-name)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars.<插件>.<设置>(不写为起)、mergedOnly 只运行已合并进默认分支的提交(不写为 false:任何提交都能跑)、questionDenial 运行期间持有这个运行(或它的子运行)里没结束的 agent 任务的会话向用户提问时,宿主当场拒绝并把这段文字回给 Agent(有值才启用;父子运行都声明时,从会话所持任务所在的运行开始往上找,用离它最近的一段,子运行没声明就沿用祖先的声明;权限审批、链接表单、密钥卡、请用户操作桌面与指给用户的流程任务(`coda:assignee=\"user\"`)不拦)",
14
14
  "properties": [
15
15
  {"name": "concurrency", "isAttr": true, "type": "String"},
16
16
  {"name": "key", "isAttr": true, "type": "String"},
@@ -19,7 +19,8 @@
19
19
  {"name": "inline", "isAttr": true, "type": "Boolean"},
20
20
  {"name": "subagents", "isAttr": true, "type": "Boolean"},
21
21
  {"name": "agents", "isAttr": true, "type": "String"},
22
- {"name": "autoRun", "isAttr": true, "type": "String"}, {"name": "mergedOnly", "isAttr": true, "type": "Boolean"}
22
+ {"name": "autoRun", "isAttr": true, "type": "String"}, {"name": "mergedOnly", "isAttr": true, "type": "Boolean"},
23
+ {"name": "questionDenial", "isAttr": true, "type": "String"}
23
24
  ]
24
25
  },
25
26
  {
@@ -11,6 +11,7 @@
11
11
  "key": {"type": "string", "pattern": "\\S", "maxLength": 4000, "x-feel": {"names": ["inputs", "github", "vars"]}, "description": "coda:key 须为 1–4000 个字符"},
12
12
  "title": {"type": "string", "pattern": "\\S", "maxLength": 200, "x-feel": true, "description": "coda:title 须为 1–200 个字符"},
13
13
  "mergedOnly": {"type": "boolean", "description": "coda:mergedOnly 只能是 true 或 false"},
14
+ "questionDenial": {"type": "string", "pattern": "\\S", "maxLength": 2000, "description": "coda:questionDenial 须为 1–2000 个字符(不想拦提问就不写)"},
14
15
  "agents": {"type": "string", "pattern": "^[\\s,]*[a-z][a-z0-9-]{0,39}(?:[\\s,]+[a-z][a-z0-9-]{0,39})*[\\s,]*$",
15
16
  "description": "coda:agents 写 Agent 的 ID,用逗号或空格分隔(小写字母、数字和「-」,以字母开头,至多 40 个字符),不能为空"},
16
17
  "autoRun": {"type": "string", "anyOf": [{"enum": ["true", "false"]}, {"pattern": "^\\s*=\\s*vars(\\.[A-Za-z_][A-Za-z0-9_-]*)+\\s*$"}], "x-feel": {"names": ["vars"]},