/** * OpenAI Responses codec. Pure request/response translation between the * Responses wire and the gateway's OpenAI Chat Completions core. Streaming * translation lives in `responses-stream.ts`; HTTP handling lives in * `responses.ts`. */ import type { OpenAiChatResponse } from "../providers/protocol.js"; import type { ResponsesRequest, ResponsesTool } from "./responses-wire.js"; import type { ExecutedSearch } from "./server-tool-loop.js"; export type { ResponsesInputItem, ResponsesRequest } from "./responses-wire.js"; export declare class ResponsesTranslationError extends Error { readonly code = "invalid_encrypted_reasoning_order"; constructor(message: string); } type OpenAiResponse = OpenAiChatResponse; /** * How a declared tool must be emitted when the model calls it: * - `function`: a plain `function_call` item (JSON-schema function tools, and * tools discovered mid-conversation via `tool_search_output`). * - `custom`: a `custom_tool_call` item carrying raw string input (freeform * tools like Codex's `apply_patch`). * - `typed`: the tool's own native item type (`_call`, e.g. * `tool_search_call`) — Codex dispatches these by payload shape, and a * `function_call` under the same name fails with "handler received * unsupported payload". * - `server`: a server-executed tool (`web_search`) the *gateway* runs via the * server-tool loop. Its calls never surface as callable items — the loop * intercepts them and the egress renders native `web_search_call` items. */ export type ResponsesToolKind = "function" | "custom" | "typed" | "server"; export type ResponsesToolEntry = { kind: ResponsesToolKind; /** * The tool's namespace, for tools *discovered* through a `tool_search` * execution (e.g. `spawn_agent` under `multi_agent_v1`). Codex routes a * discovered tool's `function_call` by name **and** namespace — without the * namespace the call fails with "unsupported call". */ namespace?: string; }; export type ResponsesToolRegistry = ReadonlyMap; /** * A declared server-executed web search tool (Codex's `{type: "web_search"}`, * or variants like `web_search_preview`). When a web-search executor is * available the gateway runs these itself (see `server-tool-loop.ts`); * otherwise they are dropped with a warning as before. */ export declare function isServerWebSearchTool(tool: ResponsesTool): boolean; /** The name the gateway-executed web search tool is projected under chat-side. */ export declare const WEB_SEARCH_TOOL_NAME = "web_search"; /** Options gating server-executed tool projection (on iff an executor exists). */ export type ResponsesTranslationOptions = { serverTools?: boolean; destinationWireShape?: string; }; /** * The per-request tool registry: every callable tool the request declares or * has discovered, keyed by the name the chat-side model calls it under, mapped * to how its calls must be emitted. Typed tools are keyed by their `type`; * discovered tools carry their namespace for egress dispatch. */ export declare function responsesToolRegistry(body: ResponsesRequest, options?: ResponsesTranslationOptions): ResponsesToolRegistry; /** Translate a Responses request to an OpenAI Chat Completions body. */ export declare function responsesToChat(body: ResponsesRequest, backendModel: string | undefined, options?: ResponsesTranslationOptions): Record; export declare function chatToResponses(openai: OpenAiResponse, model: string, toolRegistry?: ResponsesToolRegistry, searches?: readonly ExecutedSearch[]): Record;