@capybara-hq/plugin-sdk 0.1.0-rc.25 → 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 (50) hide show
  1. package/agent-docs/extension-points/model-provider.md +3 -1
  2. package/agent-docs/extension-points/object-store.md +2 -0
  3. package/dist/cards.d.ts +17 -8
  4. package/dist/cards.js +21 -10
  5. package/dist/channel.d.ts +91 -47
  6. package/dist/channel.js +10 -5
  7. package/dist/connector-auth.d.ts +5 -2
  8. package/dist/connector-auth.js +14 -8
  9. package/dist/connector.d.ts +67 -32
  10. package/dist/ctx.d.ts +41 -23
  11. package/dist/define-extension.d.ts +21 -11
  12. package/dist/define-extension.js +10 -4
  13. package/dist/device-protocol.d.ts +2 -1
  14. package/dist/extension-point.js +1 -1
  15. package/dist/hooks.d.ts +6 -4
  16. package/dist/identity.d.ts +22 -9
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/model-params.d.ts +41 -22
  20. package/dist/model-params.js +28 -15
  21. package/dist/model.d.ts +121 -70
  22. package/dist/model.js +49 -19
  23. package/dist/permissions.d.ts +6 -6
  24. package/dist/permissions.js +8 -32
  25. package/dist/plugin-package.d.ts +79 -38
  26. package/dist/plugin-package.js +57 -29
  27. package/dist/sandbox-linux-runtime-source.d.ts +15 -0
  28. package/dist/sandbox-linux-runtime-source.js +1412 -0
  29. package/dist/sandbox-runtime-source.d.ts +9 -3
  30. package/dist/sandbox-runtime-source.js +16 -4
  31. package/dist/sandbox.d.ts +4 -1
  32. package/dist/sandbox.js +7 -3
  33. package/dist/secret.d.ts +4 -1
  34. package/dist/secret.js +4 -1
  35. package/dist/setup-guide.d.ts +1 -1
  36. package/dist/setup-guide.js +1 -1
  37. package/dist/skill.d.ts +27 -17
  38. package/dist/skill.js +39 -25
  39. package/dist/storage.d.ts +52 -25
  40. package/dist/tool.d.ts +51 -23
  41. package/dist/tool.js +21 -9
  42. package/dist/ui-resolve.d.ts +2 -7
  43. package/dist/ui-resolve.js +7 -19
  44. package/dist/ui-slots.d.ts +1 -3
  45. package/dist/ui-slots.js +0 -9
  46. package/dist/ui.d.ts +63 -49
  47. package/dist/ui.js +36 -22
  48. package/dist/url.d.ts +4 -1
  49. package/dist/url.js +4 -1
  50. package/package.json +1 -1
@@ -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;
@@ -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;
@@ -112,39 +122,63 @@ export type ContentBlock =
112
122
  isError: boolean;
113
123
  }
114
124
  /**
115
- * 图片(只出现在 user 消息里)。模型不支持 `vision` 时内核换成文字占位,插件不用把关;
116
- * 不认识此块的旧插件会跳过它。
125
+ * An image (only in user messages). When the model has no `vision` the kernel sends an English
126
+ * placeholder instead; a plugin need not check. An older plugin that does not know this block
127
+ * skips it. `size` is display metadata (the UI chip, the reference line) and is never sent.
117
128
  */
118
129
  | {
119
130
  type: "image";
120
131
  mediaType: ImageMediaType;
121
132
  source: MediaSource;
122
133
  name?: string;
134
+ size?: number;
123
135
  }
124
- /** 文档(只出现在 user 消息里),由 `capabilities.documents` 把关,规则同 image。 */
136
+ /** A document (only in user messages), gated by `capabilities.documents`; same rules as image. */
125
137
  | {
126
138
  type: "document";
127
139
  mediaType: DocumentMediaType;
128
140
  source: MediaSource;
129
141
  name?: string;
142
+ size?: number;
143
+ }
144
+ /**
145
+ * An attachment whose content the model cannot read (an xlsx, say): the kernel replaces it with
146
+ * text carrying an unsigned object reference before the request, so a provider **never** receives
147
+ * this block. `mediaType` is any non-empty `type/subtype`; `size` is display metadata (the UI
148
+ * chip, the reference line) and is never sent.
149
+ */
150
+ | {
151
+ type: "file";
152
+ mediaType: string;
153
+ source: MediaSource;
154
+ name?: string;
155
+ size?: number;
130
156
  };
131
- /** 媒体块 `name` 的最大长度(字符)。 */
157
+ /** Maximum length (characters) of a media block's `name`. */
132
158
  export declare const MEDIA_NAME_MAX_CHARS = 255;
133
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
159
+ /**
160
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
161
+ * {@link clipMediaName}.
162
+ */
134
163
  export declare const PROVIDER_MEDIA_NAME_MAX = 200;
135
164
  /**
136
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
137
- * 尽量保留扩展名(不超过 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.
138
169
  */
139
170
  export declare function clipMediaName(name: string, max?: number): string;
140
- /** 是否含控制字符(C0、DEL 与 C1)。 */
171
+ /** Whether it contains control characters (C0, DEL and C1). */
141
172
  export declare function hasControlChars(s: string): boolean;
142
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
173
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
143
174
  export declare function isAttachmentId(s: unknown): s is string;
144
175
  /**
145
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
146
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
147
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
176
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
177
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
178
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
179
+ * `attachmentId` is a UUID; `name`, when present, is a string of at most
180
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
181
+ * non-negative integer (display metadata, never sent by a plugin).
148
182
  */
149
183
  export declare function validateMediaBlock(b: unknown): string[];
150
184
  export type ModelMessage = {
@@ -154,7 +188,10 @@ export type ModelMessage = {
154
188
  role: "assistant";
155
189
  content: ContentBlock[];
156
190
  }
157
- /** 对话中途的系统提醒;模型不支持时由插件转成 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
+ */
158
195
  | {
159
196
  role: "system";
160
197
  content: string;
@@ -166,7 +203,10 @@ export interface ToolDefinition {
166
203
  }
167
204
  export interface ModelRequest {
168
205
  model: string;
169
- /** 稳定内容在前;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
+ */
170
210
  system: {
171
211
  text: string;
172
212
  cache: boolean;
@@ -174,32 +214,46 @@ export interface ModelRequest {
174
214
  messages: ModelMessage[];
175
215
  tools: ToolDefinition[];
176
216
  /**
177
- * `@2`:模型可否调用工具。`"none"` = 本次只能回复文本、不得调用工具(`tools` 仍照常带上:历史里有工具调用时
178
- * 部分供应商要求请求声明工具,且保持缓存前缀稳定);缺省或 `"auto"` = 由模型决定。
179
- * 插件映射到原生字段(如 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.
180
223
  */
181
224
  toolChoice?: "auto" | "none";
182
225
  maxOutputTokens: number;
183
- /** `@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
+ */
184
230
  params: Record<string, ParamValue>;
185
- /** @deprecated `model-provider@1` 用;`@2` 插件读 `params.effort`。 */
186
- 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;
187
237
  }
188
- /** `model-provider@1` 的请求:没有 `params` 与 `toolChoice`。 */
189
- export type ModelRequestV1 = Omit<ModelRequest, "params" | "toolChoice">;
190
238
  export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
191
239
  /**
192
- * 一次调用的 token 用量。三类输入互不重叠:本次请求的输入总量 =
193
- * `inputTokens + cacheReadTokens + cacheWriteTokens`(内核据此校正上下文估算、决定何时压缩)。
194
- * 供应商 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.
195
246
  */
196
247
  export interface ModelUsage {
197
- /** 未命中缓存、也未写入缓存的输入 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
+ */
198
252
  inputTokens: number;
199
253
  outputTokens: number;
200
- /** 从提示词缓存读取的输入 token。 */
254
+ /** Input tokens read from the prompt cache. */
201
255
  cacheReadTokens: number;
202
- /** 本次写入提示词缓存的输入 token。 */
256
+ /** Input tokens written to the prompt cache in this call. */
203
257
  cacheWriteTokens: number;
204
258
  }
205
259
  export type ModelStreamEvent = {
@@ -215,9 +269,11 @@ export type ModelStreamEvent = {
215
269
  usage: ModelUsage;
216
270
  };
217
271
  export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "aborted";
218
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
272
+ /** True for rate_limited / overloaded / server / timeout / network. */
219
273
  export declare function isRetryableKind(kind: ModelErrorKind): boolean;
220
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
274
+ /**
275
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
276
+ */
221
277
  export declare function isModelError(e: unknown): e is ModelError;
222
278
  export declare class ModelError extends Error {
223
279
  readonly kind: ModelErrorKind;
@@ -226,7 +282,7 @@ export declare class ModelError extends Error {
226
282
  retryAfterMs?: number;
227
283
  cause?: unknown;
228
284
  });
229
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
285
+ /** True for rate_limited / overloaded / server / timeout / network. */
230
286
  get retryable(): boolean;
231
287
  }
232
288
  /**
@@ -260,11 +316,14 @@ export interface EmbedResult {
260
316
  * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
261
317
  */
262
318
  export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
263
- /** `model-provider@2` 的实现。 */
319
+ /** The `model-provider@2` implementation. */
264
320
  export interface ModelProvider {
265
- /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
321
+ /**
322
+ * Every model's `parameters` must pass `assertValidDeclarations`, otherwise the kernel does not
323
+ * use this vendor.
324
+ */
266
325
  listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
267
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
326
+ /** The event sequence must end with exactly one message_complete; throw ModelError on error. */
268
327
  stream(req: ModelRequest, opts: {
269
328
  signal: AbortSignal;
270
329
  } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
@@ -273,13 +332,5 @@ export interface ModelProvider {
273
332
  signal: AbortSignal;
274
333
  } & ModelCallOptions): Promise<EmbedResult>;
275
334
  }
276
- /** `model-provider@1` 的实现(旧契约,内核经适配层接入:effort 由 `capabilities.effort` 推导)。 */
277
- export interface ModelProviderV1 {
278
- listModels(): Promise<ModelInfoV1[]>;
279
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
280
- stream(req: ModelRequestV1, opts: {
281
- signal: AbortSignal;
282
- }): AsyncIterable<ModelStreamEvent>;
283
- }
284
- 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). */
285
336
  export declare const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";