feat(server): 添加统一命令系统 API
- 新增 /api/commands 路由,支持列出、查询、执行和搜索命令 - Server 通过动态导入 Core 的 CommandRegistry 和 CommandExecutor - CLI、Web、Desktop 客户端均可通过 REST API 访问斜杠命令 - 支持三层命令优先级: project > user > builtin
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user