生产agent接入真实数据,并完善记忆、历史
This commit is contained in:
parent
2b18e066ee
commit
5c1a8bb02a
46
NOTICES.txt
46
NOTICES.txt
@ -40,6 +40,12 @@ Repository: https://github.com/vercel/ai
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: @huggingface/transformers
|
||||
License: Apache-2.0
|
||||
Repository: https://github.com/huggingface/transformers.js
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: @rmp135/sql-ts
|
||||
License: MIT
|
||||
Repository: https://github.com/rmp135/sql-ts
|
||||
@ -76,6 +82,12 @@ Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: @types/lodash
|
||||
License: MIT
|
||||
Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: @types/morgan
|
||||
License: MIT
|
||||
Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@ -178,6 +190,12 @@ Repository: https://github.com/form-data/form-data
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: graphlib
|
||||
License: MIT
|
||||
Repository: https://github.com/dagrejs/graphlib
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: is-path-inside
|
||||
License: MIT
|
||||
Repository: https://github.com/sindresorhus/is-path-inside
|
||||
@ -208,6 +226,12 @@ Repository: https://github.com/davglass/license-checker
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: lodash
|
||||
License: MIT
|
||||
Repository: https://github.com/lodash/lodash
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: morgan
|
||||
License: MIT
|
||||
Repository: https://github.com/expressjs/morgan
|
||||
@ -220,9 +244,9 @@ Repository: https://github.com/remy/nodemon
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: qwen-ai-provider
|
||||
Name: qwen-ai-provider-v5
|
||||
License: Apache-2.0
|
||||
Repository: https://github.com/Younis-Ahmed/qwen-ai-provider
|
||||
Repository: https://github.com/bolechen/qwen-ai-provider-v5
|
||||
|
||||
-----------------------------
|
||||
|
||||
@ -244,12 +268,24 @@ Repository: https://github.com/lovell/sharp
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: socket.io
|
||||
License: MIT
|
||||
Repository: https://github.com/socketio/socket.io
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: sqlite3
|
||||
License: BSD-3-Clause
|
||||
Repository: https://github.com/TryGhost/node-sqlite3
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: sucrase
|
||||
License: MIT
|
||||
Repository: https://github.com/alangpierce/sucrase
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: tsx
|
||||
License: MIT
|
||||
Repository: https://github.com/privatenumber/tsx
|
||||
@ -268,6 +304,12 @@ Repository: https://github.com/uuidjs/uuid
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: vm2
|
||||
License: MIT
|
||||
Repository: https://github.com/patriksimek/vm2
|
||||
|
||||
-----------------------------
|
||||
|
||||
Name: zhipu-ai-provider
|
||||
License: Apache-2.0
|
||||
Repository: https://github.com/Xiang-CH/zhipu-ai-provider
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
"license": "bun run scripts/license.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ag-ui/core": "^0.0.47",
|
||||
"@ai-sdk/anthropic": "^3.0.35",
|
||||
"@ai-sdk/deepseek": "^2.0.17",
|
||||
"@ai-sdk/devtools": "^0.0.11",
|
||||
|
||||
@ -35,7 +35,7 @@ function buildSystemPrompt(skillPrompt: string, mem: Awaited<ReturnType<Memory["
|
||||
const subAgentList = ["executionAI", "supervisionAI"] as const;
|
||||
|
||||
export async function decisionAI(ctx: AgentContext) {
|
||||
const { socket, isolationKey, text, abortSignal } = ctx;
|
||||
const { isolationKey, text, abortSignal } = ctx;
|
||||
const memory = new Memory("productionAgent", isolationKey);
|
||||
await memory.add("user", text);
|
||||
const [skill, mem] = await Promise.all([useSkill("production-agent", "decision"), memory.get(text)]);
|
||||
@ -55,7 +55,7 @@ export async function decisionAI(ctx: AgentContext) {
|
||||
...useTools(ctx.resTool),
|
||||
},
|
||||
onFinish: async (completion) => {
|
||||
await memory.add("decisionAI", completion.text);
|
||||
await memory.add("assistant:decision", completion.text);
|
||||
},
|
||||
});
|
||||
|
||||
@ -84,7 +84,7 @@ export async function executionAI(ctx: AgentContext) {
|
||||
...useTools(ctx.resTool),
|
||||
},
|
||||
onFinish: async (completion) => {
|
||||
await memory.add("executionAI", completion.text);
|
||||
await memory.add("assistant:execution", completion.text);
|
||||
},
|
||||
});
|
||||
|
||||
@ -94,7 +94,6 @@ export async function executionAI(ctx: AgentContext) {
|
||||
export async function supervisionAI(ctx: AgentContext) {
|
||||
const { isolationKey, text, abortSignal } = ctx;
|
||||
const memory = new Memory("productionAgent", isolationKey);
|
||||
await memory.add("user", text);
|
||||
const [skill, mem] = await Promise.all([useSkill("production-agent", "supervision"), memory.get(text)]);
|
||||
|
||||
const systemPrompt = buildSystemPrompt(skill.prompt, mem);
|
||||
@ -108,7 +107,7 @@ export async function supervisionAI(ctx: AgentContext) {
|
||||
...memory.getTools(),
|
||||
},
|
||||
onFinish: async (completion) => {
|
||||
await memory.add("supervisionAI", completion.text);
|
||||
await memory.add("assistant:supervision", completion.text);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import { z } from "zod";
|
||||
import _ from "lodash";
|
||||
import ResTool from "@/socket/resTool";
|
||||
|
||||
const deriveAssetSchema = z.object({
|
||||
export const deriveAssetSchema = z.object({
|
||||
id: z.number().describe("衍生资产ID,如果新增则为空").optional(),
|
||||
assetsId: z.string().describe("关联的资产ID"),
|
||||
name: z.string().describe("衍生资产名称"),
|
||||
@ -11,14 +11,14 @@ const deriveAssetSchema = z.object({
|
||||
src: z.string().describe("衍生资产资源路径"),
|
||||
state: z.enum(["未生成", "生成中", "已完成", "生成失败"]).describe("衍生资产生成状态"),
|
||||
});
|
||||
const assetItemSchema = z.object({
|
||||
export const assetItemSchema = z.object({
|
||||
assetsId: z.string().describe("资产唯一标识"),
|
||||
name: z.string().describe("资产名称"),
|
||||
desc: z.string().describe("资产描述"),
|
||||
src: z.string().describe("资产资源路径"),
|
||||
derive: z.array(deriveAssetSchema).describe("衍生资产列表"),
|
||||
});
|
||||
const storyboardSchema = z.object({
|
||||
export const storyboardSchema = z.object({
|
||||
id: z.number().describe("分镜ID"),
|
||||
title: z.string().describe("分镜标题"),
|
||||
description: z.string().describe("分镜描述"),
|
||||
@ -31,7 +31,7 @@ const storyboardSchema = z.object({
|
||||
associateAssetsIds: z.array(z.number()).describe("关联资产ID列表"),
|
||||
src: z.string().nullable().describe("分镜资源路径"),
|
||||
});
|
||||
const workbenchDataSchema = z.object({
|
||||
export const workbenchDataSchema = z.object({
|
||||
name: z.string().describe("项目名称"),
|
||||
duration: z.string().describe("视频时长"),
|
||||
resolution: z.string().describe("分辨率"),
|
||||
@ -39,11 +39,11 @@ const workbenchDataSchema = z.object({
|
||||
cover: z.string().optional().describe("封面图片路径"),
|
||||
gradient: z.string().optional().describe("渐变色配置"),
|
||||
});
|
||||
const posterItemSchema = z.object({
|
||||
export const posterItemSchema = z.object({
|
||||
id: z.number().describe("海报ID"),
|
||||
image: z.string().describe("海报图片路径"),
|
||||
});
|
||||
const flowDataSchema = z.object({
|
||||
export const flowDataSchema = z.object({
|
||||
script: z.string().describe("剧本内容"),
|
||||
scriptPlan: z.string().describe("拍摄计划"),
|
||||
assets: z.array(assetItemSchema).describe("衍生资产"),
|
||||
@ -57,7 +57,7 @@ const flowDataSchema = z.object({
|
||||
.describe("海报配置"),
|
||||
});
|
||||
|
||||
type FlowData = z.infer<typeof flowDataSchema>;
|
||||
export type FlowData = z.infer<typeof flowDataSchema>;
|
||||
|
||||
const keySchema = z.enum(Object.keys(flowDataSchema.shape) as [keyof FlowData, ...Array<keyof FlowData>]);
|
||||
const flowDataKeyLabels = Object.fromEntries(
|
||||
|
||||
@ -329,8 +329,12 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
||||
name: "o_flowData",
|
||||
builder: (table) => {
|
||||
table.integer("id").notNullable();
|
||||
table.string("name");
|
||||
table.integer("projectId");
|
||||
table.integer("espisodeId");
|
||||
table.string("key"); //用户其他方式索引
|
||||
table.string("data");
|
||||
table.integer("createTime");
|
||||
table.integer("updateTime");
|
||||
table.primary(["id"]);
|
||||
table.unique(["id"]);
|
||||
},
|
||||
|
||||
126
src/router.ts
126
src/router.ts
@ -1,4 +1,4 @@
|
||||
// @routes-hash 3d0673061005074e704638efccc539d1
|
||||
// @routes-hash 4e2d02be3d3fe94b8130773d32713c03
|
||||
import { Express } from "express";
|
||||
|
||||
import route1 from "./routes/agents/clearMemory";
|
||||
@ -38,36 +38,38 @@ import route34 from "./routes/production/editStoryboard/generateStoryboardImage"
|
||||
import route35 from "./routes/production/editStoryboard/getStoryboardFlow";
|
||||
import route36 from "./routes/production/editStoryboard/saveStoryboardFlow";
|
||||
import route37 from "./routes/production/editStoryboard/updateStoryboardFlow";
|
||||
import route38 from "./routes/production/getProductionData";
|
||||
import route39 from "./routes/production/getStoryboardData";
|
||||
import route40 from "./routes/production/workbench/generateVideo";
|
||||
import route41 from "./routes/production/workbench/getVideoModelDetail";
|
||||
import route42 from "./routes/project/addProject";
|
||||
import route43 from "./routes/project/delProject";
|
||||
import route44 from "./routes/project/editProject";
|
||||
import route45 from "./routes/project/getProject";
|
||||
import route46 from "./routes/script/addScript";
|
||||
import route47 from "./routes/script/delScript";
|
||||
import route48 from "./routes/script/getScrptApi";
|
||||
import route49 from "./routes/script/updateScript";
|
||||
import route50 from "./routes/setting/agentDeploy/deployAgentModel";
|
||||
import route51 from "./routes/setting/agentDeploy/getAgentDeploy";
|
||||
import route52 from "./routes/setting/agentDeploy/updateKey";
|
||||
import route53 from "./routes/setting/dbConfig/clearData";
|
||||
import route54 from "./routes/setting/getTextModel";
|
||||
import route55 from "./routes/setting/loginConfig/getUser";
|
||||
import route56 from "./routes/setting/loginConfig/updateUserPwd";
|
||||
import route57 from "./routes/setting/memoryConfig/getMemory";
|
||||
import route58 from "./routes/setting/memoryConfig/sureMemory";
|
||||
import route59 from "./routes/setting/vendorConfig/addVendor";
|
||||
import route60 from "./routes/setting/vendorConfig/deleteVendor";
|
||||
import route61 from "./routes/setting/vendorConfig/getVendorList";
|
||||
import route62 from "./routes/setting/vendorConfig/modelTest";
|
||||
import route63 from "./routes/setting/vendorConfig/updateVendor";
|
||||
import route64 from "./routes/task/getMyTaskApi";
|
||||
import route65 from "./routes/task/getTaskCategories";
|
||||
import route66 from "./routes/task/taskDetails";
|
||||
import route67 from "./routes/test/test";
|
||||
import route38 from "./routes/production/getFlowData";
|
||||
import route39 from "./routes/production/getProductionData";
|
||||
import route40 from "./routes/production/getStoryboardData";
|
||||
import route41 from "./routes/production/saveFlowData";
|
||||
import route42 from "./routes/production/workbench/generateVideo";
|
||||
import route43 from "./routes/production/workbench/getVideoModelDetail";
|
||||
import route44 from "./routes/project/addProject";
|
||||
import route45 from "./routes/project/delProject";
|
||||
import route46 from "./routes/project/editProject";
|
||||
import route47 from "./routes/project/getProject";
|
||||
import route48 from "./routes/script/addScript";
|
||||
import route49 from "./routes/script/delScript";
|
||||
import route50 from "./routes/script/getScrptApi";
|
||||
import route51 from "./routes/script/updateScript";
|
||||
import route52 from "./routes/setting/agentDeploy/deployAgentModel";
|
||||
import route53 from "./routes/setting/agentDeploy/getAgentDeploy";
|
||||
import route54 from "./routes/setting/agentDeploy/updateKey";
|
||||
import route55 from "./routes/setting/dbConfig/clearData";
|
||||
import route56 from "./routes/setting/getTextModel";
|
||||
import route57 from "./routes/setting/loginConfig/getUser";
|
||||
import route58 from "./routes/setting/loginConfig/updateUserPwd";
|
||||
import route59 from "./routes/setting/memoryConfig/getMemory";
|
||||
import route60 from "./routes/setting/memoryConfig/sureMemory";
|
||||
import route61 from "./routes/setting/vendorConfig/addVendor";
|
||||
import route62 from "./routes/setting/vendorConfig/deleteVendor";
|
||||
import route63 from "./routes/setting/vendorConfig/getVendorList";
|
||||
import route64 from "./routes/setting/vendorConfig/modelTest";
|
||||
import route65 from "./routes/setting/vendorConfig/updateVendor";
|
||||
import route66 from "./routes/task/getTaskApi";
|
||||
import route67 from "./routes/task/getTaskCategories";
|
||||
import route68 from "./routes/task/taskDetails";
|
||||
import route69 from "./routes/test/test";
|
||||
|
||||
export default async (app: Express) => {
|
||||
app.use("/api/agents/clearMemory", route1);
|
||||
@ -107,34 +109,36 @@ export default async (app: Express) => {
|
||||
app.use("/api/production/editStoryboard/getStoryboardFlow", route35);
|
||||
app.use("/api/production/editStoryboard/saveStoryboardFlow", route36);
|
||||
app.use("/api/production/editStoryboard/updateStoryboardFlow", route37);
|
||||
app.use("/api/production/getProductionData", route38);
|
||||
app.use("/api/production/getStoryboardData", route39);
|
||||
app.use("/api/production/workbench/generateVideo", route40);
|
||||
app.use("/api/production/workbench/getVideoModelDetail", route41);
|
||||
app.use("/api/project/addProject", route42);
|
||||
app.use("/api/project/delProject", route43);
|
||||
app.use("/api/project/editProject", route44);
|
||||
app.use("/api/project/getProject", route45);
|
||||
app.use("/api/script/addScript", route46);
|
||||
app.use("/api/script/delScript", route47);
|
||||
app.use("/api/script/getScrptApi", route48);
|
||||
app.use("/api/script/updateScript", route49);
|
||||
app.use("/api/setting/agentDeploy/deployAgentModel", route50);
|
||||
app.use("/api/setting/agentDeploy/getAgentDeploy", route51);
|
||||
app.use("/api/setting/agentDeploy/updateKey", route52);
|
||||
app.use("/api/setting/dbConfig/clearData", route53);
|
||||
app.use("/api/setting/getTextModel", route54);
|
||||
app.use("/api/setting/loginConfig/getUser", route55);
|
||||
app.use("/api/setting/loginConfig/updateUserPwd", route56);
|
||||
app.use("/api/setting/memoryConfig/getMemory", route57);
|
||||
app.use("/api/setting/memoryConfig/sureMemory", route58);
|
||||
app.use("/api/setting/vendorConfig/addVendor", route59);
|
||||
app.use("/api/setting/vendorConfig/deleteVendor", route60);
|
||||
app.use("/api/setting/vendorConfig/getVendorList", route61);
|
||||
app.use("/api/setting/vendorConfig/modelTest", route62);
|
||||
app.use("/api/setting/vendorConfig/updateVendor", route63);
|
||||
app.use("/api/task/getMyTaskApi", route64);
|
||||
app.use("/api/task/getTaskCategories", route65);
|
||||
app.use("/api/task/taskDetails", route66);
|
||||
app.use("/api/test/test", route67);
|
||||
app.use("/api/production/getFlowData", route38);
|
||||
app.use("/api/production/getProductionData", route39);
|
||||
app.use("/api/production/getStoryboardData", route40);
|
||||
app.use("/api/production/saveFlowData", route41);
|
||||
app.use("/api/production/workbench/generateVideo", route42);
|
||||
app.use("/api/production/workbench/getVideoModelDetail", route43);
|
||||
app.use("/api/project/addProject", route44);
|
||||
app.use("/api/project/delProject", route45);
|
||||
app.use("/api/project/editProject", route46);
|
||||
app.use("/api/project/getProject", route47);
|
||||
app.use("/api/script/addScript", route48);
|
||||
app.use("/api/script/delScript", route49);
|
||||
app.use("/api/script/getScrptApi", route50);
|
||||
app.use("/api/script/updateScript", route51);
|
||||
app.use("/api/setting/agentDeploy/deployAgentModel", route52);
|
||||
app.use("/api/setting/agentDeploy/getAgentDeploy", route53);
|
||||
app.use("/api/setting/agentDeploy/updateKey", route54);
|
||||
app.use("/api/setting/dbConfig/clearData", route55);
|
||||
app.use("/api/setting/getTextModel", route56);
|
||||
app.use("/api/setting/loginConfig/getUser", route57);
|
||||
app.use("/api/setting/loginConfig/updateUserPwd", route58);
|
||||
app.use("/api/setting/memoryConfig/getMemory", route59);
|
||||
app.use("/api/setting/memoryConfig/sureMemory", route60);
|
||||
app.use("/api/setting/vendorConfig/addVendor", route61);
|
||||
app.use("/api/setting/vendorConfig/deleteVendor", route62);
|
||||
app.use("/api/setting/vendorConfig/getVendorList", route63);
|
||||
app.use("/api/setting/vendorConfig/modelTest", route64);
|
||||
app.use("/api/setting/vendorConfig/updateVendor", route65);
|
||||
app.use("/api/task/getTaskApi", route66);
|
||||
app.use("/api/task/getTaskCategories", route67);
|
||||
app.use("/api/task/taskDetails", route68);
|
||||
app.use("/api/test/test", route69);
|
||||
}
|
||||
|
||||
@ -16,10 +16,20 @@ export default router.post(
|
||||
const { projectId, episodesId, type = "all" } = req.body;
|
||||
const isolationKey = `${projectId}:${episodesId ?? ""}`;
|
||||
|
||||
const query = u.db("memories").where({ isolationKey });
|
||||
if (type !== "all") query.where("type", type);
|
||||
|
||||
await query.del();
|
||||
if (type === "all") {
|
||||
await u.db("memories").where({ isolationKey }).del();
|
||||
} else if (type === "message") {
|
||||
// 删 message 时同步删关联的 summary,避免悬挂引用
|
||||
await u.db("memories").where({ isolationKey, type: "message" }).del();
|
||||
await u.db("memories").where({ isolationKey, type: "summary" }).del();
|
||||
} else {
|
||||
// 删 summary 时将关联的 message 重置为未总结,使其重新进入 shortTerm
|
||||
await u
|
||||
.db("memories")
|
||||
.where({ isolationKey, type: "message", summarized: 1 })
|
||||
.update({ summarized: 0 });
|
||||
await u.db("memories").where({ isolationKey, type: "summary" }).del();
|
||||
}
|
||||
|
||||
res.status(200).send(success(null));
|
||||
},
|
||||
|
||||
@ -5,6 +5,15 @@ import { success } from "@/lib/responseFormat";
|
||||
import { validateFields } from "@/middleware/middleware";
|
||||
const router = express.Router();
|
||||
|
||||
function normalizeRole(role?: string | null): "user" | "assistant" {
|
||||
return role?.startsWith("assistant") ? "assistant" : "user";
|
||||
}
|
||||
|
||||
function getAssistantName(role?: string | null): string | undefined {
|
||||
if (!role?.startsWith("assistant:")) return undefined;
|
||||
return role.split(":")[1] || "assistant";
|
||||
}
|
||||
|
||||
export default router.post(
|
||||
"/",
|
||||
validateFields({
|
||||
@ -19,15 +28,16 @@ export default router.post(
|
||||
.db("memories")
|
||||
.where({ isolationKey, type: "message" })
|
||||
.orderBy("createTime", "asc")
|
||||
.select("id", "content", "createTime");
|
||||
.select("id", "role", "content", "createTime");
|
||||
|
||||
const history = rows.map((row) => ({
|
||||
id: row.id,
|
||||
role: "user",
|
||||
content: [{ type: "text", status: "complete", data: row.content }],
|
||||
role: normalizeRole(row.role),
|
||||
name: getAssistantName(row.role),
|
||||
content: [{ type: "markdown", status: "complete", data: row.content }],
|
||||
createTime: row.createTime,
|
||||
}));
|
||||
|
||||
res.status(200).send(success({ history }));
|
||||
res.status(200).send(success(history));
|
||||
},
|
||||
);
|
||||
|
||||
@ -153,6 +153,7 @@ export default router.post(
|
||||
return res.status(500).send("资产已被删除");
|
||||
}
|
||||
} catch (e) {
|
||||
console.errork(e);
|
||||
await u.db("o_image").where("id", imageId).update({
|
||||
state: "生成失败",
|
||||
});
|
||||
|
||||
82
src/routes/production/getFlowData.ts
Normal file
82
src/routes/production/getFlowData.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import express from "express";
|
||||
import u from "@/utils";
|
||||
import { z } from "zod";
|
||||
import { success, error } from "@/lib/responseFormat";
|
||||
import { validateFields } from "@/middleware/middleware";
|
||||
const router = express.Router();
|
||||
import { FlowData } from "@/agents/productionAgent/tools";
|
||||
|
||||
export default router.post(
|
||||
"/",
|
||||
validateFields({
|
||||
projectId: z.number(),
|
||||
episodesId: z.number(),
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { projectId, episodesId } = req.body;
|
||||
const sqlData = await u.db("o_flowData").where({ projectId, episodesId }).first();
|
||||
|
||||
const scriptData = await u.db("o_script").where("projectId", projectId).first();
|
||||
|
||||
const assetsData = await u
|
||||
.db("o_assets")
|
||||
.leftJoin("o_image", "o_assets.imageId", "o_image.id")
|
||||
.select("o_assets.*", "o_image.filePath")
|
||||
.where("o_assets.projectId", projectId);
|
||||
let childAssetsData = await u
|
||||
.db("o_assets")
|
||||
.leftJoin("o_image", "o_assets.imageId", "o_image.id")
|
||||
.select("o_assets.*", "o_image.filePath")
|
||||
.where("o_assets.projectId", projectId)
|
||||
.whereNotNull("o_assets.sonId");
|
||||
|
||||
if (!sqlData) {
|
||||
const flowData: FlowData = {
|
||||
script: scriptData?.content ?? "",
|
||||
scriptPlan: "",
|
||||
assets: await Promise.all(
|
||||
assetsData.map(async (item) => ({
|
||||
assetsId: item.id,
|
||||
name: item.name ?? "",
|
||||
desc: item.describe ?? "",
|
||||
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
||||
derive: await Promise.all(
|
||||
childAssetsData
|
||||
.filter((child) => child.sonId === item.id)
|
||||
.map(async (child) => ({
|
||||
id: child.id,
|
||||
assetsId: item.id,
|
||||
name: child.name ?? "",
|
||||
desc: child.describe ?? "",
|
||||
src: child.filePath && (await u.oss.getFileUrl(child.filePath!)),
|
||||
state: child.state ?? "未生成", //todo:矫正状态值
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
storyboardTable: "",
|
||||
storyboard: [],
|
||||
//todo:矫正workbench数据
|
||||
workbench: {
|
||||
name: scriptData?.name ?? "",
|
||||
duration: "01:03",
|
||||
resolution: "1920×1080",
|
||||
fps: "30fps",
|
||||
gradient: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
||||
},
|
||||
//todo:矫正封面数据
|
||||
poster: {
|
||||
items: [],
|
||||
},
|
||||
};
|
||||
return res.status(200).send(success(flowData));
|
||||
} else {
|
||||
try {
|
||||
const flowData = JSON.parse(sqlData!.data ?? "{}");
|
||||
res.status(200).send(success(flowData));
|
||||
} catch (err) {
|
||||
res.status(200).send(error());
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
35
src/routes/production/saveFlowData.ts
Normal file
35
src/routes/production/saveFlowData.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import express from "express";
|
||||
import u from "@/utils";
|
||||
import { z } from "zod";
|
||||
import { success } from "@/lib/responseFormat";
|
||||
import { validateFields } from "@/middleware/middleware";
|
||||
const router = express.Router();
|
||||
import { flowDataSchema } from "@/agents/productionAgent/tools";
|
||||
|
||||
export default router.post(
|
||||
"/",
|
||||
validateFields({
|
||||
projectId: z.number(),
|
||||
episodesId: z.number(),
|
||||
data: flowDataSchema,
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { projectId, episodesId } = req.body;
|
||||
const sqlData = await u.db("o_flowData").where({ projectId, episodesId }).first();
|
||||
if (!sqlData) {
|
||||
await u.db("o_flowData").insert({
|
||||
projectId,
|
||||
episodesId,
|
||||
data: JSON.stringify(req.body.data),
|
||||
});
|
||||
} else {
|
||||
await u
|
||||
.db("o_flowData")
|
||||
.where({ projectId, episodesId })
|
||||
.update({
|
||||
data: JSON.stringify(req.body.data),
|
||||
});
|
||||
}
|
||||
return res.status(200).send(success());
|
||||
},
|
||||
);
|
||||
@ -28,7 +28,8 @@ export default router.post(
|
||||
})
|
||||
.select("o_tasks.*", "o_project.* ")
|
||||
.offset(offset)
|
||||
.limit(limit);
|
||||
.limit(limit)
|
||||
.orderBy("o_tasks.id", "desc");
|
||||
const totalQuery = (await u
|
||||
.db("o_tasks")
|
||||
.andWhere((qb) => {
|
||||
114
src/types/database.d.ts
vendored
114
src/types/database.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// @db-hash bd46e7c381481a74efedc662a4f9049f
|
||||
// @db-hash db6e8dfe8be75f6c605991904268fd8d
|
||||
//该文件由脚本自动生成,请勿手动修改
|
||||
|
||||
export interface memories {
|
||||
@ -35,18 +35,12 @@ export interface o_assets {
|
||||
'projectId'?: number | null;
|
||||
'prompt'?: string | null;
|
||||
'remark'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sonId'?: number | null;
|
||||
'startTime'?: number | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_chatHistory {
|
||||
'data'?: string | null;
|
||||
'id'?: number;
|
||||
'novel'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_event {
|
||||
'createTime'?: number | null;
|
||||
'detail'?: string | null;
|
||||
@ -60,40 +54,21 @@ export interface o_eventChapter {
|
||||
}
|
||||
export interface o_flowData {
|
||||
'createTime'?: number | null;
|
||||
'data'?: string | null;
|
||||
'episodesId'?: number | null;
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'key'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'updateTime'?: number | null;
|
||||
}
|
||||
export interface o_image {
|
||||
'assetsId'?: number | null;
|
||||
'filePath'?: string | null;
|
||||
'id'?: number;
|
||||
'projectId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
'model'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
'videoId'?: number | null;
|
||||
}
|
||||
export interface o_model {
|
||||
'apiKey'?: string | null;
|
||||
'baseUrl'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'id'?: number;
|
||||
'index'?: number | null;
|
||||
'manufacturer'?: string | null;
|
||||
'model'?: string | null;
|
||||
'modelType'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_myTasks {
|
||||
'describe'?: string | null;
|
||||
'id'?: number;
|
||||
'model'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'reason'?: string | null;
|
||||
'relatedObjects'?: string | null;
|
||||
'startTime'?: number | null;
|
||||
'state'?: string | null;
|
||||
'taskClass'?: string | null;
|
||||
}
|
||||
export interface o_novel {
|
||||
'chapter'?: string | null;
|
||||
@ -126,15 +101,6 @@ export interface o_project {
|
||||
'userId'?: number | null;
|
||||
'videoRatio'?: string | null;
|
||||
}
|
||||
export interface o_prompts {
|
||||
'code'?: string | null;
|
||||
'customValue'?: string | null;
|
||||
'defaultValue'?: string | null;
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'parentCode'?: string | null;
|
||||
'type'?: string | null;
|
||||
}
|
||||
export interface o_script {
|
||||
'content'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
@ -142,40 +108,31 @@ export interface o_script {
|
||||
'name'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
}
|
||||
export interface o_scriptAssets {
|
||||
'assetsId'?: number | null;
|
||||
'id'?: number;
|
||||
'scriptId'?: number | null;
|
||||
}
|
||||
export interface o_scriptOutline {
|
||||
'id'?: number;
|
||||
'outlineId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
}
|
||||
export interface o_setting {
|
||||
'key'?: string | null;
|
||||
'value'?: string | null;
|
||||
}
|
||||
export interface o_skills {
|
||||
'id'?: number;
|
||||
'name'?: string | null;
|
||||
'startTime'?: number | null;
|
||||
}
|
||||
export interface o_storyboard {
|
||||
'associateAssetsIds'?: string | null;
|
||||
'camera'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'duration'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'frameType'?: string | null;
|
||||
'id'?: number;
|
||||
'mode'?: string | null;
|
||||
'model'?: string | null;
|
||||
'name'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sound'?: string | null;
|
||||
}
|
||||
export interface o_storyboardFlow {
|
||||
'flowData': string;
|
||||
'id'?: number;
|
||||
'stroryboardId': number;
|
||||
}
|
||||
export interface o_storyboardScript {
|
||||
'id'?: number;
|
||||
'scriptId'?: number | null;
|
||||
'storyboardId'?: number | null;
|
||||
}
|
||||
export interface o_tasks {
|
||||
'describe'?: string | null;
|
||||
'id'?: number;
|
||||
@ -204,36 +161,27 @@ export interface o_vendorConfig {
|
||||
'version'?: string | null;
|
||||
}
|
||||
export interface o_video {
|
||||
'configId'?: number | null;
|
||||
'errorReason'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'firstFrame'?: string | null;
|
||||
'id'?: number;
|
||||
'model'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'state'?: number | null;
|
||||
'storyboardImgs'?: string | null;
|
||||
'state'?: string | null;
|
||||
'storyboardId'?: number | null;
|
||||
'time'?: number | null;
|
||||
}
|
||||
export interface o_videoConfig {
|
||||
'aiConfigId'?: number | null;
|
||||
'audioEnabled'?: number | null;
|
||||
'audio'?: number | null;
|
||||
'createTime'?: number | null;
|
||||
'data'?: string | null;
|
||||
'duration'?: number | null;
|
||||
'endFrame'?: string | null;
|
||||
'id'?: number;
|
||||
'images'?: string | null;
|
||||
'manufacturer'?: string | null;
|
||||
'mode'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'model'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'selectedResultId'?: number | null;
|
||||
'startFrame'?: string | null;
|
||||
'storyboardId'?: number | null;
|
||||
'updateTime'?: number | null;
|
||||
'videoId'?: number | null;
|
||||
}
|
||||
|
||||
export interface DB {
|
||||
@ -241,26 +189,18 @@ export interface DB {
|
||||
"o_agentDeploy": o_agentDeploy;
|
||||
"o_artStyle": o_artStyle;
|
||||
"o_assets": o_assets;
|
||||
"o_chatHistory": o_chatHistory;
|
||||
"o_event": o_event;
|
||||
"o_eventChapter": o_eventChapter;
|
||||
"o_flowData": o_flowData;
|
||||
"o_image": o_image;
|
||||
"o_model": o_model;
|
||||
"o_myTasks": o_myTasks;
|
||||
"o_novel": o_novel;
|
||||
"o_outline": o_outline;
|
||||
"o_outlineNovel": o_outlineNovel;
|
||||
"o_project": o_project;
|
||||
"o_prompts": o_prompts;
|
||||
"o_script": o_script;
|
||||
"o_scriptAssets": o_scriptAssets;
|
||||
"o_scriptOutline": o_scriptOutline;
|
||||
"o_setting": o_setting;
|
||||
"o_skills": o_skills;
|
||||
"o_storyboard": o_storyboard;
|
||||
"o_storyboardFlow": o_storyboardFlow;
|
||||
"o_storyboardScript": o_storyboardScript;
|
||||
"o_tasks": o_tasks;
|
||||
"o_user": o_user;
|
||||
"o_vendorConfig": o_vendorConfig;
|
||||
|
||||
@ -12,7 +12,6 @@ let extractor: FeatureExtractionPipeline | null = null;
|
||||
export async function initEmbedding(): Promise<void> {
|
||||
if (extractor) return;
|
||||
|
||||
//todo 模型配置放到这里
|
||||
const modelConfigData = await db("o_setting").whereIn("key", ["modelOnnxFile", "modelDtype"]);
|
||||
const modelObj: Record<string, string> = {};
|
||||
Object.entries(modelConfigData).forEach(([key, value]) => {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { generateText, streamText, Output, stepCountIs, ModelMessage, LanguageModel, Tool, GenerateTextResult } from "ai";
|
||||
import { parse } from "best-effort-json-parser";
|
||||
import { generateText, streamText, wrapLanguageModel, stepCountIs } from "ai";
|
||||
import { devToolsMiddleware } from "@ai-sdk/devtools";
|
||||
import axios from "axios";
|
||||
import { transform } from "sucrase";
|
||||
import u from "@/utils";
|
||||
@ -76,7 +76,10 @@ class AiText {
|
||||
return streamText({
|
||||
...(input.tools && { stopWhen: stepCountIs(Object.keys(input.tools).length * 5) }),
|
||||
...input,
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
model: wrapLanguageModel({
|
||||
model: await getVendorTemplateFn("textRequest", modelName),
|
||||
middleware: devToolsMiddleware(),
|
||||
}),
|
||||
} as Parameters<typeof streamText>[0]);
|
||||
}
|
||||
}
|
||||
|
||||
22
yarn.lock
22
yarn.lock
@ -7,14 +7,6 @@
|
||||
resolved "https://registry.npmmirror.com/7zip-bin/-/7zip-bin-5.2.0.tgz#7a03314684dd6572b7dfa89e68ce31d60286854d"
|
||||
integrity sha512-ukTPVhqG4jNzMro2qA9HSCSSVJN3aN7tlb+hfqYCt3ER0yWroeA2VR38MNrOHLQ/cVj+DaIMad0kFCtWWowh/A==
|
||||
|
||||
"@ag-ui/core@^0.0.47":
|
||||
version "0.0.47"
|
||||
resolved "https://registry.npmmirror.com/@ag-ui/core/-/core-0.0.47.tgz#0f6b8cb6bf1f90a562c64d6c0b4585ae0174e4ed"
|
||||
integrity sha512-fHat7ZErAH028R90psYclTWaj6PdcvN2GJxzwWPF/j1c5ceqbF2+6xe+t06Psg+gCzZneI9QE3IkOkdJNplZ5A==
|
||||
dependencies:
|
||||
rxjs "7.8.1"
|
||||
zod "^3.22.4"
|
||||
|
||||
"@ai-sdk/anthropic@^3.0.35":
|
||||
version "3.0.50"
|
||||
resolved "https://registry.npmmirror.com/@ai-sdk/anthropic/-/anthropic-3.0.50.tgz#5ffdb638ae5418a2bf53d97448346af7ab77e09a"
|
||||
@ -4110,13 +4102,6 @@ runtime-required@^1.1.0:
|
||||
resolved "https://registry.npmmirror.com/runtime-required/-/runtime-required-1.1.0.tgz#a000a50c2748dba123f4dac5105e66d4599519c4"
|
||||
integrity sha512-yX97f5E0WfNpcQnfVjap6vzQcvErkYYCx6eTK4siqGEdC8lglwypUFgZVTX7ShvIlgfkC4XGFl9O1KTYcff0pw==
|
||||
|
||||
rxjs@7.8.1:
|
||||
version "7.8.1"
|
||||
resolved "https://registry.npmmirror.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543"
|
||||
integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==
|
||||
dependencies:
|
||||
tslib "^2.1.0"
|
||||
|
||||
safe-buffer@5.1.2:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
||||
@ -4762,7 +4747,7 @@ ts-interface-checker@^0.1.9:
|
||||
resolved "https://registry.npmmirror.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699"
|
||||
integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==
|
||||
|
||||
tslib@^2.1.0, tslib@^2.4.0:
|
||||
tslib@^2.4.0:
|
||||
version "2.8.1"
|
||||
resolved "https://registry.npmmirror.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
|
||||
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
|
||||
@ -5081,11 +5066,6 @@ zhipu-ai-provider@^0.2.2:
|
||||
"@ai-sdk/provider" "^2.0.0"
|
||||
"@ai-sdk/provider-utils" "^3.0.0"
|
||||
|
||||
zod@^3.22.4:
|
||||
version "3.25.76"
|
||||
resolved "https://registry.npmmirror.com/zod/-/zod-3.25.76.tgz#26841c3f6fd22a6a2760e7ccb719179768471e34"
|
||||
integrity sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==
|
||||
|
||||
zod@^4.3.5:
|
||||
version "4.3.6"
|
||||
resolved "https://registry.npmmirror.com/zod/-/zod-4.3.6.tgz#89c56e0aa7d2b05107d894412227087885ab112a"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user