feat(agents): 添加 Agent 预设管理功能

- 创建 Server Agents API 路由 (CRUD + presets + defaults)
- 添加 UI Agent 类型定义和 API 客户端函数
- 实现 AgentsPanel 组件 (预设/自定义 Agent 列表)
- 实现 AgentEditor 组件 (创建/编辑 Agent)
- 实现 AgentDefaultsEditor 组件 (全局默认配置)
- 集成 AgentsPanel 到 Web 和 Desktop 应用
This commit is contained in:
2025-12-12 21:23:01 +08:00
parent 9365e07df1
commit a225e66ad7
13 changed files with 2447 additions and 5 deletions
+112
View File
@@ -24,6 +24,10 @@ import type {
FileHookConfig,
ShellCommandConfig,
HookTestResult,
AgentListItem,
AgentDetail,
AgentInput,
AgentDefaults,
} from './types.js';
// Re-export types
@@ -54,6 +58,19 @@ export type {
FileHookConfig,
ShellCommandConfig,
HookTestResult,
// Agent types
AgentMode,
AgentModelConfig,
AgentToolConfig,
PermissionRule,
AgentBashPermission,
AgentFilePermission,
AgentGitPermission,
AgentPermission,
AgentListItem,
AgentDetail,
AgentInput,
AgentDefaults,
} from './types.js';
// API Configuration
@@ -476,3 +493,98 @@ export async function testHookCommand(command: ShellCommandConfig): Promise<{
}> {
return request('POST', '/hooks/test', command);
}
// ============ Agents API ============
/**
* 获取所有 Agent 列表
*/
export async function listAgents(): Promise<{
success: boolean;
data: AgentListItem[];
error?: string;
}> {
return request('GET', '/agents');
}
/**
* 获取单个 Agent 详情
*/
export async function getAgent(name: string): Promise<{
success: boolean;
data?: AgentDetail;
error?: string;
}> {
return request('GET', `/agents/${encodeURIComponent(name)}`);
}
/**
* 创建新 Agent
*/
export async function createAgent(
name: string,
config: AgentInput
): Promise<{
success: boolean;
data?: AgentDetail;
error?: string;
}> {
return request('POST', '/agents', { name, ...config });
}
/**
* 更新 Agent
*/
export async function updateAgent(
name: string,
config: AgentInput
): Promise<{
success: boolean;
data?: AgentDetail;
error?: string;
}> {
return request('PUT', `/agents/${encodeURIComponent(name)}`, config);
}
/**
* 删除 Agent
*/
export async function deleteAgent(name: string): Promise<{
success: boolean;
error?: string;
}> {
return request('DELETE', `/agents/${encodeURIComponent(name)}`);
}
/**
* 获取预设 Agent 列表
*/
export async function listPresetAgents(): Promise<{
success: boolean;
data: AgentListItem[];
error?: string;
}> {
return request('GET', '/agents/presets');
}
/**
* 获取全局默认配置
*/
export async function getAgentDefaults(): Promise<{
success: boolean;
data: AgentDefaults;
error?: string;
}> {
return request('GET', '/agents/defaults');
}
/**
* 更新全局默认配置
*/
export async function updateAgentDefaults(defaults: AgentDefaults): Promise<{
success: boolean;
data: AgentDefaults;
error?: string;
}> {
return request('PUT', '/agents/defaults', defaults);
}