/** * Did a provider stream open with a usable response, and what did it say it was? * * Moved out of `backend.ts` unchanged (HOTSPOT-10). The bodies below are byte-identical to the * ones that lived there; only the three names `backend.ts` still calls became exports. * * Two jobs, kept together because the preflight performs both in one pass over the same bytes: * * - **Preflight.** Read up to `STREAM_PREFLIGHT_LIMIT` bytes looking for the first data event, * validate it, then REPLAY every consumed byte to the consumer. A stream that opens with an * in-band error is a dead turn, so failing it here is what lets the candidate walk reach a * member that answers instead of spending the pool inside one member's 200. * - **Provenance.** Record what the upstream called itself, so a served response can be logged * against the model that actually answered rather than the one that was routed to. * * ⚠ The metadata is process-local, never a wire header. It is declared here because the preflight * is what fills it; `backend.ts` keeps the `WeakMap` that binds it to a `Response`. * * ⚠ Nothing here imports `backend.js`, and nothing may. This module sits beneath the transport it * probes for, exactly like `envelope-validator.ts` beside it. */ import { type ResponseProtocol } from "./envelope-validator.js"; export interface UpstreamResponseMetadata { reportedModel?: string; /** * How many `tool_use` ids the relay had to mint for this response (`tool-use-ids.ts`). Mutable * after the Response exists on purpose: on a stream the pass runs while the body drains, and the * server reads this where it reports end-of-stream facts. A count, never an id. */ toolUseIdRewrites?: number; /** * How many OUTBOUND tool-call ids the request mapper rewrote to this provider's stated shape * (`openai-request.ts`, `compat.toolCallIds: "strict9"`). A count, never an id. Known before * egress, so it is set once when the metadata is built. */ toolCallIdRewrites?: number; /** * How many replayed tool calls the request mapper stamped with gemini's documented * thought-signature sentinel (`openai-request.ts`, `compat.thoughtSignature: "sentinel"`). A * count, never a signature. Known before egress, like `toolCallIdRewrites`. * * Deliberately NOT announced as a response header: this one adds vendor-protocol padding to the * relay's own outbound shape and changes nothing about the caller's data, so the operator sees * it in the log and the client is told nothing it could act on. */ thoughtSignatureSentinels?: number; } type StreamPreflight = { ok: true; body: ReadableStream; metadata: UpstreamResponseMetadata; } | { ok: false; reason: string; }; export declare function captureReportedModel(metadata: UpstreamResponseMetadata, value: unknown, protocol: ResponseProtocol, streamed: boolean): void; /** Inspect the first data event before handing a provider stream to llm-bridge. */ export declare function preflightResponseStream(body: ReadableStream, protocol: ResponseProtocol): Promise; export {};