import type { ProviderConfig, ProviderType } from '../config.js'; /** * Provider 接口定义 * 每个 provider 需要实现这些方法来处理 API 请求差异 */ export interface Provider { /** * 构建请求头 */ buildHeaders(apiKey: string): Record; /** * 获取 endpoint 路径 */ getEndpoint(path: string): string; /** * 获取 provider 类型 */ getType(): 'openai' | 'anthropic' | 'response-api'; /** * 构建完整的请求 URL */ buildUrl(config: ProviderConfig, path: string): string; } /** * Provider 工厂接口 */ export interface ProviderFactory { getProvider(config: ProviderConfig): Provider; } /** * 基础 Provider 实现(共享逻辑) */ export declare abstract class BaseProvider implements Provider { abstract buildHeaders(apiKey: string): Record; abstract getEndpoint(path: string): string; abstract getType(): ProviderType; /** * 获取 Base URL */ getBaseUrl(config: ProviderConfig): string; /** * 规范化 URL 路径:移除末尾的斜杠 */ private normalizeBaseUrl; /** * 规范化 endpoint 路径:确保以 / 开头 */ private normalizeEndpoint; /** * 检测 baseUrl 是否已包含 endpoint 的前缀 * 例如:baseUrl = "https://api.openai.com/v1", endpoint = "/v1/chat/completions" * 应该返回 true,因为 baseUrl 已经包含了 /v1 */ private baseUrlIncludesEndpoint; /** * 构建完整的请求 URL * * 智能处理各种 baseUrl 格式: * - https://api.openai.com + /v1/chat/completions -> https://api.openai.com/v1/chat/completions * - https://api.openai.com/ + /v1/chat/completions -> https://api.openai.com/v1/chat/completions * - https://api.openai.com/v1 + /v1/chat/completions -> https://api.openai.com/v1/chat/completions * - https://api.openai.com/v1/ + /v1/chat/completions -> https://api.openai.com/v1/chat/completions */ buildUrl(config: ProviderConfig, path: string): string; } //# sourceMappingURL=base.d.ts.map