修正表名,去掉冗余表

This commit is contained in:
ACT丶流星雨 2026-03-19 20:00:24 +08:00
parent 25c3194e5e
commit 1f6c000664
9 changed files with 84 additions and 135 deletions

View File

@ -48,20 +48,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
initData: async (knex) => { initData: async (knex) => {},
},
},
//技能表
{
name: "o_skills",
builder: (table) => {
table.integer("id").notNullable();
table.string("name");
table.integer("startTime");
table.primary(["id"]);
table.unique(["id"]);
},
initData: async (knex) => { },
}, },
//Agent配置表 //Agent配置表
{ {
@ -167,64 +154,9 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
]); ]);
}, },
}, },
//模型表
{
name: "o_model",
builder: (table) => {
table.integer("id").notNullable();
table.text("type");
table.text("model");
table.text("modelType");
table.text("apiKey");
table.text("baseUrl");
table.text("manufacturer");
table.integer("createTime");
table.integer("index");
table.primary(["id"]);
table.unique(["id"]);
},
initData: async (knex) => { },
},
//提示词表
{
name: "o_prompts",
builder: (table) => {
table.integer("id").notNullable();
table.text("code"); // 代号,唯一标识
table.text("name"); // 名称/描述
table.text("type"); // 类型mainAgent/subAgent/system
table.text("parentCode"); // 父级代号subAgent关联主agent
table.text("defaultValue"); // 默认提示词
table.text("customValue"); // 自定义修改值
table.primary(["id"]);
table.unique(["id"]);
table.unique(["code"]); // 代号唯一
},
initData: async (knex) => { },
},
//资产表
{
name: "o_assets",
builder: (table) => {
table.integer("id").notNullable();
table.text("name");
table.text("prompt");
table.text("remark");
table.text("type");
table.text("describe");
table.integer("imageId").unsigned().references("id").inTable("o_image");
table.integer("sonId");
table.integer("projectId");
table.integer("startTime");
table.text("state");
table.primary(["id"]);
table.unique(["id"]);
},
initData: async (knex) => { },
},
//任务中心表 //任务中心表
{ {
name: "o_myTasks", name: "o_tasks",
builder: (table) => { builder: (table) => {
table.integer("id").notNullable(); table.integer("id").notNullable();
table.integer("projectId"); table.integer("projectId");
@ -238,7 +170,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
initData: async (knex) => { }, initData: async (knex) => {},
}, },
//小说原文表 //小说原文表
{ {
@ -314,24 +246,38 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.unique(["id"]); table.unique(["id"]);
}, },
}, },
//剧本-大纲 //资产表
{ {
name: "o_scriptOutline", name: "o_assets",
builder: (table) => { builder: (table) => {
table.integer("id").notNullable(); table.integer("id").notNullable();
table.integer("scriptId").unsigned().references("id").inTable("o_script"); table.text("name");
table.integer("outlineId").unsigned().references("id").inTable("o_outline"); table.text("prompt");
table.text("remark");
table.text("type");
table.text("describe");
table.integer("imageId").unsigned().references("id").inTable("o_image");
table.integer("sonId");
table.integer("projectId");
table.integer("startTime");
table.text("state");
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
initData: async (knex) => {},
}, },
//剧本-资产 //生成图片表
{ {
name: "o_scriptAssets", name: "o_image",
builder: (table) => { builder: (table) => {
table.integer("id").notNullable(); table.integer("id").notNullable();
table.integer("assetsId").unsigned().references("id").inTable("o_assets"); table.text("filePath");
table.integer("scriptId").unsigned().references("id").inTable("o_script"); table.text("type");
table.integer("assetsId");
table.integer("scriptId");
table.integer("projectId");
table.integer("videoId");
table.text("state");
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
@ -347,13 +293,13 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.unique(["id"]); table.unique(["id"]);
}, },
}, },
//分镜-剧本 //flowData-剧本
{ {
name: "o_storyboardScript", name: "o_flowData",
builder: (table) => { builder: (table) => {
table.integer("id").notNullable(); table.integer("id").notNullable();
table.integer("storyboardId").unsigned().references("id").inTable("o_storyboard"); table.string("name");
table.integer("scriptId").unsigned().references("id").inTable("o_script"); table.integer("createTime");
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
@ -378,19 +324,6 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.unique(["id"]); table.unique(["id"]);
}, },
}, },
//聊天记录
{
name: "o_chatHistory",
builder: (table) => {
table.integer("id").notNullable();
table.text("type");
table.text("data");
table.text("novel");
table.integer("projectId");
table.primary(["id"]);
table.unique(["id"]);
},
},
//视频配置 //视频配置
{ {
name: "o_videoConfig", name: "o_videoConfig",
@ -415,18 +348,19 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.unique(["id"]); table.unique(["id"]);
}, },
}, },
//生成图片 //供应商配置
{ {
name: "o_image", name: "o_vendorConfig",
builder: (table) => { builder: (table) => {
table.integer("id").notNullable(); table.integer("id").notNullable();
table.text("filePath"); table.text("name");
table.text("type"); table.text("version");
table.integer("assetsId"); table.text("icon");
table.integer("scriptId"); table.text("inputs"); // 输入项配置 JSON
table.integer("projectId"); table.text("inputValues"); // 输入项值 JSON
table.integer("videoId"); table.text("models"); // 模型配置 JSON
table.text("state"); table.text("code"); // 模型配置 JSON
table.integer("createTime");
table.primary(["id"]); table.primary(["id"]);
table.unique(["id"]); table.unique(["id"]);
}, },
@ -460,7 +394,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
table.text("embedding"); // 向量嵌入 JSON table.text("embedding"); // 向量嵌入 JSON
table.text("relatedMessageIds"); // summary关联的message id列表 JSON table.text("relatedMessageIds"); // summary关联的message id列表 JSON
table.integer("summarized").defaultTo(0); // message是否已被总结 0/1 table.integer("summarized").defaultTo(0); // message是否已被总结 0/1
table.integer("createdAt").notNullable(); table.integer("createTime").notNullable();
table.primary(["id"]); table.primary(["id"]);
table.index(["isolationKey", "type"]); table.index(["isolationKey", "type"]);
table.index(["isolationKey", "summarized"]); table.index(["isolationKey", "summarized"]);

View File

@ -18,14 +18,14 @@ export default router.post(
const rows = await u const rows = await u
.db("memories") .db("memories")
.where({ isolationKey, type: "message" }) .where({ isolationKey, type: "message" })
.orderBy("createdAt", "asc") .orderBy("createTime", "asc")
.select("id", "content", "createdAt"); .select("id", "content", "createTime");
const history = rows.map((row) => ({ const history = rows.map((row) => ({
id: row.id, id: row.id,
role: "user", role: "user",
content: [{ type: "text", status: "complete", data: row.content }], content: [{ type: "text", status: "complete", data: row.content }],
createdAt: row.createdAt, createTime: row.createTime,
})); }));
res.status(200).send(success({ history })); res.status(200).send(success({ history }));

View File

@ -26,7 +26,7 @@ export default router.post(
await u.db("o_project").where("id", id).delete(); await u.db("o_project").where("id", id).delete();
await u.db("o_novel").where("projectId", id).delete(); await u.db("o_novel").where("projectId", id).delete();
await u.db("o_outline").where("projectId", id).delete(); await u.db("o_outline").where("projectId", id).delete();
await u.db("o_myTasks").where("projectId", id).delete(); await u.db("o_tasks").where("projectId", id).delete();
await u.db("o_script").where("projectId", id).delete(); await u.db("o_script").where("projectId", id).delete();
await u.db("o_assets").where("projectId", id).delete(); await u.db("o_assets").where("projectId", id).delete();
@ -45,8 +45,6 @@ export default router.post(
await u.db("o_video").whereIn("scriptId", scriptIds).delete(); await u.db("o_video").whereIn("scriptId", scriptIds).delete();
await u.db("o_chatHistory").where("projectId", id).delete();
try { try {
await u.oss.deleteDirectory(`${id}/`); await u.oss.deleteDirectory(`${id}/`);
console.log(`项目 ${id} 的OSS文件夹删除成功`); console.log(`项目 ${id} 的OSS文件夹删除成功`);

View File

@ -16,27 +16,27 @@ export default router.post(
const { taskClass, state, page = 1, limit = 10 }: any = req.body; const { taskClass, state, page = 1, limit = 10 }: any = req.body;
const offset = (page - 1) * limit; const offset = (page - 1) * limit;
const data = await u const data = await u
.db("o_myTasks") .db("o_tasks")
.leftJoin("o_project", "o_project.id", "o_myTasks.projectId") .leftJoin("o_project", "o_project.id", "o_tasks.projectId")
.andWhere((qb) => { .andWhere((qb) => {
if (taskClass) { if (taskClass) {
qb.andWhere("o_myTasks.taskClass", taskClass); qb.andWhere("o_tasks.taskClass", taskClass);
} }
if (state) { if (state) {
qb.andWhere("o_myTasks.state", state); qb.andWhere("o_tasks.state", state);
} }
}) })
.select("o_myTasks.*", "o_project.* ") .select("o_tasks.*", "o_project.* ")
.offset(offset) .offset(offset)
.limit(limit); .limit(limit);
const totalQuery = (await u const totalQuery = (await u
.db("o_myTasks") .db("o_tasks")
.andWhere((qb) => { .andWhere((qb) => {
if (taskClass) { if (taskClass) {
qb.andWhere("o_myTasks.taskClass", taskClass); qb.andWhere("o_tasks.taskClass", taskClass);
} }
if (state) { if (state) {
qb.andWhere("o_myTasks.state", state); qb.andWhere("o_tasks.state", state);
} }
}) })
.count("* as total") .count("* as total")

View File

@ -11,7 +11,7 @@ export default router.post(
projectId: z.number(), projectId: z.number(),
}), }),
async (req, res) => { async (req, res) => {
const data = await u.db("o_myTasks").where("projectId", req.body.projectId).select("taskClass").groupBy("taskClass"); const data = await u.db("o_tasks").where("projectId", req.body.projectId).select("taskClass").groupBy("taskClass");
res.status(200).send(success(data)); res.status(200).send(success(data));
}, },
); );

View File

@ -12,7 +12,7 @@ export default router.post(
}), }),
async (req, res) => { async (req, res) => {
const { taskId } = req.body; const { taskId } = req.body;
const data = await u.db("o_myTasks").where("id", taskId).select("*").first(); const data = await u.db("o_tasks").where("id", taskId).select("*").first();
res.status(200).send(success(data)); res.status(200).send(success(data));
} }
); );

View File

@ -1,4 +1,4 @@
// @db-hash ad26ece2cf8002d48518ba2b8cd908f8 // @db-hash 2f9e6a9e9145cead00652858cafb9159
//该文件由脚本自动生成,请勿手动修改 //该文件由脚本自动生成,请勿手动修改
export interface memories { export interface memories {
@ -58,6 +58,11 @@ export interface o_eventChapter {
'id'?: number; 'id'?: number;
'novelId'?: number | null; 'novelId'?: number | null;
} }
export interface o_flowData {
'createTime'?: number | null;
'id'?: number;
'name'?: string | null;
}
export interface o_image { export interface o_image {
'assetsId'?: number | null; 'assetsId'?: number | null;
'filePath'?: string | null; 'filePath'?: string | null;
@ -166,6 +171,17 @@ export interface o_storyboardScript {
'scriptId'?: number | null; 'scriptId'?: number | null;
'storyboardId'?: number | null; 'storyboardId'?: number | null;
} }
export interface o_tasks {
'describe'?: string | null;
'id'?: number;
'model'?: string | null;
'projectId'?: number | null;
'reason'?: string | null;
'relatedObjects'?: string | null;
'startTime'?: number | null;
'state'?: string | null;
'taskClass'?: string | null;
}
export interface o_user { export interface o_user {
'id'?: number; 'id'?: number;
'name'?: string | null; 'name'?: string | null;
@ -223,6 +239,7 @@ export interface DB {
"o_chatHistory": o_chatHistory; "o_chatHistory": o_chatHistory;
"o_event": o_event; "o_event": o_event;
"o_eventChapter": o_eventChapter; "o_eventChapter": o_eventChapter;
"o_flowData": o_flowData;
"o_image": o_image; "o_image": o_image;
"o_model": o_model; "o_model": o_model;
"o_myTasks": o_myTasks; "o_myTasks": o_myTasks;
@ -238,6 +255,7 @@ export interface DB {
"o_skills": o_skills; "o_skills": o_skills;
"o_storyboard": o_storyboard; "o_storyboard": o_storyboard;
"o_storyboardScript": o_storyboardScript; "o_storyboardScript": o_storyboardScript;
"o_tasks": o_tasks;
"o_user": o_user; "o_user": o_user;
"o_vendorConfig": o_vendorConfig; "o_vendorConfig": o_vendorConfig;
"o_video": o_video; "o_video": o_video;

View File

@ -58,7 +58,6 @@ class Memory {
async add( role: string = "user",content: string) { async add( role: string = "user",content: string) {
const id = uuidv4(); const id = uuidv4();
const embedding = await getEmbedding(content); const embedding = await getEmbedding(content);
const now = Date.now();
const isolationKey = this.isolationKey; const isolationKey = this.isolationKey;
await u.db("memories").insert({ await u.db("memories").insert({
@ -70,11 +69,11 @@ class Memory {
embedding: JSON.stringify(embedding), embedding: JSON.stringify(embedding),
relatedMessageIds: null, relatedMessageIds: null,
summarized: 0, summarized: 0,
createdAt: now, createTime: Date.now(),
} as any); } as any);
// 检查未总结消息数量 // 检查未总结消息数量
const unsummarized = await u.db("memories").where({ isolationKey, type: "message", summarized: 0 }).orderBy("createdAt", "asc"); const unsummarized = await u.db("memories").where({ isolationKey, type: "message", summarized: 0 }).orderBy("createTime", "asc");
if (unsummarized.length >= messagesPerSummary) { if (unsummarized.length >= messagesPerSummary) {
const batch = unsummarized.slice(0, messagesPerSummary); const batch = unsummarized.slice(0, messagesPerSummary);
@ -93,7 +92,7 @@ class Memory {
embedding: JSON.stringify(summaryEmbedding), embedding: JSON.stringify(summaryEmbedding),
relatedMessageIds: JSON.stringify(batchIds), relatedMessageIds: JSON.stringify(batchIds),
summarized: 0, summarized: 0,
createdAt: Date.now(), createTime: Date.now(),
}); });
// 标记已总结 // 标记已总结
@ -107,12 +106,12 @@ class Memory {
const shortTerm = await u const shortTerm = await u
.db("memories") .db("memories")
.where({ isolationKey, type: "message", summarized: 0 }) .where({ isolationKey, type: "message", summarized: 0 })
.orderBy("createdAt", "desc") .orderBy("createTime", "desc")
.limit(shortTermLimit); .limit(shortTermLimit);
shortTerm.reverse(); // 最旧在前 shortTerm.reverse(); // 最旧在前
// summaries: 最近的 summary // summaries: 最近的 summary
const summaries = await u.db("memories").where({ isolationKey, type: "summary" }).orderBy("createdAt", "desc").limit(summaryLimit); const summaries = await u.db("memories").where({ isolationKey, type: "summary" }).orderBy("createTime", "desc").limit(summaryLimit);
summaries.reverse(); summaries.reverse();
// rag: 向量搜索所有 messages // rag: 向量搜索所有 messages
@ -121,12 +120,12 @@ class Memory {
const ragResults = vectorSearch(allMessages, queryEmbedding, ragLimit); const ragResults = vectorSearch(allMessages, queryEmbedding, ragLimit);
return { return {
shortTerm: shortTerm.map((m: any) => ({ id: m.id, role: m.role, content: m.content, createdAt: m.createdAt })), shortTerm: shortTerm.map((m: any) => ({ id: m.id, role: m.role, content: m.content, createTime: m.createTime })),
summaries: summaries.map((s) => ({ summaries: summaries.map((s) => ({
id: s.id, id: s.id,
content: s.content, content: s.content,
relatedMessageIds: JSON.parse(s.relatedMessageIds || "[]"), relatedMessageIds: JSON.parse(s.relatedMessageIds || "[]"),
createdAt: s.createdAt, createTime: s.createTime,
})), })),
rag: ragResults.map((r) => ({ id: r.id, content: r.content, similarity: r.similarity })), rag: ragResults.map((r) => ({ id: r.id, content: r.content, similarity: r.similarity })),
}; };
@ -155,9 +154,9 @@ class Memory {
if (messageIds.length === 0) return []; if (messageIds.length === 0) return [];
const messages = await u.db("memories").whereIn("id", messageIds).orderBy("createdAt", "asc"); const messages = await u.db("memories").whereIn("id", messageIds).orderBy("createTime", "asc");
return messages.map((m) => ({ id: m.id, content: m.content, createdAt: m.createdAt })); return messages.map((m) => ({ id: m.id, content: m.content, createTime: m.createTime }));
} }
getTools() { getTools() {

View File

@ -38,7 +38,7 @@ export default async function taskRecord(
} }
} }
const [id] = await db("o_myTasks").insert({ const [id] = await db("o_tasks").insert({
projectId, projectId,
taskClass, taskClass,
relatedObjects: opteorContent, relatedObjects: opteorContent,
@ -50,7 +50,7 @@ export default async function taskRecord(
/** 任务成功时调用 done(1),失败时调用 done(-1, '原因') */ /** 任务成功时调用 done(1),失败时调用 done(-1, '原因') */
return async function done(state: 1 | -1, reason?: string) { return async function done(state: 1 | -1, reason?: string) {
await db("o_myTasks") await db("o_tasks")
.where("id", id) .where("id", id)
.update({ .update({
state: taskStateMap[state], state: taskStateMap[state],