@capybara-hq/plugin-sdk 0.1.0-rc.25 → 0.1.0-rc.27
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 +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- 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/hooks.d.ts +6 -4
- 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 +121 -70
- package/dist/model.js +49 -19
- 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 +1412 -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 +52 -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.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,18 +46,26 @@ 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
|
}
|
|
53
|
+
/** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
|
|
54
|
+
const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
|
|
45
55
|
const MEDIA = {
|
|
46
56
|
image: { types: IMAGE_MEDIA_TYPES, limit: MEDIA_LIMITS.imageBytes },
|
|
47
57
|
document: { types: DOCUMENT_MEDIA_TYPES, limit: MEDIA_LIMITS.documentBytes },
|
|
58
|
+
// A file the model cannot read: the kernel resolves it to text before the request, so no media
|
|
59
|
+
// type list applies. The byte ceiling is the one attachments already have.
|
|
60
|
+
file: { types: [], limit: MEDIA_LIMITS.documentBytes, anyType: true },
|
|
48
61
|
};
|
|
49
62
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
63
|
+
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
64
|
+
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
65
|
+
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
66
|
+
* `attachmentId` is a UUID; `name`, when present, is a string of at most
|
|
67
|
+
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
68
|
+
* non-negative integer (display metadata, never sent by a plugin).
|
|
53
69
|
*/
|
|
54
70
|
export function validateMediaBlock(b) {
|
|
55
71
|
if (typeof b !== "object" || b === null || Array.isArray(b))
|
|
@@ -57,9 +73,16 @@ export function validateMediaBlock(b) {
|
|
|
57
73
|
const o = b;
|
|
58
74
|
const spec = typeof o.type === "string" && Object.hasOwn(MEDIA, o.type) ? MEDIA[o.type] : undefined;
|
|
59
75
|
if (!spec)
|
|
60
|
-
return ['block type must be "image" or "
|
|
76
|
+
return ['block type must be "image", "document" or "file"'];
|
|
61
77
|
const errs = [];
|
|
62
|
-
if (
|
|
78
|
+
if (spec.anyType) {
|
|
79
|
+
if (typeof o.mediaType !== "string" ||
|
|
80
|
+
!MEDIA_TYPE_RE.test(o.mediaType) ||
|
|
81
|
+
hasControlChars(o.mediaType)) {
|
|
82
|
+
errs.push(`${o.type} mediaType must be a non-empty type/subtype string`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
|
|
63
86
|
errs.push(`${o.type} mediaType must be one of ${spec.types.join(", ")}`);
|
|
64
87
|
}
|
|
65
88
|
if (o.name !== undefined) {
|
|
@@ -72,6 +95,10 @@ export function validateMediaBlock(b) {
|
|
|
72
95
|
errs.push(`${o.type} name must not contain control characters`);
|
|
73
96
|
}
|
|
74
97
|
}
|
|
98
|
+
if (o.size !== undefined &&
|
|
99
|
+
(typeof o.size !== "number" || !Number.isInteger(o.size) || o.size < 0)) {
|
|
100
|
+
errs.push(`${o.type} size must be a non-negative integer`);
|
|
101
|
+
}
|
|
75
102
|
const src = o.source;
|
|
76
103
|
if (typeof src !== "object" || src === null) {
|
|
77
104
|
errs.push(`${o.type} source must be an object`);
|
|
@@ -89,7 +116,8 @@ export function validateMediaBlock(b) {
|
|
|
89
116
|
errs.push(`${o.type} source.data must be non-empty padded base64`);
|
|
90
117
|
return errs;
|
|
91
118
|
}
|
|
92
|
-
//
|
|
119
|
+
// Compute the decoded size from the length first; when over the limit, skip the per-character
|
|
120
|
+
// validation
|
|
93
121
|
const pad = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
|
|
94
122
|
const bytes = (data.length / 4) * 3 - pad;
|
|
95
123
|
if (bytes > spec.limit) {
|
|
@@ -122,11 +150,13 @@ const RETRYABLE = new Set([
|
|
|
122
150
|
"timeout",
|
|
123
151
|
"network",
|
|
124
152
|
]);
|
|
125
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
153
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
126
154
|
export function isRetryableKind(kind) {
|
|
127
155
|
return RETRYABLE.has(kind);
|
|
128
156
|
}
|
|
129
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
|
|
159
|
+
*/
|
|
130
160
|
export function isModelError(e) {
|
|
131
161
|
if (!(e instanceof Error))
|
|
132
162
|
return false;
|
|
@@ -143,7 +173,7 @@ export class ModelError extends Error {
|
|
|
143
173
|
if (opts?.retryAfterMs !== undefined)
|
|
144
174
|
this.retryAfterMs = opts.retryAfterMs;
|
|
145
175
|
}
|
|
146
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
176
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
147
177
|
get retryable() {
|
|
148
178
|
return isRetryableKind(this.kind);
|
|
149
179
|
}
|
|
@@ -170,5 +200,5 @@ export function validateEmbedResult(req, info, res) {
|
|
|
170
200
|
}
|
|
171
201
|
return null;
|
|
172
202
|
}
|
|
173
|
-
|
|
203
|
+
/** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
|
|
174
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],
|
package/dist/plugin-package.d.ts
CHANGED
|
@@ -11,17 +11,29 @@ import type { PluginManifest } from "./plugin-manifest.js";
|
|
|
11
11
|
* entry is single-file ESM with third-party dependencies bundled; only {@link HOST_PROVIDED_PACKAGES}
|
|
12
12
|
* come from the host.
|
|
13
13
|
*/
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Packages provided by the host (peerDependencies, linked to the host's copy on install); every
|
|
16
|
+
* other third-party dependency must be bundled into the entry.
|
|
17
|
+
*/
|
|
15
18
|
export declare const HOST_PROVIDED_PACKAGES: readonly ["@capybara-hq/plugin-sdk", "zod"];
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Scripts npm runs automatically on install: a plugin package must never have any (installs run no
|
|
21
|
+
* scripts, so having them would mislead).
|
|
22
|
+
*/
|
|
17
23
|
export declare const FORBIDDEN_INSTALL_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepare"];
|
|
18
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* A config field in the static manifest (a dotted path; an empty string when the root is itself the
|
|
26
|
+
* leaf).
|
|
27
|
+
*/
|
|
19
28
|
export interface StaticConfigField {
|
|
20
29
|
path: string;
|
|
21
30
|
secret: boolean;
|
|
22
31
|
hot: boolean;
|
|
23
32
|
}
|
|
24
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The static part of the plugin manifest (JSON-serializable; excludes setup, zod schemas and
|
|
35
|
+
* migration paths).
|
|
36
|
+
*/
|
|
25
37
|
export interface StaticExtensionManifest {
|
|
26
38
|
name: string;
|
|
27
39
|
version: string;
|
|
@@ -36,27 +48,38 @@ export interface StaticExtensionManifest {
|
|
|
36
48
|
org: StaticConfigField[];
|
|
37
49
|
};
|
|
38
50
|
}
|
|
39
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* An import in the entry module: `name` is the specifier (an empty string for a dynamic import that
|
|
53
|
+
* is not a literal).
|
|
54
|
+
*/
|
|
40
55
|
export interface EntryImport {
|
|
41
56
|
name: string;
|
|
42
57
|
dynamic: boolean;
|
|
43
58
|
literal: boolean;
|
|
44
59
|
}
|
|
45
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* npm package name rule (simplified): may carry a scope, lowercase, ≤ 214 characters (the length is
|
|
62
|
+
* checked separately).
|
|
63
|
+
*/
|
|
46
64
|
export declare const NPM_PACKAGE_NAME_RE: RegExp;
|
|
47
65
|
/**
|
|
48
|
-
*
|
|
66
|
+
* Whether a path relative to the package is safe: non-empty, not starting with `/`, no `\`, control
|
|
67
|
+
* characters or drive letters, no empty segments, `.` or `..` segments, ≤ 1024 characters.
|
|
49
68
|
*/
|
|
50
69
|
export declare function isSafePackagePath(p: string): boolean;
|
|
51
70
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
71
|
+
* Checks the entry module's imports (C11): static and literal dynamic imports may only be `node:*`,
|
|
72
|
+
* {@link HOST_PROVIDED_PACKAGES} (subpaths included)
|
|
73
|
+
* and in-package relative paths (`./`, `../`; whether they escape the package is judged by the
|
|
74
|
+
* caller from the file location); non-literal dynamic imports are always rejected.
|
|
75
|
+
* Returns the list of problems (empty means valid).
|
|
55
76
|
*/
|
|
56
77
|
export declare function checkEntryImports(specifiers: EntryImport[]): string[];
|
|
57
78
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
79
|
+
* The static part of the real manifest: written into `capybara.manifest` when packing, and compared
|
|
80
|
+
* with the in-package one at load time (`manifest_mismatch`).
|
|
81
|
+
* The result survives a JSON round trip (undefined fields removed); config fields are sorted by
|
|
82
|
+
* path.
|
|
60
83
|
*/
|
|
61
84
|
export declare function staticManifestOf(m: ExtensionManifest): StaticExtensionManifest;
|
|
62
85
|
/**
|
|
@@ -79,64 +102,82 @@ export declare function validatePluginPackageJsonFor(pkg: unknown, manifest: Plu
|
|
|
79
102
|
*/
|
|
80
103
|
export declare function hostSdkProblem(sdk: string, hostSdkVersion: string): string | undefined;
|
|
81
104
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
105
|
+
* Connector template (C30): connector plugin reference + `Connector.kind` + endpoint preset +
|
|
106
|
+
* endpoint paths an org may change + auth preset (no credentials) +
|
|
107
|
+
* default ownership + default policy per tool + icon. When installing, an org may only fill in
|
|
108
|
+
* credentials, the client id / secret and the fields in `editableEndpoint`.
|
|
84
109
|
*/
|
|
85
110
|
export interface ConnectorTemplateSpec {
|
|
86
|
-
/**
|
|
111
|
+
/** Connector plugin name (e.g. `connector-mcp`). */
|
|
87
112
|
plugin: string;
|
|
88
|
-
/**
|
|
113
|
+
/** Semver range of the connector plugin, optional. */
|
|
89
114
|
pluginVersion?: string;
|
|
90
|
-
/** `Connector.kind
|
|
115
|
+
/** `Connector.kind` (e.g. `"mcp"`). */
|
|
91
116
|
connector: string;
|
|
92
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Endpoint preset; on import the kernel validates it against that connector's `endpointSchema`.
|
|
119
|
+
*/
|
|
93
120
|
endpoint: Record<string, unknown>;
|
|
94
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Dotted paths an org may change when installing (e.g. `"url"`); everything else follows the
|
|
123
|
+
* template. The paths must exist in the connector's endpoint schema.
|
|
124
|
+
*/
|
|
95
125
|
editableEndpoint?: string[];
|
|
96
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* The same shape as the auth method of the connector install API ({@link ConnectorAuthSchema}),
|
|
128
|
+
* carrying no credentials.
|
|
129
|
+
*/
|
|
97
130
|
auth: Record<string, unknown>;
|
|
98
|
-
/**
|
|
131
|
+
/** Defaults to `auth.ownership`; if given it must agree. */
|
|
99
132
|
ownership?: "org" | "personal";
|
|
100
|
-
/**
|
|
133
|
+
/** Tool name -> default policy (recorded as `policy_source 'template'` after install). */
|
|
101
134
|
defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
|
|
102
135
|
/** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
|
|
103
136
|
git?: GitSource;
|
|
104
|
-
/**
|
|
137
|
+
/** In-package path, svg / png, ≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`. */
|
|
105
138
|
icon?: string;
|
|
106
139
|
}
|
|
107
|
-
/**
|
|
140
|
+
/** Bilingual display name. */
|
|
108
141
|
export interface LocalizedName {
|
|
109
142
|
zh: string;
|
|
110
143
|
en: string;
|
|
111
144
|
}
|
|
112
|
-
/**
|
|
145
|
+
/** Limits of connector templates and catalog segments. */
|
|
113
146
|
export declare const CONNECTOR_TEMPLATE_LIMITS: {
|
|
114
|
-
/**
|
|
147
|
+
/** Upper bound on icon bytes. */
|
|
115
148
|
readonly iconBytes: number;
|
|
116
|
-
/**
|
|
149
|
+
/** Upper bound on the characters of the endpoint preset after JSON serialization. */
|
|
117
150
|
readonly endpointChars: number;
|
|
118
|
-
/** `editableEndpoint`
|
|
151
|
+
/** Upper bound on the number of `editableEndpoint` entries. */
|
|
119
152
|
readonly editablePaths: 50;
|
|
120
|
-
/** `defaultToolPolicies`
|
|
153
|
+
/** Upper bound on the number of `defaultToolPolicies` entries. */
|
|
121
154
|
readonly toolPolicies: 1000;
|
|
122
|
-
/** publisher
|
|
155
|
+
/** Upper bound on the characters of publisher. */
|
|
123
156
|
readonly publisherChars: 100;
|
|
124
|
-
/** description
|
|
157
|
+
/** Upper bound on the characters of description. */
|
|
125
158
|
readonly descriptionChars: 1024;
|
|
126
|
-
/** displayName
|
|
159
|
+
/** Upper bound on the characters of displayName per language. */
|
|
127
160
|
readonly displayNameChars: 100;
|
|
128
161
|
};
|
|
129
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* Catalog entry name (the same rule as manifest entry names): starts with a lowercase letter or
|
|
164
|
+
* digit, then lowercase letters, digits and hyphens, ≤ 64.
|
|
165
|
+
*/
|
|
130
166
|
export declare const CATALOG_ITEM_NAME_RE: RegExp;
|
|
131
167
|
/** An exact semver version (a regex JSON Schema can use). */
|
|
132
168
|
export declare const SEMVER_VERSION_RE: RegExp;
|
|
133
169
|
/** The sha512 SRI of an npm package tgz: `sha512-<86 base64 chars>==`. */
|
|
134
170
|
export declare const SHA512_INTEGRITY_RE: RegExp;
|
|
135
171
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
172
|
+
* Validates the static part of a connector template ({@link ConnectorTemplateSpec}) and returns the
|
|
173
|
+
* list of problems (empty means valid; paths are relative to the template root, values are not
|
|
174
|
+
* echoed):
|
|
175
|
+
* fields complete, no unknown fields; `auth` conforms to {@link ConnectorAuthSchema} (strict: extra
|
|
176
|
+
* fields such as `token` are rejected);
|
|
177
|
+
* no credential-style key at any level of the endpoint preset; `editableEndpoint` is a list of
|
|
178
|
+
* distinct dotted paths; `ownership` agrees with `auth.ownership`;
|
|
179
|
+
* default policies may only be allow / ask / deny; icon is an in-package .svg / .png path.
|
|
180
|
+
* Whether the endpoint conforms to the connector's `endpointSchema` and whether `editableEndpoint`
|
|
181
|
+
* exists in it is checked by the kernel on import against the loaded connector.
|
|
141
182
|
*/
|
|
142
183
|
export declare function validateConnectorTemplate(t: unknown): string[];
|
package/dist/plugin-package.js
CHANGED
|
@@ -11,16 +11,24 @@ import { validateGitSource } from "./git-hosts.js";
|
|
|
11
11
|
* entry is single-file ESM with third-party dependencies bundled; only {@link HOST_PROVIDED_PACKAGES}
|
|
12
12
|
* come from the host.
|
|
13
13
|
*/
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Packages provided by the host (peerDependencies, linked to the host's copy on install); every
|
|
16
|
+
* other third-party dependency must be bundled into the entry.
|
|
17
|
+
*/
|
|
15
18
|
export const HOST_PROVIDED_PACKAGES = ["@capybara-hq/plugin-sdk", "zod"];
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Scripts npm runs automatically on install: a plugin package must never have any (installs run no
|
|
21
|
+
* scripts, so having them would mislead).
|
|
22
|
+
*/
|
|
17
23
|
export const FORBIDDEN_INSTALL_SCRIPTS = [
|
|
18
24
|
"preinstall",
|
|
19
25
|
"install",
|
|
20
26
|
"postinstall",
|
|
21
27
|
"prepare",
|
|
22
28
|
];
|
|
23
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Dependency fields that must not appear: third-party dependencies must be bundled into the entry.
|
|
31
|
+
*/
|
|
24
32
|
const FORBIDDEN_DEP_FIELDS = [
|
|
25
33
|
"dependencies",
|
|
26
34
|
"optionalDependencies",
|
|
@@ -28,16 +36,20 @@ const FORBIDDEN_DEP_FIELDS = [
|
|
|
28
36
|
"bundledDependencies",
|
|
29
37
|
];
|
|
30
38
|
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
31
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* npm package name rule (simplified): may carry a scope, lowercase, ≤ 214 characters (the length is
|
|
41
|
+
* checked separately).
|
|
42
|
+
*/
|
|
32
43
|
export const NPM_PACKAGE_NAME_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
33
44
|
const NPM_NAME_RE = NPM_PACKAGE_NAME_RE;
|
|
34
45
|
/**
|
|
35
|
-
*
|
|
46
|
+
* Whether a path relative to the package is safe: non-empty, not starting with `/`, no `\`, control
|
|
47
|
+
* characters or drive letters, no empty segments, `.` or `..` segments, ≤ 1024 characters.
|
|
36
48
|
*/
|
|
37
49
|
export function isSafePackagePath(p) {
|
|
38
50
|
if (typeof p !== "string" || p === "" || p.length > 1024)
|
|
39
51
|
return false;
|
|
40
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex:
|
|
52
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be rejected
|
|
41
53
|
if (p.startsWith("/") || p.includes("\\") || /[\u0000-\u001f\u007f]/.test(p))
|
|
42
54
|
return false;
|
|
43
55
|
if (/^[A-Za-z]:/.test(p))
|
|
@@ -46,9 +58,11 @@ export function isSafePackagePath(p) {
|
|
|
46
58
|
}
|
|
47
59
|
const isHostPackage = (name) => HOST_PROVIDED_PACKAGES.some((h) => name === h || name.startsWith(`${h}/`));
|
|
48
60
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
61
|
+
* Checks the entry module's imports (C11): static and literal dynamic imports may only be `node:*`,
|
|
62
|
+
* {@link HOST_PROVIDED_PACKAGES} (subpaths included)
|
|
63
|
+
* and in-package relative paths (`./`, `../`; whether they escape the package is judged by the
|
|
64
|
+
* caller from the file location); non-literal dynamic imports are always rejected.
|
|
65
|
+
* Returns the list of problems (empty means valid).
|
|
52
66
|
*/
|
|
53
67
|
export function checkEntryImports(specifiers) {
|
|
54
68
|
const out = [];
|
|
@@ -72,7 +86,10 @@ export function checkEntryImports(specifiers) {
|
|
|
72
86
|
const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
|
|
73
87
|
const defOf = (s) => s._zod.def;
|
|
74
88
|
const metaOf = (s) => s.meta();
|
|
75
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* The same traversal as the kernel's `configFields`: objects are expanded recursively, wrappers
|
|
91
|
+
* such as default / optional are stripped, and a secret on an object is inherited downward.
|
|
92
|
+
*/
|
|
76
93
|
function configFieldsOf(schema, prefix = "", inheritedSecret = false) {
|
|
77
94
|
if (!schema)
|
|
78
95
|
return [];
|
|
@@ -92,8 +109,10 @@ function configFieldsOf(schema, prefix = "", inheritedSecret = false) {
|
|
|
92
109
|
const byPath = (a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
93
110
|
const jsonClone = (v) => JSON.parse(JSON.stringify(v));
|
|
94
111
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
112
|
+
* The static part of the real manifest: written into `capybara.manifest` when packing, and compared
|
|
113
|
+
* with the in-package one at load time (`manifest_mismatch`).
|
|
114
|
+
* The result survives a JSON round trip (undefined fields removed); config fields are sorted by
|
|
115
|
+
* path.
|
|
97
116
|
*/
|
|
98
117
|
export function staticManifestOf(m) {
|
|
99
118
|
const out = {
|
|
@@ -254,24 +273,27 @@ export function hostSdkProblem(sdk, hostSdkVersion) {
|
|
|
254
273
|
return undefined;
|
|
255
274
|
return `extension.manifest.sdk "${sdk}" is not satisfied by the host SDK version ${hostSdkVersion}`;
|
|
256
275
|
}
|
|
257
|
-
/**
|
|
276
|
+
/** Limits of connector templates and catalog segments. */
|
|
258
277
|
export const CONNECTOR_TEMPLATE_LIMITS = {
|
|
259
|
-
/**
|
|
278
|
+
/** Upper bound on icon bytes. */
|
|
260
279
|
iconBytes: 64 * 1024,
|
|
261
|
-
/**
|
|
280
|
+
/** Upper bound on the characters of the endpoint preset after JSON serialization. */
|
|
262
281
|
endpointChars: 16 * 1024,
|
|
263
|
-
/** `editableEndpoint`
|
|
282
|
+
/** Upper bound on the number of `editableEndpoint` entries. */
|
|
264
283
|
editablePaths: 50,
|
|
265
|
-
/** `defaultToolPolicies`
|
|
284
|
+
/** Upper bound on the number of `defaultToolPolicies` entries. */
|
|
266
285
|
toolPolicies: 1000,
|
|
267
|
-
/** publisher
|
|
286
|
+
/** Upper bound on the characters of publisher. */
|
|
268
287
|
publisherChars: 100,
|
|
269
|
-
/** description
|
|
288
|
+
/** Upper bound on the characters of description. */
|
|
270
289
|
descriptionChars: 1024,
|
|
271
|
-
/** displayName
|
|
290
|
+
/** Upper bound on the characters of displayName per language. */
|
|
272
291
|
displayNameChars: 100,
|
|
273
292
|
};
|
|
274
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* Catalog entry name (the same rule as manifest entry names): starts with a lowercase letter or
|
|
295
|
+
* digit, then lowercase letters, digits and hyphens, ≤ 64.
|
|
296
|
+
*/
|
|
275
297
|
export const CATALOG_ITEM_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
276
298
|
/** An exact semver version (a regex JSON Schema can use). */
|
|
277
299
|
export const SEMVER_VERSION_RE = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/;
|
|
@@ -280,8 +302,9 @@ export const SHA512_INTEGRITY_RE = /^sha512-[A-Za-z0-9+/]{86}==$/;
|
|
|
280
302
|
const PATH_SEG_RE = /^[A-Za-z0-9_-]{1,100}$/;
|
|
281
303
|
const PROTO_KEYS = new Set(["__proto__", "prototype", "constructor"]);
|
|
282
304
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
305
|
+
* Credential-style field names (compared lowercased with `-` and `_` removed): templates are seen
|
|
306
|
+
* by every org, so endpoint presets containing these keys are always rejected.
|
|
307
|
+
* Header names such as `authorization` / `cookie` are listed too (credentials in endpoint headers).
|
|
285
308
|
*/
|
|
286
309
|
const CREDENTIAL_KEYS = new Set([
|
|
287
310
|
"token",
|
|
@@ -306,7 +329,7 @@ const CREDENTIAL_KEYS = new Set([
|
|
|
306
329
|
"sessiontoken",
|
|
307
330
|
]);
|
|
308
331
|
const normKey = (k) => k.toLowerCase().replace(/[-_]/g, "");
|
|
309
|
-
/**
|
|
332
|
+
/** Recursively finds credential-style keys (reports only paths, never echoes values). */
|
|
310
333
|
function credentialKeyPaths(v, at, out, depth = 0) {
|
|
311
334
|
if (depth > 20)
|
|
312
335
|
return;
|
|
@@ -338,11 +361,16 @@ const TEMPLATE_KEYS = new Set([
|
|
|
338
361
|
"icon",
|
|
339
362
|
]);
|
|
340
363
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
364
|
+
* Validates the static part of a connector template ({@link ConnectorTemplateSpec}) and returns the
|
|
365
|
+
* list of problems (empty means valid; paths are relative to the template root, values are not
|
|
366
|
+
* echoed):
|
|
367
|
+
* fields complete, no unknown fields; `auth` conforms to {@link ConnectorAuthSchema} (strict: extra
|
|
368
|
+
* fields such as `token` are rejected);
|
|
369
|
+
* no credential-style key at any level of the endpoint preset; `editableEndpoint` is a list of
|
|
370
|
+
* distinct dotted paths; `ownership` agrees with `auth.ownership`;
|
|
371
|
+
* default policies may only be allow / ask / deny; icon is an in-package .svg / .png path.
|
|
372
|
+
* Whether the endpoint conforms to the connector's `endpointSchema` and whether `editableEndpoint`
|
|
373
|
+
* exists in it is checked by the kernel on import against the loaded connector.
|
|
346
374
|
*/
|
|
347
375
|
export function validateConnectorTemplate(t) {
|
|
348
376
|
if (!isObj(t))
|