@tangle-network/sandbox 0.63.16 → 0.63.18
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/index.d.ts +4 -4
- package/dist/agent/index.js +4 -4
- package/dist/agent/preview.d.ts +1 -1
- package/dist/{agent-run-outcome-3p-OlQJG.d.ts → agent-run-outcome-DlYhZnhD.d.ts} +1 -1
- package/dist/{chunked-upload-B867njKv.js → chunked-upload-KJyRCAiC.js} +1 -1
- package/dist/{chunked-upload-file-Bs5qcfRB.js → chunked-upload-file-DfiGzqaR.js} +2 -2
- package/dist/{client-Be-_CMPh.js → client-Dl22CVOz.js} +7 -4
- package/dist/{client-MQkP1a3i.d.ts → client-DraGbXEP.d.ts} +7 -5
- package/dist/collaboration/index.js +1 -1
- package/dist/{collaboration-CXtTwK3x.js → collaboration-XHg5BEUI.js} +1 -1
- package/dist/core.d.ts +7 -7
- package/dist/core.js +3 -3
- package/dist/{direct-http2-D8mo1ePx.js → direct-http2-Dq7tq6jV.js} +1 -1
- package/dist/{errors-BJIX8RRM.d.ts → error-classes-BWS1a9HO.d.ts} +2 -2
- package/dist/{errors-Bfhg_Zc6.js → errors-AB5BD3FM.js} +29 -27
- package/dist/{index-YVbORwwO.d.ts → index-xS3mRl69.d.ts} +2 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +6 -6
- package/dist/intelligence/index.js +1 -1
- package/dist/{interactive-controller-C0bJnKLu.js → interactive-controller-zE6hwv3C.js} +2 -2
- package/dist/{keep-alive-fetch-qPVvvkgJ.js → keep-alive-fetch-CXvfSczd.js} +6 -1
- package/dist/{lines-CINbUZJ6.d.ts → lines-hsXVdk60.d.ts} +1 -1
- package/dist/lines.d.ts +1 -1
- package/dist/lines.js +1 -1
- package/dist/{managed-process-Coh-wv8s.d.ts → managed-process-B-pXdMLC.d.ts} +1 -1
- package/dist/{preview-Dyn4ECT8.d.ts → preview-D8UAF7F9.d.ts} +3 -3
- package/dist/{public-templates-CYURc1KE.d.ts → public-templates-BP3sTaSb.d.ts} +2 -2
- package/dist/public-templates.d.ts +1 -1
- package/dist/public-templates.js +1 -1
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.js +3 -3
- package/dist/{sandbox-C6Y2Hzlv.js → sandbox-BJkpVtLN.js} +483 -336
- package/dist/{sandbox-BAwRXm2a.d.ts → sandbox-DDdPhk2j.d.ts} +3 -3
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-DUDjP2F4.js → tangle-BBpguPfj.js} +2 -2
- package/dist/{types-B2SfJtb1.d.ts → types-BxZX2EVj.d.ts} +18 -0
- package/package.json +5 -5
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { r as backendTypeSchema } from "./backend-types-D6bYbvMB.js";
|
|
2
|
-
import { A as assertCurrentBackendType, B as deriveAgentResultOutcome, C as sessionHeaders, D as encodeTextForWire, E as encodePromptForWire, F as requestedSecretProfilePublicDigest, M as mergeRuntimeBackendConfig, N as normalizeRuntimeBackendConfig, O as parseSSEStream, P as requestedPublicProfileDigest, R as withoutRuntimeSecrets, S as appendSessionIdQuery, T as validateAcceptedDispatchRunRef, _ as TRACE_ID_HEADER, a as terminalUpgradeHeadersSupported, b as resolveTraceId, d as SandboxRuntimeApi, f as isRetryableCredentialRefusal, g as waitForRetryAfter, h as sessionMessageRequestBody, i as TerminalStreamError, k as applyRequestedModel, l as requestScopedToken, m as normalizeSessionInfo, n as InteractiveSessionController, p as normalizeEffectiveBackend, r as TerminalStream, s as assertScopedTokenActive, u as canUseNodeHttp2, v as isTraceId, w as resolveDispatchRunIdentity, x as traceHeaders, y as mintTraceId, z as createAgentRunOutcomeTracker } from "./interactive-controller-
|
|
3
|
-
import { A as PROFILE_FILE_MOUNT_OUTSIDE_ROOTS_CODE, C as
|
|
2
|
+
import { A as assertCurrentBackendType, B as deriveAgentResultOutcome, C as sessionHeaders, D as encodeTextForWire, E as encodePromptForWire, F as requestedSecretProfilePublicDigest, M as mergeRuntimeBackendConfig, N as normalizeRuntimeBackendConfig, O as parseSSEStream, P as requestedPublicProfileDigest, R as withoutRuntimeSecrets, S as appendSessionIdQuery, T as validateAcceptedDispatchRunRef, _ as TRACE_ID_HEADER, a as terminalUpgradeHeadersSupported, b as resolveTraceId, d as SandboxRuntimeApi, f as isRetryableCredentialRefusal, g as waitForRetryAfter, h as sessionMessageRequestBody, i as TerminalStreamError, k as applyRequestedModel, l as requestScopedToken, m as normalizeSessionInfo, n as InteractiveSessionController, p as normalizeEffectiveBackend, r as TerminalStream, s as assertScopedTokenActive, u as canUseNodeHttp2, v as isTraceId, w as resolveDispatchRunIdentity, x as traceHeaders, y as mintTraceId, z as createAgentRunOutcomeTracker } from "./interactive-controller-zE6hwv3C.js";
|
|
3
|
+
import { A as PROFILE_FILE_MOUNT_OUTSIDE_ROOTS_CODE, C as TimeoutError, M as SANDBOX_FILE_API_ABSOLUTE_ROOTS, N as isProfileFileMountOutsideRoots, O as SANDBOX_PROXY_REQUEST_MAX_BYTES, P as profileFileMountOutsideRootsMessage, S as StreamInterruptedError, _ as QuotaError, b as ServerError, g as ProfileFileMountPathError, i as AuthError, j as SANDBOX_AGENT_HOME, m as NotFoundError, n as parseResponseError, o as CapabilityError, p as NetworkError, r as readResponseJson, s as EdgeNotReadyError, t as parseErrorResponse, w as ValidationError, x as StateError, y as SandboxError } from "./errors-AB5BD3FM.js";
|
|
4
4
|
import { d as awaitWithAbort, f as combineAbortSignals, g as interactiveSessionStatusResponseSchema, h as interactiveSessionControlValidationResponseSchema, l as createInteractiveControlHolderId, m as interactiveSessionControlReleaseResponseSchema, p as interactiveSessionControlClaimResponseSchema } from "./browser-interactive-control-controller-BJf0P_J4.js";
|
|
5
|
-
import { n as fetchWithKeepAlive, t as emitTiming } from "./keep-alive-fetch-
|
|
5
|
+
import { n as fetchWithKeepAlive, t as emitTiming } from "./keep-alive-fetch-CXvfSczd.js";
|
|
6
6
|
import { SandboxLines } from "./lines.js";
|
|
7
7
|
import { r as cliAuthReferenceSchema } from "./cli-auth-bundle-CMgB8Ec3.js";
|
|
8
|
-
import { s as uploadChunked } from "./chunked-upload-
|
|
8
|
+
import { s as uploadChunked } from "./chunked-upload-KJyRCAiC.js";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { AgentExactRunControlRefSchema, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, InteractionAcknowledgementSchema, InteractionBindingSchema, InteractionRequestSchema, InteractionResponseCommandSchema, InteractionResponseSchema, PlanContinuationSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionStatusMatchesRef, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentProfileSchema, agentRunCancellationAcknowledgementMatchesRequest, canonicalCandidateDigest, canonicalCandidateJson, exactAgentInteractiveSessionStart, sha256DigestSchema, terminalSessionUsable } from "@tangle-network/agent-interface";
|
|
11
11
|
import { AgentInteractiveSessionControlClaimSchema as AgentInteractiveSessionControlClaimSchema$1, AgentInteractiveSessionPromptAcknowledgementSchema as AgentInteractiveSessionPromptAcknowledgementSchema$1, AgentInteractiveSessionRefSchema as AgentInteractiveSessionRefSchema$1, AgentInteractiveSessionStatusSchema, AgentInteractiveSessionStopAcknowledgementSchema as AgentInteractiveSessionStopAcknowledgementSchema$1 } from "@tangle-network/agent-interface/environment-interactive-control";
|
|
@@ -973,79 +973,6 @@ async function materializeAbsentProfileFiles(box, files, options) {
|
|
|
973
973
|
};
|
|
974
974
|
}
|
|
975
975
|
//#endregion
|
|
976
|
-
//#region ../../../packages/runtime-contracts/dist/sidecar-request.js
|
|
977
|
-
/**
|
|
978
|
-
* One normalizer for every edge route and host proxy, including preview ports.
|
|
979
|
-
* Decode URL data once, reject path syntax, then encode segment data for the
|
|
980
|
-
* next hop. A bounded safety probe rejects hidden traversal syntax without
|
|
981
|
-
* applying another decoding layer to filenames that are actually forwarded.
|
|
982
|
-
*/
|
|
983
|
-
function normalizeSidecarPathname(input) {
|
|
984
|
-
if (/[?#]/.test(input)) return null;
|
|
985
|
-
let decoded;
|
|
986
|
-
try {
|
|
987
|
-
decoded = decodeURIComponent(input);
|
|
988
|
-
} catch {
|
|
989
|
-
return null;
|
|
990
|
-
}
|
|
991
|
-
let probe = decoded;
|
|
992
|
-
for (let layer = 0; layer <= 8; layer++) {
|
|
993
|
-
if (probe.includes("\\") || [...probe].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127) || probe.split("/").some((segment) => segment === "." || segment === "..")) return null;
|
|
994
|
-
const next = probe.replace(/%(25|2e|2f|5c)/gi, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
|
|
995
|
-
if (next === probe) {
|
|
996
|
-
const pathname = decoded.split("/").map((segment) => encodeURIComponent(segment).replace(/%(3a|40|24|26|2b|2c|3b|3d)/gi, (escaped) => String.fromCharCode(Number.parseInt(escaped.slice(1), 16)))).join("/");
|
|
997
|
-
return {
|
|
998
|
-
path: decoded.replace(/^\/+|\/+$/g, ""),
|
|
999
|
-
pathname: `/${pathname.replace(/^\/+/, "")}`
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
if (layer === 8) return null;
|
|
1003
|
-
probe = next;
|
|
1004
|
-
}
|
|
1005
|
-
return null;
|
|
1006
|
-
}
|
|
1007
|
-
const EXEC_ROUTES = [
|
|
1008
|
-
{
|
|
1009
|
-
path: "exec",
|
|
1010
|
-
rateFamily: "process"
|
|
1011
|
-
},
|
|
1012
|
-
{
|
|
1013
|
-
path: "code/exec",
|
|
1014
|
-
rateFamily: "process"
|
|
1015
|
-
},
|
|
1016
|
-
{
|
|
1017
|
-
path: "process/spawn",
|
|
1018
|
-
rateFamily: "process"
|
|
1019
|
-
},
|
|
1020
|
-
{
|
|
1021
|
-
path: "process/ensure-dev-server",
|
|
1022
|
-
rateFamily: "process"
|
|
1023
|
-
},
|
|
1024
|
-
{
|
|
1025
|
-
path: "terminals/commands",
|
|
1026
|
-
rateFamily: "terminal"
|
|
1027
|
-
}
|
|
1028
|
-
];
|
|
1029
|
-
/** Classify once, before constructing a URL that could erase dot segments. */
|
|
1030
|
-
function classifySidecarRequest(input, method, upgrade = false) {
|
|
1031
|
-
const normalized = normalizeSidecarPathname(input);
|
|
1032
|
-
if (!normalized) return null;
|
|
1033
|
-
const { path, pathname } = normalized;
|
|
1034
|
-
const exec = method === "POST" && !upgrade ? EXEC_ROUTES.find((route) => route.path === path) : void 0;
|
|
1035
|
-
let auditAction = exec ? "sandbox.exec" : null;
|
|
1036
|
-
if (upgrade && /^terminals\/[^/]+\/ws$/.test(path)) auditAction = "sandbox.terminal.attach";
|
|
1037
|
-
else if (upgrade && path === "ssh") auditAction = "sandbox.ssh.open";
|
|
1038
|
-
else if (!upgrade && method === "POST" && path === "terminals") auditAction = "sandbox.terminal.attach";
|
|
1039
|
-
const rateFamily = exec?.rateFamily ?? (auditAction ? "terminal-open" : null) ?? (path === "process" || path.startsWith("process/") ? "process" : null);
|
|
1040
|
-
return {
|
|
1041
|
-
path,
|
|
1042
|
-
pathname,
|
|
1043
|
-
auditAction,
|
|
1044
|
-
rateFamily,
|
|
1045
|
-
shortTokenRequired: !!exec
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
//#endregion
|
|
1049
976
|
//#region src/lib/file-download.ts
|
|
1050
977
|
/** Retain only complete downloads; failed streams leave the destination intact. */
|
|
1051
978
|
async function downloadFile(request, localPath, options = {}) {
|
|
@@ -1291,6 +1218,158 @@ var ManagedProcessClient = class {
|
|
|
1291
1218
|
}
|
|
1292
1219
|
};
|
|
1293
1220
|
//#endregion
|
|
1221
|
+
//#region src/types/network.ts
|
|
1222
|
+
/** Largest `limit` the denials route accepts; it rejects anything above. */
|
|
1223
|
+
const MAX_EGRESS_DENIALS_LIMIT = 50;
|
|
1224
|
+
//#endregion
|
|
1225
|
+
//#region src/sandbox-egress-operations.ts
|
|
1226
|
+
/** Internal owner of the sandbox control-plane egress operations. */
|
|
1227
|
+
var SandboxEgressOperations = class {
|
|
1228
|
+
constructor(host) {
|
|
1229
|
+
this.host = host;
|
|
1230
|
+
}
|
|
1231
|
+
async egressGet() {
|
|
1232
|
+
const data = await readResponseJson(await this.host.fetch(`/v1/sandboxes/${encodeURIComponent(this.host.id())}`));
|
|
1233
|
+
return {
|
|
1234
|
+
policy: data.egressPolicy ?? { mode: "open" },
|
|
1235
|
+
source: data.egressPolicySource ?? "platform"
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
async egressUpdate(policy) {
|
|
1239
|
+
const data = await readResponseJson(await this.host.fetch(`/v1/sandboxes/${encodeURIComponent(this.host.id())}/egress`, {
|
|
1240
|
+
method: "PATCH",
|
|
1241
|
+
body: JSON.stringify(policy)
|
|
1242
|
+
}));
|
|
1243
|
+
this.host.adoptPolicy(data.egressPolicy, data.source);
|
|
1244
|
+
return {
|
|
1245
|
+
policy: data.egressPolicy,
|
|
1246
|
+
source: data.source
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
async egressDenials(options) {
|
|
1250
|
+
const limit = options?.limit;
|
|
1251
|
+
if (limit !== void 0) {
|
|
1252
|
+
if (!Number.isInteger(limit) || limit < 1) throw new ValidationError(`egress denials limit must be a positive integer, got ${limit}`);
|
|
1253
|
+
if (limit > 50) throw new ValidationError(`egress denials limit must be at most 50, got ${limit}`);
|
|
1254
|
+
}
|
|
1255
|
+
const query = limit === void 0 ? "" : `?limit=${encodeURIComponent(limit)}`;
|
|
1256
|
+
const response = await this.host.fetch(`/v1/sandboxes/${encodeURIComponent(this.host.id())}/egress/denials${query}`);
|
|
1257
|
+
if (!response.ok) throw await parseResponseError(response);
|
|
1258
|
+
const body = await readEgressJson(response, "Egress denials response was malformed: body is not valid JSON");
|
|
1259
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) throw new ServerError("Egress denials response was malformed: body is not an object", 502);
|
|
1260
|
+
const raw = body.denials;
|
|
1261
|
+
if (raw === void 0 || raw === null) return [];
|
|
1262
|
+
if (!Array.isArray(raw)) throw new ServerError("Egress denials response was malformed: denials is not a list", 502);
|
|
1263
|
+
const denials = [];
|
|
1264
|
+
for (const [index, entry] of raw.entries()) {
|
|
1265
|
+
const row = entry;
|
|
1266
|
+
if (typeof row !== "object" || row === null || typeof row.host !== "string" || typeof row.rejectedBy !== "string" || typeof row.count !== "number" || !Number.isInteger(row.count) || row.count < 0 || row.lastAt !== void 0 && row.lastAt !== null && typeof row.lastAt !== "string") throw new ServerError(`Egress denials response was malformed: entry ${index} is not a denial`, 502);
|
|
1267
|
+
denials.push(row.lastAt === void 0 || row.lastAt === null ? {
|
|
1268
|
+
host: row.host,
|
|
1269
|
+
rejectedBy: row.rejectedBy,
|
|
1270
|
+
count: row.count
|
|
1271
|
+
} : {
|
|
1272
|
+
host: row.host,
|
|
1273
|
+
rejectedBy: row.rejectedBy,
|
|
1274
|
+
count: row.count,
|
|
1275
|
+
lastAt: row.lastAt
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
return denials;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* This sandbox's egress for one calendar month, from the billing meter. A
|
|
1282
|
+
* malformed answer is a typed `ServerError`, never a defaulted zero: a
|
|
1283
|
+
* caller budgeting on it must not read a broken reply as no usage.
|
|
1284
|
+
*/
|
|
1285
|
+
async egressUsage(options) {
|
|
1286
|
+
const month = options?.month;
|
|
1287
|
+
if (month !== void 0 && !/^\d{4}-(0[1-9]|1[0-2])$/.test(month)) throw new ValidationError(`egress usage month must be YYYY-MM, got ${month}`);
|
|
1288
|
+
const query = month === void 0 ? "" : `?month=${encodeURIComponent(month)}`;
|
|
1289
|
+
const response = await this.host.fetch(`/v1/sandboxes/${encodeURIComponent(this.host.id())}/egress/usage${query}`);
|
|
1290
|
+
if (!response.ok) throw await parseResponseError(response);
|
|
1291
|
+
const body = await readEgressJson(response, "Egress usage response was malformed: body is not valid JSON");
|
|
1292
|
+
const usage = typeof body === "object" && body !== null && !Array.isArray(body) ? body.usage : void 0;
|
|
1293
|
+
const row = typeof usage === "object" && usage !== null && !Array.isArray(usage) ? usage : void 0;
|
|
1294
|
+
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
1295
|
+
const usd = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
1296
|
+
if (!row || typeof row.sandboxId !== "string" || typeof row.month !== "string" || row.plan !== "free" && row.plan !== "pro" && row.plan !== "enterprise" || !count(row.bytes) || !(row.includedBytes === null || count(row.includedBytes)) || !count(row.overageBytes) || !usd(row.chargeUsd) || !usd(row.usdPerGb) || !count(row.accountBytes) || !(row.accountCapBytes === null || count(row.accountCapBytes))) throw new ServerError("Egress usage response was malformed: usage is not a month record", 502);
|
|
1297
|
+
return {
|
|
1298
|
+
sandboxId: row.sandboxId,
|
|
1299
|
+
month: row.month,
|
|
1300
|
+
plan: row.plan,
|
|
1301
|
+
bytes: row.bytes,
|
|
1302
|
+
includedBytes: row.includedBytes,
|
|
1303
|
+
overageBytes: row.overageBytes,
|
|
1304
|
+
chargeUsd: row.chargeUsd,
|
|
1305
|
+
usdPerGb: row.usdPerGb,
|
|
1306
|
+
accountBytes: row.accountBytes,
|
|
1307
|
+
accountCapBytes: row.accountCapBytes
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
/**
|
|
1311
|
+
* What the sandbox reached, and whether that is decidable.
|
|
1312
|
+
*
|
|
1313
|
+
* Every malformed answer leaves as a typed `ServerError` rather than a
|
|
1314
|
+
* defaulted record. That matters more here than on `denials()`: a caller uses
|
|
1315
|
+
* this to establish a NEGATIVE claim, so inventing a `complete: true` record
|
|
1316
|
+
* from a broken response would manufacture the very proof it came for.
|
|
1317
|
+
*/
|
|
1318
|
+
async egressActivity(options) {
|
|
1319
|
+
const limit = options?.limit;
|
|
1320
|
+
if (limit !== void 0) {
|
|
1321
|
+
if (!Number.isInteger(limit) || limit < 1) throw new ValidationError(`egress activity limit must be a positive integer, got ${limit}`);
|
|
1322
|
+
if (limit > 500) throw new ValidationError(`egress activity limit must be at most 500, got ${limit}`);
|
|
1323
|
+
}
|
|
1324
|
+
const query = limit === void 0 ? "" : `?limit=${encodeURIComponent(limit)}`;
|
|
1325
|
+
const response = await this.host.fetch(`/v1/sandboxes/${encodeURIComponent(this.host.id())}/egress/activity${query}`);
|
|
1326
|
+
if (!response.ok) throw await parseResponseError(response);
|
|
1327
|
+
const body = await readEgressJson(response, "Egress activity response was malformed: body is not valid JSON");
|
|
1328
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) throw new ServerError("Egress activity response was malformed: body is not an object", 502);
|
|
1329
|
+
const raw = body.activity;
|
|
1330
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ServerError("Egress activity response was malformed: activity is not a record", 502);
|
|
1331
|
+
const record = raw;
|
|
1332
|
+
if (typeof record.complete !== "boolean" || typeof record.requestsObserved !== "number" || !Number.isInteger(record.requestsObserved) || record.requestsObserved < 0 || typeof record.unparsedLines !== "number" || !Number.isInteger(record.unparsedLines) || record.unparsedLines < 0 || !Array.isArray(record.destinations) || !Array.isArray(record.incompleteReasons) || !record.incompleteReasons.every((one) => typeof one === "string") || record.complete !== (record.incompleteReasons.length === 0)) throw new ServerError("Egress activity response was malformed: activity is not an activity record", 502);
|
|
1333
|
+
const destinations = [];
|
|
1334
|
+
for (const [index, entry] of record.destinations.entries()) {
|
|
1335
|
+
const row = entry;
|
|
1336
|
+
if (typeof row !== "object" || row === null || typeof row.host !== "string" || row.host.length === 0 || row.action !== "allow" && row.action !== "reject" || typeof row.count !== "number" || !Number.isInteger(row.count) || row.count < 0 || ![
|
|
1337
|
+
"firstAt",
|
|
1338
|
+
"lastAt",
|
|
1339
|
+
"rejectedBy"
|
|
1340
|
+
].every((field) => {
|
|
1341
|
+
const value = row[field];
|
|
1342
|
+
return value === void 0 || value === null || typeof value === "string";
|
|
1343
|
+
})) throw new ServerError(`Egress activity response was malformed: destination ${index} is not a destination`, 502);
|
|
1344
|
+
destinations.push({
|
|
1345
|
+
host: row.host,
|
|
1346
|
+
action: row.action,
|
|
1347
|
+
count: row.count,
|
|
1348
|
+
...typeof row.firstAt === "string" ? { firstAt: row.firstAt } : {},
|
|
1349
|
+
...typeof row.lastAt === "string" ? { lastAt: row.lastAt } : {},
|
|
1350
|
+
...typeof row.rejectedBy === "string" ? { rejectedBy: row.rejectedBy } : {}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
destinations,
|
|
1355
|
+
requestsObserved: record.requestsObserved,
|
|
1356
|
+
unparsedLines: record.unparsedLines,
|
|
1357
|
+
complete: record.complete,
|
|
1358
|
+
incompleteReasons: record.incompleteReasons
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
/** Preserve the endpoint's malformed-JSON error and original cause. */
|
|
1363
|
+
async function readEgressJson(response, message) {
|
|
1364
|
+
try {
|
|
1365
|
+
return await response.json();
|
|
1366
|
+
} catch (cause) {
|
|
1367
|
+
const error = new ServerError(message, 502);
|
|
1368
|
+
error.cause = cause;
|
|
1369
|
+
throw error;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
//#endregion
|
|
1294
1373
|
//#region src/capabilities.ts
|
|
1295
1374
|
function invalidCapabilities(message) {
|
|
1296
1375
|
throw new ServerError(`Capability discovery returned ${message}`, 502, {
|
|
@@ -1678,6 +1757,310 @@ var DirectReadRoute = class {
|
|
|
1678
1757
|
}
|
|
1679
1758
|
};
|
|
1680
1759
|
//#endregion
|
|
1760
|
+
//#region ../../../packages/runtime-contracts/dist/sidecar-proxy-error.js
|
|
1761
|
+
/**
|
|
1762
|
+
* Response header that the host-agent sidecar proxy puts on each error it
|
|
1763
|
+
* writes itself. The value is the host-agent error code, for example
|
|
1764
|
+
* `NOT_MANAGED` or `ROUTE_LOOKUP_FAILED`.
|
|
1765
|
+
*
|
|
1766
|
+
* The orchestrator reaches a sidecar only through the host-agent sidecar
|
|
1767
|
+
* proxy. Thus two services write errors on that path. They use the same
|
|
1768
|
+
* statuses (404, 502, 503, 504) and the same `{error, code}` JSON body. This
|
|
1769
|
+
* header names the author of the response. If the header is present, the
|
|
1770
|
+
* host-agent wrote the response. If the header is absent, the sidecar wrote
|
|
1771
|
+
* the response.
|
|
1772
|
+
*
|
|
1773
|
+
* The orchestrator invalidates the endpoint and sends the request again only
|
|
1774
|
+
* for a host-agent error. A sidecar error is an ordinary answer, and a new
|
|
1775
|
+
* endpoint cannot change it.
|
|
1776
|
+
*
|
|
1777
|
+
* The host-agent deletes this header from an upstream response before it
|
|
1778
|
+
* returns that response. A sidecar must not be able to set the header. A
|
|
1779
|
+
* tenant preview app on an in-container port must not be able to set it.
|
|
1780
|
+
*/
|
|
1781
|
+
const SIDECAR_PROXY_ERROR_HEADER = "X-Tangle-Sidecar-Proxy-Error";
|
|
1782
|
+
//#endregion
|
|
1783
|
+
//#region ../../../packages/runtime-contracts/dist/sidecar-request.js
|
|
1784
|
+
/**
|
|
1785
|
+
* One normalizer for every edge route and host proxy, including preview ports.
|
|
1786
|
+
* Decode URL data once, reject path syntax, then encode segment data for the
|
|
1787
|
+
* next hop. A bounded safety probe rejects hidden traversal syntax without
|
|
1788
|
+
* applying another decoding layer to filenames that are actually forwarded.
|
|
1789
|
+
*/
|
|
1790
|
+
function normalizeSidecarPathname(input) {
|
|
1791
|
+
if (/[?#]/.test(input)) return null;
|
|
1792
|
+
let decoded;
|
|
1793
|
+
try {
|
|
1794
|
+
decoded = decodeURIComponent(input);
|
|
1795
|
+
} catch {
|
|
1796
|
+
return null;
|
|
1797
|
+
}
|
|
1798
|
+
let probe = decoded;
|
|
1799
|
+
for (let layer = 0; layer <= 8; layer++) {
|
|
1800
|
+
if (probe.includes("\\") || [...probe].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127) || probe.split("/").some((segment) => segment === "." || segment === "..")) return null;
|
|
1801
|
+
const next = probe.replace(/%(25|2e|2f|5c)/gi, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
|
|
1802
|
+
if (next === probe) {
|
|
1803
|
+
const pathname = decoded.split("/").map((segment) => encodeURIComponent(segment).replace(/%(3a|40|24|26|2b|2c|3b|3d)/gi, (escaped) => String.fromCharCode(Number.parseInt(escaped.slice(1), 16)))).join("/");
|
|
1804
|
+
return {
|
|
1805
|
+
path: decoded.replace(/^\/+|\/+$/g, ""),
|
|
1806
|
+
pathname: `/${pathname.replace(/^\/+/, "")}`
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
if (layer === 8) return null;
|
|
1810
|
+
probe = next;
|
|
1811
|
+
}
|
|
1812
|
+
return null;
|
|
1813
|
+
}
|
|
1814
|
+
const EXEC_ROUTES = [
|
|
1815
|
+
{
|
|
1816
|
+
path: "exec",
|
|
1817
|
+
rateFamily: "process"
|
|
1818
|
+
},
|
|
1819
|
+
{
|
|
1820
|
+
path: "code/exec",
|
|
1821
|
+
rateFamily: "process"
|
|
1822
|
+
},
|
|
1823
|
+
{
|
|
1824
|
+
path: "process/spawn",
|
|
1825
|
+
rateFamily: "process"
|
|
1826
|
+
},
|
|
1827
|
+
{
|
|
1828
|
+
path: "process/ensure-dev-server",
|
|
1829
|
+
rateFamily: "process"
|
|
1830
|
+
},
|
|
1831
|
+
{
|
|
1832
|
+
path: "terminals/commands",
|
|
1833
|
+
rateFamily: "terminal"
|
|
1834
|
+
}
|
|
1835
|
+
];
|
|
1836
|
+
/** Classify once, before constructing a URL that could erase dot segments. */
|
|
1837
|
+
function classifySidecarRequest(input, method, upgrade = false) {
|
|
1838
|
+
const normalized = normalizeSidecarPathname(input);
|
|
1839
|
+
if (!normalized) return null;
|
|
1840
|
+
const { path, pathname } = normalized;
|
|
1841
|
+
const exec = method === "POST" && !upgrade ? EXEC_ROUTES.find((route) => route.path === path) : void 0;
|
|
1842
|
+
let auditAction = exec ? "sandbox.exec" : null;
|
|
1843
|
+
if (upgrade && /^terminals\/[^/]+\/ws$/.test(path)) auditAction = "sandbox.terminal.attach";
|
|
1844
|
+
else if (upgrade && path === "ssh") auditAction = "sandbox.ssh.open";
|
|
1845
|
+
else if (!upgrade && method === "POST" && path === "terminals") auditAction = "sandbox.terminal.attach";
|
|
1846
|
+
const rateFamily = exec?.rateFamily ?? (auditAction ? "terminal-open" : null) ?? (path === "process" || path.startsWith("process/") ? "process" : null);
|
|
1847
|
+
return {
|
|
1848
|
+
path,
|
|
1849
|
+
pathname,
|
|
1850
|
+
auditAction,
|
|
1851
|
+
rateFamily,
|
|
1852
|
+
shortTokenRequired: !!exec
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
//#endregion
|
|
1856
|
+
//#region src/direct-runtime-client.ts
|
|
1857
|
+
/**
|
|
1858
|
+
* The SDK's direct runtime transport: exec-family calls sent straight to the
|
|
1859
|
+
* sandbox's cell on its short exec grant, everything else through the API.
|
|
1860
|
+
* `SandboxInstance.direct()` uses it for every runtime call; every default
|
|
1861
|
+
* handle uses it in exec-only mode (`SandboxConfig.directExec`).
|
|
1862
|
+
*/
|
|
1863
|
+
/** Renew an exec grant this close to its expiry before sending it. */
|
|
1864
|
+
const EXEC_GRANT_RENEW_BEFORE_MS = 5e3;
|
|
1865
|
+
function execGrantExpiresSoon(expiresAt) {
|
|
1866
|
+
if (!expiresAt) return false;
|
|
1867
|
+
const at = Date.parse(expiresAt);
|
|
1868
|
+
return Number.isFinite(at) && at - Date.now() < EXEC_GRANT_RENEW_BEFORE_MS;
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Host-agent refusals answered before it forwards anything to the sidecar
|
|
1872
|
+
* (apps/host-agent/src/routes/runtime-sidecar-proxy.ts): the box is not on
|
|
1873
|
+
* this host, has no address, its route could not be read, or the access
|
|
1874
|
+
* record could not be written.
|
|
1875
|
+
*/
|
|
1876
|
+
const UNDELIVERED_HOST_REFUSALS = new Set([
|
|
1877
|
+
"NOT_MANAGED",
|
|
1878
|
+
"NO_IP",
|
|
1879
|
+
"ROUTE_LOOKUP_FAILED",
|
|
1880
|
+
"DIRECT_ACCESS_AUDIT_UNAVAILABLE"
|
|
1881
|
+
]);
|
|
1882
|
+
/**
|
|
1883
|
+
* True only when the direct exec never reached the sidecar: the edge has no
|
|
1884
|
+
* route for the box (404 `unknown_host`), or the host refused it before
|
|
1885
|
+
* forwarding. Reads a clone, so the caller keeps the body.
|
|
1886
|
+
*/
|
|
1887
|
+
async function isUndeliveredExecRefusal(response) {
|
|
1888
|
+
const hostCode = response.headers.get(SIDECAR_PROXY_ERROR_HEADER);
|
|
1889
|
+
if (hostCode) return UNDELIVERED_HOST_REFUSALS.has(hostCode);
|
|
1890
|
+
if (response.status !== 404) return false;
|
|
1891
|
+
try {
|
|
1892
|
+
return (await response.clone().json()).reason === "unknown_host";
|
|
1893
|
+
} catch {
|
|
1894
|
+
return false;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* A runtime refusal that says the sandbox is not there to answer: the edge
|
|
1899
|
+
* has no route for the box (`unknown_host`), or the proxy could not reach its
|
|
1900
|
+
* sidecar (502, 503). These are the answers a stale cached `running` earns.
|
|
1901
|
+
*/
|
|
1902
|
+
async function isRuntimeUnreachable(response) {
|
|
1903
|
+
if (response.status === 502 || response.status === 503) return true;
|
|
1904
|
+
if (response.status !== 404) return false;
|
|
1905
|
+
try {
|
|
1906
|
+
return (await response.clone().json()).reason === "unknown_host";
|
|
1907
|
+
} catch {
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
var DirectRuntimeHttpClient = class {
|
|
1912
|
+
baseClient;
|
|
1913
|
+
sandboxId;
|
|
1914
|
+
getConnection;
|
|
1915
|
+
onUnauthorized;
|
|
1916
|
+
onUnreachable;
|
|
1917
|
+
/**
|
|
1918
|
+
* The default mode: only exec-family calls holding an exec grant go
|
|
1919
|
+
* direct, and a call the cell cannot serve is sent again through the API.
|
|
1920
|
+
* Without it (`SandboxInstance.direct()`) every runtime call goes direct.
|
|
1921
|
+
*/
|
|
1922
|
+
execOnly;
|
|
1923
|
+
constructor(baseClient, sandboxId, getConnection, onUnauthorized, onUnreachable, options = {}) {
|
|
1924
|
+
this.baseClient = baseClient;
|
|
1925
|
+
this.sandboxId = sandboxId;
|
|
1926
|
+
this.getConnection = getConnection;
|
|
1927
|
+
this.onUnauthorized = onUnauthorized;
|
|
1928
|
+
this.onUnreachable = onUnreachable;
|
|
1929
|
+
this.execOnly = options.execOnly === true;
|
|
1930
|
+
}
|
|
1931
|
+
get onTiming() {
|
|
1932
|
+
return this.baseClient.onTiming;
|
|
1933
|
+
}
|
|
1934
|
+
get directExec() {
|
|
1935
|
+
return this.baseClient.directExec;
|
|
1936
|
+
}
|
|
1937
|
+
get isExecOnly() {
|
|
1938
|
+
return this.execOnly;
|
|
1939
|
+
}
|
|
1940
|
+
/** The API client this wrapper falls back to. */
|
|
1941
|
+
get apiClient() {
|
|
1942
|
+
return this.baseClient;
|
|
1943
|
+
}
|
|
1944
|
+
getApiKey() {
|
|
1945
|
+
return this.baseClient.getApiKey?.();
|
|
1946
|
+
}
|
|
1947
|
+
getBaseUrl() {
|
|
1948
|
+
return this.baseClient.getBaseUrl?.();
|
|
1949
|
+
}
|
|
1950
|
+
/** Token-refresh subscribers live on the client that created the sandbox. */
|
|
1951
|
+
_emitTokenRefresh(sandboxId, newToken) {
|
|
1952
|
+
this.baseClient._emitTokenRefresh?.(sandboxId, newToken);
|
|
1953
|
+
}
|
|
1954
|
+
async fetch(path, options, fetchOptions) {
|
|
1955
|
+
const runtimePrefix = `/v1/sandboxes/${encodeURIComponent(this.sandboxId)}/runtime`;
|
|
1956
|
+
if (!path.startsWith(runtimePrefix)) return this.baseClient.fetch(path, options, fetchOptions);
|
|
1957
|
+
const runtimePath = path.slice(runtimePrefix.length);
|
|
1958
|
+
if (runtimePath === "/network" || runtimePath.startsWith("/network/") || runtimePath === "/preview-links" || runtimePath.startsWith("/preview-links/")) return this.baseClient.fetch(path, options, fetchOptions);
|
|
1959
|
+
const command = classifySidecarRequest(runtimePath.split("?")[0], options?.method ?? "GET");
|
|
1960
|
+
if (!command) {
|
|
1961
|
+
if (this.execOnly) return this.baseClient.fetch(path, options, fetchOptions);
|
|
1962
|
+
throw new NetworkError("Invalid direct runtime path");
|
|
1963
|
+
}
|
|
1964
|
+
const selectRoute = () => {
|
|
1965
|
+
const connection = this.getConnection();
|
|
1966
|
+
const useExec = command.shortTokenRequired && !!connection?.execHost && !!connection.execToken;
|
|
1967
|
+
if (command.shortTokenRequired && !useExec) return void 0;
|
|
1968
|
+
if (this.execOnly && !useExec) return void 0;
|
|
1969
|
+
const origin = useExec ? connection?.execHost : connection?.runtimeUrl;
|
|
1970
|
+
if (!origin) return void 0;
|
|
1971
|
+
return {
|
|
1972
|
+
useExec,
|
|
1973
|
+
url: `${origin.replace(/\/$/, "")}${runtimePath}`,
|
|
1974
|
+
bearer: useExec ? connection?.execToken : connection?.authToken
|
|
1975
|
+
};
|
|
1976
|
+
};
|
|
1977
|
+
let route = selectRoute();
|
|
1978
|
+
if (!route) return this.baseClient.fetch(path, options, fetchOptions);
|
|
1979
|
+
if (this.execOnly && route.useExec && this.onUnauthorized && execGrantExpiresSoon(this.getConnection()?.execTokenExpiresAt)) {
|
|
1980
|
+
try {
|
|
1981
|
+
await this.onUnauthorized();
|
|
1982
|
+
} catch {
|
|
1983
|
+
return this.baseClient.fetch(path, options, fetchOptions);
|
|
1984
|
+
}
|
|
1985
|
+
route = selectRoute();
|
|
1986
|
+
if (!route) return this.baseClient.fetch(path, options, fetchOptions);
|
|
1987
|
+
}
|
|
1988
|
+
const canResendThroughApi = this.execOnly && (options?.body === void 0 || options.body === null || typeof options.body === "string");
|
|
1989
|
+
const headers = new Headers(options?.headers);
|
|
1990
|
+
const authenticate = () => {
|
|
1991
|
+
headers.delete("Authorization");
|
|
1992
|
+
headers.delete("X-Tangle-Sandbox-Ref");
|
|
1993
|
+
if (route?.useExec) headers.set("X-Tangle-Sandbox-Ref", this.sandboxId);
|
|
1994
|
+
if (route?.bearer) headers.set("Authorization", `Bearer ${route.bearer}`);
|
|
1995
|
+
};
|
|
1996
|
+
authenticate();
|
|
1997
|
+
const isFormDataBody = typeof FormData !== "undefined" && options?.body instanceof FormData;
|
|
1998
|
+
if (!headers.has("Content-Type") && !isFormDataBody) headers.set("Content-Type", "application/json");
|
|
1999
|
+
const init = {
|
|
2000
|
+
...options,
|
|
2001
|
+
headers
|
|
2002
|
+
};
|
|
2003
|
+
if (options?.body && typeof options.body === "object" && !isFormDataBody) init.duplex = "half";
|
|
2004
|
+
const directTimeoutMs = fetchOptions?.timeoutMs;
|
|
2005
|
+
if (!init.signal && typeof directTimeoutMs === "number" && directTimeoutMs > 0) init.signal = AbortSignal.timeout(directTimeoutMs);
|
|
2006
|
+
const send = async (request) => {
|
|
2007
|
+
const timing = {
|
|
2008
|
+
onTiming: this.onTiming,
|
|
2009
|
+
path
|
|
2010
|
+
};
|
|
2011
|
+
if (!route) throw new NetworkError("Direct runtime route was withdrawn");
|
|
2012
|
+
if (route.useExec && canUseNodeHttp2()) {
|
|
2013
|
+
const { fetchDirectHttp2 } = await import("./direct-http2-Dq7tq6jV.js");
|
|
2014
|
+
return fetchDirectHttp2(route.url, request, timing);
|
|
2015
|
+
}
|
|
2016
|
+
return fetchWithKeepAlive(route.url, request, timing);
|
|
2017
|
+
};
|
|
2018
|
+
let response = await send(init);
|
|
2019
|
+
if ((response.status === 401 || response.status === 403 && await isRefusedBearer(response)) && this.onUnauthorized && !headers.has("x-no-retry")) {
|
|
2020
|
+
const refusal = {
|
|
2021
|
+
status: response.status,
|
|
2022
|
+
statusText: response.statusText,
|
|
2023
|
+
headers: new Headers(response.headers)
|
|
2024
|
+
};
|
|
2025
|
+
const refusedBody = await response.arrayBuffer().catch(() => null);
|
|
2026
|
+
try {
|
|
2027
|
+
await this.onUnauthorized();
|
|
2028
|
+
} catch {
|
|
2029
|
+
if (canResendThroughApi) return this.baseClient.fetch(path, options, fetchOptions);
|
|
2030
|
+
return new Response(refusedBody, refusal);
|
|
2031
|
+
}
|
|
2032
|
+
route = selectRoute();
|
|
2033
|
+
if (!route) return this.baseClient.fetch(path, options, fetchOptions);
|
|
2034
|
+
authenticate();
|
|
2035
|
+
response = await send({
|
|
2036
|
+
...init,
|
|
2037
|
+
headers
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
if (canResendThroughApi && route?.useExec && !headers.has("x-no-retry") && await isUndeliveredExecRefusal(response)) {
|
|
2041
|
+
await response.body?.cancel().catch(() => {});
|
|
2042
|
+
return this.baseClient.fetch(path, options, fetchOptions);
|
|
2043
|
+
}
|
|
2044
|
+
if (this.onUnreachable && await isRuntimeUnreachable(response)) await this.onUnreachable();
|
|
2045
|
+
const responseHeaders = new Headers(response.headers);
|
|
2046
|
+
responseHeaders.set("x-tangle-request-path", path);
|
|
2047
|
+
if (options?.method) responseHeaders.set("x-tangle-request-method", options.method);
|
|
2048
|
+
return rewrapResponse(response, responseHeaders);
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
/**
|
|
2052
|
+
* True when a 403 is the sidecar refusing the bearer itself, not a bearer
|
|
2053
|
+
* that lacks a capability. Reads a clone, so the caller keeps the body.
|
|
2054
|
+
*/
|
|
2055
|
+
async function isRefusedBearer(response) {
|
|
2056
|
+
try {
|
|
2057
|
+
const body = await response.clone().json();
|
|
2058
|
+
return body.error?.code === "FORBIDDEN" && body.error.message === "Invalid authentication token";
|
|
2059
|
+
} catch {
|
|
2060
|
+
return false;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
//#endregion
|
|
1681
2064
|
//#region ../../../packages/runtime-contracts/dist/interaction-response.js
|
|
1682
2065
|
/** Durable states reported for a recorded interaction response. */
|
|
1683
2066
|
const interactionResolutionDeliveryStateSchema = z.enum([
|
|
@@ -4131,10 +4514,6 @@ var SandboxTaskSession = class extends SandboxSession {
|
|
|
4131
4514
|
}
|
|
4132
4515
|
};
|
|
4133
4516
|
//#endregion
|
|
4134
|
-
//#region src/types/network.ts
|
|
4135
|
-
/** Largest `limit` the denials route accepts; it rejects anything above. */
|
|
4136
|
-
const MAX_EGRESS_DENIALS_LIMIT = 50;
|
|
4137
|
-
//#endregion
|
|
4138
4517
|
//#region src/workspace-images.ts
|
|
4139
4518
|
const DEFAULT_WORKSPACE_IMAGE_CLIENT_TIMEOUT_MS = 99e4;
|
|
4140
4519
|
const WORKSPACE_IMAGE_REQUEST_ATTEMPTS = 2;
|
|
@@ -4788,20 +5167,6 @@ const REFRESH_REASON_HEADER = "x-tangle-refresh-reason";
|
|
|
4788
5167
|
function sendsRefreshReason() {
|
|
4789
5168
|
return !("document" in globalThis);
|
|
4790
5169
|
}
|
|
4791
|
-
/**
|
|
4792
|
-
* A runtime refusal that says the sandbox is not there to answer: the edge
|
|
4793
|
-
* has no route for the box (`unknown_host`), or the proxy could not reach its
|
|
4794
|
-
* sidecar (502, 503). These are the answers a stale cached `running` earns.
|
|
4795
|
-
*/
|
|
4796
|
-
async function isRuntimeUnreachable(response) {
|
|
4797
|
-
if (response.status === 502 || response.status === 503) return true;
|
|
4798
|
-
if (response.status !== 404) return false;
|
|
4799
|
-
try {
|
|
4800
|
-
return (await response.clone().json()).reason === "unknown_host";
|
|
4801
|
-
} catch {
|
|
4802
|
-
return false;
|
|
4803
|
-
}
|
|
4804
|
-
}
|
|
4805
5170
|
function readFilesystemIncarnationTuple(value) {
|
|
4806
5171
|
const rawId = value.filesystemIncarnationId;
|
|
4807
5172
|
const rawProvenance = value.filesystemIncarnationProvenance;
|
|
@@ -4817,7 +5182,11 @@ function readFilesystemIncarnationTuple(value) {
|
|
|
4817
5182
|
};
|
|
4818
5183
|
}
|
|
4819
5184
|
function createSandboxInstanceFromResponse(client, info, defaultRuntimeBackend, raw) {
|
|
4820
|
-
|
|
5185
|
+
let instance;
|
|
5186
|
+
const apiClient = client instanceof DirectRuntimeHttpClient && client.isExecOnly ? client.apiClient : client;
|
|
5187
|
+
instance = new SandboxInstance(apiClient.directExec === false || apiClient instanceof DirectRuntimeHttpClient ? apiClient : new DirectRuntimeHttpClient(apiClient, info.id, () => instance.connection, async () => {
|
|
5188
|
+
await instance.refresh();
|
|
5189
|
+
}, void 0, { execOnly: true }), info, defaultRuntimeBackend);
|
|
4821
5190
|
if (raw) instance.adoptDirectRead(raw);
|
|
4822
5191
|
sandboxStatusObservedAt.set(instance, Date.now());
|
|
4823
5192
|
return instance;
|
|
@@ -4877,6 +5246,17 @@ function timerMsViolation(value) {
|
|
|
4877
5246
|
*/
|
|
4878
5247
|
var SandboxInstance = class SandboxInstance {
|
|
4879
5248
|
#client;
|
|
5249
|
+
#egressOperations = new SandboxEgressOperations({
|
|
5250
|
+
id: () => this.id,
|
|
5251
|
+
fetch: (...args) => this.#client.fetch(...args),
|
|
5252
|
+
adoptPolicy: (policy, source) => {
|
|
5253
|
+
this.#info = {
|
|
5254
|
+
...this.#info,
|
|
5255
|
+
egressPolicy: policy,
|
|
5256
|
+
egressPolicySource: source
|
|
5257
|
+
};
|
|
5258
|
+
}
|
|
5259
|
+
});
|
|
4880
5260
|
#info;
|
|
4881
5261
|
refreshInFlight;
|
|
4882
5262
|
#defaultRuntimeBackend;
|
|
@@ -6741,7 +7121,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
6741
7121
|
totalBytes: size,
|
|
6742
7122
|
percentage: 0
|
|
6743
7123
|
});
|
|
6744
|
-
const { uploadChunkedFromFile } = await import("./chunked-upload-file-
|
|
7124
|
+
const { uploadChunkedFromFile } = await import("./chunked-upload-file-DfiGzqaR.js");
|
|
6745
7125
|
await uploadChunkedFromFile({ fetch: (path, init) => this.runtimeFetch(path, init) }, remotePath, localPath, {
|
|
6746
7126
|
mode: options?.permissions,
|
|
6747
7127
|
onProgress: options?.onProgress ? (progress) => {
|
|
@@ -7456,64 +7836,13 @@ var SandboxInstance = class SandboxInstance {
|
|
|
7456
7836
|
return await readResponseJson(await this.runtimeFetch("/network"));
|
|
7457
7837
|
}
|
|
7458
7838
|
async egressGet() {
|
|
7459
|
-
|
|
7460
|
-
return {
|
|
7461
|
-
policy: data.egressPolicy ?? { mode: "open" },
|
|
7462
|
-
source: data.egressPolicySource ?? "platform"
|
|
7463
|
-
};
|
|
7839
|
+
return this.#egressOperations.egressGet();
|
|
7464
7840
|
}
|
|
7465
7841
|
async egressUpdate(policy) {
|
|
7466
|
-
|
|
7467
|
-
method: "PATCH",
|
|
7468
|
-
body: JSON.stringify(policy)
|
|
7469
|
-
}));
|
|
7470
|
-
this.#info = {
|
|
7471
|
-
...this.#info,
|
|
7472
|
-
egressPolicy: data.egressPolicy,
|
|
7473
|
-
egressPolicySource: data.source
|
|
7474
|
-
};
|
|
7475
|
-
return {
|
|
7476
|
-
policy: data.egressPolicy,
|
|
7477
|
-
source: data.source
|
|
7478
|
-
};
|
|
7842
|
+
return this.#egressOperations.egressUpdate(policy);
|
|
7479
7843
|
}
|
|
7480
7844
|
async egressDenials(options) {
|
|
7481
|
-
|
|
7482
|
-
if (limit !== void 0) {
|
|
7483
|
-
if (!Number.isInteger(limit) || limit < 1) throw new ValidationError(`egress denials limit must be a positive integer, got ${limit}`);
|
|
7484
|
-
if (limit > 50) throw new ValidationError(`egress denials limit must be at most 50, got ${limit}`);
|
|
7485
|
-
}
|
|
7486
|
-
const query = limit === void 0 ? "" : `?limit=${encodeURIComponent(limit)}`;
|
|
7487
|
-
const response = await this.#client.fetch(`/v1/sandboxes/${encodeURIComponent(this.id)}/egress/denials${query}`);
|
|
7488
|
-
if (!response.ok) throw await parseResponseError(response);
|
|
7489
|
-
let body;
|
|
7490
|
-
try {
|
|
7491
|
-
body = await response.json();
|
|
7492
|
-
} catch (cause) {
|
|
7493
|
-
const error = new ServerError("Egress denials response was malformed: body is not valid JSON", 502);
|
|
7494
|
-
error.cause = cause;
|
|
7495
|
-
throw error;
|
|
7496
|
-
}
|
|
7497
|
-
if (typeof body !== "object" || body === null || Array.isArray(body)) throw new ServerError("Egress denials response was malformed: body is not an object", 502);
|
|
7498
|
-
const raw = body.denials;
|
|
7499
|
-
if (raw === void 0 || raw === null) return [];
|
|
7500
|
-
if (!Array.isArray(raw)) throw new ServerError("Egress denials response was malformed: denials is not a list", 502);
|
|
7501
|
-
const denials = [];
|
|
7502
|
-
for (const [index, entry] of raw.entries()) {
|
|
7503
|
-
const row = entry;
|
|
7504
|
-
if (typeof row !== "object" || row === null || typeof row.host !== "string" || typeof row.rejectedBy !== "string" || typeof row.count !== "number" || !Number.isInteger(row.count) || row.count < 0 || row.lastAt !== void 0 && row.lastAt !== null && typeof row.lastAt !== "string") throw new ServerError(`Egress denials response was malformed: entry ${index} is not a denial`, 502);
|
|
7505
|
-
denials.push(row.lastAt === void 0 || row.lastAt === null ? {
|
|
7506
|
-
host: row.host,
|
|
7507
|
-
rejectedBy: row.rejectedBy,
|
|
7508
|
-
count: row.count
|
|
7509
|
-
} : {
|
|
7510
|
-
host: row.host,
|
|
7511
|
-
rejectedBy: row.rejectedBy,
|
|
7512
|
-
count: row.count,
|
|
7513
|
-
lastAt: row.lastAt
|
|
7514
|
-
});
|
|
7515
|
-
}
|
|
7516
|
-
return denials;
|
|
7845
|
+
return this.#egressOperations.egressDenials(options);
|
|
7517
7846
|
}
|
|
7518
7847
|
/**
|
|
7519
7848
|
* This sandbox's egress for one calendar month, from the billing meter. A
|
|
@@ -7521,36 +7850,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
7521
7850
|
* caller budgeting on it must not read a broken reply as no usage.
|
|
7522
7851
|
*/
|
|
7523
7852
|
async egressUsage(options) {
|
|
7524
|
-
|
|
7525
|
-
if (month !== void 0 && !/^\d{4}-(0[1-9]|1[0-2])$/.test(month)) throw new ValidationError(`egress usage month must be YYYY-MM, got ${month}`);
|
|
7526
|
-
const query = month === void 0 ? "" : `?month=${encodeURIComponent(month)}`;
|
|
7527
|
-
const response = await this.#client.fetch(`/v1/sandboxes/${encodeURIComponent(this.id)}/egress/usage${query}`);
|
|
7528
|
-
if (!response.ok) throw await parseResponseError(response);
|
|
7529
|
-
let body;
|
|
7530
|
-
try {
|
|
7531
|
-
body = await response.json();
|
|
7532
|
-
} catch (cause) {
|
|
7533
|
-
const error = new ServerError("Egress usage response was malformed: body is not valid JSON", 502);
|
|
7534
|
-
error.cause = cause;
|
|
7535
|
-
throw error;
|
|
7536
|
-
}
|
|
7537
|
-
const usage = typeof body === "object" && body !== null && !Array.isArray(body) ? body.usage : void 0;
|
|
7538
|
-
const row = typeof usage === "object" && usage !== null && !Array.isArray(usage) ? usage : void 0;
|
|
7539
|
-
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
7540
|
-
const usd = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
7541
|
-
if (!row || typeof row.sandboxId !== "string" || typeof row.month !== "string" || row.plan !== "free" && row.plan !== "pro" && row.plan !== "enterprise" || !count(row.bytes) || !(row.includedBytes === null || count(row.includedBytes)) || !count(row.overageBytes) || !usd(row.chargeUsd) || !usd(row.usdPerGb) || !count(row.accountBytes) || !(row.accountCapBytes === null || count(row.accountCapBytes))) throw new ServerError("Egress usage response was malformed: usage is not a month record", 502);
|
|
7542
|
-
return {
|
|
7543
|
-
sandboxId: row.sandboxId,
|
|
7544
|
-
month: row.month,
|
|
7545
|
-
plan: row.plan,
|
|
7546
|
-
bytes: row.bytes,
|
|
7547
|
-
includedBytes: row.includedBytes,
|
|
7548
|
-
overageBytes: row.overageBytes,
|
|
7549
|
-
chargeUsd: row.chargeUsd,
|
|
7550
|
-
usdPerGb: row.usdPerGb,
|
|
7551
|
-
accountBytes: row.accountBytes,
|
|
7552
|
-
accountCapBytes: row.accountCapBytes
|
|
7553
|
-
};
|
|
7853
|
+
return this.#egressOperations.egressUsage(options);
|
|
7554
7854
|
}
|
|
7555
7855
|
/**
|
|
7556
7856
|
* What the sandbox reached, and whether that is decidable.
|
|
@@ -7561,54 +7861,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
7561
7861
|
* from a broken response would manufacture the very proof it came for.
|
|
7562
7862
|
*/
|
|
7563
7863
|
async egressActivity(options) {
|
|
7564
|
-
|
|
7565
|
-
if (limit !== void 0) {
|
|
7566
|
-
if (!Number.isInteger(limit) || limit < 1) throw new ValidationError(`egress activity limit must be a positive integer, got ${limit}`);
|
|
7567
|
-
if (limit > 500) throw new ValidationError(`egress activity limit must be at most 500, got ${limit}`);
|
|
7568
|
-
}
|
|
7569
|
-
const query = limit === void 0 ? "" : `?limit=${encodeURIComponent(limit)}`;
|
|
7570
|
-
const response = await this.#client.fetch(`/v1/sandboxes/${encodeURIComponent(this.id)}/egress/activity${query}`);
|
|
7571
|
-
if (!response.ok) throw await parseResponseError(response);
|
|
7572
|
-
let body;
|
|
7573
|
-
try {
|
|
7574
|
-
body = await response.json();
|
|
7575
|
-
} catch (cause) {
|
|
7576
|
-
const error = new ServerError("Egress activity response was malformed: body is not valid JSON", 502);
|
|
7577
|
-
error.cause = cause;
|
|
7578
|
-
throw error;
|
|
7579
|
-
}
|
|
7580
|
-
if (typeof body !== "object" || body === null || Array.isArray(body)) throw new ServerError("Egress activity response was malformed: body is not an object", 502);
|
|
7581
|
-
const raw = body.activity;
|
|
7582
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ServerError("Egress activity response was malformed: activity is not a record", 502);
|
|
7583
|
-
const record = raw;
|
|
7584
|
-
if (typeof record.complete !== "boolean" || typeof record.requestsObserved !== "number" || !Number.isInteger(record.requestsObserved) || record.requestsObserved < 0 || typeof record.unparsedLines !== "number" || !Number.isInteger(record.unparsedLines) || record.unparsedLines < 0 || !Array.isArray(record.destinations) || !Array.isArray(record.incompleteReasons) || !record.incompleteReasons.every((one) => typeof one === "string") || record.complete !== (record.incompleteReasons.length === 0)) throw new ServerError("Egress activity response was malformed: activity is not an activity record", 502);
|
|
7585
|
-
const destinations = [];
|
|
7586
|
-
for (const [index, entry] of record.destinations.entries()) {
|
|
7587
|
-
const row = entry;
|
|
7588
|
-
if (typeof row !== "object" || row === null || typeof row.host !== "string" || row.host.length === 0 || row.action !== "allow" && row.action !== "reject" || typeof row.count !== "number" || !Number.isInteger(row.count) || row.count < 0 || ![
|
|
7589
|
-
"firstAt",
|
|
7590
|
-
"lastAt",
|
|
7591
|
-
"rejectedBy"
|
|
7592
|
-
].every((field) => {
|
|
7593
|
-
const value = row[field];
|
|
7594
|
-
return value === void 0 || value === null || typeof value === "string";
|
|
7595
|
-
})) throw new ServerError(`Egress activity response was malformed: destination ${index} is not a destination`, 502);
|
|
7596
|
-
destinations.push({
|
|
7597
|
-
host: row.host,
|
|
7598
|
-
action: row.action,
|
|
7599
|
-
count: row.count,
|
|
7600
|
-
...typeof row.firstAt === "string" ? { firstAt: row.firstAt } : {},
|
|
7601
|
-
...typeof row.lastAt === "string" ? { lastAt: row.lastAt } : {},
|
|
7602
|
-
...typeof row.rejectedBy === "string" ? { rejectedBy: row.rejectedBy } : {}
|
|
7603
|
-
});
|
|
7604
|
-
}
|
|
7605
|
-
return {
|
|
7606
|
-
destinations,
|
|
7607
|
-
requestsObserved: record.requestsObserved,
|
|
7608
|
-
unparsedLines: record.unparsedLines,
|
|
7609
|
-
complete: record.complete,
|
|
7610
|
-
incompleteReasons: record.incompleteReasons
|
|
7611
|
-
};
|
|
7864
|
+
return this.#egressOperations.egressActivity(options);
|
|
7612
7865
|
}
|
|
7613
7866
|
async gpuProviders(options = {}) {
|
|
7614
7867
|
const query = new URLSearchParams();
|
|
@@ -10007,112 +10260,6 @@ function readPublicProfileConflicts(value) {
|
|
|
10007
10260
|
reason: entry.reason
|
|
10008
10261
|
}));
|
|
10009
10262
|
}
|
|
10010
|
-
var DirectRuntimeHttpClient = class {
|
|
10011
|
-
baseClient;
|
|
10012
|
-
sandboxId;
|
|
10013
|
-
getConnection;
|
|
10014
|
-
onUnauthorized;
|
|
10015
|
-
onUnreachable;
|
|
10016
|
-
constructor(baseClient, sandboxId, getConnection, onUnauthorized, onUnreachable) {
|
|
10017
|
-
this.baseClient = baseClient;
|
|
10018
|
-
this.sandboxId = sandboxId;
|
|
10019
|
-
this.getConnection = getConnection;
|
|
10020
|
-
this.onUnauthorized = onUnauthorized;
|
|
10021
|
-
this.onUnreachable = onUnreachable;
|
|
10022
|
-
}
|
|
10023
|
-
get onTiming() {
|
|
10024
|
-
return this.baseClient.onTiming;
|
|
10025
|
-
}
|
|
10026
|
-
async fetch(path, options, fetchOptions) {
|
|
10027
|
-
const runtimePrefix = `/v1/sandboxes/${encodeURIComponent(this.sandboxId)}/runtime`;
|
|
10028
|
-
if (!path.startsWith(runtimePrefix)) return this.baseClient.fetch(path, options, fetchOptions);
|
|
10029
|
-
const runtimePath = path.slice(runtimePrefix.length);
|
|
10030
|
-
if (runtimePath === "/network" || runtimePath.startsWith("/network/") || runtimePath === "/preview-links" || runtimePath.startsWith("/preview-links/")) return this.baseClient.fetch(path, options, fetchOptions);
|
|
10031
|
-
const command = classifySidecarRequest(runtimePath.split("?")[0], options?.method ?? "GET");
|
|
10032
|
-
if (!command) throw new NetworkError("Invalid direct runtime path");
|
|
10033
|
-
const selectRoute = () => {
|
|
10034
|
-
const connection = this.getConnection();
|
|
10035
|
-
const useExec = command.shortTokenRequired && !!connection?.execHost && !!connection.execToken;
|
|
10036
|
-
if (command.shortTokenRequired && !useExec) return void 0;
|
|
10037
|
-
const origin = useExec ? connection?.execHost : connection?.runtimeUrl;
|
|
10038
|
-
if (!origin) return void 0;
|
|
10039
|
-
return {
|
|
10040
|
-
useExec,
|
|
10041
|
-
url: `${origin.replace(/\/$/, "")}${runtimePath}`,
|
|
10042
|
-
bearer: useExec ? connection?.execToken : connection?.authToken
|
|
10043
|
-
};
|
|
10044
|
-
};
|
|
10045
|
-
let route = selectRoute();
|
|
10046
|
-
if (!route) return this.baseClient.fetch(path, options, fetchOptions);
|
|
10047
|
-
const headers = new Headers(options?.headers);
|
|
10048
|
-
const authenticate = () => {
|
|
10049
|
-
headers.delete("Authorization");
|
|
10050
|
-
headers.delete("X-Tangle-Sandbox-Ref");
|
|
10051
|
-
if (route?.useExec) headers.set("X-Tangle-Sandbox-Ref", this.sandboxId);
|
|
10052
|
-
if (route?.bearer) headers.set("Authorization", `Bearer ${route.bearer}`);
|
|
10053
|
-
};
|
|
10054
|
-
authenticate();
|
|
10055
|
-
const isFormDataBody = typeof FormData !== "undefined" && options?.body instanceof FormData;
|
|
10056
|
-
if (!headers.has("Content-Type") && !isFormDataBody) headers.set("Content-Type", "application/json");
|
|
10057
|
-
const init = {
|
|
10058
|
-
...options,
|
|
10059
|
-
headers
|
|
10060
|
-
};
|
|
10061
|
-
if (options?.body && typeof options.body === "object" && !isFormDataBody) init.duplex = "half";
|
|
10062
|
-
const directTimeoutMs = fetchOptions?.timeoutMs;
|
|
10063
|
-
if (!init.signal && typeof directTimeoutMs === "number" && directTimeoutMs > 0) init.signal = AbortSignal.timeout(directTimeoutMs);
|
|
10064
|
-
const send = async (request) => {
|
|
10065
|
-
const timing = {
|
|
10066
|
-
onTiming: this.onTiming,
|
|
10067
|
-
path
|
|
10068
|
-
};
|
|
10069
|
-
if (!route) throw new NetworkError("Direct runtime route was withdrawn");
|
|
10070
|
-
if (route.useExec && canUseNodeHttp2()) {
|
|
10071
|
-
const { fetchDirectHttp2 } = await import("./direct-http2-D8mo1ePx.js");
|
|
10072
|
-
return fetchDirectHttp2(route.url, request, timing);
|
|
10073
|
-
}
|
|
10074
|
-
return fetchWithKeepAlive(route.url, request, timing);
|
|
10075
|
-
};
|
|
10076
|
-
let response = await send(init);
|
|
10077
|
-
if ((response.status === 401 || response.status === 403 && await isRefusedBearer(response)) && this.onUnauthorized && !headers.has("x-no-retry")) {
|
|
10078
|
-
const refusal = {
|
|
10079
|
-
status: response.status,
|
|
10080
|
-
statusText: response.statusText,
|
|
10081
|
-
headers: new Headers(response.headers)
|
|
10082
|
-
};
|
|
10083
|
-
const refusedBody = await response.arrayBuffer().catch(() => null);
|
|
10084
|
-
try {
|
|
10085
|
-
await this.onUnauthorized();
|
|
10086
|
-
} catch {
|
|
10087
|
-
return new Response(refusedBody, refusal);
|
|
10088
|
-
}
|
|
10089
|
-
route = selectRoute();
|
|
10090
|
-
if (!route) return this.baseClient.fetch(path, options, fetchOptions);
|
|
10091
|
-
authenticate();
|
|
10092
|
-
response = await send({
|
|
10093
|
-
...init,
|
|
10094
|
-
headers
|
|
10095
|
-
});
|
|
10096
|
-
}
|
|
10097
|
-
if (this.onUnreachable && await isRuntimeUnreachable(response)) await this.onUnreachable();
|
|
10098
|
-
const responseHeaders = new Headers(response.headers);
|
|
10099
|
-
responseHeaders.set("x-tangle-request-path", path);
|
|
10100
|
-
if (options?.method) responseHeaders.set("x-tangle-request-method", options.method);
|
|
10101
|
-
return rewrapResponse(response, responseHeaders);
|
|
10102
|
-
}
|
|
10103
|
-
};
|
|
10104
|
-
/**
|
|
10105
|
-
* True when a 403 is the sidecar refusing the bearer itself, not a bearer
|
|
10106
|
-
* that lacks a capability. Reads a clone, so the caller keeps the body.
|
|
10107
|
-
*/
|
|
10108
|
-
async function isRefusedBearer(response) {
|
|
10109
|
-
try {
|
|
10110
|
-
const body = await response.clone().json();
|
|
10111
|
-
return body.error?.code === "FORBIDDEN" && body.error.message === "Invalid authentication token";
|
|
10112
|
-
} catch {
|
|
10113
|
-
return false;
|
|
10114
|
-
}
|
|
10115
|
-
}
|
|
10116
10263
|
/**
|
|
10117
10264
|
* Headers for one exec, read, write or search call: the task session it runs in
|
|
10118
10265
|
* and the turn trace it belongs to. Undefined when it names neither.
|
|
@@ -10130,4 +10277,4 @@ function quoteForShell(value) {
|
|
|
10130
10277
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
10131
10278
|
}
|
|
10132
10279
|
//#endregion
|
|
10133
|
-
export { rewrapResponse as A, isRetryableProfileFileMaterializeFailure as C, validateDeferredProfileFileMounts as D, splitInlineProfileSkills as E, exportTraceBundle as M, otelTraceIdForTangleTrace as N, normalizeConnection as O, toOtelJson as P, ManagedProcessClient as S, splitInlineProfileFileMounts as T,
|
|
10280
|
+
export { rewrapResponse as A, isRetryableProfileFileMaterializeFailure as C, validateDeferredProfileFileMounts as D, splitInlineProfileSkills as E, exportTraceBundle as M, otelTraceIdForTangleTrace as N, normalizeConnection as O, toOtelJson as P, ManagedProcessClient as S, splitInlineProfileFileMounts as T, collectAgentFinalMessageText as _, normalizeStartupDiagnostics as a, isToolBearingEvent as b, SandboxSession as c, InteractiveTerminalFrameLog as d, createInteractiveTerminalCapture as f, applySandboxEventText as g, SandboxOperationFailedError as h, normalizeSandboxCreateReceipt as i, buildTraceExportPayload as j, normalizeSandboxShape as k, InteractiveSessionHandle as l, SandboxOperation as m, createSandboxInstanceFromResponse as n, WorkspaceImages as o, createInteractiveTerminalSession as p, normalizeCaptureProof as r, SandboxTaskSession as s, SandboxInstance as t, agentInteractiveSessionPromptRequestDigest as u, collectAgentResponseText as v, materializeProfileFileMounts as w, MAX_EGRESS_DENIALS_LIMIT as x, getSandboxEventText as y };
|