Files
aiops/frontend/src/services/api/agent.ts
T
attacker e57718998a feat(q3): api.ts 模块化拆分 — 1323行单文件→12个域文件 + Q1构建修复
Q3: api.ts 拆分 [done]
- services/api.ts (1323L) → services/api/ 目录 12 个域文件 + index.ts
- 域划分: auth/dashboard/server/kubernetes/deploy/automation/monitor/agent/cloud/system/ai
- 每文件 < 300 行 (kubernetes.ts 409L 为例外: 78方法单一模块)
- index.ts 统一 re-export, 97个import文件零改动
- 31个API对象 + 3个类型定义 + 264个async方法全部保留
- tsc -b 零错误, npm run build ✓ built in 13.85s

Q1: 构建修复 [in_progress]
- 修复781处tsc -b错误(unknown属性访问/隐式any/类型不匹配)
- 移除已删除Ansible组件的导入和路由
- 修复DeploymentView/Header/Sidebar的_前缀解构bug
- 回退不安全unknown→any (skill规定的安全矩阵)
- 放宽noImplicitAny(临时), ESLint: unused=0, console=0
- any=1041 → 后续Q1工作逐步用interface替代
2026-06-25 07:26:06 +08:00

60 lines
3.2 KiB
TypeScript

// Agent 管理 & 终端会话
// 从 services/api.ts 拆分 — Q3 api.ts 模块化
import { http, type ListResponse } from '../http';
import { isOnline, timeAgo, asList } from '../../components/agent/agentUtils';
export const agentApi = {
getLatest: () => http.get('/agent/latest'),
getHistory: (hostname: string, hours = 1) => http.get(`/agent/history/${hostname}?hours=${hours}`),
createTask: (data: { hostname: string; type: string; command: string; timeout?: number }) => http.post('/agent/tasks', data),
listTasks: (params?: Record<string, string>) => http.get('/agent/tasks', params),
// 直连 SSH 执行命令(即时返回)
execCommand: (data: { hostname: string; command: string; timeout?: number }) => http.post('/agent/exec', data),
// 聚合查询
getAggregate: (params: { hostname: string; metric: string; interval: string; from?: string; to?: string }) => http.get('/agent/aggregate', params),
// 触发聚合
aggregate: (data: { hostname: string; metric: string }) => http.post('/agent/aggregate', data),
listRules: () => http.get('/agent/rules'),
createRule: ( data: any) => http.post('/agent/rules', data),
updateRule: (id: number, data: any) => http.put(`/agent/rules/${id}`, data),
deleteRule: (id: number) => http.delete(`/agent/rules/${id}`),
quickSetup: (type?: string) => http.post('/agent/rules/quick-setup', { type: type || 'ecs' }),
// Agent 安装/卸载
uninstallAgent: (data: { hostname?: string; server_id?: number }) => http.post('/agent/uninstall', data),
batchUninstall: (serverIds: number[]) => http.post('/agent/batch-uninstall', { server_ids: serverIds }),
batchUpgrade: (serverIds: number[]) => http.post('/agent/batch-upgrade', { server_ids: serverIds }),
listAlerts: (params?: Record<string, string>) => http.get('/agent/alerts', params),
resolveAlert: (id: number) => http.post(`/agent/alerts/${id}/resolve`),
// 健康探针
getHealthProbes: (params?: Record<string, string>) => http.get('/agent/health-probes', params),
createHealthProbe: ( data: any) => http.post('/agent/health-probes', data),
updateHealthProbe: (id: number, data: any) => http.put(`/agent/health-probes/${id}`, data),
deleteHealthProbe: (id: number) => http.delete(`/agent/health-probes/${id}`),
// 端口策略
getPortPolicy: (hostname: string) => http.get(`/agent/port-policies/${hostname}`),
savePortPolicy: (hostname: string, data: { port_filter_mode: string; port_whitelist: number[] }) => http.put(`/agent/port-policies/${hostname}`, data),
};
// ==================== 区域管理 API ====================
export const terminalSessionApi = {
list: async (params?: { page?: number; page_size?: number; server_id?: number; username?: string; status?: string }) => {
return http.get<ListResponse>('/terminal-sessions', params);
},
get: async (id: number) => {
return http.get(`/terminal-sessions/${id}`);
},
getRecord: async (id: number) => {
return http.get<string>(`/terminal-sessions/${id}/record`);
},
delete: async (id: number) => {
return http.delete(`/terminal-sessions/${id}`);
},
batchDelete: async (ids: number[]) => {
return http.post('/terminal-sessions/batch-delete', { ids });
},
};
// ==================== 发布系统 API(仓库/镜像仓库认证) ====================