@capybara-hq/plugin-sdk 0.1.0-rc.26 → 0.1.0-rc.28

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.
Files changed (48) hide show
  1. package/agent-docs/extension-points/model-provider.md +1 -1
  2. package/dist/cards.d.ts +17 -8
  3. package/dist/cards.js +21 -10
  4. package/dist/channel.d.ts +91 -47
  5. package/dist/channel.js +10 -5
  6. package/dist/connector-auth.d.ts +5 -2
  7. package/dist/connector-auth.js +14 -8
  8. package/dist/connector.d.ts +67 -32
  9. package/dist/ctx.d.ts +41 -23
  10. package/dist/define-extension.d.ts +21 -11
  11. package/dist/define-extension.js +10 -4
  12. package/dist/device-protocol.d.ts +2 -1
  13. package/dist/extension-point.js +1 -1
  14. package/dist/identity.d.ts +22 -9
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/model-params.d.ts +41 -22
  18. package/dist/model-params.js +28 -15
  19. package/dist/model.d.ts +96 -64
  20. package/dist/model.js +25 -14
  21. package/dist/permissions.d.ts +6 -6
  22. package/dist/permissions.js +8 -32
  23. package/dist/plugin-package.d.ts +79 -38
  24. package/dist/plugin-package.js +57 -29
  25. package/dist/sandbox-linux-runtime-source.d.ts +15 -0
  26. package/dist/sandbox-linux-runtime-source.js +1421 -0
  27. package/dist/sandbox-runtime-source.d.ts +9 -3
  28. package/dist/sandbox-runtime-source.js +16 -4
  29. package/dist/sandbox.d.ts +4 -1
  30. package/dist/sandbox.js +7 -3
  31. package/dist/secret.d.ts +4 -1
  32. package/dist/secret.js +4 -1
  33. package/dist/setup-guide.d.ts +1 -1
  34. package/dist/setup-guide.js +1 -1
  35. package/dist/skill.d.ts +27 -17
  36. package/dist/skill.js +39 -25
  37. package/dist/storage.d.ts +45 -25
  38. package/dist/tool.d.ts +51 -23
  39. package/dist/tool.js +21 -9
  40. package/dist/ui-resolve.d.ts +2 -7
  41. package/dist/ui-resolve.js +7 -19
  42. package/dist/ui-slots.d.ts +1 -3
  43. package/dist/ui-slots.js +0 -9
  44. package/dist/ui.d.ts +63 -49
  45. package/dist/ui.js +36 -22
  46. package/dist/url.d.ts +4 -1
  47. package/dist/url.js +4 -1
  48. package/package.json +1 -1
@@ -1,16 +1,19 @@
1
1
  import type { ZodTypeAny } from "zod";
2
2
  import type { FormAnswer, ToolContent, ToolResult, ToolSpec } from "./tool.js";
3
- /** 注入到出站请求的鉴权信息。 */
3
+ /** Authentication information injected into outbound requests. */
4
4
  export interface AuthInjection {
5
5
  headers: Record<string, string>;
6
6
  query?: Record<string, string>;
7
7
  }
8
- /** 连接器与远端服务的一次会话。 */
8
+ /** One session between the connector and the remote service. */
9
9
  export interface ConnectorSession {
10
10
  listTools(): Promise<ToolSpec[]>;
11
11
  /**
12
- * `ctx.spec`:内核快照里该工具已复核的定义(`connector_tools.spec`,绝不是待复核的新定义),含 listTools 时给出的
13
- * `connectorData`。连接器应按它路由调用,而不是重新读取远端描述(远端变化须先经漂移复核)。旧内核不传,须判空。
12
+ * `ctx.spec`: the already-reviewed definition of this tool in the kernel snapshot
13
+ * (`connector_tools.spec`, never a new definition awaiting review), including the `connectorData`
14
+ * given at listTools.
15
+ * The connector should route the call by it rather than re-reading the remote description (remote
16
+ * changes must pass drift review first). Old kernels do not pass it; check for absence.
14
17
  */
15
18
  callTool(name: string, input: unknown, signal: AbortSignal, ctx?: {
16
19
  spec: ToolSpec;
@@ -22,13 +25,19 @@ export interface ConnectorSession {
22
25
  mimeType?: string;
23
26
  }[]>;
24
27
  readResource?(uri: string): Promise<ToolResult>;
25
- /** 可选:远端提供的提示模板(如 MCP prompts)。不支持时不实现,内核须判空。 */
28
+ /**
29
+ * Optional: prompt templates the remote provides (e.g. MCP prompts). Do not implement when
30
+ * unsupported; the kernel must check for absence.
31
+ */
26
32
  listPrompts?(): Promise<PromptInfo[]>;
27
- /** 可选:按参数渲染一个提示模板,返回消息(如 MCP `prompts/get`)。失败抛 ToolError(英文、不含凭据)。 */
33
+ /**
34
+ * Optional: renders a prompt template with arguments and returns messages (e.g. MCP
35
+ * `prompts/get`). On failure throw ToolError (English, no credentials).
36
+ */
28
37
  getPrompt?(name: string, args: Record<string, string>): Promise<RenderedPrompt>;
29
38
  close(): Promise<void>;
30
39
  }
31
- /** 远端提示模板(`/连接器:提示名` 斜杠命令)。 */
40
+ /** A remote prompt template (the `/connector:promptName` slash command). */
32
41
  export interface PromptInfo {
33
42
  name: string;
34
43
  title?: string;
@@ -39,7 +48,10 @@ export interface PromptInfo {
39
48
  required?: boolean;
40
49
  }[];
41
50
  }
42
- /** 渲染后的提示:按顺序的消息,内容块同工具结果(非文本给类型说明)。 */
51
+ /**
52
+ * A rendered prompt: messages in order, content blocks the same as tool results (non-text gets a
53
+ * type description).
54
+ */
43
55
  export interface RenderedPrompt {
44
56
  description?: string;
45
57
  messages: {
@@ -48,9 +60,11 @@ export interface RenderedPrompt {
48
60
  }[];
49
61
  }
50
62
  /**
51
- * 远端在一次调用中途向用户要输入(MCP `elicitation/create`):
52
- * - `form`:`requestedSchema` 是远端给的扁平 JSON Schema(object + 原始类型属性),由内核映射成交互表单;
53
- * - `url`:请用户在浏览器里打开 `url` 完成某步(授权、付款、填敏感信息),完成与否由用户确认。
63
+ * The remote asks the user for input in the middle of a call (MCP `elicitation/create`):
64
+ * - `form`: `requestedSchema` is the flat JSON Schema the remote gives (object + primitive-typed
65
+ * properties), which the kernel maps to an interactive form;
66
+ * - `url`: asks the user to open `url` in a browser to complete a step (authorization, payment,
67
+ * entering sensitive information); the user confirms whether it was completed.
54
68
  */
55
69
  export type ElicitationRequest = {
56
70
  mode: "form";
@@ -62,7 +76,10 @@ export type ElicitationRequest = {
62
76
  url: string;
63
77
  elicitationId: string;
64
78
  };
65
- /** 对 elicitation 的答复(与 MCP `ElicitResult` 对应):接受(带表单内容)/ 拒绝 / 取消。 */
79
+ /**
80
+ * The reply to an elicitation (corresponds to MCP `ElicitResult`): accept (with form content) /
81
+ * decline / cancel.
82
+ */
66
83
  export type ElicitationResponse = {
67
84
  action: "accept";
68
85
  content?: FormAnswer;
@@ -71,18 +88,21 @@ export type ElicitationResponse = {
71
88
  } | {
72
89
  action: "cancel";
73
90
  };
74
- /** 内核打开会话时传给连接器的参数。 */
91
+ /** Parameters the kernel passes to the connector when it opens a session. */
75
92
  export interface ConnectorOpenArgs {
76
- /** 已按 endpointSchema 校验。 */
93
+ /** Already validated against endpointSchema. */
77
94
  endpoint: unknown;
78
- /** 每次请求前调用,凭据的刷新由内核负责。 */
95
+ /** Called before every request; refreshing credentials is the kernel's job. */
79
96
  auth: () => Promise<AuthInjection>;
80
- /** 收到 401 时调用一次;内核刷新凭据后,插件重试一次。 */
97
+ /** Called once on a 401; after the kernel refreshes credentials the plugin retries once. */
81
98
  onUnauthorized: () => Promise<void>;
82
99
  signal: AbortSignal;
83
100
  /**
84
- * 会话期间远端报告工具清单变了(如 MCP `notifications/tools/list_changed`)时调用,可能多次;内核据此安排一次
85
- * 漂移检查(新的 / 变了的工具在管理员复核前不可用)。可选:旧内核不提供,连接器须判空。不要等待它、不要因它抛错。
101
+ * Called when the remote reports during the session that its tool list changed (e.g. MCP
102
+ * `notifications/tools/list_changed`), possibly several times; the kernel schedules one
103
+ * drift check from it (new / changed tools are unavailable until an admin reviews them).
104
+ * Optional: old kernels do not provide it, so the connector must check for absence. Do not wait
105
+ * for it and do not throw because of it.
86
106
  */
87
107
  onToolsChanged?: () => void;
88
108
  /**
@@ -91,17 +111,26 @@ export interface ConnectorOpenArgs {
91
111
  * when the kernel does not provide it, the connector does not declare the MCP elicitation
92
112
  * capability (so the remote never starts one).
93
113
  *
94
- * 内核不能在等用户回答期间保持远端调用(运行会暂停、worker 释放、会话关闭):需要问用户时,内核**中止本次调用**
95
- * (经 `callTool` 的 signal)并让运行进入等待;用户回答后内核重新发起同一调用,远端再次发起同样的 elicitation 时
96
- * 由本回调立即用用户的答案答复。所以连接器只需「收到就调用、拿到就回」,不要自己缓存或重试;需要问用户时本回调
97
- * 以错误拒绝(调用已被中止),连接器让该错误原样结束本次调用即可。
114
+ * The kernel cannot hold a remote call while waiting for the user to answer (the run pauses, the
115
+ * worker is released, the session closes): when the user must be asked, the kernel **aborts this
116
+ * call**
117
+ * (via the `callTool` signal) and puts the run into waiting; after the user answers the kernel
118
+ * issues the same call again, and when the remote raises the same elicitation again
119
+ * this callback replies at once with the user's answer. So the connector only needs "call it when
120
+ * received, return what it gets"; do not cache or retry yourself; when the user must be asked
121
+ * this callback
122
+ * rejects with an error (the call has already been aborted), and the connector simply lets that
123
+ * error end this call unchanged.
98
124
  */
99
125
  onElicit?: (request: ElicitationRequest) => Promise<ElicitationResponse>;
100
126
  }
101
127
  /**
102
- * 远端描述里声明的一种认证方式,映射到内核连接器认证(ConnectorAuth)的形状,供安装向导预填。
103
- * `scheme` 是远端描述里的名字(如 OpenAPI `securitySchemes` 的键),`description` 原样给出(可能缺省)。
104
- * 只列内核支持的方式;其余(cookie 里的 API key、OpenID Connect、implicit / password 流等)不出现。
128
+ * An authentication method declared in the remote description, mapped to the shape of the kernel's
129
+ * connector auth (ConnectorAuth), to prefill the install wizard.
130
+ * `scheme` is the name in the remote description (e.g. the key of OpenAPI `securitySchemes`),
131
+ * `description` is given as is (may be absent).
132
+ * Only methods the kernel supports are listed; the rest (API keys in cookies, OpenID Connect,
133
+ * implicit / password flows, etc.) do not appear.
105
134
  */
106
135
  export type AuthHint = {
107
136
  scheme: string;
@@ -124,28 +153,34 @@ export type AuthHint = {
124
153
  tokenUrl: string;
125
154
  scopes: string[];
126
155
  });
127
- /** 远端描述里的一个操作(如 OpenAPI operation),供安装向导勾选。 */
156
+ /**
157
+ * An operation in the remote description (e.g. an OpenAPI operation), for the install wizard to
158
+ * tick.
159
+ */
128
160
  export interface ConnectorOperation {
129
- /** 端点配置里勾选用的 id(如 OpenAPI 的 operationId)。 */
161
+ /** The id used for ticking in the endpoint config (e.g. OpenAPI's operationId). */
130
162
  id: string;
131
- /** 大写 HTTP 方法。 */
163
+ /** Uppercase HTTP method. */
132
164
  method: string;
133
165
  path: string;
134
166
  summary?: string;
135
167
  }
136
- /** `Connector.inspect` 的结果。 */
168
+ /** The result of `Connector.inspect`. */
137
169
  export interface ConnectorInspection {
138
170
  authHints: AuthHint[];
139
171
  operations?: ConnectorOperation[];
140
172
  }
141
- /** `connector@1`:插件实现、内核调用。 */
173
+ /** `connector@1`: implemented by the plugin, called by the kernel. */
142
174
  export interface Connector {
143
175
  kind: string;
144
176
  endpointSchema: ZodTypeAny;
145
177
  open(args: ConnectorOpenArgs): Promise<ConnectorSession>;
146
178
  /**
147
- * 可选:不带凭据读取端点的描述(安装向导的预览用),返回声明的认证方式与可选的操作清单。
148
- * `endpoint` 已按 endpointSchema 校验。失败抛 ToolError(消息英文、不含凭据)。旧连接器不实现,内核须判空。
179
+ * Optional: reads the endpoint's description without credentials (for the install wizard
180
+ * preview), returning the declared auth methods and an optional operation list.
181
+ * `endpoint` is already validated against endpointSchema. On failure throw ToolError (message in
182
+ * English, no credentials). Old connectors do not implement it; the kernel must check for
183
+ * absence.
149
184
  */
150
185
  inspect?(args: {
151
186
  endpoint: unknown;
package/dist/ctx.d.ts CHANGED
@@ -7,21 +7,24 @@ import type { SetupCheckDefinition } from "./setup-check.js";
7
7
  import type { ObjectHead, PresignedUpload, PresignGetOptions } from "./storage.js";
8
8
  import type { ToolHandler, ToolSpec } from "./tool.js";
9
9
  import type { EmbedClaims, UiActionArgs, UiActionResult, UiRenderArgs, UiView } from "./ui.js";
10
- /** 日志接口。 */
10
+ /** Logger interface. */
11
11
  export interface Logger {
12
12
  info(msg: string, fields?: Record<string, unknown>): void;
13
13
  warn(msg: string, fields?: Record<string, unknown>): void;
14
14
  error(msg: string, fields?: Record<string, unknown>): void;
15
15
  }
16
- /** 分布式锁租约。 */
16
+ /** Distributed lock lease. */
17
17
  export interface Lease {
18
18
  renew(): Promise<boolean>;
19
19
  release(): Promise<void>;
20
20
  }
21
21
  /**
22
- * 插件的对象存储(`ctx.storage`,需 `permissions.storage`):与 `ObjectStore` 同形,但每个方法的第一个参数是
23
- * `orgId`,键与前缀由内核自动加上 `plugins/<插件名>/<orgId>/`——插件只能看到自己在该组织下的对象。
24
- * 底层是部署配置的 `object-store@1` 提供方;没有提供方时各方法抛错。
22
+ * The plugin's object storage (`ctx.storage`, needs `permissions.storage`): the same shape as
23
+ * `ObjectStore`, but the first parameter of every method is
24
+ * `orgId`, and the kernel adds `plugins/<plugin name>/<orgId>/` to keys and prefixes automatically:
25
+ * a plugin sees only its own objects under that org.
26
+ * The backing store is the deployment-configured `object-store@1` provider; every method throws
27
+ * when there is no provider.
25
28
  */
26
29
  export interface ExtensionStorage {
27
30
  put(orgId: string, key: string, body: Uint8Array | ReadableStream<Uint8Array>, opts: {
@@ -30,8 +33,10 @@ export interface ExtensionStorage {
30
33
  signal?: AbortSignal;
31
34
  }): Promise<ObjectHead>;
32
35
  /**
33
- * 不存在返回 null。`range` 为闭区间字节范围,缺省 `end` 表示读到末尾。
34
- * 带 `range` 时 `head.size` 仍是整个对象的大小;存储忽略 Range 时 body 可能是整个对象。
36
+ * Returns null when missing. `range` is a closed byte range; an omitted `end` means read to the
37
+ * end.
38
+ * With `range`, `head.size` is still the size of the whole object; when the store ignores Range,
39
+ * body may be the whole object.
35
40
  */
36
41
  get(orgId: string, key: string, opts?: {
37
42
  signal?: AbortSignal;
@@ -44,7 +49,7 @@ export interface ExtensionStorage {
44
49
  body: ReadableStream<Uint8Array>;
45
50
  } | null>;
46
51
  head(orgId: string, key: string): Promise<ObjectHead | null>;
47
- /** 不存在也算成功。 */
52
+ /** A missing key also counts as success. */
48
53
  delete(orgId: string, key: string): Promise<void>;
49
54
  deletePrefix(orgId: string, prefix: string): Promise<number>;
50
55
  list(orgId: string, prefix: string, opts?: {
@@ -120,7 +125,10 @@ export interface ExtensionModels {
120
125
  purpose: string;
121
126
  }): Promise<ExtensionModelTarget | null>;
122
127
  }
123
- /** 传给插件 `setup` 的上下文。不提供定时器与进程内共享状态;kv 写入必须带 TTL。 */
128
+ /**
129
+ * The context passed to a plugin's `setup`. It provides no timers or in-process shared state; kv
130
+ * writes must carry a TTL.
131
+ */
124
132
  export interface ExtensionContext {
125
133
  kv: {
126
134
  get(key: string): Promise<string | null>;
@@ -154,11 +162,11 @@ export interface ExtensionContext {
154
162
  get(orgId: string, key: string): Promise<string | null>;
155
163
  set(orgId: string, key: string, value: string): Promise<void>;
156
164
  };
157
- /** 对象存储(需 `permissions.storage`,见 {@link ExtensionStorage})。 */
165
+ /** Object storage (needs `permissions.storage`, see {@link ExtensionStorage}). */
158
166
  storage: ExtensionStorage;
159
167
  /** Models by purpose (requires `permissions.models`, see {@link ExtensionModels}). */
160
168
  models: ExtensionModels;
161
- /** 已切到本插件 schema(withSchema)的 Kysely 实例。 */
169
+ /** A Kysely instance already switched to this plugin's schema (withSchema). */
162
170
  db: Kysely<any>;
163
171
  http: {
164
172
  /**
@@ -169,7 +177,7 @@ export interface ExtensionContext {
169
177
  route(method: "GET" | "POST" | "PUT" | "DELETE", path: string, handler: (req: Request, caller: RouteCaller) => Promise<Response>): void;
170
178
  };
171
179
  tools: {
172
- /** 注册一个工具;只能在 `setup` 期间调用,名称不可重复。 */
180
+ /** Registers a tool; callable only during `setup`, names must not repeat. */
173
181
  register(spec: ToolSpec, handler: ToolHandler): void;
174
182
  };
175
183
  /**
@@ -201,14 +209,19 @@ export interface ExtensionContext {
201
209
  }[]>;
202
210
  };
203
211
  /**
204
- * 界面贡献的运行时(清单 `ui` + `permissions.ui`):
205
- * - `view` / `action`:只能在 `setup` 期间注册,id 是清单里 kind view 的贡献 id;
206
- * `action` 收到视图里按钮或表单提交(`args.actionId` 区分是哪一个);
207
- * - `invalidate`:告诉内核「这个贡献变了」,打开着它的网页会重新取视图(经 bus,跨副本);a
212
+ * Runtime of UI contributions (manifest `ui` + `permissions.ui`):
213
+ * - `view` / `action`: can be registered only during `setup`; the id is the contribution id of
214
+ * the kind-view entry in the manifest;
215
+ * `action` receives a button click or form submission from the view (`args.actionId` tells
216
+ * which one);
217
+ * - `invalidate`: tells the kernel "this contribution changed", and the web pages that have it
218
+ * open fetch the view again (via the bus, across replicas); a
208
219
  * `platform.page` contribution takes no `orgId` (it refreshes the admin console), every other
209
220
  * contribution requires one;
210
- * - `verifyEmbedToken`:校验 embed 页面拿到的嵌入令牌,只认签给本插件、未过期的,且此刻插件仍在该组织启用、
211
- * 调用者仍是 active 成员,角色仍满足位置的 minRole,否则返回 null;返回的 `role` 是此刻的角色。A
221
+ * - `verifyEmbedToken`: validates the embed token an embed page received; it accepts only
222
+ * tokens signed for this plugin and not expired, while the plugin is still enabled in that org,
223
+ * the caller is still an active member and the role still satisfies the slot's minRole,
224
+ * otherwise it returns null; the returned `role` is the role at this moment. A
212
225
  * platform-scope token (`scope: "platform"`, no `orgId`) verifies only for a `platform.page`
213
226
  * contribution while the account is still an active super admin.
214
227
  */
@@ -249,14 +262,19 @@ export interface ExtensionContext {
249
262
  };
250
263
  provide(extensionPoint: ExtensionPointRef, impl: unknown): void;
251
264
  /**
252
- * 本插件实例的生命周期信号:实例被撤销(停用、卸载、升级)时、在途调用排空之后中止。
253
- * 插件自己起的长任务(轮询循环、长连接等)据此收尾。
265
+ * The lifecycle signal of this plugin instance: aborted when the instance is revoked (disabled,
266
+ * uninstalled, upgraded), after in-flight calls have drained.
267
+ * Long-running tasks the plugin started itself (polling loops, long connections, etc.) wind down
268
+ * on it.
254
269
  */
255
270
  signal: AbortSignal;
256
271
  /**
257
- * 部署级配置,已按插件 schema 校验(启动配置与企业管理员在后台保存的值合并后)。这是一个 getter:
258
- * 标了 `hot`(`.meta({ hot: true })`)的字段改动时内核就地替换,插件**在用时读** `ctx.config` 才能拿到新值,
259
- * 不要在 setup 里把 hot 字段拷进闭包;改了非 hot 字段时内核重新加载插件实例(新的 setup)。
272
+ * Deployment-level config, validated against the plugin schema (the startup config merged with
273
+ * values the super admin saved in the console). This is a getter:
274
+ * when a field marked `hot` (`.meta({ hot: true })`) changes, the kernel replaces it in place, so
275
+ * the plugin must read `ctx.config` **at the time of use** to get the new value;
276
+ * do not copy hot fields into a closure in setup; when a non-hot field changes the kernel reloads
277
+ * the plugin instance (a new setup).
260
278
  */
261
279
  readonly config: unknown;
262
280
  log: Logger;
@@ -3,16 +3,19 @@ import type { ExtensionContext } from "./ctx.js";
3
3
  import { type ExtensionPointRef } from "./extension-point.js";
4
4
  import { type ExtensionPermissions } from "./permissions.js";
5
5
  import type { UiContribution } from "./ui.js";
6
- /** 插件清单。 */
6
+ /** The plugin manifest. */
7
7
  export interface ExtensionManifest {
8
8
  name: string;
9
9
  version: string;
10
10
  sdk: string;
11
11
  provides: ExtensionPointRef[];
12
12
  requires?: ExtensionPointRef[];
13
- /** 可选依赖:缺失时插件照常加载,运行时经 ctx.extensionPoints 判断。 */
13
+ /**
14
+ * Optional dependencies: when missing the plugin still loads, and decides at runtime through
15
+ * ctx.extensionPoints.
16
+ */
14
17
  optional?: ExtensionPointRef[];
15
- /** 权限清单(治理而非沙箱)。 */
18
+ /** Permission manifest (governance, not a sandbox). */
16
19
  permissions?: ExtensionPermissions;
17
20
  /**
18
21
  * UI contributions, each in a slot of `UI_SLOTS`; every id is also listed in `permissions.ui`.
@@ -27,19 +30,26 @@ export interface ExtensionManifest {
27
30
  migrations?: string;
28
31
  setup(ctx: ExtensionContext): void | Promise<void>;
29
32
  /**
30
- * 可选:插件实例被撤销(停用、卸载、升级换新实例、依赖方随提供方重新加载)时调用。
31
- * 调用时内核已经:停止接新的调用、等在途调用结束(最多 `extensionHost.drainSeconds`)、中止 `ctx.signal`、
32
- * 撤销本实例经 ctx 做过的全部登记(工具、路由、队列 worker、bus 订阅、锁租约、界面、provide)。
33
- * 这里只收拾插件自己在 ctx 之外开的东西(如自建的连接);不要再经 ctx 登记任何东西。
34
- * setup 抛错时不调用(已登记的由内核撤销)。
33
+ * Optional: called when the plugin instance is revoked (disabled, uninstalled, replaced by a new
34
+ * instance on upgrade, a dependent reloaded together with its provider).
35
+ * By then the kernel has already: stopped accepting new calls, waited for in-flight calls to
36
+ * finish (at most `extensionHost.drainSeconds`), aborted `ctx.signal`,
37
+ * and revoked every registration this instance made through ctx (tools, routes, queue workers,
38
+ * bus subscriptions, lock leases, UI, provide).
39
+ * Clean up here only what the plugin opened outside ctx (e.g. its own connections); do not
40
+ * register anything through ctx again.
41
+ * Not called when setup throws (the kernel revokes what was already registered).
35
42
  */
36
43
  dispose?(ctx: ExtensionContext): void | Promise<void>;
37
44
  }
38
- /** 插件清单不合法。 */
45
+ /** The plugin manifest is invalid. */
39
46
  export declare class ExtensionManifestError extends Error {
40
47
  constructor(plugin: string, message: string);
41
48
  }
42
- /** 插件名规则(清单 `name`;连接器模板的 `plugin` 也按它校验)。 */
49
+ /** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
43
50
  export declare const EXTENSION_NAME_RE: RegExp;
44
- /** 校验并原样返回插件清单;不合法抛 ExtensionManifestError。 */
51
+ /**
52
+ * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
53
+ * invalid.
54
+ */
45
55
  export declare function defineExtension(m: ExtensionManifest): ExtensionManifest;
@@ -1,17 +1,20 @@
1
1
  import semver from "semver";
2
2
  import { EXTENSION_POINTS, parseExtensionPoint, } from "./extension-point.js";
3
3
  import { validatePermissions, validateUiContributions, } from "./permissions.js";
4
- /** 插件清单不合法。 */
4
+ /** The plugin manifest is invalid. */
5
5
  export class ExtensionManifestError extends Error {
6
6
  constructor(plugin, message) {
7
7
  super(`extension ${plugin}: ${message}`);
8
8
  this.name = "ExtensionManifestError";
9
9
  }
10
10
  }
11
- /** 插件名规则(清单 `name`;连接器模板的 `plugin` 也按它校验)。 */
11
+ /** Plugin name rule (manifest `name`; a connector template's `plugin` is validated by it too). */
12
12
  export const EXTENSION_NAME_RE = /^[a-z][a-z0-9-]{1,40}$/;
13
13
  const NAME_RE = EXTENSION_NAME_RE;
14
- /** 保留的插件名:内核用 `kernel` 作为自己的 secrets 命名空间,插件不能与之相同。 */
14
+ /**
15
+ * Reserved plugin name: the kernel uses `kernel` as its own secrets namespace, so a plugin cannot
16
+ * take it.
17
+ */
15
18
  const RESERVED_NAMES = new Set(["kernel"]);
16
19
  function checkRefs(label, refs, fail, forbidBrokered = false) {
17
20
  for (const ref of refs) {
@@ -30,7 +33,10 @@ function checkRefs(label, refs, fail, forbidBrokered = false) {
30
33
  }
31
34
  }
32
35
  }
33
- /** 校验并原样返回插件清单;不合法抛 ExtensionManifestError。 */
36
+ /**
37
+ * Validates the plugin manifest and returns it unchanged; throws ExtensionManifestError when
38
+ * invalid.
39
+ */
34
40
  export function defineExtension(m) {
35
41
  const plugin = typeof m?.name === "string" && m.name !== "" ? m.name : "<unnamed>";
36
42
  const fail = (msg) => {
@@ -143,7 +143,8 @@ export interface DeviceExecArgs {
143
143
  actor: SandboxActor;
144
144
  limits: SandboxLimits;
145
145
  /**
146
- * Hosts the kernel allows for this command beyond the local policy (a run's 「这次允许」 or a
146
+ * Hosts the kernel allows for this command beyond the local policy (a run's "Allow this time" or
147
+ * a
147
148
  * scheduled task's grants). A device applies them only in sandbox mode, within `limits`; a
148
149
  * device without the feature ignores the field.
149
150
  */
@@ -13,7 +13,7 @@ export const EXTENSION_POINTS = {
13
13
  "secret-store": info([1], "Stores and resolves secrets (connector credentials, secret config) outside the database.", "single", true),
14
14
  "object-store": info([1], "Stores files and artifacts in S3-compatible object storage, with presigned uploads.", "single", true),
15
15
  channel: info([1], "Connects an instant-messaging platform (Slack, Lark): inbound events, replies and cards.", "multi", false, true),
16
- "model-provider": info([1, 2], "Calls a model vendor's API and streams the result back to the runtime.", "multi", true),
16
+ "model-provider": info([2], "Calls a model vendor's API and streams the result back to the runtime.", "multi", true),
17
17
  "identity-source": info([1], "Signs people in through an external identity provider (SSO).", "multi"),
18
18
  directory: info([1], "Syncs members and departments from an external company directory.", "multi", false, true),
19
19
  counter: info([1], "Counts usage so quotas and reports can be built on it.", "multi"),
@@ -1,8 +1,12 @@
1
- /** 外部身份;登录、渠道入站、通讯录三处用同一个 (source, externalId) 键。 */
1
+ /**
2
+ * An external identity; login, channel inbound and directory all use the same (source, externalId)
3
+ * key.
4
+ */
2
5
  export interface ExternalIdentity {
3
6
  /**
4
- * `"<插件名>:<租户 id>"`,必须与 `tenantId` 一致。第三方登录时内核核对
5
- * `source === \`${插件名}:${tenantId}\``,不一致按身份源出错拒绝。
7
+ * `"<plugin name>:<tenant id>"`, must equal `tenantId`. On third-party login the kernel checks
8
+ * `source === \`${plugin name}:${tenantId}\``, and rejects a mismatch as an identity source
9
+ * error.
6
10
  */
7
11
  source: string;
8
12
  externalId: string;
@@ -13,9 +17,12 @@ export interface ExternalIdentity {
13
17
  avatarUrl?: string;
14
18
  }
15
19
  /**
16
- * 第三方登录(`identity-source@1`)。state、nonce 与 PKCE 都由内核生成并保存在服务端:
17
- * 插件把 `codeChallenge` / `codeChallengeMethod` 放进授权地址(`code_challenge` / `code_challenge_method`),
18
- * 回调换 token 时带上 `codeVerifier`(`code_verifier`)。平台不支持 PKCE 时忽略这几个字段即可。
20
+ * Third-party login (`identity-source@1`). State, nonce and PKCE are all generated by the kernel
21
+ * and kept server-side:
22
+ * the plugin puts `codeChallenge` / `codeChallengeMethod` into the authorization URL
23
+ * (`code_challenge` / `code_challenge_method`),
24
+ * and passes `codeVerifier` (`code_verifier`) when exchanging the token at the callback. If the
25
+ * platform does not support PKCE, just ignore these fields.
19
26
  */
20
27
  export interface IdentitySource {
21
28
  label: {
@@ -27,9 +34,12 @@ export interface IdentitySource {
27
34
  redirectUri: string;
28
35
  state: string;
29
36
  nonce: string;
30
- /** PKCE challenge(base64url(SHA-256(codeVerifier)));内核总会提供,旧内核不提供。 */
37
+ /**
38
+ * PKCE challenge (base64url(SHA-256(codeVerifier))); the kernel always provides it, old kernels
39
+ * do not.
40
+ */
31
41
  codeChallenge?: string;
32
- /** PKCE challenge 的算法;内核只用 `"S256"`。 */
42
+ /** The PKCE challenge algorithm; the kernel uses only `"S256"`. */
33
43
  codeChallengeMethod?: "S256";
34
44
  }): string;
35
45
  callback(args: {
@@ -38,7 +48,10 @@ export interface IdentitySource {
38
48
  query: Record<string, string>;
39
49
  nonce: string;
40
50
  signal: AbortSignal;
41
- /** 与本次发起的 `codeChallenge` 对应的 PKCE verifier;内核总会提供,旧内核不提供。 */
51
+ /**
52
+ * The PKCE verifier matching this flow's `codeChallenge`; the kernel always provides it, old
53
+ * kernels do not.
54
+ */
42
55
  codeVerifier?: string;
43
56
  }): Promise<ExternalIdentity>;
44
57
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.26";
1
+ export declare const SDK_VERSION = "0.1.0-rc.28";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.26";
1
+ export const SDK_VERSION = "0.1.0-rc.28";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
@@ -1,22 +1,29 @@
1
1
  /**
2
- * `model-provider@2` 的参数声明与校验(纯函数;issue / 错误信息用英文,供日志与 API 返回)。
3
- * 每个模型在 `ModelInfo.parameters` 中声明自己支持的参数,取值约束是受限的 JSON Schema 子集。
2
+ * Parameter declarations and validation for `model-provider@2` (pure functions; issues / error
3
+ * messages are in English, for logs and API responses).
4
+ * Each model declares in `ModelInfo.parameters` the parameters it supports; value constraints are a
5
+ * restricted JSON Schema subset.
4
6
  */
5
7
  export type Effort = "low" | "medium" | "high" | "xhigh" | "max";
6
8
  /**
7
- * 标准旋钮:平台统一语义,界面专门渲染,换模型或兜底时语义可迁移;插件负责映射到原生参数。
8
- * - `effort`:思考深度,`{ type: "string", enum }`,取值是 `low|medium|high|xhigh|max` 的子集;
9
- * - `thinking`:思考模式,`{ type: "string", enum }`,取值是 `off|on|summarized` 的子集;
10
- * - `temperature`:`{ type: "number" }`(可带范围);
11
- * - `maxOutputTokens`:最大输出 token,`{ type: "integer" }`(可带范围)。
9
+ * Standard knobs: uniform platform semantics, rendered specially by the UI, with semantics that
10
+ * carry over when switching models or falling back; the plugin maps them to native parameters.
11
+ * - `effort`: thinking depth, `{ type: "string", enum }`, values a subset of
12
+ * `low|medium|high|xhigh|max`;
13
+ * - `thinking`: thinking mode, `{ type: "string", enum }`, values a subset of `off|on|summarized`;
14
+ * - `temperature`: `{ type: "number" }` (may carry a range);
15
+ * - `maxOutputTokens`: maximum output tokens, `{ type: "integer" }` (may carry a range).
12
16
  */
13
17
  export type StandardKnob = "effort" | "thinking" | "temperature" | "maxOutputTokens";
14
18
  export declare const STANDARD_KNOBS: readonly StandardKnob[];
15
- /** `effort` 旋钮允许的取值全集。 */
19
+ /** The full set of values the `effort` knob allows. */
16
20
  export declare const EFFORT_VALUES: readonly Effort[];
17
- /** `thinking` 旋钮允许的取值全集。 */
21
+ /** The full set of values the `thinking` knob allows. */
18
22
  export declare const THINKING_VALUES: readonly string[];
19
- /** 参数取值约束:受限的 JSON Schema 子集(可序列化后交给界面;内核自行校验,不依赖 ajv)。 */
23
+ /**
24
+ * Parameter value constraints: a restricted JSON Schema subset (serializable for the UI; the kernel
25
+ * validates it itself, without ajv).
26
+ */
20
27
  export type ParamSchema = {
21
28
  type: "string";
22
29
  enum: string[];
@@ -31,14 +38,20 @@ export type ParamSchema = {
31
38
  maximum?: number;
32
39
  };
33
40
  export type ParamValue = string | number | boolean;
34
- /** 模型声明的一个参数。 */
41
+ /** One parameter a model declares. */
35
42
  export interface ModelParameter {
36
- /** 标准旋钮名(见 {@link StandardKnob}),或厂商专有参数 `"<插件名>.<名称>"`。 */
43
+ /**
44
+ * A standard knob name (see {@link StandardKnob}), or a vendor-specific parameter `"<plugin
45
+ * name>.<name>"`.
46
+ */
37
47
  key: string;
38
- /** key 为标准旋钮时必填且必须等于 key;厂商专有参数不得填写。 */
48
+ /**
49
+ * Required when key is a standard knob and must equal key; vendor-specific parameters must not
50
+ * set it.
51
+ */
39
52
  standard?: StandardKnob;
40
53
  schema: ParamSchema;
41
- /** 未设置时使用的值;必须满足 schema。 */
54
+ /** The value used when unset; must satisfy the schema. */
42
55
  default?: ParamValue;
43
56
  label: {
44
57
  zh: string;
@@ -53,11 +66,13 @@ export interface ParamIssue {
53
66
  key: string;
54
67
  message: string;
55
68
  }
56
- /** 值不满足 schema 时返回英文原因,满足时返回 undefined。 */
69
+ /** Returns an English reason when the value does not satisfy the schema, undefined when it does. */
57
70
  export declare function checkParamValue(schema: ParamSchema, v: unknown): string | undefined;
58
71
  /**
59
- * 严格校验(保存 agent 时用):未知键、类型不符、枚举越界、超出范围都算错,逐键报告。
60
- * 成功时 `value` 为传入的参数,不补默认值;值为 undefined 的键视为未设置。
72
+ * Strict validation (used when saving an agent): unknown keys, type mismatches, enum violations and
73
+ * out-of-range values are all errors, reported per key.
74
+ * On success `value` is the input parameters, with no defaults filled in; a key whose value is
75
+ * undefined counts as unset.
61
76
  */
62
77
  export declare function validateParams(decl: ModelParameter[], params: Record<string, unknown>): {
63
78
  ok: true;
@@ -67,16 +82,20 @@ export declare function validateParams(decl: ModelParameter[], params: Record<st
67
82
  issues: ParamIssue[];
68
83
  };
69
84
  /**
70
- * 宽松版(运行时用):丢弃未知或不合法的项(键记入 `dropped`),再为未设置的已声明参数补默认值。
71
- * 用于插件升级后已保存的参数不再合法的情况,不让整轮运行失败。
85
+ * The lenient variant (used at runtime): drops unknown or invalid entries (their keys go into
86
+ * `dropped`), then fills defaults for declared parameters that are unset.
87
+ * For the case where saved parameters are no longer valid after a plugin upgrade, so that the whole
88
+ * run does not fail.
72
89
  */
73
90
  export declare function sanitizeParams(decl: ModelParameter[], params: Record<string, unknown>): {
74
91
  value: Record<string, ParamValue>;
75
92
  dropped: string[];
76
93
  };
77
94
  /**
78
- * 校验插件为一个模型声明的参数:键名是标准旋钮或 `<plugin>.<名称>`、`standard` 与键一致、
79
- * schema 属于受支持的子集、标准旋钮符合取值约定、默认值满足 schema、文案齐全、键不重复。
80
- * 有问题时抛错,信息点名插件与各个键(英文)。
95
+ * Validates the parameters a plugin declares for a model: the key is a standard knob or
96
+ * `<plugin>.<name>`, `standard` agrees with the key,
97
+ * the schema belongs to the supported subset, standard knobs satisfy the value conventions,
98
+ * defaults satisfy the schema, copy is complete, keys do not repeat.
99
+ * Throws when there is a problem, with a message naming the plugin and each key (in English).
81
100
  */
82
101
  export declare function assertValidDeclarations(plugin: string, decl: ModelParameter[]): void;