autopilot-ai 1.20.0 → 1.20.1

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/index.js CHANGED
@@ -1478,9 +1478,46 @@ function stripOldImages(messages, keepLastTurns) {
1478
1478
  };
1479
1479
  });
1480
1480
  }
1481
+ function appendStoppedToolResults(messages, calls) {
1482
+ const answered = new Set(messages.filter((m) => m.role === "tool").map((m) => m.tool_call_id));
1483
+ let added = 0;
1484
+ for (const [id, name] of calls) {
1485
+ if (answered.has(id)) continue;
1486
+ messages.push({ role: "tool", tool_call_id: id, content: STOPPED_TOOL_RESULT, name });
1487
+ answered.add(id);
1488
+ added++;
1489
+ }
1490
+ return added;
1491
+ }
1492
+ function repairDanglingToolCalls(messages) {
1493
+ let inserted = 0;
1494
+ for (let i = 0; i < messages.length; i++) {
1495
+ const m = messages[i];
1496
+ if (m.role !== "assistant" || !m.tool_calls?.length) continue;
1497
+ let j = i + 1;
1498
+ const answered = /* @__PURE__ */ new Set();
1499
+ while (j < messages.length && messages[j].role === "tool") {
1500
+ const id = messages[j].tool_call_id;
1501
+ if (id) answered.add(id);
1502
+ j++;
1503
+ }
1504
+ const missing = m.tool_calls.filter((tc) => !answered.has(tc.id));
1505
+ if (missing.length === 0) continue;
1506
+ messages.splice(
1507
+ j,
1508
+ 0,
1509
+ ...missing.map((tc) => ({ role: "tool", tool_call_id: tc.id, content: STOPPED_TOOL_RESULT, name: tc.function.name }))
1510
+ );
1511
+ inserted += missing.length;
1512
+ i = j + missing.length - 1;
1513
+ }
1514
+ return inserted;
1515
+ }
1516
+ var STOPPED_TOOL_RESULT;
1481
1517
  var init_messages = __esm({
1482
1518
  "src/agent/messages.ts"() {
1483
1519
  "use strict";
1520
+ STOPPED_TOOL_RESULT = "(stopped)";
1484
1521
  }
1485
1522
  });
1486
1523
 
@@ -13066,7 +13103,9 @@ async function listSessions(limit = 30, cwd) {
13066
13103
  }
13067
13104
  async function loadSession(filePath) {
13068
13105
  const raw = await readFile13(filePath, "utf8");
13069
- return JSON.parse(raw);
13106
+ const file = JSON.parse(raw);
13107
+ if (Array.isArray(file.messages)) repairDanglingToolCalls(file.messages);
13108
+ return file;
13070
13109
  }
13071
13110
  async function addCheckpoint(filePath, checkpoint) {
13072
13111
  const file = await loadSession(filePath);
@@ -13095,6 +13134,7 @@ var INTENT_PREFIX_MAP;
13095
13134
  var init_sessions = __esm({
13096
13135
  "src/sessions.ts"() {
13097
13136
  "use strict";
13137
+ init_messages();
13098
13138
  init_storage_limits();
13099
13139
  INTENT_PREFIX_MAP = {
13100
13140
  diagnose: "Bug:",
@@ -37700,6 +37740,7 @@ function interruptTurn(deps) {
37700
37740
  ...e,
37701
37741
  { kind: "info", key: deps.mkKey(), text: "(interrupted)" }
37702
37742
  ]);
37743
+ appendStoppedToolResults(deps.messagesRef.current, deps.pendingToolCallsRef.current);
37703
37744
  if (!deps.skipPendingToolCleanup) {
37704
37745
  for (const [toolId] of deps.pendingToolCallsRef.current) {
37705
37746
  deps.updateTool(toolId, { status: "cancelled" });
@@ -37725,6 +37766,7 @@ function interruptOrExit(deps) {
37725
37766
  var init_input_handlers = __esm({
37726
37767
  "src/ui/input-handlers.ts"() {
37727
37768
  "use strict";
37769
+ init_messages();
37728
37770
  }
37729
37771
  });
37730
37772
 
@@ -40036,6 +40078,7 @@ ${wcagWarnings.join("\n")}` }
40036
40078
  denyPendingPermission,
40037
40079
  pendingToolCallsRef,
40038
40080
  updateTool,
40081
+ messagesRef,
40039
40082
  setEvents,
40040
40083
  mkKey,
40041
40084
  saveSessionSafe,
@@ -41163,14 +41206,7 @@ ${result2.output ?? "(output not captured)"}`,
41163
41206
  onError: async (e) => {
41164
41207
  noteTurnEnded(turnId);
41165
41208
  if (e.name === "AbortError") {
41166
- for (const [tcId, tcName] of pendingToolCallsRef.current) {
41167
- messagesRef.current.push({
41168
- role: "tool",
41169
- tool_call_id: tcId,
41170
- content: "(stopped)",
41171
- name: tcName
41172
- });
41173
- }
41209
+ appendStoppedToolResults(messagesRef.current, pendingToolCallsRef.current);
41174
41210
  setEvents(
41175
41211
  (evts) => evts.map((e2) => e2.kind === "tool" && e2.status === "running" ? { ...e2, status: "error", result: "(stopped)" } : e2)
41176
41212
  );