feat: add flow edit
This commit is contained in:
		| @@ -31,7 +31,9 @@ app | |||||||
|     key: 'list', |     key: 'list', | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     ctx.body = await PageModel.findAll(); |     ctx.body = await PageModel.findAll({ | ||||||
|  |       order: [['updatedAt', 'DESC']], | ||||||
|  |     }); | ||||||
|     return ctx; |     return ctx; | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
| @@ -42,25 +44,65 @@ app | |||||||
|     key: 'update', |     key: 'update', | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     const { data, id, ...rest } = ctx.query.data; |     const { data, id, title, type, description } = ctx.query.data; | ||||||
|     if (id) { |     if (id) { | ||||||
|       const page = await PageModel.findByPk(id); |       const page = await PageModel.findByPk(id); | ||||||
|       if (page) { |       if (page) { | ||||||
|         const newPage = await page.update({ data: data, ...rest }); |         const newPage = await page.update({ data: data, title, type, description }); | ||||||
|         ctx.body = newPage; |         ctx.body = newPage; | ||||||
|  |       } else { | ||||||
|  |         throw new CustomError('page not found'); | ||||||
|       } |       } | ||||||
|     } else if (data) { |     } else if (data) { | ||||||
|       const page = await PageModel.create({ data, ...rest }); |       const page = await PageModel.create({ data, title, type, description }); | ||||||
|       ctx.body = page; |       ctx.body = page; | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .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 | app | ||||||
|   .route({ |   .route({ | ||||||
|     path: 'page', |     path: 'page', | ||||||
|     key: 'delete', |     key: 'delete', | ||||||
|   }) |   }) | ||||||
|  |   .define({ | ||||||
|  |     validator: { | ||||||
|  |       id: { | ||||||
|  |         required: true, | ||||||
|  |         type: 'string', | ||||||
|  |       }, | ||||||
|  |     }, | ||||||
|  |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     const id = ctx.query.id; |     const id = ctx.query.id; | ||||||
|     const page = await PageModel.findByPk(id); |     const page = await PageModel.findByPk(id); | ||||||
|   | |||||||
| @@ -3,15 +3,20 @@ import { Prompt } from '@/models/prompt.ts'; | |||||||
| import { chat } from '@/modules/ollama.ts'; | import { chat } from '@/modules/ollama.ts'; | ||||||
| import { CustomError } from '@abearxiong/router'; | import { CustomError } from '@abearxiong/router'; | ||||||
| import { PromptTemplate } from '@kevisual/ai-graph'; | import { PromptTemplate } from '@kevisual/ai-graph'; | ||||||
|  | import { v4 } from 'uuid'; | ||||||
| app | app | ||||||
|   .route('ai', 'run', { nextRoute: { id: 'runOllama' } }) |   .route('ai', 'run', { nextRoute: { id: 'runOllama' } }) | ||||||
|   .define({ |   .define({ | ||||||
|     validator: { |     validator: { | ||||||
|       key: { |       data: { | ||||||
|         type: 'string', |         type: 'object', | ||||||
|         required: true, |         properties: { | ||||||
|         message: 'Prompt key is required', |           key: { | ||||||
|  |             type: 'string', | ||||||
|  |             required: true, | ||||||
|  |             message: 'Prompt key is required', | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|       }, |       }, | ||||||
|     }, |     }, | ||||||
|   }) |   }) | ||||||
| @@ -23,6 +28,7 @@ app | |||||||
|       throw new CustomError('Prompt key is required'); |       throw new CustomError('Prompt key is required'); | ||||||
|     } |     } | ||||||
|     const prompt = await Prompt.findOne({ where: { key } }); |     const prompt = await Prompt.findOne({ where: { key } }); | ||||||
|  |     console.log('prompt', 'key', key, prompt); | ||||||
|     if (!prompt) { |     if (!prompt) { | ||||||
|       throw new CustomError('Prompt not found'); |       throw new CustomError('Prompt not found'); | ||||||
|     } |     } | ||||||
| @@ -54,16 +60,16 @@ app | |||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|     const prompt = ctx.state.prompt; |     const prompt = ctx.state.prompt; | ||||||
|  |     const uuid = v4(); | ||||||
|     if (!prompt) { |     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([ |     const res = await chat([ | ||||||
|       { |       { | ||||||
|         role: 'user', |         role: 'user', | ||||||
|         content: prompt, |         content: prompt, | ||||||
|       }, |       }, | ||||||
|     ]); |     ]); | ||||||
|     ctx.body = res; |     ctx.body = { id: uuid, ...res }; | ||||||
|   }) |   }) | ||||||
|   .addTo(app); |   .addTo(app); | ||||||
|   | |||||||
| @@ -48,11 +48,19 @@ module.exports = { | |||||||
|           loader: 'ts-loader', |           loader: 'ts-loader', | ||||||
|           options: { |           options: { | ||||||
|             allowTsInNodeModules: true, |             allowTsInNodeModules: true, | ||||||
|  |             transpileOnly: true, // 可选,加快构建速度 | ||||||
|           }, |           }, | ||||||
|         }, |         }, | ||||||
|       }, |       }, | ||||||
|     ], |     ], | ||||||
|   }, |   }, | ||||||
|  |   // 忽略特定警告 | ||||||
|  |   ignoreWarnings: [ | ||||||
|  |     { | ||||||
|  |       message: /Critical dependency: the request of a dependency is an expression/, | ||||||
|  |     }, | ||||||
|  |   ], | ||||||
|  |  | ||||||
|   resolve: { |   resolve: { | ||||||
|     extensions: ['.ts', '.js'], |     extensions: ['.ts', '.js'], | ||||||
|     alias: { |     alias: { | ||||||
| @@ -60,9 +68,7 @@ module.exports = { | |||||||
|       hexoid: 'hexoid/dist/index.js', |       hexoid: 'hexoid/dist/index.js', | ||||||
|     }, |     }, | ||||||
|   }, |   }, | ||||||
|   // externals: [ |  | ||||||
|   //   // nodeExternals(), |  | ||||||
|   // ], |  | ||||||
|   externals: { |   externals: { | ||||||
|     sequelize: 'commonjs sequelize', |     sequelize: 'commonjs sequelize', | ||||||
|     'socket.io': 'commonjs socket.io', |     'socket.io': 'commonjs socket.io', | ||||||
| @@ -73,5 +79,8 @@ module.exports = { | |||||||
|   node: {}, |   node: {}, | ||||||
|   stats: { |   stats: { | ||||||
|     errorDetails: true, |     errorDetails: true, | ||||||
|  |     all: false, | ||||||
|  |     errors: true, | ||||||
|  |     warnings: true, | ||||||
|   }, |   }, | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user