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

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 +1412 -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,6 +1,8 @@
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 const STANDARD_KNOBS = [
6
8
  "effort",
@@ -8,13 +10,13 @@ export const STANDARD_KNOBS = [
8
10
  "temperature",
9
11
  "maxOutputTokens",
10
12
  ];
11
- /** `effort` 旋钮允许的取值全集。 */
13
+ /** The full set of values the `effort` knob allows. */
12
14
  export const EFFORT_VALUES = ["low", "medium", "high", "xhigh", "max"];
13
- /** `thinking` 旋钮允许的取值全集。 */
15
+ /** The full set of values the `thinking` knob allows. */
14
16
  export const THINKING_VALUES = ["off", "on", "summarized"];
15
17
  const isStandardKnob = (k) => STANDARD_KNOBS.includes(k);
16
18
  const VENDOR_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
17
- /** 值不满足 schema 时返回英文原因,满足时返回 undefined。 */
19
+ /** Returns an English reason when the value does not satisfy the schema, undefined when it does. */
18
20
  export function checkParamValue(schema, v) {
19
21
  switch (schema.type) {
20
22
  case "boolean":
@@ -45,11 +47,16 @@ export function checkParamValue(schema, v) {
45
47
  return `has unsupported schema type ${JSON.stringify(schema.type)}`;
46
48
  }
47
49
  }
48
- /** 按键查声明(用 Map,避免 `constructor` 等原型属性被当成已声明的键)。 */
50
+ /**
51
+ * Looks up a declaration by key (uses a Map so that prototype properties such as `constructor` are
52
+ * not mistaken for declared keys).
53
+ */
49
54
  const declMap = (decl) => new Map(decl.map((d) => [d.key, d]));
50
55
  /**
51
- * 严格校验(保存 agent 时用):未知键、类型不符、枚举越界、超出范围都算错,逐键报告。
52
- * 成功时 `value` 为传入的参数,不补默认值;值为 undefined 的键视为未设置。
56
+ * Strict validation (used when saving an agent): unknown keys, type mismatches, enum violations and
57
+ * out-of-range values are all errors, reported per key.
58
+ * On success `value` is the input parameters, with no defaults filled in; a key whose value is
59
+ * undefined counts as unset.
53
60
  */
54
61
  export function validateParams(decl, params) {
55
62
  const byKey = declMap(decl);
@@ -72,8 +79,10 @@ export function validateParams(decl, params) {
72
79
  return issues.length > 0 ? { ok: false, issues } : { ok: true, value };
73
80
  }
74
81
  /**
75
- * 宽松版(运行时用):丢弃未知或不合法的项(键记入 `dropped`),再为未设置的已声明参数补默认值。
76
- * 用于插件升级后已保存的参数不再合法的情况,不让整轮运行失败。
82
+ * The lenient variant (used at runtime): drops unknown or invalid entries (their keys go into
83
+ * `dropped`), then fills defaults for declared parameters that are unset.
84
+ * For the case where saved parameters are no longer valid after a plugin upgrade, so that the whole
85
+ * run does not fail.
77
86
  */
78
87
  export function sanitizeParams(decl, params) {
79
88
  const byKey = declMap(decl);
@@ -143,7 +152,9 @@ function schemaProblems(schema) {
143
152
  return [`unsupported schema type ${JSON.stringify(s.type)}`];
144
153
  }
145
154
  }
146
- /** 标准旋钮的取值约定(schema 本身已合法时才检查)。 */
155
+ /**
156
+ * The value conventions of standard knobs (checked only when the schema itself is already valid).
157
+ */
147
158
  function knobProblems(key, schema) {
148
159
  const values = schema.type === "string" && "enum" in schema ? schema.enum : undefined;
149
160
  switch (key) {
@@ -178,7 +189,7 @@ function textProblems(d) {
178
189
  }
179
190
  return out;
180
191
  }
181
- /** 一个参数声明的全部问题;无问题返回空数组。 */
192
+ /** All problems of one parameter declaration; an empty array when there are none. */
182
193
  function declarationProblems(plugin, d) {
183
194
  if (typeof d !== "object" || d === null)
184
195
  return ["declaration must be an object"];
@@ -198,9 +209,11 @@ function declarationProblems(plugin, d) {
198
209
  return out;
199
210
  }
200
211
  /**
201
- * 校验插件为一个模型声明的参数:键名是标准旋钮或 `<plugin>.<名称>`、`standard` 与键一致、
202
- * schema 属于受支持的子集、标准旋钮符合取值约定、默认值满足 schema、文案齐全、键不重复。
203
- * 有问题时抛错,信息点名插件与各个键(英文)。
212
+ * Validates the parameters a plugin declares for a model: the key is a standard knob or
213
+ * `<plugin>.<name>`, `standard` agrees with the key,
214
+ * the schema belongs to the supported subset, standard knobs satisfy the value conventions,
215
+ * defaults satisfy the schema, copy is complete, keys do not repeat.
216
+ * Throws when there is a problem, with a message naming the plugin and each key (in English).
204
217
  */
205
218
  export function assertValidDeclarations(plugin, decl) {
206
219
  if (!Array.isArray(decl)) {
package/dist/model.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /**
2
- * 与供应商无关的模型契约;原生协议留在各供应商插件内部。
3
- * 当前契约为 `model-provider@2`(`ModelProvider` / `ModelInfo` / `ModelRequest`,参数由插件按模型声明,
4
- * 见 `model-params.ts`);旧契约 `model-provider@1`(`ModelProviderV1` 等)由内核经适配层继续支持。
2
+ * The vendor-neutral model contract; native protocols stay inside each vendor plugin.
3
+ * The contract is `model-provider@2` (`ModelProvider` / `ModelInfo` / `ModelRequest`, parameters
4
+ * declared by the plugin per model, see `model-params.ts`).
5
5
  */
6
- import type { Effort, ModelParameter, ParamValue } from "./model-params.js";
6
+ import type { ModelCallPurpose } from "./hooks.js";
7
+ import type { ModelParameter, ParamValue } from "./model-params.js";
7
8
  import type { LocalizedName } from "./plugin-package.js";
8
9
  /** What a model does. Absent on a `ModelInfo` means `chat`. */
9
10
  export type ModelKind = "chat" | "embedding" | "rerank" | "image_generation" | "video_generation" | "speech_to_text" | "text_to_speech";
@@ -39,43 +40,46 @@ export interface ModelInfo {
39
40
  caching: boolean;
40
41
  midConversationSystem: boolean;
41
42
  /**
42
- * 是否接受 `document` 块(缺省为 false)。图片看 `vision`。模型不支持时内核把媒体块换成英文文字占位
43
- * (如 `[Attached image "<name>" — this model cannot view images.]`;`text/*` 文档改为内联截断后的文本),
44
- * 绝不把字节发给它。
43
+ * Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
44
+ * the model does not support them the kernel replaces media blocks with English text
45
+ * placeholders
46
+ * (e.g. `[Attached image "<name>" — this model cannot view images.]`; `text/*` documents are
47
+ * inlined as truncated text instead),
48
+ * and never sends the bytes to it.
45
49
  */
46
50
  documents?: boolean;
47
- /**
48
- * @deprecated `model-provider@1` 用:是否支持 `ModelRequestV1.effort`。`@2` 插件不填,改在
49
- * `parameters` 中声明 `effort` 旋钮;内核的 `@1` 适配层据此推导 `parameters`。
50
- */
51
- effort?: boolean;
52
51
  };
53
- /** 流空闲看门狗阈值;推理类模型应更长。未给时内核用配置默认值。 */
52
+ /**
53
+ * Stream idle watchdog threshold; reasoning models should use a longer one. When unset the kernel
54
+ * uses the config default.
55
+ */
54
56
  streamIdleTimeoutMs?: number;
55
- /** 该模型支持的参数(`@2` 必填,可为空数组;须通过 `assertValidDeclarations`)。 */
57
+ /**
58
+ * The parameters this model supports (may be an empty array; must pass
59
+ * `assertValidDeclarations`). Effort is the standard `effort` knob declared here.
60
+ */
56
61
  parameters: ModelParameter[];
57
62
  }
58
- /** `model-provider@1` 的模型信息:没有 `parameters`,effort 支持由 `capabilities.effort` 表示。 */
59
- export type ModelInfoV1 = Omit<ModelInfo, "parameters" | "capabilities"> & {
60
- capabilities: Omit<ModelInfo["capabilities"], "effort"> & {
61
- effort: boolean;
62
- };
63
- };
64
- /** 供应商私有数据:只回放给同一供应商(如 Anthropic 思考块签名、OpenAI 加密推理项)。 */
63
+ /**
64
+ * Vendor-private data: replayed only to the same vendor (e.g. Anthropic thinking block signatures,
65
+ * OpenAI encrypted reasoning items).
66
+ */
65
67
  export interface ProviderOpaque {
66
68
  provider: string;
67
69
  model: string;
68
70
  data: unknown;
69
71
  }
70
- /** 图片块接受的类型。 */
72
+ /** Types accepted by image blocks. */
71
73
  export declare const IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
72
- /** 文档块接受的类型。 */
74
+ /** Types accepted by document blocks. */
73
75
  export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv"];
74
76
  export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
75
77
  export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
76
78
  /**
77
- * 媒体内容的来源:`base64` 是字节本身,`ref` 是内核附件的引用。
78
- * 事件日志里只存 `ref`(字节不进日志);内核构建请求时把 `ref` 解析成 `base64`,插件只会收到 `base64`。
79
+ * The source of media content: `base64` is the bytes themselves, `ref` is a reference to a kernel
80
+ * attachment.
81
+ * The event log stores only `ref` (bytes never enter the log); when building a request the kernel
82
+ * resolves `ref` into `base64`, so plugins only ever receive `base64`.
79
83
  */
80
84
  export type MediaSource = {
81
85
  kind: "base64";
@@ -84,13 +88,19 @@ export type MediaSource = {
84
88
  kind: "ref";
85
89
  attachmentId: string;
86
90
  };
87
- /** 单个媒体块解码后的字节上限(按主流供应商的较小值取)。 */
91
+ /**
92
+ * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
93
+ * vendors).
94
+ */
88
95
  export declare const MEDIA_LIMITS: {
89
96
  readonly imageBytes: 5242880;
90
97
  readonly documentBytes: 33554432;
91
98
  };
92
99
  export type ContentBlock =
93
- /** text 的 opaque:供应商需要随文本回放的私有数据(如 OpenAI message 输出项的 id)。 */
100
+ /**
101
+ * Opaque for text: vendor-private data that must be replayed with the text (e.g. the id of an
102
+ * OpenAI message output item).
103
+ */
94
104
  {
95
105
  type: "text";
96
106
  text: string;
@@ -144,18 +154,23 @@ export type ContentBlock =
144
154
  name?: string;
145
155
  size?: number;
146
156
  };
147
- /** 媒体块 `name` 的最大长度(字符)。 */
157
+ /** Maximum length (characters) of a media block's `name`. */
148
158
  export declare const MEDIA_NAME_MAX_CHARS = 255;
149
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
159
+ /**
160
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
161
+ * {@link clipMediaName}.
162
+ */
150
163
  export declare const PROVIDER_MEDIA_NAME_MAX = 200;
151
164
  /**
152
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
153
- * 尽量保留扩展名(不超过 16 个字符的 `.ext`),中间用 `…` 表示截掉的部分。纯函数。
165
+ * Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
166
+ * filename / title length, and adding a suffix makes it longer still).
167
+ * Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
168
+ * part in the middle. A pure function.
154
169
  */
155
170
  export declare function clipMediaName(name: string, max?: number): string;
156
- /** 是否含控制字符(C0、DEL 与 C1)。 */
171
+ /** Whether it contains control characters (C0, DEL and C1). */
157
172
  export declare function hasControlChars(s: string): boolean;
158
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
173
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
159
174
  export declare function isAttachmentId(s: unknown): s is string;
160
175
  /**
161
176
  * Validates an image / document / file block, returning a list of errors (empty means valid): the
@@ -173,7 +188,10 @@ export type ModelMessage = {
173
188
  role: "assistant";
174
189
  content: ContentBlock[];
175
190
  }
176
- /** 对话中途的系统提醒;模型不支持时由插件转成 user 文本块(以 "[system] " 开头)。 */
191
+ /**
192
+ * A mid-conversation system reminder; when the model does not support it the plugin turns it into
193
+ * a user text block (starting with "[system] ").
194
+ */
177
195
  | {
178
196
  role: "system";
179
197
  content: string;
@@ -185,7 +203,10 @@ export interface ToolDefinition {
185
203
  }
186
204
  export interface ModelRequest {
187
205
  model: string;
188
- /** 稳定内容在前;cache 为 true 的块之后打缓存断点(由插件按原生协议实现)。 */
206
+ /**
207
+ * Stable content first; after a block with cache true a cache breakpoint is placed (implemented
208
+ * by the plugin per the native protocol).
209
+ */
189
210
  system: {
190
211
  text: string;
191
212
  cache: boolean;
@@ -193,32 +214,46 @@ export interface ModelRequest {
193
214
  messages: ModelMessage[];
194
215
  tools: ToolDefinition[];
195
216
  /**
196
- * `@2`:模型可否调用工具。`"none"` = 本次只能回复文本、不得调用工具(`tools` 仍照常带上:历史里有工具调用时
197
- * 部分供应商要求请求声明工具,且保持缓存前缀稳定);缺省或 `"auto"` = 由模型决定。
198
- * 插件映射到原生字段(如 Anthropic `tool_choice: {type: "none"}`);`tools` 为空时插件不发送该字段。
217
+ * `@2`: whether the model may call tools. `"none"` = this call may only reply with text and must
218
+ * not call tools (`tools` is still sent as usual: when the history has tool calls
219
+ * some vendors require the request to declare tools, and it keeps the cache prefix stable);
220
+ * omitted or `"auto"` = the model decides.
221
+ * The plugin maps it to the native field (e.g. Anthropic `tool_choice: {type: "none"}`); when
222
+ * `tools` is empty the plugin does not send the field.
199
223
  */
200
224
  toolChoice?: "auto" | "none";
201
225
  maxOutputTokens: number;
202
- /** `@2`:本次调用的参数(已按该模型的 `parameters` 处理过),由插件映射到原生请求。 */
226
+ /**
227
+ * The parameters of this call (already processed against the model's `parameters`), mapped to the
228
+ * native request by the plugin.
229
+ */
203
230
  params: Record<string, ParamValue>;
204
- /** @deprecated `model-provider@1` 用;`@2` 插件读 `params.effort`。 */
205
- effort?: Effort;
231
+ /**
232
+ * What this call is for, when the kernel says so: `"compaction"` for a conversation summary call.
233
+ * Absent on ordinary step calls. Informational (a scripted test model keys on it); real providers
234
+ * ignore it and must not forward it to a vendor API.
235
+ */
236
+ purpose?: ModelCallPurpose;
206
237
  }
207
- /** `model-provider@1` 的请求:没有 `params` 与 `toolChoice`。 */
208
- export type ModelRequestV1 = Omit<ModelRequest, "params" | "toolChoice">;
209
238
  export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
210
239
  /**
211
- * 一次调用的 token 用量。三类输入互不重叠:本次请求的输入总量 =
212
- * `inputTokens + cacheReadTokens + cacheWriteTokens`(内核据此校正上下文估算、决定何时压缩)。
213
- * 供应商 API 的输入计数若已包含缓存命中 / 写入的 token(如 OpenAI 的 `prompt_tokens`),插件必须先减掉。
240
+ * Token usage of one call. The three kinds of input do not overlap: the total input of this request
241
+ * =
242
+ * `inputTokens + cacheReadTokens + cacheWriteTokens` (the kernel uses it to correct context
243
+ * estimates and to decide when to compact).
244
+ * If the vendor API's input count already includes cache-hit / cache-write tokens (e.g. OpenAI's
245
+ * `prompt_tokens`), the plugin must subtract them first.
214
246
  */
215
247
  export interface ModelUsage {
216
- /** 未命中缓存、也未写入缓存的输入 token(只是未缓存部分,不是输入总量)。 */
248
+ /**
249
+ * Input tokens that neither hit the cache nor were written to it (only the uncached part, not the
250
+ * total input).
251
+ */
217
252
  inputTokens: number;
218
253
  outputTokens: number;
219
- /** 从提示词缓存读取的输入 token。 */
254
+ /** Input tokens read from the prompt cache. */
220
255
  cacheReadTokens: number;
221
- /** 本次写入提示词缓存的输入 token。 */
256
+ /** Input tokens written to the prompt cache in this call. */
222
257
  cacheWriteTokens: number;
223
258
  }
224
259
  export type ModelStreamEvent = {
@@ -234,9 +269,11 @@ export type ModelStreamEvent = {
234
269
  usage: ModelUsage;
235
270
  };
236
271
  export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "aborted";
237
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
272
+ /** True for rate_limited / overloaded / server / timeout / network. */
238
273
  export declare function isRetryableKind(kind: ModelErrorKind): boolean;
239
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
274
+ /**
275
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
276
+ */
240
277
  export declare function isModelError(e: unknown): e is ModelError;
241
278
  export declare class ModelError extends Error {
242
279
  readonly kind: ModelErrorKind;
@@ -245,7 +282,7 @@ export declare class ModelError extends Error {
245
282
  retryAfterMs?: number;
246
283
  cause?: unknown;
247
284
  });
248
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
285
+ /** True for rate_limited / overloaded / server / timeout / network. */
249
286
  get retryable(): boolean;
250
287
  }
251
288
  /**
@@ -279,11 +316,14 @@ export interface EmbedResult {
279
316
  * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
280
317
  */
281
318
  export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
282
- /** `model-provider@2` 的实现。 */
319
+ /** The `model-provider@2` implementation. */
283
320
  export interface ModelProvider {
284
- /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
321
+ /**
322
+ * Every model's `parameters` must pass `assertValidDeclarations`, otherwise the kernel does not
323
+ * use this vendor.
324
+ */
285
325
  listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
286
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
326
+ /** The event sequence must end with exactly one message_complete; throw ModelError on error. */
287
327
  stream(req: ModelRequest, opts: {
288
328
  signal: AbortSignal;
289
329
  } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
@@ -292,13 +332,5 @@ export interface ModelProvider {
292
332
  signal: AbortSignal;
293
333
  } & ModelCallOptions): Promise<EmbedResult>;
294
334
  }
295
- /** `model-provider@1` 的实现(旧契约,内核经适配层接入:effort 由 `capabilities.effort` 推导)。 */
296
- export interface ModelProviderV1 {
297
- listModels(): Promise<ModelInfoV1[]>;
298
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
299
- stream(req: ModelRequestV1, opts: {
300
- signal: AbortSignal;
301
- }): AsyncIterable<ModelStreamEvent>;
302
- }
303
- export declare const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
335
+ /** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
304
336
  export declare const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
package/dist/model.js CHANGED
@@ -1,23 +1,31 @@
1
- /** 图片块接受的类型。 */
1
+ /** Types accepted by image blocks. */
2
2
  export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
3
- /** 文档块接受的类型。 */
3
+ /** Types accepted by document blocks. */
4
4
  export const DOCUMENT_MEDIA_TYPES = [
5
5
  "application/pdf",
6
6
  "text/plain",
7
7
  "text/markdown",
8
8
  "text/csv",
9
9
  ];
10
- /** 单个媒体块解码后的字节上限(按主流供应商的较小值取)。 */
10
+ /**
11
+ * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
12
+ * vendors).
13
+ */
11
14
  export const MEDIA_LIMITS = { imageBytes: 5_242_880, documentBytes: 33_554_432 };
12
15
  const B64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
13
16
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
- /** 媒体块 `name` 的最大长度(字符)。 */
17
+ /** Maximum length (characters) of a media block's `name`. */
15
18
  export const MEDIA_NAME_MAX_CHARS = 255;
16
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
19
+ /**
20
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
21
+ * {@link clipMediaName}.
22
+ */
17
23
  export const PROVIDER_MEDIA_NAME_MAX = 200;
18
24
  /**
19
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
20
- * 尽量保留扩展名(不超过 16 个字符的 `.ext`),中间用 `…` 表示截掉的部分。纯函数。
25
+ * Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
26
+ * filename / title length, and adding a suffix makes it longer still).
27
+ * Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
28
+ * part in the middle. A pure function.
21
29
  */
22
30
  export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
23
31
  const cps = [...name];
@@ -29,7 +37,7 @@ export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
29
37
  const head = cps.slice(0, max - 1 - keep.length);
30
38
  return `${head.join("")}…${keep.join("")}`;
31
39
  }
32
- /** 是否含控制字符(C0、DEL 与 C1)。 */
40
+ /** Whether it contains control characters (C0, DEL and C1). */
33
41
  export function hasControlChars(s) {
34
42
  for (let i = 0; i < s.length; i++) {
35
43
  const c = s.charCodeAt(i);
@@ -38,7 +46,7 @@ export function hasControlChars(s) {
38
46
  }
39
47
  return false;
40
48
  }
41
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
49
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
42
50
  export function isAttachmentId(s) {
43
51
  return typeof s === "string" && UUID_RE.test(s);
44
52
  }
@@ -108,7 +116,8 @@ export function validateMediaBlock(b) {
108
116
  errs.push(`${o.type} source.data must be non-empty padded base64`);
109
117
  return errs;
110
118
  }
111
- // 先按长度算解码后的大小,超限就不再逐字符校验
119
+ // Compute the decoded size from the length first; when over the limit, skip the per-character
120
+ // validation
112
121
  const pad = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
113
122
  const bytes = (data.length / 4) * 3 - pad;
114
123
  if (bytes > spec.limit) {
@@ -141,11 +150,13 @@ const RETRYABLE = new Set([
141
150
  "timeout",
142
151
  "network",
143
152
  ]);
144
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
153
+ /** True for rate_limited / overloaded / server / timeout / network. */
145
154
  export function isRetryableKind(kind) {
146
155
  return RETRYABLE.has(kind);
147
156
  }
148
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
157
+ /**
158
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
159
+ */
149
160
  export function isModelError(e) {
150
161
  if (!(e instanceof Error))
151
162
  return false;
@@ -162,7 +173,7 @@ export class ModelError extends Error {
162
173
  if (opts?.retryAfterMs !== undefined)
163
174
  this.retryAfterMs = opts.retryAfterMs;
164
175
  }
165
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
176
+ /** True for rate_limited / overloaded / server / timeout / network. */
166
177
  get retryable() {
167
178
  return isRetryableKind(this.kind);
168
179
  }
@@ -189,5 +200,5 @@ export function validateEmbedResult(req, info, res) {
189
200
  }
190
201
  return null;
191
202
  }
192
- export const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
203
+ /** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
193
204
  export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
@@ -6,7 +6,7 @@ export interface ExtensionPermissions {
6
6
  secrets?: boolean;
7
7
  /** Routes registered with ctx.http.route; each declares who may call it (`access`). */
8
8
  http?: HttpPermission[];
9
- /** ctx.tools.register 的工具名。 */
9
+ /** Tool names for ctx.tools.register. */
10
10
  tools?: string[];
11
11
  /**
12
12
  * Hook mount points (`ctx.hooks.on`). From M7, five mount points are registrable; see
@@ -31,9 +31,9 @@ export interface ExtensionPermissions {
31
31
  en: string;
32
32
  };
33
33
  }[];
34
- /** ctx.storage(对象存储,键限定在 `plugins/<插件名>/<orgId>/` 下)。 */
34
+ /** ctx.storage (object storage, keys confined under `plugins/<plugin name>/<orgId>/`). */
35
35
  storage?: boolean;
36
- /** 访问的域名,只展示不拦截。 */
36
+ /** Domains accessed; displayed only, not enforced. */
37
37
  network?: string[];
38
38
  /**
39
39
  * Client code: the package's `client` section (a browser bundle the web app loads for the
@@ -58,9 +58,9 @@ export interface ExtensionPermissions {
58
58
  */
59
59
  setupChecks?: string[];
60
60
  }
61
- /** hook 挂载点(封闭列表,见总设计 2.4)。 */
61
+ /** Hook mount points (a closed list, see the overall design 2.4). */
62
62
  export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
63
- /** hook 挂载点名。 */
63
+ /** A hook mount point name. */
64
64
  export type HookMountPoint = (typeof HOOK_MOUNT_POINTS)[number];
65
65
  /** A platform API not declared in the manifest was used. */
66
66
  export declare class ExtensionPermissionError extends Error {
@@ -70,7 +70,7 @@ export declare class ExtensionPermissionError extends Error {
70
70
  export declare class ExtensionPointUnavailableError extends Error {
71
71
  constructor(message: string);
72
72
  }
73
- /** 校验权限清单,返回错误列表(空表示合法)。 */
73
+ /** Validates the permission manifest and returns the list of errors (empty means valid). */
74
74
  export declare function validatePermissions(plugin: string, p: unknown): string[];
75
75
  /**
76
76
  * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
@@ -2,8 +2,8 @@ import { POLICY_HOOKS } from "./hooks.js";
2
2
  import { HTTP_ACCESS } from "./http-access.js";
3
3
  import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
4
4
  import { UI_ICONS } from "./ui.js";
5
- import { PLACE_SLOTS, parseSlotRef, uiSlot } from "./ui-slots.js";
6
- /** hook 挂载点(封闭列表,见总设计 2.4)。 */
5
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
6
+ /** Hook mount points (a closed list, see the overall design 2.4). */
7
7
  export const HOOK_MOUNT_POINTS = [
8
8
  "session.start",
9
9
  "session.end",
@@ -65,7 +65,7 @@ function strList(label, v, errs) {
65
65
  }
66
66
  return out;
67
67
  }
68
- /** 校验权限清单,返回错误列表(空表示合法)。 */
68
+ /** Validates the permission manifest and returns the list of errors (empty means valid). */
69
69
  export function validatePermissions(plugin, p) {
70
70
  if (p === undefined)
71
71
  return [];
@@ -202,7 +202,6 @@ export function validatePermissions(plugin, p) {
202
202
  }
203
203
  const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
204
204
  const UI_TITLE_MAX = 100;
205
- const UI_PLACES = Object.keys(PLACE_SLOTS);
206
205
  const UI_EMBED_PREFIX = "/ui/";
207
206
  /**
208
207
  * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
@@ -249,7 +248,6 @@ export function validateUiContributions(ui, permissions) {
249
248
  contributions.push(...ui);
250
249
  }
251
250
  const seen = new Map();
252
- const aliases = [];
253
251
  contributions.forEach((c, i) => {
254
252
  const at = `ui[${i}]`;
255
253
  if (!isObj(c)) {
@@ -265,22 +263,10 @@ export function validateUiContributions(ui, permissions) {
265
263
  if (!title ||
266
264
  [title.zh, title.en].some((t) => typeof t !== "string" || t === "" || t.length > UI_TITLE_MAX))
267
265
  errs.push(`ui "${id}" title needs non-empty zh and en of at most ${UI_TITLE_MAX} characters`);
268
- // the slot it names, when the slot / place is well formed (known to the catalog or not)
269
- let slotRef = null;
270
- if ((c.slot === undefined) === (c.place === undefined)) {
271
- errs.push(`ui "${id}" needs exactly one of slot and place`);
272
- }
273
- else if (c.slot !== undefined) {
274
- slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
275
- if (slotRef === null)
276
- errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
277
- }
278
- else if (!UI_PLACES.includes(c.place)) {
279
- errs.push(`ui "${id}" place must be one of ${UI_PLACES.join(", ")}`);
280
- }
281
- else {
282
- slotRef = { id: PLACE_SLOTS[c.place], version: 1 };
283
- }
266
+ // the slot it names, when it is well formed (known to the catalog or not)
267
+ const slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
268
+ if (slotRef === null)
269
+ errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
284
270
  if (c.after !== undefined && typeof c.after !== "string")
285
271
  errs.push(`ui "${id}" after must be a string`);
286
272
  if (c.kind !== "view" && c.kind !== "embed" && c.kind !== "component") {
@@ -296,11 +282,9 @@ export function validateUiContributions(ui, permissions) {
296
282
  if (spec !== undefined) {
297
283
  if (!spec.accepts.includes(c.kind))
298
284
  errs.push(`ui "${id}" slot ${spec.id} does not accept kind ${c.kind}`);
299
- if (spec.icon === "required" && c.icon === undefined && c.aliasOf === undefined)
285
+ if (spec.icon === "required" && c.icon === undefined)
300
286
  errs.push(`ui "${id}" slot ${spec.id} needs an icon`);
301
287
  }
302
- if (c.aliasOf !== undefined)
303
- aliases.push({ id, kind: c.kind, target: c.aliasOf });
304
288
  if (seen.has(id))
305
289
  errs.push(`ui has duplicate id "${id}"`);
306
290
  seen.set(id, c.kind);
@@ -327,14 +311,6 @@ export function validateUiContributions(ui, permissions) {
327
311
  errs.push(`ui "${id}" embed path "${c.path}" must be declared in permissions.http as GET with access public`);
328
312
  }
329
313
  });
330
- const aliasIds = new Set(aliases.map((a) => a.id));
331
- for (const a of aliases) {
332
- if (typeof a.target !== "string" ||
333
- a.target === a.id ||
334
- aliasIds.has(a.target) ||
335
- seen.get(a.target) !== a.kind)
336
- errs.push(`ui "${a.id}" aliasOf must name another, non-alias ${a.kind} contribution`);
337
- }
338
314
  for (const [k, kind, ids] of [
339
315
  ["views", "view", views],
340
316
  ["embeds", "embed", embeds],