@mindstudio-ai/remy 0.1.65 → 0.1.66
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/headless.js +32 -1
- package/dist/index.js +32 -1
- package/package.json +1 -1
package/dist/headless.js
CHANGED
|
@@ -2501,6 +2501,37 @@ function findLastSummaryCheckpoint(messages, name) {
|
|
|
2501
2501
|
}
|
|
2502
2502
|
return -1;
|
|
2503
2503
|
}
|
|
2504
|
+
function fixOrphanedToolCalls(messages) {
|
|
2505
|
+
const toolResultIds = /* @__PURE__ */ new Set();
|
|
2506
|
+
for (const msg of messages) {
|
|
2507
|
+
if (msg.role === "user" && msg.toolCallId) {
|
|
2508
|
+
toolResultIds.add(msg.toolCallId);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
const result = [...messages];
|
|
2512
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
2513
|
+
const msg = result[i];
|
|
2514
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
2515
|
+
continue;
|
|
2516
|
+
}
|
|
2517
|
+
const toolBlocks = msg.content.filter(
|
|
2518
|
+
(b) => b.type === "tool"
|
|
2519
|
+
);
|
|
2520
|
+
const orphans = toolBlocks.filter((tc) => !toolResultIds.has(tc.id));
|
|
2521
|
+
if (orphans.length === 0) {
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
const synthetics = orphans.map((tc) => ({
|
|
2525
|
+
role: "user",
|
|
2526
|
+
content: "Error: tool result lost (session recovered)",
|
|
2527
|
+
toolCallId: tc.id,
|
|
2528
|
+
isToolError: true
|
|
2529
|
+
}));
|
|
2530
|
+
result.splice(i + 1, 0, ...synthetics);
|
|
2531
|
+
break;
|
|
2532
|
+
}
|
|
2533
|
+
return result;
|
|
2534
|
+
}
|
|
2504
2535
|
function cleanMessagesForApi(messages) {
|
|
2505
2536
|
const checkpointIdx = findLastSummaryCheckpoint(messages, "conversation");
|
|
2506
2537
|
let startIdx = 0;
|
|
@@ -2522,7 +2553,7 @@ ${summaryBlock.text}
|
|
|
2522
2553
|
}
|
|
2523
2554
|
startIdx = checkpointIdx + 1;
|
|
2524
2555
|
}
|
|
2525
|
-
const messagesToProcess = messages.slice(startIdx);
|
|
2556
|
+
const messagesToProcess = fixOrphanedToolCalls(messages.slice(startIdx));
|
|
2526
2557
|
const toolUseIds = /* @__PURE__ */ new Set();
|
|
2527
2558
|
for (const msg of messagesToProcess) {
|
|
2528
2559
|
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
package/dist/index.js
CHANGED
|
@@ -2228,6 +2228,37 @@ function findLastSummaryCheckpoint(messages, name) {
|
|
|
2228
2228
|
}
|
|
2229
2229
|
return -1;
|
|
2230
2230
|
}
|
|
2231
|
+
function fixOrphanedToolCalls(messages) {
|
|
2232
|
+
const toolResultIds = /* @__PURE__ */ new Set();
|
|
2233
|
+
for (const msg of messages) {
|
|
2234
|
+
if (msg.role === "user" && msg.toolCallId) {
|
|
2235
|
+
toolResultIds.add(msg.toolCallId);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
const result = [...messages];
|
|
2239
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
2240
|
+
const msg = result[i];
|
|
2241
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
const toolBlocks = msg.content.filter(
|
|
2245
|
+
(b) => b.type === "tool"
|
|
2246
|
+
);
|
|
2247
|
+
const orphans = toolBlocks.filter((tc) => !toolResultIds.has(tc.id));
|
|
2248
|
+
if (orphans.length === 0) {
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
const synthetics = orphans.map((tc) => ({
|
|
2252
|
+
role: "user",
|
|
2253
|
+
content: "Error: tool result lost (session recovered)",
|
|
2254
|
+
toolCallId: tc.id,
|
|
2255
|
+
isToolError: true
|
|
2256
|
+
}));
|
|
2257
|
+
result.splice(i + 1, 0, ...synthetics);
|
|
2258
|
+
break;
|
|
2259
|
+
}
|
|
2260
|
+
return result;
|
|
2261
|
+
}
|
|
2231
2262
|
function cleanMessagesForApi(messages) {
|
|
2232
2263
|
const checkpointIdx = findLastSummaryCheckpoint(messages, "conversation");
|
|
2233
2264
|
let startIdx = 0;
|
|
@@ -2249,7 +2280,7 @@ ${summaryBlock.text}
|
|
|
2249
2280
|
}
|
|
2250
2281
|
startIdx = checkpointIdx + 1;
|
|
2251
2282
|
}
|
|
2252
|
-
const messagesToProcess = messages.slice(startIdx);
|
|
2283
|
+
const messagesToProcess = fixOrphanedToolCalls(messages.slice(startIdx));
|
|
2253
2284
|
const toolUseIds = /* @__PURE__ */ new Set();
|
|
2254
2285
|
for (const msg of messagesToProcess) {
|
|
2255
2286
|
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|