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
|
// @ts-check
|
||||||
// https://bun.sh/docs/bundler
|
|
||||||
// @ts-ignore
|
|
||||||
import { resolvePath } from '@kevisual/use-config/env';
|
import { resolvePath } from '@kevisual/use-config/env';
|
||||||
import pkg from './package.json';
|
|
||||||
import { execSync } from 'node:child_process';
|
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({
|
await Bun.build({
|
||||||
target: 'node',
|
target: 'node',
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
entrypoints: [resolvePath('./src/provider/index.ts')],
|
entrypoints: [resolvePath(entry, { meta: import.meta })],
|
||||||
outdir: resolvePath('./dist'),
|
outdir: resolvePath('./dist', { meta: import.meta }),
|
||||||
naming: {
|
naming: {
|
||||||
entry: 'ai-provider.mjs',
|
entry: `${naming}.js`,
|
||||||
},
|
},
|
||||||
|
external,
|
||||||
define: {
|
env: 'KEVISUAL_*',
|
||||||
ENVISION_VERSION: JSON.stringify(pkg.version),
|
|
||||||
},
|
|
||||||
env: 'ENVISION_*',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cmd = 'dts -i src/provider/index.ts -o ai-provider.d.ts';
|
// const cmd = `dts -i src/index.ts -o app.d.ts`;
|
||||||
execSync(cmd, { stdio: 'inherit' });
|
// 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",
|
"name": "@kevisual/ai-center-services",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "后面需要把ai-center的provider模块提取出去",
|
"description": "后面需要把ai-center的provider模块提取出去",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"basename": "/root/ai-center-services",
|
"basename": "/root/ai-center-services",
|
||||||
"app": {
|
"app": {
|
||||||
"entry": "dist/app.mjs",
|
"entry": "dist/app.js",
|
||||||
"key": "ai-center-services",
|
"key": "ai-center-services",
|
||||||
"type": "system-app"
|
"type": "system-app",
|
||||||
|
"runtime": [
|
||||||
|
"client",
|
||||||
|
"server"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
@ -16,7 +20,6 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run clean && bun bun.config.mjs",
|
"build": "npm run clean && bun bun.config.mjs",
|
||||||
"dev": "bun run --watch bun.config.mjs",
|
"dev": "bun run --watch bun.config.mjs",
|
||||||
"test": "tsx test/**/*.ts",
|
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"pub": "envision pack -p -u"
|
"pub": "envision pack -p -u"
|
||||||
},
|
},
|
||||||
@ -29,19 +32,13 @@
|
|||||||
"registry": "https://registry.npmjs.org/",
|
"registry": "https://registry.npmjs.org/",
|
||||||
"access": "public"
|
"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": {
|
"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/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/router": "0.0.21",
|
||||||
"@kevisual/types": "^0.0.10",
|
"@kevisual/types": "^0.0.10",
|
||||||
"@kevisual/use-config": "^1.0.17",
|
"@kevisual/use-config": "^1.0.17",
|
||||||
@ -50,7 +47,6 @@
|
|||||||
"@types/formidable": "^3.4.5",
|
"@types/formidable": "^3.4.5",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^22.15.21",
|
"@types/node": "^22.15.21",
|
||||||
"@vitejs/plugin-basic-ssl": "^2.0.0",
|
|
||||||
"cookie": "^1.0.2",
|
"cookie": "^1.0.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
@ -58,18 +54,15 @@
|
|||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"formidable": "^3.5.4",
|
"formidable": "^3.5.4",
|
||||||
"ioredis": "^5.6.1",
|
"ioredis": "^5.6.1",
|
||||||
"json5": "^2.2.3",
|
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
|
"nanoid": "^5.1.5",
|
||||||
"openai": "4.103.0",
|
"openai": "4.103.0",
|
||||||
|
"pg-hstore": "^2.3.4",
|
||||||
"pm2": "^6.0.6",
|
"pm2": "^6.0.6",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"rollup": "^4.41.0",
|
|
||||||
"rollup-plugin-dts": "^6.2.1",
|
|
||||||
"sequelize": "^6.37.7",
|
"sequelize": "^6.37.7",
|
||||||
"tape": "^5.9.0",
|
"tape": "^5.9.0",
|
||||||
"tiktoken": "^1.0.21",
|
"tiktoken": "^1.0.21"
|
||||||
"typescript": "^5.8.3",
|
|
||||||
"vite": "^6.3.5"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kevisual/logger": "^0.0.4"
|
"@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 = {
|
export type ProviderResult = {
|
||||||
provider: string;
|
provider: string;
|
||||||
model: string;
|
model: string;
|
||||||
group: string;
|
group?: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
dayLimit?: number;
|
dayLimit?: number;
|
||||||
tokenLimit?: number;
|
tokenLimit?: number;
|
||||||
@ -74,7 +74,7 @@ export type ProviderResult = {
|
|||||||
export type AIConfig = {
|
export type AIConfig = {
|
||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
models: AIModel[];
|
models?: AIModel[];
|
||||||
secretKeys: SecretKey[];
|
secretKeys: SecretKey[];
|
||||||
permission?: Permission;
|
permission?: Permission;
|
||||||
filter?: {
|
filter?: {
|
||||||
|
@ -19,6 +19,7 @@ app
|
|||||||
let { username, model, group, getFull = false } = ctx.query;
|
let { username, model, group, getFull = false } = ctx.query;
|
||||||
const tokenUser = ctx.state.tokenUser || {};
|
const tokenUser = ctx.state.tokenUser || {};
|
||||||
const tokenUsername = tokenUser.username;
|
const tokenUsername = tokenUser.username;
|
||||||
|
const token = ctx.query.token || ctx.state.token;
|
||||||
const options = ctx.query.options || {};
|
const options = ctx.query.options || {};
|
||||||
let aiChatHistory: AiChatHistoryModel;
|
let aiChatHistory: AiChatHistoryModel;
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -46,6 +47,7 @@ app
|
|||||||
model,
|
model,
|
||||||
group,
|
group,
|
||||||
username: tokenUsername,
|
username: tokenUsername,
|
||||||
|
token,
|
||||||
});
|
});
|
||||||
if (!isSelf && username !== 'root') {
|
if (!isSelf && username !== 'root') {
|
||||||
const aiConfig = chatServices.aiConfig;
|
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 { redis } from '@/modules/db.ts';
|
||||||
import { CustomError } from '@kevisual/router';
|
import { CustomError } from '@kevisual/router';
|
||||||
import { queryConfig } from '@/modules/query.ts';
|
import { queryConfig } from '@/modules/query.ts';
|
||||||
import { log } from '@/logger/index.ts';
|
import { logger } from '@/modules/logger.ts';
|
||||||
export class ChatConfigServices {
|
export class ChatConfigServices {
|
||||||
cachePrefix = 'ai:chat:config';
|
cachePrefix = 'ai:chat:config';
|
||||||
// 使用谁的模型
|
// 使用谁的模型
|
||||||
@ -11,6 +11,7 @@ export class ChatConfigServices {
|
|||||||
username: string;
|
username: string;
|
||||||
aiConfig?: AIConfig;
|
aiConfig?: AIConfig;
|
||||||
isOwner: boolean;
|
isOwner: boolean;
|
||||||
|
token?: string;
|
||||||
/**
|
/**
|
||||||
* username 是使用的模型的用户名,使用谁的模型
|
* username 是使用的模型的用户名,使用谁的模型
|
||||||
* @param username
|
* @param username
|
||||||
@ -19,6 +20,7 @@ export class ChatConfigServices {
|
|||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.isOwner = owner === username;
|
this.isOwner = owner === username;
|
||||||
|
// this.token = token;
|
||||||
}
|
}
|
||||||
getKey() {
|
getKey() {
|
||||||
return `${this.cachePrefix}:${this.owner}`;
|
return `${this.cachePrefix}:${this.owner}`;
|
||||||
@ -28,13 +30,14 @@ export class ChatConfigServices {
|
|||||||
* @param keepSecret 是否需要清除secret 默认 不清除 为true
|
* @param keepSecret 是否需要清除secret 默认 不清除 为true
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getChatConfig(keepSecret = true, token?: string) {
|
async getChatConfig(keepSecret = true, newToken?: string) {
|
||||||
const key = this.getKey();
|
const key = this.getKey();
|
||||||
const cache = await redis.get(key);
|
const cache = await redis.get(key);
|
||||||
let modelConfig = null;
|
let modelConfig = null;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
modelConfig = JSON.parse(cache);
|
modelConfig = JSON.parse(cache);
|
||||||
}
|
}
|
||||||
|
const token = newToken || this.token;
|
||||||
if (!modelConfig) {
|
if (!modelConfig) {
|
||||||
if (this.owner !== this.username) {
|
if (this.owner !== this.username) {
|
||||||
throw new CustomError(
|
throw new CustomError(
|
||||||
@ -45,6 +48,7 @@ export class ChatConfigServices {
|
|||||||
if (res.code === 200 && res.data?.data) {
|
if (res.code === 200 && res.data?.data) {
|
||||||
modelConfig = res.data.data;
|
modelConfig = res.data.data;
|
||||||
} else {
|
} else {
|
||||||
|
logger.error('获取ai.json配置失败', res, 'username', this.username);
|
||||||
throw new CustomError(400, 'get config failed');
|
throw new CustomError(400, 'get config failed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ export type ChatServicesConfig = {
|
|||||||
model: string;
|
model: string;
|
||||||
group: string;
|
group: string;
|
||||||
decryptKey?: string;
|
decryptKey?: string;
|
||||||
|
token?: string;
|
||||||
};
|
};
|
||||||
export class ChatServices {
|
export class ChatServices {
|
||||||
cachePrefix = 'ai-chat:model:';
|
cachePrefix = 'ai-chat:model:';
|
||||||
@ -39,6 +40,7 @@ export class ChatServices {
|
|||||||
modelConfig?: ProviderResult;
|
modelConfig?: ProviderResult;
|
||||||
aiConfig?: AIConfig;
|
aiConfig?: AIConfig;
|
||||||
chatProvider?: BaseChat;
|
chatProvider?: BaseChat;
|
||||||
|
token?: string;
|
||||||
constructor(opts: ChatServicesConfig) {
|
constructor(opts: ChatServicesConfig) {
|
||||||
this.owner = opts.owner;
|
this.owner = opts.owner;
|
||||||
this.model = opts.model;
|
this.model = opts.model;
|
||||||
@ -91,7 +93,8 @@ export class ChatServices {
|
|||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
async getConfig(username: string) {
|
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();
|
return services.getChatConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +148,7 @@ export class ChatServices {
|
|||||||
return item;
|
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 owner = opts.owner || 'root';
|
||||||
const model = opts.model || 'deepseek-chat';
|
const model = opts.model || 'deepseek-chat';
|
||||||
const group = opts.group || 'deepseek';
|
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