@capybara-hq/plugin-sdk 0.1.0-rc.26 → 0.1.0-rc.28
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/agent-docs/extension-points/model-provider.md +1 -1
- package/dist/cards.d.ts +17 -8
- package/dist/cards.js +21 -10
- package/dist/channel.d.ts +91 -47
- package/dist/channel.js +10 -5
- package/dist/connector-auth.d.ts +5 -2
- package/dist/connector-auth.js +14 -8
- package/dist/connector.d.ts +67 -32
- package/dist/ctx.d.ts +41 -23
- package/dist/define-extension.d.ts +21 -11
- package/dist/define-extension.js +10 -4
- package/dist/device-protocol.d.ts +2 -1
- package/dist/extension-point.js +1 -1
- package/dist/identity.d.ts +22 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +96 -64
- package/dist/model.js +25 -14
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +8 -32
- package/dist/plugin-package.d.ts +79 -38
- package/dist/plugin-package.js +57 -29
- package/dist/sandbox-linux-runtime-source.d.ts +15 -0
- package/dist/sandbox-linux-runtime-source.js +1421 -0
- package/dist/sandbox-runtime-source.d.ts +9 -3
- package/dist/sandbox-runtime-source.js +16 -4
- package/dist/sandbox.d.ts +4 -1
- package/dist/sandbox.js +7 -3
- package/dist/secret.d.ts +4 -1
- package/dist/secret.js +4 -1
- package/dist/setup-guide.d.ts +1 -1
- package/dist/setup-guide.js +1 -1
- package/dist/skill.d.ts +27 -17
- package/dist/skill.js +39 -25
- package/dist/storage.d.ts +45 -25
- package/dist/tool.d.ts +51 -23
- package/dist/tool.js +21 -9
- package/dist/ui-resolve.d.ts +2 -7
- package/dist/ui-resolve.js +7 -19
- package/dist/ui-slots.d.ts +1 -3
- package/dist/ui-slots.js +0 -9
- package/dist/ui.d.ts +63 -49
- package/dist/ui.js +36 -22
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/package.json +1 -1
package/dist/model-params.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `model-provider@2`
|
|
3
|
-
*
|
|
2
|
+
* Parameter declarations and validation for `model-provider@2` (pure functions; issues / error
|
|
3
|
+
* messages are in English, for logs and API responses).
|
|
4
|
+
* Each model declares in `ModelInfo.parameters` the parameters it supports; value constraints are a
|
|
5
|
+
* restricted JSON Schema subset.
|
|
4
6
|
*/
|
|
5
7
|
export const STANDARD_KNOBS = [
|
|
6
8
|
"effort",
|
|
@@ -8,13 +10,13 @@ export const STANDARD_KNOBS = [
|
|
|
8
10
|
"temperature",
|
|
9
11
|
"maxOutputTokens",
|
|
10
12
|
];
|
|
11
|
-
/** `effort`
|
|
13
|
+
/** The full set of values the `effort` knob allows. */
|
|
12
14
|
export const EFFORT_VALUES = ["low", "medium", "high", "xhigh", "max"];
|
|
13
|
-
/** `thinking`
|
|
15
|
+
/** The full set of values the `thinking` knob allows. */
|
|
14
16
|
export const THINKING_VALUES = ["off", "on", "summarized"];
|
|
15
17
|
const isStandardKnob = (k) => STANDARD_KNOBS.includes(k);
|
|
16
18
|
const VENDOR_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
17
|
-
/**
|
|
19
|
+
/** Returns an English reason when the value does not satisfy the schema, undefined when it does. */
|
|
18
20
|
export function checkParamValue(schema, v) {
|
|
19
21
|
switch (schema.type) {
|
|
20
22
|
case "boolean":
|
|
@@ -45,11 +47,16 @@ export function checkParamValue(schema, v) {
|
|
|
45
47
|
return `has unsupported schema type ${JSON.stringify(schema.type)}`;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Looks up a declaration by key (uses a Map so that prototype properties such as `constructor` are
|
|
52
|
+
* not mistaken for declared keys).
|
|
53
|
+
*/
|
|
49
54
|
const declMap = (decl) => new Map(decl.map((d) => [d.key, d]));
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
56
|
+
* Strict validation (used when saving an agent): unknown keys, type mismatches, enum violations and
|
|
57
|
+
* out-of-range values are all errors, reported per key.
|
|
58
|
+
* On success `value` is the input parameters, with no defaults filled in; a key whose value is
|
|
59
|
+
* undefined counts as unset.
|
|
53
60
|
*/
|
|
54
61
|
export function validateParams(decl, params) {
|
|
55
62
|
const byKey = declMap(decl);
|
|
@@ -72,8 +79,10 @@ export function validateParams(decl, params) {
|
|
|
72
79
|
return issues.length > 0 ? { ok: false, issues } : { ok: true, value };
|
|
73
80
|
}
|
|
74
81
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
82
|
+
* The lenient variant (used at runtime): drops unknown or invalid entries (their keys go into
|
|
83
|
+
* `dropped`), then fills defaults for declared parameters that are unset.
|
|
84
|
+
* For the case where saved parameters are no longer valid after a plugin upgrade, so that the whole
|
|
85
|
+
* run does not fail.
|
|
77
86
|
*/
|
|
78
87
|
export function sanitizeParams(decl, params) {
|
|
79
88
|
const byKey = declMap(decl);
|
|
@@ -143,7 +152,9 @@ function schemaProblems(schema) {
|
|
|
143
152
|
return [`unsupported schema type ${JSON.stringify(s.type)}`];
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* The value conventions of standard knobs (checked only when the schema itself is already valid).
|
|
157
|
+
*/
|
|
147
158
|
function knobProblems(key, schema) {
|
|
148
159
|
const values = schema.type === "string" && "enum" in schema ? schema.enum : undefined;
|
|
149
160
|
switch (key) {
|
|
@@ -178,7 +189,7 @@ function textProblems(d) {
|
|
|
178
189
|
}
|
|
179
190
|
return out;
|
|
180
191
|
}
|
|
181
|
-
/**
|
|
192
|
+
/** All problems of one parameter declaration; an empty array when there are none. */
|
|
182
193
|
function declarationProblems(plugin, d) {
|
|
183
194
|
if (typeof d !== "object" || d === null)
|
|
184
195
|
return ["declaration must be an object"];
|
|
@@ -198,9 +209,11 @@ function declarationProblems(plugin, d) {
|
|
|
198
209
|
return out;
|
|
199
210
|
}
|
|
200
211
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
212
|
+
* Validates the parameters a plugin declares for a model: the key is a standard knob or
|
|
213
|
+
* `<plugin>.<name>`, `standard` agrees with the key,
|
|
214
|
+
* the schema belongs to the supported subset, standard knobs satisfy the value conventions,
|
|
215
|
+
* defaults satisfy the schema, copy is complete, keys do not repeat.
|
|
216
|
+
* Throws when there is a problem, with a message naming the plugin and each key (in English).
|
|
204
217
|
*/
|
|
205
218
|
export function assertValidDeclarations(plugin, decl) {
|
|
206
219
|
if (!Array.isArray(decl)) {
|
package/dist/model.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
/** What a model does. Absent on a `ModelInfo` means `chat`. */
|
|
9
10
|
export type ModelKind = "chat" | "embedding" | "rerank" | "image_generation" | "video_generation" | "speech_to_text" | "text_to_speech";
|
|
@@ -39,43 +40,46 @@ export interface ModelInfo {
|
|
|
39
40
|
caching: boolean;
|
|
40
41
|
midConversationSystem: boolean;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
|
|
44
|
+
* the model does not support them the kernel replaces media blocks with English text
|
|
45
|
+
* placeholders
|
|
46
|
+
* (e.g. `[Attached image "<name>" — this model cannot view images.]`; `text/*` documents are
|
|
47
|
+
* inlined as truncated text instead),
|
|
48
|
+
* and never sends the bytes to it.
|
|
45
49
|
*/
|
|
46
50
|
documents?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated `model-provider@1` 用:是否支持 `ModelRequestV1.effort`。`@2` 插件不填,改在
|
|
49
|
-
* `parameters` 中声明 `effort` 旋钮;内核的 `@1` 适配层据此推导 `parameters`。
|
|
50
|
-
*/
|
|
51
|
-
effort?: boolean;
|
|
52
51
|
};
|
|
53
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Stream idle watchdog threshold; reasoning models should use a longer one. When unset the kernel
|
|
54
|
+
* uses the config default.
|
|
55
|
+
*/
|
|
54
56
|
streamIdleTimeoutMs?: number;
|
|
55
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The parameters this model supports (may be an empty array; must pass
|
|
59
|
+
* `assertValidDeclarations`). Effort is the standard `effort` knob declared here.
|
|
60
|
+
*/
|
|
56
61
|
parameters: ModelParameter[];
|
|
57
62
|
}
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
/** 供应商私有数据:只回放给同一供应商(如 Anthropic 思考块签名、OpenAI 加密推理项)。 */
|
|
63
|
+
/**
|
|
64
|
+
* Vendor-private data: replayed only to the same vendor (e.g. Anthropic thinking block signatures,
|
|
65
|
+
* OpenAI encrypted reasoning items).
|
|
66
|
+
*/
|
|
65
67
|
export interface ProviderOpaque {
|
|
66
68
|
provider: string;
|
|
67
69
|
model: string;
|
|
68
70
|
data: unknown;
|
|
69
71
|
}
|
|
70
|
-
/**
|
|
72
|
+
/** Types accepted by image blocks. */
|
|
71
73
|
export declare const IMAGE_MEDIA_TYPES: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
72
|
-
/**
|
|
74
|
+
/** Types accepted by document blocks. */
|
|
73
75
|
export declare const DOCUMENT_MEDIA_TYPES: readonly ["application/pdf", "text/plain", "text/markdown", "text/csv"];
|
|
74
76
|
export type ImageMediaType = (typeof IMAGE_MEDIA_TYPES)[number];
|
|
75
77
|
export type DocumentMediaType = (typeof DOCUMENT_MEDIA_TYPES)[number];
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
+
* The source of media content: `base64` is the bytes themselves, `ref` is a reference to a kernel
|
|
80
|
+
* attachment.
|
|
81
|
+
* The event log stores only `ref` (bytes never enter the log); when building a request the kernel
|
|
82
|
+
* resolves `ref` into `base64`, so plugins only ever receive `base64`.
|
|
79
83
|
*/
|
|
80
84
|
export type MediaSource = {
|
|
81
85
|
kind: "base64";
|
|
@@ -84,13 +88,19 @@ export type MediaSource = {
|
|
|
84
88
|
kind: "ref";
|
|
85
89
|
attachmentId: string;
|
|
86
90
|
};
|
|
87
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
|
|
93
|
+
* vendors).
|
|
94
|
+
*/
|
|
88
95
|
export declare const MEDIA_LIMITS: {
|
|
89
96
|
readonly imageBytes: 5242880;
|
|
90
97
|
readonly documentBytes: 33554432;
|
|
91
98
|
};
|
|
92
99
|
export type ContentBlock =
|
|
93
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Opaque for text: vendor-private data that must be replayed with the text (e.g. the id of an
|
|
102
|
+
* OpenAI message output item).
|
|
103
|
+
*/
|
|
94
104
|
{
|
|
95
105
|
type: "text";
|
|
96
106
|
text: string;
|
|
@@ -144,18 +154,23 @@ export type ContentBlock =
|
|
|
144
154
|
name?: string;
|
|
145
155
|
size?: number;
|
|
146
156
|
};
|
|
147
|
-
/**
|
|
157
|
+
/** Maximum length (characters) of a media block's `name`. */
|
|
148
158
|
export declare const MEDIA_NAME_MAX_CHARS = 255;
|
|
149
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Suggested upper bound (code points) for file names / titles in vendor requests, the default of
|
|
161
|
+
* {@link clipMediaName}.
|
|
162
|
+
*/
|
|
150
163
|
export declare const PROVIDER_MEDIA_NAME_MAX = 200;
|
|
151
164
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
165
|
+
* Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
|
|
166
|
+
* filename / title length, and adding a suffix makes it longer still).
|
|
167
|
+
* Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
|
|
168
|
+
* part in the middle. A pure function.
|
|
154
169
|
*/
|
|
155
170
|
export declare function clipMediaName(name: string, max?: number): string;
|
|
156
|
-
/**
|
|
171
|
+
/** Whether it contains control characters (C0, DEL and C1). */
|
|
157
172
|
export declare function hasControlChars(s: string): boolean;
|
|
158
|
-
/**
|
|
173
|
+
/** Whether the attachment id is a UUID (any version, case-insensitive). */
|
|
159
174
|
export declare function isAttachmentId(s: unknown): s is string;
|
|
160
175
|
/**
|
|
161
176
|
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
@@ -173,7 +188,10 @@ export type ModelMessage = {
|
|
|
173
188
|
role: "assistant";
|
|
174
189
|
content: ContentBlock[];
|
|
175
190
|
}
|
|
176
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* A mid-conversation system reminder; when the model does not support it the plugin turns it into
|
|
193
|
+
* a user text block (starting with "[system] ").
|
|
194
|
+
*/
|
|
177
195
|
| {
|
|
178
196
|
role: "system";
|
|
179
197
|
content: string;
|
|
@@ -185,7 +203,10 @@ export interface ToolDefinition {
|
|
|
185
203
|
}
|
|
186
204
|
export interface ModelRequest {
|
|
187
205
|
model: string;
|
|
188
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* Stable content first; after a block with cache true a cache breakpoint is placed (implemented
|
|
208
|
+
* by the plugin per the native protocol).
|
|
209
|
+
*/
|
|
189
210
|
system: {
|
|
190
211
|
text: string;
|
|
191
212
|
cache: boolean;
|
|
@@ -193,32 +214,46 @@ export interface ModelRequest {
|
|
|
193
214
|
messages: ModelMessage[];
|
|
194
215
|
tools: ToolDefinition[];
|
|
195
216
|
/**
|
|
196
|
-
* `@2
|
|
197
|
-
*
|
|
198
|
-
*
|
|
217
|
+
* `@2`: whether the model may call tools. `"none"` = this call may only reply with text and must
|
|
218
|
+
* not call tools (`tools` is still sent as usual: when the history has tool calls
|
|
219
|
+
* some vendors require the request to declare tools, and it keeps the cache prefix stable);
|
|
220
|
+
* omitted or `"auto"` = the model decides.
|
|
221
|
+
* The plugin maps it to the native field (e.g. Anthropic `tool_choice: {type: "none"}`); when
|
|
222
|
+
* `tools` is empty the plugin does not send the field.
|
|
199
223
|
*/
|
|
200
224
|
toolChoice?: "auto" | "none";
|
|
201
225
|
maxOutputTokens: number;
|
|
202
|
-
/**
|
|
226
|
+
/**
|
|
227
|
+
* The parameters of this call (already processed against the model's `parameters`), mapped to the
|
|
228
|
+
* native request by the plugin.
|
|
229
|
+
*/
|
|
203
230
|
params: Record<string, ParamValue>;
|
|
204
|
-
/**
|
|
205
|
-
|
|
231
|
+
/**
|
|
232
|
+
* What this call is for, when the kernel says so: `"compaction"` for a conversation summary call.
|
|
233
|
+
* Absent on ordinary step calls. Informational (a scripted test model keys on it); real providers
|
|
234
|
+
* ignore it and must not forward it to a vendor API.
|
|
235
|
+
*/
|
|
236
|
+
purpose?: ModelCallPurpose;
|
|
206
237
|
}
|
|
207
|
-
/** `model-provider@1` 的请求:没有 `params` 与 `toolChoice`。 */
|
|
208
|
-
export type ModelRequestV1 = Omit<ModelRequest, "params" | "toolChoice">;
|
|
209
238
|
export type StopReason = "end_turn" | "tool_use" | "max_tokens" | "refusal" | "other";
|
|
210
239
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
240
|
+
* Token usage of one call. The three kinds of input do not overlap: the total input of this request
|
|
241
|
+
* =
|
|
242
|
+
* `inputTokens + cacheReadTokens + cacheWriteTokens` (the kernel uses it to correct context
|
|
243
|
+
* estimates and to decide when to compact).
|
|
244
|
+
* If the vendor API's input count already includes cache-hit / cache-write tokens (e.g. OpenAI's
|
|
245
|
+
* `prompt_tokens`), the plugin must subtract them first.
|
|
214
246
|
*/
|
|
215
247
|
export interface ModelUsage {
|
|
216
|
-
/**
|
|
248
|
+
/**
|
|
249
|
+
* Input tokens that neither hit the cache nor were written to it (only the uncached part, not the
|
|
250
|
+
* total input).
|
|
251
|
+
*/
|
|
217
252
|
inputTokens: number;
|
|
218
253
|
outputTokens: number;
|
|
219
|
-
/**
|
|
254
|
+
/** Input tokens read from the prompt cache. */
|
|
220
255
|
cacheReadTokens: number;
|
|
221
|
-
/**
|
|
256
|
+
/** Input tokens written to the prompt cache in this call. */
|
|
222
257
|
cacheWriteTokens: number;
|
|
223
258
|
}
|
|
224
259
|
export type ModelStreamEvent = {
|
|
@@ -234,9 +269,11 @@ export type ModelStreamEvent = {
|
|
|
234
269
|
usage: ModelUsage;
|
|
235
270
|
};
|
|
236
271
|
export type ModelErrorKind = "rate_limited" | "overloaded" | "server" | "timeout" | "network" | "auth" | "invalid_request" | "context_overflow" | "aborted";
|
|
237
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
272
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
238
273
|
export declare function isRetryableKind(kind: ModelErrorKind): boolean;
|
|
239
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
|
|
276
|
+
*/
|
|
240
277
|
export declare function isModelError(e: unknown): e is ModelError;
|
|
241
278
|
export declare class ModelError extends Error {
|
|
242
279
|
readonly kind: ModelErrorKind;
|
|
@@ -245,7 +282,7 @@ export declare class ModelError extends Error {
|
|
|
245
282
|
retryAfterMs?: number;
|
|
246
283
|
cause?: unknown;
|
|
247
284
|
});
|
|
248
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
285
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
249
286
|
get retryable(): boolean;
|
|
250
287
|
}
|
|
251
288
|
/**
|
|
@@ -279,11 +316,14 @@ export interface EmbedResult {
|
|
|
279
316
|
* valid, else the reason: wrong vector count, wrong dimension, or a non-finite number.
|
|
280
317
|
*/
|
|
281
318
|
export declare function validateEmbedResult(req: EmbedRequest, info: ModelEmbeddingInfo, res: EmbedResult): string | null;
|
|
282
|
-
/** `model-provider@2`
|
|
319
|
+
/** The `model-provider@2` implementation. */
|
|
283
320
|
export interface ModelProvider {
|
|
284
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* Every model's `parameters` must pass `assertValidDeclarations`, otherwise the kernel does not
|
|
323
|
+
* use this vendor.
|
|
324
|
+
*/
|
|
285
325
|
listModels(opts?: ModelCallOptions): Promise<ModelInfo[]>;
|
|
286
|
-
/**
|
|
326
|
+
/** The event sequence must end with exactly one message_complete; throw ModelError on error. */
|
|
287
327
|
stream(req: ModelRequest, opts: {
|
|
288
328
|
signal: AbortSignal;
|
|
289
329
|
} & ModelCallOptions): AsyncIterable<ModelStreamEvent>;
|
|
@@ -292,13 +332,5 @@ export interface ModelProvider {
|
|
|
292
332
|
signal: AbortSignal;
|
|
293
333
|
} & ModelCallOptions): Promise<EmbedResult>;
|
|
294
334
|
}
|
|
295
|
-
/**
|
|
296
|
-
export interface ModelProviderV1 {
|
|
297
|
-
listModels(): Promise<ModelInfoV1[]>;
|
|
298
|
-
/** 事件序列必须以且仅以一个 message_complete 结束;出错抛 ModelError。 */
|
|
299
|
-
stream(req: ModelRequestV1, opts: {
|
|
300
|
-
signal: AbortSignal;
|
|
301
|
-
}): AsyncIterable<ModelStreamEvent>;
|
|
302
|
-
}
|
|
303
|
-
export declare const MODEL_PROVIDER_EXTENSION_POINT = "model-provider@1";
|
|
335
|
+
/** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
|
|
304
336
|
export declare const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
|
package/dist/model.js
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Types accepted by image blocks. */
|
|
2
2
|
export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
3
|
-
/**
|
|
3
|
+
/** Types accepted by document blocks. */
|
|
4
4
|
export const DOCUMENT_MEDIA_TYPES = [
|
|
5
5
|
"application/pdf",
|
|
6
6
|
"text/plain",
|
|
7
7
|
"text/markdown",
|
|
8
8
|
"text/csv",
|
|
9
9
|
];
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
|
|
12
|
+
* vendors).
|
|
13
|
+
*/
|
|
11
14
|
export const MEDIA_LIMITS = { imageBytes: 5_242_880, documentBytes: 33_554_432 };
|
|
12
15
|
const B64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
13
16
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
14
|
-
/**
|
|
17
|
+
/** Maximum length (characters) of a media block's `name`. */
|
|
15
18
|
export const MEDIA_NAME_MAX_CHARS = 255;
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Suggested upper bound (code points) for file names / titles in vendor requests, the default of
|
|
21
|
+
* {@link clipMediaName}.
|
|
22
|
+
*/
|
|
17
23
|
export const PROVIDER_MEDIA_NAME_MAX = 200;
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
25
|
+
* Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
|
|
26
|
+
* filename / title length, and adding a suffix makes it longer still).
|
|
27
|
+
* Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
|
|
28
|
+
* part in the middle. A pure function.
|
|
21
29
|
*/
|
|
22
30
|
export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
|
|
23
31
|
const cps = [...name];
|
|
@@ -29,7 +37,7 @@ export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
|
|
|
29
37
|
const head = cps.slice(0, max - 1 - keep.length);
|
|
30
38
|
return `${head.join("")}…${keep.join("")}`;
|
|
31
39
|
}
|
|
32
|
-
/**
|
|
40
|
+
/** Whether it contains control characters (C0, DEL and C1). */
|
|
33
41
|
export function hasControlChars(s) {
|
|
34
42
|
for (let i = 0; i < s.length; i++) {
|
|
35
43
|
const c = s.charCodeAt(i);
|
|
@@ -38,7 +46,7 @@ export function hasControlChars(s) {
|
|
|
38
46
|
}
|
|
39
47
|
return false;
|
|
40
48
|
}
|
|
41
|
-
/**
|
|
49
|
+
/** Whether the attachment id is a UUID (any version, case-insensitive). */
|
|
42
50
|
export function isAttachmentId(s) {
|
|
43
51
|
return typeof s === "string" && UUID_RE.test(s);
|
|
44
52
|
}
|
|
@@ -108,7 +116,8 @@ export function validateMediaBlock(b) {
|
|
|
108
116
|
errs.push(`${o.type} source.data must be non-empty padded base64`);
|
|
109
117
|
return errs;
|
|
110
118
|
}
|
|
111
|
-
//
|
|
119
|
+
// Compute the decoded size from the length first; when over the limit, skip the per-character
|
|
120
|
+
// validation
|
|
112
121
|
const pad = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
|
|
113
122
|
const bytes = (data.length / 4) * 3 - pad;
|
|
114
123
|
if (bytes > spec.limit) {
|
|
@@ -141,11 +150,13 @@ const RETRYABLE = new Set([
|
|
|
141
150
|
"timeout",
|
|
142
151
|
"network",
|
|
143
152
|
]);
|
|
144
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
153
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
145
154
|
export function isRetryableKind(kind) {
|
|
146
155
|
return RETRYABLE.has(kind);
|
|
147
156
|
}
|
|
148
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
|
|
159
|
+
*/
|
|
149
160
|
export function isModelError(e) {
|
|
150
161
|
if (!(e instanceof Error))
|
|
151
162
|
return false;
|
|
@@ -162,7 +173,7 @@ export class ModelError extends Error {
|
|
|
162
173
|
if (opts?.retryAfterMs !== undefined)
|
|
163
174
|
this.retryAfterMs = opts.retryAfterMs;
|
|
164
175
|
}
|
|
165
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
176
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
166
177
|
get retryable() {
|
|
167
178
|
return isRetryableKind(this.kind);
|
|
168
179
|
}
|
|
@@ -189,5 +200,5 @@ export function validateEmbedResult(req, info, res) {
|
|
|
189
200
|
}
|
|
190
201
|
return null;
|
|
191
202
|
}
|
|
192
|
-
|
|
203
|
+
/** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
|
|
193
204
|
export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface ExtensionPermissions {
|
|
|
6
6
|
secrets?: boolean;
|
|
7
7
|
/** Routes registered with ctx.http.route; each declares who may call it (`access`). */
|
|
8
8
|
http?: HttpPermission[];
|
|
9
|
-
/** ctx.tools.register
|
|
9
|
+
/** Tool names for ctx.tools.register. */
|
|
10
10
|
tools?: string[];
|
|
11
11
|
/**
|
|
12
12
|
* Hook mount points (`ctx.hooks.on`). From M7, five mount points are registrable; see
|
|
@@ -31,9 +31,9 @@ export interface ExtensionPermissions {
|
|
|
31
31
|
en: string;
|
|
32
32
|
};
|
|
33
33
|
}[];
|
|
34
|
-
/** ctx.storage
|
|
34
|
+
/** ctx.storage (object storage, keys confined under `plugins/<plugin name>/<orgId>/`). */
|
|
35
35
|
storage?: boolean;
|
|
36
|
-
/**
|
|
36
|
+
/** Domains accessed; displayed only, not enforced. */
|
|
37
37
|
network?: string[];
|
|
38
38
|
/**
|
|
39
39
|
* Client code: the package's `client` section (a browser bundle the web app loads for the
|
|
@@ -58,9 +58,9 @@ export interface ExtensionPermissions {
|
|
|
58
58
|
*/
|
|
59
59
|
setupChecks?: string[];
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
61
|
+
/** Hook mount points (a closed list, see the overall design 2.4). */
|
|
62
62
|
export declare const HOOK_MOUNT_POINTS: readonly ["session.start", "session.end", "agent.preStep", "model.request", "model.response", "tool.preExecute", "tool.postExecute", "usage.report", "org.member_removed", "agent.deleted", "org.deleted"];
|
|
63
|
-
/** hook
|
|
63
|
+
/** A hook mount point name. */
|
|
64
64
|
export type HookMountPoint = (typeof HOOK_MOUNT_POINTS)[number];
|
|
65
65
|
/** A platform API not declared in the manifest was used. */
|
|
66
66
|
export declare class ExtensionPermissionError extends Error {
|
|
@@ -70,7 +70,7 @@ export declare class ExtensionPermissionError extends Error {
|
|
|
70
70
|
export declare class ExtensionPointUnavailableError extends Error {
|
|
71
71
|
constructor(message: string);
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
73
|
+
/** Validates the permission manifest and returns the list of errors (empty means valid). */
|
|
74
74
|
export declare function validatePermissions(plugin: string, p: unknown): string[];
|
|
75
75
|
/**
|
|
76
76
|
* Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
|
package/dist/permissions.js
CHANGED
|
@@ -2,8 +2,8 @@ import { POLICY_HOOKS } from "./hooks.js";
|
|
|
2
2
|
import { HTTP_ACCESS } from "./http-access.js";
|
|
3
3
|
import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
|
|
4
4
|
import { UI_ICONS } from "./ui.js";
|
|
5
|
-
import {
|
|
6
|
-
/**
|
|
5
|
+
import { parseSlotRef, uiSlot } from "./ui-slots.js";
|
|
6
|
+
/** Hook mount points (a closed list, see the overall design 2.4). */
|
|
7
7
|
export const HOOK_MOUNT_POINTS = [
|
|
8
8
|
"session.start",
|
|
9
9
|
"session.end",
|
|
@@ -65,7 +65,7 @@ function strList(label, v, errs) {
|
|
|
65
65
|
}
|
|
66
66
|
return out;
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
68
|
+
/** Validates the permission manifest and returns the list of errors (empty means valid). */
|
|
69
69
|
export function validatePermissions(plugin, p) {
|
|
70
70
|
if (p === undefined)
|
|
71
71
|
return [];
|
|
@@ -202,7 +202,6 @@ export function validatePermissions(plugin, p) {
|
|
|
202
202
|
}
|
|
203
203
|
const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
|
|
204
204
|
const UI_TITLE_MAX = 100;
|
|
205
|
-
const UI_PLACES = Object.keys(PLACE_SLOTS);
|
|
206
205
|
const UI_EMBED_PREFIX = "/ui/";
|
|
207
206
|
/**
|
|
208
207
|
* Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
|
|
@@ -249,7 +248,6 @@ export function validateUiContributions(ui, permissions) {
|
|
|
249
248
|
contributions.push(...ui);
|
|
250
249
|
}
|
|
251
250
|
const seen = new Map();
|
|
252
|
-
const aliases = [];
|
|
253
251
|
contributions.forEach((c, i) => {
|
|
254
252
|
const at = `ui[${i}]`;
|
|
255
253
|
if (!isObj(c)) {
|
|
@@ -265,22 +263,10 @@ export function validateUiContributions(ui, permissions) {
|
|
|
265
263
|
if (!title ||
|
|
266
264
|
[title.zh, title.en].some((t) => typeof t !== "string" || t === "" || t.length > UI_TITLE_MAX))
|
|
267
265
|
errs.push(`ui "${id}" title needs non-empty zh and en of at most ${UI_TITLE_MAX} characters`);
|
|
268
|
-
// the slot it names, when
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
errs.push(`ui "${id}"
|
|
272
|
-
}
|
|
273
|
-
else if (c.slot !== undefined) {
|
|
274
|
-
slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
|
|
275
|
-
if (slotRef === null)
|
|
276
|
-
errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
|
|
277
|
-
}
|
|
278
|
-
else if (!UI_PLACES.includes(c.place)) {
|
|
279
|
-
errs.push(`ui "${id}" place must be one of ${UI_PLACES.join(", ")}`);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
slotRef = { id: PLACE_SLOTS[c.place], version: 1 };
|
|
283
|
-
}
|
|
266
|
+
// the slot it names, when it is well formed (known to the catalog or not)
|
|
267
|
+
const slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
|
|
268
|
+
if (slotRef === null)
|
|
269
|
+
errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
|
|
284
270
|
if (c.after !== undefined && typeof c.after !== "string")
|
|
285
271
|
errs.push(`ui "${id}" after must be a string`);
|
|
286
272
|
if (c.kind !== "view" && c.kind !== "embed" && c.kind !== "component") {
|
|
@@ -296,11 +282,9 @@ export function validateUiContributions(ui, permissions) {
|
|
|
296
282
|
if (spec !== undefined) {
|
|
297
283
|
if (!spec.accepts.includes(c.kind))
|
|
298
284
|
errs.push(`ui "${id}" slot ${spec.id} does not accept kind ${c.kind}`);
|
|
299
|
-
if (spec.icon === "required" && c.icon === undefined
|
|
285
|
+
if (spec.icon === "required" && c.icon === undefined)
|
|
300
286
|
errs.push(`ui "${id}" slot ${spec.id} needs an icon`);
|
|
301
287
|
}
|
|
302
|
-
if (c.aliasOf !== undefined)
|
|
303
|
-
aliases.push({ id, kind: c.kind, target: c.aliasOf });
|
|
304
288
|
if (seen.has(id))
|
|
305
289
|
errs.push(`ui has duplicate id "${id}"`);
|
|
306
290
|
seen.set(id, c.kind);
|
|
@@ -327,14 +311,6 @@ export function validateUiContributions(ui, permissions) {
|
|
|
327
311
|
errs.push(`ui "${id}" embed path "${c.path}" must be declared in permissions.http as GET with access public`);
|
|
328
312
|
}
|
|
329
313
|
});
|
|
330
|
-
const aliasIds = new Set(aliases.map((a) => a.id));
|
|
331
|
-
for (const a of aliases) {
|
|
332
|
-
if (typeof a.target !== "string" ||
|
|
333
|
-
a.target === a.id ||
|
|
334
|
-
aliasIds.has(a.target) ||
|
|
335
|
-
seen.get(a.target) !== a.kind)
|
|
336
|
-
errs.push(`ui "${a.id}" aliasOf must name another, non-alias ${a.kind} contribution`);
|
|
337
|
-
}
|
|
338
314
|
for (const [k, kind, ids] of [
|
|
339
315
|
["views", "view", views],
|
|
340
316
|
["embeds", "embed", embeds],
|