Merge branch '108' of https://github.com/HBAI-Ltd/Toonflow-app into 108
# Conflicts: # src/routes/project/editProject.ts # src/types/database.d.ts
This commit is contained in:
commit
020c971ad7
@ -11,8 +11,10 @@ export interface AgentContext {
|
|||||||
socket: Socket;
|
socket: Socket;
|
||||||
isolationKey: string;
|
isolationKey: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
userMessageTime?: number;
|
||||||
abortSignal?: AbortSignal;
|
abortSignal?: AbortSignal;
|
||||||
resTool: ResTool;
|
resTool: ResTool;
|
||||||
|
msg: ReturnType<ResTool["newMessage"]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSystemPrompt(skillPrompt: string, mem: Awaited<ReturnType<Memory["get"]>>): string {
|
function buildSystemPrompt(skillPrompt: string, mem: Awaited<ReturnType<Memory["get"]>>): string {
|
||||||
@ -52,7 +54,7 @@ export async function decisionAI(ctx: AgentContext) {
|
|||||||
...skill.tools,
|
...skill.tools,
|
||||||
...memory.getTools(),
|
...memory.getTools(),
|
||||||
run_sub_agent: runSubAgent(ctx),
|
run_sub_agent: runSubAgent(ctx),
|
||||||
...useTools(ctx.resTool),
|
...useTools({ resTool: ctx.resTool, msg: ctx.msg }),
|
||||||
},
|
},
|
||||||
onFinish: async (completion) => {
|
onFinish: async (completion) => {
|
||||||
await memory.add("assistant:decision", completion.text);
|
await memory.add("assistant:decision", completion.text);
|
||||||
@ -65,78 +67,80 @@ export async function decisionAI(ctx: AgentContext) {
|
|||||||
//====================== 执行层 ======================
|
//====================== 执行层 ======================
|
||||||
|
|
||||||
export async function executionAI(ctx: AgentContext) {
|
export async function executionAI(ctx: AgentContext) {
|
||||||
const { isolationKey, text, abortSignal, resTool } = ctx;
|
const { text, abortSignal } = ctx;
|
||||||
|
|
||||||
resTool.systemMessage("执行层AI 接管聊天");
|
const skill = await useSkill("production_agent_execution.md");
|
||||||
|
|
||||||
const memory = new Memory("productionAgent", isolationKey);
|
const subMsg = ctx.resTool.newMessage("assistant", "执行导演");
|
||||||
const [skill, mem] = await Promise.all([useSkill("production_agent_execution.md"), memory.get(text)]);
|
|
||||||
|
|
||||||
const systemPrompt = buildSystemPrompt(skill.prompt, mem);
|
|
||||||
|
|
||||||
const { textStream } = await u.Ai.Text("productionAgent").stream({
|
const { textStream } = await u.Ai.Text("productionAgent").stream({
|
||||||
system: systemPrompt,
|
system: skill.prompt,
|
||||||
messages: [{ role: "user", content: text }],
|
messages: [{ role: "user", content: text }],
|
||||||
abortSignal,
|
abortSignal,
|
||||||
tools: {
|
tools: {
|
||||||
...skill.tools,
|
...skill.tools,
|
||||||
...memory.getTools(),
|
...useTools({ resTool: ctx.resTool, msg: subMsg }),
|
||||||
...useTools(ctx.resTool),
|
|
||||||
},
|
|
||||||
onFinish: async (completion) => {
|
|
||||||
await memory.add("assistant:execution", completion.text);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return textStream;
|
return { textStream, subMsg };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function supervisionAI(ctx: AgentContext) {
|
export async function supervisionAI(ctx: AgentContext) {
|
||||||
const { isolationKey, text, abortSignal } = ctx;
|
const { text, abortSignal } = ctx;
|
||||||
const memory = new Memory("productionAgent", isolationKey);
|
|
||||||
const [skill, mem] = await Promise.all([useSkill("production_agent_supervision.md"), memory.get(text)]);
|
|
||||||
|
|
||||||
const systemPrompt = buildSystemPrompt(skill.prompt, mem);
|
const skill = await useSkill("production_agent_supervision.md");
|
||||||
|
const subMsg = ctx.resTool.newMessage("assistant", "编辑");
|
||||||
|
|
||||||
const { textStream } = await u.Ai.Text("productionAgent").stream({
|
const { textStream } = await u.Ai.Text("scriptAgent").stream({
|
||||||
system: systemPrompt,
|
system: skill.prompt,
|
||||||
messages: [{ role: "user", content: text }],
|
messages: [{ role: "user", content: text }],
|
||||||
abortSignal,
|
abortSignal,
|
||||||
tools: {
|
tools: {
|
||||||
...skill.tools,
|
...skill.tools,
|
||||||
...useTools(ctx.resTool),
|
...useTools({
|
||||||
},
|
resTool: ctx.resTool,
|
||||||
onFinish: async (completion) => {
|
msg: subMsg,
|
||||||
await memory.add("assistant:supervision", completion.text);
|
}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return textStream;
|
return { textStream, subMsg };
|
||||||
}
|
}
|
||||||
|
|
||||||
//工具函数
|
//工具函数
|
||||||
function runSubAgent(parentCtx: AgentContext) {
|
function runSubAgent(parentCtx: AgentContext) {
|
||||||
|
const memory = new Memory("scriptAgent", parentCtx.isolationKey);
|
||||||
return tool({
|
return tool({
|
||||||
description: "启动子Agent执行独立任务。可用子Agent:executionAI, decisionAI, supervisionAI",
|
description: "启动子Agent执行独立任务。可用子Agent:executionAI, decisionAI, supervisionAI",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
agent: z.enum(["executionAI", "supervisionAI"]).describe("子Agent名称"),
|
agent: z.enum(["executionAI", "supervisionAI"]).describe("子Agent名称"),
|
||||||
prompt: z.string().max(100).describe("交给子Agent的任务简约描述"),
|
prompt: z.string().describe("交给子Agent的任务简约描述,100字以内"),
|
||||||
}),
|
}),
|
||||||
execute: async ({ agent, prompt }) => {
|
execute: async ({ agent, prompt }) => {
|
||||||
//todo 传入md有问题
|
|
||||||
const fn = [executionAI, supervisionAI][subAgentList.indexOf(agent)];
|
const fn = [executionAI, supervisionAI][subAgentList.indexOf(agent)];
|
||||||
//运行子Agent
|
|
||||||
const subTextStream = await fn({ ...parentCtx, text: prompt });
|
|
||||||
|
|
||||||
let msg: ReturnType<typeof parentCtx.resTool.textMessage>;
|
// 先完成主Agent当前的消息
|
||||||
|
parentCtx.msg.complete();
|
||||||
|
// 子Agent用新消息回复
|
||||||
|
const { textStream: subTextStream, subMsg } = await fn({ ...parentCtx, text: prompt });
|
||||||
|
let text = subMsg.text();
|
||||||
let fullResponse = "";
|
let fullResponse = "";
|
||||||
|
|
||||||
for await (const chunk of subTextStream) {
|
for await (const chunk of subTextStream) {
|
||||||
if (!msg!) msg = parentCtx.resTool.textMessage();
|
text.append(chunk);
|
||||||
msg.send(chunk);
|
|
||||||
fullResponse += chunk;
|
fullResponse += chunk;
|
||||||
}
|
}
|
||||||
msg!.end();
|
text.complete();
|
||||||
|
subMsg.complete();
|
||||||
|
if (fullResponse.trim()) {
|
||||||
|
await memory.add(`assistant:${agent === "executionAI" ? "execution" : "supervision"}`, fullResponse, {
|
||||||
|
name: agent === "executionAI" ? "编剧" : "编辑",
|
||||||
|
createTime: new Date(subMsg.datetime).getTime(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 为主Agent后续输出创建新消息
|
||||||
|
parentCtx.msg = parentCtx.resTool.newMessage("assistant", "统筹");
|
||||||
|
|
||||||
return fullResponse;
|
return fullResponse;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { z } from "zod";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import ResTool from "@/socket/resTool";
|
import ResTool from "@/socket/resTool";
|
||||||
import u from "@/utils";
|
import u from "@/utils";
|
||||||
import { useSkill } from "@/utils/agent/skillsTools";
|
|
||||||
import { urlToBase64 } from "@/utils/vm";
|
import { urlToBase64 } from "@/utils/vm";
|
||||||
export const deriveAssetSchema = z.object({
|
export const deriveAssetSchema = z.object({
|
||||||
id: z.number().describe("衍生资产ID,如果新增则为空"),
|
id: z.number().describe("衍生资产ID,如果新增则为空"),
|
||||||
@ -75,7 +74,14 @@ const flowDataKeyLabels = Object.fromEntries(
|
|||||||
Object.entries(flowDataSchema.shape).map(([key, schema]) => [key, (schema as z.ZodTypeAny).description ?? key]),
|
Object.entries(flowDataSchema.shape).map(([key, schema]) => [key, (schema as z.ZodTypeAny).description ?? key]),
|
||||||
) as Record<keyof FlowData, string>;
|
) as Record<keyof FlowData, string>;
|
||||||
|
|
||||||
export default (resTool: ResTool, toolsNames?: string[]) => {
|
interface ToolConfig {
|
||||||
|
resTool: ResTool;
|
||||||
|
toolsNames?: string[];
|
||||||
|
msg: ReturnType<ResTool["newMessage"]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (toolCpnfig: ToolConfig) => {
|
||||||
|
const { resTool, toolsNames, msg } = toolCpnfig;
|
||||||
const { socket } = resTool;
|
const { socket } = resTool;
|
||||||
const tools: Record<string, Tool> = {
|
const tools: Record<string, Tool> = {
|
||||||
get_flowData: tool({
|
get_flowData: tool({
|
||||||
@ -84,9 +90,12 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
key: keySchema.describe("数据key"),
|
key: keySchema.describe("数据key"),
|
||||||
}),
|
}),
|
||||||
execute: async ({ key }) => {
|
execute: async ({ key }) => {
|
||||||
resTool.systemMessage(`正在阅读 ${flowDataKeyLabels[key]} 数据...`);
|
const thinking = msg.thinking(`正在获取${flowDataKeyLabels[key]}工作区数据...`);
|
||||||
console.log("[tools] get_flowData", key);
|
console.log("[tools] get_flowData", key);
|
||||||
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key }, (res: any) => resolve(res)));
|
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key }, (res: any) => resolve(res)));
|
||||||
|
thinking.appendText(`获取到${flowDataKeyLabels[key]}:\n` + flowData[key]);
|
||||||
|
thinking.updateTitle(`获取${flowDataKeyLabels[key]}完成`);
|
||||||
|
thinking.complete();
|
||||||
return flowData[key];
|
return flowData[key];
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -95,8 +104,10 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.script }),
|
inputSchema: z.object({ value: flowDataSchema.shape.script }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData script", value);
|
console.log("[tools] set_flowData script", value);
|
||||||
resTool.systemMessage("正在保存 剧本 数据");
|
const thinking = msg.thinking("正在保存 剧本 数据");
|
||||||
socket.emit("setFlowData", { key: "script", value });
|
socket.emit("setFlowData", { key: "script", value });
|
||||||
|
thinking.updateTitle("保存 剧本 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -105,8 +116,10 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.scriptPlan }),
|
inputSchema: z.object({ value: flowDataSchema.shape.scriptPlan }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData scriptPlan", value);
|
console.log("[tools] set_flowData scriptPlan", value);
|
||||||
resTool.systemMessage("正在保存 拍摄计划 数据");
|
const thinking = msg.thinking("正在保存 拍摄计划 数据");
|
||||||
socket.emit("setFlowData", { key: "scriptPlan", value });
|
socket.emit("setFlowData", { key: "scriptPlan", value });
|
||||||
|
thinking.updateTitle("保存 拍摄计划 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -115,7 +128,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: z.array(deriveAssetSchema.omit({ id: true })).describe("需要新增的衍生资产列表") }),
|
inputSchema: z.object({ value: z.array(deriveAssetSchema.omit({ id: true })).describe("需要新增的衍生资产列表") }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData add_flowData_assets", value);
|
console.log("[tools] set_flowData add_flowData_assets", value);
|
||||||
resTool.systemMessage("正在保存 衍生资产 数据");
|
const thinking = msg.thinking("正在保存 衍生资产 数据");
|
||||||
const setData = [...value] as z.infer<typeof deriveAssetSchema>[];
|
const setData = [...value] as z.infer<typeof deriveAssetSchema>[];
|
||||||
const { projectId, scriptId } = resTool.data;
|
const { projectId, scriptId } = resTool.data;
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
@ -154,6 +167,9 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
i.derive = [...(i.derive || []), ...watiAddAssetsMap[i.id]];
|
i.derive = [...(i.derive || []), ...watiAddAssetsMap[i.id]];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
thinking.updateTitle("保存 衍生资产 数据完成");
|
||||||
|
thinking.complete();
|
||||||
|
|
||||||
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@ -163,7 +179,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: z.array(deriveAssetSchema).describe("需要更新的衍生资产列表") }),
|
inputSchema: z.object({ value: z.array(deriveAssetSchema).describe("需要更新的衍生资产列表") }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] update_flowData update_flowData_assets", value);
|
console.log("[tools] update_flowData update_flowData_assets", value);
|
||||||
resTool.systemMessage("正在保存 衍生资产 数据");
|
const thinking = msg.thinking("正在保存 衍生资产 数据");
|
||||||
for (const i of value) {
|
for (const i of value) {
|
||||||
await u
|
await u
|
||||||
.db("o_assets")
|
.db("o_assets")
|
||||||
@ -195,6 +211,8 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
asset.derive = (asset.derive || []).map((d) => updatedMap[d.id] ?? d);
|
asset.derive = (asset.derive || []).map((d) => updatedMap[d.id] ?? d);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
thinking.updateTitle("保存 衍生资产 数据完成");
|
||||||
|
thinking.complete();
|
||||||
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@ -204,13 +222,15 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ ids: z.array(z.number()).describe("需要删除的 衍生资产id ") }),
|
inputSchema: z.object({ ids: z.array(z.number()).describe("需要删除的 衍生资产id ") }),
|
||||||
execute: async ({ ids }) => {
|
execute: async ({ ids }) => {
|
||||||
console.log("[tools] delete_flowData delete_flowData_assets", ids);
|
console.log("[tools] delete_flowData delete_flowData_assets", ids);
|
||||||
resTool.systemMessage("正在保存 衍生资产 数据");
|
const thinking = msg.thinking("正在删除指定 衍生资产 数据...");
|
||||||
await u.db("o_assets").whereIn("id", ids).delete();
|
await u.db("o_assets").whereIn("id", ids).delete();
|
||||||
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key: "assets" }, (res: any) => resolve(res)));
|
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key: "assets" }, (res: any) => resolve(res)));
|
||||||
const assetsData = flowData.assets;
|
const assetsData = flowData.assets;
|
||||||
assetsData.forEach((i) => {
|
assetsData.forEach((i) => {
|
||||||
i.derive = (i.derive || []).filter((d) => !ids.includes(d.id));
|
i.derive = (i.derive || []).filter((d) => !ids.includes(d.id));
|
||||||
});
|
});
|
||||||
|
thinking.updateTitle("删除指定 衍生资产 数据完成");
|
||||||
|
thinking.complete();
|
||||||
// 将 derive 中已存在的条目替换为更新后的数据
|
// 将 derive 中已存在的条目替换为更新后的数据
|
||||||
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
socket.emit("setFlowData", { key: "assets", value: assetsData });
|
||||||
return true;
|
return true;
|
||||||
@ -265,8 +285,10 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.storyboardTable }),
|
inputSchema: z.object({ value: flowDataSchema.shape.storyboardTable }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData storyboardTable", value);
|
console.log("[tools] set_flowData storyboardTable", value);
|
||||||
resTool.systemMessage("正在保存 分镜表 数据...");
|
const thinking = msg.thinking("正在保存 分镜表 数据...");
|
||||||
socket.emit("setFlowData", { key: "storyboardTable", value });
|
socket.emit("setFlowData", { key: "storyboardTable", value });
|
||||||
|
thinking.updateTitle("保存 分镜表 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -275,7 +297,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: z.array(storyboardSchema.omit({ id: true })) }),
|
inputSchema: z.object({ value: z.array(storyboardSchema.omit({ id: true })) }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] add_flowData storyboard", value);
|
console.log("[tools] add_flowData storyboard", value);
|
||||||
resTool.systemMessage("正在新增 分镜面板 数据...");
|
const thinking = msg.thinking("正在保存 分镜面板 数据...");
|
||||||
const setData = [...value] as z.infer<typeof storyboardSchema>[];
|
const setData = [...value] as z.infer<typeof storyboardSchema>[];
|
||||||
for (const item of setData) {
|
for (const item of setData) {
|
||||||
item.src = "";
|
item.src = "";
|
||||||
@ -302,6 +324,9 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
const storyboardData = flowData["storyboard"].concat([...setData]);
|
const storyboardData = flowData["storyboard"].concat([...setData]);
|
||||||
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
||||||
|
|
||||||
|
thinking.updateTitle("保存 分镜面板 数据完成");
|
||||||
|
thinking.complete();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -310,7 +335,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.storyboard }),
|
inputSchema: z.object({ value: flowDataSchema.shape.storyboard }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] update_flowData storyboard", value);
|
console.log("[tools] update_flowData storyboard", value);
|
||||||
resTool.systemMessage("正在更新 分镜面板 数据...");
|
const thinking = msg.thinking("正在保存 分镜面板 数据...");
|
||||||
for (const item of value) {
|
for (const item of value) {
|
||||||
await u
|
await u
|
||||||
.db("o_storyboard")
|
.db("o_storyboard")
|
||||||
@ -344,6 +369,8 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
||||||
|
thinking.updateTitle("保存 分镜面板 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -352,13 +379,15 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ ids: z.array(z.number()).describe("需要删除的 分镜id ") }),
|
inputSchema: z.object({ ids: z.array(z.number()).describe("需要删除的 分镜id ") }),
|
||||||
execute: async ({ ids }) => {
|
execute: async ({ ids }) => {
|
||||||
console.log("[tools] delete_flowData storyboard", ids);
|
console.log("[tools] delete_flowData storyboard", ids);
|
||||||
resTool.systemMessage("正在删除指定 分镜面板 数据...");
|
const thinking = msg.thinking("正在删除指定 分镜面板 数据...");
|
||||||
await u.db("o_storyboard").whereIn("id", ids).delete();
|
await u.db("o_storyboard").whereIn("id", ids).delete();
|
||||||
await u.db("o_assets2Storyboard").whereIn("storyboardId", ids).delete();
|
await u.db("o_assets2Storyboard").whereIn("storyboardId", ids).delete();
|
||||||
await u.db("o_storyboardFlow").whereIn("storyboardId", ids).delete();
|
await u.db("o_storyboardFlow").whereIn("storyboardId", ids).delete();
|
||||||
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key: "storyboard" }, (res: any) => resolve(res)));
|
const flowData: FlowData = await new Promise((resolve) => socket.emit("getFlowData", { key: "storyboard" }, (res: any) => resolve(res)));
|
||||||
const storyboardData = flowData["storyboard"].filter((item) => !ids.includes(item.id));
|
const storyboardData = flowData["storyboard"].filter((item) => !ids.includes(item.id));
|
||||||
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
socket.emit("setFlowData", { key: "storyboard", value: storyboardData });
|
||||||
|
thinking.updateTitle("删除指定 分镜面板 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -400,8 +429,10 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.workbench }),
|
inputSchema: z.object({ value: flowDataSchema.shape.workbench }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData workbench", value);
|
console.log("[tools] set_flowData workbench", value);
|
||||||
resTool.systemMessage("正在保存 工作台配置 数据...");
|
const thinking = msg.thinking("正在保存 工作台配置 数据...");
|
||||||
socket.emit("setFlowData", { key: "workbench", value });
|
socket.emit("setFlowData", { key: "workbench", value });
|
||||||
|
thinking.updateTitle("保存 工作台配置 数据完成");
|
||||||
|
thinking.complete();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -410,7 +441,9 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
inputSchema: z.object({ value: flowDataSchema.shape.poster }),
|
inputSchema: z.object({ value: flowDataSchema.shape.poster }),
|
||||||
execute: async ({ value }) => {
|
execute: async ({ value }) => {
|
||||||
console.log("[tools] set_flowData poster", value);
|
console.log("[tools] set_flowData poster", value);
|
||||||
resTool.systemMessage("正在保存 海报 数据...");
|
const thinking = msg.thinking("正在保存 海报配置 数据...");
|
||||||
|
thinking.updateTitle("保存 海报配置 数据完成");
|
||||||
|
thinking.complete();
|
||||||
socket.emit("setFlowData", { key: "poster", value });
|
socket.emit("setFlowData", { key: "poster", value });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@ -448,7 +481,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
}),
|
}),
|
||||||
execute: async ({ images }) => {
|
execute: async ({ images }) => {
|
||||||
console.log("[tools] generate_storyboard_images", images);
|
console.log("[tools] generate_storyboard_images", images);
|
||||||
|
const thinking = msg.thinking("正在生成 分镜图片 数据...");
|
||||||
// --- 构建任务id集合 ---
|
// --- 构建任务id集合 ---
|
||||||
const taskIds = new Set(images.map((item) => item.id));
|
const taskIds = new Set(images.map((item) => item.id));
|
||||||
const imageMap = new Map(images.map((item) => [item.id, item]));
|
const imageMap = new Map(images.map((item) => [item.id, item]));
|
||||||
@ -492,11 +525,13 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
// 循环依赖检测
|
// 循环依赖检测
|
||||||
if (visited.size !== images.length) {
|
if (visited.size !== images.length) {
|
||||||
const cyclicIds = images.filter((item) => !visited.has(item.id)).map((item) => item.id);
|
const cyclicIds = images.filter((item) => !visited.has(item.id)).map((item) => item.id);
|
||||||
resTool.systemMessage(`检测到循环依赖,涉及分镜id: ${cyclicIds.join(", ")},请修正后重试`);
|
thinking.appendText(`检测到循环依赖,涉及分镜id: ${cyclicIds.join(", ")},请修正后重试`);
|
||||||
|
thinking.updateTitle("循环依赖错误");
|
||||||
|
thinking.error();
|
||||||
return `错误:检测到循环依赖,涉及分镜id: ${cyclicIds.join(", ")}`;
|
return `错误:检测到循环依赖,涉及分镜id: ${cyclicIds.join(", ")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
resTool.systemMessage(`图片生成调度计划:共 ${levels.length} 层,${images.length} 张图片`);
|
thinking.appendText(`图片生成调度计划:共 ${levels.length} 层,${images.length} 张图片`);
|
||||||
|
|
||||||
// --- 准备公共数据 ---
|
// --- 准备公共数据 ---
|
||||||
const projectData = await u.db("o_project").where("id", resTool.data.projectId).select("videoRatio").first();
|
const projectData = await u.db("o_project").where("id", resTool.data.projectId).select("videoRatio").first();
|
||||||
@ -504,7 +539,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
|
|
||||||
// 生成单张图片的函数
|
// 生成单张图片的函数
|
||||||
const generateOneImage = async (item: (typeof images)[0]) => {
|
const generateOneImage = async (item: (typeof images)[0]) => {
|
||||||
resTool.systemMessage(`正在生成分镜 id:${item.id} 图片`);
|
const thinking = msg.thinking(`正在生成分镜 id:${item.id} 图片`);
|
||||||
// 更新数据库状态为生成中
|
// 更新数据库状态为生成中
|
||||||
await u.db("o_storyboard").where("id", item.id).update({ state: "生成中" });
|
await u.db("o_storyboard").where("id", item.id).update({ state: "生成中" });
|
||||||
// 更新前端为生成中
|
// 更新前端为生成中
|
||||||
@ -544,7 +579,8 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
referenceIds: item.referenceIds,
|
referenceIds: item.referenceIds,
|
||||||
};
|
};
|
||||||
// 前端对话框提示
|
// 前端对话框提示
|
||||||
resTool.systemMessage(`分镜 id:${item.id} 图片生成完成`);
|
thinking.appendText(`分镜 id:${item.id} 图片生成完成`);
|
||||||
|
thinking.complete();
|
||||||
// 更新前端界面展示
|
// 更新前端界面展示
|
||||||
socket.emit("setFlowData", { key: "setStoryboardImage", value: obj });
|
socket.emit("setFlowData", { key: "setStoryboardImage", value: obj });
|
||||||
};
|
};
|
||||||
@ -553,7 +589,9 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
for (let levelIndex = 0; levelIndex < levels.length; levelIndex++) {
|
for (let levelIndex = 0; levelIndex < levels.length; levelIndex++) {
|
||||||
const levelIds = levels[levelIndex];
|
const levelIds = levels[levelIndex];
|
||||||
const levelItems = levelIds.map((id) => imageMap.get(id)!);
|
const levelItems = levelIds.map((id) => imageMap.get(id)!);
|
||||||
resTool.systemMessage(`开始生成第 ${levelIndex + 1}/${levels.length} 层,共 ${levelItems.length} 张图片 (ids: ${levelIds.join(", ")})`);
|
const thinking = msg.thinking(
|
||||||
|
`开始生成第 ${levelIndex + 1}/${levels.length} 层,共 ${levelItems.length} 张图片 (ids: ${levelIds.join(", ")})`,
|
||||||
|
);
|
||||||
|
|
||||||
// 同层内所有图片并行生成,使用 allSettled 确保不会因单张失败中断整层
|
// 同层内所有图片并行生成,使用 allSettled 确保不会因单张失败中断整层
|
||||||
const results = await Promise.allSettled(levelItems.map((item) => generateOneImage(item)));
|
const results = await Promise.allSettled(levelItems.map((item) => generateOneImage(item)));
|
||||||
@ -564,7 +602,7 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
const failedId = levelIds[i];
|
const failedId = levelIds[i];
|
||||||
const reason = (results[i] as PromiseRejectedResult).reason;
|
const reason = (results[i] as PromiseRejectedResult).reason;
|
||||||
console.error(`[tools] 分镜 id:${failedId} 图片生成失败`, reason);
|
console.error(`[tools] 分镜 id:${failedId} 图片生成失败`, reason);
|
||||||
resTool.systemMessage(`分镜 id:${failedId} 图片生成失败: ${reason?.message || reason}`);
|
thinking.appendText(`分镜 id:${failedId} 图片生成失败: ${reason?.message || reason}`);
|
||||||
await u.db("o_storyboard").where("id", failedId).update({ state: "生成失败" });
|
await u.db("o_storyboard").where("id", failedId).update({ state: "生成失败" });
|
||||||
socket.emit("setFlowData", {
|
socket.emit("setFlowData", {
|
||||||
key: "setStoryboardImage",
|
key: "setStoryboardImage",
|
||||||
@ -572,7 +610,12 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
thinking.appendText(`第 ${levelIndex + 1}/${levels.length} 层图片生成完成`);
|
||||||
|
thinking.complete();
|
||||||
}
|
}
|
||||||
|
thinking.appendText("所有分镜图片生成完成");
|
||||||
|
thinking.updateTitle("分镜图片生成完成");
|
||||||
|
thinking.complete();
|
||||||
|
|
||||||
return "分镜图片生成完成";
|
return "分镜图片生成完成";
|
||||||
},
|
},
|
||||||
|
|||||||
@ -69,6 +69,9 @@ export async function decisionAI(ctx: AgentContext) {
|
|||||||
run_sub_agent: runSubAgent(ctx),
|
run_sub_agent: runSubAgent(ctx),
|
||||||
...useTools({ resTool: ctx.resTool, msg: ctx.msg }),
|
...useTools({ resTool: ctx.resTool, msg: ctx.msg }),
|
||||||
},
|
},
|
||||||
|
onFinish: async (completion) => {
|
||||||
|
await memory.add("assistant:decision", completion.text);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return textStream;
|
return textStream;
|
||||||
|
|||||||
@ -191,7 +191,8 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
builder: (table) => {
|
builder: (table) => {
|
||||||
table.integer("id").notNullable();
|
table.integer("id").notNullable();
|
||||||
table.string("name");
|
table.string("name");
|
||||||
table.text("prompt");
|
table.string("type");
|
||||||
|
table.text("data");
|
||||||
table.primary(["id"]);
|
table.primary(["id"]);
|
||||||
table.unique(["id"]);
|
table.unique(["id"]);
|
||||||
},
|
},
|
||||||
|
|||||||
288
src/router.ts
288
src/router.ts
@ -1,4 +1,4 @@
|
|||||||
// @routes-hash 7027f20b3def330f442689eb22769f31
|
// @routes-hash 58fd64b8de7872e80874b1244bbe3569
|
||||||
import { Express } from "express";
|
import { Express } from "express";
|
||||||
|
|
||||||
import route1 from "./routes/agents/clearMemory";
|
import route1 from "./routes/agents/clearMemory";
|
||||||
@ -39,76 +39,79 @@ import route35 from "./routes/novel/event/deletEvent";
|
|||||||
import route36 from "./routes/novel/event/generateEvents";
|
import route36 from "./routes/novel/event/generateEvents";
|
||||||
import route37 from "./routes/novel/event/getEvent";
|
import route37 from "./routes/novel/event/getEvent";
|
||||||
import route38 from "./routes/novel/getNovel";
|
import route38 from "./routes/novel/getNovel";
|
||||||
import route39 from "./routes/novel/getNovelEventState";
|
import route39 from "./routes/novel/getNovelData";
|
||||||
import route40 from "./routes/novel/getNovelIndex";
|
import route40 from "./routes/novel/getNovelEventState";
|
||||||
import route41 from "./routes/novel/updateNovel";
|
import route41 from "./routes/novel/getNovelIndex";
|
||||||
import route42 from "./routes/other/deleteAllData";
|
import route42 from "./routes/novel/updateNovel";
|
||||||
import route43 from "./routes/other/getVersion";
|
import route43 from "./routes/other/deleteAllData";
|
||||||
import route44 from "./routes/production/assets/getAssetsData";
|
import route44 from "./routes/other/getVersion";
|
||||||
import route45 from "./routes/production/editImage/generateFlowImage";
|
import route45 from "./routes/production/assets/getAssetsData";
|
||||||
import route46 from "./routes/production/editImage/getImageFlow";
|
import route46 from "./routes/production/editImage/generateFlowImage";
|
||||||
import route47 from "./routes/production/editImage/saveImageFlow";
|
import route47 from "./routes/production/editImage/getImageFlow";
|
||||||
import route48 from "./routes/production/editImage/updateImageFlow";
|
import route48 from "./routes/production/editImage/saveImageFlow";
|
||||||
import route49 from "./routes/production/exportImage";
|
import route49 from "./routes/production/editImage/updateImageFlow";
|
||||||
import route50 from "./routes/production/getFlowData";
|
import route50 from "./routes/production/exportImage";
|
||||||
import route51 from "./routes/production/getProductionData";
|
import route51 from "./routes/production/getFlowData";
|
||||||
import route52 from "./routes/production/getStoryboardData";
|
import route52 from "./routes/production/getProductionData";
|
||||||
import route53 from "./routes/production/saveFlowData";
|
import route53 from "./routes/production/getStoryboardData";
|
||||||
import route54 from "./routes/production/storyboard/downPreviewImage";
|
import route54 from "./routes/production/saveFlowData";
|
||||||
import route55 from "./routes/production/storyboard/getStoryboardData";
|
import route55 from "./routes/production/storyboard/downPreviewImage";
|
||||||
import route56 from "./routes/production/storyboard/previewImage";
|
import route56 from "./routes/production/storyboard/getStoryboardData";
|
||||||
import route57 from "./routes/production/workbench/confirmSelection";
|
import route57 from "./routes/production/storyboard/previewImage";
|
||||||
import route58 from "./routes/production/workbench/delVideo";
|
import route58 from "./routes/production/workbench/confirmSelection";
|
||||||
import route59 from "./routes/production/workbench/generateVideo";
|
import route59 from "./routes/production/workbench/delVideo";
|
||||||
import route60 from "./routes/production/workbench/getChatLines";
|
import route60 from "./routes/production/workbench/generateVideo";
|
||||||
import route61 from "./routes/production/workbench/getVideoModelDetail";
|
import route61 from "./routes/production/workbench/getChatLines";
|
||||||
import route62 from "./routes/production/workbench/videoPolling";
|
import route62 from "./routes/production/workbench/getVideoModelDetail";
|
||||||
import route63 from "./routes/project/addProject";
|
import route63 from "./routes/production/workbench/videoPolling";
|
||||||
import route64 from "./routes/project/delProject";
|
import route64 from "./routes/project/addProject";
|
||||||
import route65 from "./routes/project/editProject";
|
import route65 from "./routes/project/delProject";
|
||||||
import route66 from "./routes/project/getProject";
|
import route66 from "./routes/project/editProject";
|
||||||
import route67 from "./routes/script/addScript";
|
import route67 from "./routes/project/getProject";
|
||||||
import route68 from "./routes/script/delScript";
|
import route68 from "./routes/script/addScript";
|
||||||
import route69 from "./routes/script/exportScript";
|
import route69 from "./routes/script/delScript";
|
||||||
import route70 from "./routes/script/extractAssets";
|
import route70 from "./routes/script/exportScript";
|
||||||
import route71 from "./routes/script/getScrptApi";
|
import route71 from "./routes/script/extractAssets";
|
||||||
import route72 from "./routes/script/pollScriptAssets";
|
import route72 from "./routes/script/getScrptApi";
|
||||||
import route73 from "./routes/script/updateScript";
|
import route73 from "./routes/script/pollScriptAssets";
|
||||||
import route74 from "./routes/scriptAgent/getPlanData";
|
import route74 from "./routes/script/updateScript";
|
||||||
import route75 from "./routes/scriptAgent/setPlanData";
|
import route75 from "./routes/scriptAgent/getPlanData";
|
||||||
import route76 from "./routes/setting/about/checkUpdate";
|
import route76 from "./routes/scriptAgent/setPlanData";
|
||||||
import route77 from "./routes/setting/about/downloadApp";
|
import route77 from "./routes/setting/about/checkUpdate";
|
||||||
import route78 from "./routes/setting/agentDeploy/agentSetKey";
|
import route78 from "./routes/setting/about/downloadApp";
|
||||||
import route79 from "./routes/setting/agentDeploy/deployAgentModel";
|
import route79 from "./routes/setting/agentDeploy/agentSetKey";
|
||||||
import route80 from "./routes/setting/agentDeploy/getAgentDeploy";
|
import route80 from "./routes/setting/agentDeploy/deployAgentModel";
|
||||||
import route81 from "./routes/setting/dbConfig/clearData";
|
import route81 from "./routes/setting/agentDeploy/getAgentDeploy";
|
||||||
import route82 from "./routes/setting/dev/getSwitchAiDevTool";
|
import route82 from "./routes/setting/dbConfig/clearData";
|
||||||
import route83 from "./routes/setting/dev/updateSwitchAiDevTool";
|
import route83 from "./routes/setting/dev/getSwitchAiDevTool";
|
||||||
import route84 from "./routes/setting/fileManagement/openFolder";
|
import route84 from "./routes/setting/dev/updateSwitchAiDevTool";
|
||||||
import route85 from "./routes/setting/getTextModel";
|
import route85 from "./routes/setting/fileManagement/openFolder";
|
||||||
import route86 from "./routes/setting/loginConfig/getUser";
|
import route86 from "./routes/setting/getTextModel";
|
||||||
import route87 from "./routes/setting/loginConfig/updateUserPwd";
|
import route87 from "./routes/setting/loginConfig/getUser";
|
||||||
import route88 from "./routes/setting/memoryConfig/delAllMemory";
|
import route88 from "./routes/setting/loginConfig/updateUserPwd";
|
||||||
import route89 from "./routes/setting/memoryConfig/getMemory";
|
import route89 from "./routes/setting/memoryConfig/delAllMemory";
|
||||||
import route90 from "./routes/setting/memoryConfig/sureMemory";
|
import route90 from "./routes/setting/memoryConfig/getMemory";
|
||||||
import route91 from "./routes/setting/skillManagement/addSkill";
|
import route91 from "./routes/setting/memoryConfig/sureMemory";
|
||||||
import route92 from "./routes/setting/skillManagement/deleteSkill";
|
import route92 from "./routes/setting/promptManage/getPrompt";
|
||||||
import route93 from "./routes/setting/skillManagement/embeddingSkill";
|
import route93 from "./routes/setting/promptManage/updatePrompt";
|
||||||
import route94 from "./routes/setting/skillManagement/generateDescription";
|
import route94 from "./routes/setting/skillManagement/addSkill";
|
||||||
import route95 from "./routes/setting/skillManagement/getSkillList";
|
import route95 from "./routes/setting/skillManagement/deleteSkill";
|
||||||
import route96 from "./routes/setting/skillManagement/scanSkills";
|
import route96 from "./routes/setting/skillManagement/embeddingSkill";
|
||||||
import route97 from "./routes/setting/skillManagement/updateSkill";
|
import route97 from "./routes/setting/skillManagement/generateDescription";
|
||||||
import route98 from "./routes/setting/vendorConfig/addVendor";
|
import route98 from "./routes/setting/skillManagement/getSkillList";
|
||||||
import route99 from "./routes/setting/vendorConfig/deleteVendor";
|
import route99 from "./routes/setting/skillManagement/scanSkills";
|
||||||
import route100 from "./routes/setting/vendorConfig/getVendorList";
|
import route100 from "./routes/setting/skillManagement/updateSkill";
|
||||||
import route101 from "./routes/setting/vendorConfig/modelTest";
|
import route101 from "./routes/setting/vendorConfig/addVendor";
|
||||||
import route102 from "./routes/setting/vendorConfig/updateCode";
|
import route102 from "./routes/setting/vendorConfig/deleteVendor";
|
||||||
import route103 from "./routes/setting/vendorConfig/updateVendor";
|
import route103 from "./routes/setting/vendorConfig/getVendorList";
|
||||||
import route104 from "./routes/task/getProject";
|
import route104 from "./routes/setting/vendorConfig/modelTest";
|
||||||
import route105 from "./routes/task/getTaskApi";
|
import route105 from "./routes/setting/vendorConfig/updateCode";
|
||||||
import route106 from "./routes/task/getTaskCategories";
|
import route106 from "./routes/setting/vendorConfig/updateVendor";
|
||||||
import route107 from "./routes/task/taskDetails";
|
import route107 from "./routes/task/getProject";
|
||||||
import route108 from "./routes/test/test";
|
import route108 from "./routes/task/getTaskApi";
|
||||||
|
import route109 from "./routes/task/getTaskCategories";
|
||||||
|
import route110 from "./routes/task/taskDetails";
|
||||||
|
import route111 from "./routes/test/test";
|
||||||
|
|
||||||
export default async (app: Express) => {
|
export default async (app: Express) => {
|
||||||
app.use("/api/agents/clearMemory", route1);
|
app.use("/api/agents/clearMemory", route1);
|
||||||
@ -149,74 +152,77 @@ export default async (app: Express) => {
|
|||||||
app.use("/api/novel/event/generateEvents", route36);
|
app.use("/api/novel/event/generateEvents", route36);
|
||||||
app.use("/api/novel/event/getEvent", route37);
|
app.use("/api/novel/event/getEvent", route37);
|
||||||
app.use("/api/novel/getNovel", route38);
|
app.use("/api/novel/getNovel", route38);
|
||||||
app.use("/api/novel/getNovelEventState", route39);
|
app.use("/api/novel/getNovelData", route39);
|
||||||
app.use("/api/novel/getNovelIndex", route40);
|
app.use("/api/novel/getNovelEventState", route40);
|
||||||
app.use("/api/novel/updateNovel", route41);
|
app.use("/api/novel/getNovelIndex", route41);
|
||||||
app.use("/api/other/deleteAllData", route42);
|
app.use("/api/novel/updateNovel", route42);
|
||||||
app.use("/api/other/getVersion", route43);
|
app.use("/api/other/deleteAllData", route43);
|
||||||
app.use("/api/production/assets/getAssetsData", route44);
|
app.use("/api/other/getVersion", route44);
|
||||||
app.use("/api/production/editImage/generateFlowImage", route45);
|
app.use("/api/production/assets/getAssetsData", route45);
|
||||||
app.use("/api/production/editImage/getImageFlow", route46);
|
app.use("/api/production/editImage/generateFlowImage", route46);
|
||||||
app.use("/api/production/editImage/saveImageFlow", route47);
|
app.use("/api/production/editImage/getImageFlow", route47);
|
||||||
app.use("/api/production/editImage/updateImageFlow", route48);
|
app.use("/api/production/editImage/saveImageFlow", route48);
|
||||||
app.use("/api/production/exportImage", route49);
|
app.use("/api/production/editImage/updateImageFlow", route49);
|
||||||
app.use("/api/production/getFlowData", route50);
|
app.use("/api/production/exportImage", route50);
|
||||||
app.use("/api/production/getProductionData", route51);
|
app.use("/api/production/getFlowData", route51);
|
||||||
app.use("/api/production/getStoryboardData", route52);
|
app.use("/api/production/getProductionData", route52);
|
||||||
app.use("/api/production/saveFlowData", route53);
|
app.use("/api/production/getStoryboardData", route53);
|
||||||
app.use("/api/production/storyboard/downPreviewImage", route54);
|
app.use("/api/production/saveFlowData", route54);
|
||||||
app.use("/api/production/storyboard/getStoryboardData", route55);
|
app.use("/api/production/storyboard/downPreviewImage", route55);
|
||||||
app.use("/api/production/storyboard/previewImage", route56);
|
app.use("/api/production/storyboard/getStoryboardData", route56);
|
||||||
app.use("/api/production/workbench/confirmSelection", route57);
|
app.use("/api/production/storyboard/previewImage", route57);
|
||||||
app.use("/api/production/workbench/delVideo", route58);
|
app.use("/api/production/workbench/confirmSelection", route58);
|
||||||
app.use("/api/production/workbench/generateVideo", route59);
|
app.use("/api/production/workbench/delVideo", route59);
|
||||||
app.use("/api/production/workbench/getChatLines", route60);
|
app.use("/api/production/workbench/generateVideo", route60);
|
||||||
app.use("/api/production/workbench/getVideoModelDetail", route61);
|
app.use("/api/production/workbench/getChatLines", route61);
|
||||||
app.use("/api/production/workbench/videoPolling", route62);
|
app.use("/api/production/workbench/getVideoModelDetail", route62);
|
||||||
app.use("/api/project/addProject", route63);
|
app.use("/api/production/workbench/videoPolling", route63);
|
||||||
app.use("/api/project/delProject", route64);
|
app.use("/api/project/addProject", route64);
|
||||||
app.use("/api/project/editProject", route65);
|
app.use("/api/project/delProject", route65);
|
||||||
app.use("/api/project/getProject", route66);
|
app.use("/api/project/editProject", route66);
|
||||||
app.use("/api/script/addScript", route67);
|
app.use("/api/project/getProject", route67);
|
||||||
app.use("/api/script/delScript", route68);
|
app.use("/api/script/addScript", route68);
|
||||||
app.use("/api/script/exportScript", route69);
|
app.use("/api/script/delScript", route69);
|
||||||
app.use("/api/script/extractAssets", route70);
|
app.use("/api/script/exportScript", route70);
|
||||||
app.use("/api/script/getScrptApi", route71);
|
app.use("/api/script/extractAssets", route71);
|
||||||
app.use("/api/script/pollScriptAssets", route72);
|
app.use("/api/script/getScrptApi", route72);
|
||||||
app.use("/api/script/updateScript", route73);
|
app.use("/api/script/pollScriptAssets", route73);
|
||||||
app.use("/api/scriptAgent/getPlanData", route74);
|
app.use("/api/script/updateScript", route74);
|
||||||
app.use("/api/scriptAgent/setPlanData", route75);
|
app.use("/api/scriptAgent/getPlanData", route75);
|
||||||
app.use("/api/setting/about/checkUpdate", route76);
|
app.use("/api/scriptAgent/setPlanData", route76);
|
||||||
app.use("/api/setting/about/downloadApp", route77);
|
app.use("/api/setting/about/checkUpdate", route77);
|
||||||
app.use("/api/setting/agentDeploy/agentSetKey", route78);
|
app.use("/api/setting/about/downloadApp", route78);
|
||||||
app.use("/api/setting/agentDeploy/deployAgentModel", route79);
|
app.use("/api/setting/agentDeploy/agentSetKey", route79);
|
||||||
app.use("/api/setting/agentDeploy/getAgentDeploy", route80);
|
app.use("/api/setting/agentDeploy/deployAgentModel", route80);
|
||||||
app.use("/api/setting/dbConfig/clearData", route81);
|
app.use("/api/setting/agentDeploy/getAgentDeploy", route81);
|
||||||
app.use("/api/setting/dev/getSwitchAiDevTool", route82);
|
app.use("/api/setting/dbConfig/clearData", route82);
|
||||||
app.use("/api/setting/dev/updateSwitchAiDevTool", route83);
|
app.use("/api/setting/dev/getSwitchAiDevTool", route83);
|
||||||
app.use("/api/setting/fileManagement/openFolder", route84);
|
app.use("/api/setting/dev/updateSwitchAiDevTool", route84);
|
||||||
app.use("/api/setting/getTextModel", route85);
|
app.use("/api/setting/fileManagement/openFolder", route85);
|
||||||
app.use("/api/setting/loginConfig/getUser", route86);
|
app.use("/api/setting/getTextModel", route86);
|
||||||
app.use("/api/setting/loginConfig/updateUserPwd", route87);
|
app.use("/api/setting/loginConfig/getUser", route87);
|
||||||
app.use("/api/setting/memoryConfig/delAllMemory", route88);
|
app.use("/api/setting/loginConfig/updateUserPwd", route88);
|
||||||
app.use("/api/setting/memoryConfig/getMemory", route89);
|
app.use("/api/setting/memoryConfig/delAllMemory", route89);
|
||||||
app.use("/api/setting/memoryConfig/sureMemory", route90);
|
app.use("/api/setting/memoryConfig/getMemory", route90);
|
||||||
app.use("/api/setting/skillManagement/addSkill", route91);
|
app.use("/api/setting/memoryConfig/sureMemory", route91);
|
||||||
app.use("/api/setting/skillManagement/deleteSkill", route92);
|
app.use("/api/setting/promptManage/getPrompt", route92);
|
||||||
app.use("/api/setting/skillManagement/embeddingSkill", route93);
|
app.use("/api/setting/promptManage/updatePrompt", route93);
|
||||||
app.use("/api/setting/skillManagement/generateDescription", route94);
|
app.use("/api/setting/skillManagement/addSkill", route94);
|
||||||
app.use("/api/setting/skillManagement/getSkillList", route95);
|
app.use("/api/setting/skillManagement/deleteSkill", route95);
|
||||||
app.use("/api/setting/skillManagement/scanSkills", route96);
|
app.use("/api/setting/skillManagement/embeddingSkill", route96);
|
||||||
app.use("/api/setting/skillManagement/updateSkill", route97);
|
app.use("/api/setting/skillManagement/generateDescription", route97);
|
||||||
app.use("/api/setting/vendorConfig/addVendor", route98);
|
app.use("/api/setting/skillManagement/getSkillList", route98);
|
||||||
app.use("/api/setting/vendorConfig/deleteVendor", route99);
|
app.use("/api/setting/skillManagement/scanSkills", route99);
|
||||||
app.use("/api/setting/vendorConfig/getVendorList", route100);
|
app.use("/api/setting/skillManagement/updateSkill", route100);
|
||||||
app.use("/api/setting/vendorConfig/modelTest", route101);
|
app.use("/api/setting/vendorConfig/addVendor", route101);
|
||||||
app.use("/api/setting/vendorConfig/updateCode", route102);
|
app.use("/api/setting/vendorConfig/deleteVendor", route102);
|
||||||
app.use("/api/setting/vendorConfig/updateVendor", route103);
|
app.use("/api/setting/vendorConfig/getVendorList", route103);
|
||||||
app.use("/api/task/getProject", route104);
|
app.use("/api/setting/vendorConfig/modelTest", route104);
|
||||||
app.use("/api/task/getTaskApi", route105);
|
app.use("/api/setting/vendorConfig/updateCode", route105);
|
||||||
app.use("/api/task/getTaskCategories", route106);
|
app.use("/api/setting/vendorConfig/updateVendor", route106);
|
||||||
app.use("/api/task/taskDetails", route107);
|
app.use("/api/task/getProject", route107);
|
||||||
app.use("/api/test/test", route108);
|
app.use("/api/task/getTaskApi", route108);
|
||||||
|
app.use("/api/task/getTaskCategories", route109);
|
||||||
|
app.use("/api/task/taskDetails", route110);
|
||||||
|
app.use("/api/test/test", route111);
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/routes/novel/getNovelData.ts
Normal file
19
src/routes/novel/getNovelData.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
// 获取原文数据
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
projectId: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { projectId } = req.body;
|
||||||
|
const data = await u.db("o_novel").where("projectId", projectId).select("*");
|
||||||
|
res.status(200).send(success(data));
|
||||||
|
},
|
||||||
|
);
|
||||||
@ -17,10 +17,11 @@ export default router.post(
|
|||||||
videoRatio: z.string(),
|
videoRatio: z.string(),
|
||||||
imageModel: z.string(),
|
imageModel: z.string(),
|
||||||
videoModel: z.string(),
|
videoModel: z.string(),
|
||||||
|
projectType: z.string(),
|
||||||
imageQuality: z.string()
|
imageQuality: z.string()
|
||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { id, name, intro, type, artStyle, videoRatio, imageModel, videoModel,imageQuality } = req.body;
|
const { id, name, intro, type, artStyle, videoRatio, imageModel, videoModel,imageQuality, projectType } = req.body;
|
||||||
|
|
||||||
await u.db("o_project").where("id", id).update({
|
await u.db("o_project").where("id", id).update({
|
||||||
name,
|
name,
|
||||||
@ -30,7 +31,8 @@ export default router.post(
|
|||||||
videoRatio,
|
videoRatio,
|
||||||
imageModel,
|
imageModel,
|
||||||
videoModel,
|
videoModel,
|
||||||
imageQuality
|
imageQuality,
|
||||||
|
projectType,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).send(success({ message: "新增项目成功" }));
|
res.status(200).send(success({ message: "新增项目成功" }));
|
||||||
|
|||||||
10
src/routes/setting/promptManage/getPrompt.ts
Normal file
10
src/routes/setting/promptManage/getPrompt.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { success, error } from "@/lib/responseFormat";
|
||||||
|
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post("/", async (req, res) => {
|
||||||
|
const data = await u.db("o_prompt").select("*");
|
||||||
|
res.status(200).send(success(data));
|
||||||
|
});
|
||||||
23
src/routes/setting/promptManage/updatePrompt.ts
Normal file
23
src/routes/setting/promptManage/updatePrompt.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
id: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { id, data } = req.body;
|
||||||
|
await u
|
||||||
|
.db("o_prompt")
|
||||||
|
.where("id", id)
|
||||||
|
.update({
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
res.status(200).send(success(123));
|
||||||
|
},
|
||||||
|
);
|
||||||
@ -3,6 +3,7 @@ import u from "@/utils";
|
|||||||
import { Namespace, Socket } from "socket.io";
|
import { Namespace, Socket } from "socket.io";
|
||||||
import * as agent from "@/agents/productionAgent/index";
|
import * as agent from "@/agents/productionAgent/index";
|
||||||
import ResTool from "@/socket/resTool";
|
import ResTool from "@/socket/resTool";
|
||||||
|
import Memory from "@/utils/agent/memory";
|
||||||
|
|
||||||
async function verifyToken(rawToken: string): Promise<Boolean> {
|
async function verifyToken(rawToken: string): Promise<Boolean> {
|
||||||
const setting = await u.db("o_setting").where("key", "tokenKey").select("value").first();
|
const setting = await u.db("o_setting").where("key", "tokenKey").select("value").first();
|
||||||
@ -41,29 +42,67 @@ export default (nsp: Namespace) => {
|
|||||||
});
|
});
|
||||||
let abortController: AbortController | null = null;
|
let abortController: AbortController | null = null;
|
||||||
|
|
||||||
socket.on("message", async (text: string) => {
|
socket.on("chat", async (data: { content: string }) => {
|
||||||
|
const { content } = data;
|
||||||
abortController?.abort();
|
abortController?.abort();
|
||||||
abortController = new AbortController();
|
abortController = new AbortController();
|
||||||
const currentController = abortController;
|
const currentController = abortController;
|
||||||
console.log("%c Line:30 🍑 isolationKey", "background:#e41a6a", isolationKey);
|
const memory = new Memory("scriptAgent", isolationKey);
|
||||||
|
|
||||||
const textStream = await agent.decisionAI({ socket, isolationKey, text, abortSignal: currentController.signal, resTool });
|
const msg = resTool.newMessage("assistant", "统筹");
|
||||||
|
const ctx: agent.AgentContext = {
|
||||||
|
socket,
|
||||||
|
isolationKey,
|
||||||
|
text: content,
|
||||||
|
userMessageTime: new Date(msg.datetime).getTime() - 1,
|
||||||
|
abortSignal: currentController.signal,
|
||||||
|
resTool,
|
||||||
|
msg,
|
||||||
|
};
|
||||||
|
|
||||||
let msg = resTool.textMessage();
|
const textStream = await agent.decisionAI(ctx);
|
||||||
|
|
||||||
|
let currentMsg = ctx.msg;
|
||||||
|
let text = currentMsg.text();
|
||||||
|
let currentContent = "";
|
||||||
|
|
||||||
|
const persistCurrentMessage = async () => {
|
||||||
|
if (!currentContent.trim()) return;
|
||||||
|
await memory.add("assistant:decision", currentContent, {
|
||||||
|
name: "统筹",
|
||||||
|
createTime: new Date(currentMsg.datetime).getTime(),
|
||||||
|
});
|
||||||
|
currentContent = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const syncCurrentMessage = async () => {
|
||||||
|
if (ctx.msg === currentMsg) return;
|
||||||
|
text.complete();
|
||||||
|
currentMsg.complete();
|
||||||
|
await persistCurrentMessage();
|
||||||
|
currentMsg = ctx.msg;
|
||||||
|
text = currentMsg.text();
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for await (const chunk of textStream) {
|
for await (const chunk of textStream) {
|
||||||
msg.send(chunk);
|
await syncCurrentMessage();
|
||||||
|
text.append(chunk);
|
||||||
|
currentContent += chunk;
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.name !== "AbortError") throw err;
|
if (err.name !== "AbortError") throw err;
|
||||||
} finally {
|
} finally {
|
||||||
msg.end();
|
await syncCurrentMessage();
|
||||||
|
text.complete();
|
||||||
|
currentMsg.complete();
|
||||||
|
await persistCurrentMessage();
|
||||||
if (abortController === currentController) {
|
if (abortController === currentController) {
|
||||||
abortController = null;
|
abortController = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("setModelData", async (data: any) => {
|
socket.on("setModelData", async (data: any) => {
|
||||||
resTool.data.imageModel = data;
|
resTool.data.imageModel = data;
|
||||||
});
|
});
|
||||||
@ -71,6 +110,7 @@ export default (nsp: Namespace) => {
|
|||||||
isolationKey = data.key;
|
isolationKey = data.key;
|
||||||
resTool.data.scriptId = data.scriptId;
|
resTool.data.scriptId = data.scriptId;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("stop", () => {
|
socket.on("stop", () => {
|
||||||
abortController?.abort();
|
abortController?.abort();
|
||||||
abortController = null;
|
abortController = null;
|
||||||
|
|||||||
17
src/types/database.d.ts
vendored
17
src/types/database.d.ts
vendored
@ -1,13 +1,6 @@
|
|||||||
// @db-hash 509ef34a31d203b2a7dca4e5dc69ae88
|
// @db-hash 8aa6e47033e9f59d1f8b797d5b4fccd3
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
export interface _o_script_old_20260327 {
|
|
||||||
'content'?: string | null;
|
|
||||||
'createTime'?: number | null;
|
|
||||||
'id'?: number;
|
|
||||||
'name'?: string | null;
|
|
||||||
'projectId'?: number | null;
|
|
||||||
}
|
|
||||||
export interface memories {
|
export interface memories {
|
||||||
'content': string;
|
'content': string;
|
||||||
'createTime': number;
|
'createTime': number;
|
||||||
@ -54,6 +47,7 @@ export interface o_assets {
|
|||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'projectId'?: number | null;
|
'projectId'?: number | null;
|
||||||
'prompt'?: string | null;
|
'prompt'?: string | null;
|
||||||
|
'promptState'?: string | null;
|
||||||
'remark'?: string | null;
|
'remark'?: string | null;
|
||||||
'scriptId'?: number | null;
|
'scriptId'?: number | null;
|
||||||
'startTime'?: number | null;
|
'startTime'?: number | null;
|
||||||
@ -117,7 +111,6 @@ export interface o_project {
|
|||||||
'createTime'?: number | null;
|
'createTime'?: number | null;
|
||||||
'id'?: number | null;
|
'id'?: number | null;
|
||||||
'imageModel'?: string | null;
|
'imageModel'?: string | null;
|
||||||
'imageQuality'?: string | null;
|
|
||||||
'intro'?: string | null;
|
'intro'?: string | null;
|
||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'projectType'?: string | null;
|
'projectType'?: string | null;
|
||||||
@ -127,9 +120,10 @@ export interface o_project {
|
|||||||
'videoRatio'?: string | null;
|
'videoRatio'?: string | null;
|
||||||
}
|
}
|
||||||
export interface o_prompt {
|
export interface o_prompt {
|
||||||
|
'data'?: string | null;
|
||||||
'id'?: number;
|
'id'?: number;
|
||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
'rompt'?: string | null;
|
'type'?: string | null;
|
||||||
}
|
}
|
||||||
export interface o_script {
|
export interface o_script {
|
||||||
'content'?: string | null;
|
'content'?: string | null;
|
||||||
@ -172,7 +166,7 @@ export interface o_storyboard {
|
|||||||
'filePath'?: string | null;
|
'filePath'?: string | null;
|
||||||
'frameMode'?: string | null;
|
'frameMode'?: string | null;
|
||||||
'id'?: number;
|
'id'?: number;
|
||||||
'index'?: string | null;
|
'index'?: number | null;
|
||||||
'lines'?: string | null;
|
'lines'?: string | null;
|
||||||
'mode'?: string | null;
|
'mode'?: string | null;
|
||||||
'model'?: string | null;
|
'model'?: string | null;
|
||||||
@ -237,7 +231,6 @@ export interface o_videoConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DB {
|
export interface DB {
|
||||||
"_o_script_old_20260327": _o_script_old_20260327;
|
|
||||||
"memories": memories;
|
"memories": memories;
|
||||||
"o_agentDeploy": o_agentDeploy;
|
"o_agentDeploy": o_agentDeploy;
|
||||||
"o_agentWorkData": o_agentWorkData;
|
"o_agentWorkData": o_agentWorkData;
|
||||||
|
|||||||
@ -27,9 +27,9 @@ class CleanNovel {
|
|||||||
private async processChapter(novel: o_novel, intansce: ReturnType<typeof u.Ai.Text>): Promise<EventType | null> {
|
private async processChapter(novel: o_novel, intansce: ReturnType<typeof u.Ai.Text>): Promise<EventType | null> {
|
||||||
try {
|
try {
|
||||||
const prompt = await u.getPrompts("event");
|
const prompt = await u.getPrompts("event");
|
||||||
const data = await u.db("o_prompt").where("name", "eventExtraction").first("prompt");
|
const data = await u.db("o_prompt").where("type", "eventExtraction").first("data");
|
||||||
const resData = await intansce.invoke({
|
const resData = await intansce.invoke({
|
||||||
system: data ? JSON.stringify(data.prompt) : (prompt as string),
|
system: data ? JSON.stringify(data.data) : (prompt as string),
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: "user",
|
role: "user",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user