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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -281,3 +281,146 @@ export interface HookTestResult {
|
||||
/** 执行时间(毫秒) */
|
||||
duration: number;
|
||||
}
|
||||
|
||||
// ============ Agent 相关 ============
|
||||
|
||||
/** Agent 运行模式 */
|
||||
export type AgentMode = 'primary' | 'subagent' | 'all';
|
||||
|
||||
/** Agent 模型配置 */
|
||||
export interface AgentModelConfig {
|
||||
/** 提供商 */
|
||||
provider?: 'anthropic' | 'deepseek' | 'openai';
|
||||
/** 模型名称 */
|
||||
model?: string;
|
||||
/** 温度参数 (0-1) */
|
||||
temperature?: number;
|
||||
/** Top-P 采样 */
|
||||
topP?: number;
|
||||
/** 最大 Token 数 */
|
||||
maxTokens?: number;
|
||||
}
|
||||
|
||||
/** Agent 工具配置 */
|
||||
export interface AgentToolConfig {
|
||||
/** 禁用的工具列表 */
|
||||
disabled?: string[];
|
||||
/** 只启用的工具列表(与 disabled 互斥) */
|
||||
enabled?: string[];
|
||||
/** 禁止嵌套 Task 调用 */
|
||||
noTask?: boolean;
|
||||
}
|
||||
|
||||
/** 权限规则 */
|
||||
export interface PermissionRule {
|
||||
/** 匹配模式(glob 或正则) */
|
||||
pattern: string;
|
||||
/** 操作:允许或拒绝 */
|
||||
action: 'allow' | 'deny';
|
||||
}
|
||||
|
||||
/** Bash 权限配置 */
|
||||
export interface AgentBashPermission {
|
||||
/** 规则列表 */
|
||||
rules?: PermissionRule[];
|
||||
/** 默认操作 */
|
||||
defaultAction?: 'allow' | 'deny';
|
||||
}
|
||||
|
||||
/** 文件权限配置 */
|
||||
export interface AgentFilePermission {
|
||||
/** 读取权限 */
|
||||
read?: { rules?: PermissionRule[]; defaultAction?: 'allow' | 'deny' };
|
||||
/** 写入权限 */
|
||||
write?: { rules?: PermissionRule[]; defaultAction?: 'allow' | 'deny' };
|
||||
}
|
||||
|
||||
/** Git 权限配置 */
|
||||
export interface AgentGitPermission {
|
||||
/** 允许的命令 */
|
||||
commands?: string[];
|
||||
/** 是否允许 push */
|
||||
allowPush?: boolean;
|
||||
/** 是否允许 force 操作 */
|
||||
allowForce?: boolean;
|
||||
}
|
||||
|
||||
/** Agent 权限配置 */
|
||||
export interface AgentPermission {
|
||||
/** Bash 命令权限 */
|
||||
bash?: AgentBashPermission;
|
||||
/** 文件操作权限 */
|
||||
file?: AgentFilePermission;
|
||||
/** Git 操作权限 */
|
||||
git?: AgentGitPermission;
|
||||
}
|
||||
|
||||
/** Agent 列表项 */
|
||||
export interface AgentListItem {
|
||||
/** Agent 名称 */
|
||||
name: string;
|
||||
/** 描述 */
|
||||
description: string;
|
||||
/** 运行模式 */
|
||||
mode: AgentMode;
|
||||
/** 是否为预设 Agent */
|
||||
isPreset: boolean;
|
||||
/** 是否被用户自定义覆盖 */
|
||||
isCustomized: boolean;
|
||||
/** 使用的模型 */
|
||||
model?: string;
|
||||
/** 最大执行步数 */
|
||||
maxSteps?: number;
|
||||
}
|
||||
|
||||
/** Agent 完整详情 */
|
||||
export interface AgentDetail {
|
||||
/** Agent 名称 */
|
||||
name: string;
|
||||
/** 描述 */
|
||||
description: string;
|
||||
/** 运行模式 */
|
||||
mode: AgentMode;
|
||||
/** 是否为预设 */
|
||||
isPreset: boolean;
|
||||
/** 是否被自定义 */
|
||||
isCustomized?: boolean;
|
||||
/** System Prompt */
|
||||
prompt?: string;
|
||||
/** 模型配置 */
|
||||
model?: AgentModelConfig;
|
||||
/** 工具配置 */
|
||||
tools?: AgentToolConfig;
|
||||
/** 权限配置 */
|
||||
permission?: AgentPermission;
|
||||
/** 最大执行步数 */
|
||||
maxSteps?: number;
|
||||
}
|
||||
|
||||
/** 创建/更新 Agent 输入 */
|
||||
export interface AgentInput {
|
||||
/** 描述 */
|
||||
description: string;
|
||||
/** 运行模式 */
|
||||
mode: AgentMode;
|
||||
/** System Prompt */
|
||||
prompt?: string;
|
||||
/** 模型配置 */
|
||||
model?: AgentModelConfig;
|
||||
/** 工具配置 */
|
||||
tools?: AgentToolConfig;
|
||||
/** 权限配置 */
|
||||
permission?: AgentPermission;
|
||||
/** 最大执行步数 */
|
||||
maxSteps?: number;
|
||||
}
|
||||
|
||||
/** 全局默认配置 */
|
||||
export interface AgentDefaults {
|
||||
/** 最大执行步数 */
|
||||
maxSteps?: number;
|
||||
/** 模型配置 */
|
||||
model?: AgentModelConfig;
|
||||
/** 权限配置 */
|
||||
permission?: AgentPermission;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user