@tangle-network/agent-app 0.60.38 → 0.60.40
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/chat-routes/index.js +2 -1
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chunk-4LBCTFBP.js +560 -0
- package/dist/chunk-4LBCTFBP.js.map +1 -0
- package/dist/{chunk-2BAASFJS.js → chunk-E7CDDDFW.js} +58 -467
- package/dist/chunk-E7CDDDFW.js.map +1 -0
- package/dist/preset-cloudflare/detached-turn-workflow.d.ts +19 -0
- package/dist/preset-cloudflare/index.d.ts +1 -1
- package/dist/preset-cloudflare/index.js +44 -3
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +7 -0
- package/dist/sandbox/index.js +44 -30
- package/dist/sandbox/transient-failure.d.ts +37 -0
- package/package.json +1 -1
- package/dist/chunk-2BAASFJS.js.map +0 -1
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SANDBOX_BACKING_CONTAINER_MISSING_CODE,
|
|
3
|
+
SandboxTransientDeadlineError,
|
|
4
|
+
classifySandboxTransientFailure,
|
|
5
|
+
isLegacySandboxBackingContainerMissingMessage,
|
|
6
|
+
isSandboxApiSandboxMissingFailure,
|
|
7
|
+
isSandboxBoxConfigFailure,
|
|
8
|
+
isSandboxHostCapacityFailure,
|
|
9
|
+
sandboxTransientBackoffMs,
|
|
10
|
+
serializeSandboxProvisioningError
|
|
11
|
+
} from "./chunk-4LBCTFBP.js";
|
|
1
12
|
import {
|
|
2
13
|
DEFAULT_HARNESS,
|
|
3
14
|
assertHarnessModelCompatible,
|
|
@@ -168,440 +179,6 @@ async function readSandboxBinaryBytes(box, absolutePath, expectedSize, options)
|
|
|
168
179
|
return { succeeded: true, value: { bytes, size: expectedSize } };
|
|
169
180
|
}
|
|
170
181
|
|
|
171
|
-
// src/sandbox/recovery.ts
|
|
172
|
-
var EGRESS_PROXY_RECOVERY_REQUIRED = "EGRESS_PROXY_RECOVERY_REQUIRED";
|
|
173
|
-
var EGRESS_PROXY_RECOVERY_PHASE = "egress_proxy_recovery";
|
|
174
|
-
var WORKSPACE_SANDBOX_MISSING = "WORKSPACE_SANDBOX_MISSING";
|
|
175
|
-
var WORKSPACE_SANDBOX_HOST_EXHAUSTED = "WORKSPACE_SANDBOX_HOST_EXHAUSTED";
|
|
176
|
-
var WORKSPACE_SANDBOX_UNRECOVERABLE = "WORKSPACE_SANDBOX_UNRECOVERABLE";
|
|
177
|
-
var WORKSPACE_SANDBOX_SNAPSHOT_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
178
|
-
var CODES = {
|
|
179
|
-
[EGRESS_PROXY_RECOVERY_REQUIRED]: { snapshotUsable: true },
|
|
180
|
-
[WORKSPACE_SANDBOX_MISSING]: { snapshotUsable: false },
|
|
181
|
-
[WORKSPACE_SANDBOX_HOST_EXHAUSTED]: { snapshotUsable: false },
|
|
182
|
-
[WORKSPACE_SANDBOX_UNRECOVERABLE]: { snapshotUsable: false }
|
|
183
|
-
};
|
|
184
|
-
var ACTIONS = {
|
|
185
|
-
confirmation_required: { replacementChosen: false, canDecide: true },
|
|
186
|
-
deletion_declined: { replacementChosen: false, canDecide: true },
|
|
187
|
-
replacement_authorized: { replacementChosen: false },
|
|
188
|
-
snapshot_replacement_authorized: { replacementChosen: false },
|
|
189
|
-
replacement_started: { replacementChosen: true, completedAs: "replacement_completed" },
|
|
190
|
-
replacement_completed: { replacementChosen: true },
|
|
191
|
-
snapshot_replacement_started: { replacementChosen: true, completedAs: "snapshot_replacement_completed" },
|
|
192
|
-
snapshot_restore_failed: { replacementChosen: true, completedAs: "snapshot_replacement_completed" },
|
|
193
|
-
snapshot_replacement_completed: { replacementChosen: true },
|
|
194
|
-
missing_replacement_started: { replacementChosen: true, completedAs: "missing_replacement_completed" },
|
|
195
|
-
missing_replacement_completed: { replacementChosen: true },
|
|
196
|
-
unrecoverable_replacement_started: { replacementChosen: true, completedAs: "unrecoverable_replacement_completed" },
|
|
197
|
-
unrecoverable_replacement_completed: { replacementChosen: true }
|
|
198
|
-
};
|
|
199
|
-
var WorkspaceSandboxRecoveryRequiredError = class extends Error {
|
|
200
|
-
code = EGRESS_PROXY_RECOVERY_REQUIRED;
|
|
201
|
-
status = 409;
|
|
202
|
-
phase = EGRESS_PROXY_RECOVERY_PHASE;
|
|
203
|
-
recovery;
|
|
204
|
-
constructor(recovery, cause) {
|
|
205
|
-
super(workspaceSandboxRecoveryMessage(recovery), { cause });
|
|
206
|
-
this.name = "WorkspaceSandboxRecoveryRequiredError";
|
|
207
|
-
this.recovery = recovery;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
function isRecord(value) {
|
|
211
|
-
return typeof value === "object" && value !== null;
|
|
212
|
-
}
|
|
213
|
-
function asNonEmptyString(value) {
|
|
214
|
-
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
215
|
-
}
|
|
216
|
-
function errorChain(error) {
|
|
217
|
-
const pending = [error];
|
|
218
|
-
const visited = /* @__PURE__ */ new Set();
|
|
219
|
-
const chain = [];
|
|
220
|
-
while (pending.length > 0) {
|
|
221
|
-
const current = pending.shift();
|
|
222
|
-
if (current === void 0 || current === null || visited.has(current)) continue;
|
|
223
|
-
visited.add(current);
|
|
224
|
-
chain.push(current);
|
|
225
|
-
if (!isRecord(current)) continue;
|
|
226
|
-
if (current.cause !== void 0) pending.push(current.cause);
|
|
227
|
-
if (Array.isArray(current.errors)) pending.push(...current.errors);
|
|
228
|
-
}
|
|
229
|
-
return chain;
|
|
230
|
-
}
|
|
231
|
-
function isEgressProxyRecoveryRequiredError(error) {
|
|
232
|
-
return errorChain(error).some(
|
|
233
|
-
(current) => isRecord(current) && current.code === EGRESS_PROXY_RECOVERY_REQUIRED
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
function isWorkspaceSandboxSnapshotRestoreError(error) {
|
|
237
|
-
return errorChain(error).some((current) => {
|
|
238
|
-
const message = current instanceof Error ? current.message : isRecord(current) && typeof current.message === "string" ? current.message : "";
|
|
239
|
-
return /snapshot|fromSnapshot|restore/i.test(message);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
function assessWorkspaceSandboxSnapshot(snapshot, sandboxId, now = Date.now()) {
|
|
243
|
-
if (!snapshot) return { availability: "missing", freshness: "unknown" };
|
|
244
|
-
const createdAt = Date.parse(snapshot.createdAt);
|
|
245
|
-
const ageMs = now - createdAt;
|
|
246
|
-
const isFresh = snapshot.fromSandboxId === sandboxId && Number.isFinite(createdAt) && ageMs >= 0 && ageMs <= WORKSPACE_SANDBOX_SNAPSHOT_MAX_AGE_MS;
|
|
247
|
-
return isFresh ? { availability: "available", freshness: "fresh", snapshot } : { availability: "stale", freshness: "stale", snapshot };
|
|
248
|
-
}
|
|
249
|
-
function isSnapshotAssessment(value) {
|
|
250
|
-
if (!isRecord(value)) return false;
|
|
251
|
-
const availability = value.availability;
|
|
252
|
-
const freshness = value.freshness;
|
|
253
|
-
return (availability === "available" || availability === "missing" || availability === "stale") && (freshness === "fresh" || freshness === "stale" || freshness === "unknown");
|
|
254
|
-
}
|
|
255
|
-
function isWorkspaceSandboxRecoveryAction(value) {
|
|
256
|
-
return typeof value === "string" && Object.hasOwn(ACTIONS, value);
|
|
257
|
-
}
|
|
258
|
-
function isWorkspaceSandboxRecoveryCode(value) {
|
|
259
|
-
return typeof value === "string" && Object.hasOwn(CODES, value);
|
|
260
|
-
}
|
|
261
|
-
function isWorkspaceSandboxRecoveryState(value) {
|
|
262
|
-
if (!isRecord(value)) return false;
|
|
263
|
-
return isWorkspaceSandboxRecoveryCode(value.code) && !!asNonEmptyString(value.sandboxId) && !!asNonEmptyString(value.detectedAt) && isSnapshotAssessment(value.snapshot) && isWorkspaceSandboxRecoveryAction(value.action);
|
|
264
|
-
}
|
|
265
|
-
function workspaceSandboxRecoveryFromError(error) {
|
|
266
|
-
for (const current of errorChain(error)) {
|
|
267
|
-
if (!isRecord(current) || !isWorkspaceSandboxRecoveryState(current.recovery)) continue;
|
|
268
|
-
return current.recovery;
|
|
269
|
-
}
|
|
270
|
-
return void 0;
|
|
271
|
-
}
|
|
272
|
-
function workspaceSandboxRecoveryMessage(recovery) {
|
|
273
|
-
if (recovery.code === WORKSPACE_SANDBOX_MISSING) {
|
|
274
|
-
return "The sandbox behind this workspace no longer exists on the platform. A replacement is being provisioned and your saved work is restored into it.";
|
|
275
|
-
}
|
|
276
|
-
if (!CODES[recovery.code].snapshotUsable) {
|
|
277
|
-
return "The sandbox behind this workspace could not be started again. A replacement is being provisioned and your saved work is restored into it.";
|
|
278
|
-
}
|
|
279
|
-
if (recovery.action === "deletion_declined") {
|
|
280
|
-
return "Sandbox recovery remains paused because replacement was declined. The stopped sandbox has not been deleted.";
|
|
281
|
-
}
|
|
282
|
-
if (recovery.action === "confirmation_required") {
|
|
283
|
-
const snapshotReason = recovery.snapshot.availability === "missing" ? "No restorable sandbox snapshot is available." : "The available sandbox snapshot is stale.";
|
|
284
|
-
return `Sandbox recovery requires owner confirmation before replacement. ${snapshotReason} The stopped sandbox has not been deleted.`;
|
|
285
|
-
}
|
|
286
|
-
if (recovery.action === "snapshot_restore_failed") {
|
|
287
|
-
return "Sandbox replacement could not restore its verified snapshot, and an empty fallback was not created because it could lose workspace state.";
|
|
288
|
-
}
|
|
289
|
-
return "Sandbox recovery is required before chat can continue. The stopped sandbox has not been deleted.";
|
|
290
|
-
}
|
|
291
|
-
function workspaceSandboxRecoveryRecommendedActions(recovery) {
|
|
292
|
-
if (!CODES[recovery.code].snapshotUsable) {
|
|
293
|
-
return ["Retry after the replacement sandbox finishes provisioning."];
|
|
294
|
-
}
|
|
295
|
-
if (recovery.action === "deletion_declined") {
|
|
296
|
-
return ["Keep the stopped sandbox for support or ask a workspace owner to authorize replacement."];
|
|
297
|
-
}
|
|
298
|
-
if (recovery.action === "confirmation_required") {
|
|
299
|
-
return ["An owner can explicitly replace the sandbox after accepting loss of unsnapshotted sandbox-local changes."];
|
|
300
|
-
}
|
|
301
|
-
if (recovery.action === "snapshot_restore_failed") {
|
|
302
|
-
return ["Retry snapshot restoration or contact support. An empty replacement is not created automatically."];
|
|
303
|
-
}
|
|
304
|
-
return ["Retry after sandbox recovery completes."];
|
|
305
|
-
}
|
|
306
|
-
function workspaceSandboxRecoveryDiagnostic(recovery) {
|
|
307
|
-
return {
|
|
308
|
-
sandboxId: recovery.sandboxId,
|
|
309
|
-
recoveryCode: recovery.code,
|
|
310
|
-
snapshotAvailability: recovery.snapshot.availability,
|
|
311
|
-
snapshotFreshness: recovery.snapshot.freshness,
|
|
312
|
-
selectedRecoveryAction: recovery.action,
|
|
313
|
-
replacementSandboxId: recovery.replacementSandboxId
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function preferredWorkspaceSandboxRecoveryBoxKey(recovery) {
|
|
317
|
-
if (!recovery?.replacementBoxKey) return void 0;
|
|
318
|
-
return ACTIONS[recovery.action].replacementChosen ? recovery.replacementBoxKey : void 0;
|
|
319
|
-
}
|
|
320
|
-
function shouldRestoreWorkspaceSandboxRecovery(recovery) {
|
|
321
|
-
if (!recovery) return false;
|
|
322
|
-
if (!CODES[recovery.code].snapshotUsable) return false;
|
|
323
|
-
return !!preferredWorkspaceSandboxRecoveryBoxKey(recovery) && recovery.snapshot.availability === "available";
|
|
324
|
-
}
|
|
325
|
-
function createWorkspaceSandboxRecoveryManager(store) {
|
|
326
|
-
async function transition(workspaceId, expected, next) {
|
|
327
|
-
if (store.compareAndSet) {
|
|
328
|
-
if (!await store.compareAndSet(workspaceId, expected, next))
|
|
329
|
-
throw new Error("Sandbox recovery changed; reload before retrying its transition");
|
|
330
|
-
} else {
|
|
331
|
-
await store.write(workspaceId, next);
|
|
332
|
-
}
|
|
333
|
-
return next;
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
read: (workspaceId) => store.read(workspaceId),
|
|
337
|
-
record: (workspaceId, recovery) => store.write(workspaceId, recovery),
|
|
338
|
-
async decide({ workspaceId, sandboxId, decision, replacementBoxKey }) {
|
|
339
|
-
const current = await store.read(workspaceId);
|
|
340
|
-
if (!current || current.sandboxId !== sandboxId || !("canDecide" in ACTIONS[current.action])) return void 0;
|
|
341
|
-
if (decision === "replace" && !asNonEmptyString(replacementBoxKey))
|
|
342
|
-
throw new Error("Sandbox replacement authorization requires a fresh replacement box key");
|
|
343
|
-
return transition(workspaceId, current, {
|
|
344
|
-
...current,
|
|
345
|
-
action: decision === "replace" ? current.snapshot.availability === "available" ? "snapshot_replacement_authorized" : "replacement_authorized" : "deletion_declined",
|
|
346
|
-
confirmedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
347
|
-
...decision === "replace" ? { replacementBoxKey } : {}
|
|
348
|
-
});
|
|
349
|
-
},
|
|
350
|
-
async complete({ workspaceId, replacementSandboxId, replacementBoxKey }) {
|
|
351
|
-
const current = await store.read(workspaceId);
|
|
352
|
-
if (!current || !asNonEmptyString(current.replacementBoxKey)) return void 0;
|
|
353
|
-
if (replacementBoxKey !== void 0 && current.replacementBoxKey !== replacementBoxKey) return void 0;
|
|
354
|
-
const policy = ACTIONS[current.action];
|
|
355
|
-
if (!("completedAs" in policy)) return void 0;
|
|
356
|
-
if (!asNonEmptyString(replacementSandboxId)) throw new Error("A replacement sandbox id is required");
|
|
357
|
-
return transition(workspaceId, current, { ...current, action: policy.completedAs, replacementSandboxId });
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
var WORKSPACE_SANDBOX_RECOVERY_ACTIONS = Object.keys(
|
|
362
|
-
ACTIONS
|
|
363
|
-
);
|
|
364
|
-
var WORKSPACE_SANDBOX_RECOVERY_CODES = Object.keys(
|
|
365
|
-
CODES
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
// src/sandbox/diagnostics.ts
|
|
369
|
-
var SAFE_ERROR_FIELDS = [
|
|
370
|
-
"code",
|
|
371
|
-
"status",
|
|
372
|
-
"phase",
|
|
373
|
-
"endpoint",
|
|
374
|
-
"origin",
|
|
375
|
-
"retryAfterMs",
|
|
376
|
-
"sidecarVersion",
|
|
377
|
-
"containerImage"
|
|
378
|
-
];
|
|
379
|
-
function isRecord2(value) {
|
|
380
|
-
return typeof value === "object" && value !== null;
|
|
381
|
-
}
|
|
382
|
-
function asSafeScalar(value) {
|
|
383
|
-
if (typeof value === "string" && value.length > 0) return redactDiagnosticText(value);
|
|
384
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
385
|
-
return void 0;
|
|
386
|
-
}
|
|
387
|
-
function redactDiagnosticText(value) {
|
|
388
|
-
const secretKeyPattern = "(?:(?:[A-Z0-9]+_)*(?:api_?key|auth_?token|access_?token|refresh_?token|key|token|password|secret|credential)|apiKey|authToken|accessToken|refreshToken)";
|
|
389
|
-
return value.replace(/(['"]authorization['"]\s*:\s*)(['"])[^'"]*\2/gi, "$1$2[REDACTED]$2").replace(/\b(authorization\s*[:=]\s*)(['"])[^'"]*\2/gi, "$1$2[REDACTED]$2").replace(/\b(authorization\s*[:=]\s*)Digest\b[^;}\n]*(?:\r?\n[ \t]+[^;}\n]*)*/gi, "$1[REDACTED]").replace(/\b(authorization\s*[:=]\s*)(?:Basic|Bearer|Negotiate)\s+[^\s;,&}\n]+(?:\r?\n[ \t]+[^\s;,&}\n]+)*/gi, "$1[REDACTED]").replace(new RegExp(`\\b(authorization\\s*[:=]\\s*)(?!(?:Basic|Bearer|Digest|Negotiate)\\b)([A-Za-z][A-Za-z0-9._-]+)\\s+(?!(?:authorization|${secretKeyPattern})\\s*[:=]|['"](?:authorization|${secretKeyPattern})['"]\\s*:)([^}\\n]*(?:\\r?\\n[ \\t]+[^}\\n]*)*)`, "gi"), (_match, prefix, _scheme, valuePart) => {
|
|
390
|
-
if (valuePart.includes(";") || /\r?\n[ \t]+/.test(valuePart)) return `${prefix}[REDACTED]`;
|
|
391
|
-
const tokenMatch = valuePart.match(/^\S+(.*)$/);
|
|
392
|
-
return `${prefix}[REDACTED]${tokenMatch?.[1] ?? ""}`;
|
|
393
|
-
}).replace(/\b(authorization\s*[:=]\s*)[A-Za-z][\w.-]+\s+[^\s;,&}\n]+(?=[;&}\n]|$)/gi, "$1[REDACTED]").replace(/\b(authorization\s*[:=]\s*)(?!\[REDACTED\])[^'"\s&}]+(?:[;,][^'"\s&}]+)*/gi, "$1[REDACTED]").replace(/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi, "Bearer [REDACTED]").replace(/\bsk-[A-Za-z0-9_-]{6,}\b/g, "sk-[REDACTED]").replace(
|
|
394
|
-
/([?&][^=&#\s]*(?:token|key|secret|password|authorization)[^=&#\s]*=)[^&#\s]+/gi,
|
|
395
|
-
"$1[REDACTED]"
|
|
396
|
-
).replace(
|
|
397
|
-
new RegExp(`(['"])(${secretKeyPattern})\\1\\s*:\\s*(['"])[^'"]+\\3`, "gi"),
|
|
398
|
-
"$1$2$1:$3[REDACTED]$3"
|
|
399
|
-
).replace(
|
|
400
|
-
new RegExp(`\\b(${secretKeyPattern})\\s*([:=])(\\s*)(['"]?)(?!Bearer\\b)[^'"\\s;,&}]+(?:[;,]\\s*[^'"\\s;,&}]+)*`, "gi"),
|
|
401
|
-
"$1$2$3$4[REDACTED]"
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
function readMessage(value) {
|
|
405
|
-
if (value instanceof Error) return redactDiagnosticText(value.message);
|
|
406
|
-
if (typeof value === "string" && value.length > 0) return redactDiagnosticText(value);
|
|
407
|
-
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
408
|
-
if (typeof value === "boolean") return String(value);
|
|
409
|
-
if (!isRecord2(value)) return void 0;
|
|
410
|
-
const message = value.message;
|
|
411
|
-
return typeof message === "string" && message.length > 0 ? redactDiagnosticText(message) : void 0;
|
|
412
|
-
}
|
|
413
|
-
function readName(value) {
|
|
414
|
-
if (value instanceof Error) return redactDiagnosticText(value.name);
|
|
415
|
-
if (!isRecord2(value)) return void 0;
|
|
416
|
-
const name = value.name;
|
|
417
|
-
return typeof name === "string" && name.length > 0 ? redactDiagnosticText(name) : void 0;
|
|
418
|
-
}
|
|
419
|
-
function readCause(value) {
|
|
420
|
-
if (!isRecord2(value)) return void 0;
|
|
421
|
-
return value.cause;
|
|
422
|
-
}
|
|
423
|
-
function serializeSandboxProvisioningError(error, options = {}) {
|
|
424
|
-
const maxDepth = options.maxDepth ?? 6;
|
|
425
|
-
const causes = [];
|
|
426
|
-
const seen = /* @__PURE__ */ new Set();
|
|
427
|
-
let truncatedAtDepth;
|
|
428
|
-
let cycle = false;
|
|
429
|
-
let current = error;
|
|
430
|
-
let depth = 0;
|
|
431
|
-
for (; depth < maxDepth && current !== void 0 && current !== null; depth += 1) {
|
|
432
|
-
if (seen.has(current)) {
|
|
433
|
-
cycle = true;
|
|
434
|
-
causes.push({
|
|
435
|
-
name: "CauseChainCycle",
|
|
436
|
-
message: `cause chain cycle detected after ${depth} entries`
|
|
437
|
-
});
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
if (isRecord2(current)) seen.add(current);
|
|
441
|
-
const cause = {};
|
|
442
|
-
const name = readName(current);
|
|
443
|
-
const message = readMessage(current);
|
|
444
|
-
if (name) cause.name = name;
|
|
445
|
-
if (message) cause.message = message;
|
|
446
|
-
if (isRecord2(current)) {
|
|
447
|
-
for (const field of SAFE_ERROR_FIELDS) {
|
|
448
|
-
const safeValue = asSafeScalar(current[field]);
|
|
449
|
-
if (safeValue !== void 0) {
|
|
450
|
-
Object.assign(cause, { [field]: safeValue });
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (Object.keys(cause).length > 0) causes.push(cause);
|
|
455
|
-
current = readCause(current);
|
|
456
|
-
}
|
|
457
|
-
if (!cycle && isRecord2(current) && seen.has(current)) {
|
|
458
|
-
cycle = true;
|
|
459
|
-
causes.push({
|
|
460
|
-
name: "CauseChainCycle",
|
|
461
|
-
message: `cause chain cycle detected after ${depth} entries`
|
|
462
|
-
});
|
|
463
|
-
} else if (current !== void 0 && current !== null && depth >= maxDepth) {
|
|
464
|
-
truncatedAtDepth = maxDepth;
|
|
465
|
-
causes.push({
|
|
466
|
-
name: "CauseChainTruncated",
|
|
467
|
-
message: `cause chain truncated after ${maxDepth} entries`
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
message: readMessage(error) ?? "Sandbox unavailable",
|
|
472
|
-
causes,
|
|
473
|
-
truncated: truncatedAtDepth !== void 0,
|
|
474
|
-
truncatedAtDepth,
|
|
475
|
-
cycle
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
function formatSandboxProvisioningSupportDetails(diagnostics) {
|
|
479
|
-
const actionableCause = diagnostics.causes.find(
|
|
480
|
-
(cause) => cause.code !== void 0 || cause.status !== void 0 || cause.phase !== void 0 || cause.endpoint !== void 0 || cause.origin !== void 0 || cause.retryAfterMs !== void 0 || cause.sidecarVersion !== void 0 || cause.containerImage !== void 0
|
|
481
|
-
) ?? diagnostics.causes[1];
|
|
482
|
-
if (!actionableCause) return "Support details: no nested sandbox cause details were available.";
|
|
483
|
-
const details = [
|
|
484
|
-
typeof actionableCause.name === "string" ? redactDiagnosticText(actionableCause.name) : void 0,
|
|
485
|
-
actionableCause.code !== void 0 ? `code=${actionableCause.code}` : void 0,
|
|
486
|
-
actionableCause.status !== void 0 ? `status=${actionableCause.status}` : void 0,
|
|
487
|
-
actionableCause.phase !== void 0 ? `phase=${redactDiagnosticText(actionableCause.phase)}` : void 0,
|
|
488
|
-
actionableCause.endpoint !== void 0 ? `endpoint=${redactDiagnosticText(actionableCause.endpoint)}` : void 0,
|
|
489
|
-
actionableCause.origin !== void 0 ? `origin=${redactDiagnosticText(actionableCause.origin)}` : void 0,
|
|
490
|
-
actionableCause.retryAfterMs !== void 0 ? `retryAfterMs=${actionableCause.retryAfterMs}` : void 0,
|
|
491
|
-
actionableCause.sidecarVersion !== void 0 ? `sidecarVersion=${redactDiagnosticText(actionableCause.sidecarVersion)}` : void 0,
|
|
492
|
-
actionableCause.containerImage !== void 0 ? `containerImage=${redactDiagnosticText(actionableCause.containerImage)}` : void 0,
|
|
493
|
-
typeof actionableCause.message === "string" ? redactDiagnosticText(actionableCause.message) : void 0
|
|
494
|
-
].filter(Boolean);
|
|
495
|
-
if (details.length === 0) return "Support details: no nested sandbox cause details were available.";
|
|
496
|
-
return `Support details: ${details.join("; ")}`;
|
|
497
|
-
}
|
|
498
|
-
function isSandboxAuthFailure(diagnostics) {
|
|
499
|
-
return diagnostics.causes.some((cause) => {
|
|
500
|
-
const code = typeof cause.code === "string" ? cause.code.toUpperCase() : void 0;
|
|
501
|
-
const status = typeof cause.status === "number" ? cause.status : typeof cause.status === "string" ? Number.parseInt(cause.status, 10) : void 0;
|
|
502
|
-
const name = typeof cause.name === "string" ? cause.name.toLowerCase() : "";
|
|
503
|
-
const message = typeof cause.message === "string" ? cause.message.toLowerCase() : "";
|
|
504
|
-
return code === "AUTH_ERROR" || status === 401 || name.includes("autherror") || message.includes("missing or invalid authentication");
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
function isSandboxApiBearerAuthFailure(diagnostics) {
|
|
508
|
-
return diagnostics.causes.some((cause) => {
|
|
509
|
-
const status = typeof cause.status === "number" ? cause.status : typeof cause.status === "string" ? Number.parseInt(cause.status, 10) : void 0;
|
|
510
|
-
if (status !== 401) return false;
|
|
511
|
-
if (cause.origin !== "sandbox-api") return false;
|
|
512
|
-
if (typeof cause.endpoint !== "string") return false;
|
|
513
|
-
const endpointPath = sandboxApiEndpointPath(cause.endpoint);
|
|
514
|
-
if (!endpointPath || !/^\/v1(?:[/?#]|$)/.test(endpointPath)) return false;
|
|
515
|
-
return !/^\/v1\/sandboxes\/[^/?#]+\/runtime(?:[/?#]|$)/.test(endpointPath);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
var SANDBOX_BACKING_CONTAINER_MISSING_CODE = "BACKING_CONTAINER_MISSING";
|
|
519
|
-
function isLegacySandboxBackingContainerMissingMessage(message) {
|
|
520
|
-
return /host-agent startcontainer failed \(404\):/i.test(message) && /container not found/i.test(message) && /"code"\s*:\s*"not_found"/i.test(message);
|
|
521
|
-
}
|
|
522
|
-
function isSandboxApiSandboxMissingFailure(diagnostics) {
|
|
523
|
-
return diagnostics.causes.some((cause) => {
|
|
524
|
-
const status = typeof cause.status === "number" ? cause.status : typeof cause.status === "string" ? Number.parseInt(cause.status, 10) : void 0;
|
|
525
|
-
if (cause.origin !== "sandbox-api") return false;
|
|
526
|
-
if (typeof cause.endpoint !== "string") return false;
|
|
527
|
-
const endpointPath = sandboxApiEndpointPath(cause.endpoint);
|
|
528
|
-
if (!endpointPath) return false;
|
|
529
|
-
const sandboxResource = /^\/v1\/sandboxes\/[^/?#]+(?:\/(?!runtime(?:[/?#]|$))[^?#]*)?(?:[?#].*)?$/.test(endpointPath);
|
|
530
|
-
if (!sandboxResource) return false;
|
|
531
|
-
if (status === 404) return true;
|
|
532
|
-
if (status !== 500 || !/^\/v1\/sandboxes\/[^/?#]+\/resume(?:[?#].*)?$/.test(endpointPath)) {
|
|
533
|
-
return false;
|
|
534
|
-
}
|
|
535
|
-
const code = typeof cause.code === "string" ? cause.code.toUpperCase() : void 0;
|
|
536
|
-
if (code === SANDBOX_BACKING_CONTAINER_MISSING_CODE) return true;
|
|
537
|
-
if (code !== void 0 && code !== "SERVER_ERROR") return false;
|
|
538
|
-
const message = typeof cause.message === "string" ? cause.message : "";
|
|
539
|
-
return isLegacySandboxBackingContainerMissingMessage(message);
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
function isSandboxHostCapacityFailure(diagnostics) {
|
|
543
|
-
return diagnostics.causes.some((cause) => {
|
|
544
|
-
if (cause.origin !== "sandbox-api") return false;
|
|
545
|
-
if (typeof cause.message !== "string") return false;
|
|
546
|
-
return /host has no available slot|host capacity reservation failed/i.test(cause.message);
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
function isSandboxBoxConfigFailure(diagnostics) {
|
|
550
|
-
return diagnostics.causes.some((cause) => {
|
|
551
|
-
if (cause.origin !== "sandbox-api") return false;
|
|
552
|
-
if (cause.code === "SANDBOX_ATTRIBUTION_MISMATCH") return true;
|
|
553
|
-
if (typeof cause.message !== "string") return false;
|
|
554
|
-
return /has no recorded egress policy|cannot rebuild the proxy config/i.test(cause.message);
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
function isSandboxApiTransientFailure(diagnostics) {
|
|
558
|
-
if (isSandboxApiSandboxMissingFailure(diagnostics) || isSandboxBoxConfigFailure(diagnostics) || isSandboxHostCapacityFailure(diagnostics)) return false;
|
|
559
|
-
return diagnostics.causes.some((cause) => {
|
|
560
|
-
const status = typeof cause.status === "number" ? cause.status : typeof cause.status === "string" ? Number.parseInt(cause.status, 10) : void 0;
|
|
561
|
-
if (status !== 500 && status !== 502 && status !== 503 && status !== 504) return false;
|
|
562
|
-
if (cause.origin !== "sandbox-api" || typeof cause.endpoint !== "string") return false;
|
|
563
|
-
const endpointPath = sandboxApiEndpointPath(cause.endpoint);
|
|
564
|
-
if (!endpointPath || !/^\/v1(?:[/?#]|$)/.test(endpointPath)) return false;
|
|
565
|
-
return !/^\/v1\/sandboxes\/[^/?#]+\/runtime(?:[/?#]|$)/.test(endpointPath);
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
function sandboxApiEndpointPath(endpoint) {
|
|
569
|
-
if (endpoint.startsWith("/")) return endpoint;
|
|
570
|
-
try {
|
|
571
|
-
const url = new URL(endpoint);
|
|
572
|
-
return `${url.pathname}${url.search}${url.hash}`;
|
|
573
|
-
} catch {
|
|
574
|
-
return null;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
function formatSandboxProvisioningUserMessage(diagnostics) {
|
|
578
|
-
if (diagnostics.causes.some((cause) => cause.code === EGRESS_PROXY_RECOVERY_REQUIRED)) {
|
|
579
|
-
return "Sandbox recovery is required before chat can continue. The stopped sandbox has not been deleted.";
|
|
580
|
-
}
|
|
581
|
-
if (diagnostics.causes.some((cause) => cause.code === "vault.hydration_incomplete")) {
|
|
582
|
-
return "I couldn't finish copying your Vault into the sandbox, so I stopped rather than work from a partial copy. The copy resumes where it left off \u2014 try again in a moment.";
|
|
583
|
-
}
|
|
584
|
-
if (isSandboxApiTransientFailure(diagnostics)) {
|
|
585
|
-
return "The sandbox service didn't answer just now. Send your message again in a moment.";
|
|
586
|
-
}
|
|
587
|
-
if (isSandboxApiBearerAuthFailure(diagnostics)) {
|
|
588
|
-
return "I'm unable to reconnect to the sandbox because its sandbox API credential was rejected. Another request may have rotated the bearer used for this operation.";
|
|
589
|
-
}
|
|
590
|
-
if (isSandboxAuthFailure(diagnostics)) {
|
|
591
|
-
return "I'm unable to reconnect to the sandbox because its runtime authentication failed. This can happen when an existing sandbox is reused with stale credentials.";
|
|
592
|
-
}
|
|
593
|
-
if (diagnostics.causes.some((cause) => cause.code === "PAYLOAD_TOO_LARGE" || cause.code === "FILE_TOO_LARGE" || cause.status === 413 || cause.status === "413")) {
|
|
594
|
-
if (diagnostics.causes.some((cause) => cause.message?.startsWith("writeProfileFilesToBox"))) {
|
|
595
|
-
return "A workspace file is too large to copy into the sandbox. The support details name the file.";
|
|
596
|
-
}
|
|
597
|
-
return "An attachment is too large for the sandbox to accept. Use a smaller file and try again.";
|
|
598
|
-
}
|
|
599
|
-
if (diagnostics.causes.some((cause) => cause.code === "UPLOAD_BUDGET_EXHAUSTED")) {
|
|
600
|
-
return "Too much attachment data is staged in the sandbox at once. Retry shortly.";
|
|
601
|
-
}
|
|
602
|
-
return "I'm unable to connect to the sandbox right now. Send your message again in a moment; if it keeps failing, share the support details with the team.";
|
|
603
|
-
}
|
|
604
|
-
|
|
605
182
|
// src/sandbox/workspace-sandbox-manager.ts
|
|
606
183
|
function createWorkspaceSandboxManager(opts) {
|
|
607
184
|
return {
|
|
@@ -1641,6 +1218,7 @@ async function isBoxAlive(box, probe) {
|
|
|
1641
1218
|
}
|
|
1642
1219
|
}
|
|
1643
1220
|
var DEFAULT_LIVENESS_CACHE_TTL_MS = 5e3;
|
|
1221
|
+
var PATIENT_LIVENESS_EXEC_TIMEOUT_MS = 3e4;
|
|
1644
1222
|
function hasRecentLivenessVerification(box, probe, now = Date.now()) {
|
|
1645
1223
|
const ttlMs = probe.cacheTtlMs ?? DEFAULT_LIVENESS_CACHE_TTL_MS;
|
|
1646
1224
|
if (!Number.isFinite(ttlMs) || ttlMs <= 0) return false;
|
|
@@ -1829,6 +1407,16 @@ function resumeEnvRequiredKeys(cause) {
|
|
|
1829
1407
|
return missingEnvKeys.filter((key) => typeof key === "string");
|
|
1830
1408
|
}
|
|
1831
1409
|
async function recoverUnresponsiveBox(client, box, probe, stage, name, resumeTimeout, runtimeEnv, onProgress) {
|
|
1410
|
+
if (probe && sandboxRuntimeUrl(box) && !sandboxEdgeFailed(box)) {
|
|
1411
|
+
const patient = await isBoxAlive(box, {
|
|
1412
|
+
...probe,
|
|
1413
|
+
execTimeoutMs: Math.max(PATIENT_LIVENESS_EXEC_TIMEOUT_MS, probe.execTimeoutMs ?? 0)
|
|
1414
|
+
});
|
|
1415
|
+
if (patient.succeeded) {
|
|
1416
|
+
livenessVerifiedAt.set(box.id, Date.now());
|
|
1417
|
+
return box;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1832
1420
|
try {
|
|
1833
1421
|
await box.stop();
|
|
1834
1422
|
} catch (err) {
|
|
@@ -2582,10 +2170,42 @@ async function resolveSandboxPromptBackend(shell, options, operation = "sandbox
|
|
|
2582
2170
|
...options.interactions ? { interactions: options.interactions } : {}
|
|
2583
2171
|
};
|
|
2584
2172
|
}
|
|
2173
|
+
var SANDBOX_DISPATCH_TRANSIENT_DEADLINE_MS = 8 * 6e4;
|
|
2174
|
+
async function* resendRefusedDispatch(dispatch, signal) {
|
|
2175
|
+
let delivered = false;
|
|
2176
|
+
let firstSeenAt;
|
|
2177
|
+
for (let attempts = 1; ; attempts += 1) {
|
|
2178
|
+
try {
|
|
2179
|
+
for await (const event of dispatch()) {
|
|
2180
|
+
delivered = true;
|
|
2181
|
+
yield event;
|
|
2182
|
+
}
|
|
2183
|
+
return;
|
|
2184
|
+
} catch (error) {
|
|
2185
|
+
const failure = delivered ? null : classifySandboxTransientFailure(error);
|
|
2186
|
+
if (!failure || failure.code === "sandbox.control_plane_transient") throw error;
|
|
2187
|
+
const at = Date.now();
|
|
2188
|
+
firstSeenAt ??= at;
|
|
2189
|
+
const delayMs = sandboxTransientBackoffMs(attempts);
|
|
2190
|
+
if (at + delayMs - firstSeenAt > SANDBOX_DISPATCH_TRANSIENT_DEADLINE_MS) {
|
|
2191
|
+
throw new SandboxTransientDeadlineError(failure, firstSeenAt, attempts, error);
|
|
2192
|
+
}
|
|
2193
|
+
console.warn("[sandbox] resending a dispatch the box refused", { code: failure.code, attempt: attempts, delayMs });
|
|
2194
|
+
await new Promise((resolve, reject) => {
|
|
2195
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
2196
|
+
const timer = setTimeout(resolve, delayMs);
|
|
2197
|
+
signal?.addEventListener("abort", () => {
|
|
2198
|
+
clearTimeout(timer);
|
|
2199
|
+
reject(signal.reason);
|
|
2200
|
+
}, { once: true });
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2585
2205
|
async function* streamSandboxPrompt(shell, box, message, options) {
|
|
2586
2206
|
const backend = await resolveSandboxPromptBackend(shell, options ?? {}, "streamSandboxPrompt");
|
|
2587
2207
|
const prompt = typeof message === "string" ? flattenHistory(message, options?.history) : mergeHistoryIntoParts(message, options?.history);
|
|
2588
|
-
const
|
|
2208
|
+
const dispatch = () => options?.detach ? detachedSandboxPromptEvents(box, prompt, options, backend) : box.streamPrompt(prompt, {
|
|
2589
2209
|
sessionId: options?.sessionId,
|
|
2590
2210
|
executionId: options?.executionId,
|
|
2591
2211
|
turnId: options?.turnId,
|
|
@@ -2598,6 +2218,7 @@ async function* streamSandboxPrompt(shell, box, message, options) {
|
|
|
2598
2218
|
...options?.expectedSecretProfileReceipt ? { expectedSecretProfileReceipt: options.expectedSecretProfileReceipt } : {},
|
|
2599
2219
|
backend
|
|
2600
2220
|
});
|
|
2221
|
+
const stream = options?.lastEventId ? dispatch() : resendRefusedDispatch(dispatch, options?.signal);
|
|
2601
2222
|
emitSandboxActivity(options?.spend, box);
|
|
2602
2223
|
let severedFinishReason = null;
|
|
2603
2224
|
try {
|
|
@@ -2818,37 +2439,6 @@ export {
|
|
|
2818
2439
|
shellQuote,
|
|
2819
2440
|
statSandboxFileSize,
|
|
2820
2441
|
readSandboxBinaryBytes,
|
|
2821
|
-
EGRESS_PROXY_RECOVERY_REQUIRED,
|
|
2822
|
-
EGRESS_PROXY_RECOVERY_PHASE,
|
|
2823
|
-
WORKSPACE_SANDBOX_MISSING,
|
|
2824
|
-
WORKSPACE_SANDBOX_HOST_EXHAUSTED,
|
|
2825
|
-
WORKSPACE_SANDBOX_UNRECOVERABLE,
|
|
2826
|
-
WORKSPACE_SANDBOX_SNAPSHOT_MAX_AGE_MS,
|
|
2827
|
-
WorkspaceSandboxRecoveryRequiredError,
|
|
2828
|
-
isEgressProxyRecoveryRequiredError,
|
|
2829
|
-
isWorkspaceSandboxSnapshotRestoreError,
|
|
2830
|
-
assessWorkspaceSandboxSnapshot,
|
|
2831
|
-
isWorkspaceSandboxRecoveryAction,
|
|
2832
|
-
isWorkspaceSandboxRecoveryCode,
|
|
2833
|
-
isWorkspaceSandboxRecoveryState,
|
|
2834
|
-
workspaceSandboxRecoveryFromError,
|
|
2835
|
-
workspaceSandboxRecoveryMessage,
|
|
2836
|
-
workspaceSandboxRecoveryRecommendedActions,
|
|
2837
|
-
workspaceSandboxRecoveryDiagnostic,
|
|
2838
|
-
preferredWorkspaceSandboxRecoveryBoxKey,
|
|
2839
|
-
shouldRestoreWorkspaceSandboxRecovery,
|
|
2840
|
-
createWorkspaceSandboxRecoveryManager,
|
|
2841
|
-
WORKSPACE_SANDBOX_RECOVERY_ACTIONS,
|
|
2842
|
-
WORKSPACE_SANDBOX_RECOVERY_CODES,
|
|
2843
|
-
serializeSandboxProvisioningError,
|
|
2844
|
-
formatSandboxProvisioningSupportDetails,
|
|
2845
|
-
isSandboxAuthFailure,
|
|
2846
|
-
isSandboxApiBearerAuthFailure,
|
|
2847
|
-
SANDBOX_BACKING_CONTAINER_MISSING_CODE,
|
|
2848
|
-
isSandboxApiSandboxMissingFailure,
|
|
2849
|
-
isSandboxHostCapacityFailure,
|
|
2850
|
-
isSandboxApiTransientFailure,
|
|
2851
|
-
formatSandboxProvisioningUserMessage,
|
|
2852
2442
|
createWorkspaceSandboxManager,
|
|
2853
2443
|
createSandboxTerminalConnectionRoute,
|
|
2854
2444
|
sandboxPrewarmClaimKey,
|
|
@@ -2898,6 +2488,7 @@ export {
|
|
|
2898
2488
|
applyPromptTokenLimits,
|
|
2899
2489
|
adaptSandboxStream,
|
|
2900
2490
|
resolveSandboxPromptBackend,
|
|
2491
|
+
SANDBOX_DISPATCH_TRANSIENT_DEADLINE_MS,
|
|
2901
2492
|
streamSandboxPrompt,
|
|
2902
2493
|
collectSandboxPromptText,
|
|
2903
2494
|
runSandboxPrompt,
|
|
@@ -2913,4 +2504,4 @@ export {
|
|
|
2913
2504
|
isTerminalPromptEvent,
|
|
2914
2505
|
detectInteractiveQuestion
|
|
2915
2506
|
};
|
|
2916
|
-
//# sourceMappingURL=chunk-
|
|
2507
|
+
//# sourceMappingURL=chunk-E7CDDDFW.js.map
|