acp-kernel 0.0.33 → 0.0.35
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/wire/demoted-thinking.d.ts +41 -0
- package/dist/wire/demoted-thinking.d.ts.map +1 -0
- package/dist/wire/index.d.ts +2 -0
- package/dist/wire/index.d.ts.map +1 -1
- package/dist/wire/index.js +212 -13
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/mirror.d.ts +72 -0
- package/dist/wire/mirror.d.ts.map +1 -0
- package/dist/wire/openai.d.ts.map +1 -1
- package/dist/wire/responses.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Inline "demoted thinking" normalization.
|
|
2
|
+
*
|
|
3
|
+
* Hosts that cannot replay prior-turn reasoning as a structured block
|
|
4
|
+
* (pi-ai transform-messages demotion on model switch, openai-completions
|
|
5
|
+
* `requiresThinkingAsText` profiles, gateways that inline native
|
|
6
|
+
* reasoning) fold it INTO the assistant content string wrapped in a
|
|
7
|
+
* dialect tag:
|
|
8
|
+
*
|
|
9
|
+
* glm / deepseek / kimi / qwen3 / hermes : <think>\n{text}\n</think>
|
|
10
|
+
* anthropic / minimax / xml : <thinking>\n{text}\n</thinking>
|
|
11
|
+
* gemini : ```thinking\n{text}\n```
|
|
12
|
+
*
|
|
13
|
+
* followed by a single "\n" glue before the next content block. The same
|
|
14
|
+
* logical turn can therefore arrive as a `reasoning_content` field (or a
|
|
15
|
+
* separate reasoning item on /v1/responses) OR as this inline form. If the
|
|
16
|
+
* wire codecs kept both as one text blob, the two serializations of one
|
|
17
|
+
* turn would land in DIFFERENT core-id/fingerprint spaces — exactly the
|
|
18
|
+
* issue #64 "restart loses blocks" class, where the mirror produced one
|
|
19
|
+
* form and the live wire the other.
|
|
20
|
+
*
|
|
21
|
+
* splitDemotedThinking() reverses the rendering byte-exactly so both
|
|
22
|
+
* codecs can normalize before identity derivation (deriveMessageId). It
|
|
23
|
+
* only fires when the tag opens at offset 0 of the content, which is the
|
|
24
|
+
* only position the demotion renderer can produce it in.
|
|
25
|
+
*
|
|
26
|
+
* One form is intentionally NOT recoverable here: the pi-ai anthropic
|
|
27
|
+
* dialect demotes to BARE text (no tag), which is indistinguishable from
|
|
28
|
+
* ordinary assistant prose; that case must be aligned upstream (mirror
|
|
29
|
+
* uses the same bare rendering), not parsed. */
|
|
30
|
+
export type DemotedSplit = {
|
|
31
|
+
reasoning: string;
|
|
32
|
+
text: string;
|
|
33
|
+
};
|
|
34
|
+
/** If `content` starts with one or more inline demoted-thinking blocks,
|
|
35
|
+
* split them out. Returns null when no tag opens the content (the common
|
|
36
|
+
* case — including every user message and every assistant message whose
|
|
37
|
+
* reasoning traveled as a field/item), in which case callers keep the
|
|
38
|
+
* content as-is. Malformed (unterminated) or empty blocks do not match;
|
|
39
|
+
* the content is then treated as plain text, never dropped. */
|
|
40
|
+
export declare function splitDemotedThinking(content: string): DemotedSplit | null;
|
|
41
|
+
//# sourceMappingURL=demoted-thinking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demoted-thinking.d.ts","sourceRoot":"","sources":["../../src/wire/demoted-thinking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDA4BgD;AAEhD,MAAM,MAAM,YAAY,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAcF;;;;;gEAKgE;AAChE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAuBzE"}
|
package/dist/wire/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export * from "./responses.js";
|
|
|
4
4
|
export * from "./formats.js";
|
|
5
5
|
export * from "./bili-message.js";
|
|
6
6
|
export * from "./message-id.js";
|
|
7
|
+
export * from "./demoted-thinking.js";
|
|
8
|
+
export * from "./mirror.js";
|
|
7
9
|
export * from "./util.js";
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/wire/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
|
package/dist/wire/index.js
CHANGED
|
@@ -185,6 +185,35 @@ function safeParse(s) {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
// src/wire/demoted-thinking.ts
|
|
189
|
+
var FORMS = [
|
|
190
|
+
{ open: "<think>\n", close: "\n</think>" },
|
|
191
|
+
{ open: "<thinking>\n", close: "\n</thinking>" },
|
|
192
|
+
{ open: "```thinking\n", close: "\n```" }
|
|
193
|
+
];
|
|
194
|
+
function splitDemotedThinking(content) {
|
|
195
|
+
let rest = content;
|
|
196
|
+
const parts = [];
|
|
197
|
+
for (; ; ) {
|
|
198
|
+
let matched = false;
|
|
199
|
+
for (const form of FORMS) {
|
|
200
|
+
if (!rest.startsWith(form.open)) continue;
|
|
201
|
+
const end = rest.indexOf(form.close, form.open.length);
|
|
202
|
+
if (end < 0) continue;
|
|
203
|
+
const inner = rest.slice(form.open.length, end);
|
|
204
|
+
if (inner.length === 0) continue;
|
|
205
|
+
parts.push(inner);
|
|
206
|
+
rest = rest.slice(end + form.close.length);
|
|
207
|
+
if (rest.startsWith("\n")) rest = rest.slice(1);
|
|
208
|
+
matched = true;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (!matched) break;
|
|
212
|
+
}
|
|
213
|
+
if (parts.length === 0) return null;
|
|
214
|
+
return { reasoning: parts.join("\n"), text: rest };
|
|
215
|
+
}
|
|
216
|
+
|
|
188
217
|
// src/wire/bili-message.ts
|
|
189
218
|
function toCoreMessages(msgs) {
|
|
190
219
|
return msgs;
|
|
@@ -224,7 +253,16 @@ function openaiToCore(body) {
|
|
|
224
253
|
break;
|
|
225
254
|
}
|
|
226
255
|
case "assistant": {
|
|
227
|
-
const
|
|
256
|
+
const fieldReasoning = typeof m.reasoning_content === "string" ? m.reasoning_content : "";
|
|
257
|
+
let reasoning = fieldReasoning;
|
|
258
|
+
let text = stringContent(m.content);
|
|
259
|
+
if (!reasoning) {
|
|
260
|
+
const split = splitDemotedThinking(text);
|
|
261
|
+
if (split) {
|
|
262
|
+
reasoning = split.reasoning;
|
|
263
|
+
text = split.text;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
228
266
|
if (reasoning) {
|
|
229
267
|
const base = deriveMessageId("assistant", "reasoning", reasoning);
|
|
230
268
|
msgs.push({
|
|
@@ -235,7 +273,6 @@ function openaiToCore(body) {
|
|
|
235
273
|
reasoningContent: reasoning
|
|
236
274
|
});
|
|
237
275
|
}
|
|
238
|
-
const text = stringContent(m.content);
|
|
239
276
|
if (text) {
|
|
240
277
|
const base = deriveMessageId("assistant", "text", text);
|
|
241
278
|
msgs.push({ id: clusters.next(base), role: "assistant", contentType: "text", text });
|
|
@@ -459,17 +496,33 @@ function responsesToCore(body) {
|
|
|
459
496
|
continue;
|
|
460
497
|
} else if (message.role === "user" || message.role === "assistant" && text) {
|
|
461
498
|
const role = message.role;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
499
|
+
let effText = text;
|
|
500
|
+
if (role === "assistant") {
|
|
501
|
+
const split = splitDemotedThinking(text);
|
|
502
|
+
if (split) {
|
|
503
|
+
msgs.push({
|
|
504
|
+
id: clusters.next(deriveMessageId("assistant", "reasoning", split.reasoning)),
|
|
505
|
+
role: "assistant",
|
|
506
|
+
contentType: "reasoning",
|
|
507
|
+
text: split.reasoning,
|
|
508
|
+
rawResponsesItem: item
|
|
509
|
+
});
|
|
510
|
+
effText = split.text;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (effText) {
|
|
514
|
+
coreId = clusters.next(deriveMessageId(role, "text", effText));
|
|
515
|
+
const imageUrl = Array.isArray(message.content) ? message.content.find((part) => part.type === "input_image" && typeof part.image_url === "string")?.image_url : void 0;
|
|
516
|
+
const image = typeof imageUrl === "string" ? parseDataUrl(imageUrl) : void 0;
|
|
517
|
+
msgs.push({
|
|
518
|
+
id: coreId,
|
|
519
|
+
role,
|
|
520
|
+
contentType: "text",
|
|
521
|
+
text: effText,
|
|
522
|
+
rawResponsesItem: item,
|
|
523
|
+
...image ? { imageMediaType: image.mediaType, imageBase64: image.base64 } : {}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
473
526
|
}
|
|
474
527
|
break;
|
|
475
528
|
}
|
|
@@ -722,6 +775,145 @@ function detectWireFormat(payload) {
|
|
|
722
775
|
}
|
|
723
776
|
return "openai";
|
|
724
777
|
}
|
|
778
|
+
|
|
779
|
+
// src/wire/mirror.ts
|
|
780
|
+
function textBlocks(blocks) {
|
|
781
|
+
const out = [];
|
|
782
|
+
for (const b of blocks ?? []) if (b.type === "text") out.push(b.text);
|
|
783
|
+
return out;
|
|
784
|
+
}
|
|
785
|
+
function joinText(blocks) {
|
|
786
|
+
return textBlocks(blocks).join("\n");
|
|
787
|
+
}
|
|
788
|
+
function thinkingText(blocks) {
|
|
789
|
+
return blocks?.filter((b) => b.type === "thinking" && b.thinking.trim().length > 0).map((b) => b.thinking).join("\n") ?? "";
|
|
790
|
+
}
|
|
791
|
+
function mirrorOpenaiMessages(view, systemText) {
|
|
792
|
+
const messages = [{ role: "system", content: systemText }];
|
|
793
|
+
for (const message of view) {
|
|
794
|
+
if (message.role === "user") {
|
|
795
|
+
const text = joinText(message.blocks);
|
|
796
|
+
if (text) messages.push({ role: "user", content: text });
|
|
797
|
+
} else if (message.role === "assistant") {
|
|
798
|
+
const calls = (message.blocks ?? []).filter((b) => b.type === "toolCall");
|
|
799
|
+
const reasoning = thinkingText(message.blocks);
|
|
800
|
+
const text = joinText(message.blocks);
|
|
801
|
+
if (calls.length > 0) {
|
|
802
|
+
messages.push({
|
|
803
|
+
role: "assistant",
|
|
804
|
+
content: text,
|
|
805
|
+
...reasoning ? { reasoning_content: reasoning } : {},
|
|
806
|
+
tool_calls: calls.map((c) => ({
|
|
807
|
+
id: c.id,
|
|
808
|
+
type: "function",
|
|
809
|
+
function: { name: c.name ?? "", arguments: JSON.stringify(c.arguments ?? {}) }
|
|
810
|
+
}))
|
|
811
|
+
});
|
|
812
|
+
} else if (text || reasoning) {
|
|
813
|
+
messages.push({ role: "assistant", content: text, ...reasoning ? { reasoning_content: reasoning } : {} });
|
|
814
|
+
}
|
|
815
|
+
} else if (message.role === "toolResult") {
|
|
816
|
+
messages.push({ role: "tool", tool_call_id: message.toolCallId ?? "", content: joinText(message.blocks) });
|
|
817
|
+
} else {
|
|
818
|
+
const text = message.text ?? "";
|
|
819
|
+
if (text) messages.push({ role: "developer", content: text });
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return messages;
|
|
823
|
+
}
|
|
824
|
+
function mirrorAnthropicMessages(view) {
|
|
825
|
+
const messages = [];
|
|
826
|
+
for (const message of view) {
|
|
827
|
+
if (message.role === "user") {
|
|
828
|
+
const text = joinText(message.blocks);
|
|
829
|
+
if (text) messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
830
|
+
} else if (message.role === "assistant") {
|
|
831
|
+
const content = [];
|
|
832
|
+
for (const b of message.blocks ?? []) {
|
|
833
|
+
if (b.type === "thinking" && b.thinking.trim().length > 0) {
|
|
834
|
+
content.push({
|
|
835
|
+
type: "thinking",
|
|
836
|
+
thinking: b.thinking,
|
|
837
|
+
...typeof b.signature === "string" && b.signature ? { signature: b.signature } : {}
|
|
838
|
+
});
|
|
839
|
+
} else if (b.type === "text" && b.text.trim().length > 0) {
|
|
840
|
+
content.push({ type: "text", text: b.text });
|
|
841
|
+
} else if (b.type === "toolCall") {
|
|
842
|
+
let input = {};
|
|
843
|
+
try {
|
|
844
|
+
input = b.arguments && typeof b.arguments === "object" ? b.arguments : JSON.parse(JSON.stringify(b.arguments ?? {}));
|
|
845
|
+
} catch {
|
|
846
|
+
input = {};
|
|
847
|
+
}
|
|
848
|
+
content.push({ type: "tool_use", id: b.id, name: b.name ?? "", input });
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
if (content.length > 0) messages.push({ role: "assistant", content });
|
|
852
|
+
} else if (message.role === "toolResult") {
|
|
853
|
+
messages.push({
|
|
854
|
+
role: "user",
|
|
855
|
+
content: [{ type: "tool_result", tool_use_id: message.toolCallId ?? "", content: joinText(message.blocks) }]
|
|
856
|
+
});
|
|
857
|
+
} else {
|
|
858
|
+
const text = message.text ?? "";
|
|
859
|
+
if (text) messages.push({ role: "user", content: [{ type: "text", text }] });
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return messages;
|
|
863
|
+
}
|
|
864
|
+
function mirrorResponsesInput(view) {
|
|
865
|
+
const input = [];
|
|
866
|
+
for (const message of view) {
|
|
867
|
+
if (message.role === "user") {
|
|
868
|
+
const text = joinText(message.blocks);
|
|
869
|
+
if (text) input.push({ type: "message", role: "user", content: [{ type: "input_text", text }] });
|
|
870
|
+
} else if (message.role === "assistant") {
|
|
871
|
+
for (const b of message.blocks ?? []) {
|
|
872
|
+
if (b.type === "thinking" && b.thinking.trim().length > 0) {
|
|
873
|
+
input.push({ type: "reasoning", summary: [{ type: "summary_text", text: b.thinking }] });
|
|
874
|
+
} else if (b.type === "text" && b.text.trim().length > 0) {
|
|
875
|
+
input.push({ type: "message", role: "assistant", content: [{ type: "output_text", text: b.text }] });
|
|
876
|
+
} else if (b.type === "toolCall") {
|
|
877
|
+
let args = "{}";
|
|
878
|
+
try {
|
|
879
|
+
args = JSON.stringify(b.arguments ?? {});
|
|
880
|
+
} catch {
|
|
881
|
+
args = "{}";
|
|
882
|
+
}
|
|
883
|
+
input.push({ type: "function_call", call_id: b.id ?? "", name: b.name ?? "", arguments: args });
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
} else if (message.role === "toolResult") {
|
|
887
|
+
input.push({ type: "function_call_output", call_id: message.toolCallId ?? "", output: joinText(message.blocks) });
|
|
888
|
+
} else {
|
|
889
|
+
const text = message.text ?? "";
|
|
890
|
+
if (text) input.push({ type: "message", role: "user", content: [{ type: "input_text", text }] });
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return input;
|
|
894
|
+
}
|
|
895
|
+
function mirrorOpenaiToCore(view, systemText) {
|
|
896
|
+
const { msgs } = openaiToCore({
|
|
897
|
+
model: "prime-fold",
|
|
898
|
+
messages: mirrorOpenaiMessages(view, systemText)
|
|
899
|
+
});
|
|
900
|
+
return msgs;
|
|
901
|
+
}
|
|
902
|
+
function mirrorAnthropicToCore(view) {
|
|
903
|
+
const { msgs } = anthropicToCore({
|
|
904
|
+
model: "prime-fold",
|
|
905
|
+
messages: mirrorAnthropicMessages(view)
|
|
906
|
+
});
|
|
907
|
+
return msgs;
|
|
908
|
+
}
|
|
909
|
+
function mirrorResponsesToCore(view, systemText) {
|
|
910
|
+
const { msgs } = responsesToCore({
|
|
911
|
+
model: "prime-fold",
|
|
912
|
+
instructions: systemText,
|
|
913
|
+
input: mirrorResponsesInput(view)
|
|
914
|
+
});
|
|
915
|
+
return msgs;
|
|
916
|
+
}
|
|
725
917
|
export {
|
|
726
918
|
ClusterCounter,
|
|
727
919
|
WIRE_FORMATS,
|
|
@@ -742,10 +934,17 @@ export {
|
|
|
742
934
|
injectOpenaiSystem,
|
|
743
935
|
injectResponsesDeveloperMessage,
|
|
744
936
|
isWireFormat,
|
|
937
|
+
mirrorAnthropicMessages,
|
|
938
|
+
mirrorAnthropicToCore,
|
|
939
|
+
mirrorOpenaiMessages,
|
|
940
|
+
mirrorOpenaiToCore,
|
|
941
|
+
mirrorResponsesInput,
|
|
942
|
+
mirrorResponsesToCore,
|
|
745
943
|
openaiToCore,
|
|
746
944
|
parseDataUrl,
|
|
747
945
|
patchResponsesInput,
|
|
748
946
|
responsesToCore,
|
|
947
|
+
splitDemotedThinking,
|
|
749
948
|
subagentNamespace,
|
|
750
949
|
toCoreMessages
|
|
751
950
|
};
|
package/dist/wire/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/wire/util.ts","../../src/wire/message-id.ts","../../src/wire/anthropic.ts","../../src/wire/bili-message.ts","../../src/wire/openai.ts","../../src/wire/responses.ts","../../src/wire/formats.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\n/** SHA-256-derived short id — kept verbatim from the proxy so message ids\n * stay byte-identical across the extraction (re-keying would orphan every\n * downstream map keyed on these ids). */\nexport function hashId(s: string): string {\n return createHash(\"sha256\").update(s, \"utf8\").digest(\"hex\").slice(0, 16);\n}\n\n/** How a conversation's identity was derived (kept verbatim from the proxy's\n * session-id.ts — only the TYPE moves; session-key derivation stays in the\n * proxy, which owns multi-tenant state). */\nexport type ConversationIdentity = {\n value: string;\n source: \"header\" | \"body-session\" | \"metadata-session\" | \"previous-response\" | \"content-fingerprint\" | \"generated\";\n clientProvided: boolean;\n};\n","import { hashId } from \"./util.js\";\n\n/**\n * Derive a stable, content-based message id.\n *\n * PROBLEM: none of the three wire protocols (Anthropic Messages, OpenAI Chat\n * Completions, OpenAI Responses) attach a stable id to request-side message\n * items. Historically each converter used `raw-${idx}` — a *position* index,\n * not an identity. As soon as a client deletes/reorders messages (other plugins\n * summarizing away old turns, multi-agent setups, etc.) the index drifts:\n * downstream ids shift, so\n * - assignRefs reuses stale `byRaw` entries, hiding new messages, and\n * - compression `effectiveMessageIds` start pointing at the *wrong* messages,\n * silently swallowing live content under an unrelated summary.\n *\n * FIX: derive the id from a SHA-256 of the message identity:\n * role + contentType + toolCallId + toolName + text\n * Two messages with identical identity collide. To keep duplicates distinct\n * (and avoid `covered` sets collapsing unrelated turns onto one id) we append a\n * within-conversation *cluster index* `_N`: the Nth occurrence of the same\n * identity, counting from 0 in arrival order.\n *\n * Trade-off vs a real client id:\n * - deleting a duplicated message only disturbs the cluster of that identity\n * (local damage), never the whole downstream (global damage like position).\n * - fully distinct messages are completely immune to reordering/deletion.\n *\n * `idx` is passed purely to break ties *within a single conversion pass*; it is\n * not part of the identity, so two passes over the same content produce the\n * same cluster numbering (deterministic).\n */\nexport function deriveMessageId(\n role: string,\n contentType: string,\n text: string,\n options: {\n toolCallId?: string;\n toolName?: string;\n } = {},\n): string {\n const seed = `${role}|${contentType}|${options.toolCallId ?? \"\"}|${options.toolName ?? \"\"}|${text}`;\n return \"h_\" + hashId(seed);\n}\n\n/**\n * Stateful cluster counter. Each converter instantiates one per conversion\n * pass; it tracks how many times each base identity has been seen so that the\n * Nth duplicate gets a `_${N}` suffix.\n */\nexport class ClusterCounter {\n private counts = new Map<string, number>();\n\n next(baseId: string): string {\n const n = this.counts.get(baseId) ?? 0;\n this.counts.set(baseId, n + 1);\n return n === 0 ? baseId : `${baseId}_${n}`;\n }\n}\n","import type { BiliMessage } from \"./bili-message.js\";\nimport { hashId } from \"./util.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\n\nexport type AnthropicTextBlock = { type: \"text\"; text: string; cache_control?: unknown };\nexport type AnthropicToolUse = {\n type: \"tool_use\";\n id: string;\n name: string;\n input: unknown;\n cache_control?: unknown;\n};\nexport type AnthropicToolResult = {\n type: \"tool_result\";\n tool_use_id: string;\n content: string | AnthropicTextBlock[];\n is_error?: boolean;\n cache_control?: unknown;\n};\nexport type AnthropicImage = { type: \"image\"; source: unknown };\nexport type AnthropicThinking = { type: \"thinking\"; thinking: string; signature?: string };\nexport type AnthropicBlock =\n | AnthropicTextBlock\n | AnthropicToolUse\n | AnthropicToolResult\n | AnthropicImage\n | AnthropicThinking;\n\nexport type AnthropicMessage = {\n role: \"user\" | \"assistant\";\n content: string | AnthropicBlock[];\n};\n\nexport type AnthropicRequestBody = {\n model?: string;\n max_tokens?: number;\n system?: string | AnthropicTextBlock[];\n messages: AnthropicMessage[];\n tools?: unknown[];\n stream?: boolean;\n temperature?: number;\n [key: string]: unknown;\n};\n\n\nexport function extractSystem(system: AnthropicRequestBody[\"system\"]): string {\n if (!system) return \"\";\n if (typeof system === \"string\") return system;\n return system.map((b) => b.text).join(\"\\n\\n\");\n}\n\nexport function buildSystem(text: string, original: AnthropicRequestBody[\"system\"]): string | AnthropicTextBlock[] {\n if (Array.isArray(original) && original.length > 0) {\n const ccBlock = original.find((b) => b.cache_control);\n return [{ type: \"text\", text, ...(ccBlock ? { cache_control: ccBlock.cache_control } : {}) }];\n }\n return text;\n}\n\ntype Flat = { msgs: BiliMessage[]; cacheControls: Map<string, unknown> };\n\nexport function anthropicToCore(body: AnthropicRequestBody): Flat {\n const msgs: BiliMessage[] = [];\n const cacheControls = new Map<string, unknown>();\n const clusters = new ClusterCounter();\n for (const m of body.messages) {\n const blocks = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n for (const b of blocks) {\n switch (b.type) {\n case \"text\": {\n const base = deriveMessageId(m.role, \"text\", b.text);\n const id = clusters.next(base);\n msgs.push({ id, role: m.role, contentType: \"text\", text: b.text });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"tool_use\": {\n const base = deriveMessageId(\"assistant\", \"tool-call\", safeStringify(b.input), {\n toolCallId: b.id,\n toolName: b.name,\n });\n const id = clusters.next(base);\n msgs.push({\n id,\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: b.name,\n toolCallId: b.id,\n text: safeStringify(b.input),\n });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"tool_result\": {\n const text = typeof b.content === \"string\" ? b.content : b.content.map((c) => c.text).join(\"\\n\");\n const base = deriveMessageId(\"tool\", \"tool-result\", text, { toolCallId: b.tool_use_id });\n const id = clusters.next(base);\n msgs.push({\n id,\n role: \"tool\",\n contentType: \"tool-result\",\n toolCallId: b.tool_use_id,\n text,\n ...(b.is_error === true ? { toolIsError: true } : {}),\n });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"thinking\": {\n const base = deriveMessageId(\"assistant\", \"reasoning\", b.thinking);\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"reasoning\",\n text: b.thinking,\n ...(b.signature ? { thinkingSignature: b.signature } : {}),\n });\n break;\n }\n case \"image\": {\n const base = deriveMessageId(m.role, \"text\", \"[image]\");\n msgs.push({\n id: clusters.next(base),\n role: m.role,\n contentType: \"text\",\n text: \"[image]\",\n rawAnthropicBlock: b,\n });\n break;\n }\n }\n }\n }\n return { msgs, cacheControls };\n}\n\nexport function coreToAnthropic(messages: BiliMessage[], cacheControls?: Map<string, unknown>): AnthropicMessage[] {\n const out: AnthropicMessage[] = [];\n let current: { role: \"user\" | \"assistant\"; blocks: AnthropicBlock[] } | null = null;\n const flush = () => {\n if (current && current.blocks.length > 0) {\n out.push({ role: current.role, content: current.blocks });\n }\n current = null;\n };\n const cc = (id: string): { cache_control?: unknown } => {\n const v = cacheControls?.get(id);\n return v ? { cache_control: v } : {};\n };\n for (const m of messages) {\n const target: \"user\" | \"assistant\" =\n m.role === \"assistant\" ? \"assistant\" : \"user\";\n if (!current || current.role !== target) {\n flush();\n current = { role: target, blocks: [] };\n }\n switch (m.contentType) {\n case \"text\": {\n if (m.rawAnthropicBlock) {\n current.blocks.push(m.rawAnthropicBlock as AnthropicBlock);\n break;\n }\n current.blocks.push({ type: \"text\", text: m.text ?? \"\", ...cc(m.id) });\n break;\n }\n case \"tool-call\":\n current.blocks.push({\n type: \"tool_use\",\n id: m.toolCallId ?? `call_${m.id}`,\n name: m.toolName ?? \"unknown\",\n input: safeParse(m.text),\n ...cc(m.id),\n });\n break;\n case \"tool-result\":\n current.blocks.push({\n type: \"tool_result\",\n tool_use_id: m.toolCallId ?? \"\",\n content: m.text ?? \"\",\n ...(m.toolIsError ? { is_error: true } : {}),\n ...cc(m.id),\n });\n break;\n case \"reasoning\":\n current.blocks.push({\n type: \"thinking\",\n thinking: m.text ?? \"\",\n ...(m.thinkingSignature ? { signature: m.thinkingSignature } : {}),\n });\n break;\n }\n }\n flush();\n return out;\n}\n\n/** Extract the conversation dimension for Anthropic: a client-provided\n * session header if present, else a content fingerprint of the first user\n * message. The protocol+upstream+key dimensions are mixed in by the caller\n * (server.ts) via deriveSessionId() — this function contributes only the\n * conversation axis. */\nexport function conversationSignalAnthropic(body: AnthropicRequestBody, headerValue?: string): string {\n if (headerValue && headerValue.trim()) return headerValue.trim();\n const firstUser = body.messages.find((m) => m.role === \"user\");\n const seed = firstUser ? JSON.stringify(firstUser.content) : \"default\";\n return hashId(seed);\n}\n\nfunction safeStringify(v: unknown): string {\n try {\n return JSON.stringify(v ?? {});\n } catch {\n return \"{}\";\n }\n}\n\nfunction safeParse(s: string | undefined): unknown {\n if (!s) return {};\n try {\n return JSON.parse(s);\n } catch {\n return {};\n }\n}\n","/**\n * Lossless message bridge between protocol-specific message formats and the\n * kernel's CoreMessage.\n *\n * Problem: `anthropicToCore` / `openaiToCore` / `responsesToCore` flatten\n * rich protocol blocks (images, thinking signatures, tool_result.is_error,\n * developer-role messages, image_url) into plain `{ text }` placeholders.\n * The reverse `coreToX` then can't reconstruct them — `is_error` is lost\n * (upstream can't tell a tool error from a result), `thinking.signature` is\n * lost (Anthropic rejects thinking blocks without a matching signature),\n * images become \"[image]\" (the model never sees the picture).\n *\n * Solution: `BiliMessage` extends CoreMessage with optional sidecar fields.\n * The kernel only reads `{ ...message }` (spread copy) and known fields, so\n * the extra fields survive the compression pipeline unchanged and arrive back\n * at `coreToX`, which prefers them over the flattened `text`. No `as any`\n * needed — TypeScript array covariance lets `BiliMessage[]` satisfy a\n * `CoreMessage[]` parameter.\n */\n\nimport type { CoreMessage } from \"acp-kernel\";\n\n/** A message that carries its original protocol block(s) verbatim, so the\n * reverse conversion can reconstruct losslessly. Every field is optional —\n * plain text messages (the common case) have none set. */\nexport interface BiliMessage extends CoreMessage {\n /** Anthropic: the original content block for an image or a structured\n * tool_result. Restored verbatim by coreToAnthropic. */\n rawAnthropicBlock?: unknown;\n /** OpenAI chat: the original content part for an image_url, or the\n * original message object for a developer-role message. */\n rawOpenaiContent?: unknown;\n /** Responses API: the original input item (for input_image, or a raw\n * function_call / function_call_output we pass through). */\n rawResponsesItem?: unknown;\n /** Anthropic thinking signature. Anthropic verifies thinking+signature\n * pairs; without it the request is rejected. Stored alongside the\n * reasoning text so coreToAnthropic can reattach it. */\n thinkingSignature?: string;\n /** OpenAI reasoning_content (chain-of-thought from DeepSeek-R1, GLM-4.6\n * thinking, Qwen-QwQ). These models require reasoning_content be echoed\n * back on subsequent requests or the API returns HTTP 400; stored so\n * coreToOpenai can reattach it. */\n reasoningContent?: string;\n /** Anthropic tool_result.is_error. Marks the tool result as an error so\n * the model knows the tool failed (not just returned an error string). */\n toolIsError?: boolean;\n /** OpenAI: original role was \"developer\" (reconstructed as \"system\" by\n * openaiToCore for the kernel; coreToOpenai restores \"developer\"). */\n originalRole?: \"system\" | \"developer\";\n /** The original media type for an image (image/png, image/jpeg, image/gif,\n * image/webp). Lets coreToOpenai/coreToResponses rebuild image_url /\n * input_image with the right data URL. */\n imageMediaType?: string;\n /** The base64 data of an image (without the data: prefix). Lets the\n * reverse conversion rebuild the full image payload. */\n imageBase64?: string;\n /** OpenAI chat: ALL original image_url content parts (each a data: URL\n * part) for a user message carrying more than one image, in wire order.\n * coreToOpenai re-emits these verbatim (after the text part). The\n * singular `rawOpenaiContent` still covers the single-image case and\n * legacy persisted state. Typed as unknown[] (not OpenAIContentPart) to\n * avoid a circular import with the openai codec. */\n rawOpenaiContentParts?: unknown[];\n}\n\n/** Narrow a BiliMessage[] to CoreMessage[] for the kernel. The sidecar fields\n * are transparently carried along — the kernel's `{ ...msg }` copies them. */\nexport function toCoreMessages(msgs: BiliMessage[]): CoreMessage[] {\n return msgs as CoreMessage[];\n}\n\n/** Re-decode a base64 data URL into media type + data. Returns undefined if\n * the input is not a recognized data URL. Used by openaiToCore/responsesToCore\n * to split image_url/input_image into the sidecar fields. */\nexport function parseDataUrl(url: string): { mediaType: string; base64: string } | undefined {\n const m = /^data:([^;,]+)(?:;base64)?,(.+)$/i.exec(url);\n if (!m) return undefined;\n return { mediaType: m[1]!, base64: m[2]! };\n}\n","import { hashId } from \"./util.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\nimport { parseDataUrl, type BiliMessage } from \"./bili-message.js\";\n\nexport type OpenAIContentPart =\n | { type: \"text\"; text: string }\n | { type: \"image_url\"; image_url: { url: string } }\n | { type: string; [k: string]: unknown };\n\nexport type OpenAIToolCall = {\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n};\n\nexport type OpenAIMessage = {\n role: \"system\" | \"developer\" | \"user\" | \"assistant\" | \"tool\";\n content?: string | null | OpenAIContentPart[];\n reasoning_content?: string | null;\n tool_calls?: OpenAIToolCall[];\n tool_call_id?: string;\n name?: string;\n};\n\nexport type OpenAITool = {\n type: \"function\";\n function: { name: string; description?: string; parameters?: unknown };\n};\n\nexport type OpenAIRequestBody = {\n model?: string;\n messages: OpenAIMessage[];\n tools?: OpenAITool[];\n stream?: boolean;\n [key: string]: unknown;\n};\n\ntype Flat = { msgs: BiliMessage[] };\n\nexport function openaiToCore(body: OpenAIRequestBody): Flat {\n const msgs: BiliMessage[] = [];\n const clusters = new ClusterCounter();\n for (const m of body.messages) {\n switch (m.role) {\n case \"system\":\n case \"developer\": {\n const base = deriveMessageId(m.role, \"text\", stringContent(m.content));\n msgs.push({ id: clusters.next(base), role: \"system\", contentType: \"text\", text: stringContent(m.content), originalRole: m.role });\n break;\n }\n case \"user\": {\n const text = stringContent(m.content);\n const imgs = allImageParts(m.content);\n const firstImg = imgs[0];\n const firstUrl = firstImg ? firstImg.image_url.url : undefined;\n const firstParsed = firstUrl ? parseDataUrl(firstUrl) : undefined;\n const base = deriveMessageId(\"user\", \"text\", text);\n msgs.push({\n id: clusters.next(base),\n role: \"user\",\n contentType: \"text\",\n text,\n ...(imgs.length === 1 && firstParsed\n ? { rawOpenaiContent: imgs[0], imageMediaType: firstParsed.mediaType, imageBase64: firstParsed.base64 }\n : imgs.length > 1\n ? { rawOpenaiContentParts: imgs }\n : {}),\n });\n break;\n }\n case \"assistant\": {\n const reasoning = typeof m.reasoning_content === \"string\" ? m.reasoning_content : \"\";\n if (reasoning) {\n const base = deriveMessageId(\"assistant\", \"reasoning\", reasoning);\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"reasoning\",\n text: reasoning,\n reasoningContent: reasoning,\n });\n }\n const text = stringContent(m.content);\n if (text) {\n const base = deriveMessageId(\"assistant\", \"text\", text);\n msgs.push({ id: clusters.next(base), role: \"assistant\", contentType: \"text\", text });\n }\n if (Array.isArray(m.tool_calls)) {\n for (const tc of m.tool_calls) {\n const base = deriveMessageId(\"assistant\", \"tool-call\", tc.function.arguments ?? \"\", {\n toolCallId: tc.id,\n toolName: tc.function.name,\n });\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: tc.function.name,\n toolCallId: tc.id,\n text: tc.function.arguments ?? \"\",\n });\n }\n }\n break;\n }\n case \"tool\": {\n const base = deriveMessageId(\"tool\", \"tool-result\", stringContent(m.content), {\n toolCallId: m.tool_call_id ?? \"\",\n });\n msgs.push({\n id: clusters.next(base),\n role: \"tool\",\n contentType: \"tool-result\",\n toolCallId: m.tool_call_id ?? \"\",\n text: stringContent(m.content),\n });\n break;\n }\n }\n }\n return { msgs };\n}\n\nexport function coreToOpenai(messages: BiliMessage[]): OpenAIMessage[] {\n const out: OpenAIMessage[] = [];\n let pending: { text: string | null; toolCalls: OpenAIToolCall[]; reasoning: string | null } | null = null;\n const flush = () => {\n if (!pending) return;\n const reasoning = pending.reasoning !== null && pending.reasoning.length > 0 ? pending.reasoning : undefined;\n if (pending.toolCalls.length > 0) {\n out.push({\n role: \"assistant\",\n content: pending.text ?? null,\n tool_calls: pending.toolCalls,\n ...(reasoning ? { reasoning_content: reasoning } : {}),\n });\n } else if (pending.text !== null) {\n out.push({ role: \"assistant\", content: pending.text, ...(reasoning ? { reasoning_content: reasoning } : {}) });\n } else if (reasoning) {\n out.push({ role: \"assistant\", content: null, reasoning_content: reasoning });\n }\n pending = null;\n };\n for (const m of messages) {\n if (m.role === \"assistant\") {\n if (!pending) pending = { text: null, toolCalls: [], reasoning: null };\n if (m.contentType === \"reasoning\") {\n pending.reasoning = (pending.reasoning ?? \"\") + (m.reasoningContent ?? m.text ?? \"\");\n } else if (m.contentType === \"text\") {\n pending.text = (pending.text ?? \"\") + (m.text ?? \"\");\n } else if (m.contentType === \"tool-call\") {\n pending.toolCalls.push({\n id: m.toolCallId ?? `call_${m.id}`,\n type: \"function\",\n function: { name: m.toolName ?? \"unknown\", arguments: m.text ?? \"\" },\n });\n }\n } else {\n flush();\n if (m.role === \"system\") {\n out.push({ role: m.originalRole === \"developer\" ? \"developer\" : \"system\", content: m.text ?? \"\" });\n } else if (m.role === \"user\") {\n if (m.rawOpenaiContent || m.imageBase64 || m.rawOpenaiContentParts) {\n const parts: OpenAIContentPart[] = [];\n if (m.text) parts.push({ type: \"text\", text: m.text });\n if (m.rawOpenaiContentParts && m.rawOpenaiContentParts.length > 0) {\n for (const part of m.rawOpenaiContentParts) parts.push(part as OpenAIContentPart);\n } else if (m.rawOpenaiContent) {\n parts.push(m.rawOpenaiContent as OpenAIContentPart);\n } else if (m.imageBase64 && m.imageMediaType) {\n parts.push({ type: \"image_url\", image_url: { url: `data:${m.imageMediaType};base64,${m.imageBase64}` } });\n }\n out.push({ role: \"user\", content: parts });\n } else {\n out.push({ role: \"user\", content: m.text ?? \"\" });\n }\n } else if (m.role === \"tool\") {\n out.push({ role: \"tool\", tool_call_id: m.toolCallId ?? \"\", content: m.text ?? \"\" });\n }\n }\n }\n flush();\n return out;\n}\n\nexport function injectOpenaiSystem(messages: OpenAIMessage[], parts: string[]): OpenAIMessage[] {\n if (parts.length === 0) return messages;\n const extra = parts.join(\"\\n\\n\");\n if (messages.length > 0 && (messages[0]?.role === \"system\" || messages[0]?.role === \"developer\")) {\n const head = messages[0] as OpenAIMessage;\n const base = stringContent(head.content);\n const merged = base ? `${base}\\n\\n---\\n\\n${extra}` : extra;\n return [{ ...head, content: merged }, ...messages.slice(1)];\n }\n return [{ role: \"system\", content: extra }, ...messages];\n}\n\n/** Extract the conversation dimension for OpenAI Chat: a client-provided\n * session header if present, else a content fingerprint of the first user\n * message. See conversationSignalAnthropic for the full rationale. */\nexport function conversationSignalOpenai(body: OpenAIRequestBody, headerValue?: string): string {\n if (headerValue && headerValue.trim()) return headerValue.trim();\n const firstUser = body.messages.find((m) => m.role === \"user\");\n const seed = firstUser ? stringContent(firstUser.content) : \"default\";\n return hashId(seed);\n}\n\nfunction stringContent(content: OpenAIMessage[\"content\"]): string {\n if (content == null) return \"\";\n if (typeof content === \"string\") return content;\n if (Array.isArray(content)) {\n return content\n .map((p) => (typeof p === \"string\" ? p : p.type === \"text\" ? (p as { text?: string }).text ?? \"\" : \"\"))\n .join(\"\\n\");\n }\n return \"\";\n}\n\ntype OpenAIImagePart = { type: \"image_url\"; image_url: { url: string } };\n\n/** Collect ALL data-URL image parts in a user content array, in wire order.\n * (firstImagePart only kept the first, which silently dropped images 2..N\n * on the coreToOpenai rebuild.) */\nfunction allImageParts(content: OpenAIMessage[\"content\"]): OpenAIImagePart[] {\n if (!Array.isArray(content)) return [];\n const out: OpenAIImagePart[] = [];\n for (const p of content) {\n if (typeof p !== \"object\" || p === null) continue;\n if (!(\"type\" in p) || p.type !== \"image_url\" || !(\"image_url\" in p)) continue;\n // The union's index-signature member leaves image_url as `unknown`, so\n // narrow via a named const before reading the url.\n const imagePart = p as { image_url: { url?: unknown } };\n const url = imagePart.image_url.url;\n if (typeof url === \"string\" && parseDataUrl(url)) out.push(p as OpenAIImagePart);\n }\n return out;\n}\n","import type { CoreMessage } from \"../types.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\nimport type { ConversationIdentity } from \"./util.js\";\nimport { hashId } from \"./util.js\";\nimport { parseDataUrl, type BiliMessage } from \"./bili-message.js\";\n\nexport type ResponseContentPart =\n | { type: \"input_text\"; text: string; [key: string]: unknown }\n | { type: \"output_text\"; text: string; [key: string]: unknown }\n | { type: \"input_image\"; image_url: string; [key: string]: unknown }\n | { type: string; [key: string]: unknown };\n\nexport type ResponseInputMessage = {\n type: \"message\";\n role: \"system\" | \"developer\" | \"user\" | \"assistant\";\n content: string | ResponseContentPart[];\n [key: string]: unknown;\n};\n\nexport type ResponseFunctionCall = {\n type: \"function_call\";\n id?: string;\n call_id: string;\n name: string;\n arguments: string;\n [key: string]: unknown;\n};\n\nexport type ResponseFunctionCallOutput = {\n type: \"function_call_output\";\n call_id: string;\n output: string;\n [key: string]: unknown;\n};\n\nexport type ResponseInputItem =\n | ResponseInputMessage\n | ResponseFunctionCall\n | ResponseFunctionCallOutput\n | { type: string; [key: string]: unknown };\n\nexport type ResponsesRequestBody = {\n model?: string;\n input: string | ResponseInputItem[];\n instructions?: string;\n tools?: unknown[];\n stream?: boolean;\n session_id?: string;\n previous_response_id?: string;\n prompt_cache_key?: string;\n metadata?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype ResponseLayoutSlot = {\n original: ResponseInputItem;\n coreId?: string;\n};\n\nexport type ResponsesProjection = {\n msgs: BiliMessage[];\n systemParts: string[];\n preamble: ResponseInputItem[];\n customToolCallIds: Set<string>;\n layout: ResponseLayoutSlot[];\n stringInput?: { original: string; coreId: string };\n /** Reasoning items dropped because ACP_REASONING_KEEP=none. 0 by default —\n * reasoning is normally routed through the compression pipeline so it is\n * hidden automatically once its turn is summarized. */\n droppedReasoning: number;\n};\n\n/** Item types that are host DIRECTIVES (tool/definition listings), not\n * conversation history: preserved verbatim and re-prepended at input[0..].\n * `additional_tools` carries the Codex code_mode exec/wait tool definitions\n * and MUST stay at input[0]. `mcp_list_tools` is a stable per-session listing.\n *\n * Only definitions belong here. Output/action items from a prior response\n * (reasoning, computer_call, function_call, mcp_call, ...) ARE conversation\n * history and are routed as tracked BiliMessages, so the compression pipeline\n * hides them once their turn is summarized — preserving them verbatim in the\n * preamble instead made them accumulate unbounded every turn and broke Codex's\n * prompt-cache prefix. */\nconst OPAQUE_ITEM_TYPES = new Set([\n \"additional_tools\",\n \"mcp_list_tools\",\n]);\n\nfunction isOpaqueItem(item: ResponseInputItem): boolean {\n return OPAQUE_ITEM_TYPES.has(item.type);\n}\n\nfunction shouldDropAllReasoning(): boolean {\n return (process.env.ACP_REASONING_KEEP ?? \"\").trim().toLowerCase() === \"none\";\n}\n\nfunction partText(part: ResponseContentPart): string {\n if (part.type === \"input_text\" || part.type === \"output_text\") {\n return typeof part.text === \"string\" ? part.text : \"\";\n }\n return \"\";\n}\n\nfunction messageContent(content: string | ResponseContentPart[]): string {\n return typeof content === \"string\" ? content : content.map(partText).join(\"\\n\");\n}\n\n/** Extract the reasoning text from a responses reasoning item. The host\n * carries it in `content` (reasoning_text parts); the primeFold mirror\n * carries it in `summary` (summary_text parts). Both must yield the same\n * text so the kernel derives the same core id (issue #64, responses). */\nfunction reasoningText(item: ResponseInputItem): string {\n const fromParts = (parts: unknown, type: string): string => {\n if (!Array.isArray(parts)) return \"\";\n const texts: string[] = [];\n for (const part of parts) {\n if (part && typeof part === \"object\" && \"type\" in part && \"text\" in part) {\n const rec = part as { type: unknown; text: unknown };\n if (rec.type === type && typeof rec.text === \"string\") texts.push(rec.text);\n }\n }\n return texts.join(\"\\n\");\n };\n const content = \"content\" in item ? item.content : undefined;\n const summary = \"summary\" in item ? item.summary : undefined;\n return fromParts(content, \"reasoning_text\") || fromParts(summary, \"summary_text\");\n}\n\nexport function responsesToCore(body: ResponsesRequestBody): ResponsesProjection {\n const msgs: BiliMessage[] = [];\n const systemParts: string[] = [];\n const preamble: ResponseInputItem[] = [];\n const customToolCallIds = new Set<string>();\n const layout: ResponseLayoutSlot[] = [];\n let droppedReasoning = 0;\n const clusters = new ClusterCounter();\n let idx = 0;\n if (typeof body.instructions === \"string\" && body.instructions.trim()) systemParts.push(body.instructions);\n if (typeof body.input === \"string\") {\n const id = clusters.next(deriveMessageId(\"user\", \"text\", body.input));\n msgs.push({ id, role: \"user\", contentType: \"text\", text: body.input });\n return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning, stringInput: { original: body.input, coreId: id } };\n }\n for (const item of body.input) {\n let coreId: string | undefined;\n if (isOpaqueItem(item)) preamble.push(item);\n switch (item.type) {\n case \"reasoning\": {\n if (shouldDropAllReasoning()) {\n droppedReasoning++;\n continue;\n }\n // Key the reasoning piece on its TEXT (deterministic), consistent\n // with the anthropic/openai codecs. The host mints a per-request\n // item id that the primeFold mirror cannot reproduce; keying on it\n // put the mirror in a different ref/fingerprint space, so restart\n // replay rejected every in-stream compress call (issue #64,\n // responses variant).\n const text = reasoningText(item);\n const rid =\n text.length > 0\n ? text\n : \"id\" in item && typeof item.id === \"string\"\n ? item.id\n : hashId(JSON.stringify(item));\n coreId = clusters.next(deriveMessageId(\"assistant\", \"reasoning\", rid));\n msgs.push({\n id: coreId,\n role: \"assistant\",\n contentType: \"reasoning\",\n text: rid,\n rawResponsesItem: item,\n });\n break;\n }\n case \"message\": {\n const message = item as ResponseInputMessage;\n const text = messageContent(message.content);\n if (message.role === \"system\" || message.role === \"developer\") {\n systemParts.push(text);\n idx++;\n continue;\n } else if (message.role === \"user\" || (message.role === \"assistant\" && text)) {\n const role = message.role;\n coreId = clusters.next(deriveMessageId(role, \"text\", text));\n const imageUrl = Array.isArray(message.content)\n ? message.content.find((part) => part.type === \"input_image\" && typeof part.image_url === \"string\")?.image_url\n : undefined;\n const image = typeof imageUrl === \"string\" ? parseDataUrl(imageUrl) : undefined;\n msgs.push({\n id: coreId,\n role,\n contentType: \"text\",\n text,\n rawResponsesItem: item,\n ...(image ? { imageMediaType: image.mediaType, imageBase64: image.base64 } : {}),\n });\n }\n break;\n }\n case \"function_call\": {\n const call = item as ResponseFunctionCall;\n coreId = clusters.next(deriveMessageId(\"assistant\", \"tool-call\", call.arguments ?? \"\", {\n toolCallId: call.call_id,\n toolName: call.name,\n }));\n msgs.push({\n id: coreId,\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: call.name,\n toolCallId: call.call_id,\n text: call.arguments ?? \"\",\n rawResponsesItem: item,\n });\n break;\n }\n case \"function_call_output\": {\n const output = item as ResponseFunctionCallOutput;\n const text = typeof output.output === \"string\" ? output.output : JSON.stringify(output.output);\n coreId = clusters.next(deriveMessageId(\"tool\", \"tool-result\", text, { toolCallId: output.call_id }));\n msgs.push({ id: coreId, role: \"tool\", contentType: \"tool-result\", toolCallId: output.call_id, text, rawResponsesItem: item });\n break;\n }\n case \"computer_call\":\n case \"computer_call_output\":\n case \"file_search_call\":\n case \"web_search_call\":\n case \"image_generation_call\":\n case \"code_interpreter_call\":\n case \"mcp_call\": {\n const rid =\n typeof (item as { id?: unknown }).id === \"string\"\n ? String((item as { id?: string }).id)\n : hashId(JSON.stringify(item));\n coreId = clusters.next(deriveMessageId(\"assistant\", \"responses-call\", rid));\n msgs.push({ id: coreId, role: \"assistant\", contentType: \"reasoning\", text: rid, rawResponsesItem: item });\n break;\n }\n case \"custom_tool_call\": {\n const ctc = item as { call_id?: string; name?: string; input?: string; arguments?: string };\n const callId = ctc.call_id ?? `call_${idx}`;\n customToolCallIds.add(callId);\n const argText = ctc.input ?? ctc.arguments ?? \"\";\n coreId = clusters.next(deriveMessageId(\"assistant\", \"tool-call\", argText, { toolCallId: callId, toolName: ctc.name ?? \"custom\" }));\n msgs.push({ id: coreId, role: \"assistant\", contentType: \"tool-call\", toolName: ctc.name ?? \"custom\", toolCallId: callId, text: argText, rawResponsesItem: item });\n break;\n }\n case \"custom_tool_call_output\": {\n const ctco = item as { call_id?: string; output?: string };\n const callId = ctco.call_id ?? `call_${idx}`;\n customToolCallIds.add(callId);\n const outText = typeof ctco.output === \"string\" ? ctco.output : JSON.stringify(ctco.output ?? \"\");\n coreId = clusters.next(deriveMessageId(\"tool\", \"tool-result\", outText, { toolCallId: callId }));\n msgs.push({ id: coreId, role: \"tool\", contentType: \"tool-result\", toolCallId: callId, text: outText, rawResponsesItem: item });\n break;\n }\n default:\n if (!isOpaqueItem(item)) preamble.push(item);\n break;\n }\n layout.push({ original: item, coreId });\n idx++;\n }\n return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning };\n}\n\nfunction patchTextParts(parts: ResponseContentPart[], text: string): ResponseContentPart[] {\n const textIndexes = parts.flatMap((part, index) =>\n part.type === \"input_text\" || part.type === \"output_text\" ? [index] : [],\n );\n if (textIndexes.length === 0) return [{ type: \"input_text\", text }, ...parts];\n const first = textIndexes[0];\n const remaining = new Set(textIndexes.slice(1));\n return parts.map((part, index) => {\n if (index === first) return { ...part, text };\n if (remaining.has(index)) return { ...part, text: \"\" };\n return part;\n });\n}\n\nfunction patchOriginalItem(original: ResponseInputItem, source: CoreMessage, next: CoreMessage): ResponseInputItem {\n if (\n source.text === next.text &&\n source.toolName === next.toolName &&\n source.toolCallId === next.toolCallId &&\n source.role === next.role &&\n source.contentType === next.contentType\n ) return original;\n if (original.type === \"message\") {\n const message = original as ResponseInputMessage;\n const content = typeof message.content === \"string\" ? next.text ?? \"\" : patchTextParts(message.content, next.text ?? \"\");\n return { ...message, content };\n }\n if (original.type === \"function_call\") {\n return {\n ...original,\n name: next.toolName ?? String(original.name ?? \"unknown\"),\n call_id: next.toolCallId ?? String(original.call_id ?? \"\"),\n arguments: next.text ?? \"\",\n };\n }\n if (original.type === \"function_call_output\") {\n return { ...original, call_id: next.toolCallId ?? String(original.call_id ?? \"\"), output: next.text ?? \"\" };\n }\n return original;\n}\n\nexport function patchResponsesInput(projection: ResponsesProjection, messages: CoreMessage[]): string | ResponseInputItem[] {\n if (projection.stringInput) {\n const original = projection.msgs.find((message) => message.id === projection.stringInput?.coreId);\n const next = messages.find((message) => message.id === projection.stringInput?.coreId);\n if (original && next && messages.length === 1 && next.role === \"user\" && next.contentType === \"text\") {\n return next.text === original.text ? projection.stringInput.original : next.text ?? \"\";\n }\n return coreToResponses(messages, projection.customToolCallIds);\n }\n const sourceById = new Map(projection.msgs.map((message) => [message.id, message]));\n const nextById = new Map(messages.map((message) => [message.id, message]));\n const slotById = new Map<string, number>();\n projection.layout.forEach((slot, index) => {\n if (slot.coreId) slotById.set(slot.coreId, index);\n });\n const insertions = new Map<number, ResponseInputItem[]>();\n for (let index = 0; index < messages.length; index++) {\n const message = messages[index]!;\n if (sourceById.has(message.id)) continue;\n let target = projection.layout.length;\n for (let nextIndex = index + 1; nextIndex < messages.length; nextIndex++) {\n const slot = slotById.get(messages[nextIndex]!.id);\n if (slot !== undefined) {\n target = slot;\n break;\n }\n }\n const generated = coreToResponses([message], projection.customToolCallIds);\n if (generated.length > 0) insertions.set(target, [...(insertions.get(target) ?? []), ...generated]);\n }\n const out: ResponseInputItem[] = [];\n projection.layout.forEach((slot, index) => {\n out.push(...(insertions.get(index) ?? []));\n if (!slot.coreId) {\n out.push(slot.original);\n return;\n }\n const source = sourceById.get(slot.coreId);\n const next = nextById.get(slot.coreId);\n if (source && next) out.push(patchOriginalItem(slot.original, source, next));\n });\n out.push(...(insertions.get(projection.layout.length) ?? []));\n return out;\n}\n\nexport function coreToResponses(\n messages: CoreMessage[],\n customToolCallIds: Set<string> = new Set(),\n): ResponseInputItem[] {\n const out: ResponseInputItem[] = [];\n for (const message of messages) {\n const biliMessage = message as BiliMessage;\n const raw = biliMessage.rawResponsesItem as ResponseInputItem | undefined;\n if (message.role === \"system\") {\n out.push({ type: \"message\", role: \"developer\", content: message.text ?? \"\" });\n } else if (message.role === \"user\") {\n if (raw?.type === \"message\" && messageContent((raw as ResponseInputMessage).content) === (message.text ?? \"\")) out.push(raw);\n else out.push({ type: \"message\", role: \"user\", content: message.text ?? \"\" });\n } else if (message.role === \"assistant\") {\n if (message.contentType === \"text\") {\n out.push({ type: \"message\", role: \"assistant\", content: message.text ?? \"\" });\n } else if (message.contentType === \"tool-call\") {\n const callId = message.toolCallId ?? `call_${message.id}`;\n if (customToolCallIds.has(callId)) {\n out.push({ type: \"custom_tool_call\", call_id: callId, name: message.toolName ?? \"unknown\", input: message.text ?? \"\", status: \"completed\" } as ResponseInputItem);\n } else {\n out.push({ type: \"function_call\", call_id: callId, name: message.toolName ?? \"unknown\", arguments: message.text ?? \"\" });\n }\n } else if (message.contentType === \"reasoning\") {\n if (raw) out.push(raw);\n }\n } else if (message.role === \"tool\") {\n const callId = message.toolCallId ?? \"\";\n if (customToolCallIds.has(callId)) {\n out.push({ type: \"custom_tool_call_output\", call_id: callId, output: message.text ?? \"\" } as ResponseInputItem);\n } else {\n out.push({ type: \"function_call_output\", call_id: callId, output: message.text ?? \"\" });\n }\n }\n }\n return out;\n}\n\nexport function injectResponsesDeveloperMessage(\n input: string | ResponseInputItem[],\n content: string,\n): ResponseInputItem[] {\n const items: ResponseInputItem[] = typeof input === \"string\"\n ? [{ type: \"message\", role: \"user\", content: input }]\n : [...input];\n let index = 0;\n while (items[index]?.type === \"additional_tools\") index++;\n items.splice(index, 0, { type: \"message\", role: \"developer\", content });\n return items;\n}\n\nexport function conversationIdentityResponses(\n body: ResponsesRequestBody,\n headerValue?: string,\n): ConversationIdentity {\n if (headerValue?.trim()) return { value: headerValue.trim(), source: \"header\", clientProvided: true };\n if (typeof body.session_id === \"string\" && body.session_id.trim()) {\n return { value: body.session_id.trim(), source: \"body-session\", clientProvided: true };\n }\n const metadataSession = body.metadata?.session_id;\n if (typeof metadataSession === \"string\" && metadataSession.trim()) {\n return { value: metadataSession.trim(), source: \"metadata-session\", clientProvided: true };\n }\n if (typeof body.previous_response_id === \"string\" && body.previous_response_id.trim()) {\n return { value: body.previous_response_id.trim(), source: \"previous-response\", clientProvided: false };\n }\n return { value: hashId(JSON.stringify(body.input ?? [])), source: \"content-fingerprint\", clientProvided: false };\n}\n\nexport function conversationSignalResponses(body: ResponsesRequestBody, headerValue?: string): string {\n return conversationIdentityResponses(body, headerValue).value;\n}\n\n// Codex subagents (guardian approval reviewer, etc.) reuse the main\n// conversation's body.session_id, so identity alone collapses their requests\n// onto the main session's compression state — a compressed subagent request\n// loses the verbatim user authorization it must read back (#150). Subagent\n// requests carry their own `instructions` (the agent's role prompt), so the\n// FIRST instructions seen for an identity anchor the main namespace (it never\n// changes for the conversation, even if the main prompt drifts), and any other\n// instructions value maps to a separate `|sub:` namespace with its own empty\n// compression state. Subagent requests are self-contained replays, so the\n// fresh namespace is lossless.\nexport interface SubagentNamespaces {\n /** Resolve the compression-state namespace for a request: the identity\n * itself for the anchored (main) instructions, `identity|sub:<fp>` for\n * any other instructions value. First-seen instructions anchor. */\n namespaceFor(identityValue: string, instructions: unknown): string;\n}\n\n/** Host-owned subagent-namespace store.\n *\n * The anchor map is per-conversation mutable state, so it belongs to the\n * host — NOT to a library module global. Create one instance and keep it for\n * the process lifetime (or persist it alongside your session store if you\n * need namespaces to survive restarts: a fresh instance re-anchors on the\n * first request it sees, which after a restart may be a subagent request,\n * orphaning the main conversation's stored compression state). */\nexport function createSubagentNamespaces(): SubagentNamespaces {\n const anchors = new Map<string, string>();\n return {\n namespaceFor(identityValue: string, instructions: unknown): string {\n if (typeof instructions !== \"string\" || instructions.trim().length === 0) return identityValue;\n const fp = hashId(instructions);\n const anchor = anchors.get(identityValue);\n if (anchor === undefined) {\n anchors.set(identityValue, fp);\n return identityValue;\n }\n return anchor === fp ? identityValue : `${identityValue}|sub:${fp}`;\n },\n };\n}\n\n// Convenience singleton for single-process proxies that don't manage\n// per-session state themselves. Hosts needing isolation between\n// conversations, deterministic namespaces across restarts, or a bound on\n// anchor memory should create their own instance via\n// createSubagentNamespaces() and own its lifecycle.\nconst defaultNamespaces = createSubagentNamespaces();\n\nexport function subagentNamespace(identityValue: string, instructions: unknown): string {\n return defaultNamespaces.namespaceFor(identityValue, instructions);\n}\n","export const WIRE_FORMATS = [\"anthropic\", \"openai\", \"responses\"] as const;\nexport type WireFormat = (typeof WIRE_FORMATS)[number];\n\nexport function isWireFormat(value: unknown): value is WireFormat {\n return (\n typeof value === \"string\" &&\n (WIRE_FORMATS as readonly string[]).includes(value)\n );\n}\n\n/**\n * Classify a provider request body by the codec that can parse it.\n * Returns undefined when no codec handles the body — the caller must\n * pass such payloads through untransformed.\n */\nexport function detectWireFormat(payload: unknown): WireFormat | undefined {\n if (payload === null || typeof payload !== \"object\") return undefined;\n const p = payload as Record<string, unknown>;\n if (Array.isArray(p.input)) return \"responses\";\n const messages = p.messages;\n if (!Array.isArray(messages)) return undefined;\n if (\"system\" in p || \"anthropic_version\" in p) return \"anthropic\";\n for (const m of messages as Array<Record<string, unknown>>) {\n if (m === null || typeof m !== \"object\") continue;\n const c = m.content;\n if (Array.isArray(c)) {\n for (const b of c as Array<Record<string, unknown>>) {\n if (b && typeof b === \"object\" && typeof b.type === \"string\") {\n if (\n b.type === \"tool_use\" ||\n b.type === \"tool_result\" ||\n b.type === \"thinking\"\n )\n return \"anthropic\";\n if (b.type === \"text\" && \"cache_control\" in b) return \"anthropic\";\n }\n }\n }\n if (Array.isArray(m.tool_calls)) return \"openai\";\n if (m.role === \"tool\" && typeof m.tool_call_id === \"string\")\n return \"openai\";\n if (m.role === \"system\" || m.role === \"developer\") return \"openai\";\n }\n // Both chat formats share role+messages; default to openai — the safer\n // guess for OpenAI-compatible endpoints (GLM, DeepSeek, vLLM).\n return \"openai\";\n}\n"],"m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BAAmB,EAAG,QAAO;AAAA,QACxD;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,QAAQ,EAAE,UAAU,EAAG,QAAO;AACxC,QAAI,EAAE,SAAS,UAAU,OAAO,EAAE,iBAAiB;AACjD,aAAO;AACT,QAAI,EAAE,SAAS,YAAY,EAAE,SAAS,YAAa,QAAO;AAAA,EAC5D;AAGA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/wire/util.ts","../../src/wire/message-id.ts","../../src/wire/anthropic.ts","../../src/wire/demoted-thinking.ts","../../src/wire/bili-message.ts","../../src/wire/openai.ts","../../src/wire/responses.ts","../../src/wire/formats.ts","../../src/wire/mirror.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\n/** SHA-256-derived short id — kept verbatim from the proxy so message ids\n * stay byte-identical across the extraction (re-keying would orphan every\n * downstream map keyed on these ids). */\nexport function hashId(s: string): string {\n return createHash(\"sha256\").update(s, \"utf8\").digest(\"hex\").slice(0, 16);\n}\n\n/** How a conversation's identity was derived (kept verbatim from the proxy's\n * session-id.ts — only the TYPE moves; session-key derivation stays in the\n * proxy, which owns multi-tenant state). */\nexport type ConversationIdentity = {\n value: string;\n source: \"header\" | \"body-session\" | \"metadata-session\" | \"previous-response\" | \"content-fingerprint\" | \"generated\";\n clientProvided: boolean;\n};\n","import { hashId } from \"./util.js\";\n\n/**\n * Derive a stable, content-based message id.\n *\n * PROBLEM: none of the three wire protocols (Anthropic Messages, OpenAI Chat\n * Completions, OpenAI Responses) attach a stable id to request-side message\n * items. Historically each converter used `raw-${idx}` — a *position* index,\n * not an identity. As soon as a client deletes/reorders messages (other plugins\n * summarizing away old turns, multi-agent setups, etc.) the index drifts:\n * downstream ids shift, so\n * - assignRefs reuses stale `byRaw` entries, hiding new messages, and\n * - compression `effectiveMessageIds` start pointing at the *wrong* messages,\n * silently swallowing live content under an unrelated summary.\n *\n * FIX: derive the id from a SHA-256 of the message identity:\n * role + contentType + toolCallId + toolName + text\n * Two messages with identical identity collide. To keep duplicates distinct\n * (and avoid `covered` sets collapsing unrelated turns onto one id) we append a\n * within-conversation *cluster index* `_N`: the Nth occurrence of the same\n * identity, counting from 0 in arrival order.\n *\n * Trade-off vs a real client id:\n * - deleting a duplicated message only disturbs the cluster of that identity\n * (local damage), never the whole downstream (global damage like position).\n * - fully distinct messages are completely immune to reordering/deletion.\n *\n * `idx` is passed purely to break ties *within a single conversion pass*; it is\n * not part of the identity, so two passes over the same content produce the\n * same cluster numbering (deterministic).\n */\nexport function deriveMessageId(\n role: string,\n contentType: string,\n text: string,\n options: {\n toolCallId?: string;\n toolName?: string;\n } = {},\n): string {\n const seed = `${role}|${contentType}|${options.toolCallId ?? \"\"}|${options.toolName ?? \"\"}|${text}`;\n return \"h_\" + hashId(seed);\n}\n\n/**\n * Stateful cluster counter. Each converter instantiates one per conversion\n * pass; it tracks how many times each base identity has been seen so that the\n * Nth duplicate gets a `_${N}` suffix.\n */\nexport class ClusterCounter {\n private counts = new Map<string, number>();\n\n next(baseId: string): string {\n const n = this.counts.get(baseId) ?? 0;\n this.counts.set(baseId, n + 1);\n return n === 0 ? baseId : `${baseId}_${n}`;\n }\n}\n","import type { BiliMessage } from \"./bili-message.js\";\nimport { hashId } from \"./util.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\n\nexport type AnthropicTextBlock = { type: \"text\"; text: string; cache_control?: unknown };\nexport type AnthropicToolUse = {\n type: \"tool_use\";\n id: string;\n name: string;\n input: unknown;\n cache_control?: unknown;\n};\nexport type AnthropicToolResult = {\n type: \"tool_result\";\n tool_use_id: string;\n content: string | AnthropicTextBlock[];\n is_error?: boolean;\n cache_control?: unknown;\n};\nexport type AnthropicImage = { type: \"image\"; source: unknown };\nexport type AnthropicThinking = { type: \"thinking\"; thinking: string; signature?: string };\nexport type AnthropicBlock =\n | AnthropicTextBlock\n | AnthropicToolUse\n | AnthropicToolResult\n | AnthropicImage\n | AnthropicThinking;\n\nexport type AnthropicMessage = {\n role: \"user\" | \"assistant\";\n content: string | AnthropicBlock[];\n};\n\nexport type AnthropicRequestBody = {\n model?: string;\n max_tokens?: number;\n system?: string | AnthropicTextBlock[];\n messages: AnthropicMessage[];\n tools?: unknown[];\n stream?: boolean;\n temperature?: number;\n [key: string]: unknown;\n};\n\n\nexport function extractSystem(system: AnthropicRequestBody[\"system\"]): string {\n if (!system) return \"\";\n if (typeof system === \"string\") return system;\n return system.map((b) => b.text).join(\"\\n\\n\");\n}\n\nexport function buildSystem(text: string, original: AnthropicRequestBody[\"system\"]): string | AnthropicTextBlock[] {\n if (Array.isArray(original) && original.length > 0) {\n const ccBlock = original.find((b) => b.cache_control);\n return [{ type: \"text\", text, ...(ccBlock ? { cache_control: ccBlock.cache_control } : {}) }];\n }\n return text;\n}\n\ntype Flat = { msgs: BiliMessage[]; cacheControls: Map<string, unknown> };\n\nexport function anthropicToCore(body: AnthropicRequestBody): Flat {\n const msgs: BiliMessage[] = [];\n const cacheControls = new Map<string, unknown>();\n const clusters = new ClusterCounter();\n for (const m of body.messages) {\n const blocks = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n for (const b of blocks) {\n switch (b.type) {\n case \"text\": {\n const base = deriveMessageId(m.role, \"text\", b.text);\n const id = clusters.next(base);\n msgs.push({ id, role: m.role, contentType: \"text\", text: b.text });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"tool_use\": {\n const base = deriveMessageId(\"assistant\", \"tool-call\", safeStringify(b.input), {\n toolCallId: b.id,\n toolName: b.name,\n });\n const id = clusters.next(base);\n msgs.push({\n id,\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: b.name,\n toolCallId: b.id,\n text: safeStringify(b.input),\n });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"tool_result\": {\n const text = typeof b.content === \"string\" ? b.content : b.content.map((c) => c.text).join(\"\\n\");\n const base = deriveMessageId(\"tool\", \"tool-result\", text, { toolCallId: b.tool_use_id });\n const id = clusters.next(base);\n msgs.push({\n id,\n role: \"tool\",\n contentType: \"tool-result\",\n toolCallId: b.tool_use_id,\n text,\n ...(b.is_error === true ? { toolIsError: true } : {}),\n });\n if (b.cache_control) cacheControls.set(id, b.cache_control);\n break;\n }\n case \"thinking\": {\n const base = deriveMessageId(\"assistant\", \"reasoning\", b.thinking);\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"reasoning\",\n text: b.thinking,\n ...(b.signature ? { thinkingSignature: b.signature } : {}),\n });\n break;\n }\n case \"image\": {\n const base = deriveMessageId(m.role, \"text\", \"[image]\");\n msgs.push({\n id: clusters.next(base),\n role: m.role,\n contentType: \"text\",\n text: \"[image]\",\n rawAnthropicBlock: b,\n });\n break;\n }\n }\n }\n }\n return { msgs, cacheControls };\n}\n\nexport function coreToAnthropic(messages: BiliMessage[], cacheControls?: Map<string, unknown>): AnthropicMessage[] {\n const out: AnthropicMessage[] = [];\n let current: { role: \"user\" | \"assistant\"; blocks: AnthropicBlock[] } | null = null;\n const flush = () => {\n if (current && current.blocks.length > 0) {\n out.push({ role: current.role, content: current.blocks });\n }\n current = null;\n };\n const cc = (id: string): { cache_control?: unknown } => {\n const v = cacheControls?.get(id);\n return v ? { cache_control: v } : {};\n };\n for (const m of messages) {\n const target: \"user\" | \"assistant\" =\n m.role === \"assistant\" ? \"assistant\" : \"user\";\n if (!current || current.role !== target) {\n flush();\n current = { role: target, blocks: [] };\n }\n switch (m.contentType) {\n case \"text\": {\n if (m.rawAnthropicBlock) {\n current.blocks.push(m.rawAnthropicBlock as AnthropicBlock);\n break;\n }\n current.blocks.push({ type: \"text\", text: m.text ?? \"\", ...cc(m.id) });\n break;\n }\n case \"tool-call\":\n current.blocks.push({\n type: \"tool_use\",\n id: m.toolCallId ?? `call_${m.id}`,\n name: m.toolName ?? \"unknown\",\n input: safeParse(m.text),\n ...cc(m.id),\n });\n break;\n case \"tool-result\":\n current.blocks.push({\n type: \"tool_result\",\n tool_use_id: m.toolCallId ?? \"\",\n content: m.text ?? \"\",\n ...(m.toolIsError ? { is_error: true } : {}),\n ...cc(m.id),\n });\n break;\n case \"reasoning\":\n current.blocks.push({\n type: \"thinking\",\n thinking: m.text ?? \"\",\n ...(m.thinkingSignature ? { signature: m.thinkingSignature } : {}),\n });\n break;\n }\n }\n flush();\n return out;\n}\n\n/** Extract the conversation dimension for Anthropic: a client-provided\n * session header if present, else a content fingerprint of the first user\n * message. The protocol+upstream+key dimensions are mixed in by the caller\n * (server.ts) via deriveSessionId() — this function contributes only the\n * conversation axis. */\nexport function conversationSignalAnthropic(body: AnthropicRequestBody, headerValue?: string): string {\n if (headerValue && headerValue.trim()) return headerValue.trim();\n const firstUser = body.messages.find((m) => m.role === \"user\");\n const seed = firstUser ? JSON.stringify(firstUser.content) : \"default\";\n return hashId(seed);\n}\n\nfunction safeStringify(v: unknown): string {\n try {\n return JSON.stringify(v ?? {});\n } catch {\n return \"{}\";\n }\n}\n\nfunction safeParse(s: string | undefined): unknown {\n if (!s) return {};\n try {\n return JSON.parse(s);\n } catch {\n return {};\n }\n}\n","/** Inline \"demoted thinking\" normalization.\n *\n * Hosts that cannot replay prior-turn reasoning as a structured block\n * (pi-ai transform-messages demotion on model switch, openai-completions\n * `requiresThinkingAsText` profiles, gateways that inline native\n * reasoning) fold it INTO the assistant content string wrapped in a\n * dialect tag:\n *\n * glm / deepseek / kimi / qwen3 / hermes : <think>\\n{text}\\n</think>\n * anthropic / minimax / xml : <thinking>\\n{text}\\n</thinking>\n * gemini : ```thinking\\n{text}\\n```\n *\n * followed by a single \"\\n\" glue before the next content block. The same\n * logical turn can therefore arrive as a `reasoning_content` field (or a\n * separate reasoning item on /v1/responses) OR as this inline form. If the\n * wire codecs kept both as one text blob, the two serializations of one\n * turn would land in DIFFERENT core-id/fingerprint spaces — exactly the\n * issue #64 \"restart loses blocks\" class, where the mirror produced one\n * form and the live wire the other.\n *\n * splitDemotedThinking() reverses the rendering byte-exactly so both\n * codecs can normalize before identity derivation (deriveMessageId). It\n * only fires when the tag opens at offset 0 of the content, which is the\n * only position the demotion renderer can produce it in.\n *\n * One form is intentionally NOT recoverable here: the pi-ai anthropic\n * dialect demotes to BARE text (no tag), which is indistinguishable from\n * ordinary assistant prose; that case must be aligned upstream (mirror\n * uses the same bare rendering), not parsed. */\n\nexport type DemotedSplit = {\n reasoning: string;\n text: string;\n};\n\ntype DelimitedForm = {\n open: string;\n close: string;\n};\n\n/** The three inline tag forms hosts actually emit (see file comment). */\nconst FORMS: readonly DelimitedForm[] = [\n { open: \"<think>\\n\", close: \"\\n</think>\" },\n { open: \"<thinking>\\n\", close: \"\\n</thinking>\" },\n { open: \"```thinking\\n\", close: \"\\n```\" },\n];\n\n/** If `content` starts with one or more inline demoted-thinking blocks,\n * split them out. Returns null when no tag opens the content (the common\n * case — including every user message and every assistant message whose\n * reasoning traveled as a field/item), in which case callers keep the\n * content as-is. Malformed (unterminated) or empty blocks do not match;\n * the content is then treated as plain text, never dropped. */\nexport function splitDemotedThinking(content: string): DemotedSplit | null {\n let rest = content;\n const parts: string[] = [];\n for (;;) {\n let matched = false;\n for (const form of FORMS) {\n if (!rest.startsWith(form.open)) continue;\n const end = rest.indexOf(form.close, form.open.length);\n if (end < 0) continue;\n const inner = rest.slice(form.open.length, end);\n if (inner.length === 0) continue;\n parts.push(inner);\n rest = rest.slice(end + form.close.length);\n // Glue the demotion renderer inserts between a demoted block\n // and the block that follows it.\n if (rest.startsWith(\"\\n\")) rest = rest.slice(1);\n matched = true;\n break;\n }\n if (!matched) break;\n }\n if (parts.length === 0) return null;\n return { reasoning: parts.join(\"\\n\"), text: rest };\n}\n","/**\n * Lossless message bridge between protocol-specific message formats and the\n * kernel's CoreMessage.\n *\n * Problem: `anthropicToCore` / `openaiToCore` / `responsesToCore` flatten\n * rich protocol blocks (images, thinking signatures, tool_result.is_error,\n * developer-role messages, image_url) into plain `{ text }` placeholders.\n * The reverse `coreToX` then can't reconstruct them — `is_error` is lost\n * (upstream can't tell a tool error from a result), `thinking.signature` is\n * lost (Anthropic rejects thinking blocks without a matching signature),\n * images become \"[image]\" (the model never sees the picture).\n *\n * Solution: `BiliMessage` extends CoreMessage with optional sidecar fields.\n * The kernel only reads `{ ...message }` (spread copy) and known fields, so\n * the extra fields survive the compression pipeline unchanged and arrive back\n * at `coreToX`, which prefers them over the flattened `text`. No `as any`\n * needed — TypeScript array covariance lets `BiliMessage[]` satisfy a\n * `CoreMessage[]` parameter.\n */\n\nimport type { CoreMessage } from \"acp-kernel\";\n\n/** A message that carries its original protocol block(s) verbatim, so the\n * reverse conversion can reconstruct losslessly. Every field is optional —\n * plain text messages (the common case) have none set. */\nexport interface BiliMessage extends CoreMessage {\n /** Anthropic: the original content block for an image or a structured\n * tool_result. Restored verbatim by coreToAnthropic. */\n rawAnthropicBlock?: unknown;\n /** OpenAI chat: the original content part for an image_url, or the\n * original message object for a developer-role message. */\n rawOpenaiContent?: unknown;\n /** Responses API: the original input item (for input_image, or a raw\n * function_call / function_call_output we pass through). */\n rawResponsesItem?: unknown;\n /** Anthropic thinking signature. Anthropic verifies thinking+signature\n * pairs; without it the request is rejected. Stored alongside the\n * reasoning text so coreToAnthropic can reattach it. */\n thinkingSignature?: string;\n /** OpenAI reasoning_content (chain-of-thought from DeepSeek-R1, GLM-4.6\n * thinking, Qwen-QwQ). These models require reasoning_content be echoed\n * back on subsequent requests or the API returns HTTP 400; stored so\n * coreToOpenai can reattach it. */\n reasoningContent?: string;\n /** Anthropic tool_result.is_error. Marks the tool result as an error so\n * the model knows the tool failed (not just returned an error string). */\n toolIsError?: boolean;\n /** OpenAI: original role was \"developer\" (reconstructed as \"system\" by\n * openaiToCore for the kernel; coreToOpenai restores \"developer\"). */\n originalRole?: \"system\" | \"developer\";\n /** The original media type for an image (image/png, image/jpeg, image/gif,\n * image/webp). Lets coreToOpenai/coreToResponses rebuild image_url /\n * input_image with the right data URL. */\n imageMediaType?: string;\n /** The base64 data of an image (without the data: prefix). Lets the\n * reverse conversion rebuild the full image payload. */\n imageBase64?: string;\n /** OpenAI chat: ALL original image_url content parts (each a data: URL\n * part) for a user message carrying more than one image, in wire order.\n * coreToOpenai re-emits these verbatim (after the text part). The\n * singular `rawOpenaiContent` still covers the single-image case and\n * legacy persisted state. Typed as unknown[] (not OpenAIContentPart) to\n * avoid a circular import with the openai codec. */\n rawOpenaiContentParts?: unknown[];\n}\n\n/** Narrow a BiliMessage[] to CoreMessage[] for the kernel. The sidecar fields\n * are transparently carried along — the kernel's `{ ...msg }` copies them. */\nexport function toCoreMessages(msgs: BiliMessage[]): CoreMessage[] {\n return msgs as CoreMessage[];\n}\n\n/** Re-decode a base64 data URL into media type + data. Returns undefined if\n * the input is not a recognized data URL. Used by openaiToCore/responsesToCore\n * to split image_url/input_image into the sidecar fields. */\nexport function parseDataUrl(url: string): { mediaType: string; base64: string } | undefined {\n const m = /^data:([^;,]+)(?:;base64)?,(.+)$/i.exec(url);\n if (!m) return undefined;\n return { mediaType: m[1]!, base64: m[2]! };\n}\n","import { splitDemotedThinking } from \"./demoted-thinking.js\";\nimport { hashId } from \"./util.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\nimport { parseDataUrl, type BiliMessage } from \"./bili-message.js\";\n\nexport type OpenAIContentPart =\n | { type: \"text\"; text: string }\n | { type: \"image_url\"; image_url: { url: string } }\n | { type: string; [k: string]: unknown };\n\nexport type OpenAIToolCall = {\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n};\n\nexport type OpenAIMessage = {\n role: \"system\" | \"developer\" | \"user\" | \"assistant\" | \"tool\";\n content?: string | null | OpenAIContentPart[];\n reasoning_content?: string | null;\n tool_calls?: OpenAIToolCall[];\n tool_call_id?: string;\n name?: string;\n};\n\nexport type OpenAITool = {\n type: \"function\";\n function: { name: string; description?: string; parameters?: unknown };\n};\n\nexport type OpenAIRequestBody = {\n model?: string;\n messages: OpenAIMessage[];\n tools?: OpenAITool[];\n stream?: boolean;\n [key: string]: unknown;\n};\n\ntype Flat = { msgs: BiliMessage[] };\n\nexport function openaiToCore(body: OpenAIRequestBody): Flat {\n const msgs: BiliMessage[] = [];\n const clusters = new ClusterCounter();\n for (const m of body.messages) {\n switch (m.role) {\n case \"system\":\n case \"developer\": {\n const base = deriveMessageId(m.role, \"text\", stringContent(m.content));\n msgs.push({ id: clusters.next(base), role: \"system\", contentType: \"text\", text: stringContent(m.content), originalRole: m.role });\n break;\n }\n case \"user\": {\n const text = stringContent(m.content);\n const imgs = allImageParts(m.content);\n const firstImg = imgs[0];\n const firstUrl = firstImg ? firstImg.image_url.url : undefined;\n const firstParsed = firstUrl ? parseDataUrl(firstUrl) : undefined;\n const base = deriveMessageId(\"user\", \"text\", text);\n msgs.push({\n id: clusters.next(base),\n role: \"user\",\n contentType: \"text\",\n text,\n ...(imgs.length === 1 && firstParsed\n ? { rawOpenaiContent: imgs[0], imageMediaType: firstParsed.mediaType, imageBase64: firstParsed.base64 }\n : imgs.length > 1\n ? { rawOpenaiContentParts: imgs }\n : {}),\n });\n break;\n }\n case \"assistant\": {\n const fieldReasoning = typeof m.reasoning_content === \"string\" ? m.reasoning_content : \"\";\n let reasoning = fieldReasoning;\n let text = stringContent(m.content);\n if (!reasoning) {\n // Hosts that cannot replay prior-turn reasoning as a\n // structured field inline it into content wrapped in a\n // dialect tag (<think>, <thinking>, ```thinking). Split\n // it back out BEFORE identity derivation so the inline\n // form and the reasoning_content field form of one turn\n // land in a single core-id/fingerprint space (issue #64\n // demoted variant).\n const split = splitDemotedThinking(text);\n if (split) {\n reasoning = split.reasoning;\n text = split.text;\n }\n }\n if (reasoning) {\n const base = deriveMessageId(\"assistant\", \"reasoning\", reasoning);\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"reasoning\",\n text: reasoning,\n reasoningContent: reasoning,\n });\n }\n if (text) {\n const base = deriveMessageId(\"assistant\", \"text\", text);\n msgs.push({ id: clusters.next(base), role: \"assistant\", contentType: \"text\", text });\n }\n if (Array.isArray(m.tool_calls)) {\n for (const tc of m.tool_calls) {\n const base = deriveMessageId(\"assistant\", \"tool-call\", tc.function.arguments ?? \"\", {\n toolCallId: tc.id,\n toolName: tc.function.name,\n });\n msgs.push({\n id: clusters.next(base),\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: tc.function.name,\n toolCallId: tc.id,\n text: tc.function.arguments ?? \"\",\n });\n }\n }\n break;\n }\n case \"tool\": {\n const base = deriveMessageId(\"tool\", \"tool-result\", stringContent(m.content), {\n toolCallId: m.tool_call_id ?? \"\",\n });\n msgs.push({\n id: clusters.next(base),\n role: \"tool\",\n contentType: \"tool-result\",\n toolCallId: m.tool_call_id ?? \"\",\n text: stringContent(m.content),\n });\n break;\n }\n }\n }\n return { msgs };\n}\n\nexport function coreToOpenai(messages: BiliMessage[]): OpenAIMessage[] {\n const out: OpenAIMessage[] = [];\n let pending: { text: string | null; toolCalls: OpenAIToolCall[]; reasoning: string | null } | null = null;\n const flush = () => {\n if (!pending) return;\n const reasoning = pending.reasoning !== null && pending.reasoning.length > 0 ? pending.reasoning : undefined;\n if (pending.toolCalls.length > 0) {\n out.push({\n role: \"assistant\",\n content: pending.text ?? null,\n tool_calls: pending.toolCalls,\n ...(reasoning ? { reasoning_content: reasoning } : {}),\n });\n } else if (pending.text !== null) {\n out.push({ role: \"assistant\", content: pending.text, ...(reasoning ? { reasoning_content: reasoning } : {}) });\n } else if (reasoning) {\n out.push({ role: \"assistant\", content: null, reasoning_content: reasoning });\n }\n pending = null;\n };\n for (const m of messages) {\n if (m.role === \"assistant\") {\n if (!pending) pending = { text: null, toolCalls: [], reasoning: null };\n if (m.contentType === \"reasoning\") {\n pending.reasoning = (pending.reasoning ?? \"\") + (m.reasoningContent ?? m.text ?? \"\");\n } else if (m.contentType === \"text\") {\n pending.text = (pending.text ?? \"\") + (m.text ?? \"\");\n } else if (m.contentType === \"tool-call\") {\n pending.toolCalls.push({\n id: m.toolCallId ?? `call_${m.id}`,\n type: \"function\",\n function: { name: m.toolName ?? \"unknown\", arguments: m.text ?? \"\" },\n });\n }\n } else {\n flush();\n if (m.role === \"system\") {\n out.push({ role: m.originalRole === \"developer\" ? \"developer\" : \"system\", content: m.text ?? \"\" });\n } else if (m.role === \"user\") {\n if (m.rawOpenaiContent || m.imageBase64 || m.rawOpenaiContentParts) {\n const parts: OpenAIContentPart[] = [];\n if (m.text) parts.push({ type: \"text\", text: m.text });\n if (m.rawOpenaiContentParts && m.rawOpenaiContentParts.length > 0) {\n for (const part of m.rawOpenaiContentParts) parts.push(part as OpenAIContentPart);\n } else if (m.rawOpenaiContent) {\n parts.push(m.rawOpenaiContent as OpenAIContentPart);\n } else if (m.imageBase64 && m.imageMediaType) {\n parts.push({ type: \"image_url\", image_url: { url: `data:${m.imageMediaType};base64,${m.imageBase64}` } });\n }\n out.push({ role: \"user\", content: parts });\n } else {\n out.push({ role: \"user\", content: m.text ?? \"\" });\n }\n } else if (m.role === \"tool\") {\n out.push({ role: \"tool\", tool_call_id: m.toolCallId ?? \"\", content: m.text ?? \"\" });\n }\n }\n }\n flush();\n return out;\n}\n\nexport function injectOpenaiSystem(messages: OpenAIMessage[], parts: string[]): OpenAIMessage[] {\n if (parts.length === 0) return messages;\n const extra = parts.join(\"\\n\\n\");\n if (messages.length > 0 && (messages[0]?.role === \"system\" || messages[0]?.role === \"developer\")) {\n const head = messages[0] as OpenAIMessage;\n const base = stringContent(head.content);\n const merged = base ? `${base}\\n\\n---\\n\\n${extra}` : extra;\n return [{ ...head, content: merged }, ...messages.slice(1)];\n }\n return [{ role: \"system\", content: extra }, ...messages];\n}\n\n/** Extract the conversation dimension for OpenAI Chat: a client-provided\n * session header if present, else a content fingerprint of the first user\n * message. See conversationSignalAnthropic for the full rationale. */\nexport function conversationSignalOpenai(body: OpenAIRequestBody, headerValue?: string): string {\n if (headerValue && headerValue.trim()) return headerValue.trim();\n const firstUser = body.messages.find((m) => m.role === \"user\");\n const seed = firstUser ? stringContent(firstUser.content) : \"default\";\n return hashId(seed);\n}\n\nfunction stringContent(content: OpenAIMessage[\"content\"]): string {\n if (content == null) return \"\";\n if (typeof content === \"string\") return content;\n if (Array.isArray(content)) {\n return content\n .map((p) => (typeof p === \"string\" ? p : p.type === \"text\" ? (p as { text?: string }).text ?? \"\" : \"\"))\n .join(\"\\n\");\n }\n return \"\";\n}\n\ntype OpenAIImagePart = { type: \"image_url\"; image_url: { url: string } };\n\n/** Collect ALL data-URL image parts in a user content array, in wire order.\n * (firstImagePart only kept the first, which silently dropped images 2..N\n * on the coreToOpenai rebuild.) */\nfunction allImageParts(content: OpenAIMessage[\"content\"]): OpenAIImagePart[] {\n if (!Array.isArray(content)) return [];\n const out: OpenAIImagePart[] = [];\n for (const p of content) {\n if (typeof p !== \"object\" || p === null) continue;\n if (!(\"type\" in p) || p.type !== \"image_url\" || !(\"image_url\" in p)) continue;\n // The union's index-signature member leaves image_url as `unknown`, so\n // narrow via a named const before reading the url.\n const imagePart = p as { image_url: { url?: unknown } };\n const url = imagePart.image_url.url;\n if (typeof url === \"string\" && parseDataUrl(url)) out.push(p as OpenAIImagePart);\n }\n return out;\n}\n","import type { CoreMessage } from \"../types.js\";\nimport { splitDemotedThinking } from \"./demoted-thinking.js\";\nimport { ClusterCounter, deriveMessageId } from \"./message-id.js\";\nimport type { ConversationIdentity } from \"./util.js\";\nimport { hashId } from \"./util.js\";\nimport { parseDataUrl, type BiliMessage } from \"./bili-message.js\";\n\nexport type ResponseContentPart =\n | { type: \"input_text\"; text: string; [key: string]: unknown }\n | { type: \"output_text\"; text: string; [key: string]: unknown }\n | { type: \"input_image\"; image_url: string; [key: string]: unknown }\n | { type: string; [key: string]: unknown };\n\nexport type ResponseInputMessage = {\n type: \"message\";\n role: \"system\" | \"developer\" | \"user\" | \"assistant\";\n content: string | ResponseContentPart[];\n [key: string]: unknown;\n};\n\nexport type ResponseFunctionCall = {\n type: \"function_call\";\n id?: string;\n call_id: string;\n name: string;\n arguments: string;\n [key: string]: unknown;\n};\n\nexport type ResponseFunctionCallOutput = {\n type: \"function_call_output\";\n call_id: string;\n output: string;\n [key: string]: unknown;\n};\n\nexport type ResponseInputItem =\n | ResponseInputMessage\n | ResponseFunctionCall\n | ResponseFunctionCallOutput\n | { type: string; [key: string]: unknown };\n\nexport type ResponsesRequestBody = {\n model?: string;\n input: string | ResponseInputItem[];\n instructions?: string;\n tools?: unknown[];\n stream?: boolean;\n session_id?: string;\n previous_response_id?: string;\n prompt_cache_key?: string;\n metadata?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype ResponseLayoutSlot = {\n original: ResponseInputItem;\n coreId?: string;\n};\n\nexport type ResponsesProjection = {\n msgs: BiliMessage[];\n systemParts: string[];\n preamble: ResponseInputItem[];\n customToolCallIds: Set<string>;\n layout: ResponseLayoutSlot[];\n stringInput?: { original: string; coreId: string };\n /** Reasoning items dropped because ACP_REASONING_KEEP=none. 0 by default —\n * reasoning is normally routed through the compression pipeline so it is\n * hidden automatically once its turn is summarized. */\n droppedReasoning: number;\n};\n\n/** Item types that are host DIRECTIVES (tool/definition listings), not\n * conversation history: preserved verbatim and re-prepended at input[0..].\n * `additional_tools` carries the Codex code_mode exec/wait tool definitions\n * and MUST stay at input[0]. `mcp_list_tools` is a stable per-session listing.\n *\n * Only definitions belong here. Output/action items from a prior response\n * (reasoning, computer_call, function_call, mcp_call, ...) ARE conversation\n * history and are routed as tracked BiliMessages, so the compression pipeline\n * hides them once their turn is summarized — preserving them verbatim in the\n * preamble instead made them accumulate unbounded every turn and broke Codex's\n * prompt-cache prefix. */\nconst OPAQUE_ITEM_TYPES = new Set([\n \"additional_tools\",\n \"mcp_list_tools\",\n]);\n\nfunction isOpaqueItem(item: ResponseInputItem): boolean {\n return OPAQUE_ITEM_TYPES.has(item.type);\n}\n\nfunction shouldDropAllReasoning(): boolean {\n return (process.env.ACP_REASONING_KEEP ?? \"\").trim().toLowerCase() === \"none\";\n}\n\nfunction partText(part: ResponseContentPart): string {\n if (part.type === \"input_text\" || part.type === \"output_text\") {\n return typeof part.text === \"string\" ? part.text : \"\";\n }\n return \"\";\n}\n\nfunction messageContent(content: string | ResponseContentPart[]): string {\n return typeof content === \"string\" ? content : content.map(partText).join(\"\\n\");\n}\n\n/** Extract the reasoning text from a responses reasoning item. The host\n * carries it in `content` (reasoning_text parts); the primeFold mirror\n * carries it in `summary` (summary_text parts). Both must yield the same\n * text so the kernel derives the same core id (issue #64, responses). */\nfunction reasoningText(item: ResponseInputItem): string {\n const fromParts = (parts: unknown, type: string): string => {\n if (!Array.isArray(parts)) return \"\";\n const texts: string[] = [];\n for (const part of parts) {\n if (part && typeof part === \"object\" && \"type\" in part && \"text\" in part) {\n const rec = part as { type: unknown; text: unknown };\n if (rec.type === type && typeof rec.text === \"string\") texts.push(rec.text);\n }\n }\n return texts.join(\"\\n\");\n };\n const content = \"content\" in item ? item.content : undefined;\n const summary = \"summary\" in item ? item.summary : undefined;\n return fromParts(content, \"reasoning_text\") || fromParts(summary, \"summary_text\");\n}\n\nexport function responsesToCore(body: ResponsesRequestBody): ResponsesProjection {\n const msgs: BiliMessage[] = [];\n const systemParts: string[] = [];\n const preamble: ResponseInputItem[] = [];\n const customToolCallIds = new Set<string>();\n const layout: ResponseLayoutSlot[] = [];\n let droppedReasoning = 0;\n const clusters = new ClusterCounter();\n let idx = 0;\n if (typeof body.instructions === \"string\" && body.instructions.trim()) systemParts.push(body.instructions);\n if (typeof body.input === \"string\") {\n const id = clusters.next(deriveMessageId(\"user\", \"text\", body.input));\n msgs.push({ id, role: \"user\", contentType: \"text\", text: body.input });\n return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning, stringInput: { original: body.input, coreId: id } };\n }\n for (const item of body.input) {\n let coreId: string | undefined;\n if (isOpaqueItem(item)) preamble.push(item);\n switch (item.type) {\n case \"reasoning\": {\n if (shouldDropAllReasoning()) {\n droppedReasoning++;\n continue;\n }\n // Key the reasoning piece on its TEXT (deterministic), consistent\n // with the anthropic/openai codecs. The host mints a per-request\n // item id that the primeFold mirror cannot reproduce; keying on it\n // put the mirror in a different ref/fingerprint space, so restart\n // replay rejected every in-stream compress call (issue #64,\n // responses variant).\n const text = reasoningText(item);\n const rid =\n text.length > 0\n ? text\n : \"id\" in item && typeof item.id === \"string\"\n ? item.id\n : hashId(JSON.stringify(item));\n coreId = clusters.next(deriveMessageId(\"assistant\", \"reasoning\", rid));\n msgs.push({\n id: coreId,\n role: \"assistant\",\n contentType: \"reasoning\",\n text: rid,\n rawResponsesItem: item,\n });\n break;\n }\n case \"message\": {\n const message = item as ResponseInputMessage;\n const text = messageContent(message.content);\n if (message.role === \"system\" || message.role === \"developer\") {\n systemParts.push(text);\n idx++;\n continue;\n } else if (message.role === \"user\" || (message.role === \"assistant\" && text)) {\n const role = message.role;\n let effText = text;\n if (role === \"assistant\") {\n // Same normalization as openaiToCore: hosts that demote\n // prior-turn reasoning inline it as a dialect tag at the\n // head of the message text. Split it out before identity\n // derivation so the inline form and the separate\n // reasoning-item form of one turn share a single\n // core-id/fingerprint space.\n const split = splitDemotedThinking(text);\n if (split) {\n msgs.push({\n id: clusters.next(deriveMessageId(\"assistant\", \"reasoning\", split.reasoning)),\n role: \"assistant\",\n contentType: \"reasoning\",\n text: split.reasoning,\n rawResponsesItem: item,\n });\n effText = split.text;\n }\n }\n if (effText) {\n coreId = clusters.next(deriveMessageId(role, \"text\", effText));\n const imageUrl = Array.isArray(message.content)\n ? message.content.find((part) => part.type === \"input_image\" && typeof part.image_url === \"string\")?.image_url\n : undefined;\n const image = typeof imageUrl === \"string\" ? parseDataUrl(imageUrl) : undefined;\n msgs.push({\n id: coreId,\n role,\n contentType: \"text\",\n text: effText,\n rawResponsesItem: item,\n ...(image ? { imageMediaType: image.mediaType, imageBase64: image.base64 } : {}),\n });\n }\n }\n break;\n }\n case \"function_call\": {\n const call = item as ResponseFunctionCall;\n coreId = clusters.next(deriveMessageId(\"assistant\", \"tool-call\", call.arguments ?? \"\", {\n toolCallId: call.call_id,\n toolName: call.name,\n }));\n msgs.push({\n id: coreId,\n role: \"assistant\",\n contentType: \"tool-call\",\n toolName: call.name,\n toolCallId: call.call_id,\n text: call.arguments ?? \"\",\n rawResponsesItem: item,\n });\n break;\n }\n case \"function_call_output\": {\n const output = item as ResponseFunctionCallOutput;\n const text = typeof output.output === \"string\" ? output.output : JSON.stringify(output.output);\n coreId = clusters.next(deriveMessageId(\"tool\", \"tool-result\", text, { toolCallId: output.call_id }));\n msgs.push({ id: coreId, role: \"tool\", contentType: \"tool-result\", toolCallId: output.call_id, text, rawResponsesItem: item });\n break;\n }\n case \"computer_call\":\n case \"computer_call_output\":\n case \"file_search_call\":\n case \"web_search_call\":\n case \"image_generation_call\":\n case \"code_interpreter_call\":\n case \"mcp_call\": {\n const rid =\n typeof (item as { id?: unknown }).id === \"string\"\n ? String((item as { id?: string }).id)\n : hashId(JSON.stringify(item));\n coreId = clusters.next(deriveMessageId(\"assistant\", \"responses-call\", rid));\n msgs.push({ id: coreId, role: \"assistant\", contentType: \"reasoning\", text: rid, rawResponsesItem: item });\n break;\n }\n case \"custom_tool_call\": {\n const ctc = item as { call_id?: string; name?: string; input?: string; arguments?: string };\n const callId = ctc.call_id ?? `call_${idx}`;\n customToolCallIds.add(callId);\n const argText = ctc.input ?? ctc.arguments ?? \"\";\n coreId = clusters.next(deriveMessageId(\"assistant\", \"tool-call\", argText, { toolCallId: callId, toolName: ctc.name ?? \"custom\" }));\n msgs.push({ id: coreId, role: \"assistant\", contentType: \"tool-call\", toolName: ctc.name ?? \"custom\", toolCallId: callId, text: argText, rawResponsesItem: item });\n break;\n }\n case \"custom_tool_call_output\": {\n const ctco = item as { call_id?: string; output?: string };\n const callId = ctco.call_id ?? `call_${idx}`;\n customToolCallIds.add(callId);\n const outText = typeof ctco.output === \"string\" ? ctco.output : JSON.stringify(ctco.output ?? \"\");\n coreId = clusters.next(deriveMessageId(\"tool\", \"tool-result\", outText, { toolCallId: callId }));\n msgs.push({ id: coreId, role: \"tool\", contentType: \"tool-result\", toolCallId: callId, text: outText, rawResponsesItem: item });\n break;\n }\n default:\n if (!isOpaqueItem(item)) preamble.push(item);\n break;\n }\n layout.push({ original: item, coreId });\n idx++;\n }\n return { msgs, systemParts, preamble, customToolCallIds, layout, droppedReasoning };\n}\n\nfunction patchTextParts(parts: ResponseContentPart[], text: string): ResponseContentPart[] {\n const textIndexes = parts.flatMap((part, index) =>\n part.type === \"input_text\" || part.type === \"output_text\" ? [index] : [],\n );\n if (textIndexes.length === 0) return [{ type: \"input_text\", text }, ...parts];\n const first = textIndexes[0];\n const remaining = new Set(textIndexes.slice(1));\n return parts.map((part, index) => {\n if (index === first) return { ...part, text };\n if (remaining.has(index)) return { ...part, text: \"\" };\n return part;\n });\n}\n\nfunction patchOriginalItem(original: ResponseInputItem, source: CoreMessage, next: CoreMessage): ResponseInputItem {\n if (\n source.text === next.text &&\n source.toolName === next.toolName &&\n source.toolCallId === next.toolCallId &&\n source.role === next.role &&\n source.contentType === next.contentType\n ) return original;\n if (original.type === \"message\") {\n const message = original as ResponseInputMessage;\n const content = typeof message.content === \"string\" ? next.text ?? \"\" : patchTextParts(message.content, next.text ?? \"\");\n return { ...message, content };\n }\n if (original.type === \"function_call\") {\n return {\n ...original,\n name: next.toolName ?? String(original.name ?? \"unknown\"),\n call_id: next.toolCallId ?? String(original.call_id ?? \"\"),\n arguments: next.text ?? \"\",\n };\n }\n if (original.type === \"function_call_output\") {\n return { ...original, call_id: next.toolCallId ?? String(original.call_id ?? \"\"), output: next.text ?? \"\" };\n }\n return original;\n}\n\nexport function patchResponsesInput(projection: ResponsesProjection, messages: CoreMessage[]): string | ResponseInputItem[] {\n if (projection.stringInput) {\n const original = projection.msgs.find((message) => message.id === projection.stringInput?.coreId);\n const next = messages.find((message) => message.id === projection.stringInput?.coreId);\n if (original && next && messages.length === 1 && next.role === \"user\" && next.contentType === \"text\") {\n return next.text === original.text ? projection.stringInput.original : next.text ?? \"\";\n }\n return coreToResponses(messages, projection.customToolCallIds);\n }\n const sourceById = new Map(projection.msgs.map((message) => [message.id, message]));\n const nextById = new Map(messages.map((message) => [message.id, message]));\n const slotById = new Map<string, number>();\n projection.layout.forEach((slot, index) => {\n if (slot.coreId) slotById.set(slot.coreId, index);\n });\n const insertions = new Map<number, ResponseInputItem[]>();\n for (let index = 0; index < messages.length; index++) {\n const message = messages[index]!;\n if (sourceById.has(message.id)) continue;\n let target = projection.layout.length;\n for (let nextIndex = index + 1; nextIndex < messages.length; nextIndex++) {\n const slot = slotById.get(messages[nextIndex]!.id);\n if (slot !== undefined) {\n target = slot;\n break;\n }\n }\n const generated = coreToResponses([message], projection.customToolCallIds);\n if (generated.length > 0) insertions.set(target, [...(insertions.get(target) ?? []), ...generated]);\n }\n const out: ResponseInputItem[] = [];\n projection.layout.forEach((slot, index) => {\n out.push(...(insertions.get(index) ?? []));\n if (!slot.coreId) {\n out.push(slot.original);\n return;\n }\n const source = sourceById.get(slot.coreId);\n const next = nextById.get(slot.coreId);\n if (source && next) out.push(patchOriginalItem(slot.original, source, next));\n });\n out.push(...(insertions.get(projection.layout.length) ?? []));\n return out;\n}\n\nexport function coreToResponses(\n messages: CoreMessage[],\n customToolCallIds: Set<string> = new Set(),\n): ResponseInputItem[] {\n const out: ResponseInputItem[] = [];\n for (const message of messages) {\n const biliMessage = message as BiliMessage;\n const raw = biliMessage.rawResponsesItem as ResponseInputItem | undefined;\n if (message.role === \"system\") {\n out.push({ type: \"message\", role: \"developer\", content: message.text ?? \"\" });\n } else if (message.role === \"user\") {\n if (raw?.type === \"message\" && messageContent((raw as ResponseInputMessage).content) === (message.text ?? \"\")) out.push(raw);\n else out.push({ type: \"message\", role: \"user\", content: message.text ?? \"\" });\n } else if (message.role === \"assistant\") {\n if (message.contentType === \"text\") {\n out.push({ type: \"message\", role: \"assistant\", content: message.text ?? \"\" });\n } else if (message.contentType === \"tool-call\") {\n const callId = message.toolCallId ?? `call_${message.id}`;\n if (customToolCallIds.has(callId)) {\n out.push({ type: \"custom_tool_call\", call_id: callId, name: message.toolName ?? \"unknown\", input: message.text ?? \"\", status: \"completed\" } as ResponseInputItem);\n } else {\n out.push({ type: \"function_call\", call_id: callId, name: message.toolName ?? \"unknown\", arguments: message.text ?? \"\" });\n }\n } else if (message.contentType === \"reasoning\") {\n if (raw) out.push(raw);\n }\n } else if (message.role === \"tool\") {\n const callId = message.toolCallId ?? \"\";\n if (customToolCallIds.has(callId)) {\n out.push({ type: \"custom_tool_call_output\", call_id: callId, output: message.text ?? \"\" } as ResponseInputItem);\n } else {\n out.push({ type: \"function_call_output\", call_id: callId, output: message.text ?? \"\" });\n }\n }\n }\n return out;\n}\n\nexport function injectResponsesDeveloperMessage(\n input: string | ResponseInputItem[],\n content: string,\n): ResponseInputItem[] {\n const items: ResponseInputItem[] = typeof input === \"string\"\n ? [{ type: \"message\", role: \"user\", content: input }]\n : [...input];\n let index = 0;\n while (items[index]?.type === \"additional_tools\") index++;\n items.splice(index, 0, { type: \"message\", role: \"developer\", content });\n return items;\n}\n\nexport function conversationIdentityResponses(\n body: ResponsesRequestBody,\n headerValue?: string,\n): ConversationIdentity {\n if (headerValue?.trim()) return { value: headerValue.trim(), source: \"header\", clientProvided: true };\n if (typeof body.session_id === \"string\" && body.session_id.trim()) {\n return { value: body.session_id.trim(), source: \"body-session\", clientProvided: true };\n }\n const metadataSession = body.metadata?.session_id;\n if (typeof metadataSession === \"string\" && metadataSession.trim()) {\n return { value: metadataSession.trim(), source: \"metadata-session\", clientProvided: true };\n }\n if (typeof body.previous_response_id === \"string\" && body.previous_response_id.trim()) {\n return { value: body.previous_response_id.trim(), source: \"previous-response\", clientProvided: false };\n }\n return { value: hashId(JSON.stringify(body.input ?? [])), source: \"content-fingerprint\", clientProvided: false };\n}\n\nexport function conversationSignalResponses(body: ResponsesRequestBody, headerValue?: string): string {\n return conversationIdentityResponses(body, headerValue).value;\n}\n\n// Codex subagents (guardian approval reviewer, etc.) reuse the main\n// conversation's body.session_id, so identity alone collapses their requests\n// onto the main session's compression state — a compressed subagent request\n// loses the verbatim user authorization it must read back (#150). Subagent\n// requests carry their own `instructions` (the agent's role prompt), so the\n// FIRST instructions seen for an identity anchor the main namespace (it never\n// changes for the conversation, even if the main prompt drifts), and any other\n// instructions value maps to a separate `|sub:` namespace with its own empty\n// compression state. Subagent requests are self-contained replays, so the\n// fresh namespace is lossless.\nexport interface SubagentNamespaces {\n /** Resolve the compression-state namespace for a request: the identity\n * itself for the anchored (main) instructions, `identity|sub:<fp>` for\n * any other instructions value. First-seen instructions anchor. */\n namespaceFor(identityValue: string, instructions: unknown): string;\n}\n\n/** Host-owned subagent-namespace store.\n *\n * The anchor map is per-conversation mutable state, so it belongs to the\n * host — NOT to a library module global. Create one instance and keep it for\n * the process lifetime (or persist it alongside your session store if you\n * need namespaces to survive restarts: a fresh instance re-anchors on the\n * first request it sees, which after a restart may be a subagent request,\n * orphaning the main conversation's stored compression state). */\nexport function createSubagentNamespaces(): SubagentNamespaces {\n const anchors = new Map<string, string>();\n return {\n namespaceFor(identityValue: string, instructions: unknown): string {\n if (typeof instructions !== \"string\" || instructions.trim().length === 0) return identityValue;\n const fp = hashId(instructions);\n const anchor = anchors.get(identityValue);\n if (anchor === undefined) {\n anchors.set(identityValue, fp);\n return identityValue;\n }\n return anchor === fp ? identityValue : `${identityValue}|sub:${fp}`;\n },\n };\n}\n\n// Convenience singleton for single-process proxies that don't manage\n// per-session state themselves. Hosts needing isolation between\n// conversations, deterministic namespaces across restarts, or a bound on\n// anchor memory should create their own instance via\n// createSubagentNamespaces() and own its lifecycle.\nconst defaultNamespaces = createSubagentNamespaces();\n\nexport function subagentNamespace(identityValue: string, instructions: unknown): string {\n return defaultNamespaces.namespaceFor(identityValue, instructions);\n}\n","export const WIRE_FORMATS = [\"anthropic\", \"openai\", \"responses\"] as const;\nexport type WireFormat = (typeof WIRE_FORMATS)[number];\n\nexport function isWireFormat(value: unknown): value is WireFormat {\n return (\n typeof value === \"string\" &&\n (WIRE_FORMATS as readonly string[]).includes(value)\n );\n}\n\n/**\n * Classify a provider request body by the codec that can parse it.\n * Returns undefined when no codec handles the body — the caller must\n * pass such payloads through untransformed.\n */\nexport function detectWireFormat(payload: unknown): WireFormat | undefined {\n if (payload === null || typeof payload !== \"object\") return undefined;\n const p = payload as Record<string, unknown>;\n if (Array.isArray(p.input)) return \"responses\";\n const messages = p.messages;\n if (!Array.isArray(messages)) return undefined;\n if (\"system\" in p || \"anthropic_version\" in p) return \"anthropic\";\n for (const m of messages as Array<Record<string, unknown>>) {\n if (m === null || typeof m !== \"object\") continue;\n const c = m.content;\n if (Array.isArray(c)) {\n for (const b of c as Array<Record<string, unknown>>) {\n if (b && typeof b === \"object\" && typeof b.type === \"string\") {\n if (\n b.type === \"tool_use\" ||\n b.type === \"tool_result\" ||\n b.type === \"thinking\"\n )\n return \"anthropic\";\n if (b.type === \"text\" && \"cache_control\" in b) return \"anthropic\";\n }\n }\n }\n if (Array.isArray(m.tool_calls)) return \"openai\";\n if (m.role === \"tool\" && typeof m.tool_call_id === \"string\")\n return \"openai\";\n if (m.role === \"system\" || m.role === \"developer\") return \"openai\";\n }\n // Both chat formats share role+messages; default to openai — the safer\n // guess for OpenAI-compatible endpoints (GLM, DeepSeek, vLLM).\n return \"openai\";\n}\n","import { anthropicToCore } from \"./anthropic.js\";\nimport { openaiToCore } from \"./openai.js\";\nimport { responsesToCore } from \"./responses.js\";\nimport type { BiliMessage } from \"./bili-message.js\";\n\n/**\n * Mirror constructors: rebuild the WIRE-SHAPE projection of a persisted\n * conversation (the mirror of \"what the host will put on the wire after a\n * restart\") for each protocol family, then fold it through the matching\n * `*ToCore` codec so the projection lands in the same identity/fingerprint\n * space as the live request.\n *\n * This used to live as three hand-rolled builders in the omp plugin\n * (wire-fold.ts) — protocol knowledge scattered across consumers is exactly\n * how the issue-#64 class of restart divergences happened (one place fixed,\n * another broke). The wire layouts now live here, next to the codecs that\n * define their identity space.\n *\n * CONTRACT: the caller maps its own persisted message shape into\n * {@link MirrorMessage} FIRST and normalizes text there (e.g. ref-tag\n * stripping is a host-app concern, not a wire concern). Builders only apply\n * host-encoder wire rules:\n * - thinking rides each wire the way the live encoder sends it\n * (openai: `reasoning_content` field — hosts that demote inline as\n * `<think>…</think>` land in the same identity space anyway because\n * `openaiToCore` normalizes the inline form; anthropic: signed\n * `{type:\"thinking\"}` blocks; responses: `{type:\"reasoning\"}` items);\n * - whitespace-only text survives on the openai wire, is dropped on the\n * anthropic/responses wires (host encoder behaviour);\n * - tool calls/results map to each wire's native shape.\n */\n\nexport type MirrorBlock =\n | { type: \"text\"; text: string }\n | { type: \"thinking\"; thinking: string; signature?: string }\n | { type: \"toolCall\"; id?: string; name?: string; arguments?: unknown };\n\nexport type MirrorMessage = {\n /** `meta` is anything the host sends as out-of-band/system-ish traffic. */\n role: \"user\" | \"assistant\" | \"toolResult\" | \"meta\";\n blocks?: MirrorBlock[];\n /** toolResult only. */\n toolCallId?: string;\n /** meta only: extracted text or summary. */\n text?: string;\n};\n\nfunction textBlocks(blocks: MirrorBlock[] | undefined): string[] {\n const out: string[] = [];\n for (const b of blocks ?? []) if (b.type === \"text\") out.push(b.text);\n return out;\n}\n\n/** Openai wire text: text blocks joined with \"\\n\" (whitespace-only kept). */\nfunction joinText(blocks: MirrorBlock[] | undefined): string {\n return textBlocks(blocks).join(\"\\n\");\n}\n\nfunction thinkingText(blocks: MirrorBlock[] | undefined): string {\n return blocks\n ?.filter((b) => b.type === \"thinking\" && b.thinking.trim().length > 0)\n .map((b) => (b as { thinking: string }).thinking)\n .join(\"\\n\") ?? \"\";\n}\n\n/** Openai/completions mirror: system message first, then the conversation\n * with thinking as the `reasoning_content` field (issue #103). */\nexport function mirrorOpenaiMessages(view: MirrorMessage[], systemText: string): Array<Record<string, unknown>> {\n const messages: Array<Record<string, unknown>> = [{ role: \"system\", content: systemText }];\n for (const message of view) {\n if (message.role === \"user\") {\n const text = joinText(message.blocks);\n if (text) messages.push({ role: \"user\", content: text });\n } else if (message.role === \"assistant\") {\n const calls = (message.blocks ?? []).filter((b) => b.type === \"toolCall\") as Array<{ id?: string; name?: string; arguments?: unknown }>;\n const reasoning = thinkingText(message.blocks);\n const text = joinText(message.blocks);\n if (calls.length > 0) {\n messages.push({\n role: \"assistant\",\n content: text,\n ...(reasoning ? { reasoning_content: reasoning } : {}),\n tool_calls: calls.map((c) => ({\n id: c.id,\n type: \"function\",\n function: { name: c.name ?? \"\", arguments: JSON.stringify(c.arguments ?? {}) },\n })),\n });\n } else if (text || reasoning) {\n messages.push({ role: \"assistant\", content: text, ...(reasoning ? { reasoning_content: reasoning } : {}) });\n }\n } else if (message.role === \"toolResult\") {\n messages.push({ role: \"tool\", tool_call_id: message.toolCallId ?? \"\", content: joinText(message.blocks) });\n } else {\n const text = message.text ?? \"\";\n if (text) messages.push({ role: \"developer\", content: text });\n }\n }\n return messages;\n}\n\n/** Anthropic/messages mirror: no system message (the live request carries it\n * as the top-level `system` field, out of the fold space — issue #64), tool\n * results folded into user messages, thinking as signed `{type:\"thinking\"}`\n * blocks (issue #103). Unsigned thinking is demoted to text by the live\n * encoder; sending it as a thinking block diverges, so callers that persist\n * unsigned thinking should send it as a text block instead. */\nexport function mirrorAnthropicMessages(view: MirrorMessage[]): Array<Record<string, unknown>> {\n const messages: Array<Record<string, unknown>> = [];\n for (const message of view) {\n if (message.role === \"user\") {\n const text = joinText(message.blocks);\n if (text) messages.push({ role: \"user\", content: [{ type: \"text\", text }] });\n } else if (message.role === \"assistant\") {\n const content: Array<Record<string, unknown>> = [];\n for (const b of message.blocks ?? []) {\n if (b.type === \"thinking\" && b.thinking.trim().length > 0) {\n content.push({\n type: \"thinking\",\n thinking: b.thinking,\n ...(typeof b.signature === \"string\" && b.signature ? { signature: b.signature } : {}),\n });\n } else if (b.type === \"text\" && b.text.trim().length > 0) {\n content.push({ type: \"text\", text: b.text });\n } else if (b.type === \"toolCall\") {\n let input: unknown = {};\n try {\n input = b.arguments && typeof b.arguments === \"object\" ? b.arguments : JSON.parse(JSON.stringify(b.arguments ?? {}));\n } catch {\n input = {};\n }\n content.push({ type: \"tool_use\", id: b.id, name: b.name ?? \"\", input });\n }\n }\n if (content.length > 0) messages.push({ role: \"assistant\", content });\n } else if (message.role === \"toolResult\") {\n messages.push({\n role: \"user\",\n content: [{ type: \"tool_result\", tool_use_id: message.toolCallId ?? \"\", content: joinText(message.blocks) }],\n });\n } else {\n const text = message.text ?? \"\";\n if (text) messages.push({ role: \"user\", content: [{ type: \"text\", text }] });\n }\n }\n return messages;\n}\n\n/** Responses mirror: the live /v1/responses request carries the system\n * prompt in the top-level `instructions` field and the conversation as an\n * `input` item array (issue #64, responses variant). Assistant blocks are\n * emitted in content order so the core sequence matches the live wire\n * (issue #103 parity). */\nexport function mirrorResponsesInput(view: MirrorMessage[]): Array<Record<string, unknown>> {\n const input: Array<Record<string, unknown>> = [];\n for (const message of view) {\n if (message.role === \"user\") {\n const text = joinText(message.blocks);\n if (text) input.push({ type: \"message\", role: \"user\", content: [{ type: \"input_text\", text }] });\n } else if (message.role === \"assistant\") {\n for (const b of message.blocks ?? []) {\n if (b.type === \"thinking\" && b.thinking.trim().length > 0) {\n input.push({ type: \"reasoning\", summary: [{ type: \"summary_text\", text: b.thinking }] });\n } else if (b.type === \"text\" && b.text.trim().length > 0) {\n input.push({ type: \"message\", role: \"assistant\", content: [{ type: \"output_text\", text: b.text }] });\n } else if (b.type === \"toolCall\") {\n let args = \"{}\";\n try {\n args = JSON.stringify(b.arguments ?? {});\n } catch {\n args = \"{}\";\n }\n input.push({ type: \"function_call\", call_id: b.id ?? \"\", name: b.name ?? \"\", arguments: args });\n }\n }\n } else if (message.role === \"toolResult\") {\n input.push({ type: \"function_call_output\", call_id: message.toolCallId ?? \"\", output: joinText(message.blocks) });\n } else {\n const text = message.text ?? \"\";\n if (text) input.push({ type: \"message\", role: \"user\", content: [{ type: \"input_text\", text }] });\n }\n }\n return input;\n}\n\n/** Fold the openai mirror through `openaiToCore`. */\nexport function mirrorOpenaiToCore(view: MirrorMessage[], systemText: string): BiliMessage[] {\n const { msgs } = openaiToCore({\n model: \"prime-fold\",\n messages: mirrorOpenaiMessages(view, systemText) as Parameters<typeof openaiToCore>[0][\"messages\"],\n });\n return msgs;\n}\n\n/** Fold the anthropic mirror through `anthropicToCore`. */\nexport function mirrorAnthropicToCore(view: MirrorMessage[]): BiliMessage[] {\n const { msgs } = anthropicToCore({\n model: \"prime-fold\",\n messages: mirrorAnthropicMessages(view) as Parameters<typeof anthropicToCore>[0][\"messages\"],\n });\n return msgs;\n}\n\n/** Fold the responses mirror through `responsesToCore`. */\nexport function mirrorResponsesToCore(view: MirrorMessage[], systemText: string): BiliMessage[] {\n const { msgs } = responsesToCore({\n model: \"prime-fold\",\n instructions: systemText,\n input: mirrorResponsesInput(view) as Parameters<typeof responsesToCore>[0][\"input\"],\n });\n return msgs;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAKpB,SAAS,OAAO,GAAmB;AACtC,SAAO,WAAW,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE;AAC3E;;;ACwBO,SAAS,gBACZ,MACA,aACA,MACA,UAGI,CAAC,GACC;AACN,QAAM,OAAO,GAAG,IAAI,IAAI,WAAW,IAAI,QAAQ,cAAc,EAAE,IAAI,QAAQ,YAAY,EAAE,IAAI,IAAI;AACjG,SAAO,OAAO,OAAO,IAAI;AAC7B;AAOO,IAAM,iBAAN,MAAqB;AAAA,EAChB,SAAS,oBAAI,IAAoB;AAAA,EAEzC,KAAK,QAAwB;AACzB,UAAM,IAAI,KAAK,OAAO,IAAI,MAAM,KAAK;AACrC,SAAK,OAAO,IAAI,QAAQ,IAAI,CAAC;AAC7B,WAAO,MAAM,IAAI,SAAS,GAAG,MAAM,IAAI,CAAC;AAAA,EAC5C;AACJ;;;ACZO,SAAS,cAAc,QAAgD;AAC1E,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO,WAAW,SAAU,QAAO;AACvC,SAAO,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,MAAM;AAChD;AAEO,S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SAAS,EAAE,MAAM,IAAI,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK,CAAC;AAAA,QAClG;AAAA,MACJ;AAAA,IACJ,WAAW,QAAQ,SAAS,cAAc;AACtC,YAAM,KAAK,EAAE,MAAM,wBAAwB,SAAS,QAAQ,cAAc,IAAI,QAAQ,SAAS,QAAQ,MAAM,EAAE,CAAC;AAAA,IACpH,OAAO;AACH,YAAM,OAAO,QAAQ,QAAQ;AAC7B,UAAI,KAAM,OAAM,KAAK,EAAE,MAAM,WAAW,MAAM,QAAQ,SAAS,CAAC,EAAE,MAAM,cAAc,KAAK,CAAC,EAAE,CAAC;AAAA,IACnG;AAAA,EACJ;AACA,SAAO;AACX;AAGO,SAAS,mBAAmB,MAAuB,YAAmC;AACzF,QAAM,EAAE,KAAK,IAAI,aAAa;AAAA,IAC1B,OAAO;AAAA,IACP,UAAU,qBAAqB,MAAM,UAAU;AAAA,EACnD,CAAC;AACD,SAAO;AACX;AAGO,SAAS,sBAAsB,MAAsC;AACxE,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAAA,IAC7B,OAAO;AAAA,IACP,UAAU,wBAAwB,IAAI;AAAA,EAC1C,CAAC;AACD,SAAO;AACX;AAGO,SAAS,sBAAsB,MAAuB,YAAmC;AAC5F,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAAA,IAC7B,OAAO;AAAA,IACP,cAAc;AAAA,IACd,OAAO,qBAAqB,IAAI;AAAA,EACpC,CAAC;AACD,SAAO;AACX;","names":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { BiliMessage } from "./bili-message.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mirror constructors: rebuild the WIRE-SHAPE projection of a persisted
|
|
4
|
+
* conversation (the mirror of "what the host will put on the wire after a
|
|
5
|
+
* restart") for each protocol family, then fold it through the matching
|
|
6
|
+
* `*ToCore` codec so the projection lands in the same identity/fingerprint
|
|
7
|
+
* space as the live request.
|
|
8
|
+
*
|
|
9
|
+
* This used to live as three hand-rolled builders in the omp plugin
|
|
10
|
+
* (wire-fold.ts) — protocol knowledge scattered across consumers is exactly
|
|
11
|
+
* how the issue-#64 class of restart divergences happened (one place fixed,
|
|
12
|
+
* another broke). The wire layouts now live here, next to the codecs that
|
|
13
|
+
* define their identity space.
|
|
14
|
+
*
|
|
15
|
+
* CONTRACT: the caller maps its own persisted message shape into
|
|
16
|
+
* {@link MirrorMessage} FIRST and normalizes text there (e.g. ref-tag
|
|
17
|
+
* stripping is a host-app concern, not a wire concern). Builders only apply
|
|
18
|
+
* host-encoder wire rules:
|
|
19
|
+
* - thinking rides each wire the way the live encoder sends it
|
|
20
|
+
* (openai: `reasoning_content` field — hosts that demote inline as
|
|
21
|
+
* `<think>…</think>` land in the same identity space anyway because
|
|
22
|
+
* `openaiToCore` normalizes the inline form; anthropic: signed
|
|
23
|
+
* `{type:"thinking"}` blocks; responses: `{type:"reasoning"}` items);
|
|
24
|
+
* - whitespace-only text survives on the openai wire, is dropped on the
|
|
25
|
+
* anthropic/responses wires (host encoder behaviour);
|
|
26
|
+
* - tool calls/results map to each wire's native shape.
|
|
27
|
+
*/
|
|
28
|
+
export type MirrorBlock = {
|
|
29
|
+
type: "text";
|
|
30
|
+
text: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "thinking";
|
|
33
|
+
thinking: string;
|
|
34
|
+
signature?: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "toolCall";
|
|
37
|
+
id?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
arguments?: unknown;
|
|
40
|
+
};
|
|
41
|
+
export type MirrorMessage = {
|
|
42
|
+
/** `meta` is anything the host sends as out-of-band/system-ish traffic. */
|
|
43
|
+
role: "user" | "assistant" | "toolResult" | "meta";
|
|
44
|
+
blocks?: MirrorBlock[];
|
|
45
|
+
/** toolResult only. */
|
|
46
|
+
toolCallId?: string;
|
|
47
|
+
/** meta only: extracted text or summary. */
|
|
48
|
+
text?: string;
|
|
49
|
+
};
|
|
50
|
+
/** Openai/completions mirror: system message first, then the conversation
|
|
51
|
+
* with thinking as the `reasoning_content` field (issue #103). */
|
|
52
|
+
export declare function mirrorOpenaiMessages(view: MirrorMessage[], systemText: string): Array<Record<string, unknown>>;
|
|
53
|
+
/** Anthropic/messages mirror: no system message (the live request carries it
|
|
54
|
+
* as the top-level `system` field, out of the fold space — issue #64), tool
|
|
55
|
+
* results folded into user messages, thinking as signed `{type:"thinking"}`
|
|
56
|
+
* blocks (issue #103). Unsigned thinking is demoted to text by the live
|
|
57
|
+
* encoder; sending it as a thinking block diverges, so callers that persist
|
|
58
|
+
* unsigned thinking should send it as a text block instead. */
|
|
59
|
+
export declare function mirrorAnthropicMessages(view: MirrorMessage[]): Array<Record<string, unknown>>;
|
|
60
|
+
/** Responses mirror: the live /v1/responses request carries the system
|
|
61
|
+
* prompt in the top-level `instructions` field and the conversation as an
|
|
62
|
+
* `input` item array (issue #64, responses variant). Assistant blocks are
|
|
63
|
+
* emitted in content order so the core sequence matches the live wire
|
|
64
|
+
* (issue #103 parity). */
|
|
65
|
+
export declare function mirrorResponsesInput(view: MirrorMessage[]): Array<Record<string, unknown>>;
|
|
66
|
+
/** Fold the openai mirror through `openaiToCore`. */
|
|
67
|
+
export declare function mirrorOpenaiToCore(view: MirrorMessage[], systemText: string): BiliMessage[];
|
|
68
|
+
/** Fold the anthropic mirror through `anthropicToCore`. */
|
|
69
|
+
export declare function mirrorAnthropicToCore(view: MirrorMessage[]): BiliMessage[];
|
|
70
|
+
/** Fold the responses mirror through `responsesToCore`. */
|
|
71
|
+
export declare function mirrorResponsesToCore(view: MirrorMessage[], systemText: string): BiliMessage[];
|
|
72
|
+
//# sourceMappingURL=mirror.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mirror.d.ts","sourceRoot":"","sources":["../../src/wire/mirror.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;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3D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,WAAW,EAAE,CAM1E;AAED,2DAA2D;AAC3D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,EAAE,CAO9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/wire/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/wire/openai.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEnE,MAAM,MAAM,iBAAiB,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC7D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,iBAAiB,EAAE,CAAC;IAC9C,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC;AAEpC,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAiG1D;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,aAAa,EAAE,CA4DrE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAU9F;AAED;;uEAEuE;AACvE,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAK9F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/wire/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/wire/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa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