feat(server): 添加统一命令系统 API

- 新增 /api/commands 路由,支持列出、查询、执行和搜索命令
- Server 通过动态导入 Core 的 CommandRegistry 和 CommandExecutor
- CLI、Web、Desktop 客户端均可通过 REST API 访问斜杠命令
- 支持三层命令优先级: project > user > builtin
This commit is contained in:
2025-12-12 18:24:04 +08:00
parent ada9f890c6
commit 61735317a0
7 changed files with 508 additions and 1 deletions
+66
View File
@@ -46,6 +46,37 @@ export interface HealthStatus {
};
}
// ============ Command 相关 ============
export interface CommandInfo {
name: string;
description?: string;
agent?: string;
model?: string;
subtask?: boolean;
source: string;
hasTemplate: boolean;
}
export interface CommandSearchResult {
name: string;
description?: string;
source: string;
score: number;
}
export interface CommandExecuteResult {
prompt: string;
agent?: string;
model?: string;
subtask?: boolean;
}
export interface CommandListResponse {
commands: Array<{ name: string; description?: string; source: string }>;
stats: { total: number; bySource: Record<string, number> };
}
/**
* API Client 类
*/
@@ -180,6 +211,41 @@ export class APIClient {
? `${sseUrl}?token=${encodeURIComponent(this.token)}`
: sseUrl;
}
// ============================================================================
// Commands
// ============================================================================
async listCommands(): Promise<{ success: boolean; data: CommandListResponse }> {
return this.request('GET', '/api/commands');
}
async getCommand(name: string): Promise<{ success: boolean; data: CommandInfo }> {
return this.request('GET', `/api/commands/${encodeURIComponent(name)}`);
}
async executeCommand(
name: string,
args: string = ''
): Promise<{ success: boolean; data?: CommandExecuteResult; error?: string }> {
return this.request('POST', `/api/commands/${encodeURIComponent(name)}/execute`, {
arguments: args,
});
}
async searchCommands(
query: string,
limit: number = 10
): Promise<{ success: boolean; data: CommandSearchResult[] }> {
return this.request('POST', '/api/commands/search', { query, limit });
}
async reloadCommands(): Promise<{
success: boolean;
data: { message: string; stats: { total: number; bySource: Record<string, number> } };
}> {
return this.request('POST', '/api/commands/reload');
}
}
/**