暂存
This commit is contained in:
		| @@ -31,7 +31,7 @@ | |||||||
|   ], |   ], | ||||||
|   "license": "ISC", |   "license": "ISC", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@abearxiong/auth": "1.0.0-alpha.5", |     "@abearxiong/auth": "1.0.1", | ||||||
|     "@abearxiong/router": "0.0.1-alpha.38", |     "@abearxiong/router": "0.0.1-alpha.38", | ||||||
|     "@abearxiong/use-config": "^0.0.2", |     "@abearxiong/use-config": "^0.0.2", | ||||||
|     "@babel/core": "^7.25.2", |     "@babel/core": "^7.25.2", | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							| @@ -14,8 +14,8 @@ importers: | |||||||
|   .: |   .: | ||||||
|     dependencies: |     dependencies: | ||||||
|       '@abearxiong/auth': |       '@abearxiong/auth': | ||||||
|         specifier: 1.0.0-alpha.5 |         specifier: 1.0.1 | ||||||
|         version: 1.0.0-alpha.5(@abearxiong/router@0.0.1-alpha.38) |         version: 1.0.1(@abearxiong/router@0.0.1-alpha.38) | ||||||
|       '@abearxiong/router': |       '@abearxiong/router': | ||||||
|         specifier: 0.0.1-alpha.38 |         specifier: 0.0.1-alpha.38 | ||||||
|         version: 0.0.1-alpha.38 |         version: 0.0.1-alpha.38 | ||||||
| @@ -222,8 +222,8 @@ importers: | |||||||
|  |  | ||||||
| packages: | packages: | ||||||
|  |  | ||||||
|   '@abearxiong/auth@1.0.0-alpha.5': |   '@abearxiong/auth@1.0.1': | ||||||
|     resolution: {integrity: sha512-/DPlwvWN0zLQ7X3D/zAhtHRTVWP/Odn3lZeyllUzjn8PFV9E5pCVXbLV9fBqmP400icZkG9a3fplSbUrVIIpOA==, tarball: https://npm.pkg.github.com/download/@abearxiong/auth/1.0.0-alpha.5/9d149a4e10bde7fd51b102b00849d75da85dd282} |     resolution: {integrity: sha512-KWolCGZorF/h+IyBToQyom/7iNUYN1V4ZsVSb8saAhnkQZ52CVT0P/8zBBq6WvbU8ZlJGCFk5mm7Jtaq9AE5kw==, tarball: https://npm.pkg.github.com/download/@abearxiong/auth/1.0.1/41c1a8845ad5fe34168bfbc209c8cb6e242de590} | ||||||
|     peerDependencies: |     peerDependencies: | ||||||
|       '@abearxiong/router': ^0.0.1-alpha.38 |       '@abearxiong/router': ^0.0.1-alpha.38 | ||||||
|  |  | ||||||
| @@ -3371,7 +3371,7 @@ packages: | |||||||
|  |  | ||||||
| snapshots: | snapshots: | ||||||
|  |  | ||||||
|   '@abearxiong/auth@1.0.0-alpha.5(@abearxiong/router@0.0.1-alpha.38)': |   '@abearxiong/auth@1.0.1(@abearxiong/router@0.0.1-alpha.38)': | ||||||
|     dependencies: |     dependencies: | ||||||
|       '@abearxiong/router': 0.0.1-alpha.38 |       '@abearxiong/router': 0.0.1-alpha.38 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -22,6 +22,15 @@ export const app = new App<{ import: any; emit: typeof emit }>({ | |||||||
|     import: dynamicImport, |     import: dynamicImport, | ||||||
|     emit, |     emit, | ||||||
|   }, |   }, | ||||||
|  |   // routerHandle(res) { | ||||||
|  |   //   console.log('routerHandle', res.query); | ||||||
|  |   //   const { code, data, message } = res; | ||||||
|  |   //   return { | ||||||
|  |   //     code, | ||||||
|  |   //     data, | ||||||
|  |   //     message, | ||||||
|  |   //   }; | ||||||
|  |   // }, | ||||||
| }); | }); | ||||||
|  |  | ||||||
| const clients = []; | const clients = []; | ||||||
|   | |||||||
							
								
								
									
										58
									
								
								src/models/chat-history.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/models/chat-history.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | |||||||
|  | import { chat } from '@/modules/ollama.ts'; | ||||||
|  | import { sequelize } from '../modules/sequelize.ts'; | ||||||
|  | import { DataTypes, Model } from 'sequelize'; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * chat 回话记录 | ||||||
|  |  * 有一些内容是预置的。 | ||||||
|  |  */ | ||||||
|  | export class ChatHistory extends Model { | ||||||
|  |   declare id: string; | ||||||
|  |   declare data: string; | ||||||
|  |   declare root: boolean; | ||||||
|  |   declare show: boolean; | ||||||
|  |   declare uid: string; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ChatHistory.init( | ||||||
|  |   { | ||||||
|  |     id: { | ||||||
|  |       type: DataTypes.UUID, | ||||||
|  |       primaryKey: true, | ||||||
|  |       defaultValue: DataTypes.UUIDV4, | ||||||
|  |     }, | ||||||
|  |     data: { | ||||||
|  |       type: DataTypes.JSON, | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |     chatId: { | ||||||
|  |       type: DataTypes.UUID, // 历史属于哪一条会话 | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |     chatPromptId: { | ||||||
|  |       type: DataTypes.UUID, // 属于哪一个prompt | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |     root: { | ||||||
|  |       type: DataTypes.BOOLEAN, // 是否是根节点 | ||||||
|  |       defaultValue: false, | ||||||
|  |     }, | ||||||
|  |     show: { | ||||||
|  |       type: DataTypes.BOOLEAN, // 当创建返回的时候,配置是否显示 | ||||||
|  |       defaultValue: true, | ||||||
|  |     }, | ||||||
|  |     uid: { | ||||||
|  |       type: DataTypes.STRING, | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |     sequelize, // 传入 Sequelize 实例 | ||||||
|  |     modelName: 'chat_history', // 模型名称 | ||||||
|  |   }, | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | // force 只能run一次,否则会删除表 | ||||||
|  | ChatHistory.sync({ alter: true, force: true, logging: false }).catch((e) => { | ||||||
|  |   console.error('History sync error', e); | ||||||
|  | }); | ||||||
							
								
								
									
										61
									
								
								src/models/chat-prompt.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/models/chat-prompt.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | |||||||
|  | import { sequelize } from '../modules/sequelize.ts'; | ||||||
|  | import { DataTypes, Model } from 'sequelize'; | ||||||
|  | import { Variable } from '@kevisual/ai-graph'; | ||||||
|  |  | ||||||
|  | export type ChatPromptData = { | ||||||
|  |   // 使用那个agent, 必须要有 | ||||||
|  |   aiAgentId: string; | ||||||
|  |   // 使用那个初始化的prompt,如果不存在则纯粹的白对话。 | ||||||
|  |   promptId?: string; | ||||||
|  | }; | ||||||
|  | /** | ||||||
|  |  * chat绑定就的agent和prompt | ||||||
|  |  * 有一些内容是预置的。 | ||||||
|  |  */ | ||||||
|  | export class ChatPrompt extends Model { | ||||||
|  |   declare id: string; | ||||||
|  |   declare title: string; | ||||||
|  |   declare description: string; | ||||||
|  |   declare uid: string; | ||||||
|  |   declare key: string; | ||||||
|  |   declare data: string; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ChatPrompt.init( | ||||||
|  |   { | ||||||
|  |     id: { | ||||||
|  |       type: DataTypes.UUID, | ||||||
|  |       primaryKey: true, | ||||||
|  |       defaultValue: DataTypes.UUIDV4, | ||||||
|  |     }, | ||||||
|  |     title: { | ||||||
|  |       type: DataTypes.STRING, | ||||||
|  |       allowNull: false, | ||||||
|  |     }, | ||||||
|  |     description: { | ||||||
|  |       type: DataTypes.TEXT, | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |     data: { | ||||||
|  |       type: DataTypes.JSON, | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |     key: { | ||||||
|  |       type: DataTypes.STRING, // 页面属于 /container/edit/list | ||||||
|  |       allowNull: false, | ||||||
|  |     }, | ||||||
|  |     uid: { | ||||||
|  |       type: DataTypes.STRING, | ||||||
|  |       allowNull: true, | ||||||
|  |     }, | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |     sequelize, // 传入 Sequelize 实例 | ||||||
|  |     modelName: 'chat_prompt', // 模型名称 | ||||||
|  |   }, | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | // force 只能run一次,否则会删除表 | ||||||
|  | ChatPrompt.sync({ alter: true, force: true, logging: false }).catch((e) => { | ||||||
|  |   console.error('Prompt sync error', e); | ||||||
|  | }); | ||||||
| @@ -5,10 +5,16 @@ import semver from 'semver'; | |||||||
| const list = app.route({ | const list = app.route({ | ||||||
|   path: 'container', |   path: 'container', | ||||||
|   key: 'list', |   key: 'list', | ||||||
|  |   middleware: ['auth'] | ||||||
| }); | }); | ||||||
|  |  | ||||||
| list.run = async (ctx) => { | list.run = async (ctx) => { | ||||||
|  |   const tokenUser = ctx.state.tokenUser; | ||||||
|   const list = await ContainerModel.findAll({ |   const list = await ContainerModel.findAll({ | ||||||
|     order: [['updatedAt', 'DESC']], |     order: [['updatedAt', 'DESC']], | ||||||
|  |     where: { | ||||||
|  |       uid: tokenUser.id, | ||||||
|  |     }, | ||||||
|   }); |   }); | ||||||
|   ctx.body = list; |   ctx.body = list; | ||||||
|   return ctx; |   return ctx; | ||||||
| @@ -42,10 +48,7 @@ add.run = async (ctx) => { | |||||||
|     title: '', |     title: '', | ||||||
|     description: '', |     description: '', | ||||||
|     code: '', |     code: '', | ||||||
|     source: '', |  | ||||||
|     type: '', |     type: '', | ||||||
|     sourceType: '', |  | ||||||
|     data: {}, |  | ||||||
|   }; |   }; | ||||||
|   const container = { |   const container = { | ||||||
|     ..._data, |     ..._data, | ||||||
| @@ -67,6 +70,8 @@ add.run = async (ctx) => { | |||||||
|     try { |     try { | ||||||
|       containerModel = await ContainerModel.create({ |       containerModel = await ContainerModel.create({ | ||||||
|         ...container, |         ...container, | ||||||
|  |         source: '', | ||||||
|  |         sourceType: '', | ||||||
|       }); |       }); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       console.log('error', e); |       console.log('error', e); | ||||||
|   | |||||||
| @@ -29,10 +29,15 @@ app | |||||||
|   .route({ |   .route({ | ||||||
|     path: 'page', |     path: 'page', | ||||||
|     key: 'list', |     key: 'list', | ||||||
|  |     middleware: ['auth'], | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|  |     const tokenUser = ctx.state.tokenUser; | ||||||
|     ctx.body = await PageModel.findAll({ |     ctx.body = await PageModel.findAll({ | ||||||
|       order: [['updatedAt', 'DESC']], |       order: [['updatedAt', 'DESC']], | ||||||
|  |       where: { | ||||||
|  |         uid: tokenUser.id, | ||||||
|  |       }, | ||||||
|     }); |     }); | ||||||
|     return ctx; |     return ctx; | ||||||
|   }) |   }) | ||||||
|   | |||||||
| @@ -6,10 +6,15 @@ app | |||||||
|   .route({ |   .route({ | ||||||
|     path: 'resource', |     path: 'resource', | ||||||
|     key: 'list', |     key: 'list', | ||||||
|  |     middleware: ['auth'], | ||||||
|   }) |   }) | ||||||
|   .define(async (ctx) => { |   .define(async (ctx) => { | ||||||
|  |     const tokenUser = ctx.state.tokenUser; | ||||||
|     const list = await ResourceModel.findAll({ |     const list = await ResourceModel.findAll({ | ||||||
|       order: [['updatedAt', 'DESC']], |       order: [['updatedAt', 'DESC']], | ||||||
|  |       where: { | ||||||
|  |         uid: tokenUser.id, | ||||||
|  |       }, | ||||||
|     }); |     }); | ||||||
|     ctx.body = list; |     ctx.body = list; | ||||||
|     return ctx; |     return ctx; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user