/** * Express 桥接层 — 将 Proxy 框架集成到 Express 路由 * * 提供: * - SSECallbacks → Express Response 的格式转换器(Chat/Responses/Anthropic SSE) * - pickProxy() 根据输入格式和提供商类型选择正确的 Proxy * - executeProxy() 便捷调用 */ import { Response } from 'express'; import type { SSECallbacks } from './Proxy/common/types'; import BaseProxy from './Proxy/common/BaseProxy'; /** * 创建 Chat Completions SSE 回调 * * 输出格式: * data: {"choices":[{"delta":{"content":"..."},"index":0}]} * data: {"choices":[{"delta":{"tool_calls":[...]},"index":0}]} * data: [DONE] */ export declare function createChatSSECallbacks(res: Response, options?: { modelId?: number; promptTokens?: number; modelName?: string; }): SSECallbacks; /** * 创建 Responses API SSE 回调 * * 参考 cc-switch (farion1231/cc-switch) 的 ChatToResponsesState 状态机模式, * 将 Chat Completions SSE 回调转换为 OpenAI Responses API 命名事件序列: * * 生命周期: * - 文本: response.created → output_item.added → content_part.added → output_text.delta → output_text.done → content_part.done → output_item.done * - 推理: response.created → output_item.added (reasoning) → reasoning_summary_part.added → reasoning_summary_text.delta → ...done * - 工具: response.created → output_item.added (function_call) → function_call_arguments.delta → ...done → output_item.done * - 完成: response.completed → [DONE] * * 关键设计(对齐 cc-switch ChatToResponsesState): * - 每个输出类型有独立的状态机(reasoning / text / tools),各自管理 added→done 生命周期 * - 推理和文本作为独立的 output item(reasoning → output_index 0, message → output_index 1) * - 工具调用通过 onToolDelta 增量添加,onToolCall 完成时发 done + output_item.done * - response.completed 只发一次(onUsage 或 onDone 先到先得) */ export declare function createResponsesSSECallbacks(res: Response, options?: { modelId?: number; modelName?: string; }): SSECallbacks; /** * 创建 Anthropic Messages SSE 回调 * * 输出 Anthropic SSE 事件序列: * message_start → content_block_start → content_block_delta * content_block_stop → message_delta → message_stop */ export declare function createAnthropicSSECallbacks(res: Response): SSECallbacks; /** * 输入格式枚举 */ export type InputFormat = 'chat' | 'responses' | 'anthropic'; /** * 提供商类型枚举 */ export type ProviderType = 'openai-chat' | 'openai-responses' | 'anthropic' | 'unknown'; /** * 根据输入格式和提供商类型选择正确的 Proxy * * Hub-and-spoke 模式:所有转换代理经过 OpenAI Chat 中间格式。 * 直传代理直接调用各自原生 API。 * * @param inputFormat 客户端请求的格式 * @param providerType 上游提供商类型 * @returns 对应的 Proxy 实例 */ export declare function pickProxy(inputFormat: InputFormat, providerType: ProviderType): BaseProxy> | null; /** * 获取输入格式对应的 SSE 回调工厂 */ export declare function createSSECallbacks(inputFormat: InputFormat, res: Response, options?: { modelId?: number; promptTokens?: number; modelName?: string; }): SSECallbacks; /** * 便捷执行 Proxy 调用 * * @param proxy Proxy 实例 * @param config 配置(baseUrl, apiKey, providerLabel, timeoutMs) * @param body 请求体 * @param callbacks SSE 回调 * @param clientRes 客户端响应对象(透传代理需要) */ export declare function executeProxy(proxy: BaseProxy>, config: { baseUrl: string; apiKey: string; providerLabel: string; timeoutMs?: number; maxRetries?: number; modelId?: number; requestId?: string; sessionId?: string; }, body: Record, callbacks: SSECallbacks, clientRes?: Response): Promise; //# sourceMappingURL=express-bridge.d.ts.map