From 624e0455526251ee7457404b0c15f1a35954ab16 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, 30 Mar 2026 21:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agents/scriptAgent/index.ts | 6 +- src/routes/setting/vendorConfig/addVendor.ts | 9 +-- src/routes/setting/vendorConfig/updateCode.ts | 9 ++- .../setting/vendorConfig/updateVendor.ts | 70 ++----------------- src/types/database.d.ts | 62 ++-------------- src/utils/ai.ts | 19 ++++- src/utils/vm.ts | 50 +++++++------ 7 files changed, 64 insertions(+), 161 deletions(-) diff --git a/src/agents/scriptAgent/index.ts b/src/agents/scriptAgent/index.ts index de24001..ea57518 100644 --- a/src/agents/scriptAgent/index.ts +++ b/src/agents/scriptAgent/index.ts @@ -139,7 +139,7 @@ function createSubAgent(parentCtx: AgentContext) { const systemPrompt = await fs.promises.readFile(skill, "utf-8"); return runAgent({ prompt, - system: systemPrompt + "你可以使用如下XML格式写入工作区:\n故事骨架内容", + system: systemPrompt + "\n你可以使用如下XML格式写入工作区:\n故事骨架内容", name: "编剧", memoryKey: "assistant:execution:storySkeleton", }); @@ -154,7 +154,7 @@ function createSubAgent(parentCtx: AgentContext) { const systemPrompt = await fs.promises.readFile(skill, "utf-8"); return runAgent({ prompt, - system: systemPrompt + "你可以使用如下XML格式写入工作区:\n改编策略内容", + system: systemPrompt + "\n你可以使用如下XML格式写入工作区:\n改编策略内容", name: "编剧", memoryKey: "assistant:execution:adaptationStrategy", }); @@ -171,7 +171,7 @@ function createSubAgent(parentCtx: AgentContext) { prompt, system: systemPrompt + - `你可以使用如下XML格式写入工作区:\nXML不得添加任何额外标签`, + `\n你可以使用如下XML格式写入工作区:\nXML不得添加任何额外标签`, name: "编剧", memoryKey: "assistant:execution:script", }); diff --git a/src/routes/setting/vendorConfig/addVendor.ts b/src/routes/setting/vendorConfig/addVendor.ts index 83cf3ca..09eb31a 100644 --- a/src/routes/setting/vendorConfig/addVendor.ts +++ b/src/routes/setting/vendorConfig/addVendor.ts @@ -1,5 +1,4 @@ import express from "express"; -import { serializeError } from "serialize-error"; import { success, error } from "@/lib/responseFormat"; import { validateFields } from "@/middleware/middleware"; import u from "@/utils"; @@ -29,14 +28,14 @@ const vendorConfigSchema = z.object({ name: z.string(), modelName: z.string(), type: z.literal("text"), - multimodal: z.boolean(), - tool: z.boolean(), + think: z.boolean(), }), z.object({ name: z.string(), modelName: z.string(), type: z.literal("image"), mode: z.array(z.enum(["text", "singleImage", "multiReference"])), + associationSkills:z.string().optional(), }), z.object({ name: z.string(), @@ -46,8 +45,6 @@ const vendorConfigSchema = z.object({ z.union([ z.enum([ "singleImage", - "multiImage", - "gridImage", "startEndRequired", "endFrameOptional", "startFrameOptional", @@ -55,7 +52,7 @@ const vendorConfigSchema = z.object({ "audioReference", "videoReference", ]), - z.array(z.enum(["video", "image", "audio", "text"])), + z.array(z.enum(["videoReference", "imageReference", "audioReference", "textReference"])), ]), ), audio: z.union([z.literal("optional"), z.boolean()]), diff --git a/src/routes/setting/vendorConfig/updateCode.ts b/src/routes/setting/vendorConfig/updateCode.ts index aa1cf43..3f544e0 100644 --- a/src/routes/setting/vendorConfig/updateCode.ts +++ b/src/routes/setting/vendorConfig/updateCode.ts @@ -29,14 +29,14 @@ const vendorConfigSchema = z.object({ name: z.string(), modelName: z.string(), type: z.literal("text"), - multimodal: z.boolean(), - tool: z.boolean(), + think: z.boolean(), }), z.object({ name: z.string(), modelName: z.string(), type: z.literal("image"), mode: z.array(z.enum(["text", "singleImage", "multiReference"])), + associationSkills:z.string().optional(), }), z.object({ name: z.string(), @@ -46,8 +46,6 @@ const vendorConfigSchema = z.object({ z.union([ z.enum([ "singleImage", - "multiImage", - "gridImage", "startEndRequired", "endFrameOptional", "startFrameOptional", @@ -55,9 +53,10 @@ const vendorConfigSchema = z.object({ "audioReference", "videoReference", ]), - z.array(z.enum(["video", "image", "audio", "text"])), + z.array(z.enum(["audioReference", "videoReference", "textReference", "imageReference"])), ]), ), + associationSkills:z.string().optional(), audio: z.union([z.literal("optional"), z.boolean()]), durationResolutionMap: z.array( z.object({ diff --git a/src/routes/setting/vendorConfig/updateVendor.ts b/src/routes/setting/vendorConfig/updateVendor.ts index 71c7e42..0d066b8 100644 --- a/src/routes/setting/vendorConfig/updateVendor.ts +++ b/src/routes/setting/vendorConfig/updateVendor.ts @@ -6,69 +6,6 @@ import { z } from "zod"; import { transform } from "sucrase"; const router = express.Router(); -const vendorConfigSchema = z.object({ - id: z.string(), - author: z.string(), - description: z.string().optional(), - name: z.string(), - icon: z.string().optional(), - inputs: z.array( - z.object({ - key: z.string(), - label: z.string(), - type: z.enum(["text", "password", "url"]), - required: z.boolean(), - placeholder: z.string().optional(), - }), - ), - inputValues: z.record(z.string(), z.string()), - models: z.array( - z.discriminatedUnion("type", [ - z.object({ - name: z.string(), - modelName: z.string(), - type: z.literal("text"), - multimodal: z.boolean(), - tool: z.boolean(), - }), - z.object({ - name: z.string(), - modelName: z.string(), - type: z.literal("image"), - mode: z.array(z.enum(["text", "singleImage", "multiReference"])), - }), - z.object({ - name: z.string(), - modelName: z.string(), - type: z.literal("video"), - mode: z.array( - z.union([ - z.enum([ - "singleImage", - "multiImage", - "gridImage", - "startEndRequired", - "endFrameOptional", - "startFrameOptional", - "text", - "audioReference", - "videoReference", - ]), - z.array(z.enum(["video", "image", "audio", "text"])), - ]), - ), - audio: z.union([z.literal("optional"), z.boolean()]), - durationResolutionMap: z.array( - z.object({ - duration: z.array(z.number()), - resolution: z.array(z.string()), - }), - ), - }), - ]), - ), -}); - export default router.post( "/", validateFields({ @@ -89,14 +26,14 @@ export default router.post( name: z.string(), modelName: z.string(), type: z.literal("text"), - multimodal: z.boolean(), - tool: z.boolean(), + think: z.boolean(), }), z.object({ name: z.string(), modelName: z.string(), type: z.literal("image"), mode: z.array(z.enum(["text", "singleImage", "multiReference"])), + associationSkills: z.string().optional(), }), z.object({ name: z.string(), @@ -104,10 +41,11 @@ export default router.post( type: z.literal("video"), mode: z.array( z.union([ - z.enum(["singleImage", "multiImage", "gridImage", "startEndRequired", "endFrameOptional", "startFrameOptional", "text"]), + z.enum(["singleImage", "startEndRequired", "endFrameOptional", "startFrameOptional", "text"]), z.array(z.enum(["audioReference", "videoReference", "textReference", "imageReference"])), ]), ), + associationSkills: z.string().optional(), audio: z.union([z.literal("optional"), z.boolean()]), durationResolutionMap: z.array( z.object({ diff --git a/src/types/database.d.ts b/src/types/database.d.ts index 9accb03..2a3bc57 100644 --- a/src/types/database.d.ts +++ b/src/types/database.d.ts @@ -1,62 +1,13 @@ -// @db-hash ea0c51ccb8c93a2f019139db9621721e +// @db-hash 93b2462070c45c2b449e9a18c4e88763 //该文件由脚本自动生成,请勿手动修改 -export interface _o_project_old_20260330 { - 'artStyle'?: string | null; - 'createTime'?: number | null; - 'id'?: number | null; - 'intro'?: string | null; - 'name'?: string | null; - 'projectType'?: string | null; - 'type'?: string | null; - 'userId'?: number | null; - 'videoRatio'?: string | null; -} -export interface _o_storyboard_old_20260325 { - 'camera'?: string | null; - 'createTime'?: number | null; - 'description'?: string | null; - 'duration'?: string | null; - 'filePath'?: string | null; - 'frameMode'?: string | null; - 'id'?: number; - 'lines'?: string | null; - 'mode'?: string | null; - 'model'?: string | null; - 'prompt'?: string | null; - 'reason'?: string | null; - 'resolution'?: string | null; - 'scriptId'?: number | null; - 'sound'?: string | null; - 'state'?: string | null; - 'title'?: string | null; -} -export interface _o_storyboard_old_20260330 { - 'camera'?: string | null; - 'createTime'?: number | null; - 'description'?: string | null; - 'duration'?: string | null; - 'filePath'?: string | null; - 'frameMode'?: string | null; - 'id'?: number; - 'index'?: string | null; - 'lines'?: string | null; - 'mode'?: string | null; - 'model'?: string | null; - 'prompt'?: string | null; - 'reason'?: string | null; - 'resolution'?: string | null; - 'scriptId'?: number | null; - 'sound'?: string | null; - 'state'?: string | null; - 'title'?: string | null; -} export interface memories { 'content': string; 'createTime': number; 'embedding'?: string | null; 'id'?: string; 'isolationKey': string; + 'name'?: string | null; 'relatedMessageIds'?: string | null; 'role'?: string | null; 'summarized'?: number | null; @@ -96,6 +47,7 @@ export interface o_assets { 'name'?: string | null; 'projectId'?: number | null; 'prompt'?: string | null; + 'promptState'?: string | null; 'remark'?: string | null; 'scriptId'?: number | null; 'startTime'?: number | null; @@ -177,6 +129,8 @@ export interface o_prompt { export interface o_script { 'content'?: string | null; 'createTime'?: number | null; + 'errorReason'?: string | null; + 'extractState'?: number | null; 'id'?: number; 'name'?: string | null; 'projectId'?: number | null; @@ -213,7 +167,7 @@ export interface o_storyboard { 'filePath'?: string | null; 'frameMode'?: string | null; 'id'?: number; - 'index'?: string | null; + 'index'?: number | null; 'lines'?: string | null; 'mode'?: string | null; 'model'?: string | null; @@ -224,7 +178,6 @@ export interface o_storyboard { 'sound'?: string | null; 'state'?: string | null; 'title'?: string | null; - 'videoPrompt'?: string | null; } export interface o_tasks { 'describe'?: string | null; @@ -279,9 +232,6 @@ export interface o_videoConfig { } export interface DB { - "_o_project_old_20260330": _o_project_old_20260330; - "_o_storyboard_old_20260325": _o_storyboard_old_20260325; - "_o_storyboard_old_20260330": _o_storyboard_old_20260330; "memories": memories; "o_agentDeploy": o_agentDeploy; "o_agentWorkData": o_agentWorkData; diff --git a/src/utils/ai.ts b/src/utils/ai.ts index ac8fea7..9c6df1e 100644 --- a/src/utils/ai.ts +++ b/src/utils/ai.ts @@ -25,10 +25,23 @@ async function getVendorTemplateFn(fnName: FnName, modelName: `${string}:${strin const selectedModel = modelList.find((i: any) => i.modelName == name); if (!selectedModel) throw new Error(`未找到模型 ${name} id=${id}`); const jsCode = transform(vendorConfigData.code!, { transforms: ["typescript"] }).code; - const fn = u.vm(jsCode)[fnName]; + const running = u.vm(jsCode); + Object.assign(running.vendor.inputValues, JSON.parse(vendorConfigData.inputValues ?? "{}")); + running.vendor.models = modelList; + const fn = running[fnName]; if (!fn) throw new Error(`未找到供应商配置中的函数 ${fnName} id=${id}`); - if (fnName == "textRequest") return fn(selectedModel); - else return (input: T) => fn(input, selectedModel); + if (fnName == "textRequest") { + const model = fn(selectedModel); + if (!model) throw new Error(`供应商 textRequest 返回无效模型 id=${id}`); + return model; + } + return async (input: T) => { + const result = await fn(input, selectedModel); + if (result === undefined || result === null) { + throw new Error(`供应商函数 ${fnName} 未返回有效结果 id=${id}`); + } + return result; + }; } async function withTaskRecord( diff --git a/src/utils/vm.ts b/src/utils/vm.ts index 677fe47..133c4f6 100644 --- a/src/utils/vm.ts +++ b/src/utils/vm.ts @@ -11,33 +11,39 @@ import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { createXai } from "@ai-sdk/xai"; import { createMinimax } from "vercel-minimax-ai-provider"; import FormData from "form-data"; +import jsonwebtoken from "jsonwebtoken"; -export default function runCode(code: string) { +export default function runCode(code: string, vendor?: Record) { // 创建一个沙盒 const exports = {}; + const sandbox: Record = { + createOpenAI, + createDeepSeek, + createZhipu, + createQwen, + createAnthropic, + createOpenAICompatible, + createXai, + createMinimax, + createGoogleGenerativeAI, + zipImage, + zipImageResolution, + urlToBase64, + mergeImages, + pollTask, + fetch, + exports, + axios, + FormData, + logger, + jsonwebtoken, + }; + if (vendor !== undefined) { + sandbox.vendor = vendor; + } const vm = new VM({ timeout: 0, - sandbox: { - createOpenAI, - createDeepSeek, - createZhipu, - createQwen, - createAnthropic, - createOpenAICompatible, - createXai, - createMinimax, - createGoogleGenerativeAI, - zipImage, - zipImageResolution, - urlToBase64, - mergeImages, - pollTask, - fetch, - exports, - axios, - FormData, - logger, - }, + sandbox, compiler: "javascript", eval: false, wasm: false,