Merge branch '108' of https://github.com/HBAI-Ltd/Toonflow-app into 108
# Conflicts: # src/types/database.d.ts
This commit is contained in:
commit
3edbe19367
@ -98,14 +98,19 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
tools: { ...extraTools, ...useTools({ resTool, msg: subMsg }) },
|
||||
});
|
||||
|
||||
for await (const chunk of textStream) {
|
||||
text.append(chunk);
|
||||
fullResponse += chunk;
|
||||
try {
|
||||
for await (const chunk of textStream) {
|
||||
text.append(chunk);
|
||||
fullResponse += chunk;
|
||||
}
|
||||
text.complete();
|
||||
subMsg.complete();
|
||||
} catch (err: any) {
|
||||
text.complete();
|
||||
subMsg.stop();
|
||||
throw err;
|
||||
}
|
||||
|
||||
text.complete();
|
||||
subMsg.complete();
|
||||
|
||||
if (fullResponse.trim()) {
|
||||
await memory.add(memoryKey, fullResponse, {
|
||||
name,
|
||||
@ -130,7 +135,7 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
const addPrompt =
|
||||
"\n" +
|
||||
[
|
||||
"你可以使用如下XML格式写入工作区:\n```",
|
||||
"你必须使用如下XML格式写入工作区:\n```",
|
||||
"拍摄计划:<scriptPlan>内容</scriptPlan>",
|
||||
"分镜表:<storyboardTable>内容</storyboardTable>",
|
||||
"```",
|
||||
@ -163,7 +168,7 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
const systemPrompt = await fs.promises.readFile(skill, "utf-8");
|
||||
return runAgent({
|
||||
prompt,
|
||||
system: systemPrompt + "你可以使用如下XML格式写入工作区:\n<storySkeleton>故事骨架内容</storySkeleton>",
|
||||
system: systemPrompt + "你必须使用如下XML格式写入工作区:\n<storySkeleton>故事骨架内容</storySkeleton>",
|
||||
name: "监制",
|
||||
memoryKey: "assistant:supervision",
|
||||
});
|
||||
|
||||
@ -108,14 +108,19 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
tools: { ...extraTools, ...useTools({ resTool, msg: subMsg }) },
|
||||
});
|
||||
|
||||
for await (const chunk of textStream) {
|
||||
text.append(chunk);
|
||||
fullResponse += chunk;
|
||||
try {
|
||||
for await (const chunk of textStream) {
|
||||
text.append(chunk);
|
||||
fullResponse += chunk;
|
||||
}
|
||||
text.complete();
|
||||
subMsg.complete();
|
||||
} catch (err: any) {
|
||||
text.complete();
|
||||
subMsg.stop();
|
||||
throw err;
|
||||
}
|
||||
|
||||
text.complete();
|
||||
subMsg.complete();
|
||||
|
||||
if (fullResponse.trim()) {
|
||||
await memory.add(memoryKey, fullResponse, {
|
||||
name,
|
||||
@ -139,7 +144,7 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
const systemPrompt = await fs.promises.readFile(skill, "utf-8");
|
||||
return runAgent({
|
||||
prompt,
|
||||
system: systemPrompt + "\n你可以使用如下XML格式写入工作区:\n<storySkeleton>故事骨架内容</storySkeleton>",
|
||||
system: systemPrompt + "\n你必须使用如下XML格式写入工作区:\n<storySkeleton>故事骨架内容</storySkeleton>",
|
||||
name: "编剧",
|
||||
memoryKey: "assistant:execution:storySkeleton",
|
||||
});
|
||||
@ -154,7 +159,7 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
const systemPrompt = await fs.promises.readFile(skill, "utf-8");
|
||||
return runAgent({
|
||||
prompt,
|
||||
system: systemPrompt + "\n你可以使用如下XML格式写入工作区:\n<adaptationStrategy>改编策略内容</adaptationStrategy>",
|
||||
system: systemPrompt + "\n你必须使用如下XML格式写入工作区:\n<adaptationStrategy>改编策略内容</adaptationStrategy>",
|
||||
name: "编剧",
|
||||
memoryKey: "assistant:execution:adaptationStrategy",
|
||||
});
|
||||
@ -171,7 +176,7 @@ function createSubAgent(parentCtx: AgentContext) {
|
||||
prompt,
|
||||
system:
|
||||
systemPrompt +
|
||||
`\n你可以使用如下XML格式写入工作区:\nXML不得添加任何额外标签<script><item name="剧本名称">剧本内容</item><item name="剧本名称">剧本内容</item><item name="剧本名称">剧本内容</item></script>`,
|
||||
`\n你必须使用如下XML格式写入工作区:\nXML不得添加任何额外标签<script><item name="剧本名称">剧本内容</item><item name="剧本名称">剧本内容</item><item name="剧本名称">剧本内容</item></script>`,
|
||||
name: "编剧",
|
||||
memoryKey: "assistant:execution:script",
|
||||
});
|
||||
|
||||
@ -2,25 +2,35 @@ import express from "express";
|
||||
const router = express.Router();
|
||||
import u from "@/utils";
|
||||
import fs from "fs";
|
||||
import { useSkill } from "@/utils/agent/skillsTools";
|
||||
import Memory from "@/utils/agent/memory";
|
||||
|
||||
|
||||
function buildMemPrompt(mem: Awaited<ReturnType<Memory["get"]>>): string {
|
||||
let memoryContext = "";
|
||||
if (mem.rag.length) {
|
||||
memoryContext += `[相关记忆]\n${mem.rag.map((r) => r.content).join("\n")}`;
|
||||
}
|
||||
if (mem.summaries.length) {
|
||||
if (memoryContext) memoryContext += "\n\n";
|
||||
memoryContext += `[历史摘要]\n${mem.summaries.map((s, i) => `${i + 1}. ${s.content}`).join("\n")}`;
|
||||
}
|
||||
if (mem.shortTerm.length) {
|
||||
if (memoryContext) memoryContext += "\n\n";
|
||||
memoryContext += `[近期对话]\n${mem.shortTerm.map((m) => `${m.role}: ${m.content}`).join("\n")}`;
|
||||
}
|
||||
return `## Memory\n以下是你对用户的记忆,可作为参考但不要主动提及:\n${memoryContext}`;
|
||||
}
|
||||
|
||||
export default router.get("/", async (req, res) => {
|
||||
const skill = await useSkill(
|
||||
{
|
||||
mainSkill: "production_agent_execution",
|
||||
workspace: ["production_agent_skills/execution"],
|
||||
attachedSkills: ["art_prompts/chinese_sweet_romance/driector_skills"],
|
||||
},
|
||||
);
|
||||
|
||||
const test = await u.Ai.Text("scriptAgent").invoke({
|
||||
system: skill.prompt,
|
||||
messages: [
|
||||
{ role: "user", content: "渐进式激活skill,技能->资源1->资源2...一直渐进到最深处,并输出你的阅读路线,同级目录你只用读取一个无需全部读取" },
|
||||
],
|
||||
tools: skill.tools,
|
||||
});
|
||||
const isolationKey = "test";
|
||||
const input = "你好"
|
||||
|
||||
console.log("%c Line:21 🌽 text", "background:#ea7e5c", test.text);
|
||||
res.send(test.text);
|
||||
const memory = new Memory("productionAgent", isolationKey);
|
||||
await memory.add("user", input);
|
||||
|
||||
|
||||
const mem = buildMemPrompt(await memory.get(input));
|
||||
|
||||
res.send(mem);
|
||||
});
|
||||
|
||||
@ -36,12 +36,22 @@ export default (nsp: Namespace) => {
|
||||
|
||||
console.log("[productionAgent] 已连接:", socket.id);
|
||||
|
||||
const resTool = new ResTool(socket, {
|
||||
let resTool = new ResTool(socket, {
|
||||
projectId: socket.handshake.auth.projectId,
|
||||
scriptId: socket.handshake.auth.scriptId,
|
||||
});
|
||||
let abortController: AbortController | null = null;
|
||||
|
||||
socket.on("updateContext", (data: { isolationKey: string; projectId: number; scriptId: number }, callback) => {
|
||||
isolationKey = data.isolationKey;
|
||||
resTool = new ResTool(socket, {
|
||||
projectId: data.projectId,
|
||||
scriptId: data.scriptId,
|
||||
});
|
||||
console.log("[productionAgent] 上下文已更新:", isolationKey);
|
||||
callback?.({ success: true });
|
||||
});
|
||||
|
||||
socket.on("chat", async (data: { content: string }) => {
|
||||
const { content } = data;
|
||||
abortController?.abort();
|
||||
@ -84,6 +94,7 @@ export default (nsp: Namespace) => {
|
||||
text = currentMsg.text();
|
||||
};
|
||||
|
||||
let aborted = false;
|
||||
try {
|
||||
for await (const chunk of textStream) {
|
||||
await syncCurrentMessage();
|
||||
@ -91,11 +102,21 @@ export default (nsp: Namespace) => {
|
||||
currentContent += chunk;
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (err.name !== "AbortError") throw err;
|
||||
if (err.name === "AbortError" || currentController.signal.aborted) {
|
||||
aborted = true;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
await syncCurrentMessage();
|
||||
text.complete();
|
||||
currentMsg.complete();
|
||||
if (aborted) {
|
||||
text.append("[已停止]");
|
||||
text.complete();
|
||||
currentMsg.stop();
|
||||
} else {
|
||||
text.complete();
|
||||
currentMsg.complete();
|
||||
}
|
||||
await persistCurrentMessage();
|
||||
if (abortController === currentController) {
|
||||
abortController = null;
|
||||
|
||||
@ -83,6 +83,7 @@ export default (nsp: Namespace) => {
|
||||
text = currentMsg.text();
|
||||
};
|
||||
|
||||
let aborted = false;
|
||||
try {
|
||||
for await (const chunk of textStream) {
|
||||
await syncCurrentMessage();
|
||||
@ -90,11 +91,20 @@ export default (nsp: Namespace) => {
|
||||
currentContent += chunk;
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (err.name !== "AbortError") throw err;
|
||||
if (err.name === "AbortError" || currentController.signal.aborted) {
|
||||
aborted = true;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
await syncCurrentMessage();
|
||||
text.complete();
|
||||
currentMsg.complete();
|
||||
if (aborted) {
|
||||
text.complete();
|
||||
currentMsg.stop();
|
||||
} else {
|
||||
text.complete();
|
||||
currentMsg.complete();
|
||||
}
|
||||
await persistCurrentMessage();
|
||||
if (abortController === currentController) {
|
||||
abortController = null;
|
||||
|
||||
4
src/types/database.d.ts
vendored
4
src/types/database.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// @db-hash 6be0a80e9c8f541987a4c1e907736237
|
||||
// @db-hash 93b2462070c45c2b449e9a18c4e88763
|
||||
//该文件由脚本自动生成,请勿手动修改
|
||||
|
||||
export interface memories {
|
||||
@ -178,7 +178,6 @@ export interface o_storyboard {
|
||||
'sound'?: string | null;
|
||||
'state'?: string | null;
|
||||
'title'?: string | null;
|
||||
'videoPrompt'?: string | null;
|
||||
}
|
||||
export interface o_tasks {
|
||||
'describe'?: string | null;
|
||||
@ -212,7 +211,6 @@ export interface o_video {
|
||||
'errorReason'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'id'?: number;
|
||||
'projectId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
'state'?: string | null;
|
||||
'storyboardId'?: number | null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user