/**
 * Responses协议相关类型定义
 * 支持OpenAI Responses API的JSON↔SSE双向转换
 */
import type { BaseSseEvent, StreamDirection, JsonObject, JsonValue } from './core-interfaces.js';
import type { RequiredAction } from './sse-events.js';
export * from './sse-events.js';
export type ResponsesSseEventType = 'response.created' | 'response.in_progress' | 'response.completed' | 'response.required_action' | 'response.done' | 'response.output_item.added' | 'response.output_item.done' | 'response.content_part.added' | 'response.content_part.done' | 'response.output_text.delta' | 'response.output_text.done' | 'response.reasoning_text.delta' | 'response.reasoning_text.done' | 'response.reasoning_signature.delta' | 'response.reasoning_image.delta' | 'response.reasoning_summary_part.added' | 'response.reasoning_summary_part.done' | 'response.reasoning_summary_text.delta' | 'response.reasoning_summary_text.done' | 'response.function_call_arguments.delta' | 'response.function_call_arguments.done' | 'response.error' | 'response.cancelled' | 'response.start' | 'content_part.delta' | 'reasoning.delta' | 'function_call.start' | 'function_call.delta' | 'function_call.done' | 'output_item.start' | 'content_part.start' | 'content_part.done' | 'output_item.done' | 'reasoning.start' | 'reasoning.done' | 'required_action' | 'error';
export interface ResponsesSseEvent extends BaseSseEvent {
    /** 事件类型（Responses协议使用点分隔符） */
    type: ResponsesSseEventType;
    /** 时间戳 */
    timestamp: number;
    /** 协议标识 */
    protocol: 'responses';
    /** 方向标识 */
    direction: StreamDirection;
}
export interface ResponsesJsonToSseContext {
    requestId: string;
    model: string;
    responsesRequest: ResponsesRequest;
    options: ResponsesJsonToSseOptions;
    startTime: number;
    sequenceCounter: number;
    outputIndexCounter: number;
    contentIndexCounter: Map<string, number>;
    isStreaming: boolean;
    currentResponse: Partial<ResponsesResponse>;
    responsesResponse?: ResponsesResponse;
    eventStats: ResponsesEventStats;
    outputItemStates: Map<string, OutputItemProcessingState>;
}
export interface SseToResponsesJsonContext {
    requestId: string;
    model: string;
    options: SseToResponsesJsonOptions;
    startTime: number;
    endTime?: number;
    duration?: number;
    aggregatedEvents: ResponsesSseEvent[];
    currentResponse: Partial<ResponsesResponse>;
    outputItemBuilders: Map<string, OutputItemBuilder>;
    eventStats: ResponsesEventStats;
    isCompleted: boolean;
    isResponseCreated: boolean;
    isInProgress: boolean;
    lastSequenceNumber: number;
}
export interface ResponsesRequest {
    model: string;
    input: ResponsesInput[];
    tools?: ResponsesTool[];
    temperature?: number;
    top_p?: number;
    max_output_tokens?: number;
    metadata?: JsonObject;
    store?: boolean;
    truncation?: 'auto' | 'disabled';
    user?: string;
    include?: ('user.id' | 'user.name' | 'user.email' | string)[];
    parallel_tool_calls?: boolean;
    previous_response_id?: string;
    reasoning?: ResponsesReasoningConfig;
    stream?: boolean;
}
export interface ResponsesInput {
    role: 'user' | 'assistant' | 'system';
    content: ResponsesContent[];
    name?: string;
}
export type ResponsesContent = {
    type: 'input_text';
    text: string;
} | {
    type: 'output_text';
    text: string;
} | {
    type: 'input_image';
    image_url: string;
    detail?: 'auto' | 'low' | 'high';
} | {
    type: 'file_search';
    file_search: JsonObject;
} | {
    type: 'computer_use';
    computer_use: JsonObject;
} | {
    type: 'function_call';
    name: string;
    arguments: string;
} | {
    type: 'function_result';
    result: JsonValue;
    tool_call_id: string;
} | {
    type: 'conversation';
    conversation: JsonValue[];
};
export interface ResponsesTool {
    type: 'function';
    name: string;
    description?: string;
    parameters?: JsonObject;
    strict?: boolean;
}
export interface ResponsesReasoningConfig {
    max_tokens: number;
    summarize?: boolean;
    summarize_threshold?: number;
}
export interface ResponsesResponse {
    id: string;
    object: 'response';
    created_at: number;
    status: 'in_progress' | 'requires_action' | 'completed' | 'failed' | 'incomplete';
    error?: JsonValue;
    model: string;
    output: ResponsesOutputItem[];
    previous_response_id?: string;
    usage?: ResponsesUsage;
    required_action?: RequiredAction;
    temperature?: number;
    top_p?: number;
    max_output_tokens?: number;
    metadata?: JsonObject;
    user?: string;
    store?: boolean;
    truncation?: 'auto' | 'disabled';
    include?: string[];
    parallel_tool_calls?: boolean;
}
export type ResponsesOutputItem = ResponsesMessageItem | ResponsesReasoningItem | ResponsesFunctionCallItem | ResponsesFunctionCallOutputItem | ResponsesSystemItem;
export interface ResponsesMessageItem {
    id: string;
    type: 'message';
    status: 'in_progress' | 'completed';
    role: 'assistant';
    content: ResponsesContent[];
}
export interface ResponsesReasoningItem {
    id: string;
    type: 'reasoning';
    summary?: Array<string | {
        type: 'summary_text';
        text: string;
    }>;
    content?: ResponsesReasoningContent[];
    encrypted_content?: string;
}
export type ResponsesReasoningContent = {
    type: 'reasoning_text';
    text: string;
} | {
    type: 'reasoning_signature';
    signature: JsonObject;
} | {
    type: 'reasoning_image';
    image_url: string;
};
export interface ResponsesFunctionCallItem {
    id: string;
    type: 'function_call';
    status: 'in_progress' | 'completed';
    call_id: string;
    name: string;
    arguments: string;
}
export interface ResponsesFunctionCallOutputItem {
    id: string;
    type: 'function_call_output';
    call_id: string;
    output: JsonValue;
    tool_call_id?: string;
}
export interface ResponsesSystemItem {
    id: string;
    type: 'system';
    name: string;
    data: JsonValue;
}
export interface ResponsesUsage {
    input_tokens: number;
    output_tokens: number;
    total_tokens: number;
    input_tokens_details: {
        cached_tokens: number;
        audio_tokens: number;
        text_tokens: number;
        image_tokens: number;
    };
    output_tokens_details: {
        reasoning_tokens: number;
        audio_tokens: number;
        text_tokens: number;
    };
}
export interface ResponsesRequiredAction {
    type: 'submit_tool_outputs' | 'run_parallel_tools';
    submit_tool_outputs?: {
        tool_calls: ResponsesToolCall[];
    };
    run_parallel_tools?: {
        tool_calls: ResponsesToolCall[];
    };
}
export interface ResponsesToolCall {
    id: string;
    type: 'function';
    function: {
        name: string;
        arguments: string;
    };
}
export interface ResponsesJsonToSseOptions {
    requestId: string;
    model: string;
    timeoutMs?: number;
    enableHeartbeat?: boolean;
    heartbeatIntervalMs?: number;
    chunkSize?: number;
    delayMs?: number;
    includeSequenceNumbers?: boolean;
    includeMetadata?: boolean;
    validationMode?: 'none' | 'basic' | 'strict';
    onEvent?: (event: ResponsesSseEvent) => void;
    onError?: (error: Error) => void;
    onComplete?: () => void;
    resumeToolOutputs?: ResponsesFunctionCallOutputItem[];
}
export interface SseToResponsesJsonOptions {
    requestId: string;
    model: string;
    timeoutMs?: number;
    validateEvents?: boolean;
    enableSequenceValidation?: boolean;
    accumulateOutputItems?: boolean;
    onPartialResult?: (partial: Partial<ResponsesResponse>) => void;
    onEvent?: (event: ResponsesSseEvent) => void;
    onCompletion?: (final: ResponsesResponse) => void;
    onError?: (error: Error) => void;
    onTimeout?: () => void;
}
export interface ResponsesEventStats {
    totalEvents: number;
    eventTypes: Record<string, number>;
    startTime: number;
    endTime?: number;
    duration?: number;
    outputItemsCount: number;
    contentPartsCount: number;
    deltaEventsCount: number;
    reasoningEventsCount: number;
    functionCallEventsCount: number;
    messageEventsCount: number;
    errorCount: number;
    lastEventTime?: number;
}
export interface OutputItemProcessingState {
    id: string;
    type: string;
    status: 'in_progress' | 'completed';
    contentIndex: number;
    isContentPartAdded: boolean;
    accumulatedContent: ResponsesContent[];
    deltaBuffer: string;
    isTextStarted: boolean;
    isTextCompleted: boolean;
}
export interface OutputItemBuilder {
    id: string;
    type: string;
    status: 'in_progress' | 'completed';
    contentParts: ResponsesContent[];
    currentContentIndex: number;
    accumulatedContent: ResponsesContent[];
    hasContentPartAdded: boolean;
    isTextInProgress: boolean;
    callId?: string;
    name?: string;
    arguments?: string;
    role?: string;
}
export interface ResponsesConversionError extends Error {
    code: string;
    requestId: string;
    eventId?: string;
    outputItemId?: string;
    sequenceNumber?: number;
    context?: JsonObject;
}
export declare const RESPONSES_CONVERSION_ERROR_CODES: {
    readonly TIMEOUT: "RESPONSES_TIMEOUT";
    readonly INVALID_EVENT: "RESPONSES_INVALID_EVENT";
    readonly SEQUENCE_ERROR: "RESPONSES_SEQUENCE_ERROR";
    readonly OUTPUT_ITEM_ERROR: "RESPONSES_OUTPUT_ITEM_ERROR";
    readonly CONTENT_PART_ERROR: "RESPONSES_CONTENT_PART_ERROR";
    readonly PARSE_ERROR: "RESPONSES_PARSE_ERROR";
    readonly VALIDATION_ERROR: "RESPONSES_VALIDATION_ERROR";
    readonly STREAM_ERROR: "RESPONSES_STREAM_ERROR";
};
export interface ResponsesConversionConfig {
    defaultTimeoutMs: number;
    heartbeatIntervalMs: number;
    eventTimeoutMs: number;
    defaultChunkSize: number;
    defaultDelayMs: number;
    reasoningChunkSize: number;
    textChunkSize: number;
    functionCallChunkSize: number;
    enableEventValidation: boolean;
    enableSequenceValidation: boolean;
    strictMode: boolean;
    validateOutputItems: boolean;
    maxConcurrentOutputItems: number;
    maxConcurrentContentParts: number;
    eventBufferSize: number;
    debugMode: boolean;
    logLevel: 'debug' | 'info' | 'warn' | 'error';
    enableMetrics: boolean;
}
export declare const DEFAULT_RESPONSES_CONVERSION_CONFIG: ResponsesConversionConfig;
export interface ResponsesSseEventStream extends AsyncIterable<ResponsesSseEvent> {
    getStats(): ResponsesEventStats;
    getConfig(): ResponsesConversionConfig;
    complete(): void;
    abort(error?: Error): void;
    on(event: 'error', handler: (error: Error) => void): this;
    on(event: 'complete', handler: () => void): this;
    on(event: 'timeout', handler: () => void): this;
    on(event: 'output_item', handler: (item: ResponsesOutputItem) => void): this;
    on(event: 'content_part', handler: (part: ResponsesContent) => void): this;
    on(event: 'stats', handler: (stats: ResponsesEventStats) => void): this;
}
