openfox 1.6.77 → 1.6.79

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 (26) hide show
  1. package/dist/{auto-compaction-GOHNI2R2.js → auto-compaction-KTA6H4HP.js} +5 -5
  2. package/dist/{chat-handler-K2RDXBO6.js → chat-handler-EKAO6CIB.js} +8 -8
  3. package/dist/{chunk-I7JVS7V5.js → chunk-2IZMUXMP.js} +3 -3
  4. package/dist/{chunk-XSUQDB6R.js → chunk-3JU4NOQD.js} +36 -22
  5. package/dist/{chunk-6SYNGMU4.js → chunk-BG7QCFGG.js} +4 -4
  6. package/dist/{chunk-XKIEDGQF.js → chunk-DL6ZILAF.js} +1 -2
  7. package/dist/{chunk-OJBFC6ER.js → chunk-HOD7GVQ5.js} +3 -3
  8. package/dist/{chunk-UVN6AKIO.js → chunk-RJRG2VER.js} +33 -2
  9. package/dist/{chunk-BBC46FN4.js → chunk-TS5XFQ2D.js} +88 -48
  10. package/dist/{chunk-EBQYRNNU.js → chunk-UCZSBKG7.js} +176 -92
  11. package/dist/cli/dev.js +1 -1
  12. package/dist/cli/index.js +1 -1
  13. package/dist/{events-5RIXWI5Y.js → events-ND5GZBT2.js} +7 -5
  14. package/dist/{folding-JNOUTI5Z.js → folding-XIKR6AFM.js} +14 -4
  15. package/dist/{inspect-proxy-Y75AXMRX.js → inspect-proxy-42ZXL2R5.js} +2 -2
  16. package/dist/{orchestrator-TW5II347.js → orchestrator-5U4O4K7V.js} +6 -6
  17. package/dist/package.json +1 -1
  18. package/dist/{processor-MZ3QIUED.js → processor-O35Q3EZT.js} +5 -5
  19. package/dist/{serve-FTTLGRAO.js → serve-55GF3KJW.js} +7 -7
  20. package/dist/server/index.js +6 -6
  21. package/dist/{service-D6LC3CAM.js → service-TU4XSXYJ.js} +33 -2
  22. package/dist/{tools-QJ5K5IJP.js → tools-W6OPDFQV.js} +5 -5
  23. package/dist/web/assets/{index-FjLp1t6r.js → index-BJtUJYiT.js} +49 -49
  24. package/dist/web/index.html +1 -1
  25. package/dist/web/sw.js +1 -1
  26. package/package.json +1 -1
@@ -2,16 +2,16 @@ import {
2
2
  maybeAutoCompactContext,
3
3
  performManualContextCompaction,
4
4
  resolveCompactionStatsIdentity
5
- } from "./chunk-EBQYRNNU.js";
5
+ } from "./chunk-UCZSBKG7.js";
6
6
  import "./chunk-OXI26S7U.js";
7
7
  import "./chunk-CMQCO27Y.js";
8
- import "./chunk-XKIEDGQF.js";
8
+ import "./chunk-DL6ZILAF.js";
9
9
  import "./chunk-PBGOZMVY.js";
10
10
  import "./chunk-VRGRAQDG.js";
11
11
  import "./chunk-CUDAT6SS.js";
12
- import "./chunk-UVN6AKIO.js";
12
+ import "./chunk-RJRG2VER.js";
13
13
  import "./chunk-KIOUKC3Z.js";
14
- import "./chunk-BBC46FN4.js";
14
+ import "./chunk-TS5XFQ2D.js";
15
15
  import "./chunk-STYHKCG7.js";
16
16
  import "./chunk-BJYPTN5S.js";
17
17
  import "./chunk-NDJ6FKSP.js";
@@ -24,4 +24,4 @@ export {
24
24
  performManualContextCompaction,
25
25
  resolveCompactionStatsIdentity
26
26
  };
27
- //# sourceMappingURL=auto-compaction-GOHNI2R2.js.map
27
+ //# sourceMappingURL=auto-compaction-KTA6H4HP.js.map
@@ -5,22 +5,22 @@ import {
5
5
  generateSessionName,
6
6
  getSessionMessageCount,
7
7
  needsNameGenerationCheck
8
- } from "./chunk-I7JVS7V5.js";
8
+ } from "./chunk-2IZMUXMP.js";
9
9
  import {
10
10
  runChatTurn
11
- } from "./chunk-6SYNGMU4.js";
12
- import "./chunk-EBQYRNNU.js";
11
+ } from "./chunk-BG7QCFGG.js";
12
+ import "./chunk-UCZSBKG7.js";
13
13
  import "./chunk-OXI26S7U.js";
14
14
  import "./chunk-CMQCO27Y.js";
15
- import "./chunk-XKIEDGQF.js";
15
+ import "./chunk-DL6ZILAF.js";
16
16
  import "./chunk-PBGOZMVY.js";
17
17
  import "./chunk-VRGRAQDG.js";
18
18
  import "./chunk-CUDAT6SS.js";
19
19
  import {
20
20
  getEventStore
21
- } from "./chunk-UVN6AKIO.js";
21
+ } from "./chunk-RJRG2VER.js";
22
22
  import "./chunk-KIOUKC3Z.js";
23
- import "./chunk-BBC46FN4.js";
23
+ import "./chunk-TS5XFQ2D.js";
24
24
  import {
25
25
  createChatMessageMessage,
26
26
  createPhaseChangedMessage,
@@ -61,7 +61,7 @@ async function startChatSession(sessionId, content, deps, options) {
61
61
  sessionManager.setRunning(sessionId, true);
62
62
  broadcastForSession(sessionId, createSessionRunningMessage(true));
63
63
  try {
64
- const { maybeAutoCompactContext } = await import("./auto-compaction-GOHNI2R2.js");
64
+ const { maybeAutoCompactContext } = await import("./auto-compaction-KTA6H4HP.js");
65
65
  await maybeAutoCompactContext({
66
66
  sessionManager,
67
67
  sessionId,
@@ -172,4 +172,4 @@ export {
172
172
  startChatSession,
173
173
  stopSessionExecution
174
174
  };
175
- //# sourceMappingURL=chat-handler-K2RDXBO6.js.map
175
+ //# sourceMappingURL=chat-handler-EKAO6CIB.js.map
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getEventStore,
3
3
  updateSessionMetadata
4
- } from "./chunk-UVN6AKIO.js";
4
+ } from "./chunk-RJRG2VER.js";
5
5
  import {
6
6
  buildMessagesFromStoredEvents,
7
7
  foldPendingConfirmations
8
- } from "./chunk-BBC46FN4.js";
8
+ } from "./chunk-TS5XFQ2D.js";
9
9
  import {
10
10
  createContextStateMessage,
11
11
  createSessionStateMessage
@@ -143,4 +143,4 @@ export {
143
143
  needsNameGenerationCheck,
144
144
  applyGeneratedSessionName
145
145
  };
146
- //# sourceMappingURL=chunk-I7JVS7V5.js.map
146
+ //# sourceMappingURL=chunk-2IZMUXMP.js.map
@@ -2,7 +2,7 @@ import {
2
2
  createVerifierNudgeConfig,
3
3
  runBuilderTurn,
4
4
  runChatTurn
5
- } from "./chunk-6SYNGMU4.js";
5
+ } from "./chunk-BG7QCFGG.js";
6
6
  import {
7
7
  TurnMetrics,
8
8
  agentExists,
@@ -37,7 +37,7 @@ import {
37
37
  setSkillEnabled,
38
38
  skillExists,
39
39
  spawnShellProcess
40
- } from "./chunk-EBQYRNNU.js";
40
+ } from "./chunk-UCZSBKG7.js";
41
41
  import {
42
42
  getProject
43
43
  } from "./chunk-CMQCO27Y.js";
@@ -87,14 +87,14 @@ import {
87
87
  updateSessionProvider,
88
88
  updateSessionRunning,
89
89
  updateSessionSummary
90
- } from "./chunk-UVN6AKIO.js";
90
+ } from "./chunk-RJRG2VER.js";
91
91
  import {
92
92
  initDatabase
93
93
  } from "./chunk-KIOUKC3Z.js";
94
94
  import {
95
95
  buildMessagesFromStoredEvents,
96
96
  foldPendingConfirmations
97
- } from "./chunk-BBC46FN4.js";
97
+ } from "./chunk-TS5XFQ2D.js";
98
98
  import {
99
99
  createChatErrorMessage,
100
100
  createChatMessageMessage,
@@ -5242,7 +5242,7 @@ function createTerminalRoutes() {
5242
5242
  }
5243
5243
 
5244
5244
  // src/constants.ts
5245
- var VERSION = "1.6.77";
5245
+ var VERSION = "1.6.79";
5246
5246
 
5247
5247
  // src/server/index.ts
5248
5248
  var __dirname2 = dirname5(fileURLToPath4(import.meta.url));
@@ -5404,7 +5404,7 @@ async function createServerHandle(config) {
5404
5404
  res.json({ success: true });
5405
5405
  });
5406
5406
  app.get("/api/sessions", async (req, res) => {
5407
- const { getRecentUserPromptsForSession } = await import("./events-5RIXWI5Y.js");
5407
+ const { getRecentUserPromptsForSession } = await import("./events-ND5GZBT2.js");
5408
5408
  const projectId = req.query["projectId"];
5409
5409
  const limit = Math.min(parseInt(req.query["limit"]) || 20, 100);
5410
5410
  const offset = parseInt(req.query["offset"]) || 0;
@@ -5437,8 +5437,8 @@ async function createServerHandle(config) {
5437
5437
  res.status(201).json({ session });
5438
5438
  });
5439
5439
  app.get("/api/sessions/:id", async (req, res) => {
5440
- const { getEventStore: getEventStore2 } = await import("./events-5RIXWI5Y.js");
5441
- const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-JNOUTI5Z.js");
5440
+ const { getEventStore: getEventStore2 } = await import("./events-ND5GZBT2.js");
5441
+ const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-XIKR6AFM.js");
5442
5442
  const session = sessionManager.getSession(req.params.id);
5443
5443
  if (!session) {
5444
5444
  return res.status(404).json({ error: "Session not found" });
@@ -5468,8 +5468,8 @@ async function createServerHandle(config) {
5468
5468
  res.json({ success: true });
5469
5469
  });
5470
5470
  app.post("/api/sessions/:id/provider", async (req, res) => {
5471
- const { getEventStore: getEventStore2 } = await import("./events-5RIXWI5Y.js");
5472
- const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-JNOUTI5Z.js");
5471
+ const { getEventStore: getEventStore2 } = await import("./events-ND5GZBT2.js");
5472
+ const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-XIKR6AFM.js");
5473
5473
  const sessionId = req.params.id;
5474
5474
  const session = sessionManager.getSession(sessionId);
5475
5475
  if (!session) {
@@ -5506,8 +5506,8 @@ async function createServerHandle(config) {
5506
5506
  res.json({ success: true });
5507
5507
  });
5508
5508
  app.put("/api/sessions/:id/mode", async (req, res) => {
5509
- const { getEventStore: getEventStore2 } = await import("./events-5RIXWI5Y.js");
5510
- const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-JNOUTI5Z.js");
5509
+ const { getEventStore: getEventStore2 } = await import("./events-ND5GZBT2.js");
5510
+ const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2 } = await import("./folding-XIKR6AFM.js");
5511
5511
  const sessionId = req.params.id;
5512
5512
  const session = sessionManager.getSession(sessionId);
5513
5513
  if (!session) {
@@ -5559,13 +5559,13 @@ async function createServerHandle(config) {
5559
5559
  if (!callId || approved === void 0) {
5560
5560
  return res.status(400).json({ error: "callId and approved are required" });
5561
5561
  }
5562
- const { providePathConfirmation } = await import("./tools-QJ5K5IJP.js");
5562
+ const { providePathConfirmation } = await import("./tools-W6OPDFQV.js");
5563
5563
  const result = providePathConfirmation(callId, approved, alwaysAllow);
5564
5564
  if (!result.found) {
5565
5565
  return res.status(404).json({ error: "No pending path confirmation with that ID" });
5566
5566
  }
5567
- const { getEventStore: getEventStore2 } = await import("./events-5RIXWI5Y.js");
5568
- const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2, foldPendingConfirmations: foldPendingConfirmations2 } = await import("./folding-JNOUTI5Z.js");
5567
+ const { getEventStore: getEventStore2 } = await import("./events-ND5GZBT2.js");
5568
+ const { buildMessagesFromStoredEvents: buildMessagesFromStoredEvents2, foldPendingConfirmations: foldPendingConfirmations2 } = await import("./folding-XIKR6AFM.js");
5569
5569
  const { createSessionStateMessage: createSessionStateMessage2 } = await import("./protocol-4CTV7OZC.js");
5570
5570
  const eventStore = getEventStore2();
5571
5571
  const events = eventStore.getEvents(sessionId);
@@ -5583,7 +5583,7 @@ async function createServerHandle(config) {
5583
5583
  if (!callId || !answer) {
5584
5584
  return res.status(400).json({ error: "callId and answer are required" });
5585
5585
  }
5586
- const { provideAnswer: provideAnswer2 } = await import("./tools-QJ5K5IJP.js");
5586
+ const { provideAnswer: provideAnswer2 } = await import("./tools-W6OPDFQV.js");
5587
5587
  const found = provideAnswer2(callId, answer);
5588
5588
  if (!found) {
5589
5589
  return res.status(404).json({ error: "No pending question with that ID" });
@@ -5619,17 +5619,31 @@ async function createServerHandle(config) {
5619
5619
  if (!session) {
5620
5620
  return res.status(404).json({ error: "Session not found" });
5621
5621
  }
5622
- const { stopSessionExecution } = await import("./chat-handler-K2RDXBO6.js");
5623
- const { cancelQuestionsForSession, cancelPathConfirmationsForSession } = await import("./tools-QJ5K5IJP.js");
5622
+ const { stopSessionExecution } = await import("./chat-handler-EKAO6CIB.js");
5623
+ const { cancelQuestionsForSession, cancelPathConfirmationsForSession } = await import("./tools-W6OPDFQV.js");
5624
5624
  stopSessionExecution(sessionId, sessionManager);
5625
5625
  abortSession(sessionId);
5626
5626
  cancelQuestionsForSession(sessionId, "Session stopped by user");
5627
5627
  cancelPathConfirmationsForSession(sessionId, "Session stopped by user");
5628
5628
  sessionManager.clearMessageQueue(sessionId);
5629
- const eventStore = (await import("./events-5RIXWI5Y.js")).getEventStore();
5629
+ const eventStore = (await import("./events-ND5GZBT2.js")).getEventStore();
5630
5630
  eventStore.append(sessionId, { type: "running.changed", data: { isRunning: false } });
5631
5631
  res.json({ success: true });
5632
5632
  });
5633
+ app.post("/api/sessions/:id/truncate", async (req, res) => {
5634
+ const sessionId = req.params.id;
5635
+ const session = sessionManager.getSession(sessionId);
5636
+ if (!session) {
5637
+ return res.status(404).json({ error: "Session not found" });
5638
+ }
5639
+ const { messageIndex } = req.body;
5640
+ if (typeof messageIndex !== "number" || messageIndex < 0) {
5641
+ return res.status(400).json({ error: "messageIndex must be a non-negative number" });
5642
+ }
5643
+ const { truncateSessionMessages } = await import("./events-ND5GZBT2.js");
5644
+ truncateSessionMessages(sessionId, messageIndex);
5645
+ res.json({ success: true });
5646
+ });
5633
5647
  app.post("/api/sessions/:id/chat", async (req, res) => {
5634
5648
  const sessionId = req.params.id;
5635
5649
  const session = sessionManager.getSession(sessionId);
@@ -6094,7 +6108,7 @@ async function createServerHandle(config) {
6094
6108
  providerManager
6095
6109
  );
6096
6110
  const wss = wssExports.wss;
6097
- const { QueueProcessor } = await import("./processor-MZ3QIUED.js");
6111
+ const { QueueProcessor } = await import("./processor-O35Q3EZT.js");
6098
6112
  const queueProcessor = new QueueProcessor({
6099
6113
  sessionManager,
6100
6114
  providerManager,
@@ -6132,7 +6146,7 @@ async function createServerHandle(config) {
6132
6146
  logger.info("Shutting down...");
6133
6147
  void (async () => {
6134
6148
  await devServerManager.stopAll();
6135
- const { stopAllInspectProxies } = await import("./inspect-proxy-Y75AXMRX.js");
6149
+ const { stopAllInspectProxies } = await import("./inspect-proxy-42ZXL2R5.js");
6136
6150
  stopAllInspectProxies();
6137
6151
  const { cleanupAllProcesses } = await import("./store-OQ45KONN.js");
6138
6152
  cleanupAllProcesses();
@@ -6169,4 +6183,4 @@ export {
6169
6183
  createServerHandle,
6170
6184
  createServer
6171
6185
  };
6172
- //# sourceMappingURL=chunk-XSUQDB6R.js.map
6186
+ //# sourceMappingURL=chunk-3JU4NOQD.js.map
@@ -13,14 +13,14 @@ import {
13
13
  getToolRegistryForAgent,
14
14
  loadAllAgentsDefault,
15
15
  runTopLevelAgentLoop
16
- } from "./chunk-EBQYRNNU.js";
16
+ } from "./chunk-UCZSBKG7.js";
17
17
  import {
18
18
  getCurrentContextWindowId,
19
19
  getEventStore
20
- } from "./chunk-UVN6AKIO.js";
20
+ } from "./chunk-RJRG2VER.js";
21
21
  import {
22
22
  buildSnapshotFromSessionState
23
- } from "./chunk-BBC46FN4.js";
23
+ } from "./chunk-TS5XFQ2D.js";
24
24
  import {
25
25
  logger
26
26
  } from "./chunk-K44MW7JJ.js";
@@ -327,4 +327,4 @@ export {
327
327
  runBuilderTurn,
328
328
  runVerifierTurn
329
329
  };
330
- //# sourceMappingURL=chunk-6SYNGMU4.js.map
330
+ //# sourceMappingURL=chunk-BG7QCFGG.js.map
@@ -155,7 +155,6 @@ ${annotation || "(none)"}`;
155
155
  client.on("error", () => targetSocket.destroy());
156
156
  targetSocket.write(clientHead);
157
157
  targetSocket.pipe(client);
158
- client.pipe(targetSocket);
159
158
  return;
160
159
  }
161
160
  targetSocket = net.connect(targetPort, targetHost);
@@ -294,4 +293,4 @@ export {
294
293
  startInspectProxy,
295
294
  stopAllInspectProxies
296
295
  };
297
- //# sourceMappingURL=chunk-XKIEDGQF.js.map
296
+ //# sourceMappingURL=chunk-DL6ZILAF.js.map
@@ -155,7 +155,7 @@ async function runCli(options) {
155
155
  break;
156
156
  }
157
157
  case "service": {
158
- const { runServiceCommand } = await import("./service-D6LC3CAM.js");
158
+ const { runServiceCommand } = await import("./service-TU4XSXYJ.js");
159
159
  const [, subcommand] = positionals;
160
160
  if (subcommand === "--help" || subcommand === "-h" || values.help) {
161
161
  runServiceCommand(mode, void 0);
@@ -190,7 +190,7 @@ async function runCli(options) {
190
190
  if (!configExists) {
191
191
  await runNetworkSetup(mode);
192
192
  }
193
- const { runServe } = await import("./serve-FTTLGRAO.js");
193
+ const { runServe } = await import("./serve-55GF3KJW.js");
194
194
  const serveOptions = { mode };
195
195
  if (values.port) serveOptions.port = parseInt(values.port);
196
196
  if (values["no-browser"] === true) serveOptions.openBrowser = false;
@@ -202,4 +202,4 @@ async function runCli(options) {
202
202
  export {
203
203
  runCli
204
204
  };
205
- //# sourceMappingURL=chunk-OJBFC6ER.js.map
205
+ //# sourceMappingURL=chunk-HOD7GVQ5.js.map
@@ -9,7 +9,7 @@ import {
9
9
  foldSessionState,
10
10
  spreadOptionalMessageFields,
11
11
  stripPromptContextMessages
12
- } from "./chunk-BBC46FN4.js";
12
+ } from "./chunk-TS5XFQ2D.js";
13
13
  import {
14
14
  getRuntimeConfig
15
15
  } from "./chunk-B5AP3RSV.js";
@@ -316,6 +316,19 @@ var EventStore = class {
316
316
  const result = this.db.prepare(`DELETE FROM events WHERE session_id = ? AND seq <= ?`).run(sessionId, upToSeq);
317
317
  return result.changes;
318
318
  }
319
+ /**
320
+ * Delete all events after a given sequence number (exclusive).
321
+ * Retains session.initialized (seq 1) and any events at/below fromSeq.
322
+ * Used when truncating session history.
323
+ *
324
+ * @param sessionId - The session ID
325
+ * @param fromSeq - Events with seq > fromSeq will be deleted
326
+ * @returns The number of events deleted
327
+ */
328
+ deleteEventsAfterSeq(sessionId, fromSeq) {
329
+ const result = this.db.prepare(`DELETE FROM events WHERE session_id = ? AND seq > ?`).run(sessionId, fromSeq);
330
+ return result.changes;
331
+ }
319
332
  /**
320
333
  * Clean up old events, keeping only:
321
334
  * - session.initialized event (seq 1)
@@ -1089,6 +1102,23 @@ function emitTurnSnapshot(sessionId, snapshot) {
1089
1102
  data: snapshot
1090
1103
  });
1091
1104
  }
1105
+ function truncateSessionMessages(sessionId, messageIndex) {
1106
+ const eventStore = getEventStore();
1107
+ const snapshotEvent = eventStore.getLatestSnapshot(sessionId);
1108
+ if (!snapshotEvent) return;
1109
+ const snapshot = snapshotEvent.data;
1110
+ const messages = snapshot.messages;
1111
+ const lastKept = messageIndex + 1;
1112
+ if (lastKept < 1 || lastKept >= messages.length) return;
1113
+ snapshot.messages = messages.slice(0, lastKept);
1114
+ eventStore.deleteEventsAfterSeq(sessionId, snapshotEvent.seq);
1115
+ eventStore.append(sessionId, {
1116
+ type: "turn.snapshot",
1117
+ data: snapshot
1118
+ });
1119
+ const removed = messages.length - messageIndex;
1120
+ updateSessionMessageCount(sessionId, -removed);
1121
+ }
1092
1122
  function compactContext(sessionId, summary, beforeTokens) {
1093
1123
  const state = getSessionState(sessionId);
1094
1124
  if (!state) {
@@ -1218,7 +1248,8 @@ export {
1218
1248
  emitChatError,
1219
1249
  emitFormatRetry,
1220
1250
  emitTurnSnapshot,
1251
+ truncateSessionMessages,
1221
1252
  compactContext,
1222
1253
  getRecentUserPromptsForSession
1223
1254
  };
1224
- //# sourceMappingURL=chunk-UVN6AKIO.js.map
1255
+ //# sourceMappingURL=chunk-RJRG2VER.js.map
@@ -38,6 +38,9 @@ function updateMessageDone(msg, data) {
38
38
  if (data.partial) msg.partial = true;
39
39
  if (data.promptContext) msg.promptContext = data.promptContext;
40
40
  if (data.tokenCount !== void 0) msg.tokenCount = data.tokenCount;
41
+ if ("preparingToolCalls" in msg) {
42
+ msg.preparingToolCalls = [];
43
+ }
41
44
  }
42
45
  function applyEvents(initialMessages, events, options) {
43
46
  const messages = new Map(initialMessages.map((message) => [message.id, deepCloneMessage(message)]));
@@ -247,7 +250,7 @@ function cloneMessage(message) {
247
250
  }))
248
251
  } : {},
249
252
  ...message.segments ? { segments: [...message.segments] } : {},
250
- ...message.preparingToolCalls ? { preparingToolCalls: [...message.preparingToolCalls] } : {}
253
+ ...message.preparingToolCalls && message.preparingToolCalls.length > 0 ? { preparingToolCalls: [...message.preparingToolCalls] } : {}
251
254
  };
252
255
  }
253
256
  function spreadOptionalMessageFields(message) {
@@ -267,6 +270,7 @@ function spreadOptionalMessageFields(message) {
267
270
  ...message.isCompactionSummary !== void 0 && { isCompactionSummary: message.isCompactionSummary },
268
271
  ...message.promptContext !== void 0 && { promptContext: message.promptContext },
269
272
  ...message.attachments !== void 0 && { attachments: message.attachments },
273
+ ...message.preparingToolCalls !== void 0 && message.preparingToolCalls.length > 0 && { preparingToolCalls: message.preparingToolCalls },
270
274
  ...message.metadata !== void 0 && { metadata: message.metadata }
271
275
  };
272
276
  }
@@ -292,11 +296,14 @@ function appendSnapshotMessageContext(result, message) {
292
296
  contextMsg.thinkingContent = message.thinkingContent;
293
297
  }
294
298
  if (message.toolCalls && message.toolCalls.length > 0) {
295
- contextMsg.toolCalls = message.toolCalls.map((toolCall) => ({
296
- id: toolCall.id,
297
- name: toolCall.name,
298
- arguments: toolCall.arguments
299
- }));
299
+ const fulfilledToolCalls = message.toolCalls.filter((tc) => tc.result);
300
+ if (fulfilledToolCalls.length > 0) {
301
+ contextMsg.toolCalls = fulfilledToolCalls.map((toolCall) => ({
302
+ id: toolCall.id,
303
+ name: toolCall.name,
304
+ arguments: toolCall.arguments
305
+ }));
306
+ }
300
307
  }
301
308
  if (message.attachments !== void 0) {
302
309
  contextMsg.attachments = message.attachments;
@@ -346,6 +353,7 @@ function buildContextMessagesFromStoredEvents(events, windowId, options) {
346
353
  const includeVerifier = options?.includeVerifier ?? true;
347
354
  const messages = [];
348
355
  const messageMap = /* @__PURE__ */ new Map();
356
+ const fulfilledToolCallIds = /* @__PURE__ */ new Set();
349
357
  for (const event of events) {
350
358
  switch (event.type) {
351
359
  case "message.start": {
@@ -363,62 +371,89 @@ function buildContextMessagesFromStoredEvents(events, windowId, options) {
363
371
  break;
364
372
  }
365
373
  case "message.thinking": {
366
- const data = event.data;
367
- const msg = messageMap.get(data.messageId);
368
- if (msg) {
369
- msg.thinkingContent = (msg.thinkingContent ?? "") + data.content;
370
- }
374
+ handleMessageThinking(messageMap, event.data);
371
375
  break;
372
376
  }
373
377
  case "message.delta": {
374
- const data = event.data;
375
- const msg = messageMap.get(data.messageId);
376
- if (msg) {
377
- msg.content += data.content;
378
- }
378
+ handleMessageDelta(messageMap, event.data);
379
379
  break;
380
380
  }
381
381
  case "tool.call": {
382
- const data = event.data;
383
- const msg = messageMap.get(data.messageId);
384
- if (msg) {
385
- if (!msg.toolCalls) msg.toolCalls = [];
386
- msg.toolCalls.push(data.toolCall);
387
- }
382
+ handleToolCall(messageMap, event.data);
388
383
  break;
389
384
  }
390
385
  case "tool.result": {
391
- const data = event.data;
392
- if (messageMap.has(data.messageId)) {
393
- const imageMeta = data.result.metadata;
394
- const msg = {
395
- id: `tool-${data.toolCallId}`,
396
- role: "tool",
397
- content: stripAnsi(
398
- data.result.success ? data.result.output ?? "Success" : data.result.output ? `${data.result.output}
386
+ handleToolResult(
387
+ messages,
388
+ messageMap,
389
+ fulfilledToolCallIds,
390
+ event.data
391
+ );
392
+ break;
393
+ }
394
+ }
395
+ }
396
+ stripOrphanedToolCalls(messages, fulfilledToolCallIds);
397
+ return messages.map(({ id: _id, ...message }) => message);
398
+ }
399
+ function handleMessageThinking(messageMap, data) {
400
+ const msg = messageMap.get(data.messageId);
401
+ if (msg) {
402
+ msg.thinkingContent = (msg.thinkingContent ?? "") + data.content;
403
+ }
404
+ }
405
+ function handleMessageDelta(messageMap, data) {
406
+ const msg = messageMap.get(data.messageId);
407
+ if (msg) {
408
+ msg.content += data.content;
409
+ }
410
+ }
411
+ function handleToolCall(messageMap, data) {
412
+ const msg = messageMap.get(data.messageId);
413
+ if (msg) {
414
+ if (!msg.toolCalls) msg.toolCalls = [];
415
+ msg.toolCalls.push(data.toolCall);
416
+ }
417
+ }
418
+ function handleToolResult(messages, messageMap, fulfilled, data) {
419
+ fulfilled.add(data.toolCallId);
420
+ if (messageMap.has(data.messageId)) {
421
+ const imageMeta = data.result.metadata;
422
+ const toolMsg = {
423
+ id: `tool-${data.toolCallId}`,
424
+ role: "tool",
425
+ content: stripAnsi(
426
+ data.result.success ? data.result.output ?? "Success" : data.result.output ? `${data.result.output}
399
427
 
400
428
  Error: ${data.result.error}` : `Error: ${data.result.error}`
401
- ),
402
- toolCallId: data.toolCallId
403
- };
404
- if (imageMeta?.dataUrl && imageMeta?.mimeType?.startsWith("image/")) {
405
- msg.attachments = [
406
- {
407
- id: crypto.randomUUID(),
408
- filename: imageMeta.path ?? "image",
409
- mimeType: imageMeta.mimeType,
410
- size: imageMeta.size ?? 0,
411
- data: imageMeta.dataUrl
412
- }
413
- ];
414
- }
415
- messages.push(msg);
429
+ ),
430
+ toolCallId: data.toolCallId
431
+ };
432
+ if (imageMeta?.dataUrl && imageMeta?.mimeType?.startsWith("image/")) {
433
+ toolMsg.attachments = [
434
+ {
435
+ id: crypto.randomUUID(),
436
+ filename: imageMeta.path ?? "image",
437
+ mimeType: imageMeta.mimeType,
438
+ size: imageMeta.size ?? 0,
439
+ data: imageMeta.dataUrl
416
440
  }
417
- break;
441
+ ];
442
+ }
443
+ messages.push(toolMsg);
444
+ }
445
+ }
446
+ function stripOrphanedToolCalls(messages, fulfilledToolCallIds) {
447
+ for (const msg of messages) {
448
+ if (msg.role === "assistant" && msg.toolCalls) {
449
+ const fulfilled = msg.toolCalls.filter((tc) => fulfilledToolCallIds.has(tc.id));
450
+ if (fulfilled.length === 0) {
451
+ delete msg.toolCalls;
452
+ } else {
453
+ msg.toolCalls = fulfilled;
418
454
  }
419
455
  }
420
456
  }
421
- return messages.map(({ id: _id, ...message }) => message);
422
457
  }
423
458
  function buildContextMessagesFromEventHistory(events, windowId, options) {
424
459
  const snapshotEvent = [...events].reverse().find((event) => event.type === "turn.snapshot");
@@ -824,6 +859,11 @@ export {
824
859
  spreadOptionalMessageFields,
825
860
  buildMessagesFromStoredEvents,
826
861
  buildContextMessagesFromStoredEvents,
862
+ handleMessageThinking,
863
+ handleMessageDelta,
864
+ handleToolCall,
865
+ handleToolResult,
866
+ stripOrphanedToolCalls,
827
867
  buildContextMessagesFromEventHistory,
828
868
  foldTurnEventsToSnapshotMessages,
829
869
  foldTurnEventsToSnapshotMessagesFromInitial,
@@ -840,4 +880,4 @@ export {
840
880
  getMessagesForWindow,
841
881
  buildContextMessagesFromMessages
842
882
  };
843
- //# sourceMappingURL=chunk-BBC46FN4.js.map
883
+ //# sourceMappingURL=chunk-TS5XFQ2D.js.map