@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.
- package/README.md +3 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +11 -3
- 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 +3 -1
- package/agent-docs/extension-points/identity-source.md +2 -0
- package/agent-docs/extension-points/model-provider.md +5 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extension-points/trigger-source.md +19 -0
- package/agent-docs/extensions.md +98 -4
- package/agent-docs/plugin-format.md +45 -10
- package/agent-docs/setup.md +54 -0
- package/api/plugin-sdk.api.md +5983 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/agents-ctx.d.ts +116 -0
- package/dist/agents-ctx.js +22 -0
- 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 +121 -13
- package/dist/cards.js +161 -19
- package/dist/channel.d.ts +133 -47
- 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 +28 -6
- package/dist/config-ui.js +88 -25
- package/dist/config-url-fetch.d.ts +19 -0
- package/dist/config-url-fetch.js +43 -0
- package/dist/connector-auth.d.ts +13 -2
- package/dist/connector-auth.js +82 -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 +344 -31
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +18 -12
- package/dist/define-extension.js +18 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +348 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +286 -49
- package/dist/device-protocol.js +766 -89
- package/dist/device-provider.d.ts +820 -0
- package/dist/device-provider.js +432 -0
- package/dist/device-service.d.ts +204 -0
- package/dist/device-service.js +291 -0
- package/dist/dial-in.d.ts +286 -0
- package/dist/dial-in.js +213 -0
- package/dist/directory.d.ts +15 -12
- package/dist/extension-point.d.ts +2 -0
- package/dist/extension-point.js +8 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +46 -9
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +185 -22
- package/dist/hooks.js +6 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/inbox.d.ts +103 -0
- package/dist/inbox.js +173 -0
- package/dist/index.d.ts +30 -4
- package/dist/index.js +30 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +295 -77
- package/dist/model.js +249 -21
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- 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 +95 -25
- package/dist/permissions.js +175 -54
- package/dist/platform-only.d.ts +27 -0
- package/dist/platform-only.js +35 -0
- package/dist/plugin-manifest.d.ts +30 -6
- package/dist/plugin-manifest.js +147 -55
- package/dist/plugin-package.d.ts +82 -39
- package/dist/plugin-package.js +68 -41
- 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 +2343 -0
- package/dist/sandbox-native-runtime-source.d.ts +10 -0
- package/dist/sandbox-native-runtime-source.js +480 -0
- package/dist/sandbox-runtime-source.d.ts +47 -0
- package/dist/sandbox-runtime-source.js +73 -0
- package/dist/sandbox-write-denies.d.ts +139 -0
- package/dist/sandbox-write-denies.js +869 -0
- package/dist/secret.d.ts +8 -2
- package/dist/secret.js +11 -4
- 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 +86 -72
- package/dist/setup-guide.js +340 -108
- package/dist/shell-capabilities.d.ts +216 -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-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- 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 +25 -9
- package/dist/theme-assets.js +87 -47
- package/dist/theme-tokens.generated.d.ts +40 -12
- package/dist/theme-tokens.generated.js +36 -8
- package/dist/theme.d.ts +56 -10
- package/dist/theme.js +117 -23
- package/dist/tool.d.ts +242 -28
- package/dist/tool.js +135 -13
- package/dist/trigger-source.d.ts +35 -0
- package/dist/trigger-source.js +2 -0
- package/dist/triggers.d.ts +88 -0
- package/dist/triggers.js +71 -0
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +374 -0
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +27 -5
- package/dist/ui-slots.js +112 -19
- package/dist/ui.d.ts +203 -64
- package/dist/ui.js +117 -23
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- 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 +62 -4
- package/schemas/plugin.v1.schema.json +74 -143
- package/schemas/theme.v1.schema.json +77 -0
- package/agent-docs/extension-points/sandbox.md +0 -15
- package/dist/org-access.d.ts +0 -27
- package/dist/org-access.js +0 -35
- 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,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
|
-
*
|
|
43
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
*
|
|
78
|
-
*
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
226
|
+
/** Maximum length (characters) of a media block's `name`. */
|
|
132
227
|
export declare const MEDIA_NAME_MAX_CHARS = 255;
|
|
133
|
-
/**
|
|
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
|
-
*
|
|
137
|
-
*
|
|
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
|
-
/**
|
|
240
|
+
/** Whether it contains control characters (C0, DEL and C1). */
|
|
141
241
|
export declare function hasControlChars(s: string): boolean;
|
|
142
|
-
/**
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
178
|
-
*
|
|
179
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
186
|
-
|
|
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
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
332
|
+
/** Input tokens read from the prompt cache. */
|
|
201
333
|
cacheReadTokens: number;
|
|
202
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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 (
|
|
236
|
-
* platform's config (equal to `ctx.config`) while the org follows it. Use
|
|
237
|
-
* work done for this org.
|
|
238
|
-
*
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
}):
|
|
500
|
+
} & ModelCallOptions): Promise<ImageGenerateResult>;
|
|
283
501
|
}
|
|
284
|
-
|
|
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";
|