/** * Pi-native wire format for the auth-gateway. * * Where the OpenAI / Anthropic / Responses route modules translate foreign * wire shapes through pi-ai's canonical {@link Context}, this module accepts * the canonical shape *directly* — for clients that already speak pi-ai * (containerized GJC deployments and sidecar auth gateways). * Skipping the wire-format → Context → wire-format round-trip cuts * per-request CPU but, more importantly, avoids the quantization that those * translations impose on first-class pi-ai fields (service tier, cache * markers, thinking budgets, tool-choice variants, …). * * The streaming wire is {@link AssistantMessageEvent} serialized as SSE. Public * projections omit private raw reasoning and serialized Responses reasoning * signatures while preserving provider-displayable summaries and genuine opaque * signatures. Including `partial: AssistantMessage` on every delta is O(N²) in * turn length on the wire — acceptable for the loopback / sidecar topology this * transport is designed for; provider latency dominates the actual cost. * * Endpoint contract: * POST /v1/pi/stream * body: { modelId, context, options?, stream? } // `stream` defaults to true * 200 SSE: stream of `AssistantMessageEvent` (terminated by `data: [DONE]`) * 200 JSON (stream=false): { message: AssistantMessage } * 4xx/5xx: { error: { type, message } } */ import type { AssistantMessageEventStream, Context, SimpleStreamOptions } from "../types"; export interface PiNativeParsedRequest { modelId: string; context: Context; options: SimpleStreamOptions; stream: boolean; } /** * Parse a pi-native request body. Validation is intentionally minimal — only * the shape the gateway itself reads is checked (`modelId`, `context.messages` * array, options is an object). Everything downstream is the canonical pi-ai * type surface; mis-shaped values surface as a `502 upstream_error` from * `streamSimple` rather than being re-validated here. * * Accepts both `{ modelId: string }` and `{ model: { id: string } }` so the * existing `streamProxy` client (which sends the full Model object) can target * the gateway with only a URL swap. */ export declare function parseRequest(body: unknown, _headers?: Headers): PiNativeParsedRequest; /** * Ship only public-safe {@link AssistantMessageEvent} projections. Unknown * thinking blocks remain buffered until their terminal partial establishes that * the provider-native block is safe; raw and mixed blocks never reach SSE. */ export declare function encodeStream(events: AssistantMessageEventStream): ReadableStream; /** * Pi-native error envelope: * `{ error: { type, message } }` * * Mirrors OpenAI's outer shape (which clients/SDKs already parse) without the * provider-specific status taxonomy — pi-native callers consume `type` * directly. */ export declare function formatError(status: number, type: string, message: string): Response;