/** * Responses egress shared builders (spec §16.5): the item/usage/terminal * constructors used by both the JSON envelope and the SSE encoder. Pure * functions — bounds enforcement and event lifecycle live in the accumulator * below and in `responses-stream.ts`. Nothing here fabricates counts or ids. */ import type { FinishReason, GenerateResponse, StreamEvent, TokenUsage, ToolCall } from '@sentropic/llm-mesh'; /** Engineering-default operation bounds (spec §16.7); a stricter host limit wins. */ export interface ResponsesLimits { readonly maxBodyBytes: number; readonly maxInputItems: number; readonly maxTools: number; readonly maxOutputItems: number; readonly maxSseEventBytes: number; readonly maxAccumulatedBytes: number; } export declare const DEFAULT_RESPONSES_LIMITS: ResponsesLimits; /** * Resolve validated host overrides against the spec defaults. Each field * takes the stricter (lower) of the default and the override; a * non-finite or non-positive override fails fast at router construction. * Unknown keys are ignored. */ export declare const resolveResponsesLimits: (overrides?: { readonly [key: string]: unknown; }) => ResponsesLimits; /** Overflow or protocol breach: aborts upstream and fails neutrally, never truncates silently. */ export declare class ResponsesBoundError extends Error { readonly code: 'responses_overflow' | 'responses_protocol'; constructor(code: ResponsesBoundError['code'], message: string); } export type ResponsesStatus = 'completed' | 'incomplete' | 'failed'; export declare const responsesTerminal: (finishReason: FinishReason) => { status: ResponsesStatus; incomplete_details: { reason: string; } | null; }; /** * Provider usage mapped to the Responses shape with native detail preserved * through `providerRawUsage` (cached input tokens, reasoning output * tokens). Total is provider-reported or computed from known components. * Fully unknown usage is null, and a partially known usage carries only its * known components — never a fabricated exact zero (spec §16.5, R4-MIN-4). */ export declare const responsesUsage: (usage?: TokenUsage) => { input_tokens?: number; output_tokens?: number; total_tokens?: number; input_tokens_details?: { cached_tokens: number; }; output_tokens_details?: { reasoning_tokens: number; }; } | null; export declare const messageItem: (id: string, text: string) => Record; export declare const functionCallItem: (id: string, call: Pick) => Record; export declare const reasoningItem: (id: string, summaryText: string) => Record; export interface ResponsesSnapshot { readonly items: readonly Record[]; readonly terminal: { finishReason: FinishReason; }; readonly usage?: TokenUsage; readonly failure?: { message: string; code?: string; type?: string; }; } /** Item allocation for one observed event: stable id, positional output index. */ export interface ResponsesAllocation { readonly itemId: string; readonly outputIndex: number; /** True when this observation created the item. */ readonly isNew: boolean; /** True when this observation replaced previously buffered content. */ readonly replaced: boolean; } export interface ResponsesAccumulator { observe(event: StreamEvent): ResponsesAllocation | undefined; ingest(response: GenerateResponse): void; snapshot(): ResponsesSnapshot; } /** * Shared bounded output accumulator for the JSON envelope and the SSE * encoder (spec §16.5): first-observation allocation with stable ids, * snapshot-wins dedup, bounded growth. Overflow or unknown call ids throw * `ResponsesBoundError` — abort upstream and fail neutrally. */ export declare const createResponsesAccumulator: (limits?: ResponsesLimits) => ResponsesAccumulator; /** * JSON envelope (spec §16.5): `object:"response"` with stable id, * `created_at`, served model, ordered output, terminal status, usage and * `store:false`. Content-filter keeps an actual refusal when the turn * produced text; unknown/error termination is a failed envelope. */ /** * Refusal conversion shared by the JSON envelope and the SSE item closure: * a content-filtered turn keeps an actual refusal part when it produced * text, never an invented one. */ export declare const finalizeMessageItem: (item: Record, finishReason: FinishReason) => Record; /** Envelope assembly from a terminal snapshot, shared by JSON and SSE terminals. */ export declare const envelopeFromSnapshot: (input: { responseId: string; model: string; createdAt: number; snap: ResponsesSnapshot; }) => Record; export declare const buildResponsesJson: (input: { responseId: string; model: string; createdAt?: number; response: GenerateResponse; failure?: { message: string; code?: string; type?: string; }; limits?: ResponsesLimits; }) => Record; //# sourceMappingURL=responses-egress.d.ts.map