@capybara-hq/plugin-sdk 0.1.0-rc.6 → 0.1.0-rc.60
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.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +7 -1
- package/agent-docs/extension-points/channel.md +1 -1
- package/agent-docs/extension-points/context.md +15 -0
- package/agent-docs/extension-points/device-provider.md +15 -0
- package/agent-docs/extension-points/file-preview.md +2 -0
- package/agent-docs/extension-points/model-provider.md +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +29 -3
- package/agent-docs/plugin-format.md +52 -2
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +67 -13
- package/dist/cards.js +91 -21
- package/dist/channel.d.ts +148 -48
- package/dist/channel.js +10 -5
- package/dist/client-css.d.ts +36 -0
- package/dist/client-css.js +326 -0
- package/dist/client-section.d.ts +35 -0
- package/dist/client-section.js +133 -0
- package/dist/config-ui.d.ts +22 -0
- package/dist/config-ui.js +64 -4
- package/dist/connector-auth.d.ts +15 -2
- package/dist/connector-auth.js +97 -8
- package/dist/connector.d.ts +74 -32
- package/dist/context.d.ts +40 -0
- package/dist/context.js +2 -0
- package/dist/ctx.d.ts +132 -29
- package/dist/define-extension.d.ts +26 -12
- package/dist/define-extension.js +12 -5
- package/dist/device-denied-paths.d.ts +18 -0
- package/dist/device-denied-paths.js +84 -0
- package/dist/device-operation.d.ts +333 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +500 -0
- package/dist/device-provider.js +302 -0
- package/dist/dial-in.d.ts +176 -0
- package/dist/dial-in.js +115 -0
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +6 -2
- package/dist/file-preview.d.ts +23 -6
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +62 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +38 -9
- package/dist/identity.js +21 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +29 -3
- package/dist/marketplace.d.ts +26 -0
- package/dist/marketplace.js +43 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +206 -71
- package/dist/model.js +152 -19
- package/dist/net.d.ts +52 -0
- package/dist/net.js +34 -0
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/permissions.d.ts +54 -22
- package/dist/permissions.js +119 -43
- package/dist/plugin-manifest.d.ts +45 -5
- package/dist/plugin-manifest.js +174 -6
- package/dist/plugin-package.d.ts +82 -38
- package/dist/plugin-package.js +61 -29
- package/dist/push.d.ts +75 -0
- package/dist/push.js +87 -0
- package/dist/sandbox-linux-runtime-source.d.ts +1 -0
- package/dist/sandbox-linux-runtime-source.js +2318 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +476 -0
- package/dist/sandbox-runtime-source.d.ts +19 -0
- package/dist/sandbox-runtime-source.js +28 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-check.d.ts +128 -0
- package/dist/setup-check.js +142 -0
- package/dist/setup-guide-parse.d.ts +121 -0
- package/dist/setup-guide-parse.js +356 -0
- package/dist/setup-guide-render.d.ts +45 -0
- package/dist/setup-guide-render.js +351 -0
- package/dist/setup-guide.d.ts +108 -0
- package/dist/setup-guide.js +367 -0
- package/dist/shell-capabilities.d.ts +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +40 -26
- package/dist/storage.d.ts +52 -25
- package/dist/svg-viewbox.d.ts +10 -0
- package/dist/svg-viewbox.js +24 -0
- package/dist/theme-assets.d.ts +55 -0
- package/dist/theme-assets.js +489 -0
- package/dist/theme-readability.d.ts +37 -0
- package/dist/theme-readability.js +145 -0
- package/dist/theme-tokens.generated.d.ts +299 -0
- package/dist/theme-tokens.generated.js +184 -0
- package/dist/theme.d.ts +190 -0
- package/dist/theme.js +471 -0
- package/dist/tool.d.ts +99 -26
- package/dist/tool.js +29 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +212 -76
- package/dist/ui.js +101 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +13 -1
- package/schemas/bootstrap-extra.v1.schema.json +186 -0
- package/schemas/bootstrap.v1.schema.json +20 -0
- package/schemas/connector-template.v1.schema.json +35 -0
- package/schemas/marketplace.v1.schema.json +14 -0
- package/schemas/plugin.v1.schema.json +122 -3
- package/schemas/theme.v1.schema.json +302 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/sandbox.d.ts +0 -254
- package/dist/sandbox.js +0 -153
package/dist/model.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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 {
|
|
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
|
+
/**
|
|
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
|
-
*
|
|
43
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
*
|
|
78
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
183
|
+
/** Maximum length (characters) of a media block's `name`. */
|
|
132
184
|
export declare const MEDIA_NAME_MAX_CHARS = 255;
|
|
133
|
-
/**
|
|
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
|
-
*
|
|
137
|
-
*
|
|
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
|
-
/**
|
|
197
|
+
/** Whether it contains control characters (C0, DEL and C1). */
|
|
141
198
|
export declare function hasControlChars(s: string): boolean;
|
|
142
|
-
/**
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
178
|
-
*
|
|
179
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
186
|
-
|
|
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
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
281
|
+
/** Input tokens read from the prompt cache. */
|
|
201
282
|
cacheReadTokens: number;
|
|
202
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
}):
|
|
417
|
+
} & ModelCallOptions): Promise<ImageGenerateResult>;
|
|
283
418
|
}
|
|
284
|
-
|
|
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";
|