import { type BiliMessage, type MirrorMessage, type ResponsesProjection } from "acp-kernel/wire"; import { type CompressionState, type Config } from "acp-kernel"; import type { AgentMessage } from "./messages.js"; export type ProviderWireFormat = "anthropic" | "openai" | "responses"; /** Kernel format detection narrowed to the formats the omp pipeline can * rebuild onto the wire. null = fail-open (pass the payload through). * The kernel's detectWireFormat only recognizes `input` arrays as * "responses"; string inputs (a single user message) are also responses * bodies (the kernel's responsesToCore handles them), so we add that case. */ export declare function detectProviderWireFormat(payload: unknown): ProviderWireFormat | null; export declare function payloadToCore(payload: unknown, fmt: ProviderWireFormat): { msgs: BiliMessage[]; cacheControls?: Map; systemText?: string; }; /** Parse a responses body into the kernel's projection (layout + core pieces). * The projection is needed for the rebuild (patchResponsesInput) — it carries * the original item layout so the round-trip preserves opaque items and * patches text in place rather than rebuilding from scratch. */ export declare function responsesProjection(payload: unknown): ResponsesProjection; /** Rebuild the responses `input` from the projection + transformed core * messages. Returns a string when the original input was a string (and the * transform kept it a single user text piece); otherwise an item array. */ export declare function responsesRebuild(projection: ResponsesProjection, msgs: BiliMessage[]): string | unknown[]; export declare function coreToPayloadMessages(msgs: BiliMessage[], fmt: ProviderWireFormat, cacheControls?: Map): unknown[]; export type Representability = { ok: true; } | { ok: false; reason: string; }; /** Whether the payloadToCore → coreToPayloadMessages round-trip can rebuild * this payload WITHOUT content loss. The sets above mirror the kernel * codec switches; everything they do not parse is dropped or flattened on * the rebuild. Unrepresentable payloads must fail the transform OPEN — * pass through untouched rather than lose content (issue #3 review). */ export declare function payloadRepresentable(payload: unknown, fmt: ProviderWireFormat): Representability; /** Restore openai wire fields the kernel codec cannot carry (issue #105). * omp's buildParams emits assistant tool-call messages with content "" (a * null trips strict/proxy implementations) and replays encrypted reasoning * as reasoning_details keyed to the tool call ids. The codec rebuild drops * the details and flips "" back to null; this pass re-attaches both so the * post-surgery body keeps the host's wire contract. */ export declare function restoreOpenaiWireFidelity(originalMessages: unknown[], rebuilt: unknown[]): unknown[]; /** Re-attach the leading system/developer messages the kernel hoisted out of * the fold id space (acp-kernel 0.0.37). The rebuilt message list no longer * carries them; without this pass, a compression covering the old system * piece dropped the model's system prompt from the wire entirely (observed * on glm-5.3: post-compression requests went from systemLen 45151 to 0). * Original messages are re-attached verbatim so the host's wire shape — * system vs developer roles, message count, name fields — survives * byte-for-byte. Mirrors the anthropic path, where the top-level system * field never enters the fold at all. */ export declare function restoreOpenaiSystemPrefix(originalMessages: unknown[], rebuilt: unknown[]): unknown[]; export type WireTagRenderScope = { config: Config; tokenCount: number; }; /** omp's wire tag contract (issue #66) on top of the kernel's "text-only" * render: the proxy keeps tool content pristine, but omp's nudge ranges * target tool results — the model must be able to cite them by ref, so tag * the tool-result pieces (kernel renderer, format single-sourced). The * kernel's "text-only" also tags assistant text — strip it: the model * echoes tags it sees on its own responses (the contract patchRefTag * enforced in the AgentMessage bridge). Tool-call args stay clean (replay * JSON-parses them). * * Rendering goes through the kernel's render-refs NODE so token counts in * the tags come from the fold state's tokenSnapshot (written once per ref, * reused forever) instead of being recomputed per call; the updated * snapshot is written back into the fold state in place. Tool names are * re-attached from the call pieces first — the codecs drop them on * tool-result pieces and classifyType would render type="tool" where the * context path (and the system-prompt contract) shows the real name. */ export declare function applyWireTagContract(msgs: BiliMessage[], state: CompressionState, scope: WireTagRenderScope): BiliMessage[]; /** Stable cross-turn identity for the core-space LCP fold. The text carries * our own ref tags from the previous turn's output (the model sees * them and they ride back in the next request) — stripped before hashing * so re-folds of an unmutated prefix stay incremental. */ export declare function coreIdentity(msg: BiliMessage): string; export { toolCallNames, toolResultTextsCore, findCompressCallsCore, spanFingerprintCore, spanFingerprintCoreIdx, boundaryRawCore, boundaryIndexCore, refOfPieceCore, staleRangeCore, rangeFingerprintsCore, rangePositionsCore, } from "acp-kernel/wire"; export type { ReplayRangeVerdict } from "acp-kernel/wire"; /** Map the persisted session view onto the kernel's neutral MirrorMessage: * the only omp-side shape knowledge left in this module — ref-tag * stripping (a persisted-format concern, messages.ts) and the pi block * types. Every wire-shape rule (system placement, reasoning_content vs * thinking blocks vs summary_text, tool_result folding, whitespace * handling) lives single-sourced in the acp-kernel mirror constructors * (≥0.0.35, PR #114). */ export declare function toMirrorView(view: AgentMessage[]): MirrorMessage[]; /** primeFold openai/completions mirror (issue #64): system first, thinking * as the `reasoning_content` field (issue #103); inline `` hosts * land in the same identity space via kernel normalization (PR #112). */ export declare function viewToCoreStream(view: AgentMessage[], systemText: string): BiliMessage[]; /** primeFold anthropic/messages mirror (issue #64): system out of the fold * space, tool results folded into user messages, signed thinking blocks. */ export declare function viewToAnthropicCore(view: AgentMessage[]): BiliMessage[]; /** primeFold responses mirror (issue #64, responses variant): system in the * top-level `instructions` field, conversation as the `input` item array. */ export declare function viewToResponsesCore(view: AgentMessage[], systemText: string): BiliMessage[];