修改字段名

This commit is contained in:
zhishi 2026-03-24 12:55:15 +08:00
parent 050b9106d8
commit c681c14d3d
10 changed files with 140 additions and 71 deletions

View File

@ -40,6 +40,7 @@ export async function decisionAI(ctx: AgentContext) {
resTool.systemMessage("决策层AI 接管聊天"); resTool.systemMessage("决策层AI 接管聊天");
const memory = new Memory("scriptAgent", isolationKey); const memory = new Memory("scriptAgent", isolationKey);
await memory.add("user", text); await memory.add("user", text);
const [skill, mem] = await Promise.all([useSkill("script-agent", "decision"), memory.get(text)]); const [skill, mem] = await Promise.all([useSkill("script-agent", "decision"), memory.get(text)]);
@ -57,9 +58,11 @@ export async function decisionAI(ctx: AgentContext) {
`目标改编视频画幅:${projectData?.videoRatio ?? "16:9"}`, `目标改编视频画幅:${projectData?.videoRatio ?? "16:9"}`,
].join("\n"); ].join("\n");
const prefixSystem = `${projectInfo}\n\n## 章节ID映射表\n${novelData.map((i: any) => `- ${i.id}: 第${i.index}`).join("\n")}\n\n`; // const prefixSystem = `${projectInfo}\n\n## 章节ID映射表\n${novelData.map((i: any) => `- ${i.id}: 第${i.index}章`).join("\n")}\n\n`;
const prefixSystem = `不管说什么直接调用 insert_script_to_sqlite 工具`
console.log("%c Line:57 🍧 prefixSystem", "background:#ea7e5c", prefixSystem); console.log("%c Line:57 🍧 prefixSystem", "background:#ea7e5c", prefixSystem);
const { textStream } = await u.Ai.Text("scriptAgent").stream({ const { textStream } = await u.Ai.Text("scriptAgent").stream({
system: prefixSystem + systemPrompt, system: prefixSystem + systemPrompt,
messages: [{ role: "user", content: text }], messages: [{ role: "user", content: text }],

View File

@ -14,7 +14,11 @@ export const AssetSchema = z.object({
state: z.enum(["未生成", "生成中", "已完成", "生成失败"]).describe("衍生资产生成状态,新增默认未生成"), state: z.enum(["未生成", "生成中", "已完成", "生成失败"]).describe("衍生资产生成状态,新增默认未生成"),
type: z.enum(["role", "tool", "scene", "clip"]).describe("衍生资产类型"), type: z.enum(["role", "tool", "scene", "clip"]).describe("衍生资产类型"),
}); });
export const ScriptSchema = z.object({
id: z.number().describe("剧本ID,如果新增则为空").optional(),
name: z.string().describe("剧本名称"),
content: z.string().describe("剧本内容"),
});
export const planData = z.object({ export const planData = z.object({
storySkeleton: z.string().describe("故事骨架"), storySkeleton: z.string().describe("故事骨架"),
adaptationStrategy: z.string().describe("改编策略"), adaptationStrategy: z.string().describe("改编策略"),
@ -92,20 +96,35 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
insert_script_to_sqlite: tool({ insert_script_to_sqlite: tool({
description: "将剧本内容插入sqlite数据库供后续业务使用", description: "将剧本内容插入sqlite数据库供后续业务使用",
inputSchema: z.object({ inputSchema: z.object({
list: z.array(AssetSchema), script: ScriptSchema,
assetsList: z.array(AssetSchema).describe("剧本所使用资产列表"),
}), }),
execute: async ({ list }) => { execute: async ({ assetsList, script }) => {
console.log("[tools] insert_script_to_sqlite", list); console.log("%c Line:103 🍷 script", "background:#42b983", script);
await u.db("o_assets").insert( console.log("[tools] insert_script_to_sqlite", assetsList);
list.map((i) => ({ const [scriptId] = await u.db("o_script").insert({
name: i.name, name: script.name,
prompt: i.prompt, content: script.content,
type: i.type, projectId: resTool.data.projectId,
describe: i.desc, createTime: Date.now(),
projectId: resTool.data.projectId, });
state: "未生成", if (assetsList && assetsList.length) {
})), const assetId = [];
); for (const i of assetsList) {
const [id] = await u.db("o_assets").insert({
name: i.name,
prompt: i.prompt,
type: i.type,
describe: i.desc,
projectId: resTool.data.projectId,
state: "未生成",
});
assetId.push(id);
}
await u.db("o_script_assets").insert(assetId.map((i) => ({ scriptId, assetId: i })));
}
return true; return true;
}, },
}), }),

View File

@ -281,10 +281,9 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.text("describe"); table.text("describe");
table.integer("scriptId"); //剧本id table.integer("scriptId"); //剧本id
table.integer("imageId").unsigned().references("id").inTable("o_image"); table.integer("imageId").unsigned().references("id").inTable("o_image");
table.integer("sonId"); table.integer("assetsId");
table.integer("projectId"); table.integer("projectId");
table.integer("startTime"); table.integer("startTime");
table.text("state");
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },

View File

@ -7,26 +7,26 @@ const router = express.Router();
// 新增资产 // 新增资产
export default router.post( export default router.post(
"/", "/",
validateFields({ validateFields({
name: z.string(), name: z.string(),
describe: z.string(), describe: z.string(),
type: z.string(), type: z.string(),
projectId: z.number(), projectId: z.number(),
remark: z.string(), remark: z.string(),
prompt: z.string().optional().nullable(), prompt: z.string().optional().nullable(),
}), }),
async (req, res) => { async (req, res) => {
const { name, describe, type, projectId, remark, prompt } = req.body; const { name, describe, type, projectId, remark, prompt } = req.body;
await u.db("o_assets").insert({ await u.db("o_assets").insert({
name, name,
describe, describe,
type, type,
projectId, projectId,
remark, remark,
prompt, prompt,
startTime: Date.now(), startTime: Date.now(),
}); });
res.status(200).send(success({ message: "新增资产成功" })); res.status(200).send(success({ message: "新增资产成功" }));
}, },
); );

View File

@ -8,13 +8,13 @@ const router = express.Router();
// 批量删除资产 // 批量删除资产
export default router.post( export default router.post(
"/", "/",
validateFields({ validateFields({
id: z.array(z.number()), id: z.array(z.number()),
}), }),
async (req, res) => { async (req, res) => {
const { id } = req.body; const { id } = req.body;
await u.db("o_assets").whereIn("id", id).delete(); await u.db("o_assets").whereIn("id", id).delete();
res.status(200).send(success({ message: "删除资产成功" })); res.status(200).send(success({ message: "删除资产成功" }));
}, },
); );

View File

@ -28,7 +28,7 @@ export default router.post(
query = query.andWhere("name", "like", `%${name}%`); query = query.andWhere("name", "like", `%${name}%`);
} }
// 分页查询 // 分页查询
const parentAssets = await query.where("o_assets.sonId", null).offset(offset).limit(limit); const parentAssets = await query.where("o_assets.assetId", null).offset(offset).limit(limit);
// 获取所有子资产供关联使用 // 获取所有子资产供关联使用
let childQuery = u let childQuery = u
@ -37,7 +37,7 @@ export default router.post(
.select("o_assets.*", "o_image.filePath") .select("o_assets.*", "o_image.filePath")
.where("o_assets.projectId", projectId) .where("o_assets.projectId", projectId)
.andWhere("o_assets.type", type) .andWhere("o_assets.type", type)
.whereNotNull("o_assets.sonId"); .whereNotNull("o_assets.assetId");
if (name) { if (name) {
childQuery = childQuery.andWhere("o_assets.name", "like", `%${name}%`); childQuery = childQuery.andWhere("o_assets.name", "like", `%${name}%`);
} }
@ -47,8 +47,8 @@ export default router.post(
const result = await Promise.all( const result = await Promise.all(
parentAssets.map(async (parent) => ({ parentAssets.map(async (parent) => ({
...parent, ...parent,
sonAssets: childAssets.filter((child) => child.sonId === parent.id), sonAssets: childAssets.filter((child) => child.assetId === parent.id),
filePath: parent.filePath && (await u.oss.getFileUrl(parent.filePath!)), src: parent.filePath && (await u.oss.getFileUrl(parent.filePath!)),
})), })),
); );
@ -57,7 +57,7 @@ export default router.post(
.db("o_assets") .db("o_assets")
.where("projectId", projectId) .where("projectId", projectId)
.andWhere("type", type) .andWhere("type", type)
.andWhere("sonId", null) .andWhere("assetId", null)
.andWhere((qb) => { .andWhere((qb) => {
if (name) { if (name) {
qb.andWhere("name", "like", `%${name}%`); qb.andWhere("name", "like", `%${name}%`);

View File

@ -36,15 +36,21 @@ export default router.post(
state: "生成成功", state: "生成成功",
}); });
// 更新资产表图片为新图片 // 更新资产表图片为新图片
await u.db("o_assets").where("id", id).update({ await u
prompt: prompt ?? "", .db("o_assets")
imageId: idData, .where("id", id)
}); .update({
prompt: prompt ?? "",
imageId: idData,
});
} else { } else {
await u.db("o_assets").where("id", id).update({ await u
prompt: prompt ?? "", .db("o_assets")
imageId: imageId, .where("id", id)
}); .update({
prompt: prompt ?? "",
imageId: imageId,
});
} }
res.status(200).send(success({ message: "保存资产图片成功" })); res.status(200).send(success({ message: "保存资产图片成功" }));
}, },

View File

@ -13,10 +13,9 @@ export default router.post(
}), }),
async (req, res) => { async (req, res) => {
const { projectId } = req.body; const { projectId } = req.body;
const parentAssetsData = await u.db("o_assets").where("projectId", projectId).whereNotNull("sonId"); const parentAssetsData = await u.db("o_assets").where("projectId", projectId).whereNotNull("assetId");
const parentIds = parentAssetsData.map((i) => i.id); const parentIds = parentAssetsData.map((i) => i.id);
const parnetIdsMap: Record<number, number> = {}; const sonAssetsData = await u.db("o_assets").whereIn("assetsId", parentIds);
const sonAssetsData = await u.db("o_assets").whereIn("sonId", parentIds);
const sonAssetsMap: Record<number, o_assets[]> = {}; const sonAssetsMap: Record<number, o_assets[]> = {};
const imageIds = [...parentAssetsData.map((i) => i.imageId).concat(sonAssetsData.map((i) => i.imageId))].filter(Boolean); const imageIds = [...parentAssetsData.map((i) => i.imageId).concat(sonAssetsData.map((i) => i.imageId))].filter(Boolean);
@ -34,8 +33,8 @@ export default router.post(
imageUrlMap[i.id!] = i.src; imageUrlMap[i.id!] = i.src;
}); });
sonAssetsData.forEach((i) => { sonAssetsData.forEach((i) => {
if (!sonAssetsMap[i.sonId!]) { if (!sonAssetsMap[i.assetsId!]) {
sonAssetsMap[i.sonId!] = []; sonAssetsMap[i.assetsId!] = [];
} }
const obj = { const obj = {
assetsId: i.id, assetsId: i.id,
@ -44,7 +43,7 @@ export default router.post(
src: imageUrlMap[i.imageId!] ?? null, src: imageUrlMap[i.imageId!] ?? null,
derive: sonAssetsMap[i.id!] ?? [], derive: sonAssetsMap[i.id!] ?? [],
}; };
sonAssetsMap[i.sonId!].push(obj); sonAssetsMap[i.assetsId!].push(obj);
}); });
const returnData = parentAssetsData.map((i) => { const returnData = parentAssetsData.map((i) => {
return { return {

View File

@ -28,7 +28,7 @@ export default router.post(
.leftJoin("o_image", "o_assets.imageId", "o_image.id") .leftJoin("o_image", "o_assets.imageId", "o_image.id")
.select("o_assets.*", "o_image.filePath") .select("o_assets.*", "o_image.filePath")
.where("o_assets.projectId", projectId) .where("o_assets.projectId", projectId)
.whereNotNull("o_assets.sonId"); .whereNotNull("o_assets.assetId");
if (!sqlData) { if (!sqlData) {
const flowData: FlowData = { const flowData: FlowData = {
@ -42,7 +42,7 @@ export default router.post(
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)), src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
derive: await Promise.all( derive: await Promise.all(
childAssetsData childAssetsData
.filter((child) => child.sonId === item.id) .filter((child) => child.assetId === item.id)
.map(async (child) => ({ .map(async (child) => ({
id: child.id, id: child.id,
assetsId: item.id, assetsId: item.id,

View File

@ -1,6 +1,45 @@
// @db-hash b6146b9f91d8b9853e0f6fcb41c3145b // @db-hash 25c88b2cb37f9deac8b2bb8354113537
//该文件由脚本自动生成,请勿手动修改 //该文件由脚本自动生成,请勿手动修改
export interface _o_assets_old_20260324 {
'describe'?: string | null;
'id'?: number;
'imageId'?: number | null;
'name'?: string | null;
'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_assets_old_20260324_1 {
'assetId'?: number | null;
'describe'?: string | null;
'id'?: number;
'imageId'?: number | null;
'name'?: string | null;
'projectId'?: number | null;
'prompt'?: string | null;
'remark'?: string | null;
'scriptId'?: number | null;
'startTime'?: number | null;
'state'?: string | null;
'type'?: string | null;
}
export interface _o_novel_old_20260323 {
'chapter'?: string | null;
'chapterData'?: string | null;
'chapterIndex'?: number | null;
'createTime'?: number | null;
'event'?: string | null;
'eventState'?: number | null;
'id'?: number;
'projectId'?: number | null;
'reel'?: string | null;
}
export interface memories { export interface memories {
'content': string; 'content': string;
'createTime': number; 'createTime': number;
@ -37,6 +76,7 @@ export interface o_artStyle {
'styles'?: string | null; 'styles'?: string | null;
} }
export interface o_assets { export interface o_assets {
'assetsId'?: number | null;
'describe'?: string | null; 'describe'?: string | null;
'id'?: number; 'id'?: number;
'imageId'?: number | null; 'imageId'?: number | null;
@ -45,7 +85,6 @@ export interface o_assets {
'prompt'?: string | null; 'prompt'?: string | null;
'remark'?: string | null; 'remark'?: string | null;
'scriptId'?: number | null; 'scriptId'?: number | null;
'sonId'?: number | null;
'startTime'?: number | null; 'startTime'?: number | null;
'state'?: string | null; 'state'?: string | null;
'type'?: string | null; 'type'?: string | null;
@ -88,6 +127,7 @@ export interface o_novel {
'chapterData'?: string | null; 'chapterData'?: string | null;
'chapterIndex'?: number | null; 'chapterIndex'?: number | null;
'createTime'?: number | null; 'createTime'?: number | null;
'errorReason'?: string | null;
'event'?: string | null; 'event'?: string | null;
'eventState'?: number | null; 'eventState'?: number | null;
'id'?: number; 'id'?: number;
@ -204,6 +244,9 @@ export interface o_videoConfig {
} }
export interface DB { export interface DB {
"_o_assets_old_20260324": _o_assets_old_20260324;
"_o_assets_old_20260324_1": _o_assets_old_20260324_1;
"_o_novel_old_20260323": _o_novel_old_20260323;
"memories": memories; "memories": memories;
"o_agentDeploy": o_agentDeploy; "o_agentDeploy": o_agentDeploy;
"o_agentWorkData": o_agentWorkData; "o_agentWorkData": o_agentWorkData;