feat(commands): 实现命令 CRUD 完整功能
Core: - 新增 CommandManager 类,支持创建、更新、删除命令 - 验证命令名称防止路径遍历攻击 - 自动生成 Markdown 文件(含 YAML frontmatter) - 内置命令保护(不可修改/删除) Server: - POST /api/commands - 创建命令 - GET /api/commands/:name/content - 获取命令完整内容 - PUT /api/commands/:name - 更新命令 - DELETE /api/commands/:name - 删除命令 UI: - 新增 createCommand、updateCommand、deleteCommand、getCommandContent 函数 - 新增 CreateCommandInput、UpdateCommandInput、CommandContent 类型
This commit is contained in:
@@ -14,6 +14,9 @@ import type {
|
||||
CommandSearchResult,
|
||||
CommandExecuteResult,
|
||||
CommandListResponse,
|
||||
CreateCommandInput,
|
||||
UpdateCommandInput,
|
||||
CommandContent,
|
||||
} from './types.js';
|
||||
|
||||
// Re-export types
|
||||
@@ -31,6 +34,9 @@ export type {
|
||||
CommandSearchResult,
|
||||
CommandExecuteResult,
|
||||
CommandListResponse,
|
||||
CreateCommandInput,
|
||||
UpdateCommandInput,
|
||||
CommandContent,
|
||||
} from './types.js';
|
||||
|
||||
// API Configuration
|
||||
@@ -203,3 +209,29 @@ export async function reloadCommands(): Promise<{
|
||||
}> {
|
||||
return request('POST', '/commands/reload');
|
||||
}
|
||||
|
||||
// Commands CRUD
|
||||
export async function createCommand(
|
||||
input: CreateCommandInput
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('POST', '/commands', input);
|
||||
}
|
||||
|
||||
export async function getCommandContent(
|
||||
name: string
|
||||
): Promise<{ success: boolean; data?: CommandContent; error?: string }> {
|
||||
return request('GET', `/commands/${encodeURIComponent(name)}/content`);
|
||||
}
|
||||
|
||||
export async function updateCommand(
|
||||
name: string,
|
||||
input: UpdateCommandInput
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('PUT', `/commands/${encodeURIComponent(name)}`, input);
|
||||
}
|
||||
|
||||
export async function deleteCommand(
|
||||
name: string
|
||||
): Promise<{ success: boolean; data?: { name: string; path: string }; error?: string }> {
|
||||
return request('DELETE', `/commands/${encodeURIComponent(name)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user