deepccc 0.2.9 → 0.2.11
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/context.js +28 -26
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -392,34 +392,35 @@ function replayStructuredAssistantMessage(message, messageIndex) {
|
|
|
392
392
|
];
|
|
393
393
|
const messages = [];
|
|
394
394
|
let assistantParts = [];
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
const knownNames = new Map();
|
|
395
|
+
const batchCalls = new Map();
|
|
396
|
+
const batchResults = new Map();
|
|
398
397
|
const emittedCallIds = new Set();
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
398
|
+
const completeToolBatch = () => {
|
|
399
|
+
if (assistantParts.length > 0) {
|
|
400
|
+
messages.push({ role: "assistant", content: assistantParts });
|
|
401
|
+
assistantParts = [];
|
|
402
|
+
}
|
|
403
|
+
if (batchCalls.size === 0) {
|
|
404
|
+
batchResults.clear();
|
|
401
405
|
return;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
for (const [toolCallId, toolName] of pendingCalls) {
|
|
407
|
-
toolParts.push({
|
|
406
|
+
}
|
|
407
|
+
const toolParts = [];
|
|
408
|
+
for (const [toolCallId, toolName] of batchCalls) {
|
|
409
|
+
toolParts.push(batchResults.get(toolCallId) ?? {
|
|
408
410
|
type: "tool-result",
|
|
409
411
|
toolCallId,
|
|
410
412
|
toolName,
|
|
411
413
|
output: { type: "text", value: "[tool execution interrupted; result unavailable]" },
|
|
412
414
|
});
|
|
413
415
|
}
|
|
414
|
-
pendingCalls.clear();
|
|
415
|
-
if (!toolParts.length)
|
|
416
|
-
return;
|
|
417
416
|
messages.push({ role: "tool", content: toolParts });
|
|
418
|
-
|
|
417
|
+
batchCalls.clear();
|
|
418
|
+
batchResults.clear();
|
|
419
419
|
};
|
|
420
420
|
for (const entry of timeline) {
|
|
421
421
|
if (entry.type === "text") {
|
|
422
|
-
|
|
422
|
+
if (batchCalls.size > 0 || batchResults.size > 0)
|
|
423
|
+
completeToolBatch();
|
|
423
424
|
const previous = assistantParts[assistantParts.length - 1];
|
|
424
425
|
if (previous?.type === "text")
|
|
425
426
|
previous.text += entry.text;
|
|
@@ -427,9 +428,13 @@ function replayStructuredAssistantMessage(message, messageIndex) {
|
|
|
427
428
|
assistantParts.push({ type: "text", text: entry.text });
|
|
428
429
|
}
|
|
429
430
|
else if (entry.type === "tool_use") {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
431
|
+
// Providers may interleave parallel tool results with later tool-call
|
|
432
|
+
// events from the same assistant step. Keep the whole contiguous tool
|
|
433
|
+
// segment together until text resumes; closing on the first result can
|
|
434
|
+
// emit a later real result as an orphaned `role: tool` message.
|
|
435
|
+
if (emittedCallIds.has(entry.id))
|
|
436
|
+
continue;
|
|
437
|
+
batchCalls.set(entry.id, entry.name);
|
|
433
438
|
emittedCallIds.add(entry.id);
|
|
434
439
|
assistantParts.push({
|
|
435
440
|
type: "tool-call",
|
|
@@ -439,14 +444,12 @@ function replayStructuredAssistantMessage(message, messageIndex) {
|
|
|
439
444
|
});
|
|
440
445
|
}
|
|
441
446
|
else {
|
|
442
|
-
if (!
|
|
447
|
+
if (!batchCalls.has(entry.tool_use_id))
|
|
443
448
|
continue;
|
|
444
|
-
const toolName = entry.name ??
|
|
449
|
+
const toolName = entry.name ?? batchCalls.get(entry.tool_use_id);
|
|
445
450
|
if (!toolName)
|
|
446
451
|
continue;
|
|
447
|
-
|
|
448
|
-
pendingCalls.delete(entry.tool_use_id);
|
|
449
|
-
toolParts.push({
|
|
452
|
+
batchResults.set(entry.tool_use_id, {
|
|
450
453
|
type: "tool-result",
|
|
451
454
|
toolCallId: entry.tool_use_id,
|
|
452
455
|
toolName,
|
|
@@ -454,8 +457,7 @@ function replayStructuredAssistantMessage(message, messageIndex) {
|
|
|
454
457
|
});
|
|
455
458
|
}
|
|
456
459
|
}
|
|
457
|
-
|
|
458
|
-
flushTools();
|
|
460
|
+
completeToolBatch();
|
|
459
461
|
return messages;
|
|
460
462
|
}
|
|
461
463
|
function serializeMessagesForCompaction(messages) {
|