@capybara-hq/plugin-sdk 0.1.0-rc.4 → 0.1.0-rc.41

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 (133) hide show
  1. package/agent-docs/agent-templates.md +15 -3
  2. package/agent-docs/concepts.md +13 -3
  3. package/agent-docs/connector-templates.md +2 -1
  4. package/agent-docs/extension-points/channel.md +2 -2
  5. package/agent-docs/extension-points/config-source.md +1 -1
  6. package/agent-docs/extension-points/connector.md +1 -1
  7. package/agent-docs/extension-points/context.md +15 -0
  8. package/agent-docs/extension-points/counter.md +1 -1
  9. package/agent-docs/extension-points/directory.md +1 -1
  10. package/agent-docs/extension-points/file-preview.md +3 -1
  11. package/agent-docs/extension-points/identity-source.md +1 -1
  12. package/agent-docs/extension-points/model-provider.md +4 -2
  13. package/agent-docs/extension-points/object-store.md +3 -1
  14. package/agent-docs/extension-points/sandbox.md +3 -3
  15. package/agent-docs/extension-points/secret-store.md +1 -1
  16. package/agent-docs/extension-points/web-fetch.md +1 -1
  17. package/agent-docs/extension-points/web-search.md +1 -1
  18. package/agent-docs/extensions.md +29 -4
  19. package/agent-docs/plugin-format.md +43 -3
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +1 -1
  22. package/agent-docs/tool-naming.md +1 -1
  23. package/dist/agent-template.d.ts +15 -6
  24. package/dist/agent-template.js +32 -13
  25. package/dist/bootstrap.d.ts +15 -1
  26. package/dist/bootstrap.js +17 -1
  27. package/dist/cards.d.ts +67 -13
  28. package/dist/cards.js +91 -21
  29. package/dist/channel.d.ts +148 -48
  30. package/dist/channel.js +10 -5
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +22 -0
  36. package/dist/config-ui.js +64 -4
  37. package/dist/connector-auth.d.ts +7 -2
  38. package/dist/connector-auth.js +29 -8
  39. package/dist/connector.d.ts +74 -32
  40. package/dist/context.d.ts +40 -0
  41. package/dist/context.js +2 -0
  42. package/dist/ctx.d.ts +120 -29
  43. package/dist/define-extension.d.ts +26 -12
  44. package/dist/define-extension.js +11 -4
  45. package/dist/device-denied-paths.d.ts +14 -0
  46. package/dist/device-denied-paths.js +41 -0
  47. package/dist/device-protocol.d.ts +481 -0
  48. package/dist/device-protocol.js +1113 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +5 -2
  51. package/dist/file-preview.d.ts +23 -6
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +125 -20
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +62 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +22 -9
  59. package/dist/index.d.ts +26 -1
  60. package/dist/index.js +26 -1
  61. package/dist/marketplace.d.ts +26 -0
  62. package/dist/marketplace.js +43 -1
  63. package/dist/model-params.d.ts +41 -22
  64. package/dist/model-params.js +28 -15
  65. package/dist/model.d.ts +206 -71
  66. package/dist/model.js +152 -19
  67. package/dist/net.d.ts +52 -0
  68. package/dist/net.js +34 -0
  69. package/dist/network-classes.d.ts +98 -0
  70. package/dist/network-classes.js +291 -0
  71. package/dist/permissions.d.ts +41 -21
  72. package/dist/permissions.js +101 -42
  73. package/dist/plugin-manifest.d.ts +45 -5
  74. package/dist/plugin-manifest.js +169 -6
  75. package/dist/plugin-package.d.ts +82 -38
  76. package/dist/plugin-package.js +61 -29
  77. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  78. package/dist/sandbox-linux-runtime-source.js +2318 -0
  79. package/dist/sandbox-native-runtime-source.d.ts +8 -0
  80. package/dist/sandbox-native-runtime-source.js +465 -0
  81. package/dist/sandbox-operation.d.ts +284 -0
  82. package/dist/sandbox-operation.js +262 -0
  83. package/dist/sandbox-runtime-source.d.ts +19 -0
  84. package/dist/sandbox-runtime-source.js +28 -0
  85. package/dist/sandbox-write-denies.d.ts +139 -0
  86. package/dist/sandbox-write-denies.js +869 -0
  87. package/dist/sandbox.d.ts +190 -16
  88. package/dist/sandbox.js +89 -14
  89. package/dist/secret.d.ts +4 -1
  90. package/dist/secret.js +4 -1
  91. package/dist/setup-check.d.ts +115 -0
  92. package/dist/setup-check.js +142 -0
  93. package/dist/setup-guide-parse.d.ts +121 -0
  94. package/dist/setup-guide-parse.js +350 -0
  95. package/dist/setup-guide-render.d.ts +45 -0
  96. package/dist/setup-guide-render.js +351 -0
  97. package/dist/setup-guide.d.ts +94 -0
  98. package/dist/setup-guide.js +336 -0
  99. package/dist/shell-capabilities.d.ts +88 -0
  100. package/dist/shell-capabilities.js +13 -0
  101. package/dist/shell-environment.d.ts +57 -0
  102. package/dist/shell-environment.js +16 -0
  103. package/dist/skill-invocation.d.ts +4 -3
  104. package/dist/skill-invocation.js +5 -4
  105. package/dist/skill.d.ts +34 -21
  106. package/dist/skill.js +48 -31
  107. package/dist/storage.d.ts +52 -25
  108. package/dist/theme-assets.d.ts +39 -0
  109. package/dist/theme-assets.js +449 -0
  110. package/dist/theme-readability.d.ts +37 -0
  111. package/dist/theme-readability.js +145 -0
  112. package/dist/theme-tokens.generated.d.ts +287 -0
  113. package/dist/theme-tokens.generated.js +176 -0
  114. package/dist/theme.d.ts +152 -0
  115. package/dist/theme.js +392 -0
  116. package/dist/tool.d.ts +69 -26
  117. package/dist/tool.js +29 -9
  118. package/dist/ui-parts.d.ts +23 -0
  119. package/dist/ui-parts.js +348 -0
  120. package/dist/ui-resolve.d.ts +35 -0
  121. package/dist/ui-resolve.js +42 -0
  122. package/dist/ui-slots.d.ts +65 -0
  123. package/dist/ui-slots.js +261 -0
  124. package/dist/ui.d.ts +212 -76
  125. package/dist/ui.js +101 -27
  126. package/dist/url.d.ts +4 -1
  127. package/dist/url.js +4 -1
  128. package/package.json +8 -1
  129. package/schemas/bootstrap.v1.schema.json +6 -0
  130. package/schemas/connector-template.v1.schema.json +35 -0
  131. package/schemas/marketplace.v1.schema.json +14 -0
  132. package/schemas/plugin.v1.schema.json +115 -3
  133. package/schemas/theme.v1.schema.json +225 -0
package/dist/model.d.ts CHANGED
@@ -1,11 +1,15 @@
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
- /** What a model does. Absent on a `ModelInfo` means `chat`. */
9
+ /**
10
+ * What a model does. Absent on a `ModelInfo` means `chat`. Callable kinds: `chat` (`stream`),
11
+ * `embedding` (`embed`) and `image_generation` (`generateImage`); the others are list-only.
12
+ */
9
13
  export type ModelKind = "chat" | "embedding" | "rerank" | "image_generation" | "video_generation" | "speech_to_text" | "text_to_speech";
10
14
  /** Embedding facts of a model whose `kind` is `embedding`. */
11
15
  export interface ModelEmbeddingInfo {
@@ -17,6 +21,27 @@ export interface ModelEmbeddingInfo {
17
21
  /** Most inputs one `embed` call may carry. */
18
22
  maxBatch: number;
19
23
  }
24
+ /** An output size of an image generation model, in pixels. */
25
+ export interface ImageSize {
26
+ width: number;
27
+ height: number;
28
+ }
29
+ /** The aspect ratios a caller may ask for instead of an exact size. */
30
+ export declare const IMAGE_ASPECT_RATIOS: readonly ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16"];
31
+ export type ImageAspectRatio = (typeof IMAGE_ASPECT_RATIOS)[number];
32
+ /** Image generation facts of a model whose `kind` is `image_generation`. */
33
+ export interface ModelImageGenerationInfo {
34
+ /** The output sizes the model offers. */
35
+ sizes: ImageSize[];
36
+ /** One of `sizes`, used when the caller asks for none. */
37
+ defaultSize: ImageSize;
38
+ /** Most images one `generateImage` call may produce. */
39
+ maxImages: number;
40
+ /** Most reference images one call may carry (0 = text to image only). */
41
+ maxReferenceImages: number;
42
+ /** The media types the model returns. */
43
+ outputMediaTypes: ImageMediaType[];
44
+ }
20
45
  export interface ModelInfo {
21
46
  id: string;
22
47
  displayName: string;
@@ -30,6 +55,8 @@ export interface ModelInfo {
30
55
  retiresAt?: string;
31
56
  /** Set when `kind` is `embedding`. */
32
57
  embedding?: ModelEmbeddingInfo;
58
+ /** Set when `kind` is `image_generation`. */
59
+ imageGeneration?: ModelImageGenerationInfo;
33
60
  contextWindow: number;
34
61
  maxOutputTokens: number;
35
62
  capabilities: {
@@ -39,43 +66,46 @@ export interface ModelInfo {
39
66
  caching: boolean;
40
67
  midConversationSystem: boolean;
41
68
  /**
42
- * 是否接受 `document` 块(缺省为 false)。图片看 `vision`。模型不支持时内核把媒体块换成英文文字占位
43
- * (如 `[Attached image "<name>" — this model cannot view images.]`;`text/*` 文档改为内联截断后的文本),
44
- * 绝不把字节发给它。
69
+ * Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
70
+ * the model does not support them the kernel replaces media blocks with English text
71
+ * placeholders
72
+ * (e.g. `[Attached image "<name>" — this model cannot view images. Read with file_id <id> sends it to the organization's vision model, if one is set.]`; `text/*` documents are
73
+ * inlined as truncated text instead),
74
+ * and never sends the bytes to it.
45
75
  */
46
76
  documents?: boolean;
47
- /**
48
- * @deprecated `model-provider@1` 用:是否支持 `ModelRequestV1.effort`。`@2` 插件不填,改在
49
- * `parameters` 中声明 `effort` 旋钮;内核的 `@1` 适配层据此推导 `parameters`。
50
- */
51
- effort?: boolean;
52
77
  };
53
- /** 流空闲看门狗阈值;推理类模型应更长。未给时内核用配置默认值。 */
78
+ /**
79
+ * Stream idle watchdog threshold; reasoning models should use a longer one. When unset the kernel
80
+ * uses the config default.
81
+ */
54
82
  streamIdleTimeoutMs?: number;
55
- /** 该模型支持的参数(`@2` 必填,可为空数组;须通过 `assertValidDeclarations`)。 */
83
+ /**
84
+ * The parameters this model supports (may be an empty array; must pass
85
+ * `assertValidDeclarations`). Effort is the standard `effort` knob declared here.
86
+ */
56
87
  parameters: ModelParameter[];
57
88
  }
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 加密推理项)。 */
89
+ /**
90
+ * Vendor-private data: replayed only to the same vendor (e.g. Anthropic thinking block signatures,
91
+ * OpenAI encrypted reasoning items).
92
+ */
65
93
  export interface ProviderOpaque {
66
94
  provider: string;
67
95
  model: string;
68
96
  data: unknown;
69
97
  }
70
- /** 图片块接受的类型。 */
98
+ /** Types accepted by image blocks. */
71
99
  export declare const IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
72
- /** 文档块接受的类型。 */
100
+ /** Types accepted by document blocks. */
73
101
  export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv"];
74
102
  export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
75
103
  export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
76
104
  /**
77
- * 媒体内容的来源:`base64` 是字节本身,`ref` 是内核附件的引用。
78
- * 事件日志里只存 `ref`(字节不进日志);内核构建请求时把 `ref` 解析成 `base64`,插件只会收到 `base64`。
105
+ * The source of media content: `base64` is the bytes themselves, `ref` is a reference to a kernel
106
+ * attachment.
107
+ * The event log stores only `ref` (bytes never enter the log); when building a request the kernel
108
+ * resolves `ref` into `base64`, so plugins only ever receive `base64`.
79
109
  */
80
110
  export type MediaSource = {
81
111
  kind: "base64";
@@ -84,13 +114,19 @@ export type MediaSource = {
84
114
  kind: "ref";
85
115
  attachmentId: string;
86
116
  };
87
- /** 单个媒体块解码后的字节上限(按主流供应商的较小值取)。 */
117
+ /**
118
+ * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
119
+ * vendors).
120
+ */
88
121
  export declare const MEDIA_LIMITS: {
89
122
  readonly imageBytes: 5242880;
90
123
  readonly documentBytes: 33554432;
91
124
  };
92
125
  export type ContentBlock =
93
- /** text 的 opaque:供应商需要随文本回放的私有数据(如 OpenAI message 输出项的 id)。 */
126
+ /**
127
+ * Opaque for text: vendor-private data that must be replayed with the text (e.g. the id of an
128
+ * OpenAI message output item).
129
+ */
94
130
  {
95
131
  type: "text";
96
132
  text: string;
@@ -112,39 +148,63 @@ export type ContentBlock =
112
148
  isError: boolean;
113
149
  }
114
150
  /**
115
- * 图片(只出现在 user 消息里)。模型不支持 `vision` 时内核换成文字占位,插件不用把关;
116
- * 不认识此块的旧插件会跳过它。
151
+ * An image (only in user messages). When the model has no `vision` the kernel sends an English
152
+ * placeholder instead; a plugin need not check. An older plugin that does not know this block
153
+ * skips it. `size` is display metadata (the UI chip, the reference line) and is never sent.
117
154
  */
118
155
  | {
119
156
  type: "image";
120
157
  mediaType: ImageMediaType;
121
158
  source: MediaSource;
122
159
  name?: string;
160
+ size?: number;
123
161
  }
124
- /** 文档(只出现在 user 消息里),由 `capabilities.documents` 把关,规则同 image。 */
162
+ /** A document (only in user messages), gated by `capabilities.documents`; same rules as image. */
125
163
  | {
126
164
  type: "document";
127
165
  mediaType: DocumentMediaType;
128
166
  source: MediaSource;
129
167
  name?: string;
168
+ size?: number;
169
+ }
170
+ /**
171
+ * An attachment whose content the model cannot read (an xlsx, say): the kernel replaces it with
172
+ * text carrying an unsigned object reference before the request, so a provider **never** receives
173
+ * this block. `mediaType` is any non-empty `type/subtype`; `size` is display metadata (the UI
174
+ * chip, the reference line) and is never sent.
175
+ */
176
+ | {
177
+ type: "file";
178
+ mediaType: string;
179
+ source: MediaSource;
180
+ name?: string;
181
+ size?: number;
130
182
  };
131
- /** 媒体块 `name` 的最大长度(字符)。 */
183
+ /** Maximum length (characters) of a media block's `name`. */
132
184
  export declare const MEDIA_NAME_MAX_CHARS = 255;
133
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
185
+ /**
186
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
187
+ * {@link clipMediaName}.
188
+ */
134
189
  export declare const PROVIDER_MEDIA_NAME_MAX = 200;
135
190
  /**
136
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
137
- * 尽量保留扩展名(不超过 16 个字符的 `.ext`),中间用 `…` 表示截掉的部分。纯函数。
191
+ * Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
192
+ * filename / title length, and adding a suffix makes it longer still).
193
+ * Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
194
+ * part in the middle. A pure function.
138
195
  */
139
196
  export declare function clipMediaName(name: string, max?: number): string;
140
- /** 是否含控制字符(C0、DEL 与 C1)。 */
197
+ /** Whether it contains control characters (C0, DEL and C1). */
141
198
  export declare function hasControlChars(s: string): boolean;
142
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
199
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
143
200
  export declare function isAttachmentId(s: unknown): s is string;
144
201
  /**
145
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
146
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
147
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
202
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
203
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
204
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
205
+ * `attachmentId` is a UUID; `name`, when present, is a string of at most
206
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
207
+ * non-negative integer (display metadata, never sent by a plugin).
148
208
  */
149
209
  export declare function validateMediaBlock(b: unknown): string[];
150
210
  export type ModelMessage = {
@@ -154,7 +214,10 @@ export type ModelMessage = {
154
214
  role: "assistant";
155
215
  content: ContentBlock[];
156
216
  }
157
- /** 对话中途的系统提醒;模型不支持时由插件转成 user 文本块(以 "[system] " 开头)。 */
217
+ /**
218
+ * A mid-conversation system reminder; when the model does not support it the plugin turns it into
219
+ * a user text block (starting with "[system] ").
220
+ */
158
221
  | {
159
222
  role: "system";
160
223
  content: string;
@@ -166,7 +229,10 @@ export interface ToolDefinition {
166
229
  }
167
230
  export interface ModelRequest {
168
231
  model: string;
169
- /** 稳定内容在前;cache 为 true 的块之后打缓存断点(由插件按原生协议实现)。 */
232
+ /**
233
+ * Stable content first; after a block with cache true a cache breakpoint is placed (implemented
234
+ * by the plugin per the native protocol).
235
+ */
170
236
  system: {
171
237
  text: string;
172
238
  cache: boolean;
@@ -174,33 +240,50 @@ export interface ModelRequest {
174
240
  messages: ModelMessage[];
175
241
  tools: ToolDefinition[];
176
242
  /**
177
- * `@2`:模型可否调用工具。`"none"` = 本次只能回复文本、不得调用工具(`tools` 仍照常带上:历史里有工具调用时
178
- * 部分供应商要求请求声明工具,且保持缓存前缀稳定);缺省或 `"auto"` = 由模型决定。
179
- * 插件映射到原生字段(如 Anthropic `tool_choice: {type: "none"}`);`tools` 为空时插件不发送该字段。
243
+ * `@2`: whether the model may call tools. `"none"` = this call may only reply with text and must
244
+ * not call tools (`tools` is still sent as usual: when the history has tool calls
245
+ * some vendors require the request to declare tools, and it keeps the cache prefix stable);
246
+ * omitted or `"auto"` = the model decides.
247
+ * The plugin maps it to the native field (e.g. Anthropic `tool_choice: {type: "none"}`); when
248
+ * `tools` is empty the plugin does not send the field.
180
249
  */
181
250
  toolChoice?: "auto" | "none";
182
251
  maxOutputTokens: number;
183
- /** `@2`:本次调用的参数(已按该模型的 `parameters` 处理过),由插件映射到原生请求。 */
252
+ /**
253
+ * The parameters of this call (already processed against the model's `parameters`), mapped to the
254
+ * native request by the plugin.
255
+ */
184
256
  params: Record<string, ParamValue>;
185
- /** @deprecated `model-provider@1` 用;`@2` 插件读 `params.effort`。 */
186
- effort?: Effort;
257
+ /**
258
+ * What this call is for, when the kernel says so: `"compaction"` for a conversation summary call,
259
+ * `"suggestion"` for a prompt suggestion call. Absent on ordinary step calls. Informational (a
260
+ * scripted test model keys on it); real providers ignore it and must not forward it to a vendor
261
+ * API.
262
+ */
263
+ purpose?: ModelCallPurpose;
187
264
  }
188
- /** `model-provider@1` 的请求:没有 `params` 与 `toolChoice`。 */
189
- export type ModelRequestV1 = Omit<ModelRequest, "params" | "toolChoice">;
190
265
  export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
191
266
  /**
192
- * 一次调用的 token 用量。三类输入互不重叠:本次请求的输入总量 =
193
- * `inputTokens + cacheReadTokens + cacheWriteTokens`(内核据此校正上下文估算、决定何时压缩)。
194
- * 供应商 API 的输入计数若已包含缓存命中 / 写入的 token(如 OpenAI 的 `prompt_tokens`),插件必须先减掉。
267
+ * Token usage of one call. The three kinds of input do not overlap: the total input of this request
268
+ * =
269
+ * `inputTokens + cacheReadTokens + cacheWriteTokens` (the kernel uses it to correct context
270
+ * estimates and to decide when to compact).
271
+ * If the vendor API's input count already includes cache-hit / cache-write tokens (e.g. OpenAI's
272
+ * `prompt_tokens`), the plugin must subtract them first.
195
273
  */
196
274
  export interface ModelUsage {
197
- /** 未命中缓存、也未写入缓存的输入 token(只是未缓存部分,不是输入总量)。 */
275
+ /**
276
+ * Input tokens that neither hit the cache nor were written to it (only the uncached part, not the
277
+ * total input).
278
+ */
198
279
  inputTokens: number;
199
280
  outputTokens: number;
200
- /** 从提示词缓存读取的输入 token。 */
281
+ /** Input tokens read from the prompt cache. */
201
282
  cacheReadTokens: number;
202
- /** 本次写入提示词缓存的输入 token。 */
283
+ /** Input tokens written to the prompt cache in this call. */
203
284
  cacheWriteTokens: number;
285
+ /** Images produced (image generation calls). */
286
+ outputImages?: number;
204
287
  }
205
288
  export type ModelStreamEvent = {
206
289
  type: "text_delta";
@@ -214,10 +297,12 @@ export type ModelStreamEvent = {
214
297
  stopReason: StopReason;
215
298
  usage: ModelUsage;
216
299
  };
217
- export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "aborted";
218
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
300
+ export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "refusal" | "aborted";
301
+ /** True for rate_limited / overloaded / server / timeout / network. */
219
302
  export declare function isRetryableKind(kind: ModelErrorKind): boolean;
220
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
303
+ /**
304
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
305
+ */
221
306
  export declare function isModelError(e: unknown): e is ModelError;
222
307
  export declare class ModelError extends Error {
223
308
  readonly kind: ModelErrorKind;
@@ -226,7 +311,7 @@ export declare class ModelError extends Error {
226
311
  retryAfterMs?: number;
227
312
  cause?: unknown;
228
313
  });
229
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
314
+ /** True for rate_limited / overloaded / server / timeout / network. */
230
315
  get retryable(): boolean;
231
316
  }
232
317
  /**
@@ -260,11 +345,62 @@ export interface EmbedResult {
260
345
  * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
261
346
  */
262
347
  export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
263
- /** `model-provider@2` 的实现。 */
348
+ export interface ImageGenerateRequest {
349
+ model: string;
350
+ prompt: string;
351
+ /** One of the model's `imageGeneration.sizes`. */
352
+ size: ImageSize;
353
+ /** Images to produce, 1 to `imageGeneration.maxImages`. */
354
+ n: number;
355
+ /** Base64 reference images, at most `imageGeneration.maxReferenceImages`. */
356
+ referenceImages?: {
357
+ mediaType: ImageMediaType;
358
+ data: string;
359
+ }[];
360
+ params: Record<string, ParamValue>;
361
+ }
362
+ export interface ImageGenerateResult {
363
+ /** Exactly `req.n` images, base64 encoded. */
364
+ images: {
365
+ mediaType: ImageMediaType;
366
+ data: string;
367
+ }[];
368
+ /** The prompt as the vendor rewrote it, when it did. */
369
+ revisedPrompt?: string;
370
+ usage: ModelUsage;
371
+ }
372
+ /** True when `x` is a well-formed {@link ModelImageGenerationInfo}. */
373
+ export declare function isValidImageGenerationInfo(x: unknown): x is ModelImageGenerationInfo;
374
+ /**
375
+ * Checks an image generation result against its request and the model's facts. Returns null when
376
+ * valid, else the reason: wrong image count, an undeclared media type, data that is not base64,
377
+ * or a `usage` that is not an object whose token counts (and `outputImages`, when present) are
378
+ * non-negative integers (a caller records usage from it, so it is checked before anything is).
379
+ */
380
+ export declare function validateImageGenerateResult(req: ImageGenerateRequest, info: ModelImageGenerationInfo, res: unknown): string | null;
381
+ /**
382
+ * Chooses an output size: an exact `size` must be one the model offers; an `aspectRatio` picks the
383
+ * closest declared ratio (ties by area closest to the default's, then declaration order); neither
384
+ * gives the default size.
385
+ */
386
+ export declare function pickImageSize(info: ModelImageGenerationInfo, opts: {
387
+ size?: ImageSize;
388
+ aspectRatio?: ImageAspectRatio;
389
+ }): {
390
+ ok: true;
391
+ size: ImageSize;
392
+ } | {
393
+ ok: false;
394
+ error: string;
395
+ };
396
+ /** The `model-provider@2` implementation. */
264
397
  export interface ModelProvider {
265
- /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
398
+ /**
399
+ * Every model's `parameters` must pass `assertValidDeclarations`, otherwise the kernel does not
400
+ * use this vendor.
401
+ */
266
402
  listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
267
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
403
+ /** The event sequence must end with exactly one message_complete; throw ModelError on error. */
268
404
  stream(req: ModelRequest, opts: {
269
405
  signal: AbortSignal;
270
406
  } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
@@ -272,14 +408,13 @@ export interface ModelProvider {
272
408
  embed?(req: EmbedRequest, opts: {
273
409
  signal: AbortSignal;
274
410
  } & ModelCallOptions): Promise<EmbedResult>;
275
- }
276
- /** `model-provider@1` 的实现(旧契约,内核经适配层接入:effort 由 `capabilities.effort` 推导)。 */
277
- export interface ModelProviderV1 {
278
- listModels(): Promise<ModelInfoV1[]>;
279
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
280
- stream(req: ModelRequestV1, opts: {
411
+ /**
412
+ * Present only on a provider that lists `image_generation` models. Throws `ModelError` of kind
413
+ * `refusal` when the vendor declines the prompt.
414
+ */
415
+ generateImage?(req: ImageGenerateRequest, opts: {
281
416
  signal: AbortSignal;
282
- }): AsyncIterable<ModelStreamEvent>;
417
+ } & ModelCallOptions): Promise<ImageGenerateResult>;
283
418
  }
284
- export declare const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
419
+ /** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
285
420
  export declare const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";