diff --git a/src/routes/page/list.ts b/src/routes/page/list.ts index 7c7b2fa..0371761 100644 --- a/src/routes/page/list.ts +++ b/src/routes/page/list.ts @@ -31,7 +31,9 @@ app key: 'list', }) .define(async (ctx) => { - ctx.body = await PageModel.findAll(); + ctx.body = await PageModel.findAll({ + order: [['updatedAt', 'DESC']], + }); return ctx; }) .addTo(app); @@ -42,25 +44,65 @@ app key: 'update', }) .define(async (ctx) => { - const { data, id, ...rest } = ctx.query.data; + const { data, id, title, type, description } = ctx.query.data; if (id) { const page = await PageModel.findByPk(id); if (page) { - const newPage = await page.update({ data: data, ...rest }); + const newPage = await page.update({ data: data, title, type, description }); ctx.body = newPage; + } else { + throw new CustomError('page not found'); } } else if (data) { - const page = await PageModel.create({ data, ...rest }); + const page = await PageModel.create({ data, title, type, description }); ctx.body = page; } }) .addTo(app); +app + .route('page', 'updateNode') + .define(async (ctx) => { + const { id, nodeData } = ctx.query.data; + if (!id) { + throw new CustomError('id is required'); + } + const page = await PageModel.findByPk(id); + if (!page) { + throw new CustomError('page not found'); + } + const { data } = page; + const { nodes = [] } = data; + let flag = false; + const newNodes = nodes.map((item) => { + if (item.id === nodeData.id) { + flag = true; + return nodeData; + } + return item; + }); + if (!flag) { + newNodes.push(nodeData); + } + const newData = { ...data, nodes: newNodes }; + const newPage = await page.update({ data: newData }); + ctx.body = newPage; + return ctx; + }) + .addTo(app); app .route({ path: 'page', key: 'delete', }) + .define({ + validator: { + id: { + required: true, + type: 'string', + }, + }, + }) .define(async (ctx) => { const id = ctx.query.id; const page = await PageModel.findByPk(id); diff --git a/src/routes/prompt-graph/ai.ts b/src/routes/prompt-graph/ai.ts index b523e4f..8e3a201 100644 --- a/src/routes/prompt-graph/ai.ts +++ b/src/routes/prompt-graph/ai.ts @@ -3,15 +3,20 @@ import { Prompt } from '@/models/prompt.ts'; import { chat } from '@/modules/ollama.ts'; import { CustomError } from '@abearxiong/router'; import { PromptTemplate } from '@kevisual/ai-graph'; - +import { v4 } from 'uuid'; app .route('ai', 'run', { nextRoute: { id: 'runOllama' } }) .define({ validator: { - key: { - type: 'string', - required: true, - message: 'Prompt key is required', + data: { + type: 'object', + properties: { + key: { + type: 'string', + required: true, + message: 'Prompt key is required', + }, + }, }, }, }) @@ -23,6 +28,7 @@ app throw new CustomError('Prompt key is required'); } const prompt = await Prompt.findOne({ where: { key } }); + console.log('prompt', 'key', key, prompt); if (!prompt) { throw new CustomError('Prompt not found'); } @@ -54,16 +60,16 @@ app }) .define(async (ctx) => { const prompt = ctx.state.prompt; + const uuid = v4(); if (!prompt) { - throw new CustomError('Prompt not found'); + throw new CustomError('Prompt Template not found'); } - console.log('prompt', typeof prompt, prompt); const res = await chat([ { role: 'user', content: prompt, }, ]); - ctx.body = res; + ctx.body = { id: uuid, ...res }; }) .addTo(app); diff --git a/webpack.config.cjs b/webpack.config.cjs index fc653d0..c46e085 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -48,11 +48,19 @@ module.exports = { loader: 'ts-loader', options: { allowTsInNodeModules: true, + transpileOnly: true, // 可选,加快构建速度 }, }, }, ], }, + // 忽略特定警告 + ignoreWarnings: [ + { + message: /Critical dependency: the request of a dependency is an expression/, + }, + ], + resolve: { extensions: ['.ts', '.js'], alias: { @@ -60,9 +68,7 @@ module.exports = { hexoid: 'hexoid/dist/index.js', }, }, - // externals: [ - // // nodeExternals(), - // ], + externals: { sequelize: 'commonjs sequelize', 'socket.io': 'commonjs socket.io', @@ -73,5 +79,8 @@ module.exports = { node: {}, stats: { errorDetails: true, + all: false, + errors: true, + warnings: true, }, };