generated from tailored/app-template
"chore: 升级 Rollup 版本并优化构建配置"
This commit is contained in:
parent
6ced3676ab
commit
0c885e9012
@ -1,23 +0,0 @@
|
||||
// @ts-check
|
||||
// https://bun.sh/docs/bundler
|
||||
// @ts-ignore
|
||||
import { resolvePath } from '@kevisual/use-config/env';
|
||||
import pkg from './package.json';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
// bun run src/index.ts --
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [resolvePath('./src/index.ts')],
|
||||
outdir: resolvePath('./dist'),
|
||||
naming: {
|
||||
entry: 'app.js',
|
||||
},
|
||||
|
||||
define: {
|
||||
ENVISION_VERSION: JSON.stringify(pkg.version),
|
||||
},
|
||||
env: 'ENVISION_*',
|
||||
});
|
||||
|
@ -1,25 +1,37 @@
|
||||
// @ts-check
|
||||
// https://bun.sh/docs/bundler
|
||||
// @ts-ignore
|
||||
import { resolvePath } from '@kevisual/use-config/env';
|
||||
import pkg from './package.json';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
// bun run src/index.ts --
|
||||
const entry = 'src/index.ts';
|
||||
const naming = 'app';
|
||||
const external = ['sequelize', 'pg', 'sqlite3', 'ioredis', 'pm2'];
|
||||
/**
|
||||
* @type {import('bun').BuildConfig}
|
||||
*/
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [resolvePath('./src/provider/index.ts')],
|
||||
outdir: resolvePath('./dist'),
|
||||
entrypoints: [resolvePath(entry, { meta: import.meta })],
|
||||
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||
naming: {
|
||||
entry: 'ai-provider.mjs',
|
||||
entry: `${naming}.js`,
|
||||
},
|
||||
|
||||
define: {
|
||||
ENVISION_VERSION: JSON.stringify(pkg.version),
|
||||
},
|
||||
env: 'ENVISION_*',
|
||||
external,
|
||||
env: 'KEVISUAL_*',
|
||||
});
|
||||
|
||||
const cmd = 'dts -i src/provider/index.ts -o ai-provider.d.ts';
|
||||
execSync(cmd, { stdio: 'inherit' });
|
||||
// const cmd = `dts -i src/index.ts -o app.d.ts`;
|
||||
// const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
|
||||
// execSync(cmd, { stdio: 'inherit' });
|
||||
|
||||
await Bun.build({
|
||||
target: 'node',
|
||||
format: 'esm',
|
||||
entrypoints: [resolvePath('./src/run.ts', { meta: import.meta })],
|
||||
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||
naming: {
|
||||
entry: `${'run'}.js`,
|
||||
},
|
||||
external,
|
||||
env: 'KEVISUAL_*',
|
||||
});
|
||||
|
39
package.json
39
package.json
@ -1,13 +1,17 @@
|
||||
{
|
||||
"name": "@kevisual/ai-center",
|
||||
"version": "0.0.4",
|
||||
"name": "@kevisual/ai-center-services",
|
||||
"version": "0.0.5",
|
||||
"description": "后面需要把ai-center的provider模块提取出去",
|
||||
"main": "index.js",
|
||||
"basename": "/root/ai-center-services",
|
||||
"app": {
|
||||
"entry": "dist/app.mjs",
|
||||
"entry": "dist/app.js",
|
||||
"key": "ai-center-services",
|
||||
"type": "system-app"
|
||||
"type": "system-app",
|
||||
"runtime": [
|
||||
"client",
|
||||
"server"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
@ -16,7 +20,6 @@
|
||||
"scripts": {
|
||||
"build": "npm run clean && bun bun.config.mjs",
|
||||
"dev": "bun run --watch bun.config.mjs",
|
||||
"test": "tsx test/**/*.ts",
|
||||
"clean": "rm -rf dist",
|
||||
"pub": "envision pack -p -u"
|
||||
},
|
||||
@ -29,19 +32,13 @@
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/ai-provider.mjs",
|
||||
"types": "./dist/ai-provider.d.ts"
|
||||
},
|
||||
"./ai-provider": {
|
||||
"import": "./dist/ai-provider.mjs",
|
||||
"types": "./dist/ai-provider.d.ts"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kevisual/code-center-module": "0.0.19",
|
||||
"@kevisual/ai": "^0.0.4",
|
||||
"@kevisual/code-center-module": "0.0.20",
|
||||
"@kevisual/mark": "0.0.7",
|
||||
"@kevisual/permission": "^0.0.3",
|
||||
"@kevisual/query": "^0.0.20",
|
||||
"@kevisual/query-config": "^0.0.2",
|
||||
"@kevisual/router": "0.0.21",
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"@kevisual/use-config": "^1.0.17",
|
||||
@ -50,7 +47,6 @@
|
||||
"@types/formidable": "^3.4.5",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^22.15.21",
|
||||
"@vitejs/plugin-basic-ssl": "^2.0.0",
|
||||
"cookie": "^1.0.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"crypto-js": "^4.2.0",
|
||||
@ -58,18 +54,15 @@
|
||||
"dotenv": "^16.5.0",
|
||||
"formidable": "^3.5.4",
|
||||
"ioredis": "^5.6.1",
|
||||
"json5": "^2.2.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"nanoid": "^5.1.5",
|
||||
"openai": "4.103.0",
|
||||
"pg-hstore": "^2.3.4",
|
||||
"pm2": "^6.0.6",
|
||||
"rimraf": "^6.0.1",
|
||||
"rollup": "^4.41.0",
|
||||
"rollup-plugin-dts": "^6.2.1",
|
||||
"sequelize": "^6.37.7",
|
||||
"tape": "^5.9.0",
|
||||
"tiktoken": "^1.0.21",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.5"
|
||||
"tiktoken": "^1.0.21"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kevisual/logger": "^0.0.4"
|
||||
|
901
pnpm-lock.yaml
generated
901
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
6
src/modules/logger.ts
Normal file
6
src/modules/logger.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Logger } from '@kevisual/logger';
|
||||
|
||||
export const logger = new Logger({
|
||||
level: process?.env?.LOG_LEVEL || 'info',
|
||||
showTime: true,
|
||||
});
|
@ -60,7 +60,7 @@ export type GetProviderOpts = {
|
||||
export type ProviderResult = {
|
||||
provider: string;
|
||||
model: string;
|
||||
group: string;
|
||||
group?: string;
|
||||
apiKey: string;
|
||||
dayLimit?: number;
|
||||
tokenLimit?: number;
|
||||
@ -74,7 +74,7 @@ export type ProviderResult = {
|
||||
export type AIConfig = {
|
||||
title?: string;
|
||||
description?: string;
|
||||
models: AIModel[];
|
||||
models?: AIModel[];
|
||||
secretKeys: SecretKey[];
|
||||
permission?: Permission;
|
||||
filter?: {
|
||||
|
@ -19,6 +19,7 @@ app
|
||||
let { username, model, group, getFull = false } = ctx.query;
|
||||
const tokenUser = ctx.state.tokenUser || {};
|
||||
const tokenUsername = tokenUser.username;
|
||||
const token = ctx.query.token || ctx.state.token;
|
||||
const options = ctx.query.options || {};
|
||||
let aiChatHistory: AiChatHistoryModel;
|
||||
if (id) {
|
||||
@ -46,6 +47,7 @@ app
|
||||
model,
|
||||
group,
|
||||
username: tokenUsername,
|
||||
token,
|
||||
});
|
||||
if (!isSelf && username !== 'root') {
|
||||
const aiConfig = chatServices.aiConfig;
|
||||
|
@ -2,7 +2,7 @@ import { AIConfigParser, type AIConfig } from '@/provider/utils/parse-config.ts'
|
||||
import { redis } from '@/modules/db.ts';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { queryConfig } from '@/modules/query.ts';
|
||||
import { log } from '@/logger/index.ts';
|
||||
import { logger } from '@/modules/logger.ts';
|
||||
export class ChatConfigServices {
|
||||
cachePrefix = 'ai:chat:config';
|
||||
// 使用谁的模型
|
||||
@ -11,6 +11,7 @@ export class ChatConfigServices {
|
||||
username: string;
|
||||
aiConfig?: AIConfig;
|
||||
isOwner: boolean;
|
||||
token?: string;
|
||||
/**
|
||||
* username 是使用的模型的用户名,使用谁的模型
|
||||
* @param username
|
||||
@ -19,6 +20,7 @@ export class ChatConfigServices {
|
||||
this.owner = owner;
|
||||
this.username = username;
|
||||
this.isOwner = owner === username;
|
||||
// this.token = token;
|
||||
}
|
||||
getKey() {
|
||||
return `${this.cachePrefix}:${this.owner}`;
|
||||
@ -28,13 +30,14 @@ export class ChatConfigServices {
|
||||
* @param keepSecret 是否需要清除secret 默认 不清除 为true
|
||||
* @returns
|
||||
*/
|
||||
async getChatConfig(keepSecret = true, token?: string) {
|
||||
async getChatConfig(keepSecret = true, newToken?: string) {
|
||||
const key = this.getKey();
|
||||
const cache = await redis.get(key);
|
||||
let modelConfig = null;
|
||||
if (cache) {
|
||||
modelConfig = JSON.parse(cache);
|
||||
}
|
||||
const token = newToken || this.token;
|
||||
if (!modelConfig) {
|
||||
if (this.owner !== this.username) {
|
||||
throw new CustomError(
|
||||
@ -45,6 +48,7 @@ export class ChatConfigServices {
|
||||
if (res.code === 200 && res.data?.data) {
|
||||
modelConfig = res.data.data;
|
||||
} else {
|
||||
logger.error('获取ai.json配置失败', res, 'username', this.username);
|
||||
throw new CustomError(400, 'get config failed');
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ export type ChatServicesConfig = {
|
||||
model: string;
|
||||
group: string;
|
||||
decryptKey?: string;
|
||||
token?: string;
|
||||
};
|
||||
export class ChatServices {
|
||||
cachePrefix = 'ai-chat:model:';
|
||||
@ -39,6 +40,7 @@ export class ChatServices {
|
||||
modelConfig?: ProviderResult;
|
||||
aiConfig?: AIConfig;
|
||||
chatProvider?: BaseChat;
|
||||
token?: string;
|
||||
constructor(opts: ChatServicesConfig) {
|
||||
this.owner = opts.owner;
|
||||
this.model = opts.model;
|
||||
@ -91,7 +93,8 @@ export class ChatServices {
|
||||
return cache;
|
||||
}
|
||||
async getConfig(username: string) {
|
||||
const services = new ChatConfigServices(this.owner, username);
|
||||
const token = this.token;
|
||||
const services = new ChatConfigServices(this.owner, username, token);
|
||||
return services.getChatConfig();
|
||||
}
|
||||
|
||||
@ -145,7 +148,7 @@ export class ChatServices {
|
||||
return item;
|
||||
});
|
||||
}
|
||||
static async createServices(opts: Partial<ChatServicesConfig> & { username: string }) {
|
||||
static async createServices(opts: Partial<ChatServicesConfig> & { username: string; token?: string }) {
|
||||
const owner = opts.owner || 'root';
|
||||
const model = opts.model || 'deepseek-chat';
|
||||
const group = opts.group || 'deepseek';
|
||||
|
1
src/run.ts
Normal file
1
src/run.ts
Normal file
@ -0,0 +1 @@
|
||||
console.log('run commander')
|
@ -1,9 +0,0 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import basicSsl from '@vitejs/plugin-basic-ssl';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [basicSsl()],
|
||||
server: {
|
||||
port: 3000,
|
||||
},
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user