/** * Toonflow AI供应商模板 - DeepSeek * @version 2.0 */ // ============================================================ // 类型定义 // ============================================================ type VideoMode = | "singleImage" | "startEndRequired" | "endFrameOptional" | "startFrameOptional" | "text" | (`videoReference:${number}` | `imageReference:${number}` | `audioReference:${number}`)[]; interface TextModel { name: string; modelName: string; type: "text"; think: boolean; } interface ImageModel { name: string; modelName: string; type: "image"; mode: ("text" | "singleImage" | "multiReference")[]; associationSkills?: string; } interface VideoModel { name: string; modelName: string; type: "video"; mode: VideoMode[]; associationSkills?: string; audio: "optional" | false | true; durationResolutionMap: { duration: number[]; resolution: string[] }[]; } interface TTSModel { name: string; modelName: string; type: "tts"; voices: { title: string; voice: string }[]; } interface VendorConfig { id: string; version: string; name: string; author: string; description?: string; icon?: string; inputs: { key: string; label: string; type: "text" | "password" | "url"; required: boolean; placeholder?: string }[]; inputValues: Record; models: (TextModel | ImageModel | VideoModel | TTSModel)[]; } interface ImageConfig { prompt: string; imageBase64: string[]; size: "1K" | "2K" | "4K"; aspectRatio: `${number}:${number}`; } interface VideoConfig { duration: number; resolution: string; aspectRatio: "16:9" | "9:16"; prompt: string; imageBase64?: string[]; audio?: boolean; mode: VideoMode[]; } interface TTSConfig { text: string; voice: string; speechRate: number; pitchRate: number; volume: number; } interface PollResult { completed: boolean; data?: string; error?: string; } // ============================================================ // 全局声明 // ============================================================ declare const axios: any; declare const logger: (msg: string) => void; declare const jsonwebtoken: any; declare const zipImage: (base64: string, size: number) => Promise; declare const zipImageResolution: (base64: string, w: number, h: number) => Promise; declare const mergeImages: (base64Arr: string[], maxSize?: string) => Promise; declare const urlToBase64: (url: string) => Promise; declare const pollTask: (fn: () => Promise, interval?: number, timeout?: number) => Promise; declare const createOpenAI: any; declare const createDeepSeek: any; declare const createZhipu: any; declare const createQwen: any; declare const createAnthropic: any; declare const createOpenAICompatible: any; declare const createXai: any; declare const createMinimax: any; declare const createGoogleGenerativeAI: any; declare const exports: { vendor: VendorConfig; textRequest: (m: TextModel, t: boolean, tl: 0 | 1 | 2 | 3) => any; imageRequest: (c: ImageConfig, m: ImageModel) => Promise; videoRequest: (c: VideoConfig, m: VideoModel) => Promise; ttsRequest: (c: TTSConfig, m: TTSModel) => Promise; checkForUpdates?: () => Promise<{ hasUpdate: boolean; latestVersion: string; notice: string }>; updateVendor?: () => Promise; }; // ============================================================ // 供应商配置 // ============================================================ const vendor: VendorConfig = { id: "deepseek", version: "2.0", author: "Toonflow", name: "DeepSeek", description: "DeepSeek 官方接口适配,支持 V4 系列模型与思考模式(思维链输出)。\n\n[前往平台](https://platform.deepseek.com/)", icon: "", inputs: [ { key: "apiKey", label: "API密钥", type: "password", required: true }, { key: "baseUrl", label: "请求地址", type: "url", required: true, placeholder: "示例:https://api.deepseek.com" }, ], inputValues: { apiKey: "", baseUrl: "https://api.deepseek.com/v1", }, models: [ { name: "DeepSeek V4 Pro", modelName: "deepseek-v4-pro", type: "text", think: true }, { name: "DeepSeek V4 Flash", modelName: "deepseek-v4-flash", type: "text", think: true }, ], }; // ============================================================ // 适配器函数 // ============================================================ const textRequest = (model: TextModel, think: boolean, thinkLevel: 0 | 1 | 2 | 3) => { if (!vendor.inputValues.apiKey) throw new Error("缺少API Key"); const apiKey = vendor.inputValues.apiKey.replace(/^Bearer\s+/i, ""); // DeepSeek 思考强度仅支持 high / max(low、medium 会被映射为 high,xhigh 会被映射为 max) // thinkLevel: 0/1/2 → high, 3 → max const effortMap: Record<0 | 1 | 2 | 3, "high" | "max"> = { 0: "high", 1: "high", 2: "high", 3: "max", }; const enableThinking = model.think && think; const extraBody: Record = { thinking: { type: enableThinking ? "enabled" : "disabled" }, }; if (enableThinking) { extraBody.reasoning_effort = effortMap[thinkLevel]; } return createDeepSeek({ baseURL: vendor.inputValues.baseUrl, apiKey, extraBody, }).chat(model.modelName); }; const imageRequest = async (config: ImageConfig, model: ImageModel): Promise => { return ""; }; const videoRequest = async (config: VideoConfig, model: VideoModel): Promise => { return ""; }; const ttsRequest = async (config: TTSConfig, model: TTSModel): Promise => { return ""; }; const checkForUpdates = async (): Promise<{ hasUpdate: boolean; latestVersion: string; notice: string }> => { return { hasUpdate: false, latestVersion: "2.0", notice: "" }; }; const updateVendor = async (): Promise => { return ""; }; // ============================================================ // 导出 // ============================================================ exports.vendor = vendor; exports.textRequest = textRequest; exports.imageRequest = imageRequest; exports.videoRequest = videoRequest; exports.ttsRequest = ttsRequest; exports.checkForUpdates = checkForUpdates; exports.updateVendor = updateVendor; export { };