@tangle-network/agent-app 0.63.41 → 0.63.42
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/default-backend.d.ts +2 -4
- package/dist/chat-routes/hybrid-producer.d.ts +1 -1
- package/dist/chat-routes/index.js +2 -3
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/{chunk-RLQRWCPB.js → chunk-JUGXFBOS.js} +5 -4
- package/dist/chunk-JUGXFBOS.js.map +1 -0
- package/dist/{chunk-Y4RVCT7Z.js → chunk-NMDKUCUJ.js} +32 -48
- package/dist/chunk-NMDKUCUJ.js.map +1 -0
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +2 -3
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/sandbox/computer-files.d.ts +9 -4
- package/dist/sandbox/computer-step.d.ts +23 -13
- package/dist/sandbox/index.d.ts +0 -1
- package/dist/sandbox/index.js +1 -9
- package/dist/sandbox/prompt-events.d.ts +2 -0
- package/dist/sandbox/prompt-result.d.ts +3 -2
- package/dist/workspace-export/d1.d.ts +1 -1
- package/dist/workspace-export/index.js +1 -7
- package/dist/workspace-export/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-GY4IPYG4.js +0 -40
- package/dist/chunk-GY4IPYG4.js.map +0 -1
- package/dist/chunk-RLQRWCPB.js.map +0 -1
- package/dist/chunk-Y4RVCT7Z.js.map +0 -1
- package/dist/sandbox/computer-receipts.d.ts +0 -46
|
@@ -972,6 +972,10 @@ function isTerminalPromptEvent(event) {
|
|
|
972
972
|
const root = asPlainRecord(event);
|
|
973
973
|
return root?.type === "result" || root?.type === "done" && asPlainRecord(root.data)?.status !== "failed";
|
|
974
974
|
}
|
|
975
|
+
function isComputerInteractionEvent(event) {
|
|
976
|
+
const type = asPlainRecord(event)?.type;
|
|
977
|
+
return type === "interaction" || type === "interaction.cancel";
|
|
978
|
+
}
|
|
975
979
|
function detectInteractiveQuestion(event) {
|
|
976
980
|
const root = asPlainRecord(event);
|
|
977
981
|
if (!root) return null;
|
|
@@ -1306,12 +1310,13 @@ function noAnswerError(observation) {
|
|
|
1306
1310
|
if (failure) return new SandboxRunError("sandbox_failed", `The computer reported a failed execution: ${failure}`, { cause });
|
|
1307
1311
|
return new SandboxRunError("sandbox_empty", "The sandbox finished without an answer.", { cause });
|
|
1308
1312
|
}
|
|
1309
|
-
async function collectSandboxPrompt(events, message2, history) {
|
|
1313
|
+
async function collectSandboxPrompt(events, message2, history, observe) {
|
|
1310
1314
|
let finalText = "";
|
|
1311
1315
|
const textParts = /* @__PURE__ */ new Map();
|
|
1312
1316
|
let anonymousTextPart = 0;
|
|
1313
1317
|
const observation = { terminal: false, types: /* @__PURE__ */ new Map() };
|
|
1314
1318
|
for await (const rawEvent of events) {
|
|
1319
|
+
observe?.(rawEvent);
|
|
1315
1320
|
const event = rawEvent;
|
|
1316
1321
|
if (!event.type) continue;
|
|
1317
1322
|
observePromptEvent(observation, event.type, record(event.data));
|
|
@@ -1331,8 +1336,8 @@ async function collectSandboxPrompt(events, message2, history) {
|
|
|
1331
1336
|
const answer = finalText || lastNonPromptTextPart(textParts, dispatchedPromptTexts(message2, history));
|
|
1332
1337
|
return { answer, observation };
|
|
1333
1338
|
}
|
|
1334
|
-
async function runSandboxPrompt(shell, box, message2, options) {
|
|
1335
|
-
const { answer, observation } = await collectSandboxPrompt(streamSandboxPrompt(shell, box, message2, options), message2, options?.history);
|
|
1339
|
+
async function runSandboxPrompt(shell, box, message2, options, observe) {
|
|
1340
|
+
const { answer, observation } = await collectSandboxPrompt(streamSandboxPrompt(shell, box, message2, options), message2, options?.history, observe);
|
|
1336
1341
|
if (!answer || !observation.terminal || observation.failure) throw noAnswerError(observation);
|
|
1337
1342
|
return answer;
|
|
1338
1343
|
}
|
|
@@ -1397,8 +1402,9 @@ async function listComputerFiles(box, root) {
|
|
|
1397
1402
|
return { succeeded: false, error: message(error) };
|
|
1398
1403
|
}
|
|
1399
1404
|
}
|
|
1405
|
+
var MTIME_TOLERANCE_MS = 1e3;
|
|
1400
1406
|
async function saveComputerFiles(input) {
|
|
1401
|
-
const { box, vault,
|
|
1407
|
+
const { box, vault, since, executionId } = input;
|
|
1402
1408
|
const root = vault.root.replace(/\/+$/, "");
|
|
1403
1409
|
const unchecked = (error) => {
|
|
1404
1410
|
console.warn(JSON.stringify({ event: "agent_app_computer_files_unchecked", executionId, error }));
|
|
@@ -1409,7 +1415,7 @@ async function saveComputerFiles(input) {
|
|
|
1409
1415
|
text: "Workspace vault: the app could not check which files this step saved, so none is confirmed to be in it."
|
|
1410
1416
|
};
|
|
1411
1417
|
};
|
|
1412
|
-
if (!
|
|
1418
|
+
if (since === void 0 || !Number.isFinite(since)) return unchecked("the runtime ledger did not report when the step started");
|
|
1413
1419
|
const after = await listComputerFiles(box, root);
|
|
1414
1420
|
if (!after.succeeded) return unchecked(after.error);
|
|
1415
1421
|
const maxFiles = vault.maxFiles ?? DEFAULT_MAX_FILES;
|
|
@@ -1417,8 +1423,7 @@ async function saveComputerFiles(input) {
|
|
|
1417
1423
|
const saved = [];
|
|
1418
1424
|
const computerOnly = [];
|
|
1419
1425
|
for (const [path, file] of Object.entries(after.files)) {
|
|
1420
|
-
|
|
1421
|
-
if (earlier && earlier.size === file.size && earlier.mtime === file.mtime) continue;
|
|
1426
|
+
if (file.mtime < since - MTIME_TOLERANCE_MS) continue;
|
|
1422
1427
|
if (!isWorkspaceFileExportable(path)) continue;
|
|
1423
1428
|
const refusal = saved.length + computerOnly.length >= maxFiles ? `more than ${maxFiles} files changed` : refuse(path, file.size);
|
|
1424
1429
|
if (refusal) {
|
|
@@ -1489,7 +1494,6 @@ function modelWithinAllowList(preferred, allowedModels) {
|
|
|
1489
1494
|
|
|
1490
1495
|
// src/sandbox/computer-step.ts
|
|
1491
1496
|
var ALLOW_LIST_BUDGET_MS = 5e3;
|
|
1492
|
-
var RECEIPT_LISTING_LIMIT = 2e3;
|
|
1493
1497
|
async function digestHex(value) {
|
|
1494
1498
|
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(value)));
|
|
1495
1499
|
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
@@ -1518,6 +1522,16 @@ function refusedForModel(error) {
|
|
|
1518
1522
|
}
|
|
1519
1523
|
return false;
|
|
1520
1524
|
}
|
|
1525
|
+
async function runStartedAt(box, sessionId, executionIds) {
|
|
1526
|
+
if (!sessionId || executionIds.length === 0) return void 0;
|
|
1527
|
+
try {
|
|
1528
|
+
const started = (await box.session(sessionId).runs()).filter((run) => executionIds.includes(run.executionId)).map((run) => run.startedAt).filter(Number.isFinite);
|
|
1529
|
+
return started.length ? Math.min(...started) : void 0;
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
console.warn(JSON.stringify({ event: "agent_app_computer_run_ledger_unread", sessionId, error: errorText(error) }));
|
|
1532
|
+
return void 0;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1521
1535
|
function createComputerStep(options) {
|
|
1522
1536
|
if (!options.run && !options.shell) throw new Error("A computer step needs the product shell or its own run");
|
|
1523
1537
|
const vault = options.files;
|
|
@@ -1534,39 +1548,18 @@ function createComputerStep(options) {
|
|
|
1534
1548
|
const parent = options.parentExecutionId?.trim();
|
|
1535
1549
|
const call = callId?.trim();
|
|
1536
1550
|
const stepId = parent ? await digestHex([parent, session?.id, call || crypto.randomUUID()]) : void 0;
|
|
1537
|
-
const receipts = stepId && call ? options.receipts : void 0;
|
|
1538
|
-
const prior = await receipts?.read(stepId).catch((error) => {
|
|
1539
|
-
console.warn(JSON.stringify({ event: "agent_app_computer_receipt_unread", stepId, error: errorText(error) }));
|
|
1540
|
-
return null;
|
|
1541
|
-
});
|
|
1542
1551
|
const report = (state, extra) => taskOptions.emit("computer_receipt", {
|
|
1543
1552
|
stepId: stepId ?? null,
|
|
1544
1553
|
sessionId: session?.id ?? null,
|
|
1545
1554
|
state,
|
|
1546
1555
|
...extra
|
|
1547
1556
|
});
|
|
1548
|
-
if (prior?.state === "settled" && prior.answer?.trim()) {
|
|
1549
|
-
report("settled", { model: prior.model ?? null, saved: prior.files?.saved ?? [], repeated: true });
|
|
1550
|
-
return prior.answer;
|
|
1551
|
-
}
|
|
1552
1557
|
const models = await modelChain(options.models, signal);
|
|
1553
1558
|
let model = models[0];
|
|
1554
|
-
const before = vault ? prior?.before ?? await listComputerFiles(box, vault.root.replace(/\/+$/, "")) : void 0;
|
|
1555
|
-
if (receipts) {
|
|
1556
|
-
const kept = before?.succeeded && Object.keys(before.files).length > RECEIPT_LISTING_LIMIT ? void 0 : before;
|
|
1557
|
-
await receipts.write({
|
|
1558
|
-
stepId,
|
|
1559
|
-
state: "prepared",
|
|
1560
|
-
sessionId: session?.id ?? "",
|
|
1561
|
-
...model ? { model } : {},
|
|
1562
|
-
...kept ? { before: kept } : {},
|
|
1563
|
-
updatedAt: Date.now()
|
|
1564
|
-
}).catch((error) => {
|
|
1565
|
-
console.warn(JSON.stringify({ event: "agent_app_computer_receipt_unwritten", stepId, state: "prepared", error: errorText(error) }));
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
1559
|
const framed = vault ? computerFileContract(vault.root.replace(/\/+$/, ""), frame(task)) : frame(task);
|
|
1560
|
+
const attempted = [];
|
|
1569
1561
|
const send = (attemptModel, executionId) => {
|
|
1562
|
+
if (executionId) attempted.push(executionId);
|
|
1570
1563
|
if (options.run) {
|
|
1571
1564
|
return options.run(box, framed, {
|
|
1572
1565
|
...taskOptions,
|
|
@@ -1585,16 +1578,20 @@ function createComputerStep(options) {
|
|
|
1585
1578
|
...executionId ? { executionId, turnId: executionId } : {},
|
|
1586
1579
|
...session ? { sessionId: session.id } : {},
|
|
1587
1580
|
...session?.isolated ? { secretProfileIsolation: true } : {},
|
|
1581
|
+
// The run outlives this request; a repeated call reattaches to it through the runtime's admission.
|
|
1582
|
+
...session && executionId ? { detach: true } : {},
|
|
1583
|
+
...options.questions ? { interactions: { ...prompt.interactions, question: true } } : { disallowQuestions: true },
|
|
1588
1584
|
signal,
|
|
1589
1585
|
timeoutMs,
|
|
1590
|
-
disallowQuestions: true,
|
|
1591
1586
|
...trace ? { trace } : {},
|
|
1592
1587
|
...span ? { traceParent: span } : {},
|
|
1593
1588
|
onDispatch: () => {
|
|
1594
1589
|
sent = true;
|
|
1595
1590
|
prompt.onDispatch?.();
|
|
1596
1591
|
}
|
|
1597
|
-
})
|
|
1592
|
+
}, options.questions ? (event) => {
|
|
1593
|
+
if (isComputerInteractionEvent(event)) taskOptions.emit("computer_interaction", event);
|
|
1594
|
+
} : void 0);
|
|
1598
1595
|
};
|
|
1599
1596
|
let answer;
|
|
1600
1597
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -1619,23 +1616,10 @@ function createComputerStep(options) {
|
|
|
1619
1616
|
}
|
|
1620
1617
|
}
|
|
1621
1618
|
if (!answer.trim()) return answer;
|
|
1622
|
-
const files = vault
|
|
1619
|
+
const files = vault ? await saveComputerFiles({ box, vault, since: await runStartedAt(box, session?.id, attempted), executionId: stepId ?? "unnamed-step" }) : void 0;
|
|
1623
1620
|
const final = files ? `${answer}
|
|
1624
1621
|
|
|
1625
1622
|
${files.text}` : answer;
|
|
1626
|
-
if (receipts) {
|
|
1627
|
-
await receipts.write({
|
|
1628
|
-
stepId,
|
|
1629
|
-
state: "settled",
|
|
1630
|
-
sessionId: session?.id ?? "",
|
|
1631
|
-
...model ? { model } : {},
|
|
1632
|
-
answer: final,
|
|
1633
|
-
...files ? { files } : {},
|
|
1634
|
-
updatedAt: Date.now()
|
|
1635
|
-
}).catch((error) => {
|
|
1636
|
-
console.warn(JSON.stringify({ event: "agent_app_computer_receipt_unwritten", stepId, state: "settled", error: errorText(error) }));
|
|
1637
|
-
});
|
|
1638
|
-
}
|
|
1639
1623
|
report("settled", { model: model ?? null, saved: files?.saved ?? [], computerOnly: files?.computerOnly.length ?? 0 });
|
|
1640
1624
|
return final;
|
|
1641
1625
|
};
|
|
@@ -4322,4 +4306,4 @@ export {
|
|
|
4322
4306
|
SandboxFilesystemNotReadyError,
|
|
4323
4307
|
runForegroundSandboxSingleFlight
|
|
4324
4308
|
};
|
|
4325
|
-
//# sourceMappingURL=chunk-
|
|
4309
|
+
//# sourceMappingURL=chunk-NMDKUCUJ.js.map
|