@capybara-hq/plugin-sdk 0.1.0-rc.8 → 0.1.0-rc.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-docs/agent-templates.md +14 -2
- package/agent-docs/concepts.md +14 -5
- package/agent-docs/connector-templates.md +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 +3 -1
- package/agent-docs/extension-points/object-store.md +2 -0
- package/agent-docs/extension-points/push-provider.md +17 -0
- package/agent-docs/extensions.md +77 -4
- package/agent-docs/plugin-format.md +45 -10
- package/agent-docs/setup.md +54 -0
- package/dist/agent-template.d.ts +15 -6
- package/dist/agent-template.js +32 -13
- package/dist/avatar-presets.d.ts +8 -0
- package/dist/avatar-presets.js +17 -0
- package/dist/bootstrap.d.ts +109 -1
- package/dist/bootstrap.js +185 -2
- package/dist/cards.d.ts +60 -13
- package/dist/cards.js +88 -18
- package/dist/channel.d.ts +128 -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 +224 -30
- package/dist/ctx.js +9 -1
- package/dist/define-extension.d.ts +23 -13
- package/dist/define-extension.js +19 -5
- package/dist/device-denied-paths.d.ts +20 -0
- package/dist/device-denied-paths.js +118 -0
- package/dist/device-operation.d.ts +339 -0
- package/dist/device-operation.js +312 -0
- package/dist/device-protocol.d.ts +285 -50
- package/dist/device-protocol.js +755 -90
- package/dist/device-provider.d.ts +780 -0
- package/dist/device-provider.js +409 -0
- package/dist/device-service.d.ts +126 -0
- package/dist/device-service.js +211 -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 +7 -3
- package/dist/field-meta.d.ts +19 -0
- package/dist/field-meta.js +54 -0
- package/dist/file-preview.d.ts +43 -10
- package/dist/git-hosts.d.ts +53 -0
- package/dist/git-hosts.js +98 -0
- package/dist/hooks.d.ts +125 -20
- package/dist/hooks.js +5 -0
- package/dist/http-access.d.ts +71 -0
- package/dist/http-access.js +12 -0
- package/dist/identity.d.ts +70 -9
- package/dist/identity.js +46 -1
- package/dist/index.d.ts +28 -4
- package/dist/index.js +28 -4
- package/dist/model-params.d.ts +41 -22
- package/dist/model-params.js +28 -15
- package/dist/model.d.ts +210 -75
- package/dist/model.js +152 -19
- 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 +65 -22
- package/dist/permissions.js +139 -43
- 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 +211 -0
- package/dist/shell-capabilities.js +44 -0
- package/dist/shell-environment.d.ts +57 -0
- package/dist/shell-environment.js +21 -0
- package/dist/skill-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 +26 -2
- package/dist/theme-tokens.generated.js +17 -0
- package/dist/theme.d.ts +48 -10
- package/dist/theme.js +100 -21
- package/dist/tool.d.ts +156 -30
- package/dist/tool.js +91 -9
- package/dist/ui-parts.d.ts +23 -0
- package/dist/ui-parts.js +385 -0
- package/dist/ui-resolve.d.ts +35 -0
- package/dist/ui-resolve.js +42 -0
- package/dist/ui-slots.d.ts +65 -0
- package/dist/ui-slots.js +261 -0
- package/dist/ui.d.ts +245 -77
- package/dist/ui.js +104 -27
- package/dist/url.d.ts +4 -1
- package/dist/url.js +4 -1
- package/dist/web.d.ts +26 -20
- package/package.json +12 -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.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The aspect ratios a caller may ask for instead of an exact size. */
|
|
2
|
+
export const IMAGE_ASPECT_RATIOS = ["1:1", "4:3", "3:4", "3:2", "2:3", "16:9", "9:16"];
|
|
3
|
+
/** Types accepted by image blocks. */
|
|
2
4
|
export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
3
|
-
/**
|
|
5
|
+
/** Types accepted by document blocks. */
|
|
4
6
|
export const DOCUMENT_MEDIA_TYPES = [
|
|
5
7
|
"application/pdf",
|
|
6
8
|
"text/plain",
|
|
7
9
|
"text/markdown",
|
|
8
10
|
"text/csv",
|
|
9
11
|
];
|
|
10
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Upper bound on the decoded bytes of a single media block (the smaller value among mainstream
|
|
14
|
+
* vendors).
|
|
15
|
+
*/
|
|
11
16
|
export const MEDIA_LIMITS = { imageBytes: 5_242_880, documentBytes: 33_554_432 };
|
|
12
17
|
const B64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
13
18
|
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
|
-
/**
|
|
19
|
+
/** Maximum length (characters) of a media block's `name`. */
|
|
15
20
|
export const MEDIA_NAME_MAX_CHARS = 255;
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Suggested upper bound (code points) for file names / titles in vendor requests, the default of
|
|
23
|
+
* {@link clipMediaName}.
|
|
24
|
+
*/
|
|
17
25
|
export const PROVIDER_MEDIA_NAME_MAX = 200;
|
|
18
26
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
27
|
+
* Truncates an attachment name to at most `max` code points (for vendor mapping: some APIs limit
|
|
28
|
+
* filename / title length, and adding a suffix makes it longer still).
|
|
29
|
+
* Keeps the extension where possible (a `.ext` of at most 16 characters), with `…` marking the cut
|
|
30
|
+
* part in the middle. A pure function.
|
|
21
31
|
*/
|
|
22
32
|
export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
|
|
23
33
|
const cps = [...name];
|
|
@@ -29,7 +39,7 @@ export function clipMediaName(name, max = PROVIDER_MEDIA_NAME_MAX) {
|
|
|
29
39
|
const head = cps.slice(0, max - 1 - keep.length);
|
|
30
40
|
return `${head.join("")}…${keep.join("")}`;
|
|
31
41
|
}
|
|
32
|
-
/**
|
|
42
|
+
/** Whether it contains control characters (C0, DEL and C1). */
|
|
33
43
|
export function hasControlChars(s) {
|
|
34
44
|
for (let i = 0; i < s.length; i++) {
|
|
35
45
|
const c = s.charCodeAt(i);
|
|
@@ -38,18 +48,26 @@ export function hasControlChars(s) {
|
|
|
38
48
|
}
|
|
39
49
|
return false;
|
|
40
50
|
}
|
|
41
|
-
/**
|
|
51
|
+
/** Whether the attachment id is a UUID (any version, case-insensitive). */
|
|
42
52
|
export function isAttachmentId(s) {
|
|
43
53
|
return typeof s === "string" && UUID_RE.test(s);
|
|
44
54
|
}
|
|
55
|
+
/** Any non-empty `type/subtype` (a `file` block's `mediaType`). */
|
|
56
|
+
const MEDIA_TYPE_RE = /^[^/\s]+\/[^/\s]+$/;
|
|
45
57
|
const MEDIA = {
|
|
46
58
|
image: { types: IMAGE_MEDIA_TYPES, limit: MEDIA_LIMITS.imageBytes },
|
|
47
59
|
document: { types: DOCUMENT_MEDIA_TYPES, limit: MEDIA_LIMITS.documentBytes },
|
|
60
|
+
// A file the model cannot read: the kernel resolves it to text before the request, so no media
|
|
61
|
+
// type list applies. The byte ceiling is the one attachments already have.
|
|
62
|
+
file: { types: [], limit: MEDIA_LIMITS.documentBytes, anyType: true },
|
|
48
63
|
};
|
|
49
64
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
65
|
+
* Validates an image / document / file block, returning a list of errors (empty means valid): the
|
|
66
|
+
* media type is in the block kind's list (`file` accepts any non-empty `type/subtype`); `base64` is
|
|
67
|
+
* standard, padded, whitespace-free base64 that decodes to at most {@link MEDIA_LIMITS}; a `ref`'s
|
|
68
|
+
* `attachmentId` is a UUID; `name`, when present, is a string of at most
|
|
69
|
+
* {@link MEDIA_NAME_MAX_CHARS} characters with no control characters; `size`, when present, is a
|
|
70
|
+
* non-negative integer (display metadata, never sent by a plugin).
|
|
53
71
|
*/
|
|
54
72
|
export function validateMediaBlock(b) {
|
|
55
73
|
if (typeof b !== "object" || b === null || Array.isArray(b))
|
|
@@ -57,9 +75,16 @@ export function validateMediaBlock(b) {
|
|
|
57
75
|
const o = b;
|
|
58
76
|
const spec = typeof o.type === "string" && Object.hasOwn(MEDIA, o.type) ? MEDIA[o.type] : undefined;
|
|
59
77
|
if (!spec)
|
|
60
|
-
return ['block type must be "image" or "
|
|
78
|
+
return ['block type must be "image", "document" or "file"'];
|
|
61
79
|
const errs = [];
|
|
62
|
-
if (
|
|
80
|
+
if (spec.anyType) {
|
|
81
|
+
if (typeof o.mediaType !== "string" ||
|
|
82
|
+
!MEDIA_TYPE_RE.test(o.mediaType) ||
|
|
83
|
+
hasControlChars(o.mediaType)) {
|
|
84
|
+
errs.push(`${o.type} mediaType must be a non-empty type/subtype string`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (typeof o.mediaType !== "string" || !spec.types.includes(o.mediaType)) {
|
|
63
88
|
errs.push(`${o.type} mediaType must be one of ${spec.types.join(", ")}`);
|
|
64
89
|
}
|
|
65
90
|
if (o.name !== undefined) {
|
|
@@ -72,6 +97,10 @@ export function validateMediaBlock(b) {
|
|
|
72
97
|
errs.push(`${o.type} name must not contain control characters`);
|
|
73
98
|
}
|
|
74
99
|
}
|
|
100
|
+
if (o.size !== undefined &&
|
|
101
|
+
(typeof o.size !== "number" || !Number.isInteger(o.size) || o.size < 0)) {
|
|
102
|
+
errs.push(`${o.type} size must be a non-negative integer`);
|
|
103
|
+
}
|
|
75
104
|
const src = o.source;
|
|
76
105
|
if (typeof src !== "object" || src === null) {
|
|
77
106
|
errs.push(`${o.type} source must be an object`);
|
|
@@ -89,7 +118,8 @@ export function validateMediaBlock(b) {
|
|
|
89
118
|
errs.push(`${o.type} source.data must be non-empty padded base64`);
|
|
90
119
|
return errs;
|
|
91
120
|
}
|
|
92
|
-
//
|
|
121
|
+
// Compute the decoded size from the length first; when over the limit, skip the per-character
|
|
122
|
+
// validation
|
|
93
123
|
const pad = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
|
|
94
124
|
const bytes = (data.length / 4) * 3 - pad;
|
|
95
125
|
if (bytes > spec.limit) {
|
|
@@ -113,6 +143,7 @@ const ALL_KINDS = new Set([
|
|
|
113
143
|
"auth",
|
|
114
144
|
"invalid_request",
|
|
115
145
|
"context_overflow",
|
|
146
|
+
"refusal",
|
|
116
147
|
"aborted",
|
|
117
148
|
]);
|
|
118
149
|
const RETRYABLE = new Set([
|
|
@@ -122,11 +153,13 @@ const RETRYABLE = new Set([
|
|
|
122
153
|
"timeout",
|
|
123
154
|
"network",
|
|
124
155
|
]);
|
|
125
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
156
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
126
157
|
export function isRetryableKind(kind) {
|
|
127
158
|
return RETRYABLE.has(kind);
|
|
128
159
|
}
|
|
129
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Duck-typed check (no instanceof), compatible with a plugin bundling another copy of plugin-sdk.
|
|
162
|
+
*/
|
|
130
163
|
export function isModelError(e) {
|
|
131
164
|
if (!(e instanceof Error))
|
|
132
165
|
return false;
|
|
@@ -143,7 +176,7 @@ export class ModelError extends Error {
|
|
|
143
176
|
if (opts?.retryAfterMs !== undefined)
|
|
144
177
|
this.retryAfterMs = opts.retryAfterMs;
|
|
145
178
|
}
|
|
146
|
-
/** rate_limited / overloaded / server / timeout / network
|
|
179
|
+
/** True for rate_limited / overloaded / server / timeout / network. */
|
|
147
180
|
get retryable() {
|
|
148
181
|
return isRetryableKind(this.kind);
|
|
149
182
|
}
|
|
@@ -170,5 +203,105 @@ export function validateEmbedResult(req, info, res) {
|
|
|
170
203
|
}
|
|
171
204
|
return null;
|
|
172
205
|
}
|
|
173
|
-
|
|
206
|
+
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
207
|
+
/** True when `x` is a well-formed {@link ModelImageGenerationInfo}. */
|
|
208
|
+
export function isValidImageGenerationInfo(x) {
|
|
209
|
+
if (typeof x !== "object" || x === null)
|
|
210
|
+
return false;
|
|
211
|
+
const o = x;
|
|
212
|
+
const isSize = (s) => typeof s === "object" &&
|
|
213
|
+
s !== null &&
|
|
214
|
+
Number.isInteger(s.width) &&
|
|
215
|
+
Number.isInteger(s.height) &&
|
|
216
|
+
s.width > 0 &&
|
|
217
|
+
s.height > 0;
|
|
218
|
+
if (!Array.isArray(o.sizes) || o.sizes.length === 0 || !o.sizes.every(isSize))
|
|
219
|
+
return false;
|
|
220
|
+
if (!isSize(o.defaultSize))
|
|
221
|
+
return false;
|
|
222
|
+
const d = o.defaultSize;
|
|
223
|
+
if (!o.sizes.some((s) => s.width === d.width && s.height === d.height))
|
|
224
|
+
return false;
|
|
225
|
+
if (!Number.isInteger(o.maxImages) || o.maxImages < 1)
|
|
226
|
+
return false;
|
|
227
|
+
if (!Number.isInteger(o.maxReferenceImages) || o.maxReferenceImages < 0) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return (Array.isArray(o.outputMediaTypes) &&
|
|
231
|
+
o.outputMediaTypes.length > 0 &&
|
|
232
|
+
o.outputMediaTypes.every((t) => IMAGE_MEDIA_TYPES.includes(t)));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Checks an image generation result against its request and the model's facts. Returns null when
|
|
236
|
+
* valid, else the reason: wrong image count, an undeclared media type, data that is not base64,
|
|
237
|
+
* or a `usage` that is not an object whose token counts (and `outputImages`, when present) are
|
|
238
|
+
* non-negative integers (a caller records usage from it, so it is checked before anything is).
|
|
239
|
+
*/
|
|
240
|
+
export function validateImageGenerateResult(req, info, res) {
|
|
241
|
+
const images = res?.images;
|
|
242
|
+
if (!Array.isArray(images))
|
|
243
|
+
return "result has no images array";
|
|
244
|
+
if (images.length !== req.n)
|
|
245
|
+
return `expected ${req.n} images, got ${images.length}`;
|
|
246
|
+
for (let i = 0; i < images.length; i++) {
|
|
247
|
+
const img = images[i];
|
|
248
|
+
const type = img?.mediaType;
|
|
249
|
+
if (typeof type !== "string" || !info.outputMediaTypes.includes(type)) {
|
|
250
|
+
return `image ${i} has media type ${String(type)}, not one of ${info.outputMediaTypes.join(", ")}`;
|
|
251
|
+
}
|
|
252
|
+
if (typeof img?.data !== "string" || !BASE64.test(img.data)) {
|
|
253
|
+
return `image ${i} data is not base64`;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const usage = res.usage;
|
|
257
|
+
if (typeof usage !== "object" || usage === null)
|
|
258
|
+
return "result has no usage object";
|
|
259
|
+
const u = usage;
|
|
260
|
+
const count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
|
|
261
|
+
for (const field of ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"]) {
|
|
262
|
+
if (!count(u[field]))
|
|
263
|
+
return `usage.${field} is ${String(u[field])}, not a non-negative integer`;
|
|
264
|
+
}
|
|
265
|
+
if (u.outputImages !== undefined && !count(u.outputImages)) {
|
|
266
|
+
return `usage.outputImages is ${String(u.outputImages)}, not a non-negative integer`;
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Chooses an output size: an exact `size` must be one the model offers; an `aspectRatio` picks the
|
|
272
|
+
* closest declared ratio (ties by area closest to the default's, then declaration order); neither
|
|
273
|
+
* gives the default size.
|
|
274
|
+
*/
|
|
275
|
+
export function pickImageSize(info, opts) {
|
|
276
|
+
const fmt = (s) => `${s.width}x${s.height}`;
|
|
277
|
+
const { size, aspectRatio } = opts;
|
|
278
|
+
if (size) {
|
|
279
|
+
const hit = info.sizes.find((s) => s.width === size.width && s.height === size.height);
|
|
280
|
+
if (hit)
|
|
281
|
+
return { ok: true, size: hit };
|
|
282
|
+
return {
|
|
283
|
+
ok: false,
|
|
284
|
+
error: `Size ${fmt(size)} is not offered by this model; use one of ${info.sizes.map(fmt).join(", ")}.`,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
if (!aspectRatio)
|
|
288
|
+
return { ok: true, size: info.defaultSize };
|
|
289
|
+
const [rw, rh] = aspectRatio.split(":").map(Number);
|
|
290
|
+
const target = Math.log(rw / rh);
|
|
291
|
+
const area = info.defaultSize.width * info.defaultSize.height;
|
|
292
|
+
let best = info.defaultSize;
|
|
293
|
+
let bestDiff = Number.POSITIVE_INFINITY;
|
|
294
|
+
let bestArea = Number.POSITIVE_INFINITY;
|
|
295
|
+
for (const s of info.sizes) {
|
|
296
|
+
const diff = Math.abs(Math.log(s.width / s.height) - target);
|
|
297
|
+
const areaDiff = Math.abs(s.width * s.height - area);
|
|
298
|
+
if (diff < bestDiff - 1e-9 || (Math.abs(diff - bestDiff) <= 1e-9 && areaDiff < bestArea)) {
|
|
299
|
+
best = s;
|
|
300
|
+
bestDiff = diff;
|
|
301
|
+
bestArea = areaDiff;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { ok: true, size: best };
|
|
305
|
+
}
|
|
306
|
+
/** The model provider extension point (the only version since `@1` was removed before 0.1.0). */
|
|
174
307
|
export const MODEL_PROVIDER_EXTENSION_POINT_V2 = "model-provider@2";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing text of a failed native file operation (#907), one mapping for every native
|
|
3
|
+
* helper and provider (capybara-device, device-docker, device-e2b). A native helper answers
|
|
4
|
+
* `{ error: { code } }` with an errno name (`ENOENT`, …), `SCOPE_DENIED`, `NOT_REGULAR_FILE` or
|
|
5
|
+
* `INVALID_NATIVE_REQUEST`; its own exception text never reaches the model (it may carry paths or
|
|
6
|
+
* other details), only the kernel-defined text for the code.
|
|
7
|
+
*/
|
|
8
|
+
/** The code a native helper answers when a read or write names something other than a regular file. */
|
|
9
|
+
export declare const NATIVE_NOT_REGULAR_FILE = "NOT_REGULAR_FILE";
|
|
10
|
+
/** The text for a code this mapping does not know. */
|
|
11
|
+
export declare const NATIVE_FAILURE_GENERIC = "Native operation failed; check the path, scope and filesystem access";
|
|
12
|
+
/** The model-facing text for a native helper's error code. */
|
|
13
|
+
export declare function nativeFailureText(code: string | undefined): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing text of a failed native file operation (#907), one mapping for every native
|
|
3
|
+
* helper and provider (capybara-device, device-docker, device-e2b). A native helper answers
|
|
4
|
+
* `{ error: { code } }` with an errno name (`ENOENT`, …), `SCOPE_DENIED`, `NOT_REGULAR_FILE` or
|
|
5
|
+
* `INVALID_NATIVE_REQUEST`; its own exception text never reaches the model (it may carry paths or
|
|
6
|
+
* other details), only the kernel-defined text for the code.
|
|
7
|
+
*/
|
|
8
|
+
/** The code a native helper answers when a read or write names something other than a regular file. */
|
|
9
|
+
export const NATIVE_NOT_REGULAR_FILE = "NOT_REGULAR_FILE";
|
|
10
|
+
/** The text for a code this mapping does not know. */
|
|
11
|
+
export const NATIVE_FAILURE_GENERIC = "Native operation failed; check the path, scope and filesystem access";
|
|
12
|
+
const TEXTS = {
|
|
13
|
+
[NATIVE_NOT_REGULAR_FILE]: "The path is not a regular file (it is a directory, a device or another special file); only regular files can be read or written",
|
|
14
|
+
ENOENT: "The path, or one of its parent directories, does not exist; check the path",
|
|
15
|
+
ENOTDIR: "A component of the path is not a directory; check the path",
|
|
16
|
+
EISDIR: "The path is a directory, not a file",
|
|
17
|
+
EEXIST: "The path already exists",
|
|
18
|
+
ENAMETOOLONG: "The path is too long",
|
|
19
|
+
ENOSPC: "The device's disk is full; free some space, then retry",
|
|
20
|
+
EDQUOT: "The device's disk quota is exhausted; free some space, then retry",
|
|
21
|
+
EROFS: "The path is on a read-only file system",
|
|
22
|
+
EFBIG: "The file is too large for the device's file system",
|
|
23
|
+
EBUSY: "The file is busy; retry the call",
|
|
24
|
+
ESTALE: "The file changed while it was being used; retry the call",
|
|
25
|
+
EIO: "The device's disk reported an input/output error",
|
|
26
|
+
};
|
|
27
|
+
/** The model-facing text for a native helper's error code. */
|
|
28
|
+
export function nativeFailureText(code) {
|
|
29
|
+
return ((code !== undefined && Object.hasOwn(TEXTS, code) ? TEXTS[code] : undefined) ??
|
|
30
|
+
NATIVE_FAILURE_GENERIC);
|
|
31
|
+
}
|
package/dist/net.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarded outbound HTTP for URLs a person supplied (`ctx.net`).
|
|
3
|
+
*
|
|
4
|
+
* Rule: a request whose host comes from a person or from config an org admin or member can set (a
|
|
5
|
+
* connector endpoint, an org-overridable base URL) goes through `ctx.net.fetch`, never the global
|
|
6
|
+
* `fetch`; a fixed vendor host, or a URL only the super admin can set, may keep `fetch`.
|
|
7
|
+
*/
|
|
8
|
+
/** Why `ctx.net.fetch` refused a request (the codes of the kernel's guarded client). */
|
|
9
|
+
export type NetDeniedCode = "net.insecure_url" | "net.private_address" | "net.dns_failed" | "net.redirect" | "net.proxy_refused";
|
|
10
|
+
/**
|
|
11
|
+
* The request was refused by the kernel's network rules; `message` is English and names `host`.
|
|
12
|
+
* Detect it with {@link isNetDeniedError} (by `name`), never `instanceof`, which fails across
|
|
13
|
+
* package copies. Map it to the plugin's own actionable error (a connector's `ToolError`, a
|
|
14
|
+
* provider's `ModelError` of kind `invalid_request`).
|
|
15
|
+
*/
|
|
16
|
+
export declare class NetDeniedError extends Error {
|
|
17
|
+
readonly code: NetDeniedCode;
|
|
18
|
+
readonly host: string;
|
|
19
|
+
/** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
|
|
20
|
+
readonly status?: number | undefined;
|
|
21
|
+
readonly name: "NetDeniedError";
|
|
22
|
+
constructor(code: NetDeniedCode, host: string, message: string,
|
|
23
|
+
/** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
|
|
24
|
+
status?: number | undefined);
|
|
25
|
+
}
|
|
26
|
+
/** True for a {@link NetDeniedError} from any copy of the SDK or the kernel (checked by `name`). */
|
|
27
|
+
export declare function isNetDeniedError(e: unknown): e is NetDeniedError;
|
|
28
|
+
/**
|
|
29
|
+
* `ctx.net`: the kernel's guarded HTTP client, no permission needed. It needs a kernel that ships
|
|
30
|
+
* it: a plugin that calls it raises its manifest's minimum `sdk` to the SDK release that added it.
|
|
31
|
+
*/
|
|
32
|
+
export interface ExtensionNet {
|
|
33
|
+
/**
|
|
34
|
+
* The global `fetch` signature with the kernel's network rules applied: https only, except plain
|
|
35
|
+
* http to an origin `http://host:port` a super admin allowed for `opts.orgId`, and to loopback
|
|
36
|
+
* under the kernel's tests-only `net.allowInsecureLoopback`; private, loopback and link-local
|
|
37
|
+
* addresses refused (link-local always), the address checked when the connection is made (no
|
|
38
|
+
* DNS-rebinding window); the deployment's egress proxy honoured. An http URL to a host the org
|
|
39
|
+
* allows only as a hostname entry (https only) is refused with a message that names the
|
|
40
|
+
* `http://host:port` origin entry which would allow it. Redirects
|
|
41
|
+
* are never followed: with `redirect: "manual"` a 3xx response is returned as is, otherwise a 3xx
|
|
42
|
+
* rejects with `net.redirect`. Bodies stream; no size cap. `init.signal` is combined with
|
|
43
|
+
* `ctx.signal`.
|
|
44
|
+
*
|
|
45
|
+
* `opts.orgId` is the org the request is made for (e.g. `ConnectorOpenArgs.orgId`): only then may
|
|
46
|
+
* the target be one of the internal endpoints a super admin allowed for that org. Without it only
|
|
47
|
+
* public addresses are reachable. A refusal rejects with {@link NetDeniedError}.
|
|
48
|
+
*/
|
|
49
|
+
fetch(url: string, init?: RequestInit, opts?: {
|
|
50
|
+
orgId?: string;
|
|
51
|
+
}): Promise<Response>;
|
|
52
|
+
}
|
package/dist/net.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarded outbound HTTP for URLs a person supplied (`ctx.net`).
|
|
3
|
+
*
|
|
4
|
+
* Rule: a request whose host comes from a person or from config an org admin or member can set (a
|
|
5
|
+
* connector endpoint, an org-overridable base URL) goes through `ctx.net.fetch`, never the global
|
|
6
|
+
* `fetch`; a fixed vendor host, or a URL only the super admin can set, may keep `fetch`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The request was refused by the kernel's network rules; `message` is English and names `host`.
|
|
10
|
+
* Detect it with {@link isNetDeniedError} (by `name`), never `instanceof`, which fails across
|
|
11
|
+
* package copies. Map it to the plugin's own actionable error (a connector's `ToolError`, a
|
|
12
|
+
* provider's `ModelError` of kind `invalid_request`).
|
|
13
|
+
*/
|
|
14
|
+
export class NetDeniedError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
host;
|
|
17
|
+
status;
|
|
18
|
+
name = "NetDeniedError";
|
|
19
|
+
constructor(code, host, message,
|
|
20
|
+
/** The HTTP status of a refused redirect (`net.redirect`); absent for the other codes. */
|
|
21
|
+
status) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.host = host;
|
|
25
|
+
this.status = status;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** True for a {@link NetDeniedError} from any copy of the SDK or the kernel (checked by `name`). */
|
|
29
|
+
export function isNetDeniedError(e) {
|
|
30
|
+
if (typeof e !== "object" || e === null)
|
|
31
|
+
return false;
|
|
32
|
+
const o = e;
|
|
33
|
+
return o.name === "NetDeniedError" && typeof o.code === "string" && typeof o.host === "string";
|
|
34
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address classes of the sandbox network (approval-only profiles design, "Open network"): pure
|
|
3
|
+
* data plus {@link classifyAddress}. The device workers (macOS SRT, the Linux forwarder) and the
|
|
4
|
+
* cloud providers' egress proxies decide every sandboxed connection on the resolved address with
|
|
5
|
+
* this one table, so the classes cannot drift between them.
|
|
6
|
+
*
|
|
7
|
+
* The table ({@link ADDRESS_CLASS_RANGES}) is data a copy in another language can mirror (the Linux
|
|
8
|
+
* forwarder's Python): the class of an address is that of the longest-prefix range containing it.
|
|
9
|
+
* Every family ends with a catch-all, so the table is total.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The class of one IP address.
|
|
13
|
+
*
|
|
14
|
+
* - `public`: globally routable; the only class open in `open-public` mode.
|
|
15
|
+
* - `private`: `10/8`, `172.16/12`, `192.168/16`.
|
|
16
|
+
* - `cgnat`: `100.64/10`.
|
|
17
|
+
* - `ula`: IPv6 unique local `fc00::/7` (except the metadata address).
|
|
18
|
+
* - `link-local`: `169.254/16` and `fe80::/10` (except the metadata addresses).
|
|
19
|
+
* - `metadata`: cloud metadata endpoints (`169.254.169.254`, `fd00:ec2::254`).
|
|
20
|
+
* - `loopback`: `127/8`, `::1`.
|
|
21
|
+
* - `multicast`, `broadcast`, `unspecified` (`0/8`, `::`), `nat64` (the NAT64 prefixes),
|
|
22
|
+
* `reserved` (every other special-purpose range).
|
|
23
|
+
*
|
|
24
|
+
* The host's own interface addresses are not a class of the table: the worker that knows them
|
|
25
|
+
* closes them in addition (a placeholder in the table test).
|
|
26
|
+
*/
|
|
27
|
+
export type AddressClass = "public" | "private" | "cgnat" | "ula" | "link-local" | "metadata" | "loopback" | "multicast" | "broadcast" | "unspecified" | "nat64" | "reserved";
|
|
28
|
+
/** Every class closed in `open-public` mode: reachable only by running outside the sandbox. */
|
|
29
|
+
export declare const OPEN_PUBLIC_DENIED_CLASSES: readonly AddressClass[];
|
|
30
|
+
/**
|
|
31
|
+
* One range of the address-class table. A range with `embeddedIpv4At` is an IPv6 form that carries
|
|
32
|
+
* an IPv4 address (v4-mapped, SIIT, v4-compatible, 6to4): the address classifies as the 32-bit IPv4
|
|
33
|
+
* address starting at that bit offset (from the most significant bit). The NAT64 prefixes are not
|
|
34
|
+
* such ranges: the design closes them whatever they embed.
|
|
35
|
+
*/
|
|
36
|
+
export type AddressClassRange = {
|
|
37
|
+
readonly family: "ipv4" | "ipv6";
|
|
38
|
+
/** `address/prefix`, the address in its canonical lower-case form. */
|
|
39
|
+
readonly cidr: string;
|
|
40
|
+
readonly class: AddressClass;
|
|
41
|
+
} | {
|
|
42
|
+
readonly family: "ipv6";
|
|
43
|
+
readonly cidr: string;
|
|
44
|
+
readonly embeddedIpv4At: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The address-class table, most specific range first within each family (longest prefix wins).
|
|
48
|
+
* IPv4 follows the kernel's `net/public-address.ts` (and the sandbox-docker egress proxy); IPv6
|
|
49
|
+
* does too, plus closures the design adds: the well-known NAT64 prefixes (`64:ff9b::/96`,
|
|
50
|
+
* `64:ff9b:1::/48`) whatever they embed, `2001::/23` (Teredo, ORCHID and the other IETF
|
|
51
|
+
* assignments), `3fff::/20`, and everything outside global unicast `2000::/3`.
|
|
52
|
+
*
|
|
53
|
+
* Not covered: an operator-specific NAT64 prefix (a network-specific prefix, RFC 6052, announced
|
|
54
|
+
* by the local DNS64) is ordinary global unicast here, so a private IPv4 address reached through
|
|
55
|
+
* it classifies as public. A worker on such a network resolves through a resolver it trusts or adds
|
|
56
|
+
* the prefix to its own deny list.
|
|
57
|
+
*/
|
|
58
|
+
export declare const ADDRESS_CLASS_RANGES: readonly AddressClassRange[];
|
|
59
|
+
/**
|
|
60
|
+
* Classifies one IPv4 or IPv6 address literal by {@link ADDRESS_CLASS_RANGES}. IPv6 may carry a
|
|
61
|
+
* zone (`fe80::1%en0`) and a trailing dotted IPv4 address; an IPv6 form that embeds an IPv4 address
|
|
62
|
+
* (v4-mapped and the others in the table) classifies as that IPv4 address, except NAT64. Throws on a
|
|
63
|
+
* string that is not an IP address: brackets, ports, short, octal or hex IPv4 forms, and an IPv4
|
|
64
|
+
* address with a zone.
|
|
65
|
+
*/
|
|
66
|
+
export declare function classifyAddress(ip: string): AddressClass;
|
|
67
|
+
/**
|
|
68
|
+
* Every address closed in `open-public` mode as one CIDR list (IPv4, then IPv6), computed from
|
|
69
|
+
* {@link ADDRESS_CLASS_RANGES}: for a consumer that can only deny ranges (the macOS runtime's
|
|
70
|
+
* resolved-address deny list). Embedded forms are expanded (the v4-mapped, SIIT, v4-compatible and
|
|
71
|
+
* 6to4 sub-ranges of every closed IPv4 range), and adjacent closed blocks are merged. An address
|
|
72
|
+
* is in a listed CIDR exactly when {@link classifyAddress} gives it a closed class.
|
|
73
|
+
*/
|
|
74
|
+
export declare const OPEN_PUBLIC_DENIED_CIDRS: readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
* Encrypted DNS for a network whose resolver answers with fake IPs (maintainer decision
|
|
77
|
+
* 2026-11-19): a router running a fake-IP proxy (OpenClash and the like) intercepts every port-53
|
|
78
|
+
* query and answers each name with an address in {@link fakeIpCidr} (`198.18.0.0/15`, a reserved
|
|
79
|
+
* class), so in open mode every name would resolve to a closed address. When the system
|
|
80
|
+
* resolver's answer for a name contains such an address, a sandbox egress proxy re-resolves the
|
|
81
|
+
* name (A and AAAA) through DNS-over-HTTPS (RFC 8484, GET, wire format) at these IP-literal
|
|
82
|
+
* endpoints, in order (Cloudflare, then Google as the fallback), verifying TLS against the
|
|
83
|
+
* endpoint's IP SAN so no DNS is needed to reach them. {@link timeoutMs} is one overall deadline
|
|
84
|
+
* per name, covering A and AAAA and every endpoint; each endpoint gets its share of the time left.
|
|
85
|
+
* An answer is cached only when both queries succeeded, for its TTL, at most
|
|
86
|
+
* {@link cacheTtlCapSeconds}, and for at most {@link cacheMaxNames} names. The real address is
|
|
87
|
+
* classified like any resolved address and dialled as checked. When encrypted DNS fails the
|
|
88
|
+
* connection is refused, naming the fake-IP resolver; the fake address is never dialled. The same
|
|
89
|
+
* rule applies to an allowlisted name. Shared by the macOS worker and the Linux forwarder, so both
|
|
90
|
+
* keep identical endpoints and limits.
|
|
91
|
+
*/
|
|
92
|
+
export declare const SANDBOX_FAKE_IP_DNS: {
|
|
93
|
+
readonly fakeIpCidr: string;
|
|
94
|
+
readonly endpoints: readonly string[];
|
|
95
|
+
readonly timeoutMs: number;
|
|
96
|
+
readonly cacheTtlCapSeconds: number;
|
|
97
|
+
readonly cacheMaxNames: number;
|
|
98
|
+
};
|