@constal/sdk 6.10.0 → 6.12.0
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/package.json +1 -1
- package/publish/api.json +42 -26
- package/publish/index.d.ts +571 -338
- package/publish/index.js +296 -302
package/publish/index.js
CHANGED
|
@@ -563,47 +563,48 @@ var casTool = {
|
|
|
563
563
|
};
|
|
564
564
|
|
|
565
565
|
// packages/sdk/src/skills.ts
|
|
566
|
-
async function required(
|
|
567
|
-
const result = timeoutMs === void 0 ? await
|
|
568
|
-
if (result.
|
|
569
|
-
throw new Error(`Copying skill ${skill} into the
|
|
566
|
+
async function required(sandbox, skill, cmd, args, timeoutMs) {
|
|
567
|
+
const result = timeoutMs === void 0 ? await sandbox.exec({ cmd, args }) : await sandbox.exec({ cmd, args, timeoutMs }, { timeoutMs });
|
|
568
|
+
if (result.state !== "exited" || result.exitCode !== 0) {
|
|
569
|
+
throw new Error(`Copying skill ${skill} into the sandbox failed: ${cmd} ended ${result.state} with exit code ${result.exitCode}. ${result.stderr}`);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
|
-
function skills(binding = "skills",
|
|
572
|
+
function skills(binding = "skills", pool = "sandbox") {
|
|
573
573
|
const prefix = binding.replaceAll(/[.-]/gu, "_");
|
|
574
574
|
const find = opTool(binding, "find", { name: `${prefix}_find` });
|
|
575
575
|
const read = opTool(binding, "read", { name: `${prefix}_read` });
|
|
576
576
|
const run = {
|
|
577
577
|
name: `${prefix}_run`,
|
|
578
|
-
version: "
|
|
579
|
-
description: "Runs one command in
|
|
580
|
-
schema: { type: "object", required: ["skill", "cmd"], additionalProperties: false, properties: {
|
|
578
|
+
version: "2",
|
|
579
|
+
description: "Runs one command in a sandbox with its working directory set to a copy of a skill's folder, which holds the skill's SKILL.md and every file it bundles. Returns the folder's path and the command's result: its state, exit code and output.",
|
|
580
|
+
schema: { type: "object", required: ["skill", "sandbox", "cmd"], additionalProperties: false, properties: {
|
|
581
581
|
skill: { type: "string", minLength: 1, description: "The skill's name." },
|
|
582
|
+
sandbox: { type: "string", minLength: 1, description: "The id of the running sandbox to run it in." },
|
|
582
583
|
cmd: { type: "string", minLength: 1, description: "The program to run." },
|
|
583
584
|
args: { type: "array", items: { type: "string" }, description: "The program's arguments." },
|
|
584
585
|
env: { type: "object", additionalProperties: { type: "string" }, description: "Environment variables for the command." },
|
|
585
586
|
stdin: { type: "string", description: "Text the command reads on its standard input." },
|
|
586
|
-
timeoutMs: { type: "integer", minimum: 1, description: "How long each command may run, in milliseconds: the program, and each command that copies the skill's folder into the
|
|
587
|
+
timeoutMs: { type: "integer", minimum: 1, description: "How long each command may run, in milliseconds: the program, and each command that copies the skill's folder into the sandbox." }
|
|
587
588
|
} },
|
|
588
589
|
maxEffect: "reconcilable",
|
|
589
|
-
needs: [{ binding, kind: "skills", ops: ["bundle"] }, { binding:
|
|
590
|
+
needs: [{ binding, kind: "skills", ops: ["bundle"] }, { binding: pool, kind: "sandbox-pool", ops: ["exec", "writeFile"] }],
|
|
590
591
|
async run(args, ctx) {
|
|
591
592
|
const { ref } = await ctx.invoke(ctx.resources[binding], "bundle", { skill: args.skill });
|
|
592
|
-
const
|
|
593
|
+
const sandbox = ctx.sandboxPool(ctx.resources[pool]).sandbox(args.sandbox);
|
|
593
594
|
const path2 = `/workspace/skills/${ref}`;
|
|
594
595
|
const bound = args.timeoutMs === void 0 ? void 0 : { timeoutMs: args.timeoutMs };
|
|
595
|
-
const present = await
|
|
596
|
-
if (present.
|
|
596
|
+
const present = await sandbox.exec({ cmd: "test", args: ["-e", path2], ...bound }, bound);
|
|
597
|
+
if (present.state !== "exited" || present.exitCode !== 0) {
|
|
597
598
|
const archive = `/workspace/.constal/imports/${ref}.tar.gz`;
|
|
598
599
|
const staging = `/workspace/.constal/staging/${ref}`;
|
|
599
|
-
await required(
|
|
600
|
-
await
|
|
601
|
-
await required(
|
|
602
|
-
await required(
|
|
603
|
-
await required(
|
|
600
|
+
await required(sandbox, args.skill, "mkdir", ["-p", "--", "/workspace/.constal/imports", staging, "/workspace/skills"], args.timeoutMs);
|
|
601
|
+
await sandbox.writeFile(archive, { ref }, bound);
|
|
602
|
+
await required(sandbox, args.skill, "tar", ["-xzf", archive, "-C", staging, "--no-same-owner", "--no-same-permissions"], args.timeoutMs);
|
|
603
|
+
await required(sandbox, args.skill, "mv", ["--", staging, path2], args.timeoutMs);
|
|
604
|
+
await required(sandbox, args.skill, "rm", ["-f", "--", archive], args.timeoutMs);
|
|
604
605
|
}
|
|
605
|
-
const { skill: _skill, ...command } = args;
|
|
606
|
-
return { path: path2, ...await
|
|
606
|
+
const { skill: _skill, sandbox: _sandbox, ...command } = args;
|
|
607
|
+
return { path: path2, ...await sandbox.exec({ ...command, cwd: path2 }, bound) };
|
|
607
608
|
}
|
|
608
609
|
};
|
|
609
610
|
return { [find.name]: find, [read.name]: read, [run.name]: run };
|
|
@@ -1420,16 +1421,6 @@ function normalizeSandboxNetworkPolicy(value, options = {}) {
|
|
|
1420
1421
|
if (Object.keys(input).some((key) => key !== "mode" && key !== "domains")) throw new TypeError("sandbox network policy has unexpected fields");
|
|
1421
1422
|
return { mode: "domain-allow", domains: normalizeDomains(input.domains) };
|
|
1422
1423
|
}
|
|
1423
|
-
if (input.mode === "managed-http") {
|
|
1424
|
-
if (input.transport !== "bridge" && input.transport !== "proxy") throw new TypeError("sandbox managed HTTP transport is invalid");
|
|
1425
|
-
if (typeof input.egress !== "string" || parseResourceName(input.egress).kind !== "service") throw new TypeError("sandbox managed HTTP egress must be a Service CRN");
|
|
1426
|
-
if (input.transport === "bridge") {
|
|
1427
|
-
if (Object.keys(input).some((key) => !["mode", "transport", "egress"].includes(key))) throw new TypeError("sandbox network policy has unexpected fields");
|
|
1428
|
-
return { mode: "managed-http", transport: "bridge", egress: input.egress };
|
|
1429
|
-
}
|
|
1430
|
-
if (Object.keys(input).some((key) => !["mode", "transport", "egress", "domains"].includes(key))) throw new TypeError("sandbox network policy has unexpected fields");
|
|
1431
|
-
return { mode: "managed-http", transport: "proxy", egress: input.egress, domains: normalizeDomains(input.domains) };
|
|
1432
|
-
}
|
|
1433
1424
|
throw new TypeError("sandbox network policy mode is invalid");
|
|
1434
1425
|
}
|
|
1435
1426
|
|
|
@@ -2376,8 +2367,8 @@ var CONSTAL_API_OPERATION_SCHEMAS = {
|
|
|
2376
2367
|
// packages/sdk/src/sandbox-policy-contract.ts
|
|
2377
2368
|
var SANDBOX_CONTRACT_REF = {
|
|
2378
2369
|
id: "constal.sandbox-pool",
|
|
2379
|
-
version: "
|
|
2380
|
-
hash: "
|
|
2370
|
+
version: "3",
|
|
2371
|
+
hash: "6d987430d15960a25d3642b13997286b2b83d84f86db1c826630310b318708f4"
|
|
2381
2372
|
};
|
|
2382
2373
|
var SANDBOX_CONTROLS_SCHEMA = {
|
|
2383
2374
|
type: "object",
|
|
@@ -2386,15 +2377,11 @@ var SANDBOX_CONTROLS_SCHEMA = {
|
|
|
2386
2377
|
command_timeout_ms: { type: "integer", minimum: 1 },
|
|
2387
2378
|
cpu: { type: "number", exclusiveMinimum: 0 },
|
|
2388
2379
|
disk_gib: { type: "number", minimum: 0 },
|
|
2389
|
-
idle_stop_ms: { type: "integer", minimum: 1 },
|
|
2390
|
-
max_concurrent_commands: { type: "integer", minimum: 1 },
|
|
2391
2380
|
max_file_bytes: { type: "integer", minimum: 1 },
|
|
2392
2381
|
memory_gib: { type: "number", exclusiveMinimum: 0 },
|
|
2393
2382
|
network_cidrs: { type: "array", minItems: 1, items: { type: "string" } },
|
|
2394
2383
|
network_domains: { type: "array", minItems: 1, items: { type: "string" } },
|
|
2395
|
-
|
|
2396
|
-
network_mode: { enum: ["block-all", "cidr-allow", "domain-allow", "managed-http", "unrestricted"] },
|
|
2397
|
-
network_transport: { enum: [null, "bridge", "proxy"] },
|
|
2384
|
+
network_mode: { enum: ["block-all", "cidr-allow", "domain-allow", "unrestricted"] },
|
|
2398
2385
|
permitted_paths: { type: "array", minItems: 1, items: { type: "string" } }
|
|
2399
2386
|
}
|
|
2400
2387
|
};
|
|
@@ -2446,7 +2433,7 @@ function sandboxControls(values) {
|
|
|
2446
2433
|
return controls(SANDBOX_CONTRACT, values, sandboxSchema);
|
|
2447
2434
|
}
|
|
2448
2435
|
function sandboxLimit(input) {
|
|
2449
|
-
return limit(SANDBOX_CONTRACT, ["commands", "
|
|
2436
|
+
return limit(SANDBOX_CONTRACT, ["commands", "requests"], input);
|
|
2450
2437
|
}
|
|
2451
2438
|
function modelControls(values, contract = MODEL_CONTRACT) {
|
|
2452
2439
|
return controls(contract, values, modelSchema);
|
|
@@ -3492,271 +3479,37 @@ function chatParsed(value) {
|
|
|
3492
3479
|
return source;
|
|
3493
3480
|
}
|
|
3494
3481
|
|
|
3495
|
-
// packages/sdk/src/container-image.ts
|
|
3496
|
-
var REPOSITORY = /^[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*(?:\/[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*)*$/u;
|
|
3497
|
-
var TAG = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/u;
|
|
3498
|
-
var DIGEST = /^[a-z][a-z0-9+._-]*:[A-Za-z0-9=_-]+$/u;
|
|
3499
|
-
var SHA256 = /^sha256:[a-f0-9]{64}$/u;
|
|
3500
|
-
function containerImageReference(value) {
|
|
3501
|
-
if (typeof value !== "string" || !value || /[\s?#\\]/u.test(value) || value.includes("://")) throw new TypeError("container image reference is invalid");
|
|
3502
|
-
const components = value.split("@");
|
|
3503
|
-
if (components.length > 2) throw new TypeError("container image reference is invalid");
|
|
3504
|
-
let name = components[0];
|
|
3505
|
-
const digest = components[1] ?? null;
|
|
3506
|
-
if (digest !== null && (!DIGEST.test(digest) || digest.startsWith("sha256:") && !SHA256.test(digest))) {
|
|
3507
|
-
throw new TypeError("container image digest is invalid");
|
|
3508
|
-
}
|
|
3509
|
-
const separator = name.lastIndexOf(":"), slash = name.lastIndexOf("/");
|
|
3510
|
-
const tag = separator > slash ? name.slice(separator + 1) : null;
|
|
3511
|
-
if (tag !== null) {
|
|
3512
|
-
if (!TAG.test(tag)) throw new TypeError("container image tag is invalid");
|
|
3513
|
-
name = name.slice(0, separator);
|
|
3514
|
-
}
|
|
3515
|
-
const parts = name.split("/"), explicit = parts.length > 1 && (/[.:]/u.test(parts[0]) || parts[0] === "localhost");
|
|
3516
|
-
const registryInput = explicit ? parts.shift() : "docker.io";
|
|
3517
|
-
let registryUrl;
|
|
3518
|
-
try {
|
|
3519
|
-
registryUrl = new URL(`https://${registryInput}`);
|
|
3520
|
-
} catch {
|
|
3521
|
-
throw new TypeError("container image registry is invalid");
|
|
3522
|
-
}
|
|
3523
|
-
if (registryUrl.username || registryUrl.password || registryUrl.pathname !== "/" || !registryUrl.hostname) throw new TypeError("container image registry is invalid");
|
|
3524
|
-
const registry = registryUrl.host === "index.docker.io" ? "docker.io" : registryUrl.host;
|
|
3525
|
-
if (registry === "docker.io" && parts.length === 1) parts.unshift("library");
|
|
3526
|
-
const repository = parts.join("/");
|
|
3527
|
-
if (!REPOSITORY.test(repository)) throw new TypeError("container image repository is invalid");
|
|
3528
|
-
const selectedTag = tag ?? (digest === null ? "latest" : null);
|
|
3529
|
-
return {
|
|
3530
|
-
registry,
|
|
3531
|
-
repository,
|
|
3532
|
-
tag: selectedTag,
|
|
3533
|
-
digest,
|
|
3534
|
-
reference: `${registry}/${repository}${digest === null ? `:${selectedTag}` : `@${digest}`}`
|
|
3535
|
-
};
|
|
3536
|
-
}
|
|
3537
|
-
function immutableContainerImageReference(value) {
|
|
3538
|
-
const image = containerImageReference(value);
|
|
3539
|
-
if (!image.digest || !SHA256.test(image.digest)) throw new TypeError("container image must be resolved to a SHA-256 digest");
|
|
3540
|
-
return image;
|
|
3541
|
-
}
|
|
3542
|
-
function containerImageSource(value) {
|
|
3543
|
-
const source = value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3544
|
-
const platform = source?.platform && typeof source.platform === "object" && !Array.isArray(source.platform) ? source.platform : null;
|
|
3545
|
-
const image = typeof source?.reference === "string" ? immutableContainerImageReference(source.reference) : null;
|
|
3546
|
-
if (!source || !image || source.digest !== image.digest || typeof source.mediaType !== "string" || !source.mediaType || !Number.isSafeInteger(source.bytes) || Number(source.bytes) < 1 || !platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && (typeof platform.variant !== "string" || !platform.variant)) {
|
|
3547
|
-
throw new TypeError("container image source is invalid");
|
|
3548
|
-
}
|
|
3549
|
-
return structuredClone(source);
|
|
3550
|
-
}
|
|
3551
|
-
function containerImageSelection(value) {
|
|
3552
|
-
const selection = value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3553
|
-
const platform = selection?.platform && typeof selection.platform === "object" && !Array.isArray(selection.platform) ? selection.platform : null;
|
|
3554
|
-
const image = typeof selection?.reference === "string" ? immutableContainerImageReference(selection.reference) : null;
|
|
3555
|
-
if (!selection || !image || !platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && (typeof platform.variant !== "string" || !platform.variant) || Object.keys(selection).some((key) => key !== "reference" && key !== "platform") || Object.keys(platform).some((key) => key !== "os" && key !== "architecture" && key !== "variant")) {
|
|
3556
|
-
throw new TypeError("container image selection is invalid");
|
|
3557
|
-
}
|
|
3558
|
-
return { reference: image.reference, platform: structuredClone(platform) };
|
|
3559
|
-
}
|
|
3560
|
-
var OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json";
|
|
3561
|
-
var OCI_INDEX = "application/vnd.oci.image.index.v1+json";
|
|
3562
|
-
var DOCKER_MANIFEST = "application/vnd.docker.distribution.manifest.v2+json";
|
|
3563
|
-
var DOCKER_INDEX = "application/vnd.docker.distribution.manifest.list.v2+json";
|
|
3564
|
-
var ACCEPT = [OCI_MANIFEST, OCI_INDEX, DOCKER_MANIFEST, DOCKER_INDEX].join(", ");
|
|
3565
|
-
var MANIFEST_BYTES = 4194304;
|
|
3566
|
-
function object3(value) {
|
|
3567
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3568
|
-
}
|
|
3569
|
-
async function manifest(image, reference, request, authorization) {
|
|
3570
|
-
const response = await request({
|
|
3571
|
-
url: `https://${image.registry}/v2/${image.repository}/manifests/${encodeURIComponent(reference)}`,
|
|
3572
|
-
method: "GET",
|
|
3573
|
-
headers: { accept: ACCEPT, ...authorization ? { authorization } : {} },
|
|
3574
|
-
maximumBytes: MANIFEST_BYTES
|
|
3575
|
-
});
|
|
3576
|
-
if (response.status < 200 || response.status >= 300) throw Object.assign(new Error(`container registry manifest request returned ${response.status}`), { status: response.status });
|
|
3577
|
-
if (response.body.byteLength === 0 || response.body.byteLength > MANIFEST_BYTES) throw new TypeError("container registry manifest size is invalid");
|
|
3578
|
-
let value;
|
|
3579
|
-
try {
|
|
3580
|
-
value = object3(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(response.body)));
|
|
3581
|
-
} catch {
|
|
3582
|
-
value = null;
|
|
3583
|
-
}
|
|
3584
|
-
if (!value || value.schemaVersion !== 2) throw new TypeError("container registry manifest is invalid");
|
|
3585
|
-
const declared = typeof value.mediaType === "string" ? value.mediaType : response.headers["content-type"]?.split(";", 1)[0];
|
|
3586
|
-
if (![OCI_MANIFEST, OCI_INDEX, DOCKER_MANIFEST, DOCKER_INDEX].includes(String(declared))) throw new TypeError("container registry manifest media type is unsupported");
|
|
3587
|
-
const digest = `sha256:${await sha256Hex(response.body)}`;
|
|
3588
|
-
const header = response.headers["docker-content-digest"];
|
|
3589
|
-
if (header !== void 0 && header !== digest) throw new TypeError("container registry digest header differs from manifest bytes");
|
|
3590
|
-
return { value, mediaType: declared, digest };
|
|
3591
|
-
}
|
|
3592
|
-
async function resolveContainerImageSource(reference, platform, request, authorization) {
|
|
3593
|
-
const image = containerImageReference(reference);
|
|
3594
|
-
if (!platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && !platform.variant) throw new TypeError("container image platform is invalid");
|
|
3595
|
-
const requested = image.digest ?? image.tag;
|
|
3596
|
-
let selected = await manifest(image, requested, request, authorization);
|
|
3597
|
-
if (image.digest && selected.digest !== image.digest) throw new TypeError("container image digest does not match its manifest");
|
|
3598
|
-
if (selected.mediaType === OCI_INDEX || selected.mediaType === DOCKER_INDEX) {
|
|
3599
|
-
if (!Array.isArray(selected.value.manifests)) throw new TypeError("container image index has no manifests");
|
|
3600
|
-
const matches = selected.value.manifests.filter((raw) => {
|
|
3601
|
-
const item = object3(raw), target = object3(item?.platform);
|
|
3602
|
-
return item && target && target.os === platform.os && target.architecture === platform.architecture && (platform.variant === void 0 ? target.variant === void 0 : target.variant === platform.variant);
|
|
3603
|
-
}).map((item) => object3(item));
|
|
3604
|
-
if (matches.length !== 1 || typeof matches[0].digest !== "string" || !SHA256.test(matches[0].digest)) {
|
|
3605
|
-
throw new TypeError("container image index does not contain one exact requested platform");
|
|
3606
|
-
}
|
|
3607
|
-
selected = await manifest(image, matches[0].digest, request, authorization);
|
|
3608
|
-
if (selected.digest !== matches[0].digest) throw new TypeError("container image platform descriptor differs from its manifest");
|
|
3609
|
-
}
|
|
3610
|
-
if (selected.mediaType !== OCI_MANIFEST && selected.mediaType !== DOCKER_MANIFEST) throw new TypeError("container image did not resolve to an image manifest");
|
|
3611
|
-
const config = object3(selected.value.config), layers = selected.value.layers;
|
|
3612
|
-
if (!config || !Number.isSafeInteger(config.size) || Number(config.size) < 0 || !Array.isArray(layers) || layers.some((layer) => !object3(layer) || !Number.isSafeInteger(object3(layer).size) || Number(object3(layer).size) < 0)) {
|
|
3613
|
-
throw new TypeError("container image manifest descriptors are invalid");
|
|
3614
|
-
}
|
|
3615
|
-
const bytes = Number(config.size) + layers.reduce((sum, layer) => sum + Number(object3(layer).size), 0);
|
|
3616
|
-
return containerImageSource({
|
|
3617
|
-
reference: `${image.registry}/${image.repository}@${selected.digest}`,
|
|
3618
|
-
digest: selected.digest,
|
|
3619
|
-
mediaType: selected.mediaType,
|
|
3620
|
-
bytes,
|
|
3621
|
-
platform
|
|
3622
|
-
});
|
|
3623
|
-
}
|
|
3624
|
-
|
|
3625
|
-
// packages/sdk/src/sandbox-egress.ts
|
|
3626
|
-
function normalizeSandboxConnectionKeys(value) {
|
|
3627
|
-
if (!Array.isArray(value)) throw new TypeError("sandbox connection keys must be an array");
|
|
3628
|
-
return [...new Set(value.map((key) => scopedBindingKey(key)))].sort();
|
|
3629
|
-
}
|
|
3630
|
-
var SANDBOX_EGRESS_LIMITS = { rules: 64, labels: 16, labelValueLength: 256 };
|
|
3631
|
-
var HEADER2 = /^[a-z0-9!#$%&'*+.^_`|~-]+$/u;
|
|
3632
|
-
var RESERVED_HEADERS2 = /* @__PURE__ */ new Set([
|
|
3633
|
-
"connection",
|
|
3634
|
-
"content-length",
|
|
3635
|
-
"host",
|
|
3636
|
-
"keep-alive",
|
|
3637
|
-
"proxy-connection",
|
|
3638
|
-
"te",
|
|
3639
|
-
"trailer",
|
|
3640
|
-
"transfer-encoding",
|
|
3641
|
-
"upgrade"
|
|
3642
|
-
]);
|
|
3643
|
-
var LABEL = /^[a-z0-9][a-z0-9._-]{0,62}$/u;
|
|
3644
|
-
function object4(value) {
|
|
3645
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3646
|
-
}
|
|
3647
|
-
function sandboxEgressHostMatches(pattern, hostname) {
|
|
3648
|
-
const host2 = hostname.toLowerCase().replace(/\.$/u, "");
|
|
3649
|
-
return pattern.startsWith("*.") ? host2 === pattern.slice(2) || host2.endsWith(pattern.slice(1)) : host2 === pattern;
|
|
3650
|
-
}
|
|
3651
|
-
function host(value) {
|
|
3652
|
-
const [normalized] = normalizeSandboxDomains([value]);
|
|
3653
|
-
return normalized;
|
|
3654
|
-
}
|
|
3655
|
-
function presentation(present) {
|
|
3656
|
-
const header = present.header === void 0 ? "authorization" : present.header;
|
|
3657
|
-
if (typeof header !== "string" || !HEADER2.test(header.toLowerCase()) || RESERVED_HEADERS2.has(header.toLowerCase()) || header.toLowerCase().startsWith("x-constal-")) throw new TypeError("Credential destination header is invalid");
|
|
3658
|
-
if (present.value !== void 0 && present.basic !== void 0) throw new TypeError("Credential destination takes value or basic, not both");
|
|
3659
|
-
if (present.value !== void 0 && (typeof present.value !== "string" || /[\r\n\0]/u.test(present.value) || present.value.split("{value}").length !== 2)) throw new TypeError("Credential destination value must contain {value} exactly once");
|
|
3660
|
-
const basic = present.basic === void 0 ? void 0 : object4(present.basic);
|
|
3661
|
-
if (present.basic !== void 0 && (!basic || Object.keys(basic).some((key) => key !== "username") || basic.username !== void 0 && (typeof basic.username !== "string" || !basic.username || /[:\r\n\0]/u.test(basic.username)))) throw new TypeError("Credential destination basic auth is invalid");
|
|
3662
|
-
if (present.field !== void 0 && (typeof present.field !== "string" || !present.field.startsWith("/") || SPACE_OR_CONTROL.test(present.field) || /~(?![01])/u.test(present.field))) throw new TypeError("Credential destination field must be a JSON Pointer");
|
|
3663
|
-
if (present.code !== void 0 && present.code !== "totp") throw new TypeError("Credential destination code must be totp");
|
|
3664
|
-
return {
|
|
3665
|
-
header: header.toLowerCase(),
|
|
3666
|
-
...basic ? { basic: basic.username === void 0 ? {} : { username: basic.username } } : { value: present.value ?? "Bearer {value}" },
|
|
3667
|
-
...present.field !== void 0 ? { field: present.field } : {},
|
|
3668
|
-
...present.code !== void 0 ? { code: "totp" } : {}
|
|
3669
|
-
};
|
|
3670
|
-
}
|
|
3671
|
-
var SPACE_OR_CONTROL = /[\s\u0000-\u001f\u007f]/u;
|
|
3672
|
-
function path(raw) {
|
|
3673
|
-
if (typeof raw !== "string" || !raw.startsWith("/") || /[%?#\\]/u.test(raw) || SPACE_OR_CONTROL.test(raw)) {
|
|
3674
|
-
throw new TypeError("Credential destination path is invalid");
|
|
3675
|
-
}
|
|
3676
|
-
const prefix = raw.length > 1 && raw.endsWith("/") ? raw.slice(0, -1) : raw;
|
|
3677
|
-
if (prefix.slice(1).split("/").some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
3678
|
-
throw new TypeError("Credential destination path is invalid");
|
|
3679
|
-
}
|
|
3680
|
-
return prefix;
|
|
3681
|
-
}
|
|
3682
|
-
function normalizeCredentialDestinations(value) {
|
|
3683
|
-
if (value === void 0) return [];
|
|
3684
|
-
if (!Array.isArray(value)) throw new TypeError("Credential destinations are invalid");
|
|
3685
|
-
const destinations = value.map((raw) => {
|
|
3686
|
-
const destination = object4(raw);
|
|
3687
|
-
const present = object4(destination?.present);
|
|
3688
|
-
if (!destination || Object.keys(destination).some((key) => !["origin", "path", "present"].includes(key)) || typeof destination.origin !== "string" || !destination.origin.startsWith("https://") || !present || Object.keys(present).some((key) => !["header", "value", "basic", "field", "code"].includes(key))) {
|
|
3689
|
-
throw new TypeError("Credential destination is invalid");
|
|
3690
|
-
}
|
|
3691
|
-
return {
|
|
3692
|
-
origin: `https://${host(destination.origin.slice("https://".length))}`,
|
|
3693
|
-
...destination.path !== void 0 ? { path: path(destination.path) } : {},
|
|
3694
|
-
present: presentation(present)
|
|
3695
|
-
};
|
|
3696
|
-
});
|
|
3697
|
-
const headers = destinations.map((destination) => JSON.stringify([destination.origin, destination.path ?? null, destination.present.header]));
|
|
3698
|
-
if (new Set(headers).size !== headers.length) throw new TypeError("Credential destinations of one origin and path name a header twice");
|
|
3699
|
-
return destinations;
|
|
3700
|
-
}
|
|
3701
|
-
function normalizeSandboxEgressPolicy(value) {
|
|
3702
|
-
const input = object4(value);
|
|
3703
|
-
if (!input || Object.keys(input).some((key) => key !== "rules" && key !== "default") || !Array.isArray(input.rules) || input.rules.length > SANDBOX_EGRESS_LIMITS.rules || input.default !== void 0 && input.default !== "allow" && input.default !== "deny") {
|
|
3704
|
-
throw new TypeError("sandbox egress policy is invalid");
|
|
3705
|
-
}
|
|
3706
|
-
const rules = input.rules.map((raw) => {
|
|
3707
|
-
const rule = object4(raw);
|
|
3708
|
-
if (!rule || Object.keys(rule).some((key) => key !== "action" && key !== "host") || rule.action !== "allow" && rule.action !== "deny") {
|
|
3709
|
-
throw new TypeError("sandbox egress rule is invalid");
|
|
3710
|
-
}
|
|
3711
|
-
return { action: rule.action, host: host(rule.host) };
|
|
3712
|
-
});
|
|
3713
|
-
return { rules, default: input.default === "allow" ? "allow" : "deny" };
|
|
3714
|
-
}
|
|
3715
|
-
function sandboxEgressDecision(policy2, hostname) {
|
|
3716
|
-
if (!policy2) return { allowed: true, rule: "pool" };
|
|
3717
|
-
const index = policy2.rules.findIndex((rule) => sandboxEgressHostMatches(rule.host, hostname));
|
|
3718
|
-
if (index < 0) return { allowed: policy2.default === "allow", rule: "sandbox:default" };
|
|
3719
|
-
return { allowed: policy2.rules[index].action === "allow", rule: `sandbox:${index}` };
|
|
3720
|
-
}
|
|
3721
|
-
function normalizeSandboxLabels(value) {
|
|
3722
|
-
if (value === void 0) return {};
|
|
3723
|
-
const input = object4(value);
|
|
3724
|
-
if (!input || Object.keys(input).length > SANDBOX_EGRESS_LIMITS.labels) throw new TypeError("sandbox labels are invalid");
|
|
3725
|
-
const labels = {};
|
|
3726
|
-
for (const [key, label] of Object.entries(input).sort(([left], [right]) => left.localeCompare(right))) {
|
|
3727
|
-
if (!LABEL.test(key) || typeof label !== "string" || label.length > SANDBOX_EGRESS_LIMITS.labelValueLength || /[\u0000-\u001f\u007f]/u.test(label)) throw new TypeError("sandbox label is invalid");
|
|
3728
|
-
labels[key] = label;
|
|
3729
|
-
}
|
|
3730
|
-
return labels;
|
|
3731
|
-
}
|
|
3732
|
-
|
|
3733
3482
|
// packages/sdk/src/sandbox-pool.ts
|
|
3734
|
-
var
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3483
|
+
var SANDBOX_POOL_OPERATIONS = [
|
|
3484
|
+
"create",
|
|
3485
|
+
"get",
|
|
3486
|
+
"start",
|
|
3487
|
+
"stop",
|
|
3488
|
+
"delete",
|
|
3489
|
+
"update",
|
|
3490
|
+
"exec",
|
|
3491
|
+
"execution",
|
|
3492
|
+
"cancel",
|
|
3493
|
+
"readFile",
|
|
3494
|
+
"writeFile",
|
|
3495
|
+
"deleteFile",
|
|
3496
|
+
"snapshot",
|
|
3497
|
+
"deleteSnapshot"
|
|
3498
|
+
];
|
|
3499
|
+
var SANDBOX_PROVIDER_UNAVAILABLE = "ProviderUnavailable";
|
|
3500
|
+
var SANDBOX_PROVIDER_FAILURE_CLASSES = ["capacity", "rate_limited", "quota", "region", "outage"];
|
|
3501
|
+
function isFailureClass(value) {
|
|
3502
|
+
return typeof value === "string" && SANDBOX_PROVIDER_FAILURE_CLASSES.includes(value);
|
|
3503
|
+
}
|
|
3504
|
+
function sandboxProviderUnavailable(value) {
|
|
3505
|
+
const source = value && typeof value === "object" ? value : null;
|
|
3506
|
+
if (!source || source.code !== SANDBOX_PROVIDER_UNAVAILABLE && source.name !== SANDBOX_PROVIDER_UNAVAILABLE) return null;
|
|
3507
|
+
const cause = source.cause && typeof source.cause === "object" ? source.cause : null;
|
|
3508
|
+
const reason = isFailureClass(source.reason) ? source.reason : isFailureClass(cause?.code) ? cause.code : "outage";
|
|
3509
|
+
const retryAfterMs = typeof source.retryAfterMs === "number" && Number.isSafeInteger(source.retryAfterMs) && source.retryAfterMs >= 0 ? source.retryAfterMs : 0;
|
|
3510
|
+
const message2 = typeof source.message === "string" ? source.message : `sandbox provider is unavailable (${reason})`;
|
|
3511
|
+
return { code: SANDBOX_PROVIDER_UNAVAILABLE, reason, retryAfterMs, message: message2 };
|
|
3757
3512
|
}
|
|
3758
|
-
var SANDBOX_PROCESS_IO_OPERATIONS = ["process.status", "process.read", "process.write", "process.close"];
|
|
3759
|
-
var SANDBOX_PROCESS_OPERATIONS = ["process.resolve", ...SANDBOX_PROCESS_IO_OPERATIONS, "process.stop"];
|
|
3760
3513
|
|
|
3761
3514
|
// packages/sdk/src/training.ts
|
|
3762
3515
|
var HASH4 = /^[a-f0-9]{64}$/u;
|
|
@@ -4320,6 +4073,114 @@ var MCP_CLIENT_CAPABILITY = {
|
|
|
4320
4073
|
hash: "a694af71191432e75980dc73962d9239dc8ea324aff084f183a2f45603bd2267"
|
|
4321
4074
|
};
|
|
4322
4075
|
|
|
4076
|
+
// packages/sdk/src/sandbox-egress.ts
|
|
4077
|
+
function normalizeSandboxConnectionKeys(value) {
|
|
4078
|
+
if (!Array.isArray(value)) throw new TypeError("sandbox connection keys must be an array");
|
|
4079
|
+
return [...new Set(value.map((key) => scopedBindingKey(key)))].sort();
|
|
4080
|
+
}
|
|
4081
|
+
var SANDBOX_EGRESS_LIMITS = { rules: 64, labels: 16, labelValueLength: 256 };
|
|
4082
|
+
var HEADER2 = /^[a-z0-9!#$%&'*+.^_`|~-]+$/u;
|
|
4083
|
+
var RESERVED_HEADERS2 = /* @__PURE__ */ new Set([
|
|
4084
|
+
"connection",
|
|
4085
|
+
"content-length",
|
|
4086
|
+
"host",
|
|
4087
|
+
"keep-alive",
|
|
4088
|
+
"proxy-connection",
|
|
4089
|
+
"te",
|
|
4090
|
+
"trailer",
|
|
4091
|
+
"transfer-encoding",
|
|
4092
|
+
"upgrade"
|
|
4093
|
+
]);
|
|
4094
|
+
var LABEL = /^[a-z0-9][a-z0-9._-]{0,62}$/u;
|
|
4095
|
+
function object3(value) {
|
|
4096
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
4097
|
+
}
|
|
4098
|
+
function sandboxEgressHostMatches(pattern, hostname) {
|
|
4099
|
+
const host2 = hostname.toLowerCase().replace(/\.$/u, "");
|
|
4100
|
+
return pattern.startsWith("*.") ? host2 === pattern.slice(2) || host2.endsWith(pattern.slice(1)) : host2 === pattern;
|
|
4101
|
+
}
|
|
4102
|
+
function host(value) {
|
|
4103
|
+
const [normalized] = normalizeSandboxDomains([value]);
|
|
4104
|
+
return normalized;
|
|
4105
|
+
}
|
|
4106
|
+
function presentation(present) {
|
|
4107
|
+
const header = present.header === void 0 ? "authorization" : present.header;
|
|
4108
|
+
if (typeof header !== "string" || !HEADER2.test(header.toLowerCase()) || RESERVED_HEADERS2.has(header.toLowerCase()) || header.toLowerCase().startsWith("x-constal-")) throw new TypeError("Credential destination header is invalid");
|
|
4109
|
+
if (present.value !== void 0 && present.basic !== void 0) throw new TypeError("Credential destination takes value or basic, not both");
|
|
4110
|
+
if (present.value !== void 0 && (typeof present.value !== "string" || /[\r\n\0]/u.test(present.value) || present.value.split("{value}").length !== 2)) throw new TypeError("Credential destination value must contain {value} exactly once");
|
|
4111
|
+
const basic = present.basic === void 0 ? void 0 : object3(present.basic);
|
|
4112
|
+
if (present.basic !== void 0 && (!basic || Object.keys(basic).some((key) => key !== "username") || basic.username !== void 0 && (typeof basic.username !== "string" || !basic.username || /[:\r\n\0]/u.test(basic.username)))) throw new TypeError("Credential destination basic auth is invalid");
|
|
4113
|
+
if (present.field !== void 0 && (typeof present.field !== "string" || !present.field.startsWith("/") || SPACE_OR_CONTROL.test(present.field) || /~(?![01])/u.test(present.field))) throw new TypeError("Credential destination field must be a JSON Pointer");
|
|
4114
|
+
if (present.code !== void 0 && present.code !== "totp") throw new TypeError("Credential destination code must be totp");
|
|
4115
|
+
return {
|
|
4116
|
+
header: header.toLowerCase(),
|
|
4117
|
+
...basic ? { basic: basic.username === void 0 ? {} : { username: basic.username } } : { value: present.value ?? "Bearer {value}" },
|
|
4118
|
+
...present.field !== void 0 ? { field: present.field } : {},
|
|
4119
|
+
...present.code !== void 0 ? { code: "totp" } : {}
|
|
4120
|
+
};
|
|
4121
|
+
}
|
|
4122
|
+
var SPACE_OR_CONTROL = /[\s\u0000-\u001f\u007f]/u;
|
|
4123
|
+
function path(raw) {
|
|
4124
|
+
if (typeof raw !== "string" || !raw.startsWith("/") || /[%?#\\]/u.test(raw) || SPACE_OR_CONTROL.test(raw)) {
|
|
4125
|
+
throw new TypeError("Credential destination path is invalid");
|
|
4126
|
+
}
|
|
4127
|
+
const prefix = raw.length > 1 && raw.endsWith("/") ? raw.slice(0, -1) : raw;
|
|
4128
|
+
if (prefix.slice(1).split("/").some((segment) => segment === "" || segment === "." || segment === "..")) {
|
|
4129
|
+
throw new TypeError("Credential destination path is invalid");
|
|
4130
|
+
}
|
|
4131
|
+
return prefix;
|
|
4132
|
+
}
|
|
4133
|
+
function normalizeCredentialDestinations(value) {
|
|
4134
|
+
if (value === void 0) return [];
|
|
4135
|
+
if (!Array.isArray(value)) throw new TypeError("Credential destinations are invalid");
|
|
4136
|
+
const destinations = value.map((raw) => {
|
|
4137
|
+
const destination = object3(raw);
|
|
4138
|
+
const present = object3(destination?.present);
|
|
4139
|
+
if (!destination || Object.keys(destination).some((key) => !["origin", "path", "present"].includes(key)) || typeof destination.origin !== "string" || !destination.origin.startsWith("https://") || !present || Object.keys(present).some((key) => !["header", "value", "basic", "field", "code"].includes(key))) {
|
|
4140
|
+
throw new TypeError("Credential destination is invalid");
|
|
4141
|
+
}
|
|
4142
|
+
return {
|
|
4143
|
+
origin: `https://${host(destination.origin.slice("https://".length))}`,
|
|
4144
|
+
...destination.path !== void 0 ? { path: path(destination.path) } : {},
|
|
4145
|
+
present: presentation(present)
|
|
4146
|
+
};
|
|
4147
|
+
});
|
|
4148
|
+
const headers = destinations.map((destination) => JSON.stringify([destination.origin, destination.path ?? null, destination.present.header]));
|
|
4149
|
+
if (new Set(headers).size !== headers.length) throw new TypeError("Credential destinations of one origin and path name a header twice");
|
|
4150
|
+
return destinations;
|
|
4151
|
+
}
|
|
4152
|
+
function normalizeSandboxEgressPolicy(value) {
|
|
4153
|
+
const input = object3(value);
|
|
4154
|
+
if (!input || Object.keys(input).some((key) => key !== "rules" && key !== "default") || !Array.isArray(input.rules) || input.rules.length > SANDBOX_EGRESS_LIMITS.rules || input.default !== void 0 && input.default !== "allow" && input.default !== "deny") {
|
|
4155
|
+
throw new TypeError("sandbox egress policy is invalid");
|
|
4156
|
+
}
|
|
4157
|
+
const rules = input.rules.map((raw) => {
|
|
4158
|
+
const rule = object3(raw);
|
|
4159
|
+
if (!rule || Object.keys(rule).some((key) => key !== "action" && key !== "host") || rule.action !== "allow" && rule.action !== "deny") {
|
|
4160
|
+
throw new TypeError("sandbox egress rule is invalid");
|
|
4161
|
+
}
|
|
4162
|
+
return { action: rule.action, host: host(rule.host) };
|
|
4163
|
+
});
|
|
4164
|
+
return { rules, default: input.default === "allow" ? "allow" : "deny" };
|
|
4165
|
+
}
|
|
4166
|
+
function sandboxEgressDecision(policy2, hostname) {
|
|
4167
|
+
if (!policy2) return { allowed: true, rule: "pool" };
|
|
4168
|
+
const index = policy2.rules.findIndex((rule) => sandboxEgressHostMatches(rule.host, hostname));
|
|
4169
|
+
if (index < 0) return { allowed: policy2.default === "allow", rule: "sandbox:default" };
|
|
4170
|
+
return { allowed: policy2.rules[index].action === "allow", rule: `sandbox:${index}` };
|
|
4171
|
+
}
|
|
4172
|
+
function normalizeSandboxLabels(value) {
|
|
4173
|
+
if (value === void 0) return {};
|
|
4174
|
+
const input = object3(value);
|
|
4175
|
+
if (!input || Object.keys(input).length > SANDBOX_EGRESS_LIMITS.labels) throw new TypeError("sandbox labels are invalid");
|
|
4176
|
+
const labels = {};
|
|
4177
|
+
for (const [key, label] of Object.entries(input).sort(([left], [right]) => left.localeCompare(right))) {
|
|
4178
|
+
if (!LABEL.test(key) || typeof label !== "string" || label.length > SANDBOX_EGRESS_LIMITS.labelValueLength || /[\u0000-\u001f\u007f]/u.test(label)) throw new TypeError("sandbox label is invalid");
|
|
4179
|
+
labels[key] = label;
|
|
4180
|
+
}
|
|
4181
|
+
return labels;
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4323
4184
|
// packages/sdk/src/credential-provider.ts
|
|
4324
4185
|
function assertNonSecretConfigSchema(value, field2 = "config") {
|
|
4325
4186
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
@@ -4743,6 +4604,136 @@ function scoreLevel(answer2) {
|
|
|
4743
4604
|
return Math.min(Object.keys(answer2.legend).length - 1, Math.max(0, Math.round(answer2.score)));
|
|
4744
4605
|
}
|
|
4745
4606
|
|
|
4607
|
+
// packages/sdk/src/container-image.ts
|
|
4608
|
+
var REPOSITORY = /^[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*(?:\/[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*)*$/u;
|
|
4609
|
+
var TAG = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/u;
|
|
4610
|
+
var DIGEST = /^[a-z][a-z0-9+._-]*:[A-Za-z0-9=_-]+$/u;
|
|
4611
|
+
var SHA256 = /^sha256:[a-f0-9]{64}$/u;
|
|
4612
|
+
function containerImageReference(value) {
|
|
4613
|
+
if (typeof value !== "string" || !value || /[\s?#\\]/u.test(value) || value.includes("://")) throw new TypeError("container image reference is invalid");
|
|
4614
|
+
const components = value.split("@");
|
|
4615
|
+
if (components.length > 2) throw new TypeError("container image reference is invalid");
|
|
4616
|
+
let name = components[0];
|
|
4617
|
+
const digest = components[1] ?? null;
|
|
4618
|
+
if (digest !== null && (!DIGEST.test(digest) || digest.startsWith("sha256:") && !SHA256.test(digest))) {
|
|
4619
|
+
throw new TypeError("container image digest is invalid");
|
|
4620
|
+
}
|
|
4621
|
+
const separator = name.lastIndexOf(":"), slash = name.lastIndexOf("/");
|
|
4622
|
+
const tag = separator > slash ? name.slice(separator + 1) : null;
|
|
4623
|
+
if (tag !== null) {
|
|
4624
|
+
if (!TAG.test(tag)) throw new TypeError("container image tag is invalid");
|
|
4625
|
+
name = name.slice(0, separator);
|
|
4626
|
+
}
|
|
4627
|
+
const parts = name.split("/"), explicit = parts.length > 1 && (/[.:]/u.test(parts[0]) || parts[0] === "localhost");
|
|
4628
|
+
const registryInput = explicit ? parts.shift() : "docker.io";
|
|
4629
|
+
let registryUrl;
|
|
4630
|
+
try {
|
|
4631
|
+
registryUrl = new URL(`https://${registryInput}`);
|
|
4632
|
+
} catch {
|
|
4633
|
+
throw new TypeError("container image registry is invalid");
|
|
4634
|
+
}
|
|
4635
|
+
if (registryUrl.username || registryUrl.password || registryUrl.pathname !== "/" || !registryUrl.hostname) throw new TypeError("container image registry is invalid");
|
|
4636
|
+
const registry = registryUrl.host === "index.docker.io" ? "docker.io" : registryUrl.host;
|
|
4637
|
+
if (registry === "docker.io" && parts.length === 1) parts.unshift("library");
|
|
4638
|
+
const repository = parts.join("/");
|
|
4639
|
+
if (!REPOSITORY.test(repository)) throw new TypeError("container image repository is invalid");
|
|
4640
|
+
const selectedTag = tag ?? (digest === null ? "latest" : null);
|
|
4641
|
+
return {
|
|
4642
|
+
registry,
|
|
4643
|
+
repository,
|
|
4644
|
+
tag: selectedTag,
|
|
4645
|
+
digest,
|
|
4646
|
+
reference: `${registry}/${repository}${digest === null ? `:${selectedTag}` : `@${digest}`}`
|
|
4647
|
+
};
|
|
4648
|
+
}
|
|
4649
|
+
function immutableContainerImageReference(value) {
|
|
4650
|
+
const image = containerImageReference(value);
|
|
4651
|
+
if (!image.digest || !SHA256.test(image.digest)) throw new TypeError("container image must be resolved to a SHA-256 digest");
|
|
4652
|
+
return image;
|
|
4653
|
+
}
|
|
4654
|
+
function containerImageSource(value) {
|
|
4655
|
+
const source = value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
4656
|
+
const platform = source?.platform && typeof source.platform === "object" && !Array.isArray(source.platform) ? source.platform : null;
|
|
4657
|
+
const image = typeof source?.reference === "string" ? immutableContainerImageReference(source.reference) : null;
|
|
4658
|
+
if (!source || !image || source.digest !== image.digest || typeof source.mediaType !== "string" || !source.mediaType || !Number.isSafeInteger(source.bytes) || Number(source.bytes) < 1 || !platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && (typeof platform.variant !== "string" || !platform.variant)) {
|
|
4659
|
+
throw new TypeError("container image source is invalid");
|
|
4660
|
+
}
|
|
4661
|
+
return structuredClone(source);
|
|
4662
|
+
}
|
|
4663
|
+
function containerImageSelection(value) {
|
|
4664
|
+
const selection = value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
4665
|
+
const platform = selection?.platform && typeof selection.platform === "object" && !Array.isArray(selection.platform) ? selection.platform : null;
|
|
4666
|
+
const image = typeof selection?.reference === "string" ? immutableContainerImageReference(selection.reference) : null;
|
|
4667
|
+
if (!selection || !image || !platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && (typeof platform.variant !== "string" || !platform.variant) || Object.keys(selection).some((key) => key !== "reference" && key !== "platform") || Object.keys(platform).some((key) => key !== "os" && key !== "architecture" && key !== "variant")) {
|
|
4668
|
+
throw new TypeError("container image selection is invalid");
|
|
4669
|
+
}
|
|
4670
|
+
return { reference: image.reference, platform: structuredClone(platform) };
|
|
4671
|
+
}
|
|
4672
|
+
var OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json";
|
|
4673
|
+
var OCI_INDEX = "application/vnd.oci.image.index.v1+json";
|
|
4674
|
+
var DOCKER_MANIFEST = "application/vnd.docker.distribution.manifest.v2+json";
|
|
4675
|
+
var DOCKER_INDEX = "application/vnd.docker.distribution.manifest.list.v2+json";
|
|
4676
|
+
var ACCEPT = [OCI_MANIFEST, OCI_INDEX, DOCKER_MANIFEST, DOCKER_INDEX].join(", ");
|
|
4677
|
+
var MANIFEST_BYTES = 4194304;
|
|
4678
|
+
function object4(value) {
|
|
4679
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
4680
|
+
}
|
|
4681
|
+
async function manifest(image, reference, request, authorization) {
|
|
4682
|
+
const response = await request({
|
|
4683
|
+
url: `https://${image.registry}/v2/${image.repository}/manifests/${encodeURIComponent(reference)}`,
|
|
4684
|
+
method: "GET",
|
|
4685
|
+
headers: { accept: ACCEPT, ...authorization ? { authorization } : {} },
|
|
4686
|
+
maximumBytes: MANIFEST_BYTES
|
|
4687
|
+
});
|
|
4688
|
+
if (response.status < 200 || response.status >= 300) throw Object.assign(new Error(`container registry manifest request returned ${response.status}`), { status: response.status });
|
|
4689
|
+
if (response.body.byteLength === 0 || response.body.byteLength > MANIFEST_BYTES) throw new TypeError("container registry manifest size is invalid");
|
|
4690
|
+
let value;
|
|
4691
|
+
try {
|
|
4692
|
+
value = object4(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(response.body)));
|
|
4693
|
+
} catch {
|
|
4694
|
+
value = null;
|
|
4695
|
+
}
|
|
4696
|
+
if (!value || value.schemaVersion !== 2) throw new TypeError("container registry manifest is invalid");
|
|
4697
|
+
const declared = typeof value.mediaType === "string" ? value.mediaType : response.headers["content-type"]?.split(";", 1)[0];
|
|
4698
|
+
if (![OCI_MANIFEST, OCI_INDEX, DOCKER_MANIFEST, DOCKER_INDEX].includes(String(declared))) throw new TypeError("container registry manifest media type is unsupported");
|
|
4699
|
+
const digest = `sha256:${await sha256Hex(response.body)}`;
|
|
4700
|
+
const header = response.headers["docker-content-digest"];
|
|
4701
|
+
if (header !== void 0 && header !== digest) throw new TypeError("container registry digest header differs from manifest bytes");
|
|
4702
|
+
return { value, mediaType: declared, digest };
|
|
4703
|
+
}
|
|
4704
|
+
async function resolveContainerImageSource(reference, platform, request, authorization) {
|
|
4705
|
+
const image = containerImageReference(reference);
|
|
4706
|
+
if (!platform || typeof platform.os !== "string" || !platform.os || typeof platform.architecture !== "string" || !platform.architecture || platform.variant !== void 0 && !platform.variant) throw new TypeError("container image platform is invalid");
|
|
4707
|
+
const requested = image.digest ?? image.tag;
|
|
4708
|
+
let selected = await manifest(image, requested, request, authorization);
|
|
4709
|
+
if (image.digest && selected.digest !== image.digest) throw new TypeError("container image digest does not match its manifest");
|
|
4710
|
+
if (selected.mediaType === OCI_INDEX || selected.mediaType === DOCKER_INDEX) {
|
|
4711
|
+
if (!Array.isArray(selected.value.manifests)) throw new TypeError("container image index has no manifests");
|
|
4712
|
+
const matches = selected.value.manifests.filter((raw) => {
|
|
4713
|
+
const item = object4(raw), target = object4(item?.platform);
|
|
4714
|
+
return item && target && target.os === platform.os && target.architecture === platform.architecture && (platform.variant === void 0 ? target.variant === void 0 : target.variant === platform.variant);
|
|
4715
|
+
}).map((item) => object4(item));
|
|
4716
|
+
if (matches.length !== 1 || typeof matches[0].digest !== "string" || !SHA256.test(matches[0].digest)) {
|
|
4717
|
+
throw new TypeError("container image index does not contain one exact requested platform");
|
|
4718
|
+
}
|
|
4719
|
+
selected = await manifest(image, matches[0].digest, request, authorization);
|
|
4720
|
+
if (selected.digest !== matches[0].digest) throw new TypeError("container image platform descriptor differs from its manifest");
|
|
4721
|
+
}
|
|
4722
|
+
if (selected.mediaType !== OCI_MANIFEST && selected.mediaType !== DOCKER_MANIFEST) throw new TypeError("container image did not resolve to an image manifest");
|
|
4723
|
+
const config = object4(selected.value.config), layers = selected.value.layers;
|
|
4724
|
+
if (!config || !Number.isSafeInteger(config.size) || Number(config.size) < 0 || !Array.isArray(layers) || layers.some((layer) => !object4(layer) || !Number.isSafeInteger(object4(layer).size) || Number(object4(layer).size) < 0)) {
|
|
4725
|
+
throw new TypeError("container image manifest descriptors are invalid");
|
|
4726
|
+
}
|
|
4727
|
+
const bytes = Number(config.size) + layers.reduce((sum, layer) => sum + Number(object4(layer).size), 0);
|
|
4728
|
+
return containerImageSource({
|
|
4729
|
+
reference: `${image.registry}/${image.repository}@${selected.digest}`,
|
|
4730
|
+
digest: selected.digest,
|
|
4731
|
+
mediaType: selected.mediaType,
|
|
4732
|
+
bytes,
|
|
4733
|
+
platform
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4746
4737
|
// packages/sdk/src/mcp.ts
|
|
4747
4738
|
var MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
4748
4739
|
function record11(value) {
|
|
@@ -5355,6 +5346,9 @@ export {
|
|
|
5355
5346
|
ResourceUnbound,
|
|
5356
5347
|
RollbackTargetInvalid,
|
|
5357
5348
|
SANDBOX_EGRESS_LIMITS,
|
|
5349
|
+
SANDBOX_POOL_OPERATIONS,
|
|
5350
|
+
SANDBOX_PROVIDER_FAILURE_CLASSES,
|
|
5351
|
+
SANDBOX_PROVIDER_UNAVAILABLE,
|
|
5358
5352
|
SessionDeleted,
|
|
5359
5353
|
SpawnCardinality,
|
|
5360
5354
|
SwallowedYield,
|
|
@@ -5463,7 +5457,6 @@ export {
|
|
|
5463
5457
|
normalizeSandboxEgressPolicy,
|
|
5464
5458
|
normalizeSandboxLabels,
|
|
5465
5459
|
normalizeSandboxNetworkPolicy,
|
|
5466
|
-
normalizeSandboxWorkspacePath,
|
|
5467
5460
|
noulDecision,
|
|
5468
5461
|
opTool,
|
|
5469
5462
|
opTools,
|
|
@@ -5490,6 +5483,7 @@ export {
|
|
|
5490
5483
|
sandboxEgressDecision,
|
|
5491
5484
|
sandboxEgressHostMatches,
|
|
5492
5485
|
sandboxLimit,
|
|
5486
|
+
sandboxProviderUnavailable,
|
|
5493
5487
|
scopedBindingKey,
|
|
5494
5488
|
scopedCredentialRef,
|
|
5495
5489
|
scopedResourceRef,
|