acp-kernel 0.0.94-pr.438.290 → 0.0.94
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/DESIGN.md +137 -158
- package/PROVENANCE.md +40 -44
- package/README.md +30 -43
- package/dist/cache-report.d.ts.map +1 -1
- package/dist/{chunk-WR7OPWNT.js → chunk-NUQZKPQS.js} +3 -7
- package/dist/chunk-NUQZKPQS.js.map +1 -0
- package/dist/compress-tools.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/decompress.d.ts.map +1 -1
- package/dist/filter/apply.d.ts.map +1 -1
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/handoff.d.ts.map +1 -1
- package/dist/hide-consumed.d.ts.map +1 -1
- package/dist/image-compress.d.ts.map +1 -1
- package/dist/index.js +75 -254
- package/dist/index.js.map +1 -1
- package/dist/message-kind.d.ts.map +1 -1
- package/dist/nudge-text.d.ts.map +1 -1
- package/dist/packs.d.ts.map +1 -1
- package/dist/panel/cache.d.ts.map +1 -1
- package/dist/panel/index.js +10 -29
- package/dist/panel/index.js.map +1 -1
- package/dist/panel/panel.d.ts.map +1 -1
- package/dist/panel/topic.d.ts.map +1 -1
- package/dist/parse-compress-input.d.ts.map +1 -1
- package/dist/persist/index.d.ts +1 -1
- package/dist/persist/index.d.ts.map +1 -1
- package/dist/persist/index.js +12 -49
- package/dist/persist/index.js.map +1 -1
- package/dist/persist/state-merge.d.ts.map +1 -1
- package/dist/persist/store.d.ts.map +1 -1
- package/dist/protected.d.ts.map +1 -1
- package/dist/rebuild.d.ts.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/render-refs.d.ts.map +1 -1
- package/dist/report.d.ts.map +1 -1
- package/dist/search/algorithms/bm25.d.ts.map +1 -1
- package/dist/search/algorithms/fuzzy.d.ts.map +1 -1
- package/dist/search/algorithms/hybrid.d.ts.map +1 -1
- package/dist/search/algorithms/semantic.d.ts.map +1 -1
- package/dist/search/algorithms/substring.d.ts.map +1 -1
- package/dist/search/doc-cache.d.ts.map +1 -1
- package/dist/search/index.d.ts +1 -1
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/registry.d.ts.map +1 -1
- package/dist/search/stemmer.d.ts.map +1 -1
- package/dist/search/tokenizer.d.ts.map +1 -1
- package/dist/search/types.d.ts.map +1 -1
- package/dist/search.d.ts +3 -3
- package/dist/search.d.ts.map +1 -1
- package/dist/surface-config.d.ts.map +1 -1
- package/dist/tool-pairs.d.ts.map +1 -1
- package/dist/truncate-tools.d.ts.map +1 -1
- package/dist/truncate.d.ts.map +1 -1
- package/dist/turn-integrity.d.ts.map +1 -1
- package/dist/wire/anthropic.d.ts.map +1 -1
- package/dist/wire/bili-message.d.ts.map +1 -1
- package/dist/wire/compress-detect.d.ts.map +1 -1
- package/dist/wire/demoted-thinking.d.ts.map +1 -1
- package/dist/wire/formats.d.ts.map +1 -1
- package/dist/wire/index.js +97 -403
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/message-id.d.ts.map +1 -1
- package/dist/wire/mirror.d.ts.map +1 -1
- package/dist/wire/openai.d.ts.map +1 -1
- package/dist/wire/responses.d.ts.map +1 -1
- package/dist/wire/strip-images.d.ts.map +1 -1
- package/dist/wire/util.d.ts.map +1 -1
- package/package.json +66 -66
- package/dist/chunk-WR7OPWNT.js.map +0 -1
package/dist/wire/index.js
CHANGED
|
@@ -27,13 +27,7 @@ function extractSystem(system) {
|
|
|
27
27
|
function buildSystem(text, original) {
|
|
28
28
|
if (Array.isArray(original) && original.length > 0) {
|
|
29
29
|
const ccBlock = original.find((b) => b.cache_control);
|
|
30
|
-
return [
|
|
31
|
-
{
|
|
32
|
-
type: "text",
|
|
33
|
-
text,
|
|
34
|
-
...ccBlock ? { cache_control: ccBlock.cache_control } : {}
|
|
35
|
-
}
|
|
36
|
-
];
|
|
30
|
+
return [{ type: "text", text, ...ccBlock ? { cache_control: ccBlock.cache_control } : {} }];
|
|
37
31
|
}
|
|
38
32
|
return text;
|
|
39
33
|
}
|
|
@@ -54,15 +48,10 @@ function anthropicToCore(body) {
|
|
|
54
48
|
break;
|
|
55
49
|
}
|
|
56
50
|
case "tool_use": {
|
|
57
|
-
const base = deriveMessageId(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
toolCallId: b.id,
|
|
63
|
-
toolName: b.name
|
|
64
|
-
}
|
|
65
|
-
);
|
|
51
|
+
const base = deriveMessageId("assistant", "tool-call", safeStringify(b.input), {
|
|
52
|
+
toolCallId: b.id,
|
|
53
|
+
toolName: b.name
|
|
54
|
+
});
|
|
66
55
|
const id = clusters.next(base);
|
|
67
56
|
msgs.push({
|
|
68
57
|
id,
|
|
@@ -79,9 +68,7 @@ function anthropicToCore(body) {
|
|
|
79
68
|
case "tool_result": {
|
|
80
69
|
const hasNonText = Array.isArray(b.content) && b.content.some((c) => c.type !== "text");
|
|
81
70
|
const text = typeof b.content === "string" ? b.content : b.content.map((c) => c.type === "text" ? c.text : "").join("\n");
|
|
82
|
-
const base = deriveMessageId("tool", "tool-result", text, {
|
|
83
|
-
toolCallId: b.tool_use_id
|
|
84
|
-
});
|
|
71
|
+
const base = deriveMessageId("tool", "tool-result", text, { toolCallId: b.tool_use_id });
|
|
85
72
|
const id = clusters.next(base);
|
|
86
73
|
const name = toolNames.get(b.tool_use_id);
|
|
87
74
|
msgs.push({
|
|
@@ -263,13 +250,7 @@ function openaiToCore(body) {
|
|
|
263
250
|
break;
|
|
264
251
|
}
|
|
265
252
|
const base = deriveMessageId(m.role, "text", stringContent(m.content));
|
|
266
|
-
msgs.push({
|
|
267
|
-
id: clusters.next(base),
|
|
268
|
-
role: "system",
|
|
269
|
-
contentType: "text",
|
|
270
|
-
text: stringContent(m.content),
|
|
271
|
-
originalRole: m.role
|
|
272
|
-
});
|
|
253
|
+
msgs.push({ id: clusters.next(base), role: "system", contentType: "text", text: stringContent(m.content), originalRole: m.role });
|
|
273
254
|
break;
|
|
274
255
|
}
|
|
275
256
|
case "user": {
|
|
@@ -295,10 +276,7 @@ function openaiToCore(body) {
|
|
|
295
276
|
rawOpenaiContent: imgs[0],
|
|
296
277
|
// data: URLs only — remote URLs ride rawOpenaiContent
|
|
297
278
|
// verbatim (#187/#291)
|
|
298
|
-
...firstParsed ? {
|
|
299
|
-
imageMediaType: firstParsed.mediaType,
|
|
300
|
-
imageBase64: firstParsed.base64
|
|
301
|
-
} : {}
|
|
279
|
+
...firstParsed ? { imageMediaType: firstParsed.mediaType, imageBase64: firstParsed.base64 } : {}
|
|
302
280
|
} : nonText.length > 0 ? { rawOpenaiContentParts: nonText } : {}
|
|
303
281
|
});
|
|
304
282
|
break;
|
|
@@ -329,25 +307,14 @@ function openaiToCore(body) {
|
|
|
329
307
|
}
|
|
330
308
|
if (text) {
|
|
331
309
|
const base = deriveMessageId("assistant", "text", text);
|
|
332
|
-
msgs.push({
|
|
333
|
-
id: clusters.next(base),
|
|
334
|
-
role: "assistant",
|
|
335
|
-
contentType: "text",
|
|
336
|
-
text,
|
|
337
|
-
...blankEcho ? { reasoningPresent: true } : {}
|
|
338
|
-
});
|
|
310
|
+
msgs.push({ id: clusters.next(base), role: "assistant", contentType: "text", text, ...blankEcho ? { reasoningPresent: true } : {} });
|
|
339
311
|
}
|
|
340
312
|
if (Array.isArray(m.tool_calls)) {
|
|
341
313
|
for (const tc of m.tool_calls) {
|
|
342
|
-
const base = deriveMessageId(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
{
|
|
347
|
-
toolCallId: tc.id,
|
|
348
|
-
toolName: tc.function.name
|
|
349
|
-
}
|
|
350
|
-
);
|
|
314
|
+
const base = deriveMessageId("assistant", "tool-call", tc.function.arguments ?? "", {
|
|
315
|
+
toolCallId: tc.id,
|
|
316
|
+
toolName: tc.function.name
|
|
317
|
+
});
|
|
351
318
|
msgs.push({
|
|
352
319
|
id: clusters.next(base),
|
|
353
320
|
role: "assistant",
|
|
@@ -363,14 +330,9 @@ function openaiToCore(body) {
|
|
|
363
330
|
break;
|
|
364
331
|
}
|
|
365
332
|
case "tool": {
|
|
366
|
-
const base = deriveMessageId(
|
|
367
|
-
"
|
|
368
|
-
|
|
369
|
-
stringContent(m.content),
|
|
370
|
-
{
|
|
371
|
-
toolCallId: m.tool_call_id ?? ""
|
|
372
|
-
}
|
|
373
|
-
);
|
|
333
|
+
const base = deriveMessageId("tool", "tool-result", stringContent(m.content), {
|
|
334
|
+
toolCallId: m.tool_call_id ?? ""
|
|
335
|
+
});
|
|
374
336
|
const name = m.name || toolNames.get(m.tool_call_id ?? "");
|
|
375
337
|
msgs.push({
|
|
376
338
|
id: clusters.next(base),
|
|
@@ -403,23 +365,13 @@ function coreToOpenai(messages) {
|
|
|
403
365
|
} else if (pending.text !== null) {
|
|
404
366
|
out.push({ role: "assistant", content: pending.text, ...reasoningField });
|
|
405
367
|
} else if (reasoning) {
|
|
406
|
-
out.push({
|
|
407
|
-
role: "assistant",
|
|
408
|
-
content: null,
|
|
409
|
-
reasoning_content: reasoning
|
|
410
|
-
});
|
|
368
|
+
out.push({ role: "assistant", content: null, reasoning_content: reasoning });
|
|
411
369
|
}
|
|
412
370
|
pending = null;
|
|
413
371
|
};
|
|
414
372
|
for (const m of messages) {
|
|
415
373
|
if (m.role === "assistant") {
|
|
416
|
-
if (!pending)
|
|
417
|
-
pending = {
|
|
418
|
-
text: null,
|
|
419
|
-
toolCalls: [],
|
|
420
|
-
reasoning: null,
|
|
421
|
-
reasoningPresent: false
|
|
422
|
-
};
|
|
374
|
+
if (!pending) pending = { text: null, toolCalls: [], reasoning: null, reasoningPresent: false };
|
|
423
375
|
if (m.reasoningPresent) pending.reasoningPresent = true;
|
|
424
376
|
if (m.contentType === "reasoning") {
|
|
425
377
|
pending.reasoning = (pending.reasoning ?? "") + (m.reasoningContent ?? m.text ?? "");
|
|
@@ -435,37 +387,24 @@ function coreToOpenai(messages) {
|
|
|
435
387
|
} else {
|
|
436
388
|
flush();
|
|
437
389
|
if (m.role === "system") {
|
|
438
|
-
out.push({
|
|
439
|
-
role: m.originalRole === "developer" ? "developer" : "system",
|
|
440
|
-
content: m.text ?? ""
|
|
441
|
-
});
|
|
390
|
+
out.push({ role: m.originalRole === "developer" ? "developer" : "system", content: m.text ?? "" });
|
|
442
391
|
} else if (m.role === "user") {
|
|
443
392
|
if (m.rawOpenaiContent || m.imageBase64 || m.rawOpenaiContentParts) {
|
|
444
393
|
const parts = [];
|
|
445
394
|
if (m.text) parts.push({ type: "text", text: m.text });
|
|
446
395
|
if (m.rawOpenaiContentParts && m.rawOpenaiContentParts.length > 0) {
|
|
447
|
-
for (const part of m.rawOpenaiContentParts)
|
|
448
|
-
parts.push(part);
|
|
396
|
+
for (const part of m.rawOpenaiContentParts) parts.push(part);
|
|
449
397
|
} else if (m.rawOpenaiContent) {
|
|
450
398
|
parts.push(m.rawOpenaiContent);
|
|
451
399
|
} else if (m.imageBase64 && m.imageMediaType) {
|
|
452
|
-
parts.push({
|
|
453
|
-
type: "image_url",
|
|
454
|
-
image_url: {
|
|
455
|
-
url: `data:${m.imageMediaType};base64,${m.imageBase64}`
|
|
456
|
-
}
|
|
457
|
-
});
|
|
400
|
+
parts.push({ type: "image_url", image_url: { url: `data:${m.imageMediaType};base64,${m.imageBase64}` } });
|
|
458
401
|
}
|
|
459
402
|
out.push({ role: "user", content: parts });
|
|
460
403
|
} else {
|
|
461
404
|
out.push({ role: "user", content: m.text ?? "" });
|
|
462
405
|
}
|
|
463
406
|
} else if (m.role === "tool") {
|
|
464
|
-
out.push({
|
|
465
|
-
role: "tool",
|
|
466
|
-
tool_call_id: m.toolCallId ?? "",
|
|
467
|
-
content: m.text ?? ""
|
|
468
|
-
});
|
|
407
|
+
out.push({ role: "tool", tool_call_id: m.toolCallId ?? "", content: m.text ?? "" });
|
|
469
408
|
}
|
|
470
409
|
}
|
|
471
410
|
}
|
|
@@ -498,9 +437,7 @@ function stringContent(content) {
|
|
|
498
437
|
if (content == null) return "";
|
|
499
438
|
if (typeof content === "string") return content;
|
|
500
439
|
if (Array.isArray(content)) {
|
|
501
|
-
return content.map(
|
|
502
|
-
(p) => typeof p === "string" ? p : p.type === "text" ? p.text ?? "" : ""
|
|
503
|
-
).join("\n");
|
|
440
|
+
return content.map((p) => typeof p === "string" ? p : p.type === "text" ? p.text ?? "" : "").join("\n");
|
|
504
441
|
}
|
|
505
442
|
return "";
|
|
506
443
|
}
|
|
@@ -509,8 +446,7 @@ function allImageParts(content) {
|
|
|
509
446
|
const out = [];
|
|
510
447
|
for (const p of content) {
|
|
511
448
|
if (typeof p !== "object" || p === null) continue;
|
|
512
|
-
if (!("type" in p) || p.type !== "image_url" || !("image_url" in p))
|
|
513
|
-
continue;
|
|
449
|
+
if (!("type" in p) || p.type !== "image_url" || !("image_url" in p)) continue;
|
|
514
450
|
const imagePart = p;
|
|
515
451
|
const url = imagePart.image_url?.url;
|
|
516
452
|
if (typeof url === "string") out.push(p);
|
|
@@ -529,7 +465,10 @@ function allNonTextParts(content) {
|
|
|
529
465
|
}
|
|
530
466
|
|
|
531
467
|
// src/wire/responses.ts
|
|
532
|
-
var OPAQUE_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
468
|
+
var OPAQUE_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
469
|
+
"additional_tools",
|
|
470
|
+
"mcp_list_tools"
|
|
471
|
+
]);
|
|
533
472
|
function isOpaqueItem(item) {
|
|
534
473
|
return OPAQUE_ITEM_TYPES.has(item.type);
|
|
535
474
|
}
|
|
@@ -537,10 +476,7 @@ var EASY_INPUT_ROLES = /* @__PURE__ */ new Set(["user", "assistant", "system", "
|
|
|
537
476
|
function normalizeEasyInputItem(item) {
|
|
538
477
|
if (typeof item.type === "string") return item;
|
|
539
478
|
if (EASY_INPUT_ROLES.has(String(item.role))) {
|
|
540
|
-
return {
|
|
541
|
-
...item,
|
|
542
|
-
type: "message"
|
|
543
|
-
};
|
|
479
|
+
return { ...item, type: "message" };
|
|
544
480
|
}
|
|
545
481
|
return item;
|
|
546
482
|
}
|
|
@@ -559,9 +495,7 @@ function messageContent(content) {
|
|
|
559
495
|
function userDisplayText(content, text) {
|
|
560
496
|
if (typeof content === "string") return text;
|
|
561
497
|
const hasImage = content.some((part) => part.type === "input_image");
|
|
562
|
-
const hasTextPart = content.some(
|
|
563
|
-
(part) => part.type === "input_text" || part.type === "output_text"
|
|
564
|
-
);
|
|
498
|
+
const hasTextPart = content.some((part) => part.type === "input_text" || part.type === "output_text");
|
|
565
499
|
return !text || hasImage && !hasTextPart ? "[image]" : text;
|
|
566
500
|
}
|
|
567
501
|
function reasoningText(item) {
|
|
@@ -571,8 +505,7 @@ function reasoningText(item) {
|
|
|
571
505
|
for (const part of parts) {
|
|
572
506
|
if (part && typeof part === "object" && "type" in part && "text" in part) {
|
|
573
507
|
const rec = part;
|
|
574
|
-
if (rec.type === type && typeof rec.text === "string")
|
|
575
|
-
texts.push(rec.text);
|
|
508
|
+
if (rec.type === type && typeof rec.text === "string") texts.push(rec.text);
|
|
576
509
|
}
|
|
577
510
|
}
|
|
578
511
|
return texts.join("\n");
|
|
@@ -591,20 +524,11 @@ function responsesToCore(body) {
|
|
|
591
524
|
const clusters = new ClusterCounter();
|
|
592
525
|
const toolNames = /* @__PURE__ */ new Map();
|
|
593
526
|
let idx = 0;
|
|
594
|
-
if (typeof body.instructions === "string" && body.instructions.trim())
|
|
595
|
-
systemParts.push(body.instructions);
|
|
527
|
+
if (typeof body.instructions === "string" && body.instructions.trim()) systemParts.push(body.instructions);
|
|
596
528
|
if (typeof body.input === "string") {
|
|
597
529
|
const id = clusters.next(deriveMessageId("user", "text", body.input));
|
|
598
530
|
msgs.push({ id, role: "user", contentType: "text", text: body.input });
|
|
599
|
-
return {
|
|
600
|
-
msgs,
|
|
601
|
-
systemParts,
|
|
602
|
-
preamble,
|
|
603
|
-
customToolCallIds,
|
|
604
|
-
layout,
|
|
605
|
-
droppedReasoning,
|
|
606
|
-
stringInput: { original: body.input, coreId: id }
|
|
607
|
-
};
|
|
531
|
+
return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning, stringInput: { original: body.input, coreId: id } };
|
|
608
532
|
}
|
|
609
533
|
for (const raw of body.input) {
|
|
610
534
|
const item = normalizeEasyInputItem(raw);
|
|
@@ -642,9 +566,7 @@ function responsesToCore(body) {
|
|
|
642
566
|
const split = splitDemotedThinking(text);
|
|
643
567
|
if (split) {
|
|
644
568
|
msgs.push({
|
|
645
|
-
id: clusters.next(
|
|
646
|
-
deriveMessageId("assistant", "reasoning", split.reasoning)
|
|
647
|
-
),
|
|
569
|
+
id: clusters.next(deriveMessageId("assistant", "reasoning", split.reasoning)),
|
|
648
570
|
role: "assistant",
|
|
649
571
|
contentType: "reasoning",
|
|
650
572
|
text: split.reasoning,
|
|
@@ -657,9 +579,7 @@ function responsesToCore(body) {
|
|
|
657
579
|
if (effText || role === "user" && hasImage) {
|
|
658
580
|
const displayText = role === "user" ? userDisplayText(message.content, effText) : effText;
|
|
659
581
|
coreId = clusters.next(deriveMessageId(role, "text", displayText));
|
|
660
|
-
const imageUrl = Array.isArray(message.content) ? message.content.find(
|
|
661
|
-
(part) => part.type === "input_image" && typeof part.image_url === "string"
|
|
662
|
-
)?.image_url : void 0;
|
|
582
|
+
const imageUrl = Array.isArray(message.content) ? message.content.find((part) => part.type === "input_image" && typeof part.image_url === "string")?.image_url : void 0;
|
|
663
583
|
const image = typeof imageUrl === "string" ? parseDataUrl(imageUrl) : void 0;
|
|
664
584
|
msgs.push({
|
|
665
585
|
id: coreId,
|
|
@@ -675,12 +595,10 @@ function responsesToCore(body) {
|
|
|
675
595
|
}
|
|
676
596
|
case "function_call": {
|
|
677
597
|
const call = item;
|
|
678
|
-
coreId = clusters.next(
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
})
|
|
683
|
-
);
|
|
598
|
+
coreId = clusters.next(deriveMessageId("assistant", "tool-call", call.arguments ?? "", {
|
|
599
|
+
toolCallId: call.call_id,
|
|
600
|
+
toolName: call.name
|
|
601
|
+
}));
|
|
684
602
|
msgs.push({
|
|
685
603
|
id: coreId,
|
|
686
604
|
role: "assistant",
|
|
@@ -696,21 +614,9 @@ function responsesToCore(body) {
|
|
|
696
614
|
case "function_call_output": {
|
|
697
615
|
const output = item;
|
|
698
616
|
const text = typeof output.output === "string" ? output.output : JSON.stringify(output.output);
|
|
699
|
-
coreId = clusters.next(
|
|
700
|
-
deriveMessageId("tool", "tool-result", text, {
|
|
701
|
-
toolCallId: output.call_id
|
|
702
|
-
})
|
|
703
|
-
);
|
|
617
|
+
coreId = clusters.next(deriveMessageId("tool", "tool-result", text, { toolCallId: output.call_id }));
|
|
704
618
|
const name = toolNames.get(output.call_id);
|
|
705
|
-
msgs.push({
|
|
706
|
-
id: coreId,
|
|
707
|
-
role: "tool",
|
|
708
|
-
contentType: "tool-result",
|
|
709
|
-
toolCallId: output.call_id,
|
|
710
|
-
text,
|
|
711
|
-
...name ? { toolName: name } : {},
|
|
712
|
-
rawResponsesItem: item
|
|
713
|
-
});
|
|
619
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: output.call_id, text, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
714
620
|
break;
|
|
715
621
|
}
|
|
716
622
|
case "computer_call":
|
|
@@ -721,16 +627,8 @@ function responsesToCore(body) {
|
|
|
721
627
|
case "code_interpreter_call":
|
|
722
628
|
case "mcp_call": {
|
|
723
629
|
const rid = typeof item.id === "string" ? String(item.id) : hashId(JSON.stringify(item));
|
|
724
|
-
coreId = clusters.next(
|
|
725
|
-
|
|
726
|
-
);
|
|
727
|
-
msgs.push({
|
|
728
|
-
id: coreId,
|
|
729
|
-
role: "assistant",
|
|
730
|
-
contentType: "reasoning",
|
|
731
|
-
text: rid,
|
|
732
|
-
rawResponsesItem: item
|
|
733
|
-
});
|
|
630
|
+
coreId = clusters.next(deriveMessageId("assistant", "responses-call", rid));
|
|
631
|
+
msgs.push({ id: coreId, role: "assistant", contentType: "reasoning", text: rid, rawResponsesItem: item });
|
|
734
632
|
break;
|
|
735
633
|
}
|
|
736
634
|
case "custom_tool_call": {
|
|
@@ -738,21 +636,8 @@ function responsesToCore(body) {
|
|
|
738
636
|
const callId = ctc.call_id ?? `call_${idx}`;
|
|
739
637
|
customToolCallIds.add(callId);
|
|
740
638
|
const argText = ctc.input ?? ctc.arguments ?? "";
|
|
741
|
-
coreId = clusters.next(
|
|
742
|
-
|
|
743
|
-
toolCallId: callId,
|
|
744
|
-
toolName: ctc.name ?? "custom"
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
msgs.push({
|
|
748
|
-
id: coreId,
|
|
749
|
-
role: "assistant",
|
|
750
|
-
contentType: "tool-call",
|
|
751
|
-
toolName: ctc.name ?? "custom",
|
|
752
|
-
toolCallId: callId,
|
|
753
|
-
text: argText,
|
|
754
|
-
rawResponsesItem: item
|
|
755
|
-
});
|
|
639
|
+
coreId = clusters.next(deriveMessageId("assistant", "tool-call", argText, { toolCallId: callId, toolName: ctc.name ?? "custom" }));
|
|
640
|
+
msgs.push({ id: coreId, role: "assistant", contentType: "tool-call", toolName: ctc.name ?? "custom", toolCallId: callId, text: argText, rawResponsesItem: item });
|
|
756
641
|
toolNames.set(callId, ctc.name ?? "custom");
|
|
757
642
|
break;
|
|
758
643
|
}
|
|
@@ -761,21 +646,9 @@ function responsesToCore(body) {
|
|
|
761
646
|
const callId = ctco.call_id ?? `call_${idx}`;
|
|
762
647
|
customToolCallIds.add(callId);
|
|
763
648
|
const outText = typeof ctco.output === "string" ? ctco.output : JSON.stringify(ctco.output ?? "");
|
|
764
|
-
coreId = clusters.next(
|
|
765
|
-
deriveMessageId("tool", "tool-result", outText, {
|
|
766
|
-
toolCallId: callId
|
|
767
|
-
})
|
|
768
|
-
);
|
|
649
|
+
coreId = clusters.next(deriveMessageId("tool", "tool-result", outText, { toolCallId: callId }));
|
|
769
650
|
const name = toolNames.get(callId);
|
|
770
|
-
msgs.push({
|
|
771
|
-
id: coreId,
|
|
772
|
-
role: "tool",
|
|
773
|
-
contentType: "tool-result",
|
|
774
|
-
toolCallId: callId,
|
|
775
|
-
text: outText,
|
|
776
|
-
...name ? { toolName: name } : {},
|
|
777
|
-
rawResponsesItem: item
|
|
778
|
-
});
|
|
651
|
+
msgs.push({ id: coreId, role: "tool", contentType: "tool-result", toolCallId: callId, text: outText, ...name ? { toolName: name } : {}, rawResponsesItem: item });
|
|
779
652
|
break;
|
|
780
653
|
}
|
|
781
654
|
default:
|
|
@@ -785,14 +658,7 @@ function responsesToCore(body) {
|
|
|
785
658
|
layout.push({ original: item, coreId });
|
|
786
659
|
idx++;
|
|
787
660
|
}
|
|
788
|
-
return {
|
|
789
|
-
msgs,
|
|
790
|
-
systemParts,
|
|
791
|
-
preamble,
|
|
792
|
-
customToolCallIds,
|
|
793
|
-
layout,
|
|
794
|
-
droppedReasoning
|
|
795
|
-
};
|
|
661
|
+
return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning };
|
|
796
662
|
}
|
|
797
663
|
function patchTextParts(parts, text) {
|
|
798
664
|
const textIndexes = parts.flatMap(
|
|
@@ -808,8 +674,7 @@ function patchTextParts(parts, text) {
|
|
|
808
674
|
});
|
|
809
675
|
}
|
|
810
676
|
function patchOriginalItem(original, source, next) {
|
|
811
|
-
if (source.text === next.text && source.toolName === next.toolName && source.toolCallId === next.toolCallId && source.role === next.role && source.contentType === next.contentType)
|
|
812
|
-
return original;
|
|
677
|
+
if (source.text === next.text && source.toolName === next.toolName && source.toolCallId === next.toolCallId && source.role === next.role && source.contentType === next.contentType) return original;
|
|
813
678
|
if (original.type === "message") {
|
|
814
679
|
const message = original;
|
|
815
680
|
const content = typeof message.content === "string" ? next.text ?? "" : patchTextParts(message.content, next.text ?? "");
|
|
@@ -824,30 +689,20 @@ function patchOriginalItem(original, source, next) {
|
|
|
824
689
|
};
|
|
825
690
|
}
|
|
826
691
|
if (original.type === "function_call_output") {
|
|
827
|
-
return {
|
|
828
|
-
...original,
|
|
829
|
-
call_id: next.toolCallId ?? String(original.call_id ?? ""),
|
|
830
|
-
output: next.text ?? ""
|
|
831
|
-
};
|
|
692
|
+
return { ...original, call_id: next.toolCallId ?? String(original.call_id ?? ""), output: next.text ?? "" };
|
|
832
693
|
}
|
|
833
694
|
return original;
|
|
834
695
|
}
|
|
835
696
|
function patchResponsesInput(projection, messages) {
|
|
836
697
|
if (projection.stringInput) {
|
|
837
|
-
const original = projection.msgs.find(
|
|
838
|
-
|
|
839
|
-
);
|
|
840
|
-
const next = messages.find(
|
|
841
|
-
(message) => message.id === projection.stringInput?.coreId
|
|
842
|
-
);
|
|
698
|
+
const original = projection.msgs.find((message) => message.id === projection.stringInput?.coreId);
|
|
699
|
+
const next = messages.find((message) => message.id === projection.stringInput?.coreId);
|
|
843
700
|
if (original && next && messages.length === 1 && next.role === "user" && next.contentType === "text") {
|
|
844
701
|
return next.text === original.text ? projection.stringInput.original : next.text ?? "";
|
|
845
702
|
}
|
|
846
703
|
return coreToResponses(messages, projection.customToolCallIds);
|
|
847
704
|
}
|
|
848
|
-
const sourceById = new Map(
|
|
849
|
-
projection.msgs.map((message) => [message.id, message])
|
|
850
|
-
);
|
|
705
|
+
const sourceById = new Map(projection.msgs.map((message) => [message.id, message]));
|
|
851
706
|
const nextById = new Map(messages.map((message) => [message.id, message]));
|
|
852
707
|
const slotById = /* @__PURE__ */ new Map();
|
|
853
708
|
projection.layout.forEach((slot, index) => {
|
|
@@ -866,8 +721,7 @@ function patchResponsesInput(projection, messages) {
|
|
|
866
721
|
}
|
|
867
722
|
}
|
|
868
723
|
const generated = coreToResponses([message], projection.customToolCallIds);
|
|
869
|
-
if (generated.length > 0)
|
|
870
|
-
insertions.set(target, [...insertions.get(target) ?? [], ...generated]);
|
|
724
|
+
if (generated.length > 0) insertions.set(target, [...insertions.get(target) ?? [], ...generated]);
|
|
871
725
|
}
|
|
872
726
|
const out = [];
|
|
873
727
|
projection.layout.forEach((slot, index) => {
|
|
@@ -878,8 +732,7 @@ function patchResponsesInput(projection, messages) {
|
|
|
878
732
|
}
|
|
879
733
|
const source = sourceById.get(slot.coreId);
|
|
880
734
|
const next = nextById.get(slot.coreId);
|
|
881
|
-
if (source && next)
|
|
882
|
-
out.push(patchOriginalItem(slot.original, source, next));
|
|
735
|
+
if (source && next) out.push(patchOriginalItem(slot.original, source, next));
|
|
883
736
|
});
|
|
884
737
|
out.push(...insertions.get(projection.layout.length) ?? []);
|
|
885
738
|
return out;
|
|
@@ -890,48 +743,20 @@ function coreToResponses(messages, customToolCallIds = /* @__PURE__ */ new Set()
|
|
|
890
743
|
const biliMessage = message;
|
|
891
744
|
const raw = biliMessage.rawResponsesItem;
|
|
892
745
|
if (message.role === "system") {
|
|
893
|
-
out.push({
|
|
894
|
-
type: "message",
|
|
895
|
-
role: "developer",
|
|
896
|
-
content: message.text ?? ""
|
|
897
|
-
});
|
|
746
|
+
out.push({ type: "message", role: "developer", content: message.text ?? "" });
|
|
898
747
|
} else if (message.role === "user") {
|
|
899
748
|
const rawMessage = raw?.type === "message" ? raw : void 0;
|
|
900
|
-
if (rawMessage && userDisplayText(
|
|
901
|
-
|
|
902
|
-
messageContent(rawMessage.content)
|
|
903
|
-
) === (message.text ?? ""))
|
|
904
|
-
out.push(rawMessage);
|
|
905
|
-
else
|
|
906
|
-
out.push({
|
|
907
|
-
type: "message",
|
|
908
|
-
role: "user",
|
|
909
|
-
content: message.text ?? ""
|
|
910
|
-
});
|
|
749
|
+
if (rawMessage && userDisplayText(rawMessage.content, messageContent(rawMessage.content)) === (message.text ?? "")) out.push(rawMessage);
|
|
750
|
+
else out.push({ type: "message", role: "user", content: message.text ?? "" });
|
|
911
751
|
} else if (message.role === "assistant") {
|
|
912
752
|
if (message.contentType === "text") {
|
|
913
|
-
out.push({
|
|
914
|
-
type: "message",
|
|
915
|
-
role: "assistant",
|
|
916
|
-
content: message.text ?? ""
|
|
917
|
-
});
|
|
753
|
+
out.push({ type: "message", role: "assistant", content: message.text ?? "" });
|
|
918
754
|
} else if (message.contentType === "tool-call") {
|
|
919
755
|
const callId = message.toolCallId ?? `call_${message.id}`;
|
|
920
756
|
if (customToolCallIds.has(callId)) {
|
|
921
|
-
out.push({
|
|
922
|
-
type: "custom_tool_call",
|
|
923
|
-
call_id: callId,
|
|
924
|
-
name: message.toolName ?? "unknown",
|
|
925
|
-
input: message.text ?? "",
|
|
926
|
-
status: "completed"
|
|
927
|
-
});
|
|
757
|
+
out.push({ type: "custom_tool_call", call_id: callId, name: message.toolName ?? "unknown", input: message.text ?? "", status: "completed" });
|
|
928
758
|
} else {
|
|
929
|
-
out.push({
|
|
930
|
-
type: "function_call",
|
|
931
|
-
call_id: callId,
|
|
932
|
-
name: message.toolName ?? "unknown",
|
|
933
|
-
arguments: message.text ?? ""
|
|
934
|
-
});
|
|
759
|
+
out.push({ type: "function_call", call_id: callId, name: message.toolName ?? "unknown", arguments: message.text ?? "" });
|
|
935
760
|
}
|
|
936
761
|
} else if (message.contentType === "reasoning") {
|
|
937
762
|
if (raw) out.push(raw);
|
|
@@ -939,17 +764,9 @@ function coreToResponses(messages, customToolCallIds = /* @__PURE__ */ new Set()
|
|
|
939
764
|
} else if (message.role === "tool") {
|
|
940
765
|
const callId = message.toolCallId ?? "";
|
|
941
766
|
if (customToolCallIds.has(callId)) {
|
|
942
|
-
out.push({
|
|
943
|
-
type: "custom_tool_call_output",
|
|
944
|
-
call_id: callId,
|
|
945
|
-
output: message.text ?? ""
|
|
946
|
-
});
|
|
767
|
+
out.push({ type: "custom_tool_call_output", call_id: callId, output: message.text ?? "" });
|
|
947
768
|
} else {
|
|
948
|
-
out.push({
|
|
949
|
-
type: "function_call_output",
|
|
950
|
-
call_id: callId,
|
|
951
|
-
output: message.text ?? ""
|
|
952
|
-
});
|
|
769
|
+
out.push({ type: "function_call_output", call_id: callId, output: message.text ?? "" });
|
|
953
770
|
}
|
|
954
771
|
}
|
|
955
772
|
}
|
|
@@ -963,39 +780,18 @@ function injectResponsesDeveloperMessage(input, content) {
|
|
|
963
780
|
return items;
|
|
964
781
|
}
|
|
965
782
|
function conversationIdentityResponses(body, headerValue) {
|
|
966
|
-
if (headerValue?.trim())
|
|
967
|
-
return {
|
|
968
|
-
value: headerValue.trim(),
|
|
969
|
-
source: "header",
|
|
970
|
-
clientProvided: true
|
|
971
|
-
};
|
|
783
|
+
if (headerValue?.trim()) return { value: headerValue.trim(), source: "header", clientProvided: true };
|
|
972
784
|
if (typeof body.session_id === "string" && body.session_id.trim()) {
|
|
973
|
-
return {
|
|
974
|
-
value: body.session_id.trim(),
|
|
975
|
-
source: "body-session",
|
|
976
|
-
clientProvided: true
|
|
977
|
-
};
|
|
785
|
+
return { value: body.session_id.trim(), source: "body-session", clientProvided: true };
|
|
978
786
|
}
|
|
979
787
|
const metadataSession = body.metadata?.session_id;
|
|
980
788
|
if (typeof metadataSession === "string" && metadataSession.trim()) {
|
|
981
|
-
return {
|
|
982
|
-
value: metadataSession.trim(),
|
|
983
|
-
source: "metadata-session",
|
|
984
|
-
clientProvided: true
|
|
985
|
-
};
|
|
789
|
+
return { value: metadataSession.trim(), source: "metadata-session", clientProvided: true };
|
|
986
790
|
}
|
|
987
791
|
if (typeof body.previous_response_id === "string" && body.previous_response_id.trim()) {
|
|
988
|
-
return {
|
|
989
|
-
value: body.previous_response_id.trim(),
|
|
990
|
-
source: "previous-response",
|
|
991
|
-
clientProvided: false
|
|
992
|
-
};
|
|
792
|
+
return { value: body.previous_response_id.trim(), source: "previous-response", clientProvided: false };
|
|
993
793
|
}
|
|
994
|
-
return {
|
|
995
|
-
value: hashId(JSON.stringify(body.input ?? [])),
|
|
996
|
-
source: "content-fingerprint",
|
|
997
|
-
clientProvided: false
|
|
998
|
-
};
|
|
794
|
+
return { value: hashId(JSON.stringify(body.input ?? [])), source: "content-fingerprint", clientProvided: false };
|
|
999
795
|
}
|
|
1000
796
|
function conversationSignalResponses(body, headerValue) {
|
|
1001
797
|
return conversationIdentityResponses(body, headerValue).value;
|
|
@@ -1004,8 +800,7 @@ function createSubagentNamespaces() {
|
|
|
1004
800
|
const anchors = /* @__PURE__ */ new Map();
|
|
1005
801
|
return {
|
|
1006
802
|
namespaceFor(identityValue, instructions) {
|
|
1007
|
-
if (typeof instructions !== "string" || instructions.trim().length === 0)
|
|
1008
|
-
return identityValue;
|
|
803
|
+
if (typeof instructions !== "string" || instructions.trim().length === 0) return identityValue;
|
|
1009
804
|
const fp = hashId(instructions);
|
|
1010
805
|
const anchor = anchors.get(identityValue);
|
|
1011
806
|
if (anchor === void 0) {
|
|
@@ -1297,12 +1092,7 @@ function jsonValue(text) {
|
|
|
1297
1092
|
}
|
|
1298
1093
|
|
|
1299
1094
|
// src/wire/formats.ts
|
|
1300
|
-
var WIRE_FORMATS = [
|
|
1301
|
-
"anthropic",
|
|
1302
|
-
"openai",
|
|
1303
|
-
"responses",
|
|
1304
|
-
"google"
|
|
1305
|
-
];
|
|
1095
|
+
var WIRE_FORMATS = ["anthropic", "openai", "responses", "google"];
|
|
1306
1096
|
function isWireFormat(value) {
|
|
1307
1097
|
return typeof value === "string" && WIRE_FORMATS.includes(value);
|
|
1308
1098
|
}
|
|
@@ -1347,17 +1137,13 @@ function thinkingText(blocks) {
|
|
|
1347
1137
|
return blocks?.filter((b) => b.type === "thinking" && b.thinking.trim().length > 0).map((b) => b.thinking).join("\n") ?? "";
|
|
1348
1138
|
}
|
|
1349
1139
|
function mirrorOpenaiMessages(view, systemText) {
|
|
1350
|
-
const messages = [
|
|
1351
|
-
{ role: "system", content: systemText }
|
|
1352
|
-
];
|
|
1140
|
+
const messages = [{ role: "system", content: systemText }];
|
|
1353
1141
|
for (const message of view) {
|
|
1354
1142
|
if (message.role === "user") {
|
|
1355
1143
|
const text = joinText(message.blocks);
|
|
1356
1144
|
if (text) messages.push({ role: "user", content: text });
|
|
1357
1145
|
} else if (message.role === "assistant") {
|
|
1358
|
-
const calls = (message.blocks ?? []).filter(
|
|
1359
|
-
(b) => b.type === "toolCall"
|
|
1360
|
-
);
|
|
1146
|
+
const calls = (message.blocks ?? []).filter((b) => b.type === "toolCall");
|
|
1361
1147
|
const reasoning = thinkingText(message.blocks);
|
|
1362
1148
|
const text = joinText(message.blocks);
|
|
1363
1149
|
if (calls.length > 0) {
|
|
@@ -1368,25 +1154,14 @@ function mirrorOpenaiMessages(view, systemText) {
|
|
|
1368
1154
|
tool_calls: calls.map((c) => ({
|
|
1369
1155
|
id: c.id,
|
|
1370
1156
|
type: "function",
|
|
1371
|
-
function: {
|
|
1372
|
-
name: c.name ?? "",
|
|
1373
|
-
arguments: JSON.stringify(c.arguments ?? {})
|
|
1374
|
-
}
|
|
1157
|
+
function: { name: c.name ?? "", arguments: JSON.stringify(c.arguments ?? {}) }
|
|
1375
1158
|
}))
|
|
1376
1159
|
});
|
|
1377
1160
|
} else if (text || reasoning) {
|
|
1378
|
-
messages.push({
|
|
1379
|
-
role: "assistant",
|
|
1380
|
-
content: text,
|
|
1381
|
-
...reasoning ? { reasoning_content: reasoning } : {}
|
|
1382
|
-
});
|
|
1161
|
+
messages.push({ role: "assistant", content: text, ...reasoning ? { reasoning_content: reasoning } : {} });
|
|
1383
1162
|
}
|
|
1384
1163
|
} else if (message.role === "toolResult") {
|
|
1385
|
-
messages.push({
|
|
1386
|
-
role: "tool",
|
|
1387
|
-
tool_call_id: message.toolCallId ?? "",
|
|
1388
|
-
content: joinText(message.blocks)
|
|
1389
|
-
});
|
|
1164
|
+
messages.push({ role: "tool", tool_call_id: message.toolCallId ?? "", content: joinText(message.blocks) });
|
|
1390
1165
|
} else {
|
|
1391
1166
|
const text = message.text ?? "";
|
|
1392
1167
|
if (text) messages.push({ role: "developer", content: text });
|
|
@@ -1399,8 +1174,7 @@ function mirrorAnthropicMessages(view) {
|
|
|
1399
1174
|
for (const message of view) {
|
|
1400
1175
|
if (message.role === "user") {
|
|
1401
1176
|
const text = joinText(message.blocks);
|
|
1402
|
-
if (text)
|
|
1403
|
-
messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
1177
|
+
if (text) messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
1404
1178
|
} else if (message.role === "assistant") {
|
|
1405
1179
|
const content = [];
|
|
1406
1180
|
for (const b of message.blocks ?? []) {
|
|
@@ -1419,30 +1193,18 @@ function mirrorAnthropicMessages(view) {
|
|
|
1419
1193
|
} catch {
|
|
1420
1194
|
input = {};
|
|
1421
1195
|
}
|
|
1422
|
-
content.push({
|
|
1423
|
-
type: "tool_use",
|
|
1424
|
-
id: b.id,
|
|
1425
|
-
name: b.name ?? "",
|
|
1426
|
-
input
|
|
1427
|
-
});
|
|
1196
|
+
content.push({ type: "tool_use", id: b.id, name: b.name ?? "", input });
|
|
1428
1197
|
}
|
|
1429
1198
|
}
|
|
1430
1199
|
if (content.length > 0) messages.push({ role: "assistant", content });
|
|
1431
1200
|
} else if (message.role === "toolResult") {
|
|
1432
1201
|
messages.push({
|
|
1433
1202
|
role: "user",
|
|
1434
|
-
content: [
|
|
1435
|
-
{
|
|
1436
|
-
type: "tool_result",
|
|
1437
|
-
tool_use_id: message.toolCallId ?? "",
|
|
1438
|
-
content: joinText(message.blocks)
|
|
1439
|
-
}
|
|
1440
|
-
]
|
|
1203
|
+
content: [{ type: "tool_result", tool_use_id: message.toolCallId ?? "", content: joinText(message.blocks) }]
|
|
1441
1204
|
});
|
|
1442
1205
|
} else {
|
|
1443
1206
|
const text = message.text ?? "";
|
|
1444
|
-
if (text)
|
|
1445
|
-
messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
1207
|
+
if (text) messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
1446
1208
|
}
|
|
1447
1209
|
}
|
|
1448
1210
|
return messages;
|
|
@@ -1452,25 +1214,13 @@ function mirrorResponsesInput(view) {
|
|
|
1452
1214
|
for (const message of view) {
|
|
1453
1215
|
if (message.role === "user") {
|
|
1454
1216
|
const text = joinText(message.blocks);
|
|
1455
|
-
if (text)
|
|
1456
|
-
input.push({
|
|
1457
|
-
type: "message",
|
|
1458
|
-
role: "user",
|
|
1459
|
-
content: [{ type: "input_text", text }]
|
|
1460
|
-
});
|
|
1217
|
+
if (text) input.push({ type: "message", role: "user", content: [{ type: "input_text", text }] });
|
|
1461
1218
|
} else if (message.role === "assistant") {
|
|
1462
1219
|
for (const b of message.blocks ?? []) {
|
|
1463
1220
|
if (b.type === "thinking" && b.thinking.trim().length > 0) {
|
|
1464
|
-
input.push({
|
|
1465
|
-
type: "reasoning",
|
|
1466
|
-
summary: [{ type: "summary_text", text: b.thinking }]
|
|
1467
|
-
});
|
|
1221
|
+
input.push({ type: "reasoning", summary: [{ type: "summary_text", text: b.thinking }] });
|
|
1468
1222
|
} else if (b.type === "text" && b.text.trim().length > 0) {
|
|
1469
|
-
input.push({
|
|
1470
|
-
type: "message",
|
|
1471
|
-
role: "assistant",
|
|
1472
|
-
content: [{ type: "output_text", text: b.text }]
|
|
1473
|
-
});
|
|
1223
|
+
input.push({ type: "message", role: "assistant", content: [{ type: "output_text", text: b.text }] });
|
|
1474
1224
|
} else if (b.type === "toolCall") {
|
|
1475
1225
|
let args = "{}";
|
|
1476
1226
|
try {
|
|
@@ -1478,28 +1228,14 @@ function mirrorResponsesInput(view) {
|
|
|
1478
1228
|
} catch {
|
|
1479
1229
|
args = "{}";
|
|
1480
1230
|
}
|
|
1481
|
-
input.push({
|
|
1482
|
-
type: "function_call",
|
|
1483
|
-
call_id: b.id ?? "",
|
|
1484
|
-
name: b.name ?? "",
|
|
1485
|
-
arguments: args
|
|
1486
|
-
});
|
|
1231
|
+
input.push({ type: "function_call", call_id: b.id ?? "", name: b.name ?? "", arguments: args });
|
|
1487
1232
|
}
|
|
1488
1233
|
}
|
|
1489
1234
|
} else if (message.role === "toolResult") {
|
|
1490
|
-
input.push({
|
|
1491
|
-
type: "function_call_output",
|
|
1492
|
-
call_id: message.toolCallId ?? "",
|
|
1493
|
-
output: joinText(message.blocks)
|
|
1494
|
-
});
|
|
1235
|
+
input.push({ type: "function_call_output", call_id: message.toolCallId ?? "", output: joinText(message.blocks) });
|
|
1495
1236
|
} else {
|
|
1496
1237
|
const text = message.text ?? "";
|
|
1497
|
-
if (text)
|
|
1498
|
-
input.push({
|
|
1499
|
-
type: "message",
|
|
1500
|
-
role: "user",
|
|
1501
|
-
content: [{ type: "input_text", text }]
|
|
1502
|
-
});
|
|
1238
|
+
if (text) input.push({ type: "message", role: "user", content: [{ type: "input_text", text }] });
|
|
1503
1239
|
}
|
|
1504
1240
|
}
|
|
1505
1241
|
return input;
|
|
@@ -1541,11 +1277,7 @@ function compressToolArgs(call) {
|
|
|
1541
1277
|
if (!args || typeof args !== "object" || Array.isArray(args)) return null;
|
|
1542
1278
|
const a = args;
|
|
1543
1279
|
if (call.name === "compress") {
|
|
1544
|
-
return Array.isArray(a.content) ? {
|
|
1545
|
-
content: a.content,
|
|
1546
|
-
topic: a.topic,
|
|
1547
|
-
summaryMaxChars: a.summaryMaxChars
|
|
1548
|
-
} : null;
|
|
1280
|
+
return Array.isArray(a.content) ? { content: a.content, topic: a.topic, summaryMaxChars: a.summaryMaxChars } : null;
|
|
1549
1281
|
}
|
|
1550
1282
|
if (call.name !== "write") return null;
|
|
1551
1283
|
const path = typeof a.path === "string" ? a.path.split("?")[0].replace(/\/+$/, "") : "";
|
|
@@ -1561,17 +1293,12 @@ function compressToolArgs(call) {
|
|
|
1561
1293
|
if (!inner || typeof inner !== "object") return null;
|
|
1562
1294
|
if (Array.isArray(inner)) return { content: inner };
|
|
1563
1295
|
const ia = inner;
|
|
1564
|
-
return Array.isArray(ia.content) ? {
|
|
1565
|
-
content: ia.content,
|
|
1566
|
-
topic: ia.topic,
|
|
1567
|
-
summaryMaxChars: ia.summaryMaxChars
|
|
1568
|
-
} : { content: [ia] };
|
|
1296
|
+
return Array.isArray(ia.content) ? { content: ia.content, topic: ia.topic, summaryMaxChars: ia.summaryMaxChars } : { content: [ia] };
|
|
1569
1297
|
}
|
|
1570
1298
|
function toolCallNames(msgs) {
|
|
1571
1299
|
const names = /* @__PURE__ */ new Map();
|
|
1572
1300
|
for (const m of msgs) {
|
|
1573
|
-
if (m.contentType === "tool-call" && m.toolCallId && m.toolName)
|
|
1574
|
-
names.set(m.toolCallId, m.toolName);
|
|
1301
|
+
if (m.contentType === "tool-call" && m.toolCallId && m.toolName) names.set(m.toolCallId, m.toolName);
|
|
1575
1302
|
}
|
|
1576
1303
|
return names;
|
|
1577
1304
|
}
|
|
@@ -1593,8 +1320,7 @@ function findCompressCallsCore(msg) {
|
|
|
1593
1320
|
const callTopic = typeof args.topic === "string" ? args.topic : void 0;
|
|
1594
1321
|
for (const item of content) {
|
|
1595
1322
|
const r = item;
|
|
1596
|
-
if (typeof r.startId !== "string" || typeof r.endId !== "string" || typeof r.summary !== "string" || r.summary.length === 0)
|
|
1597
|
-
continue;
|
|
1323
|
+
if (typeof r.startId !== "string" || typeof r.endId !== "string" || typeof r.summary !== "string" || r.summary.length === 0) continue;
|
|
1598
1324
|
ranges.push({
|
|
1599
1325
|
startRef: r.startId,
|
|
1600
1326
|
endRef: r.endId,
|
|
@@ -1649,8 +1375,7 @@ function boundaryIndexCore(ref, byRef, blocks, coreMessages, pick, fallbackIdx =
|
|
|
1649
1375
|
function refOfPieceCore(coreMessages, idx, byRef) {
|
|
1650
1376
|
const id = coreMessages[idx]?.id;
|
|
1651
1377
|
if (!id) return "";
|
|
1652
|
-
for (const [ref, mapped] of Object.entries(byRef))
|
|
1653
|
-
if (mapped === id) return ref;
|
|
1378
|
+
for (const [ref, mapped] of Object.entries(byRef)) if (mapped === id) return ref;
|
|
1654
1379
|
return "";
|
|
1655
1380
|
}
|
|
1656
1381
|
function staleRangeCore(r, rangeIndex, resultText, coreMessages, callIndex, byRef, blocks) {
|
|
@@ -1660,13 +1385,7 @@ function staleRangeCore(r, rangeIndex, resultText, coreMessages, callIndex, byRe
|
|
|
1660
1385
|
const [ps, pe] = pair === "-" ? ["", ""] : pair.split("-");
|
|
1661
1386
|
const fbStart = ps && ps !== "" ? Number.parseInt(ps, 10) : -1;
|
|
1662
1387
|
const fbEnd = pe && pe !== "" ? Number.parseInt(pe, 10) : -1;
|
|
1663
|
-
const startRaw = boundaryRawCore(
|
|
1664
|
-
r.startRef,
|
|
1665
|
-
byRef,
|
|
1666
|
-
blocks,
|
|
1667
|
-
coreMessages,
|
|
1668
|
-
"min"
|
|
1669
|
-
);
|
|
1388
|
+
const startRaw = boundaryRawCore(r.startRef, byRef, blocks, coreMessages, "min");
|
|
1670
1389
|
const endRaw = boundaryRawCore(r.endRef, byRef, blocks, coreMessages, "max");
|
|
1671
1390
|
const rawStartIdx = startRaw ? coreMessages.findIndex((cm) => cm.id === startRaw) : -1;
|
|
1672
1391
|
const rawEndIdx = endRaw ? coreMessages.findIndex((cm) => cm.id === endRaw) : -1;
|
|
@@ -1674,46 +1393,27 @@ function staleRangeCore(r, rangeIndex, resultText, coreMessages, callIndex, byRe
|
|
|
1674
1393
|
const endIdx = rawEndIdx >= 0 ? rawEndIdx : fbEnd >= 0 && fbEnd < coreMessages.length ? fbEnd : -1;
|
|
1675
1394
|
if (startIdx < 0 || endIdx < 0) {
|
|
1676
1395
|
if (!/^b\d+$/i.test(r.startRef.trim()) && !/^b\d+$/i.test(r.endRef.trim()))
|
|
1677
|
-
return {
|
|
1678
|
-
reject: `unresolved ${r.startRef}..${r.endRef} -> ${startIdx}..${endIdx}`,
|
|
1679
|
-
...hinted ? { hint: true } : {}
|
|
1680
|
-
};
|
|
1396
|
+
return { reject: `unresolved ${r.startRef}..${r.endRef} -> ${startIdx}..${endIdx}`, ...hinted ? { hint: true } : {} };
|
|
1681
1397
|
return {};
|
|
1682
1398
|
}
|
|
1683
|
-
if (endIdx > callIndex)
|
|
1684
|
-
return {
|
|
1685
|
-
reject: `end idx ${endIdx} > callIndex ${callIndex}`,
|
|
1686
|
-
...hinted ? { hint: true } : {}
|
|
1687
|
-
};
|
|
1399
|
+
if (endIdx > callIndex) return { reject: `end idx ${endIdx} > callIndex ${callIndex}`, ...hinted ? { hint: true } : {} };
|
|
1688
1400
|
const m = resultText.match(/\[fp=([0-9a-f,-]+)\]/);
|
|
1689
1401
|
if (m) {
|
|
1690
1402
|
const want = m[1].split(",")[rangeIndex];
|
|
1691
1403
|
if (want !== void 0 && want !== "-") {
|
|
1692
1404
|
const got = spanFingerprintCoreIdx(coreMessages, startIdx, endIdx);
|
|
1693
|
-
if (want !== got)
|
|
1694
|
-
return {
|
|
1695
|
-
reject: `fp ${r.startRef}..${r.endRef} want ${want} got ${got} @${startIdx}..${endIdx}`,
|
|
1696
|
-
...hinted ? { hint: true } : {}
|
|
1697
|
-
};
|
|
1405
|
+
if (want !== got) return { reject: `fp ${r.startRef}..${r.endRef} want ${want} got ${got} @${startIdx}..${endIdx}`, ...hinted ? { hint: true } : {} };
|
|
1698
1406
|
}
|
|
1699
1407
|
}
|
|
1700
1408
|
const remap = {};
|
|
1701
1409
|
if (/^m\d+$/i.test(r.startRef.trim()) && rawStartIdx < 0) {
|
|
1702
1410
|
const ref = refOfPieceCore(coreMessages, startIdx, byRef);
|
|
1703
|
-
if (!ref)
|
|
1704
|
-
return {
|
|
1705
|
-
reject: `recovered ${r.startRef} @${startIdx} has no ref (protected piece)`,
|
|
1706
|
-
...hinted ? { hint: true } : {}
|
|
1707
|
-
};
|
|
1411
|
+
if (!ref) return { reject: `recovered ${r.startRef} @${startIdx} has no ref (protected piece)`, ...hinted ? { hint: true } : {} };
|
|
1708
1412
|
remap.startRef = ref;
|
|
1709
1413
|
}
|
|
1710
1414
|
if (/^m\d+$/i.test(r.endRef.trim()) && rawEndIdx < 0) {
|
|
1711
1415
|
const ref = refOfPieceCore(coreMessages, endIdx, byRef);
|
|
1712
|
-
if (!ref)
|
|
1713
|
-
return {
|
|
1714
|
-
reject: `recovered ${r.endRef} @${endIdx} has no ref (protected piece)`,
|
|
1715
|
-
...hinted ? { hint: true } : {}
|
|
1716
|
-
};
|
|
1416
|
+
if (!ref) return { reject: `recovered ${r.endRef} @${endIdx} has no ref (protected piece)`, ...hinted ? { hint: true } : {} };
|
|
1717
1417
|
remap.endRef = ref;
|
|
1718
1418
|
}
|
|
1719
1419
|
if (!remap.startRef && !remap.endRef) return {};
|
|
@@ -1721,13 +1421,7 @@ function staleRangeCore(r, rangeIndex, resultText, coreMessages, callIndex, byRe
|
|
|
1721
1421
|
}
|
|
1722
1422
|
function rangeFingerprintsCore(ranges, coreMessages, byRef, blocks) {
|
|
1723
1423
|
return ranges.map((r) => {
|
|
1724
|
-
const start = boundaryRawCore(
|
|
1725
|
-
r.startRef,
|
|
1726
|
-
byRef,
|
|
1727
|
-
blocks,
|
|
1728
|
-
coreMessages,
|
|
1729
|
-
"min"
|
|
1730
|
-
);
|
|
1424
|
+
const start = boundaryRawCore(r.startRef, byRef, blocks, coreMessages, "min");
|
|
1731
1425
|
const end = start ? boundaryRawCore(r.endRef, byRef, blocks, coreMessages, "max") : "";
|
|
1732
1426
|
if (start && end) {
|
|
1733
1427
|
const fp = spanFingerprintCore(coreMessages, start, end);
|