@capybara-hq/plugin-sdk 0.1.0-rc.9 → 0.1.0-rc.90

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 (159) hide show
  1. package/README.md +3 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +3 -1
  9. package/agent-docs/extension-points/identity-source.md +2 -0
  10. package/agent-docs/extension-points/model-provider.md +5 -1
  11. package/agent-docs/extension-points/object-store.md +2 -0
  12. package/agent-docs/extension-points/push-provider.md +17 -0
  13. package/agent-docs/extension-points/trigger-source.md +19 -0
  14. package/agent-docs/extensions.md +98 -4
  15. package/agent-docs/plugin-format.md +45 -10
  16. package/agent-docs/setup.md +54 -0
  17. package/api/plugin-sdk.api.md +5983 -0
  18. package/dist/agent-template.d.ts +15 -6
  19. package/dist/agent-template.js +32 -13
  20. package/dist/agents-ctx.d.ts +116 -0
  21. package/dist/agents-ctx.js +22 -0
  22. package/dist/avatar-presets.d.ts +8 -0
  23. package/dist/avatar-presets.js +17 -0
  24. package/dist/bootstrap.d.ts +109 -1
  25. package/dist/bootstrap.js +185 -2
  26. package/dist/cards.d.ts +121 -13
  27. package/dist/cards.js +161 -19
  28. package/dist/channel.d.ts +133 -47
  29. package/dist/channel.js +10 -5
  30. package/dist/client-css.d.ts +36 -0
  31. package/dist/client-css.js +326 -0
  32. package/dist/client-section.d.ts +35 -0
  33. package/dist/client-section.js +133 -0
  34. package/dist/config-ui.d.ts +28 -6
  35. package/dist/config-ui.js +88 -25
  36. package/dist/config-url-fetch.d.ts +19 -0
  37. package/dist/config-url-fetch.js +43 -0
  38. package/dist/connector-auth.d.ts +13 -2
  39. package/dist/connector-auth.js +82 -8
  40. package/dist/connector.d.ts +74 -32
  41. package/dist/context.d.ts +40 -0
  42. package/dist/context.js +2 -0
  43. package/dist/ctx.d.ts +344 -31
  44. package/dist/ctx.js +9 -1
  45. package/dist/define-extension.d.ts +18 -12
  46. package/dist/define-extension.js +18 -5
  47. package/dist/device-denied-paths.d.ts +20 -0
  48. package/dist/device-denied-paths.js +118 -0
  49. package/dist/device-operation.d.ts +348 -0
  50. package/dist/device-operation.js +312 -0
  51. package/dist/device-protocol.d.ts +286 -49
  52. package/dist/device-protocol.js +766 -89
  53. package/dist/device-provider.d.ts +820 -0
  54. package/dist/device-provider.js +432 -0
  55. package/dist/device-service.d.ts +204 -0
  56. package/dist/device-service.js +291 -0
  57. package/dist/dial-in.d.ts +286 -0
  58. package/dist/dial-in.js +213 -0
  59. package/dist/directory.d.ts +15 -12
  60. package/dist/extension-point.d.ts +2 -0
  61. package/dist/extension-point.js +8 -3
  62. package/dist/field-meta.d.ts +19 -0
  63. package/dist/field-meta.js +54 -0
  64. package/dist/file-preview.d.ts +46 -9
  65. package/dist/git-hosts.d.ts +53 -0
  66. package/dist/git-hosts.js +98 -0
  67. package/dist/hooks.d.ts +185 -22
  68. package/dist/hooks.js +6 -0
  69. package/dist/http-access.d.ts +71 -0
  70. package/dist/http-access.js +12 -0
  71. package/dist/identity.d.ts +70 -9
  72. package/dist/identity.js +46 -1
  73. package/dist/inbox.d.ts +103 -0
  74. package/dist/inbox.js +173 -0
  75. package/dist/index.d.ts +30 -4
  76. package/dist/index.js +30 -4
  77. package/dist/model-params.d.ts +41 -22
  78. package/dist/model-params.js +28 -15
  79. package/dist/model.d.ts +295 -77
  80. package/dist/model.js +249 -21
  81. package/dist/native-failure.d.ts +13 -0
  82. package/dist/native-failure.js +31 -0
  83. package/dist/net.d.ts +52 -0
  84. package/dist/net.js +34 -0
  85. package/dist/network-classes.d.ts +98 -0
  86. package/dist/network-classes.js +291 -0
  87. package/dist/permissions.d.ts +95 -25
  88. package/dist/permissions.js +175 -54
  89. package/dist/platform-only.d.ts +27 -0
  90. package/dist/platform-only.js +35 -0
  91. package/dist/plugin-manifest.d.ts +30 -6
  92. package/dist/plugin-manifest.js +147 -55
  93. package/dist/plugin-package.d.ts +82 -39
  94. package/dist/plugin-package.js +68 -41
  95. package/dist/push.d.ts +75 -0
  96. package/dist/push.js +87 -0
  97. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  98. package/dist/sandbox-linux-runtime-source.js +2343 -0
  99. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  100. package/dist/sandbox-native-runtime-source.js +480 -0
  101. package/dist/sandbox-runtime-source.d.ts +47 -0
  102. package/dist/sandbox-runtime-source.js +73 -0
  103. package/dist/sandbox-write-denies.d.ts +139 -0
  104. package/dist/sandbox-write-denies.js +869 -0
  105. package/dist/secret.d.ts +8 -2
  106. package/dist/secret.js +11 -4
  107. package/dist/setup-check.d.ts +128 -0
  108. package/dist/setup-check.js +142 -0
  109. package/dist/setup-guide-parse.d.ts +121 -0
  110. package/dist/setup-guide-parse.js +356 -0
  111. package/dist/setup-guide-render.d.ts +45 -0
  112. package/dist/setup-guide-render.js +351 -0
  113. package/dist/setup-guide.d.ts +86 -72
  114. package/dist/setup-guide.js +340 -108
  115. package/dist/shell-capabilities.d.ts +216 -0
  116. package/dist/shell-capabilities.js +44 -0
  117. package/dist/shell-environment.d.ts +57 -0
  118. package/dist/shell-environment.js +21 -0
  119. package/dist/skill-invocation.d.ts +5 -0
  120. package/dist/skill-invocation.js +4 -3
  121. package/dist/skill.d.ts +27 -17
  122. package/dist/skill.js +40 -26
  123. package/dist/storage.d.ts +52 -25
  124. package/dist/svg-viewbox.d.ts +10 -0
  125. package/dist/svg-viewbox.js +24 -0
  126. package/dist/theme-assets.d.ts +25 -9
  127. package/dist/theme-assets.js +87 -47
  128. package/dist/theme-tokens.generated.d.ts +40 -12
  129. package/dist/theme-tokens.generated.js +36 -8
  130. package/dist/theme.d.ts +56 -10
  131. package/dist/theme.js +117 -23
  132. package/dist/tool.d.ts +242 -28
  133. package/dist/tool.js +135 -13
  134. package/dist/trigger-source.d.ts +35 -0
  135. package/dist/trigger-source.js +2 -0
  136. package/dist/triggers.d.ts +88 -0
  137. package/dist/triggers.js +71 -0
  138. package/dist/ui-parts.d.ts +23 -0
  139. package/dist/ui-parts.js +374 -0
  140. package/dist/ui-resolve.d.ts +2 -7
  141. package/dist/ui-resolve.js +7 -19
  142. package/dist/ui-slots.d.ts +27 -5
  143. package/dist/ui-slots.js +112 -19
  144. package/dist/ui.d.ts +203 -64
  145. package/dist/ui.js +117 -23
  146. package/dist/url.d.ts +4 -1
  147. package/dist/url.js +4 -1
  148. package/dist/web.d.ts +26 -20
  149. package/package.json +13 -1
  150. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  151. package/schemas/bootstrap.v1.schema.json +20 -0
  152. package/schemas/connector-template.v1.schema.json +62 -4
  153. package/schemas/plugin.v1.schema.json +74 -143
  154. package/schemas/theme.v1.schema.json +77 -0
  155. package/agent-docs/extension-points/sandbox.md +0 -15
  156. package/dist/org-access.d.ts +0 -27
  157. package/dist/org-access.js +0 -35
  158. package/dist/sandbox.d.ts +0 -254
  159. package/dist/sandbox.js +0 -153
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,69 @@ 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
+ }
45
+ /**
46
+ * explicit: the plugin places breakpoints and the lifetime is known; implicit: the service caches
47
+ * on its own (best-effort unless it declares a lifetime floor); none: no caching.
48
+ */
49
+ export type ModelCacheMechanism = "explicit" | "implicit" | "none";
50
+ /** How a model's prompt cache behaves. Absent or `mechanism: "none"` = no caching. */
51
+ export interface ModelCacheInfo {
52
+ /** See {@link ModelCacheMechanism}. */
53
+ mechanism: ModelCacheMechanism;
54
+ /**
55
+ * Lifetimes a request can choose, in seconds ([300, 3600] Anthropic / Qwen4, [1800, 43200]
56
+ * OpenAI 5.6+, [300] Bailian); empty when the service decides alone. Ascending and unique.
57
+ */
58
+ ttlOptions: number[];
59
+ /**
60
+ * The lifetime a request that names none gets (OpenAI 5.6+: 1800). Required, and one of
61
+ * `ttlOptions`, when `ttlOptions` is non-empty.
62
+ */
63
+ defaultTtl?: number;
64
+ /** OpenAI: the lifetime is a floor, entries may live longer; Anthropic / Bailian: exact. */
65
+ ttlIsMinimum: boolean;
66
+ /**
67
+ * True only if a hit restarts the lifetime of every tier the kernel may select. The kernel
68
+ * selects only `defaultTtl` or the smallest option of at least 1800 s, so OpenAI GPT-5.6+
69
+ * declares true (its 30m tier refreshes on a hit; its 12h tier does not, and the kernel never
70
+ * selects 43200). Anthropic and Bailian declare true. When unconfirmed, declare false.
71
+ */
72
+ refreshOnHit: boolean;
73
+ /** When the lifetime starts counting; Anthropic: the request's start. */
74
+ ttlClock: "request_start" | "unknown";
75
+ /** Below this many prompt tokens nothing is cached. */
76
+ minTokens?: number;
77
+ /** A hit on an unchanged prefix within the lifetime is expected, not best-effort. */
78
+ guaranteed: boolean;
79
+ }
80
+ /**
81
+ * Checks a model's cache declaration: positive integer TTLs, `ttlOptions` ascending and unique,
82
+ * `defaultTtl` present and among the options when options exist, `none` with no options and no
83
+ * guarantee, a guarantee only with a known lifetime, `minTokens` a positive integer. Returns the
84
+ * first problem (naming the field), or `null` when valid.
85
+ */
86
+ export declare function validateModelCache(cache: ModelCacheInfo | undefined): string | null;
20
87
  export interface ModelInfo {
21
88
  id: string;
22
89
  displayName: string;
@@ -30,67 +97,79 @@ export interface ModelInfo {
30
97
  retiresAt?: string;
31
98
  /** Set when `kind` is `embedding`. */
32
99
  embedding?: ModelEmbeddingInfo;
100
+ /** Set when `kind` is `image_generation`. */
101
+ imageGeneration?: ModelImageGenerationInfo;
33
102
  contextWindow: number;
34
103
  maxOutputTokens: number;
35
104
  capabilities: {
36
105
  tools: boolean;
37
106
  vision: boolean;
38
107
  reasoning: boolean;
39
- caching: boolean;
40
108
  midConversationSystem: boolean;
41
109
  /**
42
- * 是否接受 `document` 块(缺省为 false)。图片看 `vision`。模型不支持时内核把媒体块换成英文文字占位
43
- * (如 `[Attached image "<name>" — this model cannot view images.]`;`text/*` 文档改为内联截断后的文本),
44
- * 绝不把字节发给它。
110
+ * Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
111
+ * the model does not support them the kernel replaces media blocks with English text
112
+ * placeholders
113
+ * (e.g. `[Attached image "<name>" — this model cannot view images. If Read is available to you, Read with file_id <id> sends it to the organization's vision model, if one is set.]`; `text/*` documents are
114
+ * inlined as truncated text instead),
115
+ * and never sends the bytes to it.
45
116
  */
46
117
  documents?: boolean;
47
- /**
48
- * @deprecated `model-provider@1` 用:是否支持 `ModelRequestV1.effort`。`@2` 插件不填,改在
49
- * `parameters` 中声明 `effort` 旋钮;内核的 `@1` 适配层据此推导 `parameters`。
50
- */
51
- effort?: boolean;
52
118
  };
53
- /** 流空闲看门狗阈值;推理类模型应更长。未给时内核用配置默认值。 */
119
+ /**
120
+ * Stream idle watchdog threshold; reasoning models should use a longer one. When unset the kernel
121
+ * uses the config default.
122
+ */
54
123
  streamIdleTimeoutMs?: number;
55
- /** 该模型支持的参数(`@2` 必填,可为空数组;须通过 `assertValidDeclarations`)。 */
124
+ /** The model's prompt cache (must pass `validateModelCache`). Absent = mechanism `none`. */
125
+ cache?: ModelCacheInfo;
126
+ /**
127
+ * The parameters this model supports (may be an empty array; must pass
128
+ * `assertValidDeclarations`). Effort is the standard `effort` knob declared here.
129
+ */
56
130
  parameters: ModelParameter[];
57
131
  }
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 加密推理项)。 */
132
+ /**
133
+ * Vendor-private data: replayed only to the same vendor (e.g. Anthropic thinking block signatures,
134
+ * OpenAI encrypted reasoning items).
135
+ */
65
136
  export interface ProviderOpaque {
66
137
  provider: string;
67
138
  model: string;
68
139
  data: unknown;
69
140
  }
70
- /** 图片块接受的类型。 */
141
+ /** Types accepted by image blocks. */
71
142
  export declare const IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
72
- /** 文档块接受的类型。 */
143
+ /** Types accepted by document blocks. */
73
144
  export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv"];
74
145
  export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
75
146
  export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
76
147
  /**
77
- * 媒体内容的来源:`base64` 是字节本身,`ref` 是内核附件的引用。
78
- * 事件日志里只存 `ref`(字节不进日志);内核构建请求时把 `ref` 解析成 `base64`,插件只会收到 `base64`。
148
+ * The source of media content: `base64` is the bytes themselves, `ref` names a kernel file by its
149
+ * id (a library file the conversation refers to, or a file the kernel stored for a tool result).
150
+ * The event log stores only `ref` (bytes never enter the log); when building a request the kernel
151
+ * resolves `ref` into `base64`, so plugins only ever receive `base64`.
79
152
  */
80
153
  export type MediaSource = {
81
154
  kind: "base64";
82
155
  data: string;
83
156
  } | {
84
157
  kind: "ref";
85
- attachmentId: string;
158
+ fileId: string;
86
159
  };
87
- /** 单个媒体块解码后的字节上限(按主流供应商的较小值取)。 */
160
+ /**
161
+ * Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
162
+ * vendors).
163
+ */
88
164
  export declare const MEDIA_LIMITS: {
89
165
  readonly imageBytes: 5242880;
90
166
  readonly documentBytes: 33554432;
91
167
  };
92
168
  export type ContentBlock =
93
- /** text 的 opaque:供应商需要随文本回放的私有数据(如 OpenAI message 输出项的 id)。 */
169
+ /**
170
+ * Opaque for text: vendor-private data that must be replayed with the text (e.g. the id of an
171
+ * OpenAI message output item).
172
+ */
94
173
  {
95
174
  type: "text";
96
175
  text: string;
@@ -112,39 +191,65 @@ export type ContentBlock =
112
191
  isError: boolean;
113
192
  }
114
193
  /**
115
- * 图片(只出现在 user 消息里)。模型不支持 `vision` 时内核换成文字占位,插件不用把关;
116
- * 不认识此块的旧插件会跳过它。
194
+ * An image (only in user messages). When the model has no `vision` the kernel sends an English
195
+ * placeholder instead; a plugin need not check. An older plugin that does not know this block
196
+ * skips it. `size` is display metadata (the UI chip, the reference line) and is never sent.
117
197
  */
118
198
  | {
119
199
  type: "image";
120
200
  mediaType: ImageMediaType;
121
201
  source: MediaSource;
122
202
  name?: string;
203
+ size?: number;
123
204
  }
124
- /** 文档(只出现在 user 消息里),由 `capabilities.documents` 把关,规则同 image。 */
205
+ /** A document (only in user messages), gated by `capabilities.documents`; same rules as image. */
125
206
  | {
126
207
  type: "document";
127
208
  mediaType: DocumentMediaType;
128
209
  source: MediaSource;
129
210
  name?: string;
211
+ size?: number;
212
+ }
213
+ /**
214
+ * An attachment whose content the model cannot read (an xlsx, say): the kernel replaces it with
215
+ * text carrying an unsigned object reference before the request, so a provider **never** receives
216
+ * this block. `mediaType` is any non-empty `type/subtype`; `size` is display metadata (the UI
217
+ * chip, the reference line) and is never sent.
218
+ */
219
+ | {
220
+ type: "file";
221
+ mediaType: string;
222
+ source: MediaSource;
223
+ name?: string;
224
+ size?: number;
130
225
  };
131
- /** 媒体块 `name` 的最大长度(字符)。 */
226
+ /** Maximum length (characters) of a media block's `name`. */
132
227
  export declare const MEDIA_NAME_MAX_CHARS = 255;
133
- /** 供应商请求里文件名 / 标题的建议上限(码点),{@link clipMediaName} 的默认值。 */
228
+ /**
229
+ * Suggested upper bound (code points) for file names / titles in vendor requests, the default of
230
+ * {@link clipMediaName}.
231
+ */
134
232
  export declare const PROVIDER_MEDIA_NAME_MAX = 200;
135
233
  /**
136
- * 把附件名截到 `max` 个码点以内(供应商映射用:有的接口对 filename / title 有长度限制,补后缀后还会更长)。
137
- * 尽量保留扩展名(不超过 16 个字符的 `.ext`),中间用 `…` 表示截掉的部分。纯函数。
234
+ * Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
235
+ * filename / title length, and adding a suffix makes it longer still).
236
+ * Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
237
+ * part in the middle. A pure function.
138
238
  */
139
239
  export declare function clipMediaName(name: string, max?: number): string;
140
- /** 是否含控制字符(C0、DEL 与 C1)。 */
240
+ /** Whether it contains control characters (C0, DEL and C1). */
141
241
  export declare function hasControlChars(s: string): boolean;
142
- /** 附件 id 是否为 UUID(任意版本,大小写不限)。 */
242
+ /** Whether the attachment id is a UUID (any version, case-insensitive). */
143
243
  export declare function isAttachmentId(s: unknown): s is string;
244
+ /** Whether the file id (a media `ref`'s `fileId`) is a UUID (any version, case-insensitive). */
245
+ export declare function isFileId(s: unknown): s is string;
144
246
  /**
145
- * 校验一个 image / document 块,返回错误列表(空表示合法):类型在列表里;`base64` 是标准、带填充、
146
- * 不含空白的 base64,解码后不超过 {@link MEDIA_LIMITS};`ref` 的 `attachmentId` 是 UUID;`name` 若有须是字符串、
147
- * 不超过 {@link MEDIA_NAME_MAX_CHARS} 个字符且不含控制字符。
247
+ * Validates an image / document / file block, returning a list of errors (empty means valid): the
248
+ * media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
249
+ * standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
250
+ * `fileId` is a UUID; `name`, when present, is a string of at most
251
+ * {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
252
+ * non-negative integer (display metadata, never sent by a plugin).
148
253
  */
149
254
  export declare function validateMediaBlock(b: unknown): string[];
150
255
  export type ModelMessage = {
@@ -154,7 +259,10 @@ export type ModelMessage = {
154
259
  role: "assistant";
155
260
  content: ContentBlock[];
156
261
  }
157
- /** 对话中途的系统提醒;模型不支持时由插件转成 user 文本块(以 "[system] " 开头)。 */
262
+ /**
263
+ * A mid-conversation system reminder; when the model does not support it the plugin turns it into
264
+ * a user text block (starting with "[system] ").
265
+ */
158
266
  | {
159
267
  role: "system";
160
268
  content: string;
@@ -166,7 +274,10 @@ export interface ToolDefinition {
166
274
  }
167
275
  export interface ModelRequest {
168
276
  model: string;
169
- /** 稳定内容在前;cache 为 true 的块之后打缓存断点(由插件按原生协议实现)。 */
277
+ /**
278
+ * Stable content first; after a block with cache true a cache breakpoint is placed (implemented
279
+ * by the plugin per the native protocol).
280
+ */
170
281
  system: {
171
282
  text: string;
172
283
  cache: boolean;
@@ -174,50 +285,107 @@ export interface ModelRequest {
174
285
  messages: ModelMessage[];
175
286
  tools: ToolDefinition[];
176
287
  /**
177
- * `@2`:模型可否调用工具。`"none"` = 本次只能回复文本、不得调用工具(`tools` 仍照常带上:历史里有工具调用时
178
- * 部分供应商要求请求声明工具,且保持缓存前缀稳定);缺省或 `"auto"` = 由模型决定。
179
- * 插件映射到原生字段(如 Anthropic `tool_choice: {type: "none"}`);`tools` 为空时插件不发送该字段。
288
+ * `@2`: whether the model may call tools. `"none"` = this call may only reply with text and must
289
+ * not call tools (`tools` is still sent as usual: when the history has tool calls
290
+ * some vendors require the request to declare tools, and it keeps the cache prefix stable);
291
+ * omitted or `"auto"` = the model decides.
292
+ * The plugin maps it to the native field (e.g. Anthropic `tool_choice: {type: "none"}`); when
293
+ * `tools` is empty the plugin does not send the field.
180
294
  */
181
295
  toolChoice?: "auto" | "none";
182
296
  maxOutputTokens: number;
183
- /** `@2`:本次调用的参数(已按该模型的 `parameters` 处理过),由插件映射到原生请求。 */
297
+ /**
298
+ * The parameters of this call (already processed against the model's `parameters`), mapped to the
299
+ * native request by the plugin.
300
+ */
184
301
  params: Record<string, ParamValue>;
185
- /** @deprecated `model-provider@1` 用;`@2` 插件读 `params.effort`。 */
186
- effort?: Effort;
302
+ /**
303
+ * What this call is for, when the kernel says so: `"compaction"` for a conversation summary call,
304
+ * `"suggestion"` for a prompt suggestion call. Absent on ordinary step calls. Informational (a
305
+ * scripted test model keys on it); real providers ignore it and must not forward it to a vendor
306
+ * API.
307
+ */
308
+ purpose?: ModelCallPurpose;
309
+ /**
310
+ * The prompt cache lifetime to ask for: seconds, one of the model's `ttlOptions` (the kernel
311
+ * only ever sends one of them); a plugin of a model without options ignores it; the plugin maps
312
+ * it to the vendor's field. Absent = the model's default.
313
+ */
314
+ cacheTtl?: number;
187
315
  }
188
- /** `model-provider@1` 的请求:没有 `params` 与 `toolChoice`。 */
189
- export type ModelRequestV1 = Omit<ModelRequest, "params" | "toolChoice">;
190
316
  export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
191
317
  /**
192
- * 一次调用的 token 用量。三类输入互不重叠:本次请求的输入总量 =
193
- * `inputTokens + cacheReadTokens + cacheWriteTokens`(内核据此校正上下文估算、决定何时压缩)。
194
- * 供应商 API 的输入计数若已包含缓存命中 / 写入的 token(如 OpenAI 的 `prompt_tokens`),插件必须先减掉。
318
+ * Token usage of one call. The three kinds of input do not overlap: the total input of this request
319
+ * =
320
+ * `inputTokens + cacheReadTokens + cacheWriteTokens` (the kernel uses it to correct context
321
+ * estimates and to decide when to compact).
322
+ * If the vendor API's input count already includes cache-hit / cache-write tokens (e.g. OpenAI's
323
+ * `prompt_tokens`), the plugin must subtract them first.
195
324
  */
196
325
  export interface ModelUsage {
197
- /** 未命中缓存、也未写入缓存的输入 token(只是未缓存部分,不是输入总量)。 */
326
+ /**
327
+ * Input tokens that neither hit the cache nor were written to it (only the uncached part, not the
328
+ * total input).
329
+ */
198
330
  inputTokens: number;
199
331
  outputTokens: number;
200
- /** 从提示词缓存读取的输入 token。 */
332
+ /** Input tokens read from the prompt cache. */
201
333
  cacheReadTokens: number;
202
- /** 本次写入提示词缓存的输入 token。 */
334
+ /** Input tokens written to the prompt cache in this call. */
203
335
  cacheWriteTokens: number;
336
+ /** Images produced (image generation calls). */
337
+ outputImages?: number;
338
+ /**
339
+ * Cache writes per lifetime tier: optional; sums to `cacheWriteTokens`; from the vendor's
340
+ * per-tier write counts.
341
+ */
342
+ cacheWriteByTtl?: CacheWriteByTtl[];
204
343
  }
344
+ /** Input tokens written to the prompt cache with one lifetime (`ttl`, seconds). */
345
+ export interface CacheWriteByTtl {
346
+ ttl: number;
347
+ tokens: number;
348
+ }
349
+ /**
350
+ * Checks `usage.cacheWriteByTtl` when present: positive integer `ttl`s, each once; non-negative
351
+ * integer `tokens`; the tokens sum to `cacheWriteTokens`. Returns the first problem, or `null`.
352
+ */
353
+ export declare function validateCacheWriteByTtl(usage: ModelUsage): string | null;
354
+ /**
355
+ * One event of a model stream. Tool call events are display only: a provider MAY emit
356
+ * `tool_call_start` when a tool call begins and `tool_call_delta` with raw input JSON fragments
357
+ * (`input` is the next piece of the call's argument JSON text) for the same `id`. A `tool_call_start`
358
+ * precedes the deltas of its `id`; calls may interleave with each other and with text and thinking.
359
+ * The parsed concatenation of an id's deltas must equal the input of that call in
360
+ * `message_complete`; the final `message_complete` is the only source of truth, and nothing
361
+ * streamed ever executes. Emitting no tool call events stays valid.
362
+ */
205
363
  export type ModelStreamEvent = {
206
364
  type: "text_delta";
207
365
  text: string;
208
366
  } | {
209
367
  type: "thinking_delta";
210
368
  text: string;
369
+ } | {
370
+ type: "tool_call_start";
371
+ id: string;
372
+ name: string;
373
+ } | {
374
+ type: "tool_call_delta";
375
+ id: string;
376
+ input: string;
211
377
  } | {
212
378
  type: "message_complete";
213
379
  content: ContentBlock[];
214
380
  stopReason: StopReason;
215
381
  usage: ModelUsage;
216
382
  };
217
- export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "aborted";
218
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
383
+ export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "refusal" | "aborted";
384
+ /** True for rate_limited / overloaded / server / timeout / network. */
219
385
  export declare function isRetryableKind(kind: ModelErrorKind): boolean;
220
- /** 鸭子类型判断(不用 instanceof),兼容插件自带另一份 plugin-sdk 副本的情况。 */
386
+ /**
387
+ * Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
388
+ */
221
389
  export declare function isModelError(e: unknown): e is ModelError;
222
390
  export declare class ModelError extends Error {
223
391
  readonly kind: ModelErrorKind;
@@ -226,16 +394,16 @@ export declare class ModelError extends Error {
226
394
  retryAfterMs?: number;
227
395
  cause?: unknown;
228
396
  });
229
- /** rate_limited / overloaded / server / timeout / network 为 true。 */
397
+ /** True for rate_limited / overloaded / server / timeout / network. */
230
398
  get retryable(): boolean;
231
399
  }
232
400
  /**
233
401
  * Options of a model call made for an organization.
234
402
  * `config` is the extension's effective deployment config for this org: the platform's deployment
235
- * config with the org's copy applied to the overridable fields (`orgAccess(…, "override")`), or the
236
- * platform's config (equal to `ctx.config`) while the org follows it. Use it, not `ctx.config`, for
237
- * work done for this org. Optional in the type so older providers compile; the kernel always passes
238
- * both.
403
+ * config with the org's copy applied to the overridable fields (every field not marked
404
+ * `platformOnly`), or the platform's config (equal to `ctx.config`) while the org follows it. Use
405
+ * it, not `ctx.config`, for work done for this org. Both are absent on a call not made for an org,
406
+ * such as a conformance run.
239
407
  */
240
408
  export interface ModelCallOptions {
241
409
  orgId?: string;
@@ -260,11 +428,62 @@ export interface EmbedResult {
260
428
  * valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
261
429
  */
262
430
  export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
263
- /** `model-provider@2` 的实现。 */
431
+ export interface ImageGenerateRequest {
432
+ model: string;
433
+ prompt: string;
434
+ /** One of the model's `imageGeneration.sizes`. */
435
+ size: ImageSize;
436
+ /** Images to produce, 1 to `imageGeneration.maxImages`. */
437
+ n: number;
438
+ /** Base64 reference images, at most `imageGeneration.maxReferenceImages`. */
439
+ referenceImages?: {
440
+ mediaType: ImageMediaType;
441
+ data: string;
442
+ }[];
443
+ params: Record<string, ParamValue>;
444
+ }
445
+ export interface ImageGenerateResult {
446
+ /** Exactly `req.n` images, base64 encoded. */
447
+ images: {
448
+ mediaType: ImageMediaType;
449
+ data: string;
450
+ }[];
451
+ /** The prompt as the vendor rewrote it, when it did. */
452
+ revisedPrompt?: string;
453
+ usage: ModelUsage;
454
+ }
455
+ /** True when `x` is a well-formed {@link ModelImageGenerationInfo}. */
456
+ export declare function isValidImageGenerationInfo(x: unknown): x is ModelImageGenerationInfo;
457
+ /**
458
+ * Checks an image generation result against its request and the model's facts. Returns null when
459
+ * valid, else the reason: wrong image count, an undeclared media type, data that is not base64,
460
+ * or a `usage` that is not an object whose token counts (and `outputImages`, when present) are
461
+ * non-negative integers (a caller records usage from it, so it is checked before anything is).
462
+ */
463
+ export declare function validateImageGenerateResult(req: ImageGenerateRequest, info: ModelImageGenerationInfo, res: unknown): string | null;
464
+ /**
465
+ * Chooses an output size: an exact `size` must be one the model offers; an `aspectRatio` picks the
466
+ * closest declared ratio (ties by area closest to the default's, then declaration order); neither
467
+ * gives the default size.
468
+ */
469
+ export declare function pickImageSize(info: ModelImageGenerationInfo, opts: {
470
+ size?: ImageSize;
471
+ aspectRatio?: ImageAspectRatio;
472
+ }): {
473
+ ok: true;
474
+ size: ImageSize;
475
+ } | {
476
+ ok: false;
477
+ error: string;
478
+ };
479
+ /** The `model-provider@2` implementation. */
264
480
  export interface ModelProvider {
265
- /** 每个模型的 `parameters` 须通过 `assertValidDeclarations`,否则内核不使用该供应商。 */
481
+ /**
482
+ * Every model's `parameters` must pass `assertValidDeclarations`, otherwise the kernel does not
483
+ * use this vendor.
484
+ */
266
485
  listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
267
- /** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
486
+ /** The event sequence must end with exactly one message_complete; throw ModelError on error. */
268
487
  stream(req: ModelRequest, opts: {
269
488
  signal: AbortSignal;
270
489
  } & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
@@ -272,14 +491,13 @@ export interface ModelProvider {
272
491
  embed?(req: EmbedRequest, opts: {
273
492
  signal: AbortSignal;
274
493
  } & 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: {
494
+ /**
495
+ * Present only on a provider that lists `image_generation` models. Throws `ModelError` of kind
496
+ * `refusal` when the vendor declines the prompt.
497
+ */
498
+ generateImage?(req: ImageGenerateRequest, opts: {
281
499
  signal: AbortSignal;
282
- }): AsyncIterable<ModelStreamEvent>;
500
+ } & ModelCallOptions): Promise<ImageGenerateResult>;
283
501
  }
284
- export declare const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
502
+ /** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
285
503
  export declare const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";