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
+40
View File
@@ -10,6 +10,10 @@ import type {
FileReadResponse,
FileTreeResponse,
ServerConfig,
CommandInfo,
CommandSearchResult,
CommandExecuteResult,
CommandListResponse,
} from './types.js';
// Re-export types
@@ -23,6 +27,10 @@ export type {
FileTreeNode,
FileTreeResponse,
ServerConfig,
CommandInfo,
CommandSearchResult,
CommandExecuteResult,
CommandListResponse,
} from './types.js';
// API Configuration
@@ -163,3 +171,35 @@ export async function updateConfig(
): Promise<{ success: boolean; data: ServerConfig }> {
return request('PATCH', '/config', config);
}
// Commands
export async function listCommands(): Promise<{ success: boolean; data: CommandListResponse }> {
return request('GET', '/commands');
}
export async function getCommand(name: string): Promise<{ success: boolean; data: CommandInfo }> {
return request('GET', `/commands/${encodeURIComponent(name)}`);
}
export async function executeCommand(
name: string,
args: string = ''
): Promise<{ success: boolean; data?: CommandExecuteResult; error?: string }> {
return request('POST', `/commands/${encodeURIComponent(name)}/execute`, {
arguments: args,
});
}
export async function searchCommands(
query: string,
limit: number = 10
): Promise<{ success: boolean; data: CommandSearchResult[] }> {
return request('POST', '/commands/search', { query, limit });
}
export async function reloadCommands(): Promise<{
success: boolean;
data: { message: string; stats: { total: number; bySource: Record<string, number> } };
}> {
return request('POST', '/commands/reload');
}
+38
View File
@@ -90,3 +90,41 @@ export interface ServerConfig {
allowedPaths: string[];
deniedPaths: string[];
}
// ============ 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>;
};
}