超级管理员完整

This commit is contained in:
zhanggangyong
2026-01-06 16:00:33 +00:00
parent 92c9d6ea68
commit 81bb3146ff
9 changed files with 6068 additions and 62 deletions
+640
View File
@@ -0,0 +1,640 @@
# Taiji-AI-PAD 项目 API 接口完整清单
本文档列出了项目中所有的 API 接口,包括接口路径、HTTP 方法、功能描述和权限要求。
---
## 目录
1. [MCP-Server 服务接口](#mcp-server-服务接口)
- [认证模块 (auth.py)](#1-认证模块-authpy)
- [超级管理员 API (admin.py)](#2-超级管理员-api-adminpy)
- [用户侧平台 API (user.py)](#3-用户侧平台-api-userpy)
- [渠道合作伙伴 API (channel.py)](#4-渠道合作伙伴-api-channelpy)
- [Agent 管理 (agents.py)](#5-agent-管理-agentspy)
- [供应商管理 (providers.py)](#6-供应商管理-providerspy)
- [会话管理 (sessions.py)](#7-会话管理-sessionspy)
- [工具管理 (tools.py)](#8-工具管理-toolspy)
- [WebSocket (websocket.py)](#9-websocket-websocketpy)
- [计费与资源管理 (billing_admin.py)](#10-计费与资源管理-billing_adminpy)
- [配额管理 (quota_management.py)](#11-配额管理-quota_managementpy)
- [平台 Agent 配额 (platform_agent_quota.py)](#12-平台-agent-配额-platform_agent_quotapy)
- [审计日志管理 (audit_management.py)](#13-审计日志管理-audit_managementpy)
- [事件管理 (event_management.py)](#14-事件管理-event_managementpy)
- [追踪管理 (trace_management.py)](#15-追踪管理-trace_managementpy)
- [定价管理 (pricing_management.py)](#16-定价管理-pricing_managementpy)
- [供应商健康检查 (provider_health_management.py)](#17-供应商健康检查-provider_health_managementpy)
- [资源监控 (resource_monitoring.py)](#18-资源监控-resource_monitoringpy)
- [前端集成 (frontend_integration.py)](#19-前端集成-frontend_integrationpy)
- [监控 (monitoring.py)](#20-监控-monitoringpy)
- [健康检查 (health.py)](#21-健康检查-healthpy)
- [Prometheus 指标 (metrics.py)](#22-prometheus-指标-metricspy)
2. [Data-Ingestion 服务接口](#data-ingestion-服务接口)
---
## MCP-Server 服务接口
### 1. 认证模块 (auth.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/auth/login` | 统一登录接口,支持用户/渠道/管理员/供应商登录 | 无 |
| POST | `/api/auth/logout` | 用户登出,将 token 加入黑名单 | 已认证用户 |
| POST | `/api/auth/refresh` | 刷新访问令牌 | 已认证用户 |
| PUT | `/api/auth/password` | 修改密码 | 已认证用户 |
| GET | `/api/auth/keys/info` | 获取当前用户的 API 密钥信息 | 已认证用户 |
| POST | `/api/auth/keys/regenerate` | 重新生成 API 密钥 | 已认证用户 |
---
### 2. 超级管理员 API (admin.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/admin/admins` | 获取管理员列表 | super_admin |
| POST | `/api/admin/admins/create` | 创建管理员 | super_admin |
| DELETE | `/api/admin/admins/{admin_id}` | 删除管理员 | super_admin |
| GET | `/api/admin/dashboard/recent-logins` | 获取最近登录的租户列表 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/dashboard/stats` | 获取平台全局统计数据 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/tenants` | 获取所有租户列表 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/channels` | 获取渠道列表 | super_admin, billing_admin, operations_admin |
| POST | `/api/admin/channels/create` | 创建渠道 | super_admin, billing_admin |
| PUT | `/api/admin/channels/{channel_id}` | 更新渠道信息 | super_admin, billing_admin |
| DELETE | `/api/admin/channels/{channel_id}` | 删除渠道 | super_admin |
| GET | `/api/admin/channels/{channel_id}/resources` | 获取渠道资源配置 | super_admin, billing_admin, operations_admin |
| PUT | `/api/admin/channels/{channel_id}/resources` | 分配渠道资源 | super_admin, billing_admin |
| PUT | `/api/admin/channels/{channel_id}/commission` | 更新渠道佣金比例 | super_admin, billing_admin |
| GET | `/api/admin/resources/allocation-stats` | 获取资源分配统计 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/channels/applications` | 获取渠道资源申请列表 | super_admin, billing_admin |
| PUT | `/api/admin/channels/applications/{application_id}/review` | 审批渠道资源申请 | super_admin, billing_admin |
| GET | `/api/admin/resources/models` | 获取模型供应商列表 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/resources/agents` | 获取所有 Agent 资源 | super_admin, billing_admin, operations_admin |
| DELETE | `/api/admin/resources/agents/{agent_id}` | 删除 Agent 资源 | super_admin |
| PUT | `/api/admin/resources/agents/{agent_id}/config` | 更新 Agent 配置 | super_admin, billing_admin |
| GET | `/api/admin/monitoring/agents` | 监控 Agent 健康状态 | super_admin, billing_admin, operations_admin |
| GET | `/api/admin/billing/overview` | 获取三维度计费统计 | super_admin, billing_admin |
| GET | `/api/admin/providers/applications` | 获取供应商申请列表 | super_admin, billing_admin |
| PUT | `/api/admin/providers/applications/{application_id}/review` | 审批供应商申请 | super_admin, billing_admin |
| GET | `/api/admin/providers/access` | 获取渠道供应商授权列表 | super_admin, billing_admin, operations_admin |
| PUT | `/api/admin/providers/access/{access_id}` | 更新供应商授权 | super_admin, billing_admin |
| DELETE | `/api/admin/providers/access/{access_id}` | 撤销供应商授权 | super_admin |
| GET | `/api/admin/channels/{channel_id}/admins` | 获取渠道管理员列表 | super_admin, billing_admin |
| GET | `/api/admin/roles` | 获取可用角色列表 | super_admin |
| GET | `/api/admin/platform-agents/templates` | 获取平台 Agent 模板列表 | super_admin, billing_admin |
| GET | `/api/admin/applications/platform-agents` | 获取平台 Agent 申请列表 | super_admin, billing_admin |
| PUT | `/api/admin/applications/platform-agents/{application_id}/review` | 审批平台 Agent 申请 | super_admin, billing_admin |
| GET | `/api/admin/platform-agents/allocations` | 查看平台 Agent 分配情况 | super_admin, billing_admin, operations_admin |
| POST | `/api/admin/platform-agents/allocate` | 直接分配平台 Agent 配额 | super_admin, billing_admin |
| DELETE | `/api/admin/platform-agents/allocate` | 撤销平台 Agent 配额 | super_admin |
| GET | `/api/admin/platform-agents/status` | 查看平台 Agent 运行状态 | super_admin, billing_admin, operations_admin |
---
### 3. 用户侧平台 API (user.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/user/dashboard/stats` | 获取用户仪表板统计数据 | 已认证用户 |
| GET | `/api/user/agents/activity` | 获取 Agent 活动数据 | 已认证用户 |
| POST | `/api/user/gateway/select` | 选择网关类型 (MCP/A2A/API) | 已认证用户 |
| POST | `/api/user/gateway/api/create` | 创建网关 API | 已认证用户 |
| GET | `/api/user/gateway/apis` | 获取网关 API 列表 | 已认证用户 |
| GET | `/api/user/gateway/monitoring` | 获取网关监控数据 | 已认证用户 |
| GET | `/api/user/custom-agent-quota` | 获取自定义 Agent 配额 | 已认证用户 |
| POST | `/api/user/tools/generate` | 生成工具(创建自定义 Agent) | 已认证用户 |
| POST | `/api/user/data-templates/create` | 创建数据模板 | 已认证用户 |
| GET | `/api/user/agents/platform` | 获取平台 Agent 列表 | 已认证用户 |
| POST | `/api/user/agents/deploy` | 部署 Agent 到 K8s | 已认证用户 |
| POST | `/api/user/workflows/create` | 创建工作流 | 已认证用户 |
| GET | `/api/user/billing/balance` | 获取余额信息 | 已认证用户 |
| POST | `/api/user/billing/recharge` | 充值余额 | 已认证用户 |
| GET | `/api/user/billing/history` | 获取计费历史 | 已认证用户 |
| GET | `/api/user/platform-agents/available` | 获取可用平台 Agent | 已认证用户 |
| POST | `/api/user/platform-agents/use` | 使用平台 Agent | 已认证用户 |
| DELETE | `/api/user/platform-agents/{instance_name}` | 停止平台 Agent | 已认证用户 |
| GET | `/api/user/platform-agents/instances` | 获取平台 Agent 实例列表 | 已认证用户 |
| GET | `/api/user/custom-agents/templates` | 获取自定义 Agent 模板 | 已认证用户 |
| POST | `/api/user/custom-agents` | 创建自定义 Agent | 已认证用户 |
| DELETE | `/api/user/custom-agents/{name}` | 删除自定义 Agent | 已认证用户 |
| PUT | `/api/user/custom-agents/{name}/scale` | 扩缩容自定义 Agent | 已认证用户 |
| GET | `/api/user/custom-agents` | 获取自定义 Agent 列表 | 已认证用户 |
| GET | `/api/user/custom-agents/{name}/logs` | 获取 Agent 日志 | 已认证用户 |
| POST | `/api/user/custom-agents/{name}/restart` | 重启 Agent | 已认证用户 |
| GET | `/api/user/agent-billing/stats` | 获取 Agent 计费统计 | 已认证用户 |
| GET | `/api/user/agent-billing/history` | 获取 Agent 计费历史 | 已认证用户 |
---
### 4. 渠道合作伙伴 API (channel.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/channel/tenants` | 获取渠道下租户列表 | channel_admin |
| POST | `/api/channel/tenants/create` | 创建租户 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/resources` | 分配租户资源 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/billing` | 更新租户计费设置 | channel_admin |
| POST | `/api/channel/tenants/{tenant_id}/recharge` | 为租户充值 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/credit` | 设置租户授信额度 | channel_admin |
| DELETE | `/api/channel/tenants/{tenant_id}` | 删除租户 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/status` | 更新租户状态 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/permissions` | 更新租户权限 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/password` | 重置租户密码 | channel_admin |
| GET | `/api/channel/tenants/{tenant_id}/custom-agent-quota` | 获取租户自定义 Agent 配额 | channel_admin |
| POST | `/api/channel/admins/create` | 创建渠道管理员 | channel_admin |
| GET | `/api/channel/admins` | 获取渠道管理员列表 | channel_admin |
| POST | `/api/channel/resources/apply` | 申请资源 | channel_admin |
| GET | `/api/channel/billing/stats` | 获取渠道计费统计 | channel_admin |
| GET | `/api/channel/providers` | 获取可用供应商列表 | channel_admin |
| POST | `/api/channel/providers/apply` | 申请使用供应商 | channel_admin |
| GET | `/api/channel/providers/applications` | 获取供应商申请列表 | channel_admin |
| GET | `/api/channel/providers/access` | 获取已授权供应商列表 | channel_admin |
| GET | `/api/channel/available-platform-agents` | 查看可用平台 Agent 模板 | channel_admin |
| POST | `/api/channel/applications/platform-agents` | 申请平台 Agent | channel_admin |
| GET | `/api/channel/applications/platform-agents` | 查看平台 Agent 申请列表 | channel_admin |
| GET | `/api/channel/platform-agents` | 查看渠道平台 Agent 配额 | channel_admin |
| POST | `/api/channel/tenants/{tenant_id}/platform-agents` | 分配平台 Agent 给租户 | channel_admin |
| GET | `/api/channel/tenants/{tenant_id}/platform-agents/usage` | 查看租户平台 Agent 使用情况 | channel_admin |
| GET | `/api/channel/agent-billing/stats` | 获取渠道 Agent 计费统计 | channel_admin |
| GET | `/api/channel/agent-billing/history` | 获取渠道 Agent 计费历史 | channel_admin |
| GET | `/api/channel/agent-billing/tenant-summary` | 获取租户 Agent 计费汇总 | channel_admin |
---
### 5. Agent 管理 (agents.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/agents/templates` | 获取所有 Agent 模板 | 已认证用户 |
| GET | `/agents/templates/platform` | 获取平台 Agent 模板 | 已认证用户 |
| GET | `/agents/templates/custom` | 获取自定义 Agent 模板 | 已认证用户 |
| GET | `/agents/templates/{template_name}` | 获取模板详情 | 已认证用户 |
| POST | `/agents` | 创建 Agent | 已认证用户 |
| GET | `/agents` | 获取 Agent 列表 | 已认证用户 |
| GET | `/agents/{agent_id}` | 获取 Agent 详情 | 已认证用户 |
| DELETE | `/agents/{agent_id}` | 删除 Agent | 已认证用户 |
| GET | `/agents/{agent_id}/status` | 获取 Agent 实时状态 | 已认证用户 |
| GET | `/agents/{agent_id}/metrics` | 获取 Agent 资源使用 | 已认证用户 |
| POST | `/agents/{agent_id}/execute` | 执行 Agent 任务 | 已认证用户 |
---
### 6. 供应商管理 (providers.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/providers/models` | 获取所有模型供应商 | 已认证用户 |
| POST | `/api/providers/models/create` | 创建模型供应商 | super_admin, billing_admin |
| GET | `/api/providers/models/{provider_id}` | 获取供应商详情 | 已认证用户 |
| PUT | `/api/providers/models/{provider_id}` | 更新供应商配置 | super_admin, billing_admin |
| DELETE | `/api/providers/models/{provider_id}` | 删除供应商 | super_admin |
| POST | `/api/providers/models/{provider_id}/test` | 测试供应商连接 | super_admin, billing_admin |
---
### 7. 会话管理 (sessions.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/sessions` | 创建会话 | 已认证用户 |
| GET | `/sessions` | 获取会话列表 | 已认证用户 |
| GET | `/sessions/{session_id}` | 获取会话详情 | 已认证用户 |
| PUT | `/sessions/{session_id}/complete` | 完成会话 | 已认证用户 |
| DELETE | `/sessions/{session_id}` | 删除会话 | 已认证用户 |
| POST | `/sessions/cleanup` | 清理旧会话 | 已认证用户 |
---
### 8. 工具管理 (tools.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/tools` | 获取工具列表 | 已认证用户 |
| GET | `/tools/{tool_id}` | 获取工具详情 | 已认证用户 |
| POST | `/tools` | 创建工具 | 已认证用户 |
| PUT | `/tools/{tool_id}` | 更新工具 | 已认证用户 |
| DELETE | `/tools/{tool_id}` | 删除工具 | 已认证用户 |
| GET | `/tools/categories/list` | 获取工具分类列表 | 已认证用户 |
---
### 9. WebSocket (websocket.py)
| 协议 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| WS | `/ws/{agent_name_or_id}` | WebSocket 实时 MCP 交互 | 已认证用户 |
**功能说明**:
- 支持连接池管理(最大 1000 连接)
- 心跳机制(每 30 秒)
- 消息队列
- 自动清理超时连接(90 秒无心跳)
---
### 10. 计费与资源管理 (billing_admin.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/quota/user/{user_id}` | 获取用户配额信息 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/quota/channel/{channel_id}` | 获取渠道配额信息 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/quota/alerts` | 获取配额预警列表 | super_admin, billing_admin, operations_admin |
| PUT | `/api/billing-admin/quota/alerts/{alert_id}/acknowledge` | 确认配额预警 | super_admin, billing_admin, operations_admin |
| PUT | `/api/billing-admin/quota/alerts/{alert_id}/resolve` | 解决配额预警 | super_admin, billing_admin |
| GET | `/api/billing-admin/resources/overview` | 获取平台资源概览 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/user/{user_id}` | 获取用户资源使用汇总 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/trends` | 获取资源使用趋势 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/agent/{agent_id}` | 获取 Agent 资源统计 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/events/pending` | 获取待处理事件 | super_admin, billing_admin, operations_admin |
| POST | `/api/billing-admin/events/retry-failed` | 重试失败事件 | super_admin, billing_admin |
| GET | `/api/billing-admin/events/stats` | 获取事件统计 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/traces/execution/{execution_id}` | 获取执行追踪详情 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/traces` | 查询追踪记录 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/traces/stats` | 获取追踪统计 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/audit/logs` | 查询审计日志 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/audit/summary` | 获取审计日志汇总 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/audit/user/{user_id}/activity` | 获取用户活动历史 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/providers/health` | 获取所有供应商健康状态 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/providers/{provider_id}/health` | 获取单个供应商健康详情 | super_admin, billing_admin, operations_admin |
| POST | `/api/billing-admin/providers/health-check` | 执行所有供应商健康检查 | super_admin, billing_admin |
| GET | `/api/billing-admin/pricing/models` | 获取模型定价列表 | super_admin, billing_admin, operations_admin |
| POST | `/api/billing-admin/pricing/models` | 创建或更新模型定价 | super_admin, billing_admin |
| POST | `/api/billing-admin/pricing/calculate` | 计算模型调用成本 | super_admin, billing_admin, operations_admin |
---
### 11. 配额管理 (quota_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/quota/user/{user_id}` | 获取用户配额汇总信息 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/quota/channel/{channel_id}` | 获取渠道配额汇总信息 | super_admin, billing_admin |
| GET | `/api/billing-admin/quota/alerts` | 获取配额预警列表 | super_admin, billing_admin, operations_admin |
| PUT | `/api/billing-admin/quota/alerts/{alert_id}/acknowledge` | 确认配额预警 | super_admin, billing_admin |
| PUT | `/api/billing-admin/quota/alerts/{alert_id}/resolve` | 解决配额预警 | super_admin, billing_admin |
---
### 12. 平台 Agent 配额 (platform_agent_quota.py)
#### 渠道路由 (channel_router)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/channel/available-platform-agents` | 获取可用平台 Agent 模板 | channel_admin |
| POST | `/api/channel/applications/platform-agents` | 申请平台 Agent 配额 | channel_admin |
| GET | `/api/channel/applications/platform-agents` | 查看渠道平台 Agent 申请列表 | channel_admin |
| GET | `/api/channel/platform-agents` | 查看渠道已分配的平台 Agent 配额 | channel_admin |
| POST | `/api/channel/tenants/{tenant_id}/platform-agents` | 分配平台 Agent 给租户 | channel_admin |
#### 管理员路由 (admin_router)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/admin/applications/platform-agents` | 查看所有平台 Agent 申请 | admin, super_admin |
| PUT | `/api/admin/applications/platform-agents/{application_id}/review` | 审批平台 Agent 申请 | admin, super_admin |
| GET | `/api/admin/platform-agents/templates` | 获取平台 Agent 模板列表 | admin, super_admin |
| PUT | `/api/admin/platform-agents/templates/{template_name}/config` | 配置平台 Agent 模板 | admin, super_admin |
| GET | `/api/admin/platform-agents/templates/{template_name}/config` | 获取平台 Agent 模板配置 | admin, super_admin |
#### 用户路由 (user_router)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/user/platform-agents` | 查看用户可用的平台 Agent 配额 | 已认证用户 |
| GET | `/api/user/platform-agents/{template}/instances` | 查看用户的平台 Agent 实例 | 已认证用户 |
| DELETE | `/api/user/platform-agents/{agent_name}` | 停止平台 Agent 实例 | 已认证用户 |
| GET | `/api/user/platform-agents/quota` | 查看用户平台 Agent 配额使用情况 | 已认证用户 |
| GET | `/api/user/platform-agents/{agent_name}/status` | 查看平台 Agent 实例状态 | 已认证用户 |
---
### 13. 审计日志管理 (audit_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/audit/logs` | 查询审计日志(分页) | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/audit/summary` | 获取审计日志汇总 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/audit/user/{user_id}/activity` | 获取用户活动历史 | super_admin, billing_admin, operations_admin |
---
### 14. 事件管理 (event_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/events/pending` | 获取待处理的计费事件列表 | super_admin, billing_admin |
| POST | `/api/billing-admin/events/retry-failed` | 重试失败的计费事件 | super_admin, billing_admin |
| GET | `/api/billing-admin/events/stats` | 获取计费事件统计 | super_admin, billing_admin, operations_admin |
---
### 15. 追踪管理 (trace_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/traces/execution/{execution_id}` | 获取执行追踪详情 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/traces` | 查询追踪记录(分页) | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/traces/stats` | 获取追踪统计 | super_admin, billing_admin, operations_admin |
---
### 16. 定价管理 (pricing_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/pricing/models` | 获取模型定价列表 | super_admin, billing_admin, operations_admin |
| POST | `/api/billing-admin/pricing/models` | 创建或更新模型定价 | super_admin, billing_admin |
| POST | `/api/billing-admin/pricing/calculate` | 计算模型调用成本 | super_admin, billing_admin, operations_admin |
---
### 17. 供应商健康检查 (provider_health_management.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/providers/health` | 获取所有供应商健康状态 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/providers/{provider_id}/health` | 获取供应商健康详情 | super_admin, billing_admin, operations_admin |
| POST | `/api/billing-admin/providers/health-check` | 执行供应商健康检查 | super_admin, billing_admin |
---
### 18. 资源监控 (resource_monitoring.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing-admin/resources/overview` | 获取平台资源概览 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/user/{user_id}` | 获取用户资源使用汇总 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/trends` | 获取资源使用趋势 | super_admin, billing_admin, operations_admin |
| GET | `/api/billing-admin/resources/agent/{agent_id}` | 获取 Agent 资源统计 | super_admin, billing_admin, operations_admin |
---
### 19. 前端集成 (frontend_integration.py)
#### 用户仪表板
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/user/dashboard/stats` | 获取用户仪表板统计 | 已认证用户 |
| GET | `/api/user/agents/activity` | 获取 Agent 活动数据 | 已认证用户 |
| GET | `/api/user/resources/usage` | 获取用户资源使用情况 | 已认证用户 |
#### 服务网关
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/gateway/select` | 选择网关类型 | 已认证用户 |
| POST | `/api/gateway/api/create` | 创建网关 API | 已认证用户 |
| GET | `/api/gateway/apis` | 获取网关 API 列表 | 已认证用户 |
| GET | `/api/gateway/monitoring` | 获取网关监控数据 | 已认证用户 |
#### 数据与工具
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/tools/generate` | 生成工具 | 已认证用户 |
| GET | `/api/tools/list` | 获取工具列表 | 已认证用户 |
| POST | `/api/data-templates/create` | 创建数据模板 | 已认证用户 |
#### Agent 工厂
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/agents/platform` | 获取平台 Agent 列表 | 已认证用户 |
| POST | `/api/agents/deploy` | 部署 Agent | 已认证用户 |
| GET | `/api/agents/deployed` | 获取已部署 Agent 列表 | 已认证用户 |
#### 工作流
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/workflows/create` | 创建工作流 | 已认证用户 |
| GET | `/api/workflows/list` | 获取工作流列表 | 已认证用户 |
| PUT | `/api/workflows/{workflow_id}` | 更新工作流 | 已认证用户 |
| DELETE | `/api/workflows/{workflow_id}` | 删除工作流 | 已认证用户 |
#### 计费与资源
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/billing/balance` | 获取余额 | 已认证用户 |
| GET | `/api/billing/history` | 获取计费历史 | 已认证用户 |
| POST | `/api/billing/recharge` | 充值 | 已认证用户 |
#### 渠道合作伙伴
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/channel/auth/login` | 渠道登录 | 无 |
| GET | `/api/channel/dashboard/stats` | 渠道仪表板统计 | channel_admin |
| GET | `/api/channel/agents/available` | 获取可用 Agent | channel_admin |
| GET | `/api/channel/tenants` | 获取租户列表 | channel_admin |
| POST | `/api/channel/tenants/create` | 创建租户 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/resources` | 更新租户资源 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/billing` | 更新租户计费 | channel_admin |
| DELETE | `/api/channel/tenants/{tenant_id}` | 删除租户 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/status` | 更新租户状态 | channel_admin |
| PUT | `/api/channel/tenants/{tenant_id}/permissions` | 更新租户权限 | channel_admin |
| GET | `/api/channel/resources/agents` | 获取渠道 Agent 资源 | channel_admin |
| GET | `/api/channel/resources/models` | 获取渠道模型资源 | channel_admin |
| POST | `/api/channel/resources/apply` | 申请资源 | channel_admin |
| GET | `/api/channel/billing/stats` | 获取渠道计费统计 | channel_admin |
| GET | `/api/channel/admins` | 获取渠道管理员列表 | channel_admin |
| POST | `/api/channel/admins/create` | 创建渠道管理员 | channel_admin |
| PUT | `/api/channel/admins/{admin_id}/permissions` | 更新管理员权限 | channel_admin |
#### 超级管理员
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/admin/auth/login` | 管理员登录 | 无 |
| GET | `/api/admin/dashboard/stats` | 管理员仪表板统计 | super_admin |
| GET | `/api/admin/channels` | 获取渠道列表 | super_admin |
| POST | `/api/admin/channels/create` | 创建渠道 | super_admin |
| PUT | `/api/admin/channels/{channel_id}/commission` | 更新渠道佣金 | super_admin |
| GET | `/api/admin/channels/{channel_id}/resources` | 获取渠道资源 | super_admin |
| PUT | `/api/admin/channels/{channel_id}/resources` | 更新渠道资源 | super_admin |
| GET | `/api/admin/channels/applications` | 获取渠道申请列表 | super_admin |
| PUT | `/api/admin/channels/applications/{request_id}/approve` | 审批渠道申请 | super_admin |
| GET | `/api/admin/resources/models` | 获取模型资源 | super_admin |
| POST | `/api/admin/resources/models/add` | 添加模型资源 | super_admin |
| GET | `/api/admin/resources/agents` | 获取 Agent 资源 | super_admin |
| PUT | `/api/admin/resources/agents/{agent_id}` | 更新 Agent 资源 | super_admin |
| GET | `/api/admin/monitoring/agents` | 监控 Agent | super_admin |
| GET | `/api/admin/billing/overview` | 计费概览 | super_admin |
| GET | `/api/admin/roles` | 获取角色列表 | super_admin |
| GET | `/api/admin/channels/{channel_id}/admins` | 获取渠道管理员 | super_admin |
| POST | `/api/admin/admins/create` | 创建管理员 | super_admin |
| GET | `/api/admin/providers/stats` | 获取供应商统计 | super_admin |
| GET | `/api/admin/channels/backend/stats` | 获取后端统计 | super_admin |
#### 供应商管理
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/api/providers/auth/login` | 供应商登录 | 无 |
| GET | `/api/providers/models` | 获取供应商模型 | provider_admin |
| POST | `/api/providers/models/add` | 添加供应商模型 | provider_admin |
| GET | `/api/providers/data` | 获取供应商数据 | provider_admin |
---
### 20. 监控 (monitoring.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/api/v1/monitoring/metrics` | 获取系统指标 | 无 |
| GET | `/api/v1/monitoring/stats` | 获取服务统计 | 无 |
| GET | `/api/v1/monitoring/trends` | 获取性能趋势 | 无 |
| GET | `/api/v1/monitoring/alerts` | 获取系统告警 | 无 |
| GET | `/api/v1/monitoring/dashboard` | 获取监控仪表板 | 无 |
---
### 21. 健康检查 (health.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/health` | 系统健康检查 | 无 |
---
### 22. Prometheus 指标 (metrics.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/metrics` | 暴露 Prometheus 指标 | 无 |
---
## Data-Ingestion 服务接口
### 1. APILLAMA 处理 (apillama.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/apillama/process` | 将 API 文档转换为结构化 schema | 无 |
---
### 2. 健康检查 (health.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/health` | 服务健康检查 | 无 |
---
### 3. Prometheus 指标 (metrics.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/metrics` | 暴露 Prometheus 指标 | 无 |
---
### 4. OpenAPI 解析 (openapi.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/openapi/parse` | 下载并解析 OpenAPI 文档 | 无 |
---
### 5. RapidAPI 集成 (rapidapi.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/rapidapi/sync` | 触发 RapidAPI 端点同步 | 无 |
| POST | `/rapidapi/test` | 测试 RapidAPI 端点 | 无 |
---
### 6. 统计与缓存 (stats.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| GET | `/stats` | 获取工具和缓存统计 | 无 |
| POST | `/cache/clear` | 清理缓存 | 无 |
---
### 7. 工具注册 (tools.py)
| 方法 | 路径 | 功能描述 | 权限要求 |
|------|------|----------|----------|
| POST | `/tools/generate` | 为 API 端点生成工具 | 无 |
| GET | `/tools` | 获取工具列表 | 无 |
| GET | `/tools/{tool_name}` | 获取工具详情 | 无 |
| DELETE | `/tools/{tool_name}` | 删除工具 | 无 |
---
## 接口统计
### MCP-Server 服务
| 模块 | 接口数量 |
|------|----------|
| 认证模块 | 6 |
| 超级管理员 API | 35 |
| 用户侧平台 API | 28 |
| 渠道合作伙伴 API | 27 |
| Agent 管理 | 11 |
| 供应商管理 | 6 |
| 会话管理 | 6 |
| 工具管理 | 6 |
| WebSocket | 1 |
| 计费与资源管理 | 24 |
| 配额管理 | 5 |
| 平台 Agent 配额 | 15 |
| 审计日志管理 | 3 |
| 事件管理 | 3 |
| 追踪管理 | 3 |
| 定价管理 | 3 |
| 供应商健康检查 | 3 |
| 资源监控 | 4 |
| 前端集成 | 50+ |
| 监控 | 5 |
| 健康检查 | 1 |
| Prometheus 指标 | 1 |
### Data-Ingestion 服务
| 模块 | 接口数量 |
|------|----------|
| APILLAMA 处理 | 1 |
| 健康检查 | 1 |
| Prometheus 指标 | 1 |
| OpenAPI 解析 | 1 |
| RapidAPI 集成 | 2 |
| 统计与缓存 | 2 |
| 工具注册 | 4 |
---
## 角色权限说明
| 角色 | 说明 |
|------|------|
| `super_admin` | 超级管理员,拥有系统所有权限 |
| `billing_admin` | 计费管理员,完整写入权限,可创建渠道、管理租户、计费操作 |
| `operations_admin` | 运维管理员,只读权限,仅查看和监控 |
| `channel_admin` | 渠道管理员,渠道内部管理权限 |
| `provider_admin` | 供应商管理员,管理供应商模型 |
| `user` | 普通用户,标准用户权限 |
---
## 技术栈
- **Web 框架**: FastAPI
- **ORM**: SQLAlchemy (异步)
- **认证**: JWT (JSON Web Token)
- **权限系统**: RBAC (基于角色的访问控制)
- **Kubernetes 集成**: Agent Manager 客户端
- **实时通信**: WebSocket
- **监控**: Prometheus
- **消息队列**: NATS
- **缓存**: Redis
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,967 @@
# 租户用户端 - 后端接口需求清单
> **版本**: v1.0.0
> **更新时间**: 2026-01-06
> **说明**: 本文档基于前端业务逻辑分析,列出所有后端接口需求,包括已对接接口和未对接接口,按钮操作接口和数据展示接口
---
## 目录
1. [认证模块 (Authentication)](#认证模块-authentication)
2. [概览模块 (Dashboard Overview)](#概览模块-dashboard-overview)
3. [服务网关模块 (Service Gateway)](#服务网关模块-service-gateway)
4. [数据与工具模块 (Data & Tools)](#数据与工具模块-data--tools)
5. [代理工厂模块 (Agent Factory)](#代理工厂模块-agent-factory)
6. [编排中心模块 (Orchestration Hub)](#编排中心模块-orchestration-hub)
7. [计费与资源模块 (Billing & Resources)](#计费与资源模块-billing--resources)
8. [附录:接口汇总表](#附录接口汇总表)
---
## 认证模块 (Authentication)
### 按钮操作接口
#### B1. 用户登录接口 ✅ 已对接
**触发位置**: 登录页面 → "登录" 按钮
**功能描述**: 租户用户使用邮箱和密码登录系统
**接口**:
```
POST /api/auth/login
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| email | string | 是 | 用户邮箱 |
| password | string | 是 | 用户密码 |
| role | string | 是 | 角色类型,固定为 "user" |
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.token | string | JWT访问令牌 |
| data.refreshToken | string | 刷新令牌 |
| data.user | object | 用户信息 |
**前端调用**: `TaijiAPIClient.login(email, password, "user")`
---
#### B2. 用户登出接口 ✅ 已对接
**触发位置**: 顶部导航栏 → 用户菜单 → "退出登录"
**功能描述**: 用户退出登录,清除会话
**接口**:
```
POST /api/auth/logout
```
**前端调用**: `TaijiAPIClient.logout()`
---
#### B3. 刷新Token接口 ✅ 已对接
**触发位置**: 系统自动调用(Token即将过期时)
**功能描述**: 刷新访问令牌
**接口**:
```
POST /api/auth/refresh
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.token | string | 新的JWT访问令牌 |
| data.refreshToken | string | 新的刷新令牌 |
**前端调用**: `TaijiAPIClient.refreshToken()`
---
#### B4. 修改密码接口 ✅ 已对接
**触发位置**: 用户菜单 → 设置 → 修改密码
**功能描述**: 用户修改自己的密码
**接口**:
```
PUT /api/auth/password
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| old_password | string | 是 | 旧密码 |
| new_password | string | 是 | 新密码 |
**前端调用**: `TaijiAPIClient.changePassword(oldPassword, newPassword)`
---
#### B5. 重新生成API密钥接口 ✅ 已对接
**触发位置**: 顶部导航栏 → 用户菜单 → "密钥管理" → "重新生成" 按钮
**功能描述**: 重新生成用户的API密钥
**接口**:
```
POST /api/auth/keys/regenerate
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.apiKey | string | 新的API密钥 |
| data.message | string | 提示信息 |
**前端调用**: `TaijiAPIClient.regenerateApiKey()`
---
### 数据展示接口
#### D1. 获取API密钥信息接口 ✅ 已对接
**展示位置**: 顶部导航栏 → 用户菜单 → "密钥管理" 对话框
**展示内容**:
- 服务终结点 URL
- API密钥(脱敏显示)
**接口**:
```
GET /api/auth/keys/info
```
**前端调用**: `TaijiAPIClient.getApiKeyInfo()`
---
## 概览模块 (Dashboard Overview)
### 数据展示接口
#### D2. 用户仪表板统计接口 ✅ 已对接
**展示位置**: 概览页面 → 顶部统计卡片区域
**展示内容**:
- 活跃代理数(Active Agents)
- 全局API调用数(Global API Calls)
- EU余额(EU Balance)
- 系统健康度(System Health)
**功能描述**: 获取当前租户的仪表板统计数据
**接口**:
```
GET /api/user/dashboard/stats
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.activeAgents | int | 活跃代理数 |
| data.totalRequests | int | 总请求数 |
| data.euBalance | float | EU余额 |
| data.systemHealth | int | 系统健康度百分比 |
**前端调用**: `TaijiAPIClient.getUserDashboardStats()`
---
#### D3. 监控仪表盘接口 ✅ 已对接
**展示位置**: 概览页面 → 系统组件状态区域
**展示内容**:
- 各服务组件状态(MCP Server、Data Ingestion、API Gateway等)
- 组件延迟信息
**接口**:
```
GET /api/v1/monitoring/dashboard
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| health.services | object | 各服务健康状态 |
| metrics | object | 性能指标 |
**前端调用**: `TaijiAPIClient.getMonitoringDashboard()`
---
#### D4. 计费余额接口 ✅ 已对接
**展示位置**: 概览页面 → EU余额卡片
**展示内容**:
- EU余额
- 账户余额
**接口**:
```
GET /api/user/billing/balance
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.balance | float | 账户余额 |
| data.euBalance | float | EU余额 |
**前端调用**: `TaijiAPIClient.getBillingBalance()`
---
#### D5. 监控趋势数据接口 ✅ 已对接
**展示位置**: 概览页面 → EU消耗图表
**展示内容**:
- 过去24小时EU消耗趋势
**接口**:
```
GET /api/v1/monitoring/trends
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| metric | string | 否 | 指标类型:executions, eu_consumption |
| period | string | 否 | 时间周期:24h, 7d, 30d |
| interval | string | 否 | 时间间隔:1h, 6h, 1d |
**前端调用**: `TaijiAPIClient.getMonitoringTrends({ metric, period, interval })`
---
## 服务网关模块 (Service Gateway)
### 按钮操作接口
#### B6. 创建API接口 ✅ 已对接
**触发位置**: 服务网关页面 → "创建API" 按钮
**功能描述**: 通过上传JSON文件或提供URL创建API接口
**接口**:
```
POST /api/user/gateway/api/create
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | API名称 |
| method | string | 是 | 上传方式:json 或 url |
| content | string | 是 | JSON内容或URL地址 |
**前端调用**: `TaijiAPIClient.createGatewayAPI(name, method, content)`
---
#### B7. 选择网关类型接口 ✅ 已对接
**触发位置**: 服务网关页面 → 网关类型选择
**功能描述**: 选择使用的服务网关类型(MCP、A2A、API)
**接口**:
```
POST /api/user/gateway/select
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| gatewayType | string | 是 | 网关类型:MCP, A2A, API |
**前端调用**: `TaijiAPIClient.selectGateway(gatewayType)`
---
### 数据展示接口
#### D6. 网关API列表接口 ✅ 已对接
**展示位置**: 服务网关页面 → 统计卡片(服务端点数)
**展示内容**:
- 已创建的API列表
- 服务端点数量
**接口**:
```
GET /api/user/gateway/apis
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.apis | array | API列表 |
**前端调用**: `TaijiAPIClient.getGatewayAPIs()`
---
#### D7. 网关监控数据接口 ✅ 已对接
**展示位置**: 服务网关页面 → 监控Tab
**展示内容**:
- 平均延迟
- 今日请求数
- 各提供商请求分布
**接口**:
```
GET /api/user/gateway/monitoring
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.averageLatency | int | 平均延迟(ms) |
| data.requestsPerMinute | int | 每分钟请求数 |
**前端调用**: `TaijiAPIClient.getGatewayMonitoring()`
---
#### D8. 模型提供商列表接口 ✅ 已对接
**展示位置**: 服务网关页面 → 监控Tab → 模型提供商监控
**展示内容**:
- 各模型提供商名称
- 请求数量
- 延迟
- 状态
**接口**:
```
GET /api/providers/models
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.providers | array | 提供商列表 |
**前端调用**: `TaijiAPIClient.getModelProviders()`
---
## 数据与工具模块 (Data & Tools)
### 按钮操作接口
#### B8. 生成工具接口 ✅ 已对接
**触发位置**: 数据与工具页面 → "生成新工具" 按钮 → 对话框 → "部署工具和Pod"
**功能描述**: 根据Agent框架模板生成工具并部署Pod
**接口**:
```
POST /api/user/tools/generate
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | 工具名称 |
| description | string | 否 | 工具描述 |
| frameworkTemplate | string | 是 | 框架模板:langchain, a2a, api |
| gateway | string | 是 | 服务网关:mcp-gateway, a2a-gateway, api-gateway |
| agentCount | int | 是 | Agent个数 |
| cpu | int | 是 | CPU核数 |
| memory | int | 是 | 内存大小(GB) |
| maxScale | int | 是 | 可扩展Agent数量 |
| model | string | 是 | 使用的模型 |
**前端调用**: `TaijiAPIClient.generateTool(data)`
---
#### B9. 创建数据模板接口 ✅ 已对接
**触发位置**: 数据与工具页面 → 数据模板Tab → "创建数据模板" 按钮
**功能描述**: 创建JSON API模板或云存储数据库模板
**接口**:
```
POST /api/user/data-templates/create
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | 模板名称 |
| type | string | 是 | 模板类型:json_api, cloud_storage |
| config | object | 是 | 配置信息(URL、密钥、连接字符串等) |
**前端调用**: `TaijiAPIClient.createDataTemplate(data)`
---
### 数据展示接口
#### D9. 工具列表接口 ✅ 已对接
**展示位置**: 数据与工具页面 → 可用工具Tab → 工具注册表
**展示内容**:
- 工具名称
- 类别
- 方法(GET/POST等)
- 端点URL
- 状态
- 创建时间
**接口**:
```
GET /tools
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| category | string | 否 | 工具类别 |
| limit | int | 否 | 返回数量限制 |
| offset | int | 否 | 偏移量 |
**前端调用**: `TaijiAPIClient.getTools()`
---
#### D10. 统计信息接口 ✅ 已对接
**展示位置**: 数据与工具页面 → 顶部统计卡片
**展示内容**:
- 总API数
- 生成的工具数
- 活跃Pod数
**接口**:
```
GET /stats
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| total_apis | int | 总API数 |
| generated_tools | int | 生成的工具数 |
| active_pods | int | 活跃Pod数 |
**前端调用**: `TaijiAPIClient.getStats()`
---
## 代理工厂模块 (Agent Factory)
### 按钮操作接口
#### B10. 部署Agent接口 ✅ 已对接
**触发位置**: 代理工厂页面 → Agent卡片 → "部署Agent" 按钮 → 对话框 → "确认部署"
**功能描述**: 部署平台原生Agent到用户资源
**接口**:
```
POST /api/user/agents/deploy
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| agentId | string | 是 | Agent ID |
| instances | int | 是 | 实例数量 |
| model | string | 是 | 使用的模型 |
| gateway | string | 是 | 服务网关:MCP, A2A, API |
**前端调用**: `TaijiAPIClient.deployAgent(data)`
---
#### B11. 创建自定义Agent接口 ✅ 已对接
**触发位置**: 代理工厂页面 → 自定义Agent区域(如有)
**功能描述**: 创建租户自定义的Agent
**接口**:
```
POST /api/user/agents/custom/create
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | Agent名称 |
| description | string | 否 | Agent描述 |
| category | string | 否 | 类别 |
| role | string | 是 | 角色定义 |
| goal | string | 是 | 目标定义 |
| tools | array | 否 | 工具列表 |
| config | object | 否 | 配置(temperature, max_tokens等) |
**前端调用**: `TaijiAPIClient.createCustomAgent(data)`
---
### 数据展示接口
#### D11. 平台Agent列表接口 ✅ 已对接
**展示位置**: 代理工厂页面 → 平台原生Agent库
**展示内容**:
- Agent图标
- Agent名称
- Agent描述
- 核心能力标签
- 状态
**接口**:
```
GET /api/user/agents/platform
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.data | array | Agent列表 |
**前端调用**: `TaijiAPIClient.getPlatformAgents()`
---
#### D12. 已部署Agent列表接口 ✅ 已对接
**展示位置**: 代理工厂页面 → 已部署Agent统计卡片
**展示内容**:
- 已部署Agent数量
- 运行中的Agent
**接口**:
```
GET /agents
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| skip | int | 否 | 跳过数量 |
| limit | int | 否 | 返回数量限制 |
**前端调用**: `TaijiAPIClient.getAgents(skip, limit)`
---
#### D13. 自定义Agent列表接口 ✅ 已对接
**展示位置**: 代理工厂页面 → 自定义Agent区域
**展示内容**:
- 自定义Agent列表
**接口**:
```
GET /api/user/agents/custom
```
**前端调用**: `TaijiAPIClient.getCustomAgents()`
---
## 编排中心模块 (Orchestration Hub)
### 按钮操作接口
#### B12. 创建工作流接口 ✅ 已对接
**触发位置**: 编排中心页面 → "创建工作流" 按钮 → 对话框 → "保存工作流"
**功能描述**: 创建Agent工作流(最多3个节点)
**接口**:
```
POST /api/user/workflows/create
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | 工作流名称 |
| description | string | 否 | 工作流描述 |
| gateway | string | 是 | 服务网关:MCP, A2A, API |
| nodes | array | 是 | 节点列表(最多3个) |
| nodes[].agentId | string | 是 | Agent ID |
| nodes[].agentType | string | 是 | Agent类型:platform, custom |
| nodes[].agentName | string | 是 | Agent名称 |
| nodes[].order | int | 是 | 节点顺序 |
**前端调用**: `TaijiAPIClient.createWorkflow(data)`
---
#### B13. 运行工作流接口 ⚠️ 待确认
**触发位置**: 编排中心页面 → 工作流卡片 → "运行" 按钮
**功能描述**: 执行指定的工作流
**接口**:
```
POST /api/user/workflows/{workflow_id}/run
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| workflow_id | string | 是 | 工作流ID(路径参数) |
| input | object | 否 | 输入参数 |
**前端调用**: 待实现
---
#### B14. 删除工作流接口 ⚠️ 待确认
**触发位置**: 编排中心页面 → 工作流卡片 → 删除按钮
**功能描述**: 删除指定的工作流
**接口**:
```
DELETE /api/user/workflows/{workflow_id}
```
**前端调用**: 待实现
---
### 数据展示接口
#### D14. 工作流列表接口 ✅ 已对接
**展示位置**: 编排中心页面 → 我的工作流
**展示内容**:
- 工作流名称
- 状态(running/stopped)
- 节点数量
**接口**:
```
GET /api/user/workflows
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.data | array | 工作流列表 |
| data.data[].id | string | 工作流ID |
| data.data[].name | string | 工作流名称 |
| data.data[].status | string | 状态 |
| data.data[].nodes | array | 节点列表 |
**前端调用**: `TaijiAPIClient.getWorkflows()`
---
## 计费与资源模块 (Billing & Resources)
### 按钮操作接口
#### B15. 充值接口 ✅ 已对接
**触发位置**: 计费与资源页面 → 账户余额卡片 → "充值" 按钮 → 对话框 → "确认充值"
**功能描述**: 为账户充值
**接口**:
```
POST /api/user/billing/recharge
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| amount | float | 是 | 充值金额 |
| paymentMethod | string | 否 | 支付方式:alipay, wechat, card |
**前端调用**: `TaijiAPIClient.rechargeBalance(amount, paymentMethod)`
---
#### B16. 导出账单接口 ⚠️ 待确认
**触发位置**: 计费与资源页面 → "导出" 按钮 → 选择格式
**功能描述**: 导出账单数据为Excel/CSV/PDF格式
**接口**:
```
GET /api/user/billing/history?export={format}
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| startTime | string | 是 | 开始时间 |
| endTime | string | 是 | 结束时间 |
| export | string | 是 | 导出格式:excel, csv, pdf |
**前端调用**: `TaijiAPIClient.getBillingHistory({ ...params, export: format })`
---
### 数据展示接口
#### D15. 计费余额接口 ✅ 已对接
**展示位置**: 计费与资源页面 → 账户余额卡片、EU余额卡片
**展示内容**:
- 账户余额(¥)
- 本月已消费
- EU余额
**接口**:
```
GET /api/user/billing/balance
```
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.balance | float | 账户余额 |
| data.monthlySpent | float | 本月消费 |
| data.euBalance | float | EU余额 |
**前端调用**: `TaijiAPIClient.getBillingBalance()`
---
#### D16. 计费历史接口 ✅ 已对接
**展示位置**: 计费与资源页面 → EU消费历史图表、费用明细图表
**展示内容**:
- 每日EU消耗趋势
- 按类别的费用明细
**接口**:
```
GET /api/user/billing/history
```
**请求参数**:
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| startTime | string | 是 | 开始时间(ISO格式) |
| endTime | string | 是 | 结束时间(ISO格式) |
| customerName | string | 否 | 客户名称筛选 |
| minCalls | int | 否 | 最小调用次数 |
| maxCalls | int | 否 | 最大调用次数 |
| page | int | 否 | 页码 |
| pageSize | int | 否 | 每页数量 |
**响应字段**:
| 字段 | 类型 | 说明 |
|------|------|------|
| success | bool | 是否成功 |
| data.records | array | 计费记录列表 |
| data.records[].timestamp | string | 时间戳 |
| data.records[].eu | float | EU消耗 |
| data.records[].cost | float | 费用 |
| data.records[].agentType | string | Agent类型 |
**前端调用**: `TaijiAPIClient.getBillingHistory(params)`
---
## 附录:接口汇总表
### 按钮操作接口汇总
| 序号 | 接口名称 | 方法 | 路径 | 状态 | 所属模块 |
|------|----------|------|------|------|----------|
| B1 | 用户登录 | POST | /api/auth/login | ✅ 已对接 | 认证 |
| B2 | 用户登出 | POST | /api/auth/logout | ✅ 已对接 | 认证 |
| B3 | 刷新Token | POST | /api/auth/refresh | ✅ 已对接 | 认证 |
| B4 | 修改密码 | PUT | /api/auth/password | ✅ 已对接 | 认证 |
| B5 | 重新生成API密钥 | POST | /api/auth/keys/regenerate | ✅ 已对接 | 认证 |
| B6 | 创建API | POST | /api/user/gateway/api/create | ✅ 已对接 | 服务网关 |
| B7 | 选择网关类型 | POST | /api/user/gateway/select | ✅ 已对接 | 服务网关 |
| B8 | 生成工具 | POST | /api/user/tools/generate | ✅ 已对接 | 数据与工具 |
| B9 | 创建数据模板 | POST | /api/user/data-templates/create | ✅ 已对接 | 数据与工具 |
| B10 | 部署Agent | POST | /api/user/agents/deploy | ✅ 已对接 | 代理工厂 |
| B11 | 创建自定义Agent | POST | /api/user/agents/custom/create | ✅ 已对接 | 代理工厂 |
| B12 | 创建工作流 | POST | /api/user/workflows/create | ✅ 已对接 | 编排中心 |
| B13 | 运行工作流 | POST | /api/user/workflows/{id}/run | ⚠️ 待确认 | 编排中心 |
| B14 | 删除工作流 | DELETE | /api/user/workflows/{id} | ⚠️ 待确认 | 编排中心 |
| B15 | 充值 | POST | /api/user/billing/recharge | ✅ 已对接 | 计费与资源 |
| B16 | 导出账单 | GET | /api/user/billing/history?export= | ⚠️ 待确认 | 计费与资源 |
### 数据展示接口汇总
| 序号 | 接口名称 | 方法 | 路径 | 状态 | 所属模块 |
|------|----------|------|------|------|----------|
| D1 | 获取API密钥信息 | GET | /api/auth/keys/info | ✅ 已对接 | 认证 |
| D2 | 用户仪表板统计 | GET | /api/user/dashboard/stats | ✅ 已对接 | 概览 |
| D3 | 监控仪表盘 | GET | /api/v1/monitoring/dashboard | ✅ 已对接 | 概览 |
| D4 | 计费余额 | GET | /api/user/billing/balance | ✅ 已对接 | 概览 |
| D5 | 监控趋势数据 | GET | /api/v1/monitoring/trends | ✅ 已对接 | 概览 |
| D6 | 网关API列表 | GET | /api/user/gateway/apis | ✅ 已对接 | 服务网关 |
| D7 | 网关监控数据 | GET | /api/user/gateway/monitoring | ✅ 已对接 | 服务网关 |
| D8 | 模型提供商列表 | GET | /api/providers/models | ✅ 已对接 | 服务网关 |
| D9 | 工具列表 | GET | /tools | ✅ 已对接 | 数据与工具 |
| D10 | 统计信息 | GET | /stats | ✅ 已对接 | 数据与工具 |
| D11 | 平台Agent列表 | GET | /api/user/agents/platform | ✅ 已对接 | 代理工厂 |
| D12 | 已部署Agent列表 | GET | /agents | ✅ 已对接 | 代理工厂 |
| D13 | 自定义Agent列表 | GET | /api/user/agents/custom | ✅ 已对接 | 代理工厂 |
| D14 | 工作流列表 | GET | /api/user/workflows | ✅ 已对接 | 编排中心 |
| D15 | 计费余额 | GET | /api/user/billing/balance | ✅ 已对接 | 计费与资源 |
| D16 | 计费历史 | GET | /api/user/billing/history | ✅ 已对接 | 计费与资源 |
---
## 接口统计
### 按状态统计
| 状态 | 数量 | 占比 |
|------|------|------|
| ✅ 已对接 | 29 | 90.6% |
| ⚠️ 待确认 | 3 | 9.4% |
| ❌ 未对接 | 0 | 0% |
| **总计** | **32** | **100%** |
### 按模块统计
| 模块 | 按钮操作接口 | 数据展示接口 | 合计 |
|------|-------------|-------------|------|
| 认证模块 | 5 | 1 | 6 |
| 概览模块 | 0 | 4 | 4 |
| 服务网关模块 | 2 | 3 | 5 |
| 数据与工具模块 | 2 | 2 | 4 |
| 代理工厂模块 | 2 | 3 | 5 |
| 编排中心模块 | 3 | 1 | 4 |
| 计费与资源模块 | 2 | 2 | 4 |
| **总计** | **16** | **16** | **32** |
---
## 待确认接口说明
### B13. 运行工作流接口
**问题**: 前端页面有"运行"按钮,但API客户端中未找到对应的接口实现。
**建议**: 需要后端确认是否已实现 `POST /api/user/workflows/{workflow_id}/run` 接口。
### B14. 删除工作流接口
**问题**: 前端页面有删除按钮,但API客户端中未找到对应的接口实现。
**建议**: 需要后端确认是否已实现 `DELETE /api/user/workflows/{workflow_id}` 接口。
### B16. 导出账单接口
**问题**: 前端有导出功能UI,但实际导出逻辑可能需要后端返回文件流。
**建议**: 需要确认后端是否支持 `export` 参数返回文件下载。
---
## 前端调用示例
### 登录流程
```typescript
// 1. 用户登录
const result = await TaijiAPIClient.login(email, password, "user")
if (result.success) {
// token 自动存储到 localStorage
window.location.href = "/"
}
```
### 仪表板数据加载
```typescript
// 并行加载仪表板数据
const [dashboardStats, monitoringDashboard, billingBalance] = await Promise.allSettled([
TaijiAPIClient.getUserDashboardStats(),
TaijiAPIClient.getMonitoringDashboard(),
TaijiAPIClient.getBillingBalance(),
])
```
### 部署Agent流程
```typescript
// 部署平台Agent
const result = await TaijiAPIClient.deployAgent({
agentId: selectedAgent.id,
instances: deployConfig.agentCount,
model: deployConfig.model,
gateway: deployConfig.serviceGateway as "MCP" | "A2A" | "API",
})
```
### 创建工作流流程
```typescript
// 创建工作流
const result = await TaijiAPIClient.createWorkflow({
name: workflowName,
gateway: selectedGateway as "MCP" | "A2A" | "API",
nodes: workflowNodes.map((nodeId, index) => ({
agentId: nodeId,
agentType: agent?.type === "custom" ? "custom" : "platform",
agentName: agent?.name || "",
order: index + 1,
})),
})
```
---
## 版本历史
| 版本 | 日期 | 更新内容 |
|------|------|----------|
| v1.0.0 | 2026-01-06 | 初始版本,基于前端代码分析生成 |
+959
View File
@@ -0,0 +1,959 @@
# 租户用户端 - 接口对接文档
> **版本**: v1.0.0
> **更新时间**: 2026-01-06
> **说明**: 本文档基于前端业务需求清单与后端实际接口实现的核实结果,提供完整的接口对接说明
---
## 目录
1. [接口核实总结](#接口核实总结)
2. [认证模块 (Authentication)](#认证模块-authentication)
3. [概览模块 (Dashboard Overview)](#概览模块-dashboard-overview)
4. [服务网关模块 (Service Gateway)](#服务网关模块-service-gateway)
5. [数据与工具模块 (Data & Tools)](#数据与工具模块-data--tools)
6. [代理工厂模块 (Agent Factory)](#代理工厂模块-agent-factory)
7. [编排中心模块 (Orchestration Hub)](#编排中心模块-orchestration-hub)
8. [计费与资源模块 (Billing & Resources)](#计费与资源模块-billing--resources)
9. [接口差异说明](#接口差异说明)
10. [附录:完整接口清单](#附录完整接口清单)
---
## 接口核实总结
### 核实结果统计
| 状态 | 数量 | 说明 |
|------|------|------|
| ✅ 完全匹配 | 26 | 前端需求与后端实现完全一致 |
| ⚠️ 路径差异 | 3 | 接口存在但路径略有不同 |
| ❌ 后端缺失 | 3 | 前端需要但后端未实现 |
| **总计** | **32** | - |
### 关键发现
1. **路径差异**:部分接口在 `user.py` 中的路径与前端需求清单略有不同
2. **缺失接口**:工作流运行、工作流删除、账单导出功能后端尚未完整实现
3. **额外接口**:后端提供了更多前端未列出的接口(如自定义Agent管理、Agent计费统计等)
---
## 认证模块 (Authentication)
### B1. 用户登录接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/auth/login` |
| **后端实际路径** | `POST /api/auth/login` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:42) |
**请求参数**:
```json
{
"email": "string", // 用户邮箱
"password": "string", // 用户密码
"role": "user" // 角色类型,固定为 "user"
}
```
**响应示例**:
```json
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": "uuid",
"name": "用户名",
"email": "user@example.com",
"role": "user",
"channelId": "uuid"
}
}
}
```
---
### B2. 用户登出接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/auth/logout` |
| **后端实际路径** | `POST /api/auth/logout` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:173) |
**请求头**:
```
Authorization: Bearer <token>
```
**响应示例**:
```json
{
"success": true,
"message": "登出成功"
}
```
---
### B3. 刷新Token接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/auth/refresh` |
| **后端实际路径** | `POST /api/auth/refresh` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:212) |
**响应示例**:
```json
{
"success": true,
"data": {
"token": "新的JWT访问令牌",
"refreshToken": "新的刷新令牌"
}
}
```
---
### B4. 修改密码接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `PUT /api/auth/password` |
| **后端实际路径** | `PUT /api/auth/password` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:250) |
**请求参数**:
```json
{
"old_password": "string", // 旧密码
"new_password": "string" // 新密码
}
```
---
### B5. 重新生成API密钥接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/auth/keys/regenerate` |
| **后端实际路径** | `POST /api/auth/keys/regenerate` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:344) |
**响应示例**:
```json
{
"success": true,
"data": {
"apiKey": "sk-xxxxxxxxxxxxx",
"message": "旧密钥已失效"
}
}
```
---
### D1. 获取API密钥信息接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/auth/keys/info` |
| **后端实际路径** | `GET /api/auth/keys/info` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/auth.py`](../services/mcp-server/app/routes/auth.py:289) |
**响应示例**:
```json
{
"success": true,
"data": {
"endpoint": "https://api.taiji-ai.com/v1",
"apiKey": "sk-xxxx...xxxx",
"createdAt": "2026-01-01T00:00:00Z",
"lastUsed": "2026-01-06T10:00:00Z"
}
}
```
---
## 概览模块 (Dashboard Overview)
### D2. 用户仪表板统计接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/dashboard/stats` |
| **后端实际路径** | `GET /api/user/dashboard/stats` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:105) |
**响应示例**:
```json
{
"success": true,
"data": {
"activeAgents": 5,
"totalRequests": 12500,
"euBalance": 1000.50,
"systemHealth": 98.5
}
}
```
---
### D3. 监控仪表盘接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/v1/monitoring/dashboard` |
| **后端实际路径** | `GET /api/v1/monitoring/dashboard` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/monitoring.py`](../services/mcp-server/app/routes/monitoring.py:63) |
**响应示例**:
```json
{
"timestamp": "2026-01-06T14:00:00Z",
"health": {
"services": {
"mcp_server": "healthy",
"data_ingestion": "healthy",
"api_gateway": "healthy"
}
},
"metrics": {
"cpu_usage": 45.2,
"memory_usage": 62.8
},
"stats": {},
"alerts": {
"items": [],
"count": 0,
"critical_count": 0,
"warning_count": 0
}
}
```
---
### D4. 计费余额接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/billing/balance` |
| **后端实际路径** | `GET /api/user/billing/balance` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:658) |
**响应示例**:
```json
{
"success": true,
"data": {
"balance": 5000.00,
"monthlySpent": 1200.50,
"currency": "CNY"
}
}
```
**注意**: 前端需求中有 `euBalance` 字段,后端返回的是 `balance`。如需 EU 余额,可从 dashboard/stats 接口获取。
---
### D5. 监控趋势数据接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/v1/monitoring/trends` |
| **后端实际路径** | `GET /api/v1/monitoring/trends` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/monitoring.py`](../services/mcp-server/app/routes/monitoring.py:36) |
**请求参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| metric | string | 否 | 指标类型:executions, eu_consumption |
| period | string | 否 | 时间周期:24h, 7d, 30d |
| interval | string | 否 | 时间间隔:1h, 6h, 1d |
---
## 服务网关模块 (Service Gateway)
### B6. 创建API接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/gateway/api/create` |
| **后端实际路径** | `POST /api/user/gateway/api/create` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:208) |
**请求参数**:
```json
{
"name": "string", // API名称
"method": "string", // 上传方式:json 或 url
"content": "string" // JSON内容或URL地址
}
```
---
### B7. 选择网关类型接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/gateway/select` |
| **后端实际路径** | `POST /api/user/gateway/select` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:192) |
**请求参数**:
```json
{
"gatewayType": "MCP" // 网关类型:MCP, A2A, API
}
```
---
### D6. 网关API列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/gateway/apis` |
| **后端实际路径** | `GET /api/user/gateway/apis` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:236) |
**响应示例**:
```json
{
"success": true,
"data": {
"apis": [
{
"id": "uuid",
"name": "API名称",
"method": "json",
"createdAt": "2026-01-01T00:00:00Z"
}
]
}
}
```
---
### D7. 网关监控数据接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/gateway/monitoring` |
| **后端实际路径** | `GET /api/user/gateway/monitoring` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:264) |
**响应示例**:
```json
{
"success": true,
"data": {
"uptime": 99.9,
"requestsPerMinute": 1250,
"averageLatency": 45,
"errorRate": 0.1
}
}
```
---
### D8. 模型提供商列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/providers/models` |
| **后端实际路径** | `GET /api/providers/models` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/providers.py`](../services/mcp-server/app/routes/providers.py:62) |
**注意**: 此接口需要 `manage:providers` 权限(super_admin 或 provider_admin)。普通用户可能无法访问。
---
## 数据与工具模块 (Data & Tools)
### B8. 生成工具接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/tools/generate` |
| **后端实际路径** | `POST /api/user/tools/generate` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:348) |
**请求参数**:
```json
{
"name": "string", // 工具名称
"description": "string", // 工具描述(可选)
"frameworkTemplate": "string", // 框架模板:langchain, a2a, api
"gateway": "string", // 服务网关:mcp-gateway, a2a-gateway, api-gateway
"agentCount": 1, // Agent个数
"cpu": 1, // CPU核数
"memory": 2, // 内存大小(GB)
"maxScale": 3, // 可扩展Agent数量
"model": "string" // 使用的模型
}
```
**配额检查**: 后端会检查用户的自定义 Agent 配额(CPU/内存),配额不足时返回 400 错误。
---
### B9. 创建数据模板接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/data-templates/create` |
| **后端实际路径** | `POST /api/user/data-templates/create` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:436) |
**请求参数**:
```json
{
"name": "string", // 模板名称
"type": "string", // 模板类型:json_api, cloud_storage
"config": {} // 配置信息
}
```
---
### D9. 工具列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /tools` |
| **后端实际路径** | `GET /tools` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/tools.py`](../services/mcp-server/app/routes/tools.py:22) |
**请求参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| category | string | 否 | 工具类别 |
| search | string | 否 | 搜索关键词 |
| is_active | bool | 否 | 是否激活 |
| is_public | bool | 否 | 是否公开 |
| page | int | 否 | 页码,默认1 |
| page_size | int | 否 | 每页数量,默认20 |
**响应示例**:
```json
{
"items": [
{
"id": "uuid",
"name": "工具名称",
"description": "工具描述",
"category": "类别",
"is_active": true,
"is_public": true
}
],
"total": 100,
"page": 1,
"page_size": 20,
"pages": 5
}
```
---
### D10. 统计信息接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /stats` |
| **后端实际路径** | `GET /stats` |
| **状态** | ✅ 完全匹配 |
| **后端服务** | Data-Ingestion 服务 |
| **后端文件** | [`services/data-ingestion/app/routes/stats.py`](../services/data-ingestion/app/routes/stats.py:14) |
**响应示例**:
```json
{
"total_apis": 150,
"processed_apis": 145,
"generated_tools": 120,
"failed_processes": 5,
"cache_size": 1024,
"last_sync": "2026-01-06T10:00:00Z",
"categories": {
"data": 50,
"ai": 30,
"utility": 40
}
}
```
**注意**: 此接口由 Data-Ingestion 服务提供,前端需要调用正确的服务地址。
---
## 代理工厂模块 (Agent Factory)
### B10. 部署Agent接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/agents/deploy` |
| **后端实际路径** | `POST /api/user/agents/deploy` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:497) |
**请求参数**:
```json
{
"agentId": "string", // Agent ID
"instances": 1, // 实例数量
"model": "string", // 使用的模型
"gateway": "MCP" // 服务网关:MCP, A2A, API
}
```
**响应示例**:
```json
{
"success": true,
"data": {
"agentId": "uuid",
"podName": "agent-name-xxxxxxxx",
"namespace": "taiji-agents",
"status": "Running",
"servicePort": 8080,
"instances": 1,
"model": "gpt-4",
"gateway": "MCP"
},
"message": "Agent xxx 部署成功"
}
```
---
### B11. 创建自定义Agent接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/agents/custom/create` |
| **后端实际路径** | `POST /api/user/custom-agents` |
| **状态** | ⚠️ 路径差异 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:1114) |
**前端需要调整**: 将 `/api/user/agents/custom/create` 改为 `/api/user/custom-agents`
**请求参数**:
```json
{
"name": "string", // Agent名称
"template": "string", // 模板名称
"endpoint": "string", // 终结点URL(可选)
"apiKey": "string", // API密钥(可选)
"cpuRequest": "100m", // CPU请求
"cpuLimit": "500m", // CPU限制(可选)
"memoryRequest": "128Mi", // 内存请求
"memoryLimit": "512Mi", // 内存限制(可选)
"envConfig": {} // 环境变量配置(可选)
}
```
---
### D11. 平台Agent列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/agents/platform` |
| **后端实际路径** | `GET /api/user/agents/platform` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:466) |
**响应示例**:
```json
{
"success": true,
"data": {
"data": [
{
"id": "uuid",
"name": "Agent名称",
"description": "Agent描述",
"category": "通用",
"cpu": 1.0,
"memory": 2.0,
"status": "available"
}
]
}
}
```
---
### D12. 已部署Agent列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /agents` |
| **后端实际路径** | `GET /agents` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/agents.py`](../services/mcp-server/app/routes/agents.py:389) |
**请求参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| skip | int | 否 | 跳过数量,默认0 |
| limit | int | 否 | 返回数量限制,默认100 |
| template | string | 否 | 按模板类型过滤 |
---
### D13. 自定义Agent列表接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/agents/custom` |
| **后端实际路径** | `GET /api/user/custom-agents` |
| **状态** | ⚠️ 路径差异 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:1457) |
**前端需要调整**: 将 `/api/user/agents/custom` 改为 `/api/user/custom-agents`
---
## 编排中心模块 (Orchestration Hub)
### B12. 创建工作流接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/workflows/create` |
| **后端实际路径** | `POST /api/user/workflows/create` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:616) |
**请求参数**:
```json
{
"name": "string", // 工作流名称
"description": "string", // 工作流描述(可选)
"gateway": "MCP", // 服务网关:MCP, A2A, API
"nodes": [ // 节点列表(最多3个)
{
"agentId": "string",
"agentType": "platform", // platform 或 custom
"agentName": "string",
"order": 1
}
]
}
```
---
### B13. 运行工作流接口 ❌ 后端缺失
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/workflows/{workflow_id}/run` |
| **后端实际路径** | 未实现 |
| **状态** | ❌ 后端缺失 |
**说明**: 后端 `user.py` 中未找到工作流运行接口的实现。需要后端补充实现。
**建议实现**:
```python
@router.post("/workflows/{workflow_id}/run", response_model=SuccessResponse)
async def run_workflow(
workflow_id: str,
input: Optional[dict] = None,
principal: dict = Depends(require_auth),
db: AsyncSession = Depends(get_db)
):
"""运行指定的工作流"""
pass
```
---
### B14. 删除工作流接口 ❌ 后端缺失
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `DELETE /api/user/workflows/{workflow_id}` |
| **后端实际路径** | 未实现 |
| **状态** | ❌ 后端缺失 |
**说明**: 后端 `user.py` 中未找到工作流删除接口的实现。需要后端补充实现。
---
### D14. 工作流列表接口 ❌ 后端缺失
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/workflows` |
| **后端实际路径** | 未实现 |
| **状态** | ❌ 后端缺失 |
**说明**: 后端 `user.py` 中未找到工作流列表接口的实现。需要后端补充实现。
**建议实现**:
```python
@router.get("/workflows", response_model=SuccessResponse)
async def list_workflows(
principal: dict = Depends(require_auth),
db: AsyncSession = Depends(get_db)
):
"""获取用户的工作流列表"""
pass
```
---
## 计费与资源模块 (Billing & Resources)
### B15. 充值接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `POST /api/user/billing/recharge` |
| **后端实际路径** | `POST /api/user/billing/recharge` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:697) |
**请求参数**:
```json
{
"amount": 100.00, // 充值金额
"paymentMethod": "alipay" // 支付方式:alipay, wechat, card(可选)
}
```
**响应示例**:
```json
{
"success": true,
"data": {
"orderId": "ORD20260106140000xxxxxxxx",
"amount": 100.00,
"paymentUrl": "https://pay.taiji-ai.com/checkout?order_id=xxx",
"status": "pending"
}
}
```
---
### B16. 导出账单接口 ⚠️ 部分实现
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/billing/history?export={format}` |
| **后端实际路径** | `GET /api/user/billing/history` (支持 export 参数) |
| **状态** | ⚠️ 部分实现 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:736) |
**说明**: 后端接口支持 `export` 参数(excel, csv, pdf),但实际返回的是模拟的文件URL,未真正生成文件。
**请求参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| startTime | string | 是 | 开始时间(ISO格式) |
| endTime | string | 是 | 结束时间(ISO格式) |
| export | string | 是 | 导出格式:excel, csv, pdf |
**响应示例**:
```json
{
"success": true,
"data": {
"fileUrl": "https://exports.taiji-ai.com/xxx/excel/billing_xxx.excel",
"format": "excel",
"expiresAt": "2026-01-07T14:00:00Z"
}
}
```
---
### D15. 计费余额接口 ✅ 已对接
与 D4 相同,参见 [D4. 计费余额接口](#d4-计费余额接口--已对接)
---
### D16. 计费历史接口 ✅ 已对接
| 项目 | 说明 |
|------|------|
| **前端需求路径** | `GET /api/user/billing/history` |
| **后端实际路径** | `GET /api/user/billing/history` |
| **状态** | ✅ 完全匹配 |
| **后端文件** | [`services/mcp-server/app/routes/user.py`](../services/mcp-server/app/routes/user.py:736) |
**请求参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| startTime | string | 是 | 开始时间(ISO格式) |
| endTime | string | 是 | 结束时间(ISO格式) |
| customerName | string | 否 | 客户名称筛选 |
| minCalls | int | 否 | 最小调用次数 |
| maxCalls | int | 否 | 最大调用次数 |
| page | int | 否 | 页码,默认1 |
| pageSize | int | 否 | 每页数量,默认20 |
**响应示例**:
```json
{
"success": true,
"data": {
"total": 150,
"records": [
{
"id": "uuid",
"timestamp": "2026-01-06T10:00:00Z",
"agentName": "Agent名称",
"duration": 120,
"eu": 12,
"cost": 1.20
}
]
}
}
```
---
## 接口差异说明
### 1. 路径差异汇总
| 前端需求路径 | 后端实际路径 | 建议 |
|-------------|-------------|------|
| `POST /api/user/agents/custom/create` | `POST /api/user/custom-agents` | 前端调整路径 |
| `GET /api/user/agents/custom` | `GET /api/user/custom-agents` | 前端调整路径 |
### 2. 后端缺失接口
| 接口 | 说明 | 优先级 |
|------|------|--------|
| `GET /api/user/workflows` | 工作流列表 | 高 |
| `POST /api/user/workflows/{id}/run` | 运行工作流 | 高 |
| `DELETE /api/user/workflows/{id}` | 删除工作流 | 中 |
### 3. 后端额外提供的接口
以下接口后端已实现,但前端需求清单中未列出:
| 接口 | 说明 |
|------|------|
| `GET /api/user/custom-agent-quota` | 获取自定义Agent配额 |
| `GET /api/user/platform-agents/available` | 获取可用平台Agent |
| `POST /api/user/platform-agents/use` | 使用平台Agent |
| `DELETE /api/user/platform-agents/{instance_name}` | 停止平台Agent |
| `GET /api/user/platform-agents/instances` | 获取平台Agent实例列表 |
| `GET /api/user/custom-agents/templates` | 获取自定义Agent模板 |
| `DELETE /api/user/custom-agents/{name}` | 删除自定义Agent |
| `PUT /api/user/custom-agents/{name}/scale` | 扩缩容自定义Agent |
| `GET /api/user/custom-agents/{name}/logs` | 获取Agent日志 |
| `POST /api/user/custom-agents/{name}/restart` | 重启Agent |
| `GET /api/user/agent-billing/stats` | Agent计费统计 |
| `GET /api/user/agent-billing/history` | Agent计费历史 |
| `GET /api/user/agents/activity` | Agent活动数据 |
---
## 附录:完整接口清单
### 按钮操作接口
| 序号 | 接口名称 | 方法 | 路径 | 状态 | 所属模块 |
|------|----------|------|------|------|----------|
| B1 | 用户登录 | POST | /api/auth/login | ✅ 已对接 | 认证 |
| B2 | 用户登出 | POST | /api/auth/logout | ✅ 已对接 | 认证 |
| B3 | 刷新Token | POST | /api/auth/refresh | ✅ 已对接 | 认证 |
| B4 | 修改密码 | PUT | /api/auth/password | ✅ 已对接 | 认证 |
| B5 | 重新生成API密钥 | POST | /api/auth/keys/regenerate | ✅ 已对接 | 认证 |
| B6 | 创建API | POST | /api/user/gateway/api/create | ✅ 已对接 | 服务网关 |
| B7 | 选择网关类型 | POST | /api/user/gateway/select | ✅ 已对接 | 服务网关 |
| B8 | 生成工具 | POST | /api/user/tools/generate | ✅ 已对接 | 数据与工具 |
| B9 | 创建数据模板 | POST | /api/user/data-templates/create | ✅ 已对接 | 数据与工具 |
| B10 | 部署Agent | POST | /api/user/agents/deploy | ✅ 已对接 | 代理工厂 |
| B11 | 创建自定义Agent | POST | /api/user/custom-agents | ⚠️ 路径差异 | 代理工厂 |
| B12 | 创建工作流 | POST | /api/user/workflows/create | ✅ 已对接 | 编排中心 |
| B13 | 运行工作流 | POST | /api/user/workflows/{id}/run | ❌ 后端缺失 | 编排中心 |
| B14 | 删除工作流 | DELETE | /api/user/workflows/{id} | ❌ 后端缺失 | 编排中心 |
| B15 | 充值 | POST | /api/user/billing/recharge | ✅ 已对接 | 计费与资源 |
| B16 | 导出账单 | GET | /api/user/billing/history?export= | ⚠️ 部分实现 | 计费与资源 |
### 数据展示接口
| 序号 | 接口名称 | 方法 | 路径 | 状态 | 所属模块 |
|------|----------|------|------|------|----------|
| D1 | 获取API密钥信息 | GET | /api/auth/keys/info | ✅ 已对接 | 认证 |
| D2 | 用户仪表板统计 | GET | /api/user/dashboard/stats | ✅ 已对接 | 概览 |
| D3 | 监控仪表盘 | GET | /api/v1/monitoring/dashboard | ✅ 已对接 | 概览 |
| D4 | 计费余额 | GET | /api/user/billing/balance | ✅ 已对接 | 概览 |
| D5 | 监控趋势数据 | GET | /api/v1/monitoring/trends | ✅ 已对接 | 概览 |
| D6 | 网关API列表 | GET | /api/user/gateway/apis | ✅ 已对接 | 服务网关 |
| D7 | 网关监控数据 | GET | /api/user/gateway/monitoring | ✅ 已对接 | 服务网关 |
| D8 | 模型提供商列表 | GET | /api/providers/models | ✅ 已对接 | 服务网关 |
| D9 | 工具列表 | GET | /tools | ✅ 已对接 | 数据与工具 |
| D10 | 统计信息 | GET | /stats | ✅ 已对接 | 数据与工具 |
| D11 | 平台Agent列表 | GET | /api/user/agents/platform | ✅ 已对接 | 代理工厂 |
| D12 | 已部署Agent列表 | GET | /agents | ✅ 已对接 | 代理工厂 |
| D13 | 自定义Agent列表 | GET | /api/user/custom-agents | ⚠️ 路径差异 | 代理工厂 |
| D14 | 工作流列表 | GET | /api/user/workflows | ❌ 后端缺失 | 编排中心 |
| D15 | 计费余额 | GET | /api/user/billing/balance | ✅ 已对接 | 计费与资源 |
| D16 | 计费历史 | GET | /api/user/billing/history | ✅ 已对接 | 计费与资源 |
### 接口统计
| 状态 | 数量 | 占比 |
|------|------|------|
| ✅ 完全匹配 | 26 | 81.3% |
| ⚠️ 路径差异/部分实现 | 3 | 9.4% |
| ❌ 后端缺失 | 3 | 9.4% |
| **总计** | **32** | **100%** |
---
## 版本历史
| 版本 | 日期 | 更新内容 |
|------|------|----------|
| v1.0.0 | 2026-01-06 | 初始版本,完成前后端接口核实 |
File diff suppressed because it is too large Load Diff
@@ -1,9 +1,10 @@
# 超级管理员控制台 - 接口对接文档
> **版本**: v1.0.1
> **版本**: v1.0.3
> **更新时间**: 2026-01-06
> **说明**: 本文档基于前端业务需求清单与后端API接口清单核实,列出所有超级管理员端接口的对接状态
> **最新测试**: 2026-01-06 13:37 UTC - 所有已对接接口测试通过
> **最新测试**: 2026-01-06 14:54 UTC - 所有已对接接口测试通过
> **前端代码核对**: 2026-01-06 14:54 UTC - 已完成前端代码与接口文档的一致性核对,修复健康状态判断问题
---
@@ -302,10 +303,13 @@
|------|-----|
| **接口路径** | `DELETE /api/admin/channels/{channel_id}` |
| **后端状态** | ✅ 已实现 (admin.py) |
| **前端状态** | ✅ 已实现 (2026-01-06 修复) |
| **权限要求** | super_admin |
**按钮位置**: 渠道管理页面 → 渠道卡片 → 更多操作菜单 → "删除渠道"
**前端调用**: 直接fetch调用 `DELETE ${API_BASE_URLS.mcpServer}/api/admin/channels/${channel.id}`
**路径参数**:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
@@ -954,39 +958,38 @@
**展示位置**: 监控页面 → Agent健康监控区域 → 汇总统计卡片
**响应字段**:
**实际响应字段** (2026-01-06 14:54 UTC 测试确认):
```json
{
"success": true,
"data": {
"summary": {
"total": 10,
"byHealthStatus": {
"healthy": 8,
"warning": 1,
"critical": 1
}
},
"agents": [
{
"id": "agent-uuid",
"name": "echo-agent-1",
"type": "platform",
"healthStatus": "healthy",
"cpuUsage": "50m",
"name": "alice-echo",
"template": "echo_agent",
"status": "Running",
"podName": "",
"podIp": "10.244.1.143",
"namespace": "ai-agents",
"cpuUsage": "0.01m",
"memoryUsage": "8.5Mi",
"cpuLimit": "500m",
"cpuUtilization": 10.0,
"memoryUsage": "128Mi",
"memoryLimit": "512Mi",
"memoryUtilization": 25.0,
"status": "running",
"source": "k8s"
"hasRealtimeMetrics": true,
"metricsTimestamp": "2026-01-06T14:44:572",
"createdAt": "2026-01-05T07:36:09+00:00"
}
]
}
}
```
> **重要说明**:
> - `status` 字段值为 `"Running"`(首字母大写),不是 `"running"`
> - 没有 `healthStatus` 字段,健康状态通过 `status` 字段判断
> - 没有 `byHealthStatus` 汇总统计,前端需要自行计算
> - 前端判断健康状态时应使用: `status === "Running"` 或 `status === "available"`
---
#### D10. Agent监控接口 ✅ 已对接
+116 -37
View File
@@ -17,7 +17,8 @@ from models import (
User, Channel, Agent, ResourceAllocation,
BillingRecord, Application, ModelProvider,
ChannelProviderAccess, ProviderApplication,
ChannelCustomAgentQuota, ResourceApplication, PlatformAgentQuota
ChannelCustomAgentQuota, ResourceApplication, PlatformAgentQuota,
PlatformAgentTemplateConfig
)
from app.auth import require_auth, get_password_hash
from app.schemas import (
@@ -2652,8 +2653,22 @@ TEMPLATE_RESOURCE_CONFIG: Dict[str, Dict[str, str]] = {
}
async def _get_platform_templates_from_agent_manager() -> List[Dict[str, Any]]:
"""从 Agent Manager 获取平台 Agent 模板列表"""
async def _get_platform_templates_from_agent_manager(db: Optional[AsyncSession] = None) -> List[Dict[str, Any]]:
"""从 Agent Manager 获取平台 Agent 模板列表
Args:
db: 数据库会话,用于读取管理员配置。如果提供,将从数据库读取配置并覆盖默认值。
"""
# 从数据库获取管理员配置
db_configs: Dict[str, PlatformAgentTemplateConfig] = {}
if db:
try:
config_result = await db.execute(select(PlatformAgentTemplateConfig))
db_configs = {c.template_name: c for c in config_result.scalars().all()}
logger.debug(f"admin: 从数据库加载了 {len(db_configs)} 个模板配置")
except Exception as e:
logger.warning(f"admin: 从数据库加载模板配置失败: {e}")
try:
from app.agent_manager_client import get_agent_manager_client, AgentManagerError
client = get_agent_manager_client()
@@ -2663,22 +2678,46 @@ async def _get_platform_templates_from_agent_manager() -> List[Dict[str, Any]]:
for template in templates:
template_name = template.template
display_info = TEMPLATE_DISPLAY_INFO.get(template_name, {})
resource_config = TEMPLATE_RESOURCE_CONFIG.get(template_name, {})
default_resource_config = TEMPLATE_RESOURCE_CONFIG.get(template_name, {})
result.append({
"name": template_name,
"displayName": display_info.get("displayName", template_name),
"description": display_info.get("description", f"{template_name} Agent"),
"category": display_info.get("category", "general"),
"version": "1.0.0",
"port": template.port,
"envInfo": template.env_info,
"cpuRequest": resource_config.get("cpuRequest", "100m"),
"cpuLimit": resource_config.get("cpuLimit", "500m"),
"memoryRequest": resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": resource_config.get("memoryLimit", "512Mi"),
"status": "available",
})
# 优先使用数据库中的管理员配置,否则使用默认值
db_config = db_configs.get(template_name)
if db_config:
# 使用数据库配置覆盖默认值
result.append({
"name": template_name,
"displayName": db_config.display_name or display_info.get("displayName", template_name),
"description": db_config.description or display_info.get("description", f"{template_name} Agent"),
"category": display_info.get("category", "general"),
"version": "1.0.0",
"port": template.port,
"envInfo": template.env_info,
"cpuRequest": db_config.cpu_request or default_resource_config.get("cpuRequest", "100m"),
"cpuLimit": db_config.cpu_limit or default_resource_config.get("cpuLimit", "500m"),
"memoryRequest": db_config.memory_request or default_resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": db_config.memory_limit or default_resource_config.get("memoryLimit", "512Mi"),
"maxPods": db_config.max_pods if db_config.max_pods is not None else 10,
"isEnabled": db_config.is_enabled if db_config.is_enabled is not None else True,
"status": "available" if (db_config.is_enabled is None or db_config.is_enabled) else "disabled",
})
else:
# 使用默认配置
result.append({
"name": template_name,
"displayName": display_info.get("displayName", template_name),
"description": display_info.get("description", f"{template_name} Agent"),
"category": display_info.get("category", "general"),
"version": "1.0.0",
"port": template.port,
"envInfo": template.env_info,
"cpuRequest": default_resource_config.get("cpuRequest", "100m"),
"cpuLimit": default_resource_config.get("cpuLimit", "500m"),
"memoryRequest": default_resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": default_resource_config.get("memoryLimit", "512Mi"),
"maxPods": 10,
"isEnabled": True,
"status": "available",
})
logger.info("admin: 从 Agent Manager 获取平台模板成功", count=len(result))
return result
@@ -2688,19 +2727,40 @@ async def _get_platform_templates_from_agent_manager() -> List[Dict[str, Any]]:
# 返回基于 TEMPLATE_DISPLAY_INFO 的默认模板
result = []
for name, info in TEMPLATE_DISPLAY_INFO.items():
resource_config = TEMPLATE_RESOURCE_CONFIG.get(name, {})
result.append({
"name": name,
"displayName": info.get("displayName", name),
"description": info.get("description", f"{name} Agent"),
"category": info.get("category", "general"),
"version": "1.0.0",
"cpuRequest": resource_config.get("cpuRequest", "100m"),
"cpuLimit": resource_config.get("cpuLimit", "500m"),
"memoryRequest": resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": resource_config.get("memoryLimit", "512Mi"),
"status": "available",
})
default_resource_config = TEMPLATE_RESOURCE_CONFIG.get(name, {})
# 优先使用数据库中的管理员配置
db_config = db_configs.get(name)
if db_config:
result.append({
"name": name,
"displayName": db_config.display_name or info.get("displayName", name),
"description": db_config.description or info.get("description", f"{name} Agent"),
"category": info.get("category", "general"),
"version": "1.0.0",
"cpuRequest": db_config.cpu_request or default_resource_config.get("cpuRequest", "100m"),
"cpuLimit": db_config.cpu_limit or default_resource_config.get("cpuLimit", "500m"),
"memoryRequest": db_config.memory_request or default_resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": db_config.memory_limit or default_resource_config.get("memoryLimit", "512Mi"),
"maxPods": db_config.max_pods if db_config.max_pods is not None else 10,
"isEnabled": db_config.is_enabled if db_config.is_enabled is not None else True,
"status": "available" if (db_config.is_enabled is None or db_config.is_enabled) else "disabled",
})
else:
result.append({
"name": name,
"displayName": info.get("displayName", name),
"description": info.get("description", f"{name} Agent"),
"category": info.get("category", "general"),
"version": "1.0.0",
"cpuRequest": default_resource_config.get("cpuRequest", "100m"),
"cpuLimit": default_resource_config.get("cpuLimit", "500m"),
"memoryRequest": default_resource_config.get("memoryRequest", "128Mi"),
"memoryLimit": default_resource_config.get("memoryLimit", "512Mi"),
"maxPods": 10,
"isEnabled": True,
"status": "available",
})
return result
@@ -2719,17 +2779,20 @@ async def _validate_template_exists(template_name: str) -> bool:
@router.get("/platform-agents/templates", response_model=SuccessResponse)
async def list_platform_agent_templates(
principal: dict = Depends(require_auth),
db: AsyncSession = Depends(get_db)
):
"""
获取平台 Agent 模板列表
从 Agent Manager 动态获取所有可用的平台 Agent 模板信息。
如果管理员通过配置接口修改了模板配置,将返回修改后的配置值。
权限:view:resources (所有管理员)
"""
_verify_read_permission(principal)
templates = await _get_platform_templates_from_agent_manager()
# 传递数据库会话以读取管理员配置
templates = await _get_platform_templates_from_agent_manager(db)
return SuccessResponse(data={"templates": templates})
@@ -2799,6 +2862,10 @@ async def review_platform_agent_application(
批准后会自动创建渠道的平台 Agent 配额记录。
支持两种请求格式:
1. 新格式(前端使用): {"action": "approve", "podQuota": 5, "reviewReason": "申请已批准"}
2. 旧格式: {"approved": true, "approvedPodQuota": 5, "reason": "申请已批准"}
权限:manage:applications (super_admin, billing_admin)
"""
_verify_write_permission(principal)
@@ -2827,15 +2894,27 @@ async def review_platform_agent_application(
detail="该申请已被处理"
)
# 使用 schema 方法获取值(支持新旧两种格式)
try:
is_approved = req.get_approved()
except ValueError as e:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=str(e)
)
review_reason = req.get_reason()
pod_quota = req.get_pod_quota()
# 更新申请状态
application.status = "approved" if req.approved else "rejected"
application.status = "approved" if is_approved else "rejected"
application.reviewed_by = user_id
application.review_reason = req.reason
application.review_reason = review_reason
application.reviewed_at = datetime.utcnow()
# 如果批准,创建渠道的平台 Agent 配额记录
if req.approved:
approved_quota = req.approvedPodQuota or application.requested_pod_quota
if is_approved:
approved_quota = pod_quota or application.requested_pod_quota
application.approved_pod_quota = approved_quota
# 检查是否已存在配额记录
@@ -2869,7 +2948,7 @@ async def review_platform_agent_application(
await db.commit()
return SuccessResponse(
message=f"平台 Agent 申请已{'批准' if req.approved else '拒绝'}"
message=f"平台 Agent 申请已{'批准' if is_approved else '拒绝'}"
)
+45 -4
View File
@@ -735,12 +735,23 @@ class ResourceApplicationInfo(BaseModel):
class ReviewResourceApplicationRequest(BaseModel):
"""审批资源申请请求"""
approved: bool
reason: Optional[str] = Field(None, max_length=500, description="审批意见")
"""审批资源申请请求
支持两种格式:
1. 新格式(前端使用): action="approve"/"reject", podQuota, reviewReason
2. 旧格式: approved=true/false, approvedPodQuota, reason
"""
# 新格式字段(前端使用)
action: Optional[str] = Field(None, pattern="^(approve|reject)$", description="审批动作: approve/reject")
podQuota: Optional[int] = Field(None, ge=0, description="批准的 Pod 配额(新格式)")
reviewReason: Optional[str] = Field(None, max_length=500, description="审批意见(新格式)")
# 旧格式字段(保留兼容)
approved: Optional[bool] = Field(None, description="是否批准(旧格式)")
reason: Optional[str] = Field(None, max_length=500, description="审批意见(旧格式)")
# 平台 Agent 审批
approvedPodQuota: Optional[int] = Field(None, ge=0, description="批准的 Pod 配额")
approvedPodQuota: Optional[int] = Field(None, ge=0, description="批准的 Pod 配额(旧格式)")
# 供应商审批
approvedRpm: Optional[int] = Field(None, ge=0, description="批准的 RPM")
@@ -749,6 +760,36 @@ class ReviewResourceApplicationRequest(BaseModel):
# 自定义 Agent 资源审批(已废弃,保留兼容)
approvedCpuQuota: Optional[float] = Field(None, ge=0, description="批准的 CPU 配额(已废弃)")
approvedMemoryQuota: Optional[float] = Field(None, ge=0, description="批准的内存配额(已废弃)")
@validator('approved', pre=True, always=True)
def resolve_approved(cls, v, values):
"""从 action 字段解析 approved 值"""
if v is not None:
return v
action = values.get('action')
if action == 'approve':
return True
elif action == 'reject':
return False
return None
def get_approved(self) -> bool:
"""获取是否批准的值"""
if self.approved is not None:
return self.approved
if self.action == 'approve':
return True
elif self.action == 'reject':
return False
raise ValueError("必须提供 action 或 approved 字段")
def get_pod_quota(self) -> Optional[int]:
"""获取 Pod 配额"""
return self.podQuota or self.approvedPodQuota
def get_reason(self) -> Optional[str]:
"""获取审批意见"""
return self.reviewReason or self.reason
# ============= 平台 Agent 配额管理 =============