acp-kernel 0.0.27 → 0.0.28

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.
@@ -37,5 +37,13 @@ export declare function computeProtectedRefs(messages: CoreMessage[], state: Com
37
37
  * survives as its own range.
38
38
  */
39
39
  export declare function buildCompressibleRanges(messages: CoreMessage[], state: CompressionState, config: Config, protectedZoneRefs?: Set<string>, countTokens?: (text: string) => number): ContextRanges;
40
+ /** Merge adjacent ranges into batches that clear `minChars` of REAL text —
41
+ * the same accounting `applyCompression` uses — so a recommended range is
42
+ * never below the threshold the kernel would atomically reject. Batching by
43
+ * token estimates (tokens*4) instead broke whenever the host injected a
44
+ * tokenizer where tokens != chars/4 (CJK-aware estimators are ~1:1, so
45
+ * tokens*4 overestimated size ~4x and nudge recommended ranges the apply
46
+ * side then refused). A sub-threshold tail batch is still emitted — callers
47
+ * filter by effectiveness separately (see pendingByTier). */
40
48
  export declare function mergeRangesToThreshold(ranges: CompressibleRange[], minChars: number): CompressibleRange[];
41
49
  //# sourceMappingURL=recommend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../src/recommend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EACN,aAAa,EACb,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAsCnD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,GAAG,CAAC,MAAM,CAAC,CAwDb;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC/B,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,aAAa,CA4Hf;AAwBD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,iBAAiB,EAAE,EAC3B,QAAQ,EAAE,MAAM,GACf,iBAAiB,EAAE,CAgBrB"}
1
+ {"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../src/recommend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EACN,aAAa,EACb,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAsCnD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,GAAG,CAAC,MAAM,CAAC,CAwDb;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC/B,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,aAAa,CAgIf;AAiCD;;;;;;;8DAO8D;AAC9D,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,iBAAiB,EAAE,EAC3B,QAAQ,EAAE,MAAM,GACf,iBAAiB,EAAE,CAkBrB"}
@@ -0,0 +1,9 @@
1
+ export type TransformChannel = "message" | "wire";
2
+ /**
3
+ * Pick the transform channel: an explicit preference always wins; otherwise
4
+ * the wire channel is used only when the caller's host actually applies the
5
+ * wire-payload replacement (adapters pass `wireViable` — e.g. the body format
6
+ * is in WIRE_FORMATS and the host honors the hook's return value).
7
+ */
8
+ export declare function resolveTransformChannel(explicit: TransformChannel | undefined, wireViable: boolean): TransformChannel;
9
+ //# sourceMappingURL=transform-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-channel.d.ts","sourceRoot":"","sources":["../src/transform-channel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,MAAM,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,EACtC,UAAU,EAAE,OAAO,GAClB,gBAAgB,CAElB"}
package/dist/types.d.ts CHANGED
@@ -134,6 +134,15 @@ export interface CompressibleRange {
134
134
  endRef: string;
135
135
  count: number;
136
136
  tokens: number;
137
+ /** Range size in characters (sum of message text lengths). The apply-side
138
+ * minCompressRange gate counts raw `msg.text.length`, so recommend-side
139
+ * gates must use this field — NOT `tokens` — or the two sides disagree
140
+ * whenever a host injects a tokenizer where tokens != chars/4 (e.g. a
141
+ * CJK-aware estimator: 1 token per char, making `tokens*4` a ~4x
142
+ * overestimate). Always set on ranges produced by buildCompressibleRanges
143
+ * / mergeRangesToThreshold; hand-built ranges without it fall back to the
144
+ * historical tokens*4 estimate for backwards compat. */
145
+ chars?: number;
137
146
  toolPct: number;
138
147
  textPct: number;
139
148
  dangerous?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,kBAAkB,GAC5B,MAAM,GAAG,WAAW,GAAG,aAAa,GAAG,WAAW,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,I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S,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC"}
@@ -0,0 +1,10 @@
1
+ export declare const WIRE_FORMATS: readonly ["anthropic", "openai", "responses"];
2
+ export type WireFormat = (typeof WIRE_FORMATS)[number];
3
+ export declare function isWireFormat(value: unknown): value is WireFormat;
4
+ /**
5
+ * Classify a provider request body by the codec that can parse it.
6
+ * Returns undefined when no codec handles the body — the caller must
7
+ * pass such payloads through untransformed.
8
+ */
9
+ export declare function detectWireFormat(payload: unknown): WireFormat | undefined;
10
+ //# sourceMappingURL=formats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/wire/formats.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,+CAAgD,CAAC;AAC1E,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAKhE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CA+BzE"}
@@ -1,6 +1,7 @@
1
1
  export * from "./anthropic.js";
2
2
  export * from "./openai.js";
3
3
  export * from "./responses.js";
4
+ export * from "./formats.js";
4
5
  export * from "./bili-message.js";
5
6
  export * from "./message-id.js";
6
7
  export * from "./util.js";
@@ -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,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,WAAW,CAAC"}
@@ -651,19 +651,60 @@ function conversationIdentityResponses(body, headerValue) {
651
651
  function conversationSignalResponses(body, headerValue) {
652
652
  return conversationIdentityResponses(body, headerValue).value;
653
653
  }
654
- var instructionAnchors = /* @__PURE__ */ new Map();
654
+ function createSubagentNamespaces() {
655
+ const anchors = /* @__PURE__ */ new Map();
656
+ return {
657
+ namespaceFor(identityValue, instructions) {
658
+ if (typeof instructions !== "string" || instructions.trim().length === 0) return identityValue;
659
+ const fp = hashId(instructions);
660
+ const anchor = anchors.get(identityValue);
661
+ if (anchor === void 0) {
662
+ anchors.set(identityValue, fp);
663
+ return identityValue;
664
+ }
665
+ return anchor === fp ? identityValue : `${identityValue}|sub:${fp}`;
666
+ }
667
+ };
668
+ }
669
+ var defaultNamespaces = createSubagentNamespaces();
655
670
  function subagentNamespace(identityValue, instructions) {
656
- if (typeof instructions !== "string" || instructions.trim().length === 0) return identityValue;
657
- const fp = hashId(instructions);
658
- const anchor = instructionAnchors.get(identityValue);
659
- if (anchor === void 0) {
660
- instructionAnchors.set(identityValue, fp);
661
- return identityValue;
671
+ return defaultNamespaces.namespaceFor(identityValue, instructions);
672
+ }
673
+
674
+ // src/wire/formats.ts
675
+ var WIRE_FORMATS = ["anthropic", "openai", "responses"];
676
+ function isWireFormat(value) {
677
+ return typeof value === "string" && WIRE_FORMATS.includes(value);
678
+ }
679
+ function detectWireFormat(payload) {
680
+ if (payload === null || typeof payload !== "object") return void 0;
681
+ const p = payload;
682
+ if (Array.isArray(p.input)) return "responses";
683
+ const messages = p.messages;
684
+ if (!Array.isArray(messages)) return void 0;
685
+ if ("system" in p || "anthropic_version" in p) return "anthropic";
686
+ for (const m of messages) {
687
+ if (m === null || typeof m !== "object") continue;
688
+ const c = m.content;
689
+ if (Array.isArray(c)) {
690
+ for (const b of c) {
691
+ if (b && typeof b === "object" && typeof b.type === "string") {
692
+ if (b.type === "tool_use" || b.type === "tool_result" || b.type === "thinking")
693
+ return "anthropic";
694
+ if (b.type === "text" && "cache_control" in b) return "anthropic";
695
+ }
696
+ }
697
+ }
698
+ if (Array.isArray(m.tool_calls)) return "openai";
699
+ if (m.role === "tool" && typeof m.tool_call_id === "string")
700
+ return "openai";
701
+ if (m.role === "system" || m.role === "developer") return "openai";
662
702
  }
663
- return anchor === fp ? identityValue : `${identityValue}|sub:${fp}`;
703
+ return "openai";
664
704
  }
665
705
  export {
666
706
  ClusterCounter,
707
+ WIRE_FORMATS,
667
708
  anthropicToCore,
668
709
  buildSystem,
669
710
  conversationIdentityResponses,
@@ -673,11 +714,14 @@ export {
673
714
  coreToAnthropic,
674
715
  coreToOpenai,
675
716
  coreToResponses,
717
+ createSubagentNamespaces,
676
718
  deriveMessageId,
719
+ detectWireFormat,
677
720
  extractSystem,
678
721
  hashId,
679
722
  injectOpenaiSystem,
680
723
  injectResponsesDeveloperMessage,
724
+ isWireFormat,
681
725
  openaiToCore,
682
726
  parseDataUrl,
683
727
  patchResponsesInput,
@@ -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"],"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}\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 img = firstImagePart(m.content);\n const base = deriveMessageId(\"user\", \"text\", text);\n msgs.push({\n id: clusters.next(base),\n role: \"user\",\n contentType: \"text\",\n text,\n ...(img ? { rawOpenaiContent: img.part, imageMediaType: img.mediaType, imageBase64: img.base64 } : {}),\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) {\n const parts: OpenAIContentPart[] = [];\n if (m.text) parts.push({ type: \"text\", text: m.text });\n 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\nfunction firstImagePart(content: OpenAIMessage[\"content\"]): { part: OpenAIContentPart; mediaType: string; base64: string } | undefined {\n if (!Array.isArray(content)) return undefined;\n for (const p of content) {\n if (p && typeof p === \"object\" && p.type === \"image_url\") {\n const iu = (p as { image_url?: { url?: string } }).image_url;\n const url = iu?.url;\n if (typeof url === \"string\") {\n const parsed = parseDataUrl(url);\n if (parsed) return { part: p, mediaType: parsed.mediaType, base64: parsed.base64 };\n }\n }\n }\n return undefined;\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\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 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\", \"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. Unbounded growth is fine: one ~100-byte entry\n// per conversation identity.\nconst instructionAnchors = new Map<string, string>();\n\nexport function subagentNamespace(identityValue: string, instructions: unknown): string {\n if (typeof instructions !== \"string\" || instructions.trim().length === 0) return identityValue;\n const fp = hashId(instructions);\n const anchor = instructionAnchors.get(identityValue);\n if (anchor === undefined) {\n instructionAnchors.set(identityValue, fp);\n return identityValue;\n }\n return anchor === fp ? identityValue : `${identityValue}|sub:${fp}`;\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,OAA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C,CAAC,GAAG,QAAQ,uBAAuB,gBAAgB,MAAM;AACnH;AAEO,SAAS,4BAA4B,MAA4B,aAA8B;AAClG,SAAO,8BAA8B,MAAM,WAAW,EAAE;AAC5D;AAaA,IAAM,qBAAqB,oBAAI,IAAoB;AAE5C,SAAS,kBAAkB,eAAuB,cAA+B;AACpF,MAAI,OAAO,iBAAiB,YAAY,aAAa,KAAK,EAAE,WAAW,EAAG,QAAO;AACjF,QAAM,KAAK,OAAO,YAAY;AAC9B,QAAM,SAAS,mBAAmB,IAAI,aAAa;AACnD,MAAI,WAAW,QAAW;AACtB,uBAAmB,IAAI,eAAe,EAAE;AACxC,WAAO;AAAA,EACX;AACA,SAAO,WAAW,KAAK,gBAAgB,GAAG,aAAa,QAAQ,EAAE;AACrE;","names":[]}
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}\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 img = firstImagePart(m.content);\n const base = deriveMessageId(\"user\", \"text\", text);\n msgs.push({\n id: clusters.next(base),\n role: \"user\",\n contentType: \"text\",\n text,\n ...(img ? { rawOpenaiContent: img.part, imageMediaType: img.mediaType, imageBase64: img.base64 } : {}),\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) {\n const parts: OpenAIContentPart[] = [];\n if (m.text) parts.push({ type: \"text\", text: m.text });\n 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\nfunction firstImagePart(content: OpenAIMessage[\"content\"]): { part: OpenAIContentPart; mediaType: string; base64: string } | undefined {\n if (!Array.isArray(content)) return undefined;\n for (const p of content) {\n if (p && typeof p === \"object\" && p.type === \"image_url\") {\n const iu = (p as { image_url?: { url?: string } }).image_url;\n const url = iu?.url;\n if (typeof url === \"string\") {\n const parsed = parseDataUrl(url);\n if (parsed) return { part: p, mediaType: parsed.mediaType, base64: parsed.base64 };\n }\n }\n }\n return undefined;\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\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 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\", \"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"],"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,GAC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O,MAAM,YAAY,OAAO,EAAE,SAAS,UAAU;AAC5D,cACE,EAAE,SAAS,cACX,EAAE,SAAS,iBACX,EAAE,SAAS;AAEX,mBAAO;AACT,cAAI,EAAE,SAAS,UAAU,mBAAmB,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":[]}
@@ -78,6 +78,21 @@ export declare function coreToResponses(messages: CoreMessage[], customToolCallI
78
78
  export declare function injectResponsesDeveloperMessage(input: string | ResponseInputItem[], content: string): ResponseInputItem[];
79
79
  export declare function conversationIdentityResponses(body: ResponsesRequestBody, headerValue?: string): ConversationIdentity;
80
80
  export declare function conversationSignalResponses(body: ResponsesRequestBody, headerValue?: string): string;
81
+ export interface SubagentNamespaces {
82
+ /** Resolve the compression-state namespace for a request: the identity
83
+ * itself for the anchored (main) instructions, `identity|sub:<fp>` for
84
+ * any other instructions value. First-seen instructions anchor. */
85
+ namespaceFor(identityValue: string, instructions: unknown): string;
86
+ }
87
+ /** Host-owned subagent-namespace store.
88
+ *
89
+ * The anchor map is per-conversation mutable state, so it belongs to the
90
+ * host — NOT to a library module global. Create one instance and keep it for
91
+ * the process lifetime (or persist it alongside your session store if you
92
+ * need namespaces to survive restarts: a fresh instance re-anchors on the
93
+ * first request it sees, which after a restart may be a subagent request,
94
+ * orphaning the main conversation's stored compression state). */
95
+ export declare function createSubagentNamespaces(): SubagentNamespaces;
81
96
  export declare function subagentNamespace(identityValue: string, instructions: unknown): string;
82
97
  export {};
83
98
  //# sourceMappingURL=responses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/wire/responses.ts"],"names":[],"mappings":"AAAA,OA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E,EACnC,OAAO,EAAE,MAAM,GAChB,iBAAiB,EAAE,CAQrB;AAED,wBAAgB,6BAA6B,CACzC,IAAI,EAAE,oBAAoB,EAC1B,WAAW,CAAC,EAAE,MAAM,GACrB,oBAAoB,CAatB;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAEpG;AAYD,MAAM,WAAW,kBAAkB;IAC/B;;wEAEoE;IACpE,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,MAAM,CAAC;CACtE;AAED;;;;;;;kEAOkE;AAClE,wBAAgB,wBAAwB,IAAI,kBAAkB,CAc7D;AASD,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,MAAM,CAEtF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acp-kernel",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
5
5
  "license": "MIT",
6
6
  "author": "ranxianglei",