From 0d2abe06af6ac9f69fafb8c8e7bff494c01adffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ACT=E4=B8=B6=E6=B5=81=E6=98=9F=E9=9B=A8?= <1340145680@qq.com> Date: Mon, 6 Apr 2026 00:43:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=81=AB=E5=B1=B1=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/initDB.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/initDB.ts b/src/lib/initDB.ts index dd3199e..ba6e956 100644 --- a/src/lib/initDB.ts +++ b/src/lib/initDB.ts @@ -455,10 +455,10 @@ export default async (knex: Knex, forceInit: boolean = false): Promise => inputValues: '{"apiKey":"","text":"https://ark.cn-beijing.volces.com/api/v3","baseUrl":"https://ark.cn-beijing.volces.com/api/v3","image":"https://ark.cn-beijing.volces.com/api/v3/images/generations","videoCreate":"https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks","videoQuery":"https://ark.cn-beijing.volces.com/api/v3/contents/generations/tasks/{id}"}', models: - '[{"name":"Doubao-Seed-2.0-pro","type":"text","modelName":"doubao-seed-2-0-pro-260215","think":false},{"name":"Doubao-Seed-2.0-lite","type":"text","modelName":"doubao-seed-2-0-lite-260215","think":false},{"name":"Doubao-Seed-2.0-mini","type":"text","modelName":"doubao-seed-2-0-mini-260215","think":false},{"name":"Doubao-Seed-2.0-Code","type":"text","modelName":"doubao-seed-2-0-code-preview-260215","think":false},{"name":"Doubao-1.5-pro-32k","type":"text","modelName":"doubao-1-5-pro-32k-250115","think":false},{"name":"deepseek-v3-250324","type":"text","modelName":"deepseek-v3-250324","think":false},{"name":"glm-4-7-251222","type":"text","modelName":"glm-4-7-251222","think":false},{"name":"Doubao-Seedream-5.0-lite","type":"image","modelName":"doubao-seedream-5-0-260128","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedream-4.5","type":"image","modelName":"doubao-seedream-4-5-251128","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedream-4.0","type":"image","modelName":"doubao-seedream-4-0-250828","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedance-1.5-pro","type":"video","modelName":"doubao-seedance-1-5-pro-251215","mode":["text","singleImage","endFrameOptional"],"audio":true,"durationResolutionMap":[{"duration":[5],"resolution":["480p","720p","1080p"]}]},{"name":"Doubao-Seedance-1.5-pro","type":"video","modelName":"doubao-seedance-1-5-pro-251215","mode":["text","singleImage","endFrameOptional"],"audio":true,"durationResolutionMap":[{"duration":[5],"resolution":["480p","720p","1080p"]}]},{"name":"Doubao-Seedance-1.0-pro-fast","type":"video","modelName":"doubao-seedance-1-0-pro-fast-251015","mode":["text","singleImage"],"audio":false,"durationResolutionMap":[{"duration":[2,3,4,5,6,7,8,9,10,11,12],"resolution":["480p","720p","1080p"]}]},{"name":"Doubao-Seedance-2.0","modelName":"doubao-seedance-2-0-260128","type":"video","mode":[["textReference","videoReference","imageReference","audioReference"]],"audio":"optional","durationResolutionMap":[{"duration":[4,5,6,7,8,9,10,11,12,13,14,15],"resolution":["480p","720p"]}],"associationSkills":""}]', - code: '//如需遥测AI请使用在toonflow安装目录运行npx @ai-sdk/devtools (要求在其他设置中打开遥测功能,且toonflow有权限在安装目录创建.devtools文件夹)\r\n// ==================== 类型定义 ====================\r\n// 文本模型\r\ninterface TextModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "text";\r\n think: boolean; // 前端显示用\r\n}\r\n\r\n// 图像模型\r\ninterface ImageModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "image";\r\n mode: ("text" | "singleImage" | "multiReference")[];\r\n associationSkills?: string; // 关联技能,多个技能用逗号分隔\r\n}\r\n// 视频模型\r\ninterface VideoModel {\r\n name: string; // 显示名称\r\n modelName: string; //全局唯一\r\n type: "video";\r\n mode: (\r\n | "singleImage" // 单图\r\n | "startEndRequired" // 首尾帧(两张都得有)\r\n | "endFrameOptional" // 首尾帧(尾帧可选)\r\n | "startFrameOptional" // 首尾帧(首帧可选)\r\n | "text" // 文本生视频\r\n | ("videoReference" | "imageReference" | "audioReference" | "textReference")[]\r\n )[]; // 混合参考\r\n associationSkills?: string; // 关联技能,多个技能用逗号分隔\r\n audio: "optional" | false | true; // 音频配置\r\n durationResolutionMap: { duration: number[]; resolution: string[] }[];\r\n}\r\n\r\ninterface TTSModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "tts";\r\n voices: {\r\n title: string; //显示名称\r\n voice: string; //说话人\r\n }[];\r\n}\r\n// 供应商配置\r\ninterface VendorConfig {\r\n id: string; //供应商唯一标识,必须全局唯一\r\n author: string;\r\n description?: string; //md5格式\r\n name: string;\r\n icon?: string; //仅支持base64格式\r\n inputs: {\r\n key: string;\r\n label: string;\r\n type: "text" | "password" | "url";\r\n required: boolean;\r\n placeholder?: string;\r\n }[];\r\n inputValues: Record;\r\n models: (TextModel | ImageModel | VideoModel)[];\r\n}\r\n// ==================== 全局工具函数 ====================\r\n//Axios实例\r\n//压缩图片大小(1MB = 1 * 1024 * 1024)\r\ndeclare const zipImage: (completeBase64: string, size: number) => Promise;\r\n//压缩图片分辨率\r\ndeclare const zipImageResolution: (completeBase64: string, width: number, height: number) => Promise;\r\n//多图拼接乘单图 maxSize 最大输出大小,默认为 10mb\r\ndeclare const mergeImages: (completeBase64: string[], maxSize?: string) => Promise;\r\n//Url转Base64\r\ndeclare const urlToBase64: (url: string) => Promise;\r\n//轮询函数\r\ndeclare const pollTask: (\r\n fn: () => Promise<{ completed: boolean; data?: string; error?: string }>,\r\n interval?: number,\r\n timeout?: number,\r\n) => Promise<{ completed: boolean; data?: string; error?: string }>;\r\ndeclare const axios: any;\r\ndeclare const createOpenAI: any;\r\ndeclare const createDeepSeek: any;\r\ndeclare const createZhipu: any;\r\ndeclare const createQwen: any;\r\ndeclare const createAnthropic: any;\r\ndeclare const createOpenAICompatible: any;\r\ndeclare const createXai: any;\r\ndeclare const createMinimax: any;\r\ndeclare const createGoogleGenerativeAI: any;\r\ndeclare const logger: (logstring: string) => void;\r\ndeclare const jsonwebtoken: any;\r\n// ==================== 供应商数据 ====================\r\nconst ARK_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";\r\nconst SUCCESS_TASK_STATUS = ["succeeded", "completed", "success"];\r\nconst FAILED_TASK_STATUS = ["failed", "failure", "error", "canceled", "cancelled"];\r\n\r\nconst vendor: VendorConfig = {\r\n id: "volcengine",\r\n author: "leeqi",\r\n description: "火山引擎方舟官方直连模板,接入 Ark 的文本、图片、视频生成 API,支持 Doubao、DeepSeek、GLM 等模型。\\n[](https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey)",\r\n name: "火山引擎",\r\n inputs: [\r\n { key: "apiKey", label: "ARK API Key", type: "password", required: true },\r\n { key: "text", label: "文本生成接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "baseUrl", label: "Ark Base URL", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "image", label: "图片生成接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "videoCreate", label: "视频任务创建接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "videoQuery", label: "视频任务查询接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n ],\r\n inputValues: {\r\n apiKey: "",\r\n text: ARK_BASE_URL,\r\n baseUrl: ARK_BASE_URL,\r\n image: `${ARK_BASE_URL}/images/generations`,\r\n videoCreate: `${ARK_BASE_URL}/contents/generations/tasks`,\r\n videoQuery: `${ARK_BASE_URL}/contents/generations/tasks/{id}`,\r\n },\r\n models: [\r\n {\r\n name: "Doubao-Seed-2.0-pro",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-pro-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-lite",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-lite-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-mini",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-mini-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-Code",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-code-preview-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-1.5-pro-32k",\r\n type: "text",\r\n modelName: "doubao-1-5-pro-32k-250115",\r\n think: false,\r\n },\r\n {\r\n name: "deepseek-v3-250324",\r\n type: "text",\r\n modelName: "deepseek-v3-250324",\r\n think: false,\r\n },\r\n {\r\n name: "glm-4-7-251222",\r\n type: "text",\r\n modelName: "glm-4-7-251222",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seedream-5.0-lite",\r\n type: "image",\r\n modelName: "doubao-seedream-5-0-260128",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedream-4.5",\r\n type: "image",\r\n modelName: "doubao-seedream-4-5-251128",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedream-4.0",\r\n type: "image",\r\n modelName: "doubao-seedream-4-0-250828",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedance-1.5-pro",\r\n type: "video",\r\n modelName: "doubao-seedance-1-5-pro-251215",\r\n mode: ["text", "singleImage", "endFrameOptional"],\r\n audio: true,\r\n durationResolutionMap: [{ duration: [5], resolution: ["480p", "720p", "1080p"] }],\r\n },\r\n {\r\n name: "Doubao-Seedance-1.5-pro",\r\n type: "video",\r\n modelName: "doubao-seedance-1-5-pro-251215",\r\n mode: ["text", "singleImage", "endFrameOptional"],\r\n audio: true,\r\n durationResolutionMap: [{ duration: [5], resolution: ["480p", "720p", "1080p"] }],\r\n },\r\n {\r\n name: "Doubao-Seedance-1.0-pro-fast",\r\n type: "video",\r\n modelName: "doubao-seedance-1-0-pro-fast-251015",\r\n mode: ["text", "singleImage"],\r\n audio: false,\r\n durationResolutionMap: [{ duration: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], resolution: ["480p", "720p", "1080p"] }],\r\n },\r\n {\r\n name: "Doubao-Seedance-2.0",\r\n modelName: "doubao-seedance-2-0-260128",\r\n type: "video",\r\n mode: [["textReference", "videoReference", "imageReference", "audioReference"]],\r\n audio: "optional",\r\n durationResolutionMap: [\r\n {\r\n duration: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],\r\n resolution: ["480p", "720p"],\r\n },\r\n ],\r\n associationSkills: "",\r\n },\r\n ],\r\n};\r\nexports.vendor = vendor;\r\n\r\n// ==================== 适配器函数 ====================\r\nconst getApiKey = () => {\r\n if (!vendor.inputValues.apiKey) throw new Error("缺少API Key");\r\n return vendor.inputValues.apiKey.replace(/^Bearer\\s+/i, "");\r\n};\r\n\r\nconst getBaseUrl = () => vendor.inputValues.baseUrl || ARK_BASE_URL;\r\nconst buildUrl = (overrideUrl: string | undefined, fallbackPath: string) => overrideUrl || `${getBaseUrl().replace(/\\/$/, "")}${fallbackPath}`;\r\n\r\nconst getHeaders = () => ({\r\n Authorization: `Bearer ${getApiKey()}`,\r\n "Content-Type": "application/json",\r\n});\r\n\r\nconst getOpenAIBaseUrl = () =>\r\n (vendor.inputValues.text || getBaseUrl())\r\n .trim()\r\n .replace(/\\/$/, "")\r\n .replace(/\\/chat\\/completions$/i, "");\r\n\r\nconst readJson = async (response: Response, action: string) => {\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(`${action}失败,状态码: ${response.status}, 错误信息: ${errorText}`);\r\n }\r\n\r\n return response.json();\r\n};\r\n\r\n//补齐图片 data url 前缀\r\nconst normalizeImageInput = (value: string) => {\r\n if (!value) return value;\r\n if (/^(https?:\\/\\/|data:|volc:)/i.test(value)) return value;\r\n return `data:image/png;base64,${value}`;\r\n};\r\n\r\nconst normalizeImageList = (imageBase64?: string[]) => (imageBase64 || []).filter(Boolean).map(normalizeImageInput);\r\n\r\nconst extractImageResult = (data: any) => {\r\n const first = data?.data?.[0] ?? data?.images?.[0] ?? data?.output?.[0];\r\n return first?.url ?? first?.image_url ?? first?.b64_json ?? first?.base64;\r\n};\r\n\r\nconst extractTaskId = (data: any) => data?.id ?? data?.task_id ?? data?.taskId ?? data?.data?.id ?? data?.data?.task_id ?? data?.data;\r\n\r\nconst extractVideoUrl = (data: any) =>\r\n data?.content?.video_url ??\r\n data?.content?.video_urls?.[0] ??\r\n data?.data?.content?.video_url ??\r\n data?.data?.content?.video_urls?.[0] ??\r\n data?.data?.video_url ??\r\n data?.result?.video_url ??\r\n data?.result_url ??\r\n data?.data?.result_url;\r\n\r\nconst getTaskStatus = (data: any) => (data?.status ?? data?.data?.status ?? "").toString().toLowerCase();\r\n\r\nconst getTaskError = (data: any) =>\r\n data?.error?.message ?? data?.message ?? data?.data?.message ?? data?.data?.fail_reason ?? data?.fail_reason ?? "任务执行失败";\r\n\r\n// 文本请求函数\r\nconst textRequest: (textModel: TextModel) => { url: string; model: string } = (textModel) => {\r\n return createOpenAI({\r\n baseURL: getOpenAIBaseUrl(),\r\n apiKey: getApiKey(),\r\n }).chat(textModel.modelName);\r\n};\r\nexports.textRequest = textRequest;\r\n\r\n//图片请求函数\r\ninterface ImageConfig {\r\n prompt: string; //图片提示词\r\n imageBase64: string[]; //输入的图片提示词\r\n size: "1K" | "2K" | "4K"; // 图片尺寸\r\n aspectRatio: `${number}:${number}`; // 长宽比\r\n}\r\n\r\nconst normalizeImageSize = (imageConfig: ImageConfig) => {\r\n const normalizedSize = imageConfig.size.toUpperCase();\r\n const normalizedAspectRatio = imageConfig.aspectRatio;\r\n\r\n if (normalizedSize === "1K") {\r\n return "2k";\r\n }\r\n\r\n const sizeMap: Record<"16:9" | "9:16", Record<"2K" | "4K", string>> = {\r\n "16:9": {\r\n "2K": "2848x1600",\r\n "4K": "4096x2304",\r\n },\r\n "9:16": {\r\n "2K": "1600x2848",\r\n "4K": "2304x4096",\r\n },\r\n };\r\n\r\n if (normalizedAspectRatio === "16:9" || normalizedAspectRatio === "9:16") {\r\n return sizeMap[normalizedAspectRatio][normalizedSize as "2K" | "4K"];\r\n }\r\n\r\n return normalizedSize === "4K" ? "3k" : "2k";\r\n};\r\n\r\nconst imageRequest = async (imageConfig: ImageConfig, imageModel: ImageModel) => {\r\n const images = normalizeImageList(imageConfig.imageBase64);\r\n const body = {\r\n model: imageModel.modelName,\r\n prompt: imageConfig.prompt,\r\n size: normalizeImageSize(imageConfig),\r\n response_format: "url",\r\n sequential_image_generation: "disabled",\r\n stream: false,\r\n watermark: false,\r\n ...(images.length ? { image: images.length === 1 ? images[0] : images } : {}),\r\n };\r\n\r\n const data = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.image, "/images/generations"), {\r\n method: "POST",\r\n headers: getHeaders(),\r\n body: JSON.stringify(body),\r\n }),\r\n "图片生成",\r\n );\r\n\r\n const result = extractImageResult(data);\r\n if (!result) throw new Error(`图片生成返回格式异常: ${JSON.stringify(data)}`);\r\n return result;\r\n};\r\nexports.imageRequest = imageRequest;\r\n\r\ninterface VideoConfig {\r\n duration: number;\r\n resolution: string;\r\n aspectRatio: "16:9" | "9:16";\r\n prompt: string;\r\n imageBase64?: string[];\r\n audio?: boolean;\r\n mode:\r\n | "singleImage" // 单图\r\n | "multiImage" // 多图模式\r\n | "gridImage" // 网格单图(传入一张图片,但该图片是网格图)\r\n | "startEndRequired" // 首尾帧(两张都得有)\r\n | "endFrameOptional" // 首尾帧(尾帧可选)\r\n | "startFrameOptional" // 首尾帧(首帧可选)\r\n | "text" // 文本生视频\r\n | ("video" | "image" | "audio" | "text")[]; // 混合参考\r\n}\r\n\r\nconst isSeedanceModel = (modelName: string) => /^doubao-seedance-/i.test(modelName);\r\nconst isSeedance15ProModel = (modelName: string) => /^doubao-seedance-1-5-pro/i.test(modelName);\r\n\r\nconst appendPromptFlag = (prompt: string, flag: string, value: string | number | boolean | undefined) => {\r\n if (value === undefined || value === null || value === "") return prompt;\r\n const normalizedPrompt = prompt.trim();\r\n const flagPattern = new RegExp(`(^|\\\\s)--${flag}(?:\\\\s+\\\\S+)?(?=\\\\s|$)`, "i");\r\n if (flagPattern.test(normalizedPrompt)) return normalizedPrompt;\r\n return `${normalizedPrompt} --${flag} ${value}`.trim();\r\n};\r\n\r\nconst buildVideoPrompt = (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n if (!isSeedanceModel(videoModel.modelName)) return videoConfig.prompt || "";\r\n\r\n let prompt = videoConfig.prompt || "";\r\n prompt = appendPromptFlag(prompt, "resolution", videoConfig.resolution);\r\n prompt = appendPromptFlag(prompt, "duration", videoConfig.duration);\r\n prompt = appendPromptFlag(prompt, "camerafixed", false);\r\n prompt = appendPromptFlag(prompt, "watermark", false);\r\n return prompt;\r\n};\r\n\r\nconst buildVideoContent = (videoConfig: VideoConfig, videoModel: VideoModel) => [\r\n { type: "text", text: buildVideoPrompt(videoConfig, videoModel) },\r\n ...normalizeImageList(videoConfig.imageBase64).map((image) => ({\r\n type: "image_url",\r\n image_url: { url: image },\r\n })),\r\n];\r\n\r\nconst buildVideoBody = (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n const isSeedance = isSeedanceModel(videoModel.modelName);\r\n const isSeedance15Pro = isSeedance15ProModel(videoModel.modelName);\r\n\r\n return {\r\n model: videoModel.modelName,\r\n content: buildVideoContent(videoConfig, videoModel),\r\n ...(!isSeedance15Pro && !isSeedance\r\n ? {\r\n duration: videoConfig.duration,\r\n resolution: videoConfig.resolution,\r\n ratio: videoConfig.aspectRatio,\r\n }\r\n : {}),\r\n ...(videoModel.audio === true && typeof videoConfig.audio === "boolean" ? { generate_audio: videoConfig.audio } : {}),\r\n };\r\n};\r\n\r\nconst queryVideoResult = async (taskId: string) => {\r\n const queryData = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.videoQuery, "/contents/generations/tasks/{id}").replace("{id}", taskId), {\r\n method: "GET",\r\n headers: getHeaders(),\r\n }),\r\n "视频任务查询",\r\n );\r\n\r\n const status = getTaskStatus(queryData);\r\n if (SUCCESS_TASK_STATUS.includes(status)) {\r\n const videoUrl = extractVideoUrl(queryData);\r\n if (!videoUrl) return { completed: true, error: `视频任务成功但未返回结果: ${JSON.stringify(queryData)}` };\r\n return { completed: true, data: videoUrl };\r\n }\r\n\r\n if (FAILED_TASK_STATUS.includes(status)) {\r\n return { completed: false, error: getTaskError(queryData) };\r\n }\r\n\r\n return { completed: false };\r\n};\r\n\r\nconst videoRequest = async (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n const createData = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.videoCreate, "/contents/generations/tasks"), {\r\n method: "POST",\r\n headers: getHeaders(),\r\n body: JSON.stringify(buildVideoBody(videoConfig, videoModel)),\r\n }),\r\n "视频任务创建",\r\n );\r\n\r\n const taskId = extractTaskId(createData);\r\n if (!taskId) throw new Error(`视频任务创建返回格式异常: ${JSON.stringify(createData)}`);\r\n\r\n const result = await pollTask(() => queryVideoResult(taskId));\r\n if (result.error) throw new Error(result.error);\r\n return result.data;\r\n};\r\nexports.videoRequest = videoRequest;\r\n\r\ninterface TTSConfig {\r\n text: string;\r\n voice: string;\r\n speechRate: number;\r\n pitchRate: number;\r\n volume: number;\r\n}\r\n\r\nconst ttsRequest = async (ttsConfig: TTSConfig, ttsModel: TTSModel) => {\r\n return null;\r\n};\r\nexports.ttsRequest = ttsRequest;\r\n', + '[{"name":"Doubao-Seed-2.0-pro","type":"text","modelName":"doubao-seed-2-0-pro-260215","think":false},{"name":"Doubao-Seed-2.0-lite","type":"text","modelName":"doubao-seed-2-0-lite-260215","think":false},{"name":"Doubao-Seed-2.0-mini","type":"text","modelName":"doubao-seed-2-0-mini-260215","think":false},{"name":"Doubao-Seed-2.0-Code","type":"text","modelName":"doubao-seed-2-0-code-preview-260215","think":false},{"name":"Doubao-1.5-pro-32k","type":"text","modelName":"doubao-1-5-pro-32k-250115","think":false},{"name":"deepseek-v3-250324","type":"text","modelName":"deepseek-v3-250324","think":false},{"name":"glm-4-7-251222","type":"text","modelName":"glm-4-7-251222","think":false},{"name":"Doubao-Seedream-5.0-lite","type":"image","modelName":"doubao-seedream-5-0-260128","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedream-4.5","type":"image","modelName":"doubao-seedream-4-5-251128","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedream-4.0","type":"image","modelName":"doubao-seedream-4-0-250828","mode":["text","singleImage","multiReference"]},{"name":"Doubao-Seedance-1.5-pro","type":"video","modelName":"doubao-seedance-1-5-pro-251215","mode":["text","singleImage","endFrameOptional"],"audio":true,"durationResolutionMap":[{"duration":[4,5,6,7,8,9,10,11,12],"resolution":["480p","720p","1080p"]}]},{"name":"Doubao-Seedance-1.0-pro-fast","type":"video","modelName":"doubao-seedance-1-0-pro-fast-251015","mode":["text","singleImage"],"audio":false,"durationResolutionMap":[{"duration":[2,3,4,5,6,7,8,9,10,11,12],"resolution":["480p","720p","1080p"]}]},{"name":"Doubao-Seedance-2.0","modelName":"doubao-seedance-2-0-260128","type":"video","mode":[["textReference","videoReference","imageReference","audioReference"]],"audio":"optional","durationResolutionMap":[{"duration":[4,5,6,7,8,9,10,11,12,13,14,15],"resolution":["480p","720p"]}],"associationSkills":""}]', + code: '//如需遥测AI请使用在toonflow安装目录运行npx @ai-sdk/devtools (要求在其他设置中打开遥测功能,且toonflow有权限在安装目录创建.devtools文件夹)\r\n// ==================== 类型定义 ====================\r\n// 文本模型\r\ninterface TextModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "text";\r\n think: boolean; // 前端显示用\r\n}\r\n\r\n// 图像模型\r\ninterface ImageModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "image";\r\n mode: ("text" | "singleImage" | "multiReference")[];\r\n associationSkills?: string; // 关联技能,多个技能用逗号分隔\r\n}\r\n// 视频模型\r\ninterface VideoModel {\r\n name: string; // 显示名称\r\n modelName: string; //全局唯一\r\n type: "video";\r\n mode: (\r\n | "singleImage" // 单图\r\n | "startEndRequired" // 首尾帧(两张都得有)\r\n | "endFrameOptional" // 首尾帧(尾帧可选)\r\n | "startFrameOptional" // 首尾帧(首帧可选)\r\n | "text" // 文本生视频\r\n | ("videoReference" | "imageReference" | "audioReference" | "textReference")[]\r\n )[]; // 混合参考\r\n associationSkills?: string; // 关联技能,多个技能用逗号分隔\r\n audio: "optional" | false | true; // 音频配置\r\n durationResolutionMap: { duration: number[]; resolution: string[] }[];\r\n}\r\n\r\ninterface TTSModel {\r\n name: string; // 显示名称\r\n modelName: string;\r\n type: "tts";\r\n voices: {\r\n title: string; //显示名称\r\n voice: string; //说话人\r\n }[];\r\n}\r\n// 供应商配置\r\ninterface VendorConfig {\r\n id: string; //供应商唯一标识,必须全局唯一\r\n author: string;\r\n description?: string; //md5格式\r\n name: string;\r\n icon?: string; //仅支持base64格式\r\n inputs: {\r\n key: string;\r\n label: string;\r\n type: "text" | "password" | "url";\r\n required: boolean;\r\n placeholder?: string;\r\n }[];\r\n inputValues: Record;\r\n models: (TextModel | ImageModel | VideoModel)[];\r\n}\r\n// ==================== 全局工具函数 ====================\r\n//Axios实例\r\n//压缩图片大小(1MB = 1 * 1024 * 1024)\r\ndeclare const zipImage: (completeBase64: string, size: number) => Promise;\r\n//压缩图片分辨率\r\ndeclare const zipImageResolution: (completeBase64: string, width: number, height: number) => Promise;\r\n//多图拼接乘单图 maxSize 最大输出大小,默认为 10mb\r\ndeclare const mergeImages: (completeBase64: string[], maxSize?: string) => Promise;\r\n//Url转Base64\r\ndeclare const urlToBase64: (url: string) => Promise;\r\n//轮询函数\r\ndeclare const pollTask: (\r\n fn: () => Promise<{ completed: boolean; data?: string; error?: string }>,\r\n interval?: number,\r\n timeout?: number,\r\n) => Promise<{ completed: boolean; data?: string; error?: string }>;\r\ndeclare const axios: any;\r\ndeclare const createOpenAI: any;\r\ndeclare const createDeepSeek: any;\r\ndeclare const createZhipu: any;\r\ndeclare const createQwen: any;\r\ndeclare const createAnthropic: any;\r\ndeclare const createOpenAICompatible: any;\r\ndeclare const createXai: any;\r\ndeclare const createMinimax: any;\r\ndeclare const createGoogleGenerativeAI: any;\r\ndeclare const logger: (logstring: string) => void;\r\ndeclare const jsonwebtoken: any;\r\n// ==================== 供应商数据 ====================\r\nconst ARK_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";\r\nconst SUCCESS_TASK_STATUS = ["succeeded", "completed", "success"];\r\nconst FAILED_TASK_STATUS = ["failed", "failure", "error", "canceled", "cancelled"];\r\n\r\nconst vendor: VendorConfig = {\r\n id: "volcengine",\r\n author: "leeqi",\r\n description:\r\n "火山引擎方舟官方直连模板,接入 Ark 的文本、图片、视频生成 API,支持 Doubao、DeepSeek、GLM 等模型。\\n[](https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey)",\r\n name: "火山引擎",\r\n inputs: [\r\n { key: "apiKey", label: "ARK API Key", type: "password", required: true },\r\n { key: "text", label: "文本生成接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "baseUrl", label: "Ark Base URL", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "image", label: "图片生成接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "videoCreate", label: "视频任务创建接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n { key: "videoQuery", label: "视频任务查询接口", type: "url", required: false, placeholder: "如非必要请勿更改" },\r\n ],\r\n inputValues: {\r\n apiKey: "",\r\n text: ARK_BASE_URL,\r\n baseUrl: ARK_BASE_URL,\r\n image: `${ARK_BASE_URL}/images/generations`,\r\n videoCreate: `${ARK_BASE_URL}/contents/generations/tasks`,\r\n videoQuery: `${ARK_BASE_URL}/contents/generations/tasks/{id}`,\r\n },\r\n models: [\r\n {\r\n name: "Doubao-Seed-2.0-pro",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-pro-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-lite",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-lite-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-mini",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-mini-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seed-2.0-Code",\r\n type: "text",\r\n modelName: "doubao-seed-2-0-code-preview-260215",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-1.5-pro-32k",\r\n type: "text",\r\n modelName: "doubao-1-5-pro-32k-250115",\r\n think: false,\r\n },\r\n {\r\n name: "deepseek-v3-250324",\r\n type: "text",\r\n modelName: "deepseek-v3-250324",\r\n think: false,\r\n },\r\n {\r\n name: "glm-4-7-251222",\r\n type: "text",\r\n modelName: "glm-4-7-251222",\r\n think: false,\r\n },\r\n {\r\n name: "Doubao-Seedream-5.0-lite",\r\n type: "image",\r\n modelName: "doubao-seedream-5-0-260128",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedream-4.5",\r\n type: "image",\r\n modelName: "doubao-seedream-4-5-251128",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedream-4.0",\r\n type: "image",\r\n modelName: "doubao-seedream-4-0-250828",\r\n mode: ["text", "singleImage", "multiReference"],\r\n },\r\n {\r\n name: "Doubao-Seedance-1.5-pro",\r\n type: "video",\r\n modelName: "doubao-seedance-1-5-pro-251215",\r\n mode: ["text", "singleImage", "endFrameOptional"],\r\n audio: true,\r\n durationResolutionMap: [{ duration: [4, 5, 6, 7, 8, 9, 10, 11, 12], resolution: ["480p", "720p", "1080p"] }],\r\n },\r\n {\r\n name: "Doubao-Seedance-1.0-pro-fast",\r\n type: "video",\r\n modelName: "doubao-seedance-1-0-pro-fast-251015",\r\n mode: ["text", "singleImage"],\r\n audio: false,\r\n durationResolutionMap: [{ duration: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], resolution: ["480p", "720p", "1080p"] }],\r\n },\r\n {\r\n name: "Doubao-Seedance-2.0",\r\n modelName: "doubao-seedance-2-0-260128",\r\n type: "video",\r\n mode: [["textReference", "videoReference", "imageReference", "audioReference"]],\r\n audio: "optional",\r\n durationResolutionMap: [\r\n {\r\n duration: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],\r\n resolution: ["480p", "720p"],\r\n },\r\n ],\r\n associationSkills: "",\r\n },\r\n ],\r\n};\r\nexports.vendor = vendor;\r\n\r\n// ==================== 适配器函数 ====================\r\nconst getApiKey = () => {\r\n if (!vendor.inputValues.apiKey) throw new Error("缺少API Key");\r\n return vendor.inputValues.apiKey.replace(/^Bearer\\s+/i, "");\r\n};\r\n\r\nconst getBaseUrl = () => vendor.inputValues.baseUrl || ARK_BASE_URL;\r\nconst buildUrl = (overrideUrl: string | undefined, fallbackPath: string) => overrideUrl || `${getBaseUrl().replace(/\\/$/, "")}${fallbackPath}`;\r\n\r\nconst getHeaders = () => ({\r\n Authorization: `Bearer ${getApiKey()}`,\r\n "Content-Type": "application/json",\r\n});\r\n\r\nconst getOpenAIBaseUrl = () =>\r\n (vendor.inputValues.text || getBaseUrl())\r\n .trim()\r\n .replace(/\\/$/, "")\r\n .replace(/\\/chat\\/completions$/i, "");\r\n\r\nconst readJson = async (response: Response, action: string) => {\r\n if (!response.ok) {\r\n const errorText = await response.text();\r\n throw new Error(`${action}失败,状态码: ${response.status}, 错误信息: ${errorText}`);\r\n }\r\n\r\n return response.json();\r\n};\r\n\r\n//补齐图片 data url 前缀\r\nconst normalizeImageInput = (value: string) => {\r\n if (!value) return value;\r\n if (/^(https?:\\/\\/|data:|volc:)/i.test(value)) return value;\r\n return `data:image/png;base64,${value}`;\r\n};\r\n\r\nconst normalizeImageList = (imageBase64?: string[]) => (imageBase64 || []).filter(Boolean).map(normalizeImageInput);\r\n\r\nconst extractImageResult = (data: any) => {\r\n const first = data?.data?.[0] ?? data?.images?.[0] ?? data?.output?.[0];\r\n return first?.url ?? first?.image_url ?? first?.b64_json ?? first?.base64;\r\n};\r\n\r\nconst extractTaskId = (data: any) => data?.id ?? data?.task_id ?? data?.taskId ?? data?.data?.id ?? data?.data?.task_id ?? data?.data;\r\n\r\nconst extractVideoUrl = (data: any) =>\r\n data?.content?.video_url ??\r\n data?.content?.video_urls?.[0] ??\r\n data?.data?.content?.video_url ??\r\n data?.data?.content?.video_urls?.[0] ??\r\n data?.data?.video_url ??\r\n data?.result?.video_url ??\r\n data?.result_url ??\r\n data?.data?.result_url;\r\n\r\nconst getTaskStatus = (data: any) => (data?.status ?? data?.data?.status ?? "").toString().toLowerCase();\r\n\r\nconst getTaskError = (data: any) =>\r\n data?.error?.message ?? data?.message ?? data?.data?.message ?? data?.data?.fail_reason ?? data?.fail_reason ?? "任务执行失败";\r\n\r\n// 文本请求函数\r\nconst textRequest: (textModel: TextModel) => { url: string; model: string } = (textModel) => {\r\n return createOpenAI({\r\n baseURL: getOpenAIBaseUrl(),\r\n apiKey: getApiKey(),\r\n }).chat(textModel.modelName);\r\n};\r\nexports.textRequest = textRequest;\r\n\r\n//图片请求函数\r\ninterface ImageConfig {\r\n prompt: string; //图片提示词\r\n imageBase64: string[]; //输入的图片提示词\r\n size: "1K" | "2K" | "4K"; // 图片尺寸\r\n aspectRatio: `${number}:${number}`; // 长宽比\r\n}\r\n\r\nconst normalizeImageSize = (imageConfig: ImageConfig) => {\r\n const normalizedAspectRatio = imageConfig.aspectRatio;\r\n const size = imageConfig.size === "1K" ? "2K" : imageConfig.size;\r\n\r\n const sizeMap: Record> = {\r\n "16:9": {\r\n "2K": "2848x1600",\r\n "4K": "4096x2304",\r\n },\r\n "9:16": {\r\n "2K": "1600x2848",\r\n "4K": "2304x4096",\r\n },\r\n };\r\n return sizeMap[normalizedAspectRatio][size];\r\n};\r\n\r\nconst imageRequest = async (imageConfig: ImageConfig, imageModel: ImageModel) => {\r\n const images = normalizeImageList(imageConfig.imageBase64);\r\n const body = {\r\n model: imageModel.modelName,\r\n prompt: imageConfig.prompt,\r\n size: normalizeImageSize(imageConfig),\r\n response_format: "url",\r\n sequential_image_generation: "disabled",\r\n stream: false,\r\n watermark: false,\r\n ...(images.length ? { image: images.length === 1 ? images[0] : images } : {}),\r\n };\r\n\r\n const data = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.image, "/images/generations"), {\r\n method: "POST",\r\n headers: getHeaders(),\r\n body: JSON.stringify(body),\r\n }),\r\n "图片生成",\r\n );\r\n\r\n const result = extractImageResult(data);\r\n if (!result) throw new Error(`图片生成返回格式异常: ${JSON.stringify(data)}`);\r\n return result;\r\n};\r\nexports.imageRequest = imageRequest;\r\n\r\ninterface VideoConfig {\r\n duration: number;\r\n resolution: string;\r\n aspectRatio: "16:9" | "9:16";\r\n prompt: string;\r\n imageBase64?: string[];\r\n audio?: boolean;\r\n mode:\r\n | "singleImage" // 单图\r\n | "multiImage" // 多图模式\r\n | "gridImage" // 网格单图(传入一张图片,但该图片是网格图)\r\n | "startEndRequired" // 首尾帧(两张都得有)\r\n | "endFrameOptional" // 首尾帧(尾帧可选)\r\n | "startFrameOptional" // 首尾帧(首帧可选)\r\n | "text" // 文本生视频\r\n | ("video" | "image" | "audio" | "text")[]; // 混合参考\r\n}\r\n\r\nconst isSeedanceModel = (modelName: string) => /^doubao-seedance-/i.test(modelName);\r\nconst isSeedance15ProModel = (modelName: string) => /^doubao-seedance-1-5-pro/i.test(modelName);\r\n\r\nconst appendPromptFlag = (prompt: string, flag: string, value: string | number | boolean | undefined) => {\r\n if (value === undefined || value === null || value === "") return prompt;\r\n const normalizedPrompt = prompt.trim();\r\n const flagPattern = new RegExp(`(^|\\\\s)--${flag}(?:\\\\s+\\\\S+)?(?=\\\\s|$)`, "i");\r\n if (flagPattern.test(normalizedPrompt)) return normalizedPrompt;\r\n return `${normalizedPrompt} --${flag} ${value}`.trim();\r\n};\r\n\r\nconst buildVideoPrompt = (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n if (!isSeedanceModel(videoModel.modelName)) return videoConfig.prompt || "";\r\n\r\n let prompt = videoConfig.prompt || "";\r\n prompt = appendPromptFlag(prompt, "resolution", videoConfig.resolution);\r\n prompt = appendPromptFlag(prompt, "duration", videoConfig.duration);\r\n prompt = appendPromptFlag(prompt, "camerafixed", false);\r\n prompt = appendPromptFlag(prompt, "watermark", false);\r\n return prompt;\r\n};\r\n\r\n//判断base64前缀 适配多参\r\nfunction getBase64Type(base64: string) {\r\n const match = base64.match(/^data:([-\\w]+)\\/([-\\w]+);base64,/);\r\n if (!match) return "unknown";\r\n const mainType = match[1];\r\n if (mainType === "image") return "image";\r\n if (mainType === "audio") return "audio";\r\n if (mainType === "video") return "video";\r\n return "unknown";\r\n}\r\n\r\nconst buildVideoContent = (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n const images = videoConfig?.imageBase64 ?? [];\r\n const content: any[] = [{ type: "text", text: buildVideoPrompt(videoConfig, videoModel) }];\r\n if (videoConfig.mode == "startEndRequired" || videoConfig.mode == "endFrameOptional") {\r\n images[0] && content.push({ type: "image_url", image_url: { url: images[0] }, role: "first_frame" });\r\n images[1] && content.push({ type: "image_url", image_url: { url: images[1] }, role: "last_frame" });\r\n }\r\n if (Array.isArray(videoConfig.mode)) {\r\n images.forEach((item) => {\r\n const type = getBase64Type(item);\r\n if (type == "audio") {\r\n content.push({\r\n type: "audio_url",\r\n audio_url: { url: item },\r\n role: "reference_audio",\r\n });\r\n } else if (type == "video") {\r\n content.push({\r\n type: "video_url",\r\n video_url: { url: item },\r\n role: "reference_video",\r\n });\r\n } else {\r\n content.push({\r\n type: "image_url",\r\n image_url: { url: item },\r\n role: "reference_image",\r\n });\r\n }\r\n });\r\n }\r\n if (videoConfig.mode == "singleImage") {\r\n images[0] && content.push({ type: "image_url", image_url: { url: images[0] } });\r\n }\r\n return content;\r\n};\r\n\r\nconst buildVideoBody = (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n const isSeedance = isSeedanceModel(videoModel.modelName);\r\n const isSeedance15Pro = isSeedance15ProModel(videoModel.modelName);\r\n\r\n return {\r\n model: videoModel.modelName,\r\n content: buildVideoContent(videoConfig, videoModel),\r\n ...(!isSeedance15Pro && !isSeedance\r\n ? {\r\n duration: videoConfig.duration,\r\n resolution: videoConfig.resolution,\r\n ratio: videoConfig.aspectRatio,\r\n }\r\n : {}),\r\n ...(videoModel.audio === true && typeof videoConfig.audio === "boolean" ? { generate_audio: videoConfig.audio } : {}),\r\n };\r\n};\r\n\r\nconst queryVideoResult = async (taskId: string) => {\r\n const queryData = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.videoQuery, "/contents/generations/tasks/{id}").replace("{id}", taskId), {\r\n method: "GET",\r\n headers: getHeaders(),\r\n }),\r\n "视频任务查询",\r\n );\r\n\r\n const status = getTaskStatus(queryData);\r\n if (SUCCESS_TASK_STATUS.includes(status)) {\r\n const videoUrl = extractVideoUrl(queryData);\r\n if (!videoUrl) return { completed: true, error: `视频任务成功但未返回结果: ${JSON.stringify(queryData)}` };\r\n return { completed: true, data: videoUrl };\r\n }\r\n\r\n if (FAILED_TASK_STATUS.includes(status)) {\r\n return { completed: false, error: getTaskError(queryData) };\r\n }\r\n\r\n return { completed: false };\r\n};\r\n\r\nconst videoRequest = async (videoConfig: VideoConfig, videoModel: VideoModel) => {\r\n const createData = await readJson(\r\n await fetch(buildUrl(vendor.inputValues.videoCreate, "/contents/generations/tasks"), {\r\n method: "POST",\r\n headers: getHeaders(),\r\n body: JSON.stringify(buildVideoBody(videoConfig, videoModel)),\r\n }),\r\n "视频任务创建",\r\n );\r\n\r\n const taskId = extractTaskId(createData);\r\n if (!taskId) throw new Error(`视频任务创建返回格式异常: ${JSON.stringify(createData)}`);\r\n\r\n const result = await pollTask(() => queryVideoResult(taskId));\r\n if (result.error) throw new Error(result.error);\r\n return result.data;\r\n};\r\nexports.videoRequest = videoRequest;\r\n\r\ninterface TTSConfig {\r\n text: string;\r\n voice: string;\r\n speechRate: number;\r\n pitchRate: number;\r\n volume: number;\r\n}\r\n\r\nconst ttsRequest = async (ttsConfig: TTSConfig, ttsModel: TTSModel) => {\r\n return null;\r\n};\r\nexports.ttsRequest = ttsRequest;\r\n', enable: 0, - createTime: 1775172727809, + createTime: 1775407135202, }, { id: "minimax",