@tangle-network/agent-app 3.0.35 → 3.0.37
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/dist/agent-profiles/d1.js +1 -1
- package/dist/agent-profiles/index.d.ts +11 -0
- package/dist/agent-profiles/index.js +1 -1
- package/dist/chat-routes/index.js +2 -2
- package/dist/{chunk-KYF6YK3C.js → chunk-BRQ2SC6V.js} +17 -9
- package/dist/chunk-BRQ2SC6V.js.map +1 -0
- package/dist/{chunk-5DG2LO3T.js → chunk-JFBJ7MGK.js} +223 -213
- package/dist/{chunk-5DG2LO3T.js.map → chunk-JFBJ7MGK.js.map} +1 -1
- package/dist/{chunk-VG27P322.js → chunk-JSWBJBPM.js} +2 -2
- package/dist/journeys/index.js +1 -1
- package/dist/journeys/index.js.map +1 -1
- package/dist/public-consultation/index.js +2 -2
- package/dist/sandbox/existing-box.d.ts +6 -0
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-KYF6YK3C.js.map +0 -1
- /package/dist/{chunk-VG27P322.js.map → chunk-JSWBJBPM.js.map} +0 -0
|
@@ -2943,139 +2943,11 @@ function sandboxModelWithinPolicy(preferred, allowedModels) {
|
|
|
2943
2943
|
return preferred.find((model) => allowedModels.includes(model)) ?? allowedModels[0];
|
|
2944
2944
|
}
|
|
2945
2945
|
|
|
2946
|
-
// src/sandbox/
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
tool,
|
|
2952
|
-
baseUrl: options.baseUrl,
|
|
2953
|
-
tokenEnvKey: options.tokenEnvKey,
|
|
2954
|
-
ctx: options.ctx,
|
|
2955
|
-
description,
|
|
2956
|
-
headerNames: options.headerNames
|
|
2957
|
-
});
|
|
2958
|
-
}
|
|
2959
|
-
return entries;
|
|
2960
|
-
}
|
|
2961
|
-
var DEFAULT_SANDBOX_TOOL_BASE_DIR = "/home/agent/tools";
|
|
2962
|
-
var SAFE_TOOL_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
2963
|
-
function normalizeSandboxToolSegment(value, label) {
|
|
2964
|
-
const segment = value.trim();
|
|
2965
|
-
if (!segment || segment === "." || segment === ".." || !SAFE_TOOL_SEGMENT.test(segment)) {
|
|
2966
|
-
throw new Error(`${label} must contain only letters, numbers, dots, underscores, or hyphens.`);
|
|
2967
|
-
}
|
|
2968
|
-
return segment;
|
|
2969
|
-
}
|
|
2970
|
-
function normalizeSandboxToolDir(value, label) {
|
|
2971
|
-
const dir = value.trim().replace(/\/+$/, "");
|
|
2972
|
-
if (!dir || !dir.startsWith("/") || dir.includes("\0") || dir.includes("\n")) {
|
|
2973
|
-
throw new Error(`${label} must be an absolute sandbox path.`);
|
|
2974
|
-
}
|
|
2975
|
-
return dir === "" ? "/" : dir;
|
|
2976
|
-
}
|
|
2977
|
-
function sandboxToolRootDir(options) {
|
|
2978
|
-
const appName = normalizeSandboxToolSegment(options.appName, "sandbox tool appName");
|
|
2979
|
-
const baseDir = normalizeSandboxToolDir(
|
|
2980
|
-
options.baseDir ?? DEFAULT_SANDBOX_TOOL_BASE_DIR,
|
|
2981
|
-
"sandbox tool baseDir"
|
|
2982
|
-
);
|
|
2983
|
-
return `${baseDir}/${appName}`;
|
|
2984
|
-
}
|
|
2985
|
-
function sandboxToolBinDir(options) {
|
|
2986
|
-
normalizeSandboxToolSegment(options.appName, "sandbox tool appName");
|
|
2987
|
-
if (options.binDir) return normalizeSandboxToolDir(options.binDir, "sandbox tool binDir");
|
|
2988
|
-
return `${sandboxToolRootDir(options)}/bin`;
|
|
2989
|
-
}
|
|
2990
|
-
function sandboxToolPath(options) {
|
|
2991
|
-
const toolName = normalizeSandboxToolSegment(options.toolName, "sandbox tool name");
|
|
2992
|
-
return `${sandboxToolBinDir(options)}/${toolName}`;
|
|
2993
|
-
}
|
|
2994
|
-
var DUPLICATE_PROGRAM_MIN_BYTES = 4096;
|
|
2995
|
-
function sandboxToolAliasShim(alias, program) {
|
|
2996
|
-
return [
|
|
2997
|
-
"#!/bin/sh",
|
|
2998
|
-
`# ${alias} runs ${program} under its own name. Mounted by buildSandboxToolFileMounts (aliasOf).`,
|
|
2999
|
-
`program=${shellSingleQuote(program)}`,
|
|
3000
|
-
`link="\${TMPDIR:-/tmp}/sandbox-tool-aliases\${program}.d/${alias}"`,
|
|
3001
|
-
'[ -L "$link" ] || { mkdir -p "${link%/*}" && { ln -s "$program" "$link" 2>/dev/null || [ -L "$link" ]; }; } || {',
|
|
3002
|
-
` echo "${alias}: cannot create its alias link under \${TMPDIR:-/tmp}" >&2`,
|
|
3003
|
-
" exit 126",
|
|
3004
|
-
"}",
|
|
3005
|
-
'exec "$link" "$@"',
|
|
3006
|
-
""
|
|
3007
|
-
].join("\n");
|
|
3008
|
-
}
|
|
3009
|
-
function buildSandboxToolFileMounts(options) {
|
|
3010
|
-
const programs = /* @__PURE__ */ new Map();
|
|
3011
|
-
const byContent = /* @__PURE__ */ new Map();
|
|
3012
|
-
for (const tool of options.tools) {
|
|
3013
|
-
if (tool.aliasOf !== void 0) continue;
|
|
3014
|
-
const name = normalizeSandboxToolSegment(tool.name, "sandbox tool name");
|
|
3015
|
-
if (tool.executable !== false) programs.set(name, sandboxToolPath({ ...options, toolName: name }));
|
|
3016
|
-
const first = byContent.get(tool.content);
|
|
3017
|
-
if (first !== void 0 && new TextEncoder().encode(tool.content).byteLength >= DUPLICATE_PROGRAM_MIN_BYTES) {
|
|
3018
|
-
throw new Error(
|
|
3019
|
-
`sandbox tools ${first} and ${name} mount the same program; mount it once and declare ${name} as { name: '${name}', aliasOf: '${first}' }.`
|
|
3020
|
-
);
|
|
3021
|
-
}
|
|
3022
|
-
if (first === void 0) byContent.set(tool.content, name);
|
|
3023
|
-
}
|
|
3024
|
-
return options.tools.map((tool) => {
|
|
3025
|
-
const name = normalizeSandboxToolSegment(tool.name, "sandbox tool name");
|
|
3026
|
-
const path = sandboxToolPath({ ...options, toolName: name });
|
|
3027
|
-
if (tool.aliasOf === void 0) {
|
|
3028
|
-
return { path, resource: { kind: "inline", name, content: tool.content }, executable: tool.executable ?? true };
|
|
3029
|
-
}
|
|
3030
|
-
const program = programs.get(normalizeSandboxToolSegment(tool.aliasOf, "sandbox tool aliasOf"));
|
|
3031
|
-
if (!program) {
|
|
3032
|
-
throw new Error(`sandbox tool ${name} is an alias of ${tool.aliasOf}, which is not an executable program in this call.`);
|
|
3033
|
-
}
|
|
3034
|
-
return { path, resource: { kind: "inline", name, content: sandboxToolAliasShim(name, program) }, executable: true };
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
function buildSandboxToolBinDirsEnv(apps) {
|
|
3038
|
-
if (apps.length === 0) {
|
|
3039
|
-
throw new Error(
|
|
3040
|
-
"buildSandboxToolBinDirsEnv: name at least one app whose tool bin dir belongs on PATH."
|
|
3041
|
-
);
|
|
3042
|
-
}
|
|
3043
|
-
const binDirs = /* @__PURE__ */ new Set();
|
|
3044
|
-
for (const app of apps) {
|
|
3045
|
-
const binDir = sandboxToolBinDir(app);
|
|
3046
|
-
if (binDir.includes(":")) {
|
|
3047
|
-
throw new Error(
|
|
3048
|
-
`sandbox tool bin dir ${binDir} contains ':', which separates entries in SANDBOX_TOOL_BIN_DIRS and in PATH. Place the tools under a colon-free directory.`
|
|
3049
|
-
);
|
|
3050
|
-
}
|
|
3051
|
-
binDirs.add(binDir);
|
|
3052
|
-
}
|
|
3053
|
-
return { SANDBOX_TOOL_BIN_DIRS: [...binDirs].join(":") };
|
|
3054
|
-
}
|
|
3055
|
-
function buildSandboxToolBinDirScript(options) {
|
|
3056
|
-
return ["set -eu", `mkdir -p ${shellSingleQuote(sandboxToolBinDir(options))}`].join("\n");
|
|
3057
|
-
}
|
|
3058
|
-
function buildSandboxToolPathSetupScript(options) {
|
|
3059
|
-
return buildSandboxToolBinDirScript(options);
|
|
3060
|
-
}
|
|
3061
|
-
async function ensureSandboxToolBinDir(box, options) {
|
|
3062
|
-
try {
|
|
3063
|
-
const res = await box.exec(buildSandboxToolBinDirScript(options));
|
|
3064
|
-
if (res.exitCode !== 0) {
|
|
3065
|
-
return fail(
|
|
3066
|
-
new Error(
|
|
3067
|
-
`ensureSandboxToolBinDir: failed to create the tool bin dir ${sandboxToolBinDir(options)} (exit ${res.exitCode}): ${res.stderr.slice(0, 500)}`
|
|
3068
|
-
)
|
|
3069
|
-
);
|
|
3070
|
-
}
|
|
3071
|
-
return ok(void 0);
|
|
3072
|
-
} catch (err) {
|
|
3073
|
-
return fail(new Error("ensureSandboxToolBinDir: exec failed", { cause: err }));
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
async function runSandboxToolPathSetup(box, options) {
|
|
3077
|
-
return ensureSandboxToolBinDir(box, options);
|
|
3078
|
-
}
|
|
2946
|
+
// src/sandbox/existing-box.ts
|
|
2947
|
+
import { createHash as createHash2 } from "crypto";
|
|
2948
|
+
|
|
2949
|
+
// src/sandbox/profile-corpus.ts
|
|
2950
|
+
import { createHash } from "crypto";
|
|
3079
2951
|
|
|
3080
2952
|
// src/sandbox/lifecycle-errors.ts
|
|
3081
2953
|
var SandboxEgressPolicyMismatchError = class extends Error {
|
|
@@ -3132,9 +3004,6 @@ var SandboxBoxBusyError = class extends Error {
|
|
|
3132
3004
|
}
|
|
3133
3005
|
};
|
|
3134
3006
|
|
|
3135
|
-
// src/sandbox/profile-corpus.ts
|
|
3136
|
-
import { createHash } from "crypto";
|
|
3137
|
-
|
|
3138
3007
|
// src/sandbox/runtime-connection.ts
|
|
3139
3008
|
var RUNTIME_AUTH_REFRESH_SKEW_MS = 6e4;
|
|
3140
3009
|
var RUNTIME_CONNECTION_WAIT_MS = 3e4;
|
|
@@ -3325,78 +3194,7 @@ async function writeDeferredCorpusMarker(box, corpusHash) {
|
|
|
3325
3194
|
}
|
|
3326
3195
|
}
|
|
3327
3196
|
|
|
3328
|
-
// src/sandbox/workspace-boxes.ts
|
|
3329
|
-
async function listRunning(client, name) {
|
|
3330
|
-
try {
|
|
3331
|
-
const running = await client.list({ status: "running" });
|
|
3332
|
-
return ok(running.find((s) => s.name === name) ?? null);
|
|
3333
|
-
} catch (err) {
|
|
3334
|
-
return fail(err);
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
async function getRunningBox(client, id, name) {
|
|
3338
|
-
try {
|
|
3339
|
-
const box = await client.get(id);
|
|
3340
|
-
if (!box || box.name !== name || box.status !== "running") return null;
|
|
3341
|
-
if (typeof box.metadata?.harness !== "string") return null;
|
|
3342
|
-
return box;
|
|
3343
|
-
} catch {
|
|
3344
|
-
return null;
|
|
3345
|
-
}
|
|
3346
|
-
}
|
|
3347
|
-
async function listStopped(client, name) {
|
|
3348
|
-
try {
|
|
3349
|
-
const stopped = await client.list({ status: "stopped" });
|
|
3350
|
-
return ok(stopped.find((s) => s.name === name) ?? null);
|
|
3351
|
-
} catch (err) {
|
|
3352
|
-
return fail(err);
|
|
3353
|
-
}
|
|
3354
|
-
}
|
|
3355
|
-
async function deleteBox(box) {
|
|
3356
|
-
try {
|
|
3357
|
-
const acknowledgement = await box.delete({ until: "removed" });
|
|
3358
|
-
forgetBox(box.id);
|
|
3359
|
-
if (acknowledgement.removal === "pending") {
|
|
3360
|
-
return fail(new Error(`sandbox ${box.id} removal is still pending; retry replacement after removal completes`));
|
|
3361
|
-
}
|
|
3362
|
-
return ok(void 0);
|
|
3363
|
-
} catch (err) {
|
|
3364
|
-
return fail(err);
|
|
3365
|
-
}
|
|
3366
|
-
}
|
|
3367
|
-
async function resolveWorkspaceSandboxClient(shell, workspaceId, userId, signal) {
|
|
3368
|
-
const scope = { workspaceId, ...userId ? { userId } : {} };
|
|
3369
|
-
const creds = await shell.credentials(scope);
|
|
3370
|
-
signal?.throwIfAborted();
|
|
3371
|
-
if (!creds) throw new Error("sandbox credentials are required (apiKey/baseUrl)");
|
|
3372
|
-
return {
|
|
3373
|
-
scope,
|
|
3374
|
-
client: getClientFromCreds(creds, signal),
|
|
3375
|
-
name: shell.boxKey ? shell.boxKey(scope) : shell.name(workspaceId)
|
|
3376
|
-
};
|
|
3377
|
-
}
|
|
3378
|
-
async function peekWorkspaceSandbox(shell, options) {
|
|
3379
|
-
options.signal?.throwIfAborted();
|
|
3380
|
-
const { client, name } = await resolveWorkspaceSandboxClient(shell, options.workspaceId, options.userId, options.signal);
|
|
3381
|
-
const displayName = shell.name(options.workspaceId);
|
|
3382
|
-
const boxes = await client.list();
|
|
3383
|
-
const match = boxes.find((box) => box.name === name) ?? boxes.find((box) => box.name === displayName);
|
|
3384
|
-
if (!match) return { status: "absent" };
|
|
3385
|
-
if (match.status !== "running") return { status: "not-running", state: match.status, box: match };
|
|
3386
|
-
if (match.filesystemIncarnationReadiness === "transitioning") {
|
|
3387
|
-
return { status: "warming", readiness: "transitioning", box: match };
|
|
3388
|
-
}
|
|
3389
|
-
if (match.filesystemIncarnationReadiness !== "ready") {
|
|
3390
|
-
throw new Error(`sandbox ${match.id} is running without filesystem incarnation readiness`);
|
|
3391
|
-
}
|
|
3392
|
-
return { status: "running", box: match };
|
|
3393
|
-
}
|
|
3394
|
-
|
|
3395
|
-
// src/sandbox/workspace-provision.ts
|
|
3396
|
-
import { parseBackendType as parseBackendType2 } from "@tangle-network/sandbox";
|
|
3397
|
-
|
|
3398
3197
|
// src/sandbox/existing-box.ts
|
|
3399
|
-
import { createHash as createHash2 } from "crypto";
|
|
3400
3198
|
async function resolveWorkspaceRuntimeEnv(shell, scope) {
|
|
3401
3199
|
const env = await shell.runtimeEnv?.(scope) ?? {};
|
|
3402
3200
|
assertEnvWithinLimits(env);
|
|
@@ -3522,6 +3320,13 @@ async function hasBootstrapMarker(box, key) {
|
|
|
3522
3320
|
return false;
|
|
3523
3321
|
}
|
|
3524
3322
|
}
|
|
3323
|
+
async function forgetBootstrap(box) {
|
|
3324
|
+
try {
|
|
3325
|
+
return (await box.exec(`rm -rf ${BOOTSTRAP_MARKERS}`)).exitCode === 0;
|
|
3326
|
+
} catch {
|
|
3327
|
+
return false;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3525
3330
|
async function writeBootstrapMarker(box, key) {
|
|
3526
3331
|
try {
|
|
3527
3332
|
await box.exec(`mkdir -p ${BOOTSTRAP_MARKERS} && : > ${BOOTSTRAP_MARKERS}/${key}`);
|
|
@@ -3615,6 +3420,210 @@ async function assertExistingBoxEgress(box, desired, migrate, stage, name, deadl
|
|
|
3615
3420
|
);
|
|
3616
3421
|
}
|
|
3617
3422
|
|
|
3423
|
+
// src/sandbox/app-tools.ts
|
|
3424
|
+
function buildAppToolMcpServers(options) {
|
|
3425
|
+
const entries = {};
|
|
3426
|
+
for (const { tool, key, description } of options.tools) {
|
|
3427
|
+
entries[key] = buildAppToolMcpServer({
|
|
3428
|
+
tool,
|
|
3429
|
+
baseUrl: options.baseUrl,
|
|
3430
|
+
tokenEnvKey: options.tokenEnvKey,
|
|
3431
|
+
ctx: options.ctx,
|
|
3432
|
+
description,
|
|
3433
|
+
headerNames: options.headerNames
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3436
|
+
return entries;
|
|
3437
|
+
}
|
|
3438
|
+
var DEFAULT_SANDBOX_TOOL_BASE_DIR = "/home/agent/tools";
|
|
3439
|
+
var SAFE_TOOL_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
3440
|
+
function normalizeSandboxToolSegment(value, label) {
|
|
3441
|
+
const segment = value.trim();
|
|
3442
|
+
if (!segment || segment === "." || segment === ".." || !SAFE_TOOL_SEGMENT.test(segment)) {
|
|
3443
|
+
throw new Error(`${label} must contain only letters, numbers, dots, underscores, or hyphens.`);
|
|
3444
|
+
}
|
|
3445
|
+
return segment;
|
|
3446
|
+
}
|
|
3447
|
+
function normalizeSandboxToolDir(value, label) {
|
|
3448
|
+
const dir = value.trim().replace(/\/+$/, "");
|
|
3449
|
+
if (!dir || !dir.startsWith("/") || dir.includes("\0") || dir.includes("\n")) {
|
|
3450
|
+
throw new Error(`${label} must be an absolute sandbox path.`);
|
|
3451
|
+
}
|
|
3452
|
+
return dir === "" ? "/" : dir;
|
|
3453
|
+
}
|
|
3454
|
+
function sandboxToolRootDir(options) {
|
|
3455
|
+
const appName = normalizeSandboxToolSegment(options.appName, "sandbox tool appName");
|
|
3456
|
+
const baseDir = normalizeSandboxToolDir(
|
|
3457
|
+
options.baseDir ?? DEFAULT_SANDBOX_TOOL_BASE_DIR,
|
|
3458
|
+
"sandbox tool baseDir"
|
|
3459
|
+
);
|
|
3460
|
+
return `${baseDir}/${appName}`;
|
|
3461
|
+
}
|
|
3462
|
+
function sandboxToolBinDir(options) {
|
|
3463
|
+
normalizeSandboxToolSegment(options.appName, "sandbox tool appName");
|
|
3464
|
+
if (options.binDir) return normalizeSandboxToolDir(options.binDir, "sandbox tool binDir");
|
|
3465
|
+
return `${sandboxToolRootDir(options)}/bin`;
|
|
3466
|
+
}
|
|
3467
|
+
function sandboxToolPath(options) {
|
|
3468
|
+
const toolName = normalizeSandboxToolSegment(options.toolName, "sandbox tool name");
|
|
3469
|
+
return `${sandboxToolBinDir(options)}/${toolName}`;
|
|
3470
|
+
}
|
|
3471
|
+
var DUPLICATE_PROGRAM_MIN_BYTES = 4096;
|
|
3472
|
+
function sandboxToolAliasShim(alias, program) {
|
|
3473
|
+
return [
|
|
3474
|
+
"#!/bin/sh",
|
|
3475
|
+
`# ${alias} runs ${program} under its own name. Mounted by buildSandboxToolFileMounts (aliasOf).`,
|
|
3476
|
+
`program=${shellSingleQuote(program)}`,
|
|
3477
|
+
`link="\${TMPDIR:-/tmp}/sandbox-tool-aliases\${program}.d/${alias}"`,
|
|
3478
|
+
'[ -L "$link" ] || { mkdir -p "${link%/*}" && { ln -s "$program" "$link" 2>/dev/null || [ -L "$link" ]; }; } || {',
|
|
3479
|
+
` echo "${alias}: cannot create its alias link under \${TMPDIR:-/tmp}" >&2`,
|
|
3480
|
+
" exit 126",
|
|
3481
|
+
"}",
|
|
3482
|
+
'exec "$link" "$@"',
|
|
3483
|
+
""
|
|
3484
|
+
].join("\n");
|
|
3485
|
+
}
|
|
3486
|
+
function buildSandboxToolFileMounts(options) {
|
|
3487
|
+
const programs = /* @__PURE__ */ new Map();
|
|
3488
|
+
const byContent = /* @__PURE__ */ new Map();
|
|
3489
|
+
for (const tool of options.tools) {
|
|
3490
|
+
if (tool.aliasOf !== void 0) continue;
|
|
3491
|
+
const name = normalizeSandboxToolSegment(tool.name, "sandbox tool name");
|
|
3492
|
+
if (tool.executable !== false) programs.set(name, sandboxToolPath({ ...options, toolName: name }));
|
|
3493
|
+
const first = byContent.get(tool.content);
|
|
3494
|
+
if (first !== void 0 && new TextEncoder().encode(tool.content).byteLength >= DUPLICATE_PROGRAM_MIN_BYTES) {
|
|
3495
|
+
throw new Error(
|
|
3496
|
+
`sandbox tools ${first} and ${name} mount the same program; mount it once and declare ${name} as { name: '${name}', aliasOf: '${first}' }.`
|
|
3497
|
+
);
|
|
3498
|
+
}
|
|
3499
|
+
if (first === void 0) byContent.set(tool.content, name);
|
|
3500
|
+
}
|
|
3501
|
+
return options.tools.map((tool) => {
|
|
3502
|
+
const name = normalizeSandboxToolSegment(tool.name, "sandbox tool name");
|
|
3503
|
+
const path = sandboxToolPath({ ...options, toolName: name });
|
|
3504
|
+
if (tool.aliasOf === void 0) {
|
|
3505
|
+
return { path, resource: { kind: "inline", name, content: tool.content }, executable: tool.executable ?? true };
|
|
3506
|
+
}
|
|
3507
|
+
const program = programs.get(normalizeSandboxToolSegment(tool.aliasOf, "sandbox tool aliasOf"));
|
|
3508
|
+
if (!program) {
|
|
3509
|
+
throw new Error(`sandbox tool ${name} is an alias of ${tool.aliasOf}, which is not an executable program in this call.`);
|
|
3510
|
+
}
|
|
3511
|
+
return { path, resource: { kind: "inline", name, content: sandboxToolAliasShim(name, program) }, executable: true };
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
function buildSandboxToolBinDirsEnv(apps) {
|
|
3515
|
+
if (apps.length === 0) {
|
|
3516
|
+
throw new Error(
|
|
3517
|
+
"buildSandboxToolBinDirsEnv: name at least one app whose tool bin dir belongs on PATH."
|
|
3518
|
+
);
|
|
3519
|
+
}
|
|
3520
|
+
const binDirs = /* @__PURE__ */ new Set();
|
|
3521
|
+
for (const app of apps) {
|
|
3522
|
+
const binDir = sandboxToolBinDir(app);
|
|
3523
|
+
if (binDir.includes(":")) {
|
|
3524
|
+
throw new Error(
|
|
3525
|
+
`sandbox tool bin dir ${binDir} contains ':', which separates entries in SANDBOX_TOOL_BIN_DIRS and in PATH. Place the tools under a colon-free directory.`
|
|
3526
|
+
);
|
|
3527
|
+
}
|
|
3528
|
+
binDirs.add(binDir);
|
|
3529
|
+
}
|
|
3530
|
+
return { SANDBOX_TOOL_BIN_DIRS: [...binDirs].join(":") };
|
|
3531
|
+
}
|
|
3532
|
+
function buildSandboxToolBinDirScript(options) {
|
|
3533
|
+
return ["set -eu", `mkdir -p ${shellSingleQuote(sandboxToolBinDir(options))}`].join("\n");
|
|
3534
|
+
}
|
|
3535
|
+
function buildSandboxToolPathSetupScript(options) {
|
|
3536
|
+
return buildSandboxToolBinDirScript(options);
|
|
3537
|
+
}
|
|
3538
|
+
async function ensureSandboxToolBinDir(box, options) {
|
|
3539
|
+
try {
|
|
3540
|
+
const res = await box.exec(buildSandboxToolBinDirScript(options));
|
|
3541
|
+
if (res.exitCode !== 0) {
|
|
3542
|
+
return fail(
|
|
3543
|
+
new Error(
|
|
3544
|
+
`ensureSandboxToolBinDir: failed to create the tool bin dir ${sandboxToolBinDir(options)} (exit ${res.exitCode}): ${res.stderr.slice(0, 500)}`
|
|
3545
|
+
)
|
|
3546
|
+
);
|
|
3547
|
+
}
|
|
3548
|
+
return ok(void 0);
|
|
3549
|
+
} catch (err) {
|
|
3550
|
+
return fail(new Error("ensureSandboxToolBinDir: exec failed", { cause: err }));
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
async function runSandboxToolPathSetup(box, options) {
|
|
3554
|
+
return ensureSandboxToolBinDir(box, options);
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
// src/sandbox/workspace-boxes.ts
|
|
3558
|
+
async function listRunning(client, name) {
|
|
3559
|
+
try {
|
|
3560
|
+
const running = await client.list({ status: "running" });
|
|
3561
|
+
return ok(running.find((s) => s.name === name) ?? null);
|
|
3562
|
+
} catch (err) {
|
|
3563
|
+
return fail(err);
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
async function getRunningBox(client, id, name) {
|
|
3567
|
+
try {
|
|
3568
|
+
const box = await client.get(id);
|
|
3569
|
+
if (!box || box.name !== name || box.status !== "running") return null;
|
|
3570
|
+
if (typeof box.metadata?.harness !== "string") return null;
|
|
3571
|
+
return box;
|
|
3572
|
+
} catch {
|
|
3573
|
+
return null;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
async function listStopped(client, name) {
|
|
3577
|
+
try {
|
|
3578
|
+
const stopped = await client.list({ status: "stopped" });
|
|
3579
|
+
return ok(stopped.find((s) => s.name === name) ?? null);
|
|
3580
|
+
} catch (err) {
|
|
3581
|
+
return fail(err);
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
async function deleteBox(box) {
|
|
3585
|
+
try {
|
|
3586
|
+
const acknowledgement = await box.delete({ until: "removed" });
|
|
3587
|
+
forgetBox(box.id);
|
|
3588
|
+
if (acknowledgement.removal === "pending") {
|
|
3589
|
+
return fail(new Error(`sandbox ${box.id} removal is still pending; retry replacement after removal completes`));
|
|
3590
|
+
}
|
|
3591
|
+
return ok(void 0);
|
|
3592
|
+
} catch (err) {
|
|
3593
|
+
return fail(err);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
async function resolveWorkspaceSandboxClient(shell, workspaceId, userId, signal) {
|
|
3597
|
+
const scope = { workspaceId, ...userId ? { userId } : {} };
|
|
3598
|
+
const creds = await shell.credentials(scope);
|
|
3599
|
+
signal?.throwIfAborted();
|
|
3600
|
+
if (!creds) throw new Error("sandbox credentials are required (apiKey/baseUrl)");
|
|
3601
|
+
return {
|
|
3602
|
+
scope,
|
|
3603
|
+
client: getClientFromCreds(creds, signal),
|
|
3604
|
+
name: shell.boxKey ? shell.boxKey(scope) : shell.name(workspaceId)
|
|
3605
|
+
};
|
|
3606
|
+
}
|
|
3607
|
+
async function peekWorkspaceSandbox(shell, options) {
|
|
3608
|
+
options.signal?.throwIfAborted();
|
|
3609
|
+
const { client, name } = await resolveWorkspaceSandboxClient(shell, options.workspaceId, options.userId, options.signal);
|
|
3610
|
+
const displayName = shell.name(options.workspaceId);
|
|
3611
|
+
const boxes = await client.list();
|
|
3612
|
+
const match = boxes.find((box) => box.name === name) ?? boxes.find((box) => box.name === displayName);
|
|
3613
|
+
if (!match) return { status: "absent" };
|
|
3614
|
+
if (match.status !== "running") return { status: "not-running", state: match.status, box: match };
|
|
3615
|
+
if (match.filesystemIncarnationReadiness === "transitioning") {
|
|
3616
|
+
return { status: "warming", readiness: "transitioning", box: match };
|
|
3617
|
+
}
|
|
3618
|
+
if (match.filesystemIncarnationReadiness !== "ready") {
|
|
3619
|
+
throw new Error(`sandbox ${match.id} is running without filesystem incarnation readiness`);
|
|
3620
|
+
}
|
|
3621
|
+
return { status: "running", box: match };
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
// src/sandbox/workspace-provision.ts
|
|
3625
|
+
import { parseBackendType as parseBackendType2 } from "@tangle-network/sandbox";
|
|
3626
|
+
|
|
3618
3627
|
// src/sandbox/box-health.ts
|
|
3619
3628
|
async function isBoxAlive(box, probe, deadline) {
|
|
3620
3629
|
if (!probe) return ok(void 0);
|
|
@@ -4330,6 +4339,12 @@ export {
|
|
|
4330
4339
|
buildProductEgressPolicy,
|
|
4331
4340
|
readSandboxModelPolicy,
|
|
4332
4341
|
sandboxModelWithinPolicy,
|
|
4342
|
+
SandboxEgressPolicyMismatchError,
|
|
4343
|
+
SandboxRuntimeAuthRefreshError,
|
|
4344
|
+
SandboxRecoveryFailedError,
|
|
4345
|
+
SandboxBoxBusyError,
|
|
4346
|
+
deferredCorpusHash,
|
|
4347
|
+
forgetBootstrap,
|
|
4333
4348
|
buildAppToolMcpServers,
|
|
4334
4349
|
sandboxToolRootDir,
|
|
4335
4350
|
sandboxToolBinDir,
|
|
@@ -4340,11 +4355,6 @@ export {
|
|
|
4340
4355
|
buildSandboxToolPathSetupScript,
|
|
4341
4356
|
ensureSandboxToolBinDir,
|
|
4342
4357
|
runSandboxToolPathSetup,
|
|
4343
|
-
SandboxEgressPolicyMismatchError,
|
|
4344
|
-
SandboxRuntimeAuthRefreshError,
|
|
4345
|
-
SandboxRecoveryFailedError,
|
|
4346
|
-
SandboxBoxBusyError,
|
|
4347
|
-
deferredCorpusHash,
|
|
4348
4358
|
peekWorkspaceSandbox,
|
|
4349
4359
|
ensureWorkspaceSandbox,
|
|
4350
4360
|
reuseWorkspaceSandbox,
|
|
@@ -4357,4 +4367,4 @@ export {
|
|
|
4357
4367
|
deleteSecret,
|
|
4358
4368
|
mintSandboxScopedToken
|
|
4359
4369
|
};
|
|
4360
|
-
//# sourceMappingURL=chunk-
|
|
4370
|
+
//# sourceMappingURL=chunk-JFBJ7MGK.js.map
|