@coda-console/protocol 6.31.0 → 6.33.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,23 @@
2
2
 
3
3
  版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
4
4
 
5
+ ## 6.33.0 — 2026-12-01
6
+
7
+ - 这是在 6.32.0 之上的次版本。依据 README「版本」一节:模块的 `coda` 对象与清单的 `contributes` 键属于内部面,只加可选的成员、类型与键,升次版本;`stable/` 不动,旧清单、旧插件一律照旧(`node scripts/stable-grows.mjs npm:latest` 通过)。为 Coda 的「去中心化空间模型路由」基座原语补齐协议:本机作用域的逻辑模型服务,以及查询全空间物理模型服务的模块接口。
8
+ - `schemas/plugin/model-providers.json`:每项新增可选的 `scope`(`space` 或 `local`,省略即 `space`)。`space` 是发布为空间里这台机器的物理模型服务;`local` 只在本机作为不带机器哈希的稳定名逻辑入口提供,不进空间目录、不跨机交付,其本机回环地址可在运行时经 `coda.modelServices.registerLocal()` 登记。`url` 不再无条件必填:`scope` 省略或为 `space` 时仍必填(行为与原来一致,错误说「缺 url:scope 省略或为 space 时 url 必填」),`scope` 为 `local` 时可写可不写;用 `if/then/else` 写成(`required` 只剩 `id`、`title`、`api`)。`key` 不受 `scope` 限制,只在 description 里说明 `local` 入口通常不配 `key`。`scope` 为别的值被拒绝。
9
+ - `./types`(`plugin.d.mts`):`Coda` 新增 Trial 成员 `modelServices`:`listPhysical(options?: { api?: ModelServiceApi })`(只列 `scope` 为 `space` 的物理模型服务,不含 `local`)、`registerLocal(id, { url, revision? })`(登记本插件声明的 `scope: "local"` 模型服务的运行时本机地址与模型目录 revision,回答 `LocalModelServiceHandle`)、`onPhysicalChanged(fn)`(物理模型服务列表变化时回调,回答 `Disposable`)。新增导出 `ModelServiceApi`、`PhysicalModelService`(`kind`、`id`、`name`、`owner`、`location`、`ref`、`title`、`url`、`path`、`stamp`、`local`、`offline`、`heardAt`)、`LocalModelServiceHandle`(继承 `Disposable`;`id`、`api`、`name`、`service` 只读,`update({ url?, revision? })`,仅地址或 revision 变了才触发刷新)。
10
+ - 文档:`docs/protocol.md` 在 `friendStreams` 之后写 `modelProviders` 的 `scope` 与 `coda.modelServices`;README 的类型清单同步。
11
+
12
+ ## 6.32.0 — 2026-12-01
13
+
14
+ - 这是在 6.31.0 之上的次版本。依据 README「版本」一节:模块的 `coda` 对象与清单的 `contributes` 键属于内部面,只加可选的成员、类型与键,升次版本;`stable/` 不动,旧清单、旧插件一律照旧。对应 Coda 的 API Level 28(需求分支 `req/67644b48-4e15-47a4-a9a2-17235870c476`)。
15
+ - `./types`(`plugin.d.mts`):`Coda` 新增 `openStream(record, name, options?)`(以插件的身份打开一条记录的流,本机的、空间里别台的、经 `coda/accord@1` 的流 `friend` 的好友的都行,回答 Web 标准的 `Response`)与 `spawnAgent(agent, { cwd, signal? })`(起这台机器上已装的 Agent 程序,回答 `Process`);新增导出 `OpenStreamOptions`(`method`、`suffix`、`search`、`headers`、`body`、`signal`)。
16
+ - `./types`:流处理函数的 `caller` 多了一种好友 `{ friend: { author, channel, scope } }`,只出现在对好友开放的流,不带 `machine`、`plugin`、`parent`。新增导出 `FriendCaller`、`ServiceCaller`(原 `StreamCaller` 的三种);`StreamCaller` 现为 `ServiceCaller | FriendCaller`,`StreamContext.caller` 是它,`ServeContext.caller`(`coda.serve`,好友到不了)改用 `ServiceCaller`,形状与原来相同。读 `StreamCaller` 的插件用 `'friend' in caller` 先分出好友(别的分支上没有 `friend`,直接写 `caller.friend` 编译不过)。
17
+ - `Coda.openStream` 与 `Coda.spawnAgent` 的注释写明权限口径(同 Coda 文档「用到的权限」):`openStream` 打开的协议是插件自己定义(`contributes.protocols`)或生效实现的,直接放行,Coda 自己维护、记录只在本机的协议(`coda/accord@1`、`coda/plugin@1` 等)除外;否则要在清单 `uses` 或 `optionalUses` 里写了含这条流的权限组,不在任何组里的流对插件不开放;向好友开流是 `coda/accord@1` 的 `friend-streams`。`spawnAgent` 的协议 `coda/plugin@1` 属于除外的那些,只看 `uses` 或 `optionalUses` 里有没有 `spawn-agent`。
18
+ - 清单 `contributes.friendStreams`(`schemas/plugin/friend-streams.json`,作公开数据放在包里,**不**接进通用清单 `plugin.json`、不在 `TYPES` 里,同 `agents`、`modelProviders`、`gitCredentials`、`repositories`:由登记这个键的 Coda 贡献点引用 `SCHEMAS['friend-streams.json']`,用 `contributionProblem` 校验;`manifestProblem` 不查它):每项 `{ kind, streams }`,`kind` 是协议名,同一种类只写一项,至多 100 项;`streams` 是 1 到 64 个不重复的流名;不收别的键。只校验形状,没有跨键规则。同一个键因此只有包里这一份 schema。`ManifestContributions` 加可选的 `friendStreams`。这个键暂不进稳定面。
19
+ - 文档:`docs/protocol.md` 在 `optionalProtocolImplementations`、`reservedAccordKinds` 之后写 `friendStreams`;README 的清单键与类型清单同步。
20
+ - 没有补的:权限组 `coda/accord@1` 的 `friend-streams`、`coda/plugin@1` 的 `spawn-agent` 与 `coda/accord@1` 的流 `friend`。这两个协议由 Coda 自己登记,定义不在本包里(本包没有它们的协议定义、权限组清单),所以这里不新开一类。
21
+
5
22
  ## 6.31.0 — 2026-11-30
6
23
 
7
24
  - 这是在 6.30.0 之上的次版本。依据 README「版本」一节:Agent 接入协议是内部面,新增一条可选的扩展请求与一个能力声明升次版本;`stable/` 不动,清单 schema 没改,既有的 `_coda/wait`、`compact`、`_session/steering` 字段与语义不变,旧用法一律照旧。
package/README.md CHANGED
@@ -2,7 +2,7 @@
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`、`optionalProtocolImplementations`、`reservedAccordKinds`、`records`);`setting.json` 是一项设置的声明。其余键由 Coda 的贡献点登记表声明:Coda 自己的(`agents`、`composerModes`、`modelProviders` 等)的 schema 仍放在这里作公开数据(如 `agents.json`、`composer-modes.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
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`、`friend-streams.json`),由登记它的 provider 引用;`contributes` 里只有 Coda 认得的键。
6
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` 负责跨节点检查。
@@ -127,7 +127,7 @@ optionsProblem([{ id: 'release', name: '发布正式版', default: false, inputs
127
127
 
128
128
  ## 插件的类型
129
129
 
130
- `@coda-console/protocol/types`(`plugin.d.mts`)是插件模块的公开 TypeScript 类型:调用与处理(`Context`、`Handler`、`Caller`)、记录(`Ref`、`KeyRef`、`RecordValue`、`RecordFilter`、`RecordChange`)、页面(`ViewInstance`)和模块里的 `coda` 对象(`Coda`)等。它们属于内部面,随 Coda 的版本可能变。TypeScript 与 `// @ts-check` 的 JSDoc 都能解析(`moduleResolution` 为 `node16`、`nodenext` 或 `bundler`):
130
+ `@coda-console/protocol/types`(`plugin.d.mts`)是插件模块的公开 TypeScript 类型:调用与处理(`Context`、`Handler`、`Caller`)、记录(`Ref`、`KeyRef`、`RecordValue`、`RecordFilter`、`RecordChange`)、记录的流(`StreamCaller`、`FriendCaller`、`OpenStreamOptions`)、模型服务(`ModelServiceApi`、`PhysicalModelService`、`LocalModelServiceHandle`)、页面(`ViewInstance`)和模块里的 `coda` 对象(`Coda`)等。它们属于内部面,随 Coda 的版本可能变。TypeScript 与 `// @ts-check` 的 JSDoc 都能解析(`moduleResolution` 为 `node16`、`nodenext` 或 `bundler`):
131
131
 
132
132
  ```js
133
133
  // @ts-check
@@ -181,7 +181,7 @@ agentValueProblem('review.json', review, '工具的审核');
181
181
  ## 协议定义与核心协议
182
182
 
183
183
  从 3.0.0 起,协议是 `命名空间/名字@大版本` + 记录格式(spec、status 的 JSON Schema)+ 操作,见[协议正文](docs/protocol.md)。
184
- 插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责);`contributes.optionalProtocolImplementations` 列可选实现的协议(本机没有这个协议时插件照常运行、这一项不生效),`contributes.reservedAccordKinds` 声明只归本插件的 Accord 签名记录种类(命名空间须是插件 ID);这两个键协议包只校验形状与两条跨键规则(可选实现不与 `protocolImplementations` 重复、保留种类的命名空间等于插件 ID),协议在不在、谁被拒绝由 Coda 宿主判定;
184
+ 插件用 `contributes.protocols` 定义自己命名空间下的协议,用 `contributes.protocolImplementations` 声明实现哪些协议,用根上的 `uses` 申请别的协议的权限组(必需),用 `optionalUses` 声明可选用到的权限组(对应协议或提供方缺席时不阻止插件运行,可用性判定与鉴权由 Coda 宿主负责);`contributes.optionalProtocolImplementations` 列可选实现的协议(本机没有这个协议时插件照常运行、这一项不生效),`contributes.reservedAccordKinds` 声明只归本插件的 Accord 签名记录种类(命名空间须是插件 ID);`contributes.friendStreams` 声明本插件持有的记录里哪个种类的哪几条流也对绑定着的好友开放(它的 schema 是 `friend-streams.json`,不在通用清单里,由 Coda 的贡献点登记引用,同 `agents` 等;`manifestProblem` 不查它,`contributionProblem` 查,只校验形状);前两个键协议包只校验形状与两条跨键规则(可选实现不与 `protocolImplementations` 重复、保留种类的命名空间等于插件 ID),协议在不在、谁被拒绝由 Coda 宿主判定;
185
185
  命名空间 `coda` 保留给核心协议。
186
186
 
187
187
  - **`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
@@ -364,6 +364,29 @@ const body = writeFrames(frames, { heartbeatMs: 15000 });
364
364
 
365
365
  这两个键协议包只校验形状与上面两条跨键规则;协议在不在、这一项生不生效、谁被拒绝由 Coda 宿主判定。
366
366
 
367
+ `contributes.friendStreams` 声明插件持有的记录里,哪个种类的哪几条流也对此刻绑定着的好友(空间之外、与本机互认的节点)开放:
368
+
369
+ ```json
370
+ "friendStreams": [{"kind": "my-plugin/box@1", "streams": ["draft", "lines"]}]
371
+ ```
372
+
373
+ - 数组,至多 100 项,每项 `{ kind, streams }`,不收别的键。`kind` 是协议名,同一种类只写一项;`streams` 是 1 到 64 个不重复的流名(格式同定义里 `streams` 的键)。不写就是都不开放。
374
+ - 它的 schema 是 `schemas/plugin/friend-streams.json`,不在通用清单 `plugin.json` 里(同 `agents`、`modelProviders` 等 Coda 自己的键):由登记这个键的 Coda 组件引用,用 `contributionProblem` 在整份清单里查;`manifestProblem` 对它不作判断。
375
+ - 这里只校验形状:没有跨键规则,`kind` 不要求写在 `protocolImplementations` 里,流在不在协议定义里也不在这里查。只对本插件持有的记录起作用、后端怎么放行好友、`ctx.caller.friend` 的内容,都由 Coda 宿主定;好友能不能用由流的处理函数自己判。
376
+
377
+ `contributes.modelProviders` 声明插件提供的模型服务(`schemas/plugin/model-providers.json`,不在通用清单 `plugin.json` 里,由登记这个键的 Coda 组件引用),6.33.0 起每项可写 `scope`:
378
+
379
+ ```json
380
+ "modelProviders": [
381
+ {"id": "main", "title": "主力模型", "api": "openai-completions", "url": "${config:kit.url}", "key": "${config:kit.key}"},
382
+ {"id": "router", "title": "模型路由", "api": "openai-completions", "scope": "local"}
383
+ ]
384
+ ```
385
+
386
+ - `scope` 是 `space` 或 `local`,省略即 `space`。`space`:发布为空间里这台机器的物理模型服务,`url` 必填,与 6.32.0 及以前完全一致。`local`:只在本机作为不带机器哈希的稳定名逻辑入口提供,不进空间目录、不跨机交付;`url` 可以不写,模块运行时用 `coda.modelServices.registerLocal(id, { url, revision? })` 登记本机的回环地址与模型目录 revision;写了就是静态地址。
387
+ - `key` 不受 `scope` 限制;`local` 入口通常不配 `key`。其余键与形状不变。
388
+ - 模块里的 `coda.modelServices`(Trial):`listPhysical({ api? })` 列空间里全部物理模型服务(只含 `scope` 为 `space` 的,绝不含 `local`),`registerLocal` 登记本插件的 `local` 入口,`onPhysicalChanged` 在列表变化时回调;类型见 `PhysicalModelService`、`LocalModelServiceHandle`。
389
+
367
390
  `contributes.records` 声明哪些种类的记录由命令给出,每种一项,至多 20 项:
368
391
 
369
392
  ```json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coda-console/protocol",
3
- "version": "6.31.0",
3
+ "version": "6.33.0",
4
4
  "description": "Coda 的协议:插件清单的类型(JSON Schema)、通用校验器、协议定义与调用信封、流程方言与 Agent 接入协议",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/plugin.d.mts CHANGED
@@ -69,7 +69,7 @@ export interface CallOptions {
69
69
  * The page's opener (`device`, `name`, `local`) is relayed by the originating backend as well.
70
70
  *
71
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,
72
+ * branch of `Caller` and `StreamCaller` but a friend's (`FriendCaller`, which has neither), so `'machine' in caller` and `'plugin' in caller` no longer tell the branches apart,
73
73
  * and TypeScript types the field as `string | undefined` after such a check. Tell this machine's own client (`local`), a
74
74
  * device (`device`, and `role` of a `StreamCaller`) and a plugin by those fields and the values of `machine` and `plugin`.
75
75
  * The two mean the same on every branch: `machine` is always the ID of the backend the call was made from, which the
@@ -136,18 +136,44 @@ export interface Context {
136
136
  /** Its return value is the result; what it throws, the failure (`coda.error`, or anything else as `handler_error`). */
137
137
  export type Handler = (input: Json, ctx: Context) => Json | Promise<Json>;
138
138
  /**
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,
140
- * of one sent on), or a plugin (by its token, or from its page; a stream's only).
139
+ * Who asks a service: this machine's own client or tools, a device, another backend of the space (the last hop, of one sent
140
+ * on), or a plugin (by its token, or from its page).
141
141
  */
142
- export type StreamCaller = ({ local: true } | { device: string; role: 'client' | 'backend'; name?: string } | { plugin: string }) & CallerOrigin;
142
+ export type ServiceCaller = ({ local: true } | { device: string; role: 'client' | 'backend'; name?: string } | { plugin: string }) & CallerOrigin;
143
+ /**
144
+ * A friend (outside the space, bound to this machine now) who asks a stream the plugin has opened to friends
145
+ * (`contributes.friendStreams`). All three are of the binding the host matched the request to, never what the request says
146
+ * of itself.
147
+ */
148
+ export interface FriendCaller {
149
+ friend: {
150
+ /** The author's public key the friend is bound as now (`ed25519:…`). */
151
+ author: string;
152
+ /** The channel's identity: `link:<link ID>` or `node:<node ID>`. */
153
+ channel: string;
154
+ /** The scope the binding was admitted in (`coda-space/…`, `coda-tailnet/…`, or the one given when the link was registered). */
155
+ scope: string;
156
+ };
157
+ /** A friend's call carries no `CallerOrigin`. */
158
+ machine?: never;
159
+ plugin?: never;
160
+ parent?: never;
161
+ }
162
+ /**
163
+ * Who asks a stream: any of those who ask a service, or a friend (`friend`), which only a stream the plugin has opened to
164
+ * friends is asked by. A friend is none of the others: there is no `local`, `device` or `plugin` on it, nor `machine` or
165
+ * `parent`. The host does not ask whether the friend may use the stream; the handler does, by `friend.author` as a rule.
166
+ */
167
+ export type StreamCaller = ServiceCaller | FriendCaller;
143
168
  /** What a handler of a service (`coda.serve`) is given beside its request. */
144
169
  export interface ServeContext {
145
- caller: StreamCaller;
170
+ caller: ServiceCaller;
146
171
  /** Goes off when the caller leaves before the answer is done; `request.signal` goes off with it. */
147
172
  signal: AbortSignal;
148
173
  }
149
174
  /** What a handler of a record's stream (`coda.stream`) is given beside its request. */
150
- export interface StreamContext extends ServeContext {
175
+ export interface StreamContext extends Omit<ServeContext, 'caller'> {
176
+ caller: StreamCaller;
151
177
  /** The record the stream is of; with its `key` when it is this plugin's own. */
152
178
  record: HandledRef;
153
179
  /** Its parameters, from the query string, as the definition's `input` has them; none (`{}`) of an `http` stream. */
@@ -221,6 +247,22 @@ export interface Process {
221
247
  kill(signal?: string): void;
222
248
  }
223
249
 
250
+ /** How `openStream` asks a record's stream. */
251
+ export interface OpenStreamOptions {
252
+ /** `GET` or `POST`; by default `POST` with a `body`, else `GET`. */
253
+ method?: 'GET' | 'POST';
254
+ /** What is below the stream's path: none, or from its `/` on (an `http` stream's only); any other is refused, nothing sent. */
255
+ suffix?: string;
256
+ /** The query string: none, or from its `?` on: a `read` or `write` stream's parameters, an `http` stream's subprotocol's; any other is refused, nothing sent. */
257
+ search?: string;
258
+ /** Of these only those of content and negotiation are sent; with no `Content-Type`, the one the body's encoding gives (a form's boundary in it). */
259
+ headers?: Record<string, string>;
260
+ /** The request's body, as a `Response` takes one; sent as it is read. */
261
+ body?: BodyInit | null;
262
+ /** Gone off, whether waiting to be answered or reading the body, the stream ends with its reason. */
263
+ signal?: AbortSignal;
264
+ }
265
+
224
266
  export interface Settings {
225
267
  /** This plugin's own settings as they are now (secrets are not among them); asked each time. */
226
268
  get(): Promise<Json>;
@@ -304,6 +346,8 @@ export interface Coda {
304
346
  * effect if it never started, of `unknown` if it started and could not be registered (killed with its group at once).
305
347
  */
306
348
  spawn(command: string, args?: string[], options?: SpawnOptions): Promise<Process>;
349
+ /** Starts an agent installed on this machine (manifest `uses` or `optionalUses`: `"coda/plugin@1": ["spawn-agent"]`; with neither it fails as `forbidden`, nothing started); the process has only its own plugin's environment and ends with this generation of the module. */
350
+ spawnAgent(agent: string, options: { cwd: string; signal?: AbortSignal }): Promise<Process>;
307
351
  /**
308
352
  * Serves the plugin's own bytes at `/v1/plugins/<plugin>/services/<id>/…`, any method a standard
309
353
  * `Request` takes: all but `CONNECT`, `TRACE` and `TRACK`. Done once Coda has it; the handle's
@@ -316,6 +360,16 @@ export interface Coda {
316
360
  * has; otherwise it throws at once. Done once Coda has it; `dispose()` as `serve`'s.
317
361
  */
318
362
  stream(kind: string, name: string, handler: StreamHandler): Promise<{ dispose(): Promise<void> }>;
363
+ /**
364
+ * Opens a record's stream as this plugin, wherever the record is held (here, on another backend of the space, or, through
365
+ * `coda/accord@1`'s stream `friend`, on a friend's): the stream's own `Response`, its body as it comes. Allowed when the
366
+ * protocol is one the plugin defines (`contributes.protocols`) or implements in force here, but for those only this machine
367
+ * keeps (Coda's `coda/accord@1`, `coda/plugin@1`, …), which implementing does not make the plugin's; else only when a
368
+ * group of the protocol that has the stream is in the manifest's `uses` or `optionalUses` (a stream in no group is open
369
+ * to no plugin; a friend's, `coda/accord@1`'s `friend-streams`). A refusal before the first byte fails with a `CallError`, its `effects` as the one refusing said them; a body
370
+ * broken off midway errors as `interrupted`; `options.signal` gone off, with its reason.
371
+ */
372
+ openStream(record: Ref, name: string, options?: OpenStreamOptions): Promise<Response>;
319
373
  /** Frame streams: ndjson, one JSON object a line, a blank line a heartbeat. As `@coda-console/protocol/frames` has them. */
320
374
  frames: Readonly<{
321
375
  /** The frames of a body, heartbeats skipped; fails with `code` `truncated`, `too_large` (a line over `maxBytes`, by default 1 MiB) or `invalid`. */
@@ -386,6 +440,62 @@ export interface Coda {
386
440
  tell(session: string, text: string): Promise<{ told: boolean }>;
387
441
  /** Trial. Runs an installed plugin's environment setup again, asked as this plugin. */
388
442
  pluginSetup: Readonly<{ retry(plugin: string): Promise<Json> }>;
443
+ /**
444
+ * Trial. Model services of the space. `listPhysical` lists the physical ones (`scope: "space"` in a plugin's
445
+ * `contributes.modelProviders`, or omitted), of every machine of the space, as this machine reaches them; never a `scope: "local"` one.
446
+ * `registerLocal` gives the address a `scope: "local"` provider the plugin declares runs at on this machine (a loopback one, which stands for the
447
+ * manifest's `url` if it has none) and the revision of its model catalog. `onPhysicalChanged` calls back when the list changes.
448
+ */
449
+ modelServices: Readonly<{
450
+ listPhysical(options?: { api?: ModelServiceApi }): Promise<PhysicalModelService[]>;
451
+ registerLocal(id: string, entry: { url: string; revision?: string }): LocalModelServiceHandle;
452
+ onPhysicalChanged(fn: () => void): Disposable;
453
+ }>;
454
+ }
455
+
456
+ /** The interfaces a model service speaks, as `contributes.modelProviders[].api` has them. */
457
+ export type ModelServiceApi = 'openai-completions' | 'openai-responses' | 'anthropic-messages' | 'openai-speech';
458
+
459
+ /** A physical model service of the space (`scope: "space"`): one a machine of the space publishes, as this machine reaches it. */
460
+ export interface PhysicalModelService {
461
+ kind: ModelServiceApi;
462
+ /** The physical resource's UUID. */
463
+ id: string;
464
+ /** The full setting name, `models/s-…`. */
465
+ name: string;
466
+ /** The ID of the backend that holds it. */
467
+ owner: string;
468
+ /** The display name of the machine it is on. */
469
+ location: string;
470
+ /** `<plugin>/<id>`: the plugin that provides it and its ID in that plugin's `contributes.modelProviders`. */
471
+ ref: string;
472
+ /** Its display title. */
473
+ title: string;
474
+ /** The base URL of this machine's own proxy to it; callable at once with a placeholder credential. */
475
+ url: string;
476
+ /** The prefix of the paths a client asks, such as `/v1`, or `""`. */
477
+ path: string;
478
+ /** The model catalog's cache stamp. */
479
+ stamp: string;
480
+ /** Whether it is on this machine. */
481
+ local: boolean;
482
+ /** Whether its holder is offline now (a hint). */
483
+ offline: boolean;
484
+ /** When its holder was last heard from (ms since the epoch); `null` when it is on this machine or not known. */
485
+ heardAt: number | null;
486
+ }
487
+
488
+ /** What `modelServices.registerLocal` gives back: the handle of one local model service; `dispose()` withdraws it. */
489
+ export interface LocalModelServiceHandle extends Disposable {
490
+ /** The provider's ID in the manifest. */
491
+ readonly id: string;
492
+ readonly api: ModelServiceApi;
493
+ /** The same on every machine: the stable setting name, `models/l-…`. */
494
+ readonly name: string;
495
+ /** This machine's usage identity of it, `coda://<api>/<uuid>`, for what folds usage by service (a token ranking, say). */
496
+ readonly service: string;
497
+ /** Changes the address it runs at, or its model catalog's `revision`; a refresh follows only when one of the two differs from what it was. */
498
+ update(entry: { url?: string; revision?: string }): void;
389
499
  }
390
500
 
391
501
  /** The record or draft a protocol hands a contributor, without who created it: its `spec` and `status` are objects the protocol's schemas describe. */
@@ -425,7 +535,7 @@ export interface ViewInstance {
425
535
  }
426
536
 
427
537
  /**
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
538
+ * The keys of the manifest's `contributes` that are typed here: only these three so far, the rest of the manifest has no type
429
539
  * 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
540
  */
431
541
  export interface ManifestContributions {
@@ -433,4 +543,6 @@ export interface ManifestContributions {
433
543
  optionalProtocolImplementations?: string[];
434
544
  /** Accord signature record kinds (`namespace/name`, the namespace the plugin's own ID) that only this plugin may publish, revoke or read. */
435
545
  reservedAccordKinds?: string[];
546
+ /** Which streams of the records this plugin holds are open to friends as well, a kind (`namespace/name@major`) once, up to 100; the handler decides which friend may use one (`ctx.caller.friend`). */
547
+ friendStreams?: { kind: string; streams: string[] }[];
436
548
  }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://coda.pub/schemas/plugin/v2/friend-streams.json",
4
+ "title": "contributes.friendStreams:对好友开放的记录的流",
5
+ "description": "插件持有的记录里,哪个种类的哪几条流也对此刻绑定着的好友(空间之外、与本机互认的节点)开放:数组,每项 { kind, streams },同一种类只写一项,至多 100 项;streams 是 1 到 64 个不重复的流名。不写就是都不开放。只对本插件持有的记录起作用;好友能不能用、能用到哪由流的处理函数自己判。协议、流在不在由 Coda 宿主判定,这里只管清单形状。",
6
+ "type": "array",
7
+ "maxItems": 100,
8
+ "x-unique-by": ["kind"],
9
+ "items": {
10
+ "type": "object",
11
+ "properties": {
12
+ "kind": {"description": "协议名「命名空间/名字@大版本」;同一种类只写一项", "$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/name"},
13
+ "streams": {
14
+ "description": "对好友开放的流名,1 到 64 个,不重复",
15
+ "type": "array",
16
+ "minItems": 1,
17
+ "maxItems": 64,
18
+ "uniqueItems": true,
19
+ "items": {"$ref": "https://coda.pub/schemas/protocol/v1/definition.json#/$defs/operationName"}
20
+ }
21
+ },
22
+ "required": ["kind", "streams"],
23
+ "additionalProperties": false
24
+ }
25
+ }
@@ -14,6 +14,10 @@
14
14
  "description": "接口:openai-completions、openai-responses、anthropic-messages、openai-speech",
15
15
  "enum": ["openai-completions", "openai-responses", "anthropic-messages", "openai-speech"]
16
16
  },
17
+ "scope": {
18
+ "description": "scope 是 space(省略即 space)或 local:space 是发布为空间里这台机器的物理模型服务,url 必填;local 只在本机作为不带机器哈希的稳定名逻辑入口提供,不进空间目录、不跨机交付,url 可以不写,运行时经 coda.modelServices.registerLocal() 登记本机回环地址;local 入口通常不配 key",
19
+ "enum": ["space", "local"]
20
+ },
17
21
  "url": {
18
22
  "description": "一行地址,只能引用本插件的单值设置(${config:<设置名>},不能是密文)",
19
23
  "type": "string",
@@ -32,7 +36,9 @@
32
36
  }
33
37
  }
34
38
  },
35
- "required": ["id", "title", "api", "url"],
39
+ "required": ["id", "title", "api"],
40
+ "if": {"properties": {"scope": {"const": "local"}}, "required": ["scope"]},
41
+ "else": {"description": "scope 省略或为 space 时 url 必填", "required": ["url"]},
36
42
  "additionalProperties": false
37
43
  },
38
44
  "x-unique-by": ["id"]