feat: 新增 Agent CLI — Web 版 AI 运维 Agent(参考 opsxcli 移植)
后端引擎 backend/pkg/agentcli/(纯引擎库,零业务依赖,剥离 CLI/TUI 外壳): - llm: OpenAI 兼容客户端,复用 model.LLMConfig - tools: ssh_execute(复用 pkg/remoteexec)+ analyze_output + 风险评估黑名单 - safety: 三级安全模式 + 五级风险 + WebSocket 异步确认 - prompt: 五层 System Prompt - core: ReAct 16 轮循环 + 自适应检查点 + 循环检测 - evolver: 四层记忆 + 进化循环,data/agentcli/ 文件存储 集成层: - controller/agent_cli.go: WebSocket 控制器(事件流推流 + 高危确认 + 会话持久化) - model/agent_cli.go: agent_cli_sessions/messages 表 + AutoMigrate - 路由 /ws/agent-cli + /api/v1/aiops/agent-cli/sessions - seed 权限 aiops:agent-cli / aiops:llm-config 前端: - AgentCLI.tsx: 对话流 + 工具块 + 高危确认 + 四模块 tips 面板 - LLMConfig.tsx: 大模型设置独立页 - api/agentCli.ts + Sidebar/App 菜单路由 文档: - docs/agent/ 11 篇(opsxcli 同名文档适配改写 + 00-README 映射总览) 其他: - CLAUDE.md 补充 agent-cli 模块说明 - 修正 .gitignore 根级二进制规则(前导 /,避免误伤 frontend/src/components/aiops/) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
f2069fe3f0
commit
92a2247390
37 files changed
+6449
-6
No files matched your search
@@ -0,0 +1,62 @@
|
||||
// Agent CLI API — WebSocket 连接 + 会话历史 REST // Logan.Li
|
||||
import { http } from '@/utils/request';
|
||||
import { useUserStore } from '@/store';
|
||||
|
||||
// 会话与消息类型(与后端 model.AgentCLISession/Message 对应) // Logan.Li
|
||||
export interface AgentCliSession {
|
||||
id: number;
|
||||
user_id: number;
|
||||
server_id: number;
|
||||
server_name: string;
|
||||
server_host: string;
|
||||
title: string;
|
||||
status: string; // running/done/aborted/error
|
||||
provider: string;
|
||||
model: string;
|
||||
rounds: number;
|
||||
total_tokens: number;
|
||||
duration: number;
|
||||
error?: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface AgentCliMessage {
|
||||
id: number;
|
||||
session_id: number;
|
||||
round: number;
|
||||
type: string; // thought/tool_call/tool_result/done/error/user
|
||||
role: string;
|
||||
content: string;
|
||||
tool_name: string;
|
||||
tool_args: string;
|
||||
tool_output: string;
|
||||
risk: string;
|
||||
success: boolean;
|
||||
duration: string;
|
||||
tokens: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export const agentCliApi = {
|
||||
// 会话列表(按当前用户隔离)
|
||||
getSessions: async (params?: { server_id?: number; page?: number; page_size?: number }) => {
|
||||
return http.get<{ list: AgentCliSession[]; total: number }>('/aiops/agent-cli/sessions', params);
|
||||
},
|
||||
// 会话详情(含完整推理消息,供回放)
|
||||
getSession: async (id: number | string) => {
|
||||
return http.get<{ session: AgentCliSession; messages: AgentCliMessage[] }>(`/aiops/agent-cli/sessions/${id}`);
|
||||
},
|
||||
// 删除会话
|
||||
deleteSession: async (id: number | string) => {
|
||||
return http.delete(`/aiops/agent-cli/sessions/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// buildAgentCliWsUrl 构造 Agent CLI WebSocket 地址(浏览器无法设 header,用 ?token= 回退) // Logan.Li
|
||||
export function buildAgentCliWsUrl(serverId: number | string): string {
|
||||
const proto = typeof location !== 'undefined' && location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
// Token 双保险:store 优先,localStorage 兜底 // Logan.Li
|
||||
const token = useUserStore.getState().token || localStorage.getItem('token') || '';
|
||||
return `${proto}://${location.host}/ws/agent-cli?id=${serverId}&token=${encodeURIComponent(token)}`;
|
||||
}
|
||||
@@ -12,3 +12,4 @@ export * from './agent';
|
||||
export * from './cloud';
|
||||
export * from './system';
|
||||
export * from './ai';
|
||||
export * from './agentCli';
|
||||
Reference in new issue
Block a user