feat(client): add routes for version, time, system info, and restart functionality
This commit is contained in:
@@ -85,6 +85,7 @@ type AuthPermission = {
|
||||
username?: string; // 用户名
|
||||
admin?: string[];
|
||||
};
|
||||
type AssistantRoutes = { type: "npm" | "file", path: string } | string
|
||||
export type AssistantConfigData = {
|
||||
app?: {
|
||||
/**
|
||||
@@ -117,6 +118,7 @@ export type AssistantConfigData = {
|
||||
base?: boolean;
|
||||
lightcode?: boolean;
|
||||
}
|
||||
routes?: AssistantRoutes[],
|
||||
/**
|
||||
* API 代理配置, 比如,api开头的,v1开头的等等
|
||||
*/
|
||||
@@ -418,10 +420,27 @@ export const parseHomeArg = (homedir?: string) => {
|
||||
}
|
||||
const checkUrl = ['.opencode', 'bin/opencode', 'opencode.exe']
|
||||
const isOpencode = checkUrl.some((item) => execPath.includes(item))
|
||||
let isServer = false;
|
||||
// 如果args包含 server 则认为是服务端运行。其中config中server必须存在
|
||||
console.log('parseHomeArg args:', args);
|
||||
if (args.includes('server') || args.includes('assistant-server')) {
|
||||
let isDaemon = false;
|
||||
// 判断 --daemon 参数, 如果有则认为是守护进程运行
|
||||
if (args.includes('--daemon') || args.includes('-d')) {
|
||||
isDaemon = true;
|
||||
}
|
||||
if (!isDaemon) {
|
||||
// 判断 -s 或者 --start 参数
|
||||
if (args.includes('-s') || args.includes('--start')) {
|
||||
isServer = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
isOpencode,
|
||||
options,
|
||||
configDir: _configDir,
|
||||
isServer
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -211,4 +211,22 @@ export class AssistantApp extends Manager {
|
||||
}
|
||||
}
|
||||
}
|
||||
async initRoutes() {
|
||||
// TODO 初始化应用内置路由
|
||||
const routes = this.config.getConfig().routes || [];
|
||||
for (const route of routes) {
|
||||
try {
|
||||
if (typeof route === 'string') {
|
||||
await import(route);
|
||||
console.log('安装路由', route);
|
||||
} else if (typeof route === 'object' && route.path) {
|
||||
const routePath = route.path;
|
||||
await import(routePath);
|
||||
console.log('安装路由', routePath);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('初始化路由失败', route, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChildProcess, fork, ForkOptions } from 'child_process';
|
||||
import { ChildProcess, fork, ForkOptions } from 'node:child_process';
|
||||
class BaseProcess {
|
||||
private process: ChildProcess;
|
||||
status: 'running' | 'stopped' | 'error' = 'stopped';
|
||||
|
||||
Reference in New Issue
Block a user