import type OpenAI from "openai"; import type { ResponseInput, ResponseInputContent, ResponseOutputItem } from "openai/resources/responses/responses"; import { type Api, type AssistantMessage, type ImageContent, type Model, type ServiceTier, type StopReason, type StreamOptions, type TextContent, type TextSignatureV1, type ToolCall, type ToolResultMessage } from "../types"; import type { AssistantMessageEventStream } from "../utils/event-stream"; export declare function isOpenAIResponsesProgressEvent(event: unknown): boolean; export declare function encodeTextSignatureV1(id: string, phase?: TextSignatureV1["phase"]): string; export declare function parseTextSignature(signature: string | undefined): { id: string; phase?: TextSignatureV1["phase"]; } | undefined; export declare function encodeResponsesToolCallId(callId: string, itemId: string | null | undefined): string; export declare function normalizeResponsesToolCallIdForTransform(id: string, model?: Model, source?: AssistantMessage): string; export declare function collectKnownCallIds(messages: ResponseInput): Set; /** Scan replay items for call_ids that were originally custom tool calls. */ export declare function collectCustomCallIds(messages: ResponseInput): Set; /** * Convert orphan `function_call_output` / `custom_tool_call_output` items — * those whose `call_id` has no matching preceding `function_call` / * `custom_tool_call` in the same input — into assistant text notes. * * The Responses API rejects unpaired outputs with * `400 No tool call found for function call output with call_id …`. Orphans * sneak in through two paths today: * * - A previous turn's `providerPayload` snapshot replaces the input array via * the `dt: false` splice (see {@link convertConversationMessages}), wiping * the matching `function_call` while leaving the matching * `function_call_output` queued in a later `toolResult`. * - A locally-rejected tool call (argument-validation failure, hook reject, * aborted turn before the call streamed) produces a tool result without a * `function_call` ever landing in any persisted provider payload. * * Dropping the result loses information the model needs to recover; sending * it as-is 400s the request. Folding it into an assistant `message` preserves * the payload (call_id + truncated output) while staying within the Responses * input grammar. Matches the behavior of {@link transformRequestBody} in the * OpenAI code backend provider — issue #1351 / regression of #472. */ export declare function repairOrphanResponsesToolOutputs(input: ResponseInput): ResponseInput; export declare function convertResponsesInputContent(content: string | Array, supportsImages: boolean): ResponseInputContent[] | undefined; export declare function convertResponsesAssistantMessage(assistantMsg: AssistantMessage, model: Model, msgIndex: number, knownCallIds: Set, includeThinkingSignatures?: boolean, customCallIds?: Set): ResponseInput; export declare function appendResponsesToolResultMessages(messages: ResponseInput, toolResults: readonly ToolResultMessage[], model: Model, strictResponsesPairing: boolean, knownCallIds: ReadonlySet, customCallIds?: ReadonlySet): void; export interface ProcessResponsesStreamOptions { onFirstToken?: () => void; onOutputItemDone?: (item: ResponseOutputItem) => void; } export declare function processResponsesStream(openaiStream: AsyncIterable, output: AssistantMessage, stream: AssistantMessageEventStream, model: Model, options?: ProcessResponsesStreamOptions): Promise; /** * Mark tool-call blocks left incomplete by a length-truncated response so the * agent loop rejects them instead of executing a best-effort partial parse. * * The universal signal is finalization: a call that never received its terminal * `output_item.done` (passed in via `isFinalized`) was cut off mid-arguments. * This covers both JSON function calls and raw-input custom tools without * mis-flagging a *completed* custom tool whose raw input is not valid JSON. As a * defensive secondary, a finalized JSON function call whose buffered arguments * still don't parse (e.g. a misbehaving relay) is flagged too. No-op unless the * turn stopped for length. * * Shared by both Responses providers (`openai-responses`, `openai-codex-responses`). */ export declare function flagTruncatedToolCalls(output: AssistantMessage, stopReason: StopReason, isFinalized: (block: ToolCall) => boolean): void; export declare function mapOpenAIResponsesStopReason(status: OpenAI.Responses.ResponseStatus | undefined): StopReason; /** Initial empty `AssistantMessage` that streaming providers accumulate into. */ export declare function createInitialResponsesAssistantMessage(api: Api, provider: string, modelId: string): AssistantMessage; /** Extension fields we add on top of `ResponseCreateParamsStreaming` across the Responses-family providers. */ export type ResponsesSamplingParamsExtras = { top_p?: number; top_k?: number; min_p?: number; presence_penalty?: number; repetition_penalty?: number; }; type CommonResponsesParams = OpenAI.Responses.ResponseCreateParamsStreaming & ResponsesSamplingParamsExtras; type CommonSamplingOptions = Pick & { serviceTier?: ServiceTier; }; /** * Apply the common `StreamOptions` → Responses sampling-parameter mapping (max output tokens, * temperature, top-p/k, min-p, presence/repetition penalties, service tier). Mutates `params`. */ export declare function applyCommonResponsesSamplingParams

(params: P, options: CommonSamplingOptions | undefined, provider: string, supportsServiceTier?: boolean): void; type ReasoningOptions = { reasoning?: string; reasoningSummary?: "auto" | "detailed" | "concise" | null; }; /** * Apply reasoning-related Responses parameters: enable encrypted reasoning content for replay, * set effort/summary when requested, and otherwise inject the GPT-5 "Juice: 0" no-reasoning hack. * Mutates `params` and may push a developer message into `messages`. */ export declare function applyResponsesReasoningParams

(params: P, model: Model, options: ReasoningOptions | undefined, messages: ResponseInput, mapEffort?: (effort: string) => string): void; /** Populate `output.usage` from a Responses-API `response.usage` payload. Does not invoke `calculateCost`. */ export declare function populateResponsesUsageFromResponse(output: AssistantMessage, usage: { input_tokens?: number | null; output_tokens?: number | null; total_tokens?: number | null; input_tokens_details?: { cached_tokens?: number | null; cache_write_tokens?: number | null; } | null; output_tokens_details?: { reasoning_tokens?: number | null; } | null; } | null | undefined): void; export {};