@tangle-network/sandbox 0.60.31 → 0.60.32
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/preview.js +2 -2
- package/dist/{agent-run-outcome-C8Si8478.d.ts → agent-run-outcome-CGf6PAs8.d.ts} +1 -1
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +24 -18
- package/dist/{browser-interactive-control-controller-DRCfxOQz.d.ts → browser-interactive-control-controller-JUW3gOGH.d.ts} +1 -1
- package/dist/chunked-upload-CfefWUE5.js +435 -0
- package/dist/chunked-upload-file-Bo2ROB52.js +109 -0
- package/dist/{client-HewG9j9A.d.ts → client-B6JfkRhc.d.ts} +5 -5
- package/dist/{client-BzXVeXvo.js → client-p2d-6oAH.js} +4 -4
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/core.d.ts +5 -5
- package/dist/core.js +3 -3
- package/dist/gpu-lease/index.d.ts +26 -4
- package/dist/gpu-lease/index.js +26 -5
- package/dist/{index-D_o4zbXJ.d.ts → index-DHgljRHu.d.ts} +2 -2
- package/dist/index.d.ts +12 -12
- package/dist/index.js +6 -6
- package/dist/interactive-control.d.ts +1 -1
- package/dist/{interactive-controller-ykaThYp6.d.ts → interactive-controller-DNbLzamS.d.ts} +2 -2
- package/dist/{interactive-controller-CvW2-UfM.js → interactive-controller-Dxt5sW2N.js} +3 -291
- package/dist/{lines-DCxU0xIV.d.ts → lines-BOWMNDp5.d.ts} +1 -1
- package/dist/lines.d.ts +1 -1
- package/dist/{local-cli-auth-Cr1fyoKv.js → local-cli-auth-BWELjBLz.js} +1 -1
- package/dist/{mcp-local-DY1CnWBn.js → mcp-local-DjryqUiY.js} +1 -1
- package/dist/{preview-DcT5Fb1W.d.ts → preview-B4yfnMgD.d.ts} +3 -3
- package/dist/runtime.d.ts +6 -31
- package/dist/runtime.js +2 -1
- package/dist/{sandbox-CbuA-iZi.js → sandbox-B6LlVm4f.js} +109 -8
- package/dist/{sandbox-CrET4m65.d.ts → sandbox-WpE5rzUa.d.ts} +6 -6
- package/dist/{secp256k1-CyKOxB5J.js → secp256k1-Dx2XABHz.js} +1 -1
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-C1dd-4xk.js → tangle-Ux41HNTu.js} +3 -3
- package/dist/{types-BeWUGJ5S.d.ts → types-i3Vs02b8.d.ts} +74 -3
- package/package.json +3 -3
- /package/dist/{cli-auth-bundle-BwIJkzAQ.js → cli-auth-bundle-Dm8w5faq.js} +0 -0
- /package/dist/{cli-auth-bundle-BMcIiB-I.d.ts → cli-auth-bundle-ODe06Ts7.d.ts} +0 -0
- /package/dist/{collaboration-CrO2Lhyi.js → collaboration-DaWEv29D.js} +0 -0
- /package/dist/{errors-D7RVedpR.d.ts → errors-CRssX9qs.d.ts} +0 -0
- /package/dist/{index-BoQeoNOD.d.ts → index-BgmgfYZZ.d.ts} +0 -0
- /package/dist/{index-BXcL8P-U.d.ts → index-DHuHjNie.d.ts} +0 -0
- /package/dist/{line-application-C2SuT1zK.js → line-application-Cq6dJLBD.js} +0 -0
- /package/dist/{preview-operations-CbTiBE-a.js → preview-operations-DqSo-IBm.js} +0 -0
- /package/dist/{raw-evidence-archive-Bi-Lt83d.js → raw-evidence-archive-Br5a3xZ_.js} +0 -0
- /package/dist/{terminal-stream-B6bUr0hj.d.ts → terminal-stream-CV1pMSKC.d.ts} +0 -0
- /package/dist/{utils-ChcSLv53.js → utils-B7_9Hl_z.js} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { r as backendTypeSchema } from "./backend-types-C7b_Gpa0.js";
|
|
2
|
-
import {
|
|
2
|
+
import { b as parseResponseError, c as NetworkError, m as ServerError, n as CapabilityError, p as SandboxError, v as ValidationError } from "./errors-Cq4hMysQ.js";
|
|
3
3
|
import { c as assertInteractiveSessionRef, d as awaitWithAbort, f as combineAbortSignals, i as createBrowserInteractiveSessionControlTransport, o as InteractiveSessionControlController, r as browserInteractiveTerminalEndpoint } from "./browser-interactive-control-controller-BJf0P_J4.js";
|
|
4
|
+
import { s as uploadChunked } from "./chunked-upload-CfefWUE5.js";
|
|
4
5
|
import { AgentExactRunControlRefSchema, AgentExecutionOutcomeSchema, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionRefSchema, AgentRuntimeAttachmentsSchema, DurablePlanSchema, InteractionRequestSchema, agentInteractiveSessionControlClaimMatchesRef, agentProfileSchema, canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
//#region src/agent-run-outcome-inspection.ts
|
|
@@ -934,63 +935,6 @@ function encodePromptForWire(message) {
|
|
|
934
935
|
} : part);
|
|
935
936
|
}
|
|
936
937
|
//#endregion
|
|
937
|
-
//#region ../../../packages/runtime-contracts/dist/file-limits.js
|
|
938
|
-
const MEBIBYTE$1 = 1024 * 1024;
|
|
939
|
-
10 * MEBIBYTE$1;
|
|
940
|
-
const FILE_DECODED_WRITE_MAX_BYTES = 5 * MEBIBYTE$1;
|
|
941
|
-
5 * MEBIBYTE$1;
|
|
942
|
-
10 * MEBIBYTE$1;
|
|
943
|
-
5 * MEBIBYTE$1;
|
|
944
|
-
//#endregion
|
|
945
|
-
//#region ../../../packages/runtime-contracts/dist/request-limits.js
|
|
946
|
-
/**
|
|
947
|
-
* Raw WIRE/TRANSPORT caps: request-byte limits checked while the body
|
|
948
|
-
* streams in (bodyLimit middleware, Content-Length, encoded proxy bodies),
|
|
949
|
-
* before anything is parsed or decoded. Rejections against these carry
|
|
950
|
-
* code `PAYLOAD_TOO_LARGE` (`payload-too-large.ts`) — the remedy is to
|
|
951
|
-
* split the delivery. Decoded/parsed-content caps (code `FILE_TOO_LARGE`)
|
|
952
|
-
* live in `file-io.ts`.
|
|
953
|
-
*/
|
|
954
|
-
const MEBIBYTE = 1024 * 1024;
|
|
955
|
-
/**
|
|
956
|
-
* Gateway (CF Worker) proxy cap on any request body it forwards — both
|
|
957
|
-
* pass-through requests and route-constructed (`options.body`) proxy
|
|
958
|
-
* payloads. Workers buffer forwarded bodies (streaming upstream stalls),
|
|
959
|
-
* so this bounds Worker memory per request.
|
|
960
|
-
*/
|
|
961
|
-
const SANDBOX_PROXY_REQUEST_MAX_BYTES = MEBIBYTE;
|
|
962
|
-
32 * MEBIBYTE;
|
|
963
|
-
/**
|
|
964
|
-
* Max assembled size of one chunked-upload session — the ceiling of the
|
|
965
|
-
* sanctioned >1 MiB delivery path. Parts stage in sidecar memory until
|
|
966
|
-
* commit, so this bounds per-session memory, not the destination
|
|
967
|
-
* filesystem.
|
|
968
|
-
*/
|
|
969
|
-
const FILE_UPLOAD_SESSION_MAX_BYTES = 64 * MEBIBYTE;
|
|
970
|
-
128 * MEBIBYTE;
|
|
971
|
-
//#endregion
|
|
972
|
-
//#region ../../../packages/runtime-contracts/dist/size-limit-errors.js
|
|
973
|
-
/** Canonical error codes for wire-size and decoded-content rejections. */
|
|
974
|
-
const PAYLOAD_TOO_LARGE_CODE = "PAYLOAD_TOO_LARGE";
|
|
975
|
-
const FILE_TOO_LARGE_CODE = "FILE_TOO_LARGE";
|
|
976
|
-
function isRecord(value) {
|
|
977
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
978
|
-
}
|
|
979
|
-
function isPositiveInteger(value) {
|
|
980
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
981
|
-
}
|
|
982
|
-
function isSizeLimitErrorBodyFor(value, code) {
|
|
983
|
-
if (!isRecord(value) || value.success !== false || !isRecord(value.error)) return false;
|
|
984
|
-
const error = value.error;
|
|
985
|
-
return error.code === code && typeof error.message === "string" && typeof error.surface === "string" && isPositiveInteger(error.limitBytes) && (error.actualBytes === void 0 || isPositiveInteger(error.actualBytes));
|
|
986
|
-
}
|
|
987
|
-
function isPayloadTooLargeErrorBody(value) {
|
|
988
|
-
return isSizeLimitErrorBodyFor(value, PAYLOAD_TOO_LARGE_CODE);
|
|
989
|
-
}
|
|
990
|
-
function isFileTooLargeErrorBody(value) {
|
|
991
|
-
return isSizeLimitErrorBodyFor(value, FILE_TOO_LARGE_CODE);
|
|
992
|
-
}
|
|
993
|
-
//#endregion
|
|
994
938
|
//#region src/dispatch-run-control.ts
|
|
995
939
|
const DISPATCH_RUN_PROVIDER = "tangle-sandbox";
|
|
996
940
|
function generateRuntimeId(prefix) {
|
|
@@ -1042,238 +986,6 @@ function validateAcceptedDispatchRunRef(raw, expected, sandboxId, sessionId, exe
|
|
|
1042
986
|
return accepted;
|
|
1043
987
|
}
|
|
1044
988
|
//#endregion
|
|
1045
|
-
//#region src/lib/chunked-upload.ts
|
|
1046
|
-
/**
|
|
1047
|
-
* Chunked upload — the sanctioned SDK path for delivering payloads larger
|
|
1048
|
-
* than the sandbox API's single-request body caps. Splits the payload into
|
|
1049
|
-
* server-sized parts against a `/fs/upload-session` session, PUTs each part
|
|
1050
|
-
* with transient retry, then commits with a whole-payload SHA-256 so the
|
|
1051
|
-
* runtime can verify nothing was dropped or reordered in transit.
|
|
1052
|
-
*
|
|
1053
|
-
* Browser/Worker-safe: no `node:` imports, no `Buffer`. Input normalizes to
|
|
1054
|
-
* a `Uint8Array` and hashes via Web Crypto (`crypto.subtle`), available in
|
|
1055
|
-
* browsers, Workers, and Node 18+ — the same environments this module must
|
|
1056
|
-
* run in unmodified.
|
|
1057
|
-
*/
|
|
1058
|
-
const DEFAULT_MAX_RETRIES = 4;
|
|
1059
|
-
const RETRY_BASE_MS = 250;
|
|
1060
|
-
const RETRY_MAX_MS = 2e3;
|
|
1061
|
-
const delay = (ms, signal) => new Promise((resolve, reject) => {
|
|
1062
|
-
if (signal?.aborted) {
|
|
1063
|
-
reject(signal.reason ?? /* @__PURE__ */ new Error("aborted"));
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
const timer = setTimeout(() => {
|
|
1067
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1068
|
-
resolve();
|
|
1069
|
-
}, ms);
|
|
1070
|
-
function onAbort() {
|
|
1071
|
-
clearTimeout(timer);
|
|
1072
|
-
reject(signal?.reason ?? /* @__PURE__ */ new Error("aborted"));
|
|
1073
|
-
}
|
|
1074
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1075
|
-
});
|
|
1076
|
-
/** Transient part-upload failures worth retrying: rate-limit/budget (429),
|
|
1077
|
-
* 5xx, transport (network), and request timeouts — mirrors
|
|
1078
|
-
* `isTransientWriteError` in `sandbox.ts`. A non-transient error (bad path,
|
|
1079
|
-
* auth, checksum, containment) fails loud immediately. */
|
|
1080
|
-
function isTransientUploadError(err) {
|
|
1081
|
-
return err instanceof QuotaError || err instanceof ServerError || err instanceof NetworkError || err instanceof TimeoutError;
|
|
1082
|
-
}
|
|
1083
|
-
function isChecksumMismatch(err) {
|
|
1084
|
-
return err instanceof SandboxError && err.code === "CHECKSUM_MISMATCH";
|
|
1085
|
-
}
|
|
1086
|
-
/** Cheap size probe used for the pre-flight cap check, read directly off
|
|
1087
|
-
* the input shape (`Blob.size` / `ArrayBuffer.byteLength` / view
|
|
1088
|
-
* `byteLength`) so an oversized `Blob` never has its bytes materialized
|
|
1089
|
-
* just to be rejected. Strings have no cheap length in UTF-8, so they're
|
|
1090
|
-
* encoded once here (and once more in {@link normalizeToBytes} — an
|
|
1091
|
-
* acceptable cost given strings are never the multi-MB case this path
|
|
1092
|
-
* exists for). */
|
|
1093
|
-
function sizeOfInput(data) {
|
|
1094
|
-
if (typeof data === "string") return new TextEncoder().encode(data).byteLength;
|
|
1095
|
-
if (data instanceof ArrayBuffer) return data.byteLength;
|
|
1096
|
-
if (ArrayBuffer.isView(data)) return data.byteLength;
|
|
1097
|
-
return data.size;
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Normalizes to a `Uint8Array` backed by a plain (never shared)
|
|
1101
|
-
* `ArrayBuffer`. A caller-supplied view may be backed by a
|
|
1102
|
-
* `SharedArrayBuffer`, which `crypto.subtle.digest` and `fetch`'s
|
|
1103
|
-
* `BodyInit` both reject at the type level (and some engines reject at
|
|
1104
|
-
* runtime) — copying here keeps every downstream call on one concrete,
|
|
1105
|
-
* always-accepted buffer type.
|
|
1106
|
-
*/
|
|
1107
|
-
async function normalizeToBytes(data) {
|
|
1108
|
-
if (typeof data === "string") return new Uint8Array(new TextEncoder().encode(data));
|
|
1109
|
-
if (data instanceof ArrayBuffer) return new Uint8Array(data.slice(0));
|
|
1110
|
-
if (ArrayBuffer.isView(data)) {
|
|
1111
|
-
const copy = new Uint8Array(data.byteLength);
|
|
1112
|
-
copy.set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
1113
|
-
return copy;
|
|
1114
|
-
}
|
|
1115
|
-
return new Uint8Array(await data.arrayBuffer());
|
|
1116
|
-
}
|
|
1117
|
-
function webCryptoSubtle() {
|
|
1118
|
-
const subtle = globalThis.crypto?.subtle;
|
|
1119
|
-
if (!subtle) throw new Error("chunked upload requires Web Crypto (crypto.subtle) for SHA-256 hashing — available in browsers, Workers, and Node 18+");
|
|
1120
|
-
return subtle;
|
|
1121
|
-
}
|
|
1122
|
-
async function sha256Hex(bytes) {
|
|
1123
|
-
const digest = await webCryptoSubtle().digest("SHA-256", bytes);
|
|
1124
|
-
return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* Canonical size-cap bodies (413 `PAYLOAD_TOO_LARGE` / `FILE_TOO_LARGE`)
|
|
1128
|
-
* carry `surface`/`limitBytes`/`actualBytes` that the generic error parser
|
|
1129
|
-
* drops; fold them into the message before delegating to
|
|
1130
|
-
* `parseErrorResponse` for the rest (status→class mapping, retryAfterMs,
|
|
1131
|
-
* origin).
|
|
1132
|
-
*/
|
|
1133
|
-
async function parseUploadError(response) {
|
|
1134
|
-
const bodyText = await response.text();
|
|
1135
|
-
let parsedBody;
|
|
1136
|
-
try {
|
|
1137
|
-
parsedBody = JSON.parse(bodyText);
|
|
1138
|
-
} catch {
|
|
1139
|
-
parsedBody = void 0;
|
|
1140
|
-
}
|
|
1141
|
-
if (isPayloadTooLargeErrorBody(parsedBody) || isFileTooLargeErrorBody(parsedBody)) {
|
|
1142
|
-
const { code, message, surface, limitBytes, actualBytes } = parsedBody.error;
|
|
1143
|
-
const detail = typeof actualBytes === "number" ? `${message} (${surface}: ${actualBytes} of ${limitBytes} bytes)` : `${message} (${surface}: limit ${limitBytes} bytes)`;
|
|
1144
|
-
return parseErrorResponse(response.status, JSON.stringify({
|
|
1145
|
-
code,
|
|
1146
|
-
message: detail
|
|
1147
|
-
}), void 0, response.headers);
|
|
1148
|
-
}
|
|
1149
|
-
return parseErrorResponse(response.status, bodyText, void 0, response.headers);
|
|
1150
|
-
}
|
|
1151
|
-
async function initUploadSession(transport, remotePath, totalBytes, sha256, mode, signal) {
|
|
1152
|
-
signal?.throwIfAborted();
|
|
1153
|
-
const response = await transport.fetch("/fs/upload-session", {
|
|
1154
|
-
method: "POST",
|
|
1155
|
-
headers: { "Content-Type": "application/json" },
|
|
1156
|
-
body: JSON.stringify({
|
|
1157
|
-
path: remotePath,
|
|
1158
|
-
mode,
|
|
1159
|
-
totalBytes,
|
|
1160
|
-
sha256
|
|
1161
|
-
}),
|
|
1162
|
-
signal
|
|
1163
|
-
});
|
|
1164
|
-
if (!response.ok) throw await parseUploadError(response);
|
|
1165
|
-
return (await response.json()).data;
|
|
1166
|
-
}
|
|
1167
|
-
async function putPart(transport, uploadId, index, chunk, options) {
|
|
1168
|
-
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1169
|
-
for (let attempt = 0;; attempt++) {
|
|
1170
|
-
options.signal?.throwIfAborted();
|
|
1171
|
-
try {
|
|
1172
|
-
const response = await transport.fetch(`/fs/upload-session/${encodeURIComponent(uploadId)}/parts/${index}`, {
|
|
1173
|
-
method: "PUT",
|
|
1174
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
1175
|
-
body: chunk,
|
|
1176
|
-
signal: options.signal
|
|
1177
|
-
});
|
|
1178
|
-
if (!response.ok) throw await parseUploadError(response);
|
|
1179
|
-
return;
|
|
1180
|
-
} catch (err) {
|
|
1181
|
-
if (isTransientUploadError(err) && attempt < maxRetries) {
|
|
1182
|
-
const retryAfterMs = err instanceof SandboxError ? err.retryAfterMs : void 0;
|
|
1183
|
-
const backoff = Math.min(RETRY_BASE_MS * 2 ** attempt, RETRY_MAX_MS);
|
|
1184
|
-
await delay(retryAfterMs ?? backoff, options.signal);
|
|
1185
|
-
continue;
|
|
1186
|
-
}
|
|
1187
|
-
throw err;
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
function partCount(totalBytes, partSize) {
|
|
1192
|
-
return Math.ceil(totalBytes / partSize);
|
|
1193
|
-
}
|
|
1194
|
-
async function uploadAllParts(transport, uploadId, bytes, partSize, totalParts, options) {
|
|
1195
|
-
const totalBytes = bytes.byteLength;
|
|
1196
|
-
const paceMs = options.paceMs ?? 0;
|
|
1197
|
-
let uploadedBytes = 0;
|
|
1198
|
-
let started = false;
|
|
1199
|
-
for (let index = 0; index < totalParts; index++) {
|
|
1200
|
-
if (started && paceMs > 0) await delay(paceMs, options.signal);
|
|
1201
|
-
started = true;
|
|
1202
|
-
const start = index * partSize;
|
|
1203
|
-
const end = Math.min(start + partSize, totalBytes);
|
|
1204
|
-
await putPart(transport, uploadId, index, bytes.subarray(start, end), options);
|
|
1205
|
-
uploadedBytes += end - start;
|
|
1206
|
-
options.onProgress?.({
|
|
1207
|
-
bytesUploaded: uploadedBytes,
|
|
1208
|
-
totalBytes,
|
|
1209
|
-
percentage: totalBytes === 0 ? 100 : Math.round(uploadedBytes / totalBytes * 100)
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
async function commitSession(transport, uploadId, totalParts, sha256, signal) {
|
|
1214
|
-
signal?.throwIfAborted();
|
|
1215
|
-
const response = await transport.fetch(`/fs/upload-session/${encodeURIComponent(uploadId)}/commit`, {
|
|
1216
|
-
method: "POST",
|
|
1217
|
-
headers: { "Content-Type": "application/json" },
|
|
1218
|
-
body: JSON.stringify({
|
|
1219
|
-
totalParts,
|
|
1220
|
-
sha256
|
|
1221
|
-
}),
|
|
1222
|
-
signal
|
|
1223
|
-
});
|
|
1224
|
-
if (!response.ok) throw await parseUploadError(response);
|
|
1225
|
-
return (await response.json()).data;
|
|
1226
|
-
}
|
|
1227
|
-
/** Best-effort abort of an in-progress session — never masks the real
|
|
1228
|
-
* failure that triggered it, and never itself throws. An orphaned session
|
|
1229
|
-
* also self-expires server-side (`expiresAt`), so a failed DELETE here is
|
|
1230
|
-
* not a leak, just deferred cleanup. */
|
|
1231
|
-
async function abortSession(transport, uploadId) {
|
|
1232
|
-
try {
|
|
1233
|
-
await transport.fetch(`/fs/upload-session/${encodeURIComponent(uploadId)}`, { method: "DELETE" });
|
|
1234
|
-
} catch {}
|
|
1235
|
-
}
|
|
1236
|
-
/**
|
|
1237
|
-
* Upload arbitrary binary or text data to the sandbox via the chunked
|
|
1238
|
-
* upload-session protocol, verifying integrity with a whole-payload
|
|
1239
|
-
* SHA-256 at commit. Browser/Worker-safe and works identically over the
|
|
1240
|
-
* gateway proxy or a direct sidecar connection — see
|
|
1241
|
-
* {@link FileSystem.uploadData}.
|
|
1242
|
-
*
|
|
1243
|
-
* @param transport - Fetch-shaped adapter scoped to the sandbox runtime
|
|
1244
|
-
* (paths are relative to it, e.g. `/fs/upload-session`).
|
|
1245
|
-
* @param remotePath - Destination path in the sandbox.
|
|
1246
|
-
* @param data - Payload to upload. Strings encode as UTF-8.
|
|
1247
|
-
* @param options - See {@link ChunkedUploadOptions}.
|
|
1248
|
-
* @throws {SandboxError} `PAYLOAD_TOO_LARGE` immediately (zero requests) if
|
|
1249
|
-
* the payload exceeds {@link FILE_UPLOAD_SESSION_MAX_BYTES}; otherwise the
|
|
1250
|
-
* typed error from whichever step (init/part/commit) failed after retries
|
|
1251
|
-
* are exhausted.
|
|
1252
|
-
*/
|
|
1253
|
-
async function uploadChunked(transport, remotePath, data, options = {}) {
|
|
1254
|
-
const estimatedSize = sizeOfInput(data);
|
|
1255
|
-
if (estimatedSize > 67108864) throw new SandboxError(`Payload for ${remotePath} is ${estimatedSize} bytes, over the ${FILE_UPLOAD_SESSION_MAX_BYTES} byte chunked-upload session cap`, "PAYLOAD_TOO_LARGE", 413);
|
|
1256
|
-
options.signal?.throwIfAborted();
|
|
1257
|
-
const bytes = await normalizeToBytes(data);
|
|
1258
|
-
options.signal?.throwIfAborted();
|
|
1259
|
-
const sha256 = await sha256Hex(bytes);
|
|
1260
|
-
const init = await initUploadSession(transport, remotePath, bytes.byteLength, sha256, options.mode, options.signal);
|
|
1261
|
-
const totalParts = partCount(bytes.byteLength, init.partSize);
|
|
1262
|
-
try {
|
|
1263
|
-
await uploadAllParts(transport, init.uploadId, bytes, init.partSize, totalParts, options);
|
|
1264
|
-
try {
|
|
1265
|
-
return await commitSession(transport, init.uploadId, totalParts, sha256, options.signal);
|
|
1266
|
-
} catch (err) {
|
|
1267
|
-
if (!isChecksumMismatch(err)) throw err;
|
|
1268
|
-
await uploadAllParts(transport, init.uploadId, bytes, init.partSize, totalParts, options);
|
|
1269
|
-
return await commitSession(transport, init.uploadId, totalParts, sha256, options.signal);
|
|
1270
|
-
}
|
|
1271
|
-
} catch (err) {
|
|
1272
|
-
await abortSession(transport, init.uploadId);
|
|
1273
|
-
throw err;
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
//#endregion
|
|
1277
989
|
//#region src/lib/session-id.ts
|
|
1278
990
|
const SESSION_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
1279
991
|
function assertValidSessionId(value) {
|
|
@@ -2737,4 +2449,4 @@ var BrowserInteractiveSessionController = class extends InteractiveSessionContro
|
|
|
2737
2449
|
}
|
|
2738
2450
|
};
|
|
2739
2451
|
//#endregion
|
|
2740
|
-
export {
|
|
2452
|
+
export { requestedPublicProfileDigest as A, encodeTextForWire as C, foldModelRoutingFields as D, assertCurrentBackendType as E, deriveAgentResultOutcome as F, deriveAgentRunOutcome as I, projectAgentTerminalRecord as L, withProfileHarness as M, withoutRuntimeSecrets as N, mergeRuntimeBackendConfig as O, createAgentRunOutcomeTracker as P, encodePromptForWire as S, applyRequestedModel as T, resolveTraceId as _, TERMINAL_WS_ECHO_SUBPROTOCOL as a, resolveDispatchRunIdentity as b, requestScopedToken as c, normalizeSessionInfo as d, sessionMessageRequestBody as f, mintTraceId as g, isTraceId as h, TerminalStreamError as i, requestedSecretProfilePublicDigest as j, normalizeRuntimeBackendConfig as k, SandboxRuntimeApi as l, TRACE_ID_HEADER as m, InteractiveSessionController as n, assertScopedTokenActive as o, waitForRetryAfter as p, TerminalStream as r, requestInteractiveSessionToken as s, BrowserInteractiveSessionController as t, isRetryableCredentialRefusal as u, appendSessionIdQuery as v, parseSSEStream as w, validateAcceptedDispatchRunRef as x, sessionHeaders as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as CreateSandboxOptions, d as BackendConfig } from "./types-
|
|
1
|
+
import { B as CreateSandboxOptions, d as BackendConfig } from "./types-i3Vs02b8.js";
|
|
2
2
|
|
|
3
3
|
//#region src/line-application.d.ts
|
|
4
4
|
/** Bounded callback request bytes after canonicalization, including JSON framing. */
|
package/dist/lines.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as LineSenderVerification, B as profileChannelReference, C as LineReplyCodeInput, D as LineRole, E as LineRespondView, F as LineVoiceOptions, I as LinesClient, L as LinesHttpClient, M as LineThread, N as LineTransport, O as LineSendInput, P as LineVoice, R as SandboxLines, S as LineReplyCode, T as LineRespondAgent, _ as LineMemberSpec, a as LineApplicationAttachOptions, b as LineProvider, c as LineAttachmentReauthorization, d as LineInstanceAttachOptions, f as LineInstanceCreate, g as LineMemberPatch, h as LineMemberInstance, i as LineAllowanceSubject, j as LineSenderVerificationStart, k as LineSendReceipt, l as LineExecutionKey, m as LineMember, n as LineAgentRolePolicy, o as LineAttachOptions, p as LineLimits, r as LineAllowance, s as LineAttachment, t as Line, u as LineFromConnectionInput, v as LineMessage, w as LineReplyGate, x as LineReminderPreferences, y as LineNumberInventory, z as lineInstanceKey } from "./lines-
|
|
1
|
+
import { A as LineSenderVerification, B as profileChannelReference, C as LineReplyCodeInput, D as LineRole, E as LineRespondView, F as LineVoiceOptions, I as LinesClient, L as LinesHttpClient, M as LineThread, N as LineTransport, O as LineSendInput, P as LineVoice, R as SandboxLines, S as LineReplyCode, T as LineRespondAgent, _ as LineMemberSpec, a as LineApplicationAttachOptions, b as LineProvider, c as LineAttachmentReauthorization, d as LineInstanceAttachOptions, f as LineInstanceCreate, g as LineMemberPatch, h as LineMemberInstance, i as LineAllowanceSubject, j as LineSenderVerificationStart, k as LineSendReceipt, l as LineExecutionKey, m as LineMember, n as LineAgentRolePolicy, o as LineAttachOptions, p as LineLimits, r as LineAllowance, s as LineAttachment, t as Line, u as LineFromConnectionInput, v as LineMessage, w as LineReplyGate, x as LineReminderPreferences, y as LineNumberInventory, z as lineInstanceKey } from "./lines-BOWMNDp5.js";
|
|
2
2
|
export { Line, LineAgentRolePolicy, LineAllowance, LineAllowanceSubject, LineApplicationAttachOptions, LineAttachOptions, LineAttachment, LineAttachmentReauthorization, LineExecutionKey, LineFromConnectionInput, LineInstanceAttachOptions, LineInstanceCreate, LineLimits, LineMember, LineMemberInstance, LineMemberPatch, LineMemberSpec, LineMessage, LineNumberInventory, LineProvider, LineReminderPreferences, LineReplyCode, LineReplyCodeInput, LineReplyGate, LineRespondAgent, LineRespondView, LineRole, LineSendInput, LineSendReceipt, LineSenderVerification, LineSenderVerificationStart, LineThread, LineTransport, LineVoice, LineVoiceOptions, LinesClient, LinesHttpClient, SandboxLines, lineInstanceKey, profileChannelReference };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as AUTH_BUNDLE_PATHS } from "./cli-auth-bundle-
|
|
1
|
+
import { t as AUTH_BUNDLE_PATHS } from "./cli-auth-bundle-Dm8w5faq.js";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as listAgentPreviews, i as getAgentPreview, o as publishAgentPreview, r as ensureAgentPreview, s as removeAgentPreview, t as AgentPreviewError } from "./preview-operations-
|
|
1
|
+
import { a as listAgentPreviews, i as getAgentPreview, o as publishAgentPreview, r as ensureAgentPreview, s as removeAgentPreview, t as AgentPreviewError } from "./preview-operations-DqSo-IBm.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
//#region \0rolldown/runtime.js
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as SandboxInstance } from "./sandbox-
|
|
2
|
-
import { Fn as PreviewLinkInfo, ht as EnsureDevServerOptions } from "./types-
|
|
3
|
-
import { i as Sandbox } from "./client-
|
|
1
|
+
import { r as SandboxInstance } from "./sandbox-WpE5rzUa.js";
|
|
2
|
+
import { Fn as PreviewLinkInfo, ht as EnsureDevServerOptions } from "./types-i3Vs02b8.js";
|
|
3
|
+
import { i as Sandbox } from "./client-B6JfkRhc.js";
|
|
4
4
|
|
|
5
5
|
//#region src/agent/preview-operations.d.ts
|
|
6
6
|
type AgentPreviewOptions = Pick<EnsureDevServerOptions, "sessionId" | "cwd"> & {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
import { A as CommitTaskSessionOptions, At as FileUsageOptions, Bi as SendSessionMessageRequest, Cn as ListMessagesOptions, Di as SandboxTerminalManager, Ei as SandboxTerminalInfo, Gi as SessionExecutionStatus, H as CreateTaskSessionOptions, Ji as SessionInfo, Mt as FileWriteResult, Na as WriteFileOptions, Oa as UploadProgress, Oi as SandboxTerminalRequestOptions, Ot as FileTreeOptions, Qi as SessionMessageAdmission, St as FileReadBatchResult, T as ChunkedUploadResult, Ti as SandboxTerminalCreateOptions, Tt as FileRenameResult, Ui as SessionEventStreamOptions, V as CreateSessionOptions, Vi as SentSessionMessage, Wi as SessionExecutionInfo, Zi as SessionMessage, cr as RenameOptions, fi as SandboxPortBinding, ga as TaskSessionInfo, jt as FileUsageResult, kr as SandboxEvent, kt as FileTreeResult, ma as TaskSessionCommitResult, pa as TaskSessionChanges, w as ChunkedUploadOptions, xt as FileReadBatchOptions, yi as SandboxRuntimeHealth, zi as SendSessionMessageOptions } from "./types-
|
|
2
|
-
import { l as ScopedToken, t as TerminalStream } from "./terminal-stream-
|
|
3
|
-
import { c as InteractiveSessionIdentity, l as InteractiveSessionNotRunningError, r as browserInteractiveControlHolderId } from "./browser-interactive-control-controller-
|
|
4
|
-
import { t as BrowserInteractiveSessionController } from "./interactive-controller-
|
|
5
|
-
import { a as FileWriteConflictError, b as ValidationError, c as NotFoundError, f as SandboxError, g as StateError, h as ServerError, l as PartialFailureError, m as SandboxFailureDetail, n as CapabilityError, p as SandboxErrorJson, s as NetworkError, t as AuthError, u as QuotaError, y as TimeoutError } from "./errors-
|
|
6
|
-
import { a as deriveAgentRunOutcome, i as deriveAgentResultOutcome, n as AgentRunOutcomeTracker, o as projectAgentTerminalRecord, r as createAgentRunOutcomeTracker, t as AgentRunOutcome } from "./agent-run-outcome-
|
|
1
|
+
import { A as CommitTaskSessionOptions, At as FileUsageOptions, Bi as SendSessionMessageRequest, Cn as ListMessagesOptions, Di as SandboxTerminalManager, Ei as SandboxTerminalInfo, Gi as SessionExecutionStatus, H as CreateTaskSessionOptions, Ia as ChunkedUploadTransport, Ji as SessionInfo, La as uploadChunked, Mt as FileWriteResult, Na as WriteFileOptions, Oa as UploadProgress, Oi as SandboxTerminalRequestOptions, Ot as FileTreeOptions, Qi as SessionMessageAdmission, St as FileReadBatchResult, T as ChunkedUploadResult, Ti as SandboxTerminalCreateOptions, Tt as FileRenameResult, Ui as SessionEventStreamOptions, V as CreateSessionOptions, Vi as SentSessionMessage, Wi as SessionExecutionInfo, Zi as SessionMessage, cr as RenameOptions, fi as SandboxPortBinding, ga as TaskSessionInfo, jt as FileUsageResult, kr as SandboxEvent, kt as FileTreeResult, ma as TaskSessionCommitResult, pa as TaskSessionChanges, w as ChunkedUploadOptions, xt as FileReadBatchOptions, yi as SandboxRuntimeHealth, zi as SendSessionMessageOptions } from "./types-i3Vs02b8.js";
|
|
2
|
+
import { l as ScopedToken, t as TerminalStream } from "./terminal-stream-CV1pMSKC.js";
|
|
3
|
+
import { c as InteractiveSessionIdentity, l as InteractiveSessionNotRunningError, r as browserInteractiveControlHolderId } from "./browser-interactive-control-controller-JUW3gOGH.js";
|
|
4
|
+
import { t as BrowserInteractiveSessionController } from "./interactive-controller-DNbLzamS.js";
|
|
5
|
+
import { a as FileWriteConflictError, b as ValidationError, c as NotFoundError, f as SandboxError, g as StateError, h as ServerError, l as PartialFailureError, m as SandboxFailureDetail, n as CapabilityError, p as SandboxErrorJson, s as NetworkError, t as AuthError, u as QuotaError, y as TimeoutError } from "./errors-CRssX9qs.js";
|
|
6
|
+
import { a as deriveAgentRunOutcome, i as deriveAgentResultOutcome, n as AgentRunOutcomeTracker, o as projectAgentTerminalRecord, r as createAgentRunOutcomeTracker, t as AgentRunOutcome } from "./agent-run-outcome-CGf6PAs8.js";
|
|
7
7
|
|
|
8
|
-
//#region src/lib/chunked-upload.d.ts
|
|
9
|
-
/** The transport a caller wires this module to — {@link SandboxInstance.runtimeFetch}
|
|
10
|
-
* in the SDK, or any fetch-shaped adapter in a standalone consumer. */
|
|
11
|
-
interface ChunkedUploadTransport {
|
|
12
|
-
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Upload arbitrary binary or text data to the sandbox via the chunked
|
|
16
|
-
* upload-session protocol, verifying integrity with a whole-payload
|
|
17
|
-
* SHA-256 at commit. Browser/Worker-safe and works identically over the
|
|
18
|
-
* gateway proxy or a direct sidecar connection — see
|
|
19
|
-
* {@link FileSystem.uploadData}.
|
|
20
|
-
*
|
|
21
|
-
* @param transport - Fetch-shaped adapter scoped to the sandbox runtime
|
|
22
|
-
* (paths are relative to it, e.g. `/fs/upload-session`).
|
|
23
|
-
* @param remotePath - Destination path in the sandbox.
|
|
24
|
-
* @param data - Payload to upload. Strings encode as UTF-8.
|
|
25
|
-
* @param options - See {@link ChunkedUploadOptions}.
|
|
26
|
-
* @throws {SandboxError} `PAYLOAD_TOO_LARGE` immediately (zero requests) if
|
|
27
|
-
* the payload exceeds {@link FILE_UPLOAD_SESSION_MAX_BYTES}; otherwise the
|
|
28
|
-
* typed error from whichever step (init/part/commit) failed after retries
|
|
29
|
-
* are exhausted.
|
|
30
|
-
*/
|
|
31
|
-
declare function uploadChunked(transport: ChunkedUploadTransport, remotePath: string, data: Blob | ArrayBuffer | ArrayBufferView | string, options?: ChunkedUploadOptions): Promise<ChunkedUploadResult>;
|
|
32
|
-
//#endregion
|
|
33
8
|
//#region src/runtime-api.d.ts
|
|
34
9
|
interface RuntimeTransport {
|
|
35
10
|
ensureRunning(): Promise<void>;
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as deriveAgentResultOutcome, I as deriveAgentRunOutcome, L as projectAgentTerminalRecord, P as createAgentRunOutcomeTracker, l as SandboxRuntimeApi, t as BrowserInteractiveSessionController } from "./interactive-controller-Dxt5sW2N.js";
|
|
2
2
|
import { _ as TimeoutError, a as FileWriteConflictError, c as NetworkError, d as QuotaError, h as StateError, l as NotFoundError, m as ServerError, n as CapabilityError, p as SandboxError, t as AuthError, u as PartialFailureError, v as ValidationError } from "./errors-Cq4hMysQ.js";
|
|
3
3
|
import { f as combineAbortSignals, n as browserInteractiveControlHolderId, s as InteractiveSessionNotRunningError } from "./browser-interactive-control-controller-BJf0P_J4.js";
|
|
4
|
+
import { s as uploadChunked } from "./chunked-upload-CfefWUE5.js";
|
|
4
5
|
//#region src/runtime-client.ts
|
|
5
6
|
const DEFAULT_RUNTIME_TIMEOUT_MS = 3e4;
|
|
6
7
|
function requireToken(token) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { r as backendTypeSchema } from "./backend-types-C7b_Gpa0.js";
|
|
2
|
-
import {
|
|
2
|
+
import { A as requestedPublicProfileDigest, C as encodeTextForWire, E as assertCurrentBackendType, F as deriveAgentResultOutcome, N as withoutRuntimeSecrets, O as mergeRuntimeBackendConfig, P as createAgentRunOutcomeTracker, S as encodePromptForWire, T as applyRequestedModel, _ as resolveTraceId, b as resolveDispatchRunIdentity, c as requestScopedToken, d as normalizeSessionInfo, f as sessionMessageRequestBody, g as mintTraceId, h as isTraceId, j as requestedSecretProfilePublicDigest, k as normalizeRuntimeBackendConfig, l as SandboxRuntimeApi, m as TRACE_ID_HEADER, n as InteractiveSessionController, o as assertScopedTokenActive, p as waitForRetryAfter, r as TerminalStream, u as isRetryableCredentialRefusal, v as appendSessionIdQuery, w as parseSSEStream, x as validateAcceptedDispatchRunRef, y as sessionHeaders } from "./interactive-controller-Dxt5sW2N.js";
|
|
3
3
|
import { _ as TimeoutError, b as parseResponseError, c as NetworkError, d as QuotaError, g as StreamInterruptedError, h as StateError, l as NotFoundError, m as ServerError, n as CapabilityError, p as SandboxError, r as EdgeNotReadyError, t as AuthError, v as ValidationError, x as readResponseJson, y as parseErrorResponse } from "./errors-Cq4hMysQ.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
5
|
import { SandboxLines } from "./lines.js";
|
|
6
|
-
import {
|
|
6
|
+
import { l as SANDBOX_PROXY_REQUEST_MAX_BYTES, s as uploadChunked } from "./chunked-upload-CfefWUE5.js";
|
|
7
|
+
import { r as cliAuthReferenceSchema } from "./cli-auth-bundle-Dm8w5faq.js";
|
|
7
8
|
import { AgentExactRunControlRefSchema, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, InteractionAcknowledgementSchema, InteractionBindingSchema, InteractionRequestSchema, InteractionResponseCommandSchema, InteractionResponseSchema, 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";
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
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";
|
|
@@ -856,6 +857,13 @@ async function downloadFile(request, localPath, options = {}) {
|
|
|
856
857
|
const maxBytes = options.maxBytes ?? Number.MAX_SAFE_INTEGER;
|
|
857
858
|
if (options.expectedSize !== void 0 && options.expectedSize > maxBytes) throw new ValidationError("expectedSize exceeds download maxBytes");
|
|
858
859
|
options.signal?.throwIfAborted();
|
|
860
|
+
if (options.parallel && options.parallel > 1) {
|
|
861
|
+
const probed = await probeRangeSupport(request, options.signal);
|
|
862
|
+
if (probed) return await downloadParallel(request, localPath, {
|
|
863
|
+
...options,
|
|
864
|
+
parallel: options.parallel
|
|
865
|
+
}, probed);
|
|
866
|
+
}
|
|
859
867
|
const response = await request(options.signal);
|
|
860
868
|
const reader = response.body?.getReader();
|
|
861
869
|
const abort = () => {
|
|
@@ -929,6 +937,98 @@ async function downloadFile(request, localPath, options = {}) {
|
|
|
929
937
|
});
|
|
930
938
|
}
|
|
931
939
|
}
|
|
940
|
+
/** Probe with a one-byte range: only a 206 with a parseable Content-Range
|
|
941
|
+
* counts as capability (200 = ignored Range, anything else = no). */
|
|
942
|
+
async function probeRangeSupport(request, signal) {
|
|
943
|
+
signal?.throwIfAborted();
|
|
944
|
+
const response = await request(signal, { headers: { Range: "bytes=0-0" } });
|
|
945
|
+
if (response.status !== 206) return void 0;
|
|
946
|
+
const contentRange = response.headers.get("content-range");
|
|
947
|
+
const total = contentRange ? /\/(\d+)$/.exec(contentRange)?.[1] : void 0;
|
|
948
|
+
if (total === void 0) return void 0;
|
|
949
|
+
await response.arrayBuffer().catch(() => void 0);
|
|
950
|
+
const totalBytes = Number(total);
|
|
951
|
+
return Number.isSafeInteger(totalBytes) ? { totalBytes } : void 0;
|
|
952
|
+
}
|
|
953
|
+
/** Parallel range download: N slices fetched concurrently, written at their
|
|
954
|
+
* offsets into one temp file, hashed in order on a single sequential re-read,
|
|
955
|
+
* published atomically. A failed or truncated slice fails loud — the
|
|
956
|
+
* destination never sees a partial file. */
|
|
957
|
+
async function downloadParallel(request, localPath, options, capable) {
|
|
958
|
+
const { totalBytes } = capable;
|
|
959
|
+
if (totalBytes > (options.maxBytes ?? Number.MAX_SAFE_INTEGER)) throw new Error("Download exceeds maxBytes");
|
|
960
|
+
if (options.expectedSize !== void 0 && totalBytes !== options.expectedSize) throw new Error("Download size does not match expectedSize");
|
|
961
|
+
const expectedHash = options.expectedSha256?.replace(/^sha256:/, "");
|
|
962
|
+
const fs = await import("node:fs/promises");
|
|
963
|
+
const path = await import("node:path");
|
|
964
|
+
const { createHash } = await import("node:crypto");
|
|
965
|
+
const directory = await fs.mkdtemp(path.join(path.dirname(localPath), ".sandbox-download-"));
|
|
966
|
+
const temporaryPath = path.join(directory, "content");
|
|
967
|
+
let received = 0;
|
|
968
|
+
try {
|
|
969
|
+
options.onProgress?.({
|
|
970
|
+
bytesDownloaded: 0,
|
|
971
|
+
totalBytes,
|
|
972
|
+
percentage: 0
|
|
973
|
+
});
|
|
974
|
+
const file = await fs.open(temporaryPath, "wx+", 384);
|
|
975
|
+
try {
|
|
976
|
+
const slices = sliceRanges(totalBytes, options.parallel);
|
|
977
|
+
await Promise.all(slices.map(async ({ start, end }) => {
|
|
978
|
+
options.signal?.throwIfAborted();
|
|
979
|
+
const response = await request(options.signal, { headers: { Range: `bytes=${start}-${end}` } });
|
|
980
|
+
if (response.status !== 206) throw new Error(`Range request answered ${response.status} after a 206 probe`);
|
|
981
|
+
const sliceBytes = end - start + 1;
|
|
982
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
983
|
+
if (buffer.byteLength !== sliceBytes) throw new Error(`Range slice ${start}-${end} returned ${buffer.byteLength} bytes (truncated)`);
|
|
984
|
+
await file.write(buffer, 0, sliceBytes, start);
|
|
985
|
+
received += sliceBytes;
|
|
986
|
+
options.onProgress?.({
|
|
987
|
+
bytesDownloaded: received,
|
|
988
|
+
totalBytes,
|
|
989
|
+
percentage: received / totalBytes * 100
|
|
990
|
+
});
|
|
991
|
+
}));
|
|
992
|
+
const hash = createHash("sha256");
|
|
993
|
+
const reader = file.createReadStream({ autoClose: false });
|
|
994
|
+
for await (const chunk of reader) hash.update(chunk);
|
|
995
|
+
const sha256 = hash.digest("hex");
|
|
996
|
+
if (expectedHash !== void 0 && sha256 !== expectedHash.toLowerCase()) throw new Error("Download SHA-256 does not match expectedSha256");
|
|
997
|
+
if (received !== totalBytes) throw new Error("Download was truncated or its size changed");
|
|
998
|
+
await file.close();
|
|
999
|
+
options.signal?.throwIfAborted();
|
|
1000
|
+
if (options.overwrite === false) await fs.link(temporaryPath, localPath);
|
|
1001
|
+
else await fs.rename(temporaryPath, localPath);
|
|
1002
|
+
options.onProgress?.({
|
|
1003
|
+
bytesDownloaded: totalBytes,
|
|
1004
|
+
totalBytes,
|
|
1005
|
+
percentage: 100
|
|
1006
|
+
});
|
|
1007
|
+
return {
|
|
1008
|
+
sizeBytes: totalBytes,
|
|
1009
|
+
sha256
|
|
1010
|
+
};
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
await file.close().catch(() => void 0);
|
|
1013
|
+
throw error;
|
|
1014
|
+
}
|
|
1015
|
+
} finally {
|
|
1016
|
+
await fs.rm(directory, {
|
|
1017
|
+
recursive: true,
|
|
1018
|
+
force: true
|
|
1019
|
+
}).catch(() => void 0);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
/** Split [0, total) into `count` contiguous inclusive ranges. */
|
|
1023
|
+
function sliceRanges(total, count) {
|
|
1024
|
+
const chunk = Math.ceil(total / count);
|
|
1025
|
+
const ranges = [];
|
|
1026
|
+
for (let start = 0; start < total; start += chunk) ranges.push({
|
|
1027
|
+
start,
|
|
1028
|
+
end: Math.min(start + chunk, total) - 1
|
|
1029
|
+
});
|
|
1030
|
+
return ranges;
|
|
1031
|
+
}
|
|
932
1032
|
//#endregion
|
|
933
1033
|
//#region src/managed-process.ts
|
|
934
1034
|
var ManagedProcessClient = class {
|
|
@@ -5708,21 +5808,22 @@ var SandboxInstance = class SandboxInstance {
|
|
|
5708
5808
|
}
|
|
5709
5809
|
async fsUpload(localPath, remotePath, options) {
|
|
5710
5810
|
await this.ensureRunning();
|
|
5711
|
-
const
|
|
5811
|
+
const { size } = await (await import("node:fs/promises")).stat(localPath);
|
|
5712
5812
|
if (options?.onProgress) options.onProgress({
|
|
5713
5813
|
bytesUploaded: 0,
|
|
5714
|
-
totalBytes:
|
|
5814
|
+
totalBytes: size,
|
|
5715
5815
|
percentage: 0
|
|
5716
5816
|
});
|
|
5717
|
-
await
|
|
5817
|
+
const { uploadChunkedFromFile } = await import("./chunked-upload-file-Bo2ROB52.js");
|
|
5818
|
+
await uploadChunkedFromFile({ fetch: (path, init) => this.runtimeFetch(path, init) }, remotePath, localPath, {
|
|
5718
5819
|
mode: options?.permissions,
|
|
5719
5820
|
onProgress: options?.onProgress ? (progress) => {
|
|
5720
5821
|
if (progress.percentage < 100) options.onProgress?.(progress);
|
|
5721
5822
|
} : void 0
|
|
5722
5823
|
});
|
|
5723
5824
|
if (options?.onProgress) options.onProgress({
|
|
5724
|
-
bytesUploaded:
|
|
5725
|
-
totalBytes:
|
|
5825
|
+
bytesUploaded: size,
|
|
5826
|
+
totalBytes: size,
|
|
5726
5827
|
percentage: 100
|
|
5727
5828
|
});
|
|
5728
5829
|
}
|
|
@@ -8306,7 +8407,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8306
8407
|
}
|
|
8307
8408
|
/** @internal — invoked before the sandbox is deleted. */
|
|
8308
8409
|
async _sessionExportRawEvidence(id, destination, options) {
|
|
8309
|
-
const { exportRawEvidenceDirectory } = await import("./raw-evidence-archive-
|
|
8410
|
+
const { exportRawEvidenceDirectory } = await import("./raw-evidence-archive-Br5a3xZ_.js");
|
|
8310
8411
|
await this.ensureRunning();
|
|
8311
8412
|
await this.refresh();
|
|
8312
8413
|
return exportRawEvidenceDirectory((signal) => this.runtimeFetch(`/agents/sessions/${encodeURIComponent(id)}/raw-evidence/archive?${new URLSearchParams({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as CliAuthReference } from "./cli-auth-bundle-
|
|
2
|
-
import { $n as PublicProfileConflict, A as CommitTaskSessionOptions, Aa as WaitForOptions, Ai as SandboxTraceBundle, Bi as SendSessionMessageRequest, C as BranchOptions, Ci as SandboxStatus, Cn as ListMessagesOptions, Cr as SandboxCreateReceipt, D as CodeExecutionResult, E as CodeExecutionOptions, Et as FileSystem, Fa as WriteManyOptions, Fi as SearchMatch, H as CreateTaskSessionOptions, Hn as ProcessManager, Ii as SearchOptions, In as PreviewLinkManager, Ji as SessionInfo, Jn as PromptResult, Ka as
|
|
3
|
-
import { a as TerminalStreamReconnectAuthority, c as MintScopedTokenOptions, h as TerminalReadyInfo, l as ScopedToken, r as TerminalStreamHandlers, t as TerminalStream } from "./terminal-stream-
|
|
4
|
-
import { f as InteractiveAttachOptions, g as InteractiveSessionStatus, h as InteractiveRequestOptions, m as InteractiveControlClaimOptions, p as InteractiveControlClaimAcknowledgement } from "./browser-interactive-control-controller-
|
|
5
|
-
import { r as InteractiveAttachRequest } from "./interactive-controller-
|
|
6
|
-
import { R as SandboxLines } from "./lines-
|
|
1
|
+
import { t as CliAuthReference } from "./cli-auth-bundle-ODe06Ts7.js";
|
|
2
|
+
import { $a as WorkspaceImagePublishResult$1, $n as PublicProfileConflict, A as CommitTaskSessionOptions, Aa as WaitForOptions, Ai as SandboxTraceBundle, Bi as SendSessionMessageRequest, C as BranchOptions, Ci as SandboxStatus, Cn as ListMessagesOptions, Cr as SandboxCreateReceipt, D as CodeExecutionResult, E as CodeExecutionOptions, Et as FileSystem, Fa as WriteManyOptions, Fi as SearchMatch, Ga as SandboxEnvRecovery, H as CreateTaskSessionOptions, Hn as ProcessManager, Ii as SearchOptions, In as PreviewLinkManager, Ja as RawEvidenceDirectoryExport, Ji as SessionInfo, Jn as PromptResult, Ka as SandboxEnvRecoveryView, Kn as PromptInputPart, M as ConversationTurnOptions, Ma as WorkspaceOperationLookup, Mt as FileWriteResult, N as ConversationTurnResult, Na as WriteFileOptions, Ni as SandboxTraceOptions, O as CodeLanguage, Pa as WriteManyFile, Pn as PermissionsManager, Q as DispatchedSession, Qi as SessionMessageAdmission, Qt as ForkLookupOptions, Sa as TeePublicKeyResponse, Sn as JsonValue, Ta as TurnDriveResult, Tr as SandboxDeleteOptions, Ui as SessionEventStreamOptions, V as CreateSessionOptions, Vi as SentSessionMessage, Wi as SessionExecutionInfo, Xi as SessionListOptions, Xn as ProvisionResult, Xt as ForkCounts, Ya as RawEvidenceExportOptions, Yi as SessionInterruptOptions, Yn as ProvisionEvent, Z as DispatchPromptOptions, Zi as SessionMessage, Zt as ForkIdempotency, _n as IntelligenceReport, aa as SnapshotInfo, an as GitStatus, ba as TeeAttestationResponse, bi as SandboxShape, d as BackendConfig, dn as GpuLeaseManager, dr as Rollout, ea as SessionResultOptions, ei as SandboxFleetTraceBundle, eo as InteractionResolutionAcknowledgement, fi as SandboxPortBinding, ga as TaskSessionInfo, gn as InstalledTool, gt as EventStreamOptions, hi as SandboxResourceUsage, hr as RolloutStartResult, in as GitDiff, it as DriverInfo, j as CompletedTurnResult, ja as WaitForRolloutOptions, jn as NetworkManager, ki as SandboxTerminals, kr as SandboxEvent, la as StartupDiagnostics, lr as RestoreSnapshotOptions, ma as TaskSessionCommitResult, na as SnapshotDeleteAcknowledgement, nn as GitCommit, nt as DriveTurnOptions, oa as SnapshotOptions, on as GpuLease, ot as DurablePlan, p as BackendManager, pa as TaskSessionChanges, pr as RolloutOptions, pt as EgressManager, qi as SessionForkOptions, qn as PromptOptions, sa as SnapshotResult, st as DurablePlanDecisionResult, tn as GitBranch, ui as SandboxInfo, ur as ResumeOptions, va as TeeAttestationOptions, vi as SandboxRuntimeCapabilities, vn as IntelligenceReportBudget, vr as SSHCommandDescriptor, vt as ExecOptions, wi as SandboxTerminalAttachOptions, wr as SandboxDeleteAcknowledgement, xn as IntelligenceReportWindow, xr as SandboxConnection, yi as SandboxRuntimeHealth, yn as IntelligenceReportCompareTo, yr as SSHCredentials, yt as ExecResult, zi as SendSessionMessageOptions } from "./types-i3Vs02b8.js";
|
|
3
|
+
import { a as TerminalStreamReconnectAuthority, c as MintScopedTokenOptions, h as TerminalReadyInfo, l as ScopedToken, r as TerminalStreamHandlers, t as TerminalStream } from "./terminal-stream-CV1pMSKC.js";
|
|
4
|
+
import { f as InteractiveAttachOptions, g as InteractiveSessionStatus, h as InteractiveRequestOptions, m as InteractiveControlClaimOptions, p as InteractiveControlClaimAcknowledgement } from "./browser-interactive-control-controller-JUW3gOGH.js";
|
|
5
|
+
import { r as InteractiveAttachRequest } from "./interactive-controller-DNbLzamS.js";
|
|
6
|
+
import { R as SandboxLines } from "./lines-BOWMNDp5.js";
|
|
7
7
|
import { AgentInteractiveSessionAttach, AgentInteractiveSessionControlClaim, AgentInteractiveSessionControlClaimAcknowledgement, AgentInteractiveSessionControlClaimRequest, AgentInteractiveSessionPromptAcknowledgement, AgentInteractiveSessionPromptCommand, AgentInteractiveSessionRef, AgentInteractiveSessionStart, AgentInteractiveSessionStopAcknowledgement, AgentInteractiveSessionStopCommand, AgentInteractiveTerminalSession, AgentInteractiveTerminalSession as AgentInteractiveTerminalSession$1, AgentProfile, AgentRunCancellationAcknowledgement, AgentRunCancellationRequest, InteractionAcknowledgement, InteractionData, InteractionRequest, InteractionResponseCommand, TerminalOutputEvent, TerminalReplayWindow, agentInteractiveSessionPromptRequestDigest } from "@tangle-network/agent-interface";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as anumber, c as concatBytes$1, f as randomBytes, h as toBytes, i as ahash, l as createHasher$1, n as abytes$1, o as aoutput, p as rotr, r as aexists, s as clean, t as Hash, u as createView, x as split } from "./utils-
|
|
1
|
+
import { a as anumber, c as concatBytes$1, f as randomBytes, h as toBytes, i as ahash, l as createHasher$1, n as abytes$1, o as aoutput, p as rotr, r as aexists, s as clean, t as Hash, u as createView, x as split } from "./utils-B7_9Hl_z.js";
|
|
2
2
|
//#region ../../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
|
|
3
3
|
/**
|
|
4
4
|
* Internal Merkle-Damgard hash utils.
|
package/dist/tangle/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as JsonResponseParamTypes, E as SandboxIdParamTypes, S as ITangleJobsAbi, T as SandboxCreateResponseParamTypes, _ as JOB_SANDBOX_DELETE, a as fetchQuote, b as TangleSandboxClientConfig, c as parseQuoteResponse, d as OperatorSession, f as OperatorSessionError, g as JOB_SANDBOX_CREATE, h as TangleSandboxClient, i as SignedQuote, l as validateQuote, m as SignMessage, n as QuoteDomain, o as inputsHashOf, p as OperatorSessionToken, r as QuoteError, s as jobQuoteDigest, t as JobQuoteDetails, u as OperatorChallenge, v as TANGLE_CHAIN_ID, w as SandboxCreateParamTypes, x as AgentSandboxBlueprintAbi, y as TANGLE_JOBS_CONTRACT } from "../index-
|
|
1
|
+
import { C as JsonResponseParamTypes, E as SandboxIdParamTypes, S as ITangleJobsAbi, T as SandboxCreateResponseParamTypes, _ as JOB_SANDBOX_DELETE, a as fetchQuote, b as TangleSandboxClientConfig, c as parseQuoteResponse, d as OperatorSession, f as OperatorSessionError, g as JOB_SANDBOX_CREATE, h as TangleSandboxClient, i as SignedQuote, l as validateQuote, m as SignMessage, n as QuoteDomain, o as inputsHashOf, p as OperatorSessionToken, r as QuoteError, s as jobQuoteDigest, t as JobQuoteDetails, u as OperatorChallenge, v as TANGLE_CHAIN_ID, w as SandboxCreateParamTypes, x as AgentSandboxBlueprintAbi, y as TANGLE_JOBS_CONTRACT } from "../index-DHgljRHu.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JobQuoteDetails, JsonResponseParamTypes, OperatorChallenge, OperatorSession, OperatorSessionError, OperatorSessionToken, QuoteDomain, QuoteError, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, SignMessage, SignedQuote, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TangleSandboxClient, TangleSandboxClientConfig, fetchQuote, inputsHashOf, jobQuoteDigest, parseQuoteResponse, validateQuote };
|
package/dist/tangle/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as SandboxCreateParamTypes, a as parseQuoteResponse, c as OperatorSession, d as JOB_SANDBOX_DELETE, f as TANGLE_CHAIN_ID, g as JsonResponseParamTypes, h as ITangleJobsAbi, i as jobQuoteDigest, l as OperatorSessionError, m as AgentSandboxBlueprintAbi, n as fetchQuote, o as validateQuote, p as TANGLE_JOBS_CONTRACT, r as inputsHashOf, s as TangleSandboxClient, t as QuoteError, u as JOB_SANDBOX_CREATE, v as SandboxCreateResponseParamTypes, y as SandboxIdParamTypes } from "../tangle-
|
|
1
|
+
import { _ as SandboxCreateParamTypes, a as parseQuoteResponse, c as OperatorSession, d as JOB_SANDBOX_DELETE, f as TANGLE_CHAIN_ID, g as JsonResponseParamTypes, h as ITangleJobsAbi, i as jobQuoteDigest, l as OperatorSessionError, m as AgentSandboxBlueprintAbi, n as fetchQuote, o as validateQuote, p as TANGLE_JOBS_CONTRACT, r as inputsHashOf, s as TangleSandboxClient, t as QuoteError, u as JOB_SANDBOX_CREATE, v as SandboxCreateResponseParamTypes, y as SandboxIdParamTypes } from "../tangle-Ux41HNTu.js";
|
|
2
2
|
export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, OperatorSession, OperatorSessionError, QuoteError, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TangleSandboxClient, fetchQuote, inputsHashOf, jobQuoteDigest, parseQuoteResponse, validateQuote };
|