/* * This file patches OpenAI SDK types for OpenResponses spec compliance. * * The OpenAI SDK uses event type names like "response.reasoning_text.delta", * but the OpenResponses spec uses "response.reasoning.delta" (without "_text"). * We maintain custom event types here to match the OpenResponses specification. * * Once the OpenAI SDK aligns with OpenResponses spec, this file can be simplified. */ import type { ResponseReasoningItem as OpenAIResponseReasoningItem, ResponseStreamEvent as OpenAIResponseStreamEvent, ResponseOutputRefusal, ResponseOutputText, ResponseContentPartAddedEvent, ResponseContentPartDoneEvent, ResponseTextDeltaEvent, ResponseTextDoneEvent, } from "openai/resources/responses/responses"; import type { ChatCompletionChunk } from "openai/resources/chat/completions"; export interface ReasoningTextContent { type: "reasoning_text"; text: string; } export type PatchedResponseReasoningItem = OpenAIResponseReasoningItem & { // Raw CoT returned in reasoning item (in addition to the summary) content: ReasoningTextContent[]; }; // Custom event types for OpenResponses spec (differs from SDK's "response.reasoning_text.*") interface PatchedResponseReasoningDeltaEvent { type: "response.reasoning.delta"; sequence_number: number; item_id: string; output_index: number; content_index: number; delta: string; } interface PatchedResponseReasoningDoneEvent { type: "response.reasoning.done"; sequence_number: number; item_id: string; output_index: number; content_index: number; text: string; } export type PatchedResponseStreamEvent = | OpenAIResponseStreamEvent | PatchedResponseReasoningDeltaEvent | PatchedResponseReasoningDoneEvent | PatchedResponseContentPartAddedEvent | PatchedResponseContentPartDoneEvent | PatchedResponseOutputTextDeltaEvent | PatchedResponseOutputTextDoneEvent; export type PatchedResponseContentPart = ResponseOutputText | ResponseOutputRefusal | ReasoningTextContent; export interface PatchedResponseOutputTextDeltaEvent extends ResponseTextDeltaEvent { logprobs: unknown[]; } export interface PatchedResponseOutputTextDoneEvent extends ResponseTextDoneEvent { logprobs: unknown[]; } interface PatchedResponseContentPartAddedEvent { content_index: number; item_id: string; output_index: number; part: PatchedResponseContentPart; sequence_number: number; type: "response.content_part.added"; } interface PatchedResponseContentPartDoneEvent { content_index: number; item_id: string; output_index: number; part: PatchedResponseContentPart; sequence_number: number; type: "response.content_part.done"; } export type PatchedDeltaWithReasoning = ChatCompletionChunk.Choice.Delta & { reasoning?: string; reasoning_content?: string; };