update change cli
This commit is contained in:
39
assistant/src/command/ai/index.ts
Normal file
39
assistant/src/command/ai/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { logger } from '@/module/logger.ts';
|
||||
import { program, Command, assistantConfig } from '@/program.ts';
|
||||
import { ProviderManager, ProviderMap } from '@kevisual/ai-center';
|
||||
const runAiCommand = new Command('ai')
|
||||
.description('AI 对话助手')
|
||||
.option('-t, --text <text>', '应用类型', '')
|
||||
.action(async (options) => {
|
||||
assistantConfig.checkMounted();
|
||||
const config = assistantConfig.getCacheAssistantConfig();
|
||||
const ai = config.ai || {};
|
||||
if (!ai.enabled) {
|
||||
logger.error('AI 功能未启用,请在助手配置文件中启用 AI 功能');
|
||||
return;
|
||||
}
|
||||
if (!options.text) {
|
||||
logger.error('请输入要发送给 AI 的文本');
|
||||
return;
|
||||
}
|
||||
if (!ProviderMap[ai.provider]) {
|
||||
logger.error('不支持的 AI 提供商,请检查配置文件中的提供商名称');
|
||||
const supportedProviders = Object.keys(ProviderMap).join(', ');
|
||||
logger.error(`支持的提供商有:${supportedProviders}`);
|
||||
return;
|
||||
}
|
||||
const provider = new ProviderManager({
|
||||
provider: ai.provider,
|
||||
apiKey: ai.apiKey,
|
||||
model: ai.model,
|
||||
});
|
||||
const result = await provider.chat([
|
||||
{
|
||||
role: 'user',
|
||||
content: options.text,
|
||||
},
|
||||
]);
|
||||
logger.info(result.choices[0].message.content);
|
||||
});
|
||||
|
||||
program.addCommand(runAiCommand);
|
||||
@@ -2,52 +2,60 @@ import { logger } from '@/module/logger.ts';
|
||||
import { program, Command, assistantConfig } from '@/program.ts';
|
||||
import { AppDownload } from '@/services/app/index.ts';
|
||||
|
||||
const appManagerCommand = new Command('app').description('本地的应用模块的安装和下载, 分为 app 和 web 两种类型');
|
||||
program.addCommand(appManagerCommand);
|
||||
const commdands = ['app', 'page'];
|
||||
const addOneCommand = (name: string) => {
|
||||
|
||||
const downloadCommand = new Command('download')
|
||||
.description('下载应用')
|
||||
.option('-i, --id <id>', '应用名称')
|
||||
.option('-t, --type <type>', '应用类型', 'web')
|
||||
.option('-r, --registry <registry>', '应用源 https://kevisual.cn')
|
||||
.option('-f --force', '强制覆盖')
|
||||
.option('-y --yes', '覆盖的时候不提示')
|
||||
.action(async (options) => {
|
||||
const { id, type, force, yes } = options;
|
||||
assistantConfig.checkMounted();
|
||||
const registry = options.registry || assistantConfig.getRegistry();
|
||||
// console.log('registry', registry);
|
||||
const app = new AppDownload(assistantConfig);
|
||||
let info = '';
|
||||
if (id) {
|
||||
const msg = await app.downloadApp({ id, type, registry, force, yes });
|
||||
info = String(msg);
|
||||
}
|
||||
logger.debug(info);
|
||||
});
|
||||
const appManagerCommand = new Command(name).description(`本地的应用模块的安装和下载, 分为 app 和 web 两种类型. 默认类型为${name}`);
|
||||
program.addCommand(appManagerCommand);
|
||||
|
||||
appManagerCommand.addCommand(downloadCommand);
|
||||
const downloadCommand = new Command('download')
|
||||
.description('下载应用')
|
||||
.option('-i, --id <id>', '应用名称')
|
||||
.option('-t, --type <type>', '应用类型', name)
|
||||
.option('-r, --registry <registry>', '应用源 https://kevisual.cn')
|
||||
.option('-f --force', '强制覆盖')
|
||||
.option('-y --yes', '覆盖的时候不提示')
|
||||
.action(async (options) => {
|
||||
const { id, type, force, yes } = options;
|
||||
assistantConfig.checkMounted();
|
||||
const registry = options.registry || assistantConfig.getRegistry();
|
||||
// console.log('registry', registry);
|
||||
const app = new AppDownload(assistantConfig);
|
||||
let info = '';
|
||||
if (id) {
|
||||
const msg = await app.downloadApp({ id, type, registry, force, yes });
|
||||
info = String(msg);
|
||||
}
|
||||
logger.debug(info);
|
||||
});
|
||||
|
||||
const deleteCommand = new Command('delete')
|
||||
.description('删除应用')
|
||||
.option('-i, --id <id>', '应用名称')
|
||||
.option('-t, --type <type>', '应用类型', 'web')
|
||||
.action(async (options) => {
|
||||
const { id, type } = options;
|
||||
const app = new AppDownload(assistantConfig);
|
||||
let info = '';
|
||||
if (id) {
|
||||
const msg = await app.deleteApp({ id, type });
|
||||
info = String(msg);
|
||||
}
|
||||
logger.debug(info);
|
||||
});
|
||||
appManagerCommand.addCommand(deleteCommand);
|
||||
appManagerCommand.addCommand(downloadCommand);
|
||||
|
||||
const uploadCommand = new Command('upload')
|
||||
.description('上传应用')
|
||||
.option('-i, --id <id>', '应用名称 root/app-name 的格式,如果是后端,会自动解析为 app-name')
|
||||
.option('-t, --type <type>', '应用类型', 'web')
|
||||
.action(async (options) => {
|
||||
//
|
||||
});
|
||||
const deleteCommand = new Command('delete')
|
||||
.description('删除应用')
|
||||
.option('-i, --id <id>', '应用名称')
|
||||
.option('-t, --type <type>', '应用类型', name)
|
||||
.action(async (options) => {
|
||||
const { id, type } = options;
|
||||
const app = new AppDownload(assistantConfig);
|
||||
let info = '';
|
||||
if (id) {
|
||||
const msg = await app.deleteApp({ id, type });
|
||||
info = String(msg);
|
||||
}
|
||||
logger.debug(info);
|
||||
});
|
||||
appManagerCommand.addCommand(deleteCommand);
|
||||
|
||||
const uploadCommand = new Command('upload')
|
||||
.description('上传应用')
|
||||
.option('-i, --id <id>', '应用名称 root/app-name 的格式,如果是后端,会自动解析为 app-name')
|
||||
.option('-t, --type <type>', '应用类型', 'app')
|
||||
.action(async (options) => {
|
||||
//
|
||||
});
|
||||
};
|
||||
|
||||
commdands.forEach((name) => {
|
||||
addOneCommand(name);
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import './command/app-manager/index.ts';
|
||||
import './command/asst-server/index.ts';
|
||||
import './command/app/index.ts';
|
||||
import './command/run-scripts/index.ts';
|
||||
import './command/ai/index.ts';
|
||||
|
||||
/**
|
||||
* 通过命令行解析器解析参数
|
||||
|
||||
@@ -90,6 +90,7 @@ export type AssistantConfigData = {
|
||||
*/
|
||||
home?: string;
|
||||
ai?: {
|
||||
enabled?: boolean;
|
||||
provider?: string | 'DeepSeek' | 'SiliconFlow';
|
||||
apiKey?: string;
|
||||
model?: string;
|
||||
|
||||
@@ -79,8 +79,9 @@ program
|
||||
console.log('以守护进程方式运行');
|
||||
} else if (options.start) {
|
||||
console.log('启动服务', chalk.green(assistantConfig.configDir));
|
||||
const listenPort = options.port || assistantConfig.config?.server?.port;
|
||||
const listenPath = assistantConfig.config?.server?.path || '127.0.0.1';
|
||||
const config = assistantConfig.getCacheAssistantConfig();
|
||||
const listenPort = options.port || config?.server?.port;
|
||||
const listenPath = config?.server?.path || '127.0.0.1';
|
||||
const server = await runServer(listenPort, listenPath);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user