update new way
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { AiAgent, AiProperties } from '@/models/agent.ts';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { agentManger } from '@kevisual/ai-lang';
|
||||
// import { agentManger } from '@kevisual/ai-lang';
|
||||
import { v4 } from 'uuid';
|
||||
app
|
||||
.route({
|
||||
@@ -66,25 +66,25 @@ app
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route('agent', 'test')
|
||||
.define(async (ctx) => {
|
||||
const { message } = ctx.query;
|
||||
const data: AiProperties = {
|
||||
type: 'ollama',
|
||||
id: 'test',
|
||||
model: 'qwen2.5:14b',
|
||||
baseUrl: 'http://mz.zxj.im:11434',
|
||||
cache: 'memory',
|
||||
};
|
||||
const agent = agentManger.createAgent(data as any);
|
||||
const res = await agent.sendHumanMessage(message);
|
||||
// agent.close();
|
||||
agentManger.removeAgent(agent.id);
|
||||
ctx.body = res;
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
// app
|
||||
// .route('agent', 'test')
|
||||
// .define(async (ctx) => {
|
||||
// const { message } = ctx.query;
|
||||
// const data: AiProperties = {
|
||||
// type: 'ollama',
|
||||
// id: 'test',
|
||||
// model: 'qwen2.5:14b',
|
||||
// baseUrl: 'http://mz.zxj.im:11434',
|
||||
// cache: 'memory',
|
||||
// };
|
||||
// const agent = agentManger.createAgent(data as any);
|
||||
// const res = await agent.sendHumanMessage(message);
|
||||
// // agent.close();
|
||||
// agentManger.removeAgent(agent.id);
|
||||
// ctx.body = res;
|
||||
// return ctx;
|
||||
// })
|
||||
// .addTo(app);
|
||||
|
||||
export const agentModelList = ['qwen2.5:14b', 'qwen2.5-coder:7b', 'llama3.1:8b', 'bakllava:latest'] as const;
|
||||
export const openAiModels = ['gpt-4o'];
|
||||
@@ -130,8 +130,8 @@ const initManager = async () => {
|
||||
cacheName: item.cacheName,
|
||||
};
|
||||
});
|
||||
agentManger.createAgentList(data);
|
||||
// agentManger.createAgentList(data);
|
||||
};
|
||||
setTimeout(() => {
|
||||
initManager();
|
||||
}, 1000);
|
||||
// setTimeout(() => {
|
||||
// initManager();
|
||||
// }, 1000);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { app } from '../../app.ts';
|
||||
import { ContainerModel, ContainerData, Container } from './models/index.ts';
|
||||
import semver from 'semver';
|
||||
import { uploadMinioContainer } from '../page/module/cache-file.ts';
|
||||
const list = app.route({
|
||||
path: 'container',
|
||||
@@ -49,7 +48,7 @@ add.run = async (ctx) => {
|
||||
const container = {
|
||||
...data,
|
||||
};
|
||||
let containerModel: any = null;
|
||||
let containerModel: ContainerModel | null = null;
|
||||
if (container.id) {
|
||||
containerModel = await ContainerModel.findByPk(container.id);
|
||||
if (containerModel) {
|
||||
@@ -134,7 +133,7 @@ app
|
||||
version: version,
|
||||
code: container.code,
|
||||
filePath: fileName,
|
||||
saveHTML
|
||||
saveHTML,
|
||||
});
|
||||
await ctx.call({
|
||||
path: 'app',
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { sequelize } from '../../../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
import crypto from 'crypto';
|
||||
export interface ContainerData {}
|
||||
export type ContainerPublish = {
|
||||
key: string;
|
||||
key: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
fileName?: string;
|
||||
@@ -21,11 +21,20 @@ export class ContainerModel extends Model {
|
||||
declare type: string;
|
||||
declare tags: string[];
|
||||
declare code: string;
|
||||
declare hash: string;
|
||||
declare source: string;
|
||||
declare sourceType: string;
|
||||
declare data: ContainerData;
|
||||
declare publish: ContainerPublish;
|
||||
declare uid: string;
|
||||
declare updatedAt: Date;
|
||||
declare createdAt: Date;
|
||||
createHash() {
|
||||
const { code } = this;
|
||||
const hash = crypto.createHash('md5');
|
||||
hash.update(code);
|
||||
this.hash = hash.digest('hex');
|
||||
}
|
||||
}
|
||||
ContainerModel.init(
|
||||
{
|
||||
@@ -55,6 +64,10 @@ ContainerModel.init(
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: '',
|
||||
},
|
||||
hash: {
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: '',
|
||||
},
|
||||
source: {
|
||||
type: DataTypes.STRING,
|
||||
defaultValue: '',
|
||||
|
||||
11
src/routes/container/module/get-container-file.ts
Normal file
11
src/routes/container/module/get-container-file.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ContainerModel } from '../models/index.ts';
|
||||
|
||||
export const getContainerById = async (id: string) => {
|
||||
const container = await ContainerModel.findByPk(id);
|
||||
const code = container?.code;
|
||||
return {
|
||||
code,
|
||||
id: container?.id,
|
||||
updatedAt: new Date(container?.updatedAt).getTime(),
|
||||
};
|
||||
};
|
||||
@@ -10,9 +10,9 @@ import './agent/index.ts';
|
||||
|
||||
import './user/index.ts';
|
||||
|
||||
import './chat-prompt/index.ts';
|
||||
// import './chat-prompt/index.ts';
|
||||
|
||||
import './chat-history/index.ts';
|
||||
// import './chat-history/index.ts';
|
||||
|
||||
import './github/index.ts';
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ app
|
||||
logging: false,
|
||||
});
|
||||
if (!user) {
|
||||
throw new CustomError(500, 'user not found');
|
||||
ctx.throw(500, 'user not found');
|
||||
}
|
||||
user.setTokenUser(tokenUser);
|
||||
ctx.body = await user.getInfo();
|
||||
@@ -30,7 +30,7 @@ app
|
||||
.define(async (ctx) => {
|
||||
const { username, email, password } = ctx.query;
|
||||
if (!username && !email) {
|
||||
throw new CustomError(400, 'username or email is required');
|
||||
ctx.throw(400, 'username or email is required');
|
||||
}
|
||||
let user: User | null = null;
|
||||
if (username) {
|
||||
@@ -40,10 +40,10 @@ app
|
||||
user = await User.findOne({ where: { email } });
|
||||
}
|
||||
if (!user) {
|
||||
throw new CustomError(500, 'Login Failed');
|
||||
ctx.throw(500, 'Login Failed');
|
||||
}
|
||||
if (!user.checkPassword(password)) {
|
||||
throw new CustomError(500, 'Password error');
|
||||
ctx.throw(500, 'Password error');
|
||||
}
|
||||
const token = await user.createToken();
|
||||
ctx.body = token;
|
||||
@@ -58,7 +58,7 @@ app
|
||||
const result = await User.verifyToken(token);
|
||||
ctx.body = result || {};
|
||||
} catch (e) {
|
||||
throw new CustomError(401, 'Token InValid ');
|
||||
ctx.throw(401, 'Token InValid ');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -73,7 +73,7 @@ app
|
||||
const { id } = tokenUser;
|
||||
const user = await User.findByPk(id);
|
||||
if (!user) {
|
||||
throw new CustomError(500, 'user not found');
|
||||
ctx.throw(500, 'user not found');
|
||||
}
|
||||
user.setTokenUser(tokenUser);
|
||||
if (username) {
|
||||
@@ -105,13 +105,13 @@ app
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { username, type = 'org' } = ctx.query.data || {};
|
||||
if (!username && type === 'org') {
|
||||
throw new CustomError('username is required');
|
||||
ctx.throw('username is required');
|
||||
}
|
||||
if (tokenUser.username === username) {
|
||||
// 自己刷新自己的token
|
||||
const user = await User.findByPk(tokenUser.id);
|
||||
if (!user) {
|
||||
throw new CustomError('user not found');
|
||||
ctx.throw('user not found');
|
||||
}
|
||||
if (user.type === 'user') {
|
||||
const token = await user.createToken();
|
||||
@@ -131,7 +131,7 @@ app
|
||||
}
|
||||
if (!me || me.type === 'org') {
|
||||
console.log('switch Error ', me.username, me.type);
|
||||
throw new CustomError('Permission denied');
|
||||
ctx.throw('Permission denied');
|
||||
}
|
||||
if (type === 'user') {
|
||||
const token = await me.createToken();
|
||||
@@ -140,13 +140,13 @@ app
|
||||
}
|
||||
const orgUser = await User.findOne({ where: { username } });
|
||||
if (!orgUser) {
|
||||
throw new CustomError('org user not found');
|
||||
ctx.throw('org user not found');
|
||||
}
|
||||
const user = await Org.findOne({ where: { username } });
|
||||
const users = user.users;
|
||||
const index = users.findIndex((u) => u.uid === me.id);
|
||||
if (index === -1) {
|
||||
throw new CustomError('Permission denied');
|
||||
ctx.throw('Permission denied');
|
||||
}
|
||||
const token = await orgUser.createToken(me.id);
|
||||
ctx.body = token;
|
||||
|
||||
Reference in New Issue
Block a user