feat: add zod dependency and implement kevisual routes for CLI commands
- Added zod as a dependency in package.json. - Enhanced assistant configuration to include skills and plugins directories. - Implemented runCmd function to execute CLI commands in run.ts. - Updated light-code module to use node:child_process. - Created new kevisual routes for checking CLI login status and deploying web pages. - Added restart functionality for OpenCode client in opencode module.
This commit is contained in:
@@ -5,6 +5,7 @@ import { checkFileExists, createDir } from '../file/index.ts';
|
||||
import { ProxyInfo } from '../proxy/proxy.ts';
|
||||
import dotenv from 'dotenv';
|
||||
import { logger } from '@/module/logger.ts';
|
||||
import { z } from 'zod'
|
||||
|
||||
let kevisualDir = path.join(homedir(), 'kevisual');
|
||||
const envKevisualDir = process.env.ASSISTANT_CONFIG_DIR
|
||||
@@ -28,12 +29,15 @@ export const initConfig = (configRootPath: string) => {
|
||||
const pageConfigPath = path.join(configDir, 'assistant-page-config.json');
|
||||
const pagesDir = createDir(path.join(configDir, 'pages'));
|
||||
const appsDir = createDir(path.join(configDir, 'apps'));
|
||||
const skillsDir = createDir(path.join(configDir, 'skills'), false);
|
||||
const pluginsDir = createDir(path.join(configDir, 'plugins'), false);
|
||||
|
||||
const appsConfigPath = path.join(configDir, 'assistant-apps-config.json');
|
||||
const appPidPath = path.join(configDir, 'assistant-app.pid');
|
||||
const envConfigPath = path.join(configDir, '.env');
|
||||
return {
|
||||
/**
|
||||
* 助手配置文件路径
|
||||
* 助手配置文件路径, assistant-app 目录
|
||||
*/
|
||||
configDir,
|
||||
/**
|
||||
@@ -41,7 +45,7 @@ export const initConfig = (configRootPath: string) => {
|
||||
*/
|
||||
configPath,
|
||||
/**
|
||||
* 服务目录, 后端服务目录
|
||||
* 服务目录, 后端服务目录, apps 目录
|
||||
*/
|
||||
appsDir,
|
||||
/**
|
||||
@@ -49,7 +53,7 @@ export const initConfig = (configRootPath: string) => {
|
||||
*/
|
||||
appsConfigPath,
|
||||
/**
|
||||
* 应用目录, 前端应用目录
|
||||
* 应用目录, 前端应用目录, pages 目录
|
||||
*/
|
||||
pagesDir,
|
||||
/**
|
||||
@@ -64,6 +68,14 @@ export const initConfig = (configRootPath: string) => {
|
||||
* 环境变量配置文件路径
|
||||
*/
|
||||
envConfigPath,
|
||||
/**
|
||||
* 技能目录,配置给 opencode 去用的
|
||||
*/
|
||||
skillsDir,
|
||||
/**
|
||||
* 插件目录, 给 cli 用的,动态加载插件,每一个都是独立的
|
||||
*/
|
||||
pluginsDir,
|
||||
};
|
||||
};
|
||||
export type ReturnInitConfigType = ReturnType<typeof initConfig>;
|
||||
|
||||
49
assistant/src/module/cmd/run.ts
Normal file
49
assistant/src/module/cmd/run.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
|
||||
type RunCmdOptions = {
|
||||
cmd: string;
|
||||
cwd?: string;
|
||||
env?: Record<string, string>;
|
||||
}
|
||||
|
||||
type RunResult = {
|
||||
code: number;
|
||||
data: string;
|
||||
}
|
||||
/**
|
||||
* 运行命令行指令
|
||||
* @param opts
|
||||
* @returns
|
||||
*/
|
||||
export const runCmd = (opts: RunCmdOptions): Promise<RunResult> => {
|
||||
const { cmd, cwd } = opts || {};
|
||||
return new Promise<RunResult>((resolve) => {
|
||||
const parts = cmd.split(' ');
|
||||
const command = parts[0];
|
||||
const args = parts.slice(1);
|
||||
const proc = spawn(command, args, {
|
||||
cwd: cwd || process.cwd(),
|
||||
shell: true,
|
||||
env: { ...process.env, ...opts?.env },
|
||||
});
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
let result = ''
|
||||
proc.stdout.on('data', (data: Buffer) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
proc.stderr.on('data', (data: Buffer) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
proc.on('close', (code: number) => {
|
||||
result = stdout;
|
||||
if (stderr) {
|
||||
result += '\n' + stderr;
|
||||
}
|
||||
resolve({ code: code === 0 ? 200 : code, data: result });
|
||||
});
|
||||
proc.on('error', (err: Error) => {
|
||||
resolve({ code: 500, data: err.message });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { fork } from 'child_process'
|
||||
import { fork } from 'node:child_process'
|
||||
import fs from 'fs';
|
||||
|
||||
export const fileExists = (path: string): boolean => {
|
||||
|
||||
Reference in New Issue
Block a user