This commit is contained in:
2024-09-30 01:39:07 +08:00
parent 962d89ff29
commit e05c042827
8 changed files with 152 additions and 9 deletions

View File

@@ -22,6 +22,15 @@ export const app = new App<{ import: any; emit: typeof emit }>({
import: dynamicImport,
emit,
},
// routerHandle(res) {
// console.log('routerHandle', res.query);
// const { code, data, message } = res;
// return {
// code,
// data,
// message,
// };
// },
});
const clients = [];

View 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
View 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);
});

View File

@@ -5,10 +5,16 @@ import semver from 'semver';
const list = app.route({
path: 'container',
key: 'list',
middleware: ['auth']
});
list.run = async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const list = await ContainerModel.findAll({
order: [['updatedAt', 'DESC']],
where: {
uid: tokenUser.id,
},
});
ctx.body = list;
return ctx;
@@ -42,10 +48,7 @@ add.run = async (ctx) => {
title: '',
description: '',
code: '',
source: '',
type: '',
sourceType: '',
data: {},
};
const container = {
..._data,
@@ -67,6 +70,8 @@ add.run = async (ctx) => {
try {
containerModel = await ContainerModel.create({
...container,
source: '',
sourceType: '',
});
} catch (e) {
console.log('error', e);

View File

@@ -29,10 +29,15 @@ app
.route({
path: 'page',
key: 'list',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
ctx.body = await PageModel.findAll({
order: [['updatedAt', 'DESC']],
where: {
uid: tokenUser.id,
},
});
return ctx;
})

View File

@@ -6,10 +6,15 @@ app
.route({
path: 'resource',
key: 'list',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const list = await ResourceModel.findAll({
order: [['updatedAt', 'DESC']],
where: {
uid: tokenUser.id,
},
});
ctx.body = list;
return ctx;