@tangle-network/agent-app 0.63.40 → 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.
Files changed (39) hide show
  1. package/dist/chat-routes/default-backend.d.ts +2 -4
  2. package/dist/chat-routes/hybrid-producer.d.ts +1 -1
  3. package/dist/chat-routes/index.js +3 -4
  4. package/dist/chat-routes/index.js.map +1 -1
  5. package/dist/{chunk-KYBE4UYT.js → chunk-JUGXFBOS.js} +5 -4
  6. package/dist/chunk-JUGXFBOS.js.map +1 -0
  7. package/dist/{chunk-NDXQFEZQ.js → chunk-NMDKUCUJ.js} +33 -49
  8. package/dist/chunk-NMDKUCUJ.js.map +1 -0
  9. package/dist/{chunk-5WSSH3X5.js → chunk-QVGDVY5U.js} +10 -3
  10. package/dist/chunk-QVGDVY5U.js.map +1 -0
  11. package/dist/{chunk-H4JL74GP.js → chunk-R5PW3FO4.js} +29 -6
  12. package/dist/{chunk-H4JL74GP.js.map → chunk-R5PW3FO4.js.map} +1 -1
  13. package/dist/{chunk-KA6LD4OI.js → chunk-U2PTQCQ3.js} +2 -2
  14. package/dist/launch-invariants/cli.js +2 -2
  15. package/dist/launch-invariants/index.js +1 -1
  16. package/dist/launch-invariants/schedule.d.ts +6 -0
  17. package/dist/launch-invariants/testing.js +2 -2
  18. package/dist/preset-cloudflare/index.js +1 -1
  19. package/dist/public-consultation/index.d.ts +1 -1
  20. package/dist/public-consultation/index.js +3 -4
  21. package/dist/public-consultation/index.js.map +1 -1
  22. package/dist/sandbox/computer-files.d.ts +9 -4
  23. package/dist/sandbox/computer-step.d.ts +23 -13
  24. package/dist/sandbox/index.d.ts +0 -1
  25. package/dist/sandbox/index.js +4 -10
  26. package/dist/sandbox/prompt-events.d.ts +2 -0
  27. package/dist/sandbox/prompt-result.d.ts +3 -2
  28. package/dist/sandbox/transient-failure.d.ts +23 -3
  29. package/dist/workspace-export/d1.d.ts +1 -1
  30. package/dist/workspace-export/index.js +1 -7
  31. package/dist/workspace-export/index.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/chunk-5WSSH3X5.js.map +0 -1
  34. package/dist/chunk-GY4IPYG4.js +0 -40
  35. package/dist/chunk-GY4IPYG4.js.map +0 -1
  36. package/dist/chunk-KYBE4UYT.js.map +0 -1
  37. package/dist/chunk-NDXQFEZQ.js.map +0 -1
  38. package/dist/sandbox/computer-receipts.d.ts +0 -46
  39. /package/dist/{chunk-KA6LD4OI.js.map → chunk-U2PTQCQ3.js.map} +0 -0
@@ -13,7 +13,7 @@ import {
13
13
  readDuringPlannedHostRestart,
14
14
  sandboxTransientBackoffMs,
15
15
  serializeSandboxProvisioningError
16
- } from "./chunk-H4JL74GP.js";
16
+ } from "./chunk-R5PW3FO4.js";
17
17
  import {
18
18
  DEFAULT_TURN_LOCK_LOCATION_HINT,
19
19
  createDurableTurnLock
@@ -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, before, executionId } = input;
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 (!before.succeeded) return unchecked(before.error);
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
- const earlier = before.files[path];
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 && before ? await saveComputerFiles({ box, vault, before, executionId: stepId ?? "unnamed-step" }) : void 0;
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-NDXQFEZQ.js.map
4309
+ //# sourceMappingURL=chunk-NMDKUCUJ.js.map