修改字段名
This commit is contained in:
parent
050b9106d8
commit
c681c14d3d
@ -40,6 +40,7 @@ export async function decisionAI(ctx: AgentContext) {
|
||||
resTool.systemMessage("决策层AI 接管聊天");
|
||||
|
||||
const memory = new Memory("scriptAgent", isolationKey);
|
||||
|
||||
await memory.add("user", text);
|
||||
const [skill, mem] = await Promise.all([useSkill("script-agent", "decision"), memory.get(text)]);
|
||||
|
||||
@ -57,8 +58,10 @@ export async function decisionAI(ctx: AgentContext) {
|
||||
`目标改编视频画幅:${projectData?.videoRatio ?? "16:9"}`,
|
||||
].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);
|
||||
|
||||
|
||||
const { textStream } = await u.Ai.Text("scriptAgent").stream({
|
||||
system: prefixSystem + systemPrompt,
|
||||
|
||||
@ -14,7 +14,11 @@ export const AssetSchema = z.object({
|
||||
state: z.enum(["未生成", "生成中", "已完成", "生成失败"]).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({
|
||||
storySkeleton: z.string().describe("故事骨架"),
|
||||
adaptationStrategy: z.string().describe("改编策略"),
|
||||
@ -92,20 +96,35 @@ export default (resTool: ResTool, toolsNames?: string[]) => {
|
||||
insert_script_to_sqlite: tool({
|
||||
description: "将剧本内容插入sqlite数据库,供后续业务使用",
|
||||
inputSchema: z.object({
|
||||
list: z.array(AssetSchema),
|
||||
script: ScriptSchema,
|
||||
assetsList: z.array(AssetSchema).describe("剧本所使用资产列表"),
|
||||
}),
|
||||
execute: async ({ list }) => {
|
||||
console.log("[tools] insert_script_to_sqlite", list);
|
||||
await u.db("o_assets").insert(
|
||||
list.map((i) => ({
|
||||
name: i.name,
|
||||
prompt: i.prompt,
|
||||
type: i.type,
|
||||
describe: i.desc,
|
||||
projectId: resTool.data.projectId,
|
||||
state: "未生成",
|
||||
})),
|
||||
);
|
||||
execute: async ({ assetsList, script }) => {
|
||||
console.log("%c Line:103 🍷 script", "background:#42b983", script);
|
||||
console.log("[tools] insert_script_to_sqlite", assetsList);
|
||||
const [scriptId] = await u.db("o_script").insert({
|
||||
name: script.name,
|
||||
content: script.content,
|
||||
projectId: resTool.data.projectId,
|
||||
createTime: Date.now(),
|
||||
});
|
||||
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;
|
||||
},
|
||||
}),
|
||||
|
||||
@ -281,10 +281,9 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
||||
table.text("describe");
|
||||
table.integer("scriptId"); //剧本id
|
||||
table.integer("imageId").unsigned().references("id").inTable("o_image");
|
||||
table.integer("sonId");
|
||||
table.integer("assetsId");
|
||||
table.integer("projectId");
|
||||
table.integer("startTime");
|
||||
table.text("state");
|
||||
table.primary(["id"]);
|
||||
table.unique(["id"]);
|
||||
},
|
||||
|
||||
@ -7,26 +7,26 @@ const router = express.Router();
|
||||
|
||||
// 新增资产
|
||||
export default router.post(
|
||||
"/",
|
||||
validateFields({
|
||||
name: z.string(),
|
||||
describe: z.string(),
|
||||
type: z.string(),
|
||||
projectId: z.number(),
|
||||
remark: z.string(),
|
||||
prompt: z.string().optional().nullable(),
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { name, describe, type, projectId, remark, prompt } = req.body;
|
||||
await u.db("o_assets").insert({
|
||||
name,
|
||||
describe,
|
||||
type,
|
||||
projectId,
|
||||
remark,
|
||||
prompt,
|
||||
startTime: Date.now(),
|
||||
});
|
||||
res.status(200).send(success({ message: "新增资产成功" }));
|
||||
},
|
||||
"/",
|
||||
validateFields({
|
||||
name: z.string(),
|
||||
describe: z.string(),
|
||||
type: z.string(),
|
||||
projectId: z.number(),
|
||||
remark: z.string(),
|
||||
prompt: z.string().optional().nullable(),
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { name, describe, type, projectId, remark, prompt } = req.body;
|
||||
await u.db("o_assets").insert({
|
||||
name,
|
||||
describe,
|
||||
type,
|
||||
projectId,
|
||||
remark,
|
||||
prompt,
|
||||
startTime: Date.now(),
|
||||
});
|
||||
res.status(200).send(success({ message: "新增资产成功" }));
|
||||
},
|
||||
);
|
||||
|
||||
@ -8,13 +8,13 @@ const router = express.Router();
|
||||
|
||||
// 批量删除资产
|
||||
export default router.post(
|
||||
"/",
|
||||
validateFields({
|
||||
id: z.array(z.number()),
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { id } = req.body;
|
||||
await u.db("o_assets").whereIn("id", id).delete();
|
||||
res.status(200).send(success({ message: "删除资产成功" }));
|
||||
},
|
||||
"/",
|
||||
validateFields({
|
||||
id: z.array(z.number()),
|
||||
}),
|
||||
async (req, res) => {
|
||||
const { id } = req.body;
|
||||
await u.db("o_assets").whereIn("id", id).delete();
|
||||
res.status(200).send(success({ message: "删除资产成功" }));
|
||||
},
|
||||
);
|
||||
|
||||
@ -28,7 +28,7 @@ export default router.post(
|
||||
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
|
||||
@ -37,7 +37,7 @@ export default router.post(
|
||||
.select("o_assets.*", "o_image.filePath")
|
||||
.where("o_assets.projectId", projectId)
|
||||
.andWhere("o_assets.type", type)
|
||||
.whereNotNull("o_assets.sonId");
|
||||
.whereNotNull("o_assets.assetId");
|
||||
if (name) {
|
||||
childQuery = childQuery.andWhere("o_assets.name", "like", `%${name}%`);
|
||||
}
|
||||
@ -47,8 +47,8 @@ export default router.post(
|
||||
const result = await Promise.all(
|
||||
parentAssets.map(async (parent) => ({
|
||||
...parent,
|
||||
sonAssets: childAssets.filter((child) => child.sonId === parent.id),
|
||||
filePath: parent.filePath && (await u.oss.getFileUrl(parent.filePath!)),
|
||||
sonAssets: childAssets.filter((child) => child.assetId === parent.id),
|
||||
src: parent.filePath && (await u.oss.getFileUrl(parent.filePath!)),
|
||||
})),
|
||||
);
|
||||
|
||||
@ -57,7 +57,7 @@ export default router.post(
|
||||
.db("o_assets")
|
||||
.where("projectId", projectId)
|
||||
.andWhere("type", type)
|
||||
.andWhere("sonId", null)
|
||||
.andWhere("assetId", null)
|
||||
.andWhere((qb) => {
|
||||
if (name) {
|
||||
qb.andWhere("name", "like", `%${name}%`);
|
||||
|
||||
@ -36,15 +36,21 @@ export default router.post(
|
||||
state: "生成成功",
|
||||
});
|
||||
// 更新资产表图片为新图片
|
||||
await u.db("o_assets").where("id", id).update({
|
||||
prompt: prompt ?? "",
|
||||
imageId: idData,
|
||||
});
|
||||
await u
|
||||
.db("o_assets")
|
||||
.where("id", id)
|
||||
.update({
|
||||
prompt: prompt ?? "",
|
||||
imageId: idData,
|
||||
});
|
||||
} else {
|
||||
await u.db("o_assets").where("id", id).update({
|
||||
prompt: prompt ?? "",
|
||||
imageId: imageId,
|
||||
});
|
||||
await u
|
||||
.db("o_assets")
|
||||
.where("id", id)
|
||||
.update({
|
||||
prompt: prompt ?? "",
|
||||
imageId: imageId,
|
||||
});
|
||||
}
|
||||
res.status(200).send(success({ message: "保存资产图片成功" }));
|
||||
},
|
||||
|
||||
@ -13,10 +13,9 @@ export default router.post(
|
||||
}),
|
||||
async (req, res) => {
|
||||
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 parnetIdsMap: Record<number, number> = {};
|
||||
const sonAssetsData = await u.db("o_assets").whereIn("sonId", parentIds);
|
||||
const sonAssetsData = await u.db("o_assets").whereIn("assetsId", parentIds);
|
||||
const sonAssetsMap: Record<number, o_assets[]> = {};
|
||||
|
||||
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;
|
||||
});
|
||||
sonAssetsData.forEach((i) => {
|
||||
if (!sonAssetsMap[i.sonId!]) {
|
||||
sonAssetsMap[i.sonId!] = [];
|
||||
if (!sonAssetsMap[i.assetsId!]) {
|
||||
sonAssetsMap[i.assetsId!] = [];
|
||||
}
|
||||
const obj = {
|
||||
assetsId: i.id,
|
||||
@ -44,7 +43,7 @@ export default router.post(
|
||||
src: imageUrlMap[i.imageId!] ?? null,
|
||||
derive: sonAssetsMap[i.id!] ?? [],
|
||||
};
|
||||
sonAssetsMap[i.sonId!].push(obj);
|
||||
sonAssetsMap[i.assetsId!].push(obj);
|
||||
});
|
||||
const returnData = parentAssetsData.map((i) => {
|
||||
return {
|
||||
|
||||
@ -28,7 +28,7 @@ export default router.post(
|
||||
.leftJoin("o_image", "o_assets.imageId", "o_image.id")
|
||||
.select("o_assets.*", "o_image.filePath")
|
||||
.where("o_assets.projectId", projectId)
|
||||
.whereNotNull("o_assets.sonId");
|
||||
.whereNotNull("o_assets.assetId");
|
||||
|
||||
if (!sqlData) {
|
||||
const flowData: FlowData = {
|
||||
@ -42,7 +42,7 @@ export default router.post(
|
||||
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
||||
derive: await Promise.all(
|
||||
childAssetsData
|
||||
.filter((child) => child.sonId === item.id)
|
||||
.filter((child) => child.assetId === item.id)
|
||||
.map(async (child) => ({
|
||||
id: child.id,
|
||||
assetsId: item.id,
|
||||
|
||||
47
src/types/database.d.ts
vendored
47
src/types/database.d.ts
vendored
@ -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 {
|
||||
'content': string;
|
||||
'createTime': number;
|
||||
@ -37,6 +76,7 @@ export interface o_artStyle {
|
||||
'styles'?: string | null;
|
||||
}
|
||||
export interface o_assets {
|
||||
'assetsId'?: number | null;
|
||||
'describe'?: string | null;
|
||||
'id'?: number;
|
||||
'imageId'?: number | null;
|
||||
@ -45,7 +85,6 @@ export interface o_assets {
|
||||
'prompt'?: string | null;
|
||||
'remark'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sonId'?: number | null;
|
||||
'startTime'?: number | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
@ -88,6 +127,7 @@ export interface o_novel {
|
||||
'chapterData'?: string | null;
|
||||
'chapterIndex'?: number | null;
|
||||
'createTime'?: number | null;
|
||||
'errorReason'?: string | null;
|
||||
'event'?: string | null;
|
||||
'eventState'?: number | null;
|
||||
'id'?: number;
|
||||
@ -204,6 +244,9 @@ export interface o_videoConfig {
|
||||
}
|
||||
|
||||
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;
|
||||
"o_agentDeploy": o_agentDeploy;
|
||||
"o_agentWorkData": o_agentWorkData;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user