feat: 添加邮箱验证码功能、删除显示名称字段、修复密码修改接口

- 在用户注册页面添加邮箱验证码输入和发送功能
- 删除注册表单和个人信息对话框中的显示名称字段
- 将用户名改为必填项
- 修复超级管理员修改租户密码时缺少channel_id参数的问题
- 改进监控仪表板API的错误处理
- 添加API接口完整清单文档
This commit is contained in:
zhanggangyong
2026-01-11 17:14:47 +00:00
parent 87cfbafc44
commit 3978ca235e
5 changed files with 1054 additions and 39 deletions
+3 -1
View File
@@ -1165,7 +1165,9 @@ export default function AdminDashboard() {
setChangePasswordLoading(true) setChangePasswordLoading(true)
try { try {
const result = await TaijiAPIClient.changeTenantPassword(selectedTenantForEdit.id, newPassword) // 超级管理员修改租户密码时,需要提供 channel_id 参数
const channelId = selectedChannel?.id
const result = await TaijiAPIClient.changeTenantPassword(selectedTenantForEdit.id, newPassword, channelId)
if (result?.success) { if (result?.success) {
alert(language === "zh" ? "密码修改成功" : "Password changed successfully") alert(language === "zh" ? "密码修改成功" : "Password changed successfully")
setIsChangePasswordDialogOpen(false) setIsChangePasswordDialogOpen(false)
+121 -18
View File
@@ -2,7 +2,7 @@
import type React from "react" import type React from "react"
import { useState } from "react" import { useState, useEffect } from "react"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input" import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label" import { Label } from "@/components/ui/label"
@@ -21,10 +21,70 @@ export default function LoginPage() {
const [password, setPassword] = useState("") const [password, setPassword] = useState("")
const [confirmPassword, setConfirmPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("")
const [username, setUsername] = useState("") const [username, setUsername] = useState("")
const [fullName, setFullName] = useState("") const [verificationCode, setVerificationCode] = useState("")
const [showPassword, setShowPassword] = useState(false) const [showPassword, setShowPassword] = useState(false)
const [showConfirmPassword, setShowConfirmPassword] = useState(false) const [showConfirmPassword, setShowConfirmPassword] = useState(false)
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [isSendingCode, setIsSendingCode] = useState(false)
const [countdown, setCountdown] = useState(0)
// 倒计时效果
useEffect(() => {
if (countdown > 0) {
const timer = setTimeout(() => setCountdown(countdown - 1), 1000)
return () => clearTimeout(timer)
}
}, [countdown])
// 发送验证码
const handleSendVerificationCode = async () => {
if (!email) {
toast({
title: t("错误", "Error"),
description: t("请先输入邮箱地址", "Please enter your email address first"),
variant: "destructive",
})
return
}
// 简单的邮箱格式验证
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (!emailRegex.test(email)) {
toast({
title: t("错误", "Error"),
description: t("请输入有效的邮箱地址", "Please enter a valid email address"),
variant: "destructive",
})
return
}
setIsSendingCode(true)
try {
const result = await TaijiAPIClient.sendEmailVerificationCode(email)
if (result && result.success) {
toast({
title: t("发送成功", "Success"),
description: t("验证码已发送到您的邮箱,请查收", "Verification code has been sent to your email"),
})
setCountdown(60) // 60秒倒计时
} else {
toast({
title: t("发送失败", "Failed"),
description: (result as any)?.message || t("发送验证码失败,请重试", "Failed to send verification code, please try again"),
variant: "destructive",
})
}
} catch (error: any) {
console.error("Send verification code error:", error)
toast({
title: t("发送失败", "Failed"),
description: error.message || t("发送验证码失败,请重试", "Failed to send verification code, please try again"),
variant: "destructive",
})
} finally {
setIsSendingCode(false)
}
}
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault() e.preventDefault()
@@ -39,6 +99,22 @@ export default function LoginPage() {
}) })
return return
} }
if (!verificationCode) {
toast({
title: t("错误", "Error"),
description: t("请输入邮箱验证码", "Please enter the email verification code"),
variant: "destructive",
})
return
}
if (!username) {
toast({
title: t("错误", "Error"),
description: t("用户名为必填项", "Username is required"),
variant: "destructive",
})
return
}
if (password.length < 8) { if (password.length < 8) {
toast({ toast({
title: t("错误", "Error"), title: t("错误", "Error"),
@@ -62,7 +138,7 @@ export default function LoginPage() {
try { try {
if (isRegisterMode) { if (isRegisterMode) {
// 注册 // 注册
const result = await TaijiAPIClient.register(email, password, username || undefined, fullName || undefined) const result = await TaijiAPIClient.register(email, password, verificationCode, username, undefined)
if (result && result.success) { if (result && result.success) {
toast({ toast({
@@ -169,26 +245,52 @@ export default function LoginPage() {
{/* 注册模式下的额外字段 */} {/* 注册模式下的额外字段 */}
{isRegisterMode && ( {isRegisterMode && (
<> <>
{/* 邮箱验证码 */}
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="username">{t("用户名", "Username")} ({t("可选", "Optional")})</Label> <Label htmlFor="verificationCode">
<Input {t("邮箱验证码", "Email Verification Code")} <span className="text-destructive">*</span>
id="username" </Label>
type="text" <div className="flex gap-2">
placeholder={t("请输入用户名(可选)", "Enter username (optional)")} <Input
value={username} id="verificationCode"
onChange={(e) => setUsername(e.target.value)} type="text"
className="h-11" placeholder={t("请输入验证码", "Enter verification code")}
/> value={verificationCode}
onChange={(e) => setVerificationCode(e.target.value)}
required
className="h-11 flex-1"
maxLength={6}
/>
<Button
type="button"
variant="outline"
onClick={handleSendVerificationCode}
disabled={isSendingCode || countdown > 0 || !email}
className="h-11 whitespace-nowrap"
>
{isSendingCode
? t("发送中...", "Sending...")
: countdown > 0
? `${countdown}s`
: t("发送验证码", "Send Code")}
</Button>
</div>
<p className="text-xs text-muted-foreground">
{t("验证码将发送到您的邮箱", "Verification code will be sent to your email")}
</p>
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="fullName">{t("显示名称", "Display Name")} ({t("可选", "Optional")})</Label> <Label htmlFor="username">
{t("用户名", "Username")} <span className="text-destructive">*</span>
</Label>
<Input <Input
id="fullName" id="username"
type="text" type="text"
placeholder={t("请输入显示名称(可选)", "Enter display name (optional)")} placeholder={t("请输入用户名", "Enter username")}
value={fullName} value={username}
onChange={(e) => setFullName(e.target.value)} onChange={(e) => setUsername(e.target.value)}
required
className="h-11" className="h-11"
/> />
</div> </div>
@@ -291,7 +393,8 @@ export default function LoginPage() {
setPassword("") setPassword("")
setConfirmPassword("") setConfirmPassword("")
setUsername("") setUsername("")
setFullName("") setVerificationCode("")
setCountdown(0)
}} }}
> >
{isRegisterMode {isRegisterMode
-14
View File
@@ -594,20 +594,6 @@ export function DashboardLayout({ children }: { children: React.ReactNode }) {
</p> </p>
</div> </div>
{/* 显示名称 - 只读 */}
<div className="space-y-2">
<Label htmlFor="name">{t("显示名称", "Display Name")}</Label>
<Input
id="name"
value={userInfo?.name || ""}
readOnly
className="bg-muted cursor-not-allowed"
/>
<p className="text-xs text-muted-foreground">
{t("显示名称不可修改", "Display name cannot be modified")}
</p>
</div>
{/* 邮箱 - 只读 */} {/* 邮箱 - 只读 */}
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="email">{t("邮箱", "Email")}</Label> <Label htmlFor="email">{t("邮箱", "Email")}</Label>
+848
View File
@@ -0,0 +1,848 @@
# API 接口完整清单 - 详细版
> 生成时间: 2026-01-08
>
> 本文档列出了 taiji-AI-PAD 平台所有后端 API 接口、对应功能和业务逻辑。
---
## 目录
1. [认证模块 (Auth)](#1-认证模块-auth)
2. [用户侧平台 (User)](#2-用户侧平台-user)
3. [渠道合作伙伴 (Channel)](#3-渠道合作伙伴-channel)
4. [超级管理员 (Admin)](#4-超级管理员-admin)
5. [供应商管理 (Providers)](#5-供应商管理-providers)
6. [计费与资源管理 (Billing Admin)](#6-计费与资源管理-billing-admin)
7. [Agent 管理 (Agents)](#7-agent-管理-agents)
8. [工具管理 (Tools)](#8-工具管理-tools)
9. [会话管理 (Sessions)](#9-会话管理-sessions)
10. [监控与健康检查 (Monitoring)](#10-监控与健康检查-monitoring)
11. [WebSocket 接口](#11-websocket-接口)
12. [前端集成接口 (Frontend Integration)](#12-前端集成接口-frontend-integration)
13. [平台 Agent 配额管理](#13-平台-agent-配额管理)
14. [Data Ingestion 服务](#14-data-ingestion-服务)
---
## 1. 认证模块 (Auth)
**路由前缀**: `/api/auth`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/login` | POST | 统一登录接口 | 支持用户/渠道/管理员登录,根据邮箱后缀或角色判断登录类型,返回 JWT Token |
| `/logout` | POST | 登出 | 将当前 Token 加入黑名单,使其失效 |
| `/refresh` | POST | 刷新令牌 | 使用 Refresh Token 获取新的 Access Token |
| `/password` | PUT | 修改密码 | 验证旧密码后更新为新密码 |
| `/keys/info` | GET | 获取 API 密钥信息 | 返回当前用户的 API Key 信息(脱敏显示) |
| `/keys/regenerate` | POST | 重新生成 API 密钥 | 生成新的 API Key,旧 Key 立即失效 |
**权限说明**:
- 所有接口需要认证(除 `/login` 外)
- 支持角色: `super_admin`, `billing_admin`, `operations_admin`, `channel_admin`, `user`
---
## 2. 用户侧平台 (User)
**路由前缀**: `/api/user`
### 2.1 仪表板
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/dashboard/stats` | GET | 获取仪表板统计 | 返回活跃 Agent 数、总请求数、EU 余额、系统健康度 |
| `/agents/activity` | GET | 获取 Agent 活动 | 返回最近 20 条执行记录 |
| `/resources/usage` | GET | 获取资源使用情况 | 返回 Agent 数、EU 消耗、CPU/内存使用 |
### 2.2 服务网关
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/gateway/select` | POST | 选择网关类型 | 选择 MCP/A2A/API 网关类型 |
| `/gateway/api/create` | POST | 创建网关 API | 创建新的网关 API 配置 |
| `/gateway/apis` | GET | 获取网关 API 列表 | 返回所有已配置的网关 API |
| `/gateway/monitoring` | GET | 网关监控 | 返回网关状态、吞吐量、错误率 |
### 2.3 自定义 Agent 配额
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/custom-agent-quota` | GET | 获取自定义 Agent 配额 | 返回 CPU/内存配额及使用情况 |
### 2.4 数据与工具
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/tools/generate` | POST | 生成工具 | 根据配置生成新工具 |
| `/tools/list` | GET | 获取工具列表 | 返回所有可用工具 |
| `/data-templates/create` | POST | 创建数据模板 | 创建新的数据模板配置 |
### 2.5 代理工厂
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/agents/platform` | GET | 获取平台 Agent 列表 | 返回所有可用的平台 Agent |
| `/agents/deploy` | POST | 部署 Agent | 部署指定的 Agent 实例 |
| `/agents/deployed` | GET | 获取已部署 Agent | 返回当前用户已部署的 Agent |
### 2.6 编排中心(工作流)
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/workflows/create` | POST | 创建工作流 | 创建新的工作流配置 |
| `/workflows/list` | GET | 获取工作流列表 | 返回所有工作流 |
| `/workflows/{id}` | PUT | 更新工作流 | 更新工作流配置 |
| `/workflows/{id}` | DELETE | 删除工作流 | 删除指定工作流 |
| `/workflows/{id}/run` | POST | 运行工作流 | 执行工作流,按顺序调用各节点 |
### 2.7 模型使用(LiteLLM 集成)
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/models` | GET | 获取可用模型列表 | 从 LiteLLM 获取租户可用的模型 |
| `/models/{model}/chat` | POST | 模型对话 | 调用 LiteLLM 进行模型对话 |
| `/models/usage` | GET | 获取模型使用统计 | 返回模型调用次数、Token 消耗 |
### 2.8 计费与资源
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/billing/balance` | GET | 获取余额 | 返回当前 EU 余额 |
| `/billing/history` | GET | 获取计费历史 | 返回计费记录列表 |
| `/billing/recharge` | POST | 充值 | 增加 EU 余额 |
### 2.9 平台 Agent 使用
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/platform-agents` | GET | 获取平台 Agent 配额 | 返回用户可用的平台 Agent 配额 |
| `/platform-agents/{template}/instances` | GET | 获取 Agent 实例列表 | 返回指定模板的运行实例 |
| `/platform-agents/{agent_name}` | DELETE | 停止 Agent | 停止并释放 Agent 实例 |
| `/platform-agents/quota` | GET | 获取配额使用情况 | 返回配额使用详情 |
| `/platform-agents/{agent_name}/status` | GET | 获取 Agent 状态 | 从 K8s 获取实时状态 |
### 2.10 自定义 Agent 管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/custom-agents` | GET | 获取自定义 Agent 列表 | 返回用户创建的自定义 Agent |
| `/custom-agents` | POST | 创建自定义 Agent | 创建新的自定义 Agent,检查配额 |
| `/custom-agents/{id}` | DELETE | 删除自定义 Agent | 删除 Agent 并释放配额 |
| `/custom-agents/{id}/scale` | POST | 扩缩容 | 调整 Agent 副本数 |
| `/custom-agents/{id}/logs` | GET | 获取日志 | 获取 Agent 运行日志 |
| `/custom-agents/{id}/restart` | POST | 重启 Agent | 重启 Agent 实例 |
### 2.11 Agent 计费统计
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/agents/billing/stats` | GET | 获取 Agent 计费统计 | 返回 Agent 使用费用统计 |
| `/agents/billing/records` | GET | 获取计费记录 | 返回详细计费记录 |
---
## 3. 渠道合作伙伴 (Channel)
**路由前缀**: `/api/channel`
### 3.1 认证
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/auth/login` | POST | 渠道登录 | 渠道管理员登录,返回带 channelId 的 Token |
### 3.2 仪表板
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/dashboard/stats` | GET | 获取仪表板统计 | 返回租户数、Agent 数、EU 消耗 |
### 3.3 租户管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/tenants` | GET | 获取租户列表 | 返回渠道下所有租户 |
| `/tenants/create` | POST | 创建租户 | 创建新租户,同时在 LiteLLM 创建 Key |
| `/tenants/{id}` | GET | 获取租户详情 | 返回租户详细信息 |
| `/tenants/{id}` | PUT | 更新租户 | 更新租户信息 |
| `/tenants/{id}` | DELETE | 删除租户 | 软删除租户 |
| `/tenants/{id}/status` | PUT | 更新租户状态 | 启用/停用租户 |
| `/tenants/{id}/permissions` | PUT | 更新租户权限 | 设置租户权限列表 |
| `/tenants/{id}/resources` | PUT | 更新租户资源 | 分配资源配额 |
| `/tenants/{id}/billing` | PUT | 更新租户计费 | 设置计费参数 |
| `/tenants/{id}/recharge` | POST | 租户充值 | 为租户充值 EU |
| `/tenants/{id}/credit` | PUT | 设置授信额度 | 设置租户授信额度 |
### 3.4 租户模型分配(LiteLLM 集成)
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/tenants/{id}/models` | GET | 获取租户模型 | 返回租户可用的模型列表 |
| `/tenants/{id}/models` | PUT | 分配租户模型 | 更新租户的 LiteLLM Key 模型权限 |
### 3.5 管理员管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/admins` | GET | 获取管理员列表 | 返回渠道下的管理员 |
| `/admins/create` | POST | 创建管理员 | 创建渠道管理员 |
| `/admins/{id}/permissions` | PUT | 更新管理员权限 | 设置管理员权限 |
### 3.6 资源申请
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/resources/agents` | GET | 获取 Agent 资源 | 返回渠道可用的 Agent 配额 |
| `/resources/models` | GET | 获取模型资源 | 返回渠道可用的模型 |
| `/resources/apply` | POST | 申请资源 | 提交资源申请 |
### 3.7 计费统计
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/billing/stats` | GET | 获取计费统计 | 返回渠道计费汇总 |
### 3.8 供应商管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/providers/available` | GET | 获取可用供应商 | 返回所有可申请的供应商 |
| `/providers/applications` | GET | 获取供应商申请 | 返回渠道的供应商申请列表 |
| `/providers/applications` | POST | 申请供应商 | 提交供应商使用申请 |
| `/providers/authorized` | GET | 获取已授权供应商 | 返回已授权的供应商列表 |
### 3.9 平台 Agent 资源申请
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/available-platform-agents` | GET | 获取可用平台 Agent | 返回所有可申请的平台 Agent 模板 |
| `/applications/platform-agents` | GET | 获取申请列表 | 返回渠道的平台 Agent 申请 |
| `/applications/platform-agents` | POST | 申请平台 Agent | 提交平台 Agent 配额申请 |
| `/platform-agents` | GET | 获取已分配配额 | 返回渠道已有的平台 Agent 配额 |
| `/tenants/{id}/platform-agents` | POST | 分配给租户 | 将配额分配给租户并启动 Pod |
### 3.10 Agent 计费统计
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/agents/billing/overview` | GET | 获取 Agent 计费概览 | 返回渠道下 Agent 计费汇总 |
---
## 4. 超级管理员 (Admin)
**路由前缀**: `/api/admin`
### 4.1 管理员管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/admins` | GET | 获取管理员列表 | 返回所有活跃管理员(仅超级管理员) |
| `/admins/create` | POST | 创建管理员 | 创建 billing_admin 或 operations_admin |
| `/admins/{id}` | DELETE | 删除管理员 | 软删除管理员 |
### 4.2 仪表板
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/dashboard/stats` | GET | 获取平台统计 | 返回渠道数、租户数、Agent 数、收入等 |
| `/dashboard/recent-logins` | GET | 获取最近登录 | 返回最近登录的租户列表 |
### 4.3 渠道管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/channels` | GET | 获取渠道列表 | 返回所有渠道及统计信息 |
| `/channels/create` | POST | 创建渠道 | 创建渠道,同时在 LiteLLM 创建 Team |
| `/channels/{id}` | PUT | 更新渠道 | 更新渠道信息 |
| `/channels/{id}` | DELETE | 删除渠道 | 软删除渠道,同时删除 LiteLLM Team |
| `/channels/{id}/resources` | GET | 获取渠道资源 | 返回渠道的资源配置 |
| `/channels/{id}/resources` | PUT | 分配渠道资源 | 分配模型、Agent、配额,更新 LiteLLM Team |
| `/channels/{id}/commission` | PUT | 更新佣金比例 | 设置渠道佣金比例 |
| `/channels/{id}/admins` | GET | 获取渠道管理员 | 返回渠道下的管理员列表 |
| `/tenants` | GET | 获取租户列表 | 返回指定渠道的租户(需指定 channel_id) |
### 4.4 资源分配统计
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/resources/allocation-stats` | GET | 获取资源分配统计 | 返回平台端/自定义 Agent 统计、配额统计 |
### 4.5 申请审批
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/channels/applications` | GET | 获取申请列表 | 返回所有渠道申请 |
| `/channels/applications/{id}/review` | PUT | 审批申请 | 批准或拒绝申请 |
### 4.6 资源管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/resources/litellm-models` | GET | 获取 LiteLLM 模型 | 从 LiteLLM 获取所有可用模型 |
| `/resources/models` | GET | 获取模型供应商 | 返回所有模型供应商 |
| `/resources/agents` | GET | 获取所有 Agent | 返回平台端 + 自定义 Agent |
| `/resources/agents/{id}` | DELETE | 删除 Agent | 软删除 Agent |
| `/resources/agents/{id}/config` | PUT | 更新 Agent 配置 | 更新资源配置 |
### 4.7 监控
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/monitoring/agents` | GET | 监控 Agent | 返回 Agent 健康状态和性能指标 |
### 4.8 计费(三维度)
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/billing/overview` | GET | 获取计费概览 | 返回渠道/租户/调用记录三维度统计 |
### 4.9 供应商申请审批
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/providers/applications` | GET | 获取供应商申请 | 返回所有供应商申请 |
| `/providers/applications/{id}/review` | PUT | 审批供应商申请 | 批准或拒绝,创建授权记录 |
| `/providers/access` | GET | 获取供应商授权 | 返回所有渠道供应商授权 |
| `/providers/access/{id}` | PUT | 更新授权 | 更新授权状态或限制 |
| `/providers/access/{id}` | DELETE | 撤销授权 | 撤销供应商授权 |
### 4.10 角色管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/roles` | GET | 获取角色列表 | 返回所有可用角色及权限 |
### 4.11 平台 Agent 模板管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/platform-agents/templates` | GET | 获取模板列表 | 从 Agent Manager 获取所有模板 |
| `/platform-agents/templates/{name}/config` | GET | 获取模板配置 | 返回管理员配置 |
| `/platform-agents/templates/{name}/config` | PUT | 配置模板 | 设置资源限制、最大 Pod 数等 |
### 4.12 平台 Agent 申请审批
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/applications/platform-agents` | GET | 获取申请列表 | 返回所有平台 Agent 申请 |
| `/applications/platform-agents/{id}/review` | PUT | 审批申请 | 批准或拒绝,创建配额记录 |
### 4.13 平台 Agent 分配管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/platform-agents/allocations` | GET | 获取分配情况 | 返回所有渠道的配额分配 |
| `/platform-agents/allocate` | POST | 直接分配配额 | 无需申请直接分配 |
| `/platform-agents/allocate` | DELETE | 撤销配额 | 撤销渠道的配额 |
| `/platform-agents/status` | GET | 获取运行状态 | 从 K8s 获取所有平台 Agent 状态 |
---
## 5. 供应商管理 (Providers)
**路由前缀**: `/api/providers`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/models` | GET | 获取模型供应商列表 | 返回所有活跃供应商(普通用户只看基本信息) |
| `/models/create` | POST | 创建模型供应商 | 创建新供应商配置,加密 API Key |
| `/models/{id}` | GET | 获取供应商详情 | 返回供应商详细配置 |
| `/models/{id}` | PUT | 更新供应商 | 更新供应商配置 |
| `/models/{id}` | DELETE | 删除供应商 | 软删除供应商 |
| `/models/{id}/test` | POST | 测试供应商连接 | 测试 API 连接是否正常 |
**权限**: `manage:providers` (super_admin, provider_admin)
---
## 6. 计费与资源管理 (Billing Admin)
**路由前缀**: `/api/billing-admin`
### 6.1 配额管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/quota/user/{user_id}` | GET | 获取用户配额 | 返回用户配额信息 |
| `/quota/channel/{channel_id}` | GET | 获取渠道配额 | 返回渠道配额信息 |
| `/quota/alerts` | GET | 获取配额预警 | 返回活跃的配额预警 |
| `/quota/alerts/{id}/acknowledge` | PUT | 确认预警 | 标记预警已确认 |
| `/quota/alerts/{id}/resolve` | PUT | 解决预警 | 标记预警已解决 |
### 6.2 资源监控
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/resources/overview` | GET | 获取资源概览 | 返回平台资源使用概览 |
| `/resources/user/{user_id}` | GET | 获取用户资源 | 返回用户资源使用汇总 |
| `/resources/trends` | GET | 获取资源趋势 | 返回资源使用趋势数据 |
| `/resources/agent/{agent_id}` | GET | 获取 Agent 资源 | 返回 Agent 资源统计 |
### 6.3 事件管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/events/pending` | GET | 获取待处理事件 | 返回待处理的计费事件 |
| `/events/retry-failed` | POST | 重试失败事件 | 重试失败的计费事件 |
| `/events/stats` | GET | 获取事件统计 | 返回事件处理统计 |
### 6.4 追踪管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/traces/execution/{execution_id}` | GET | 获取执行追踪 | 返回执行追踪详情 |
| `/traces` | GET | 查询追踪记录 | 分页查询追踪记录 |
| `/traces/stats` | GET | 获取追踪统计 | 返回追踪统计数据 |
### 6.5 审计日志
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/audit/logs` | GET | 查询审计日志 | 分页查询审计日志 |
| `/audit/summary` | GET | 获取审计汇总 | 返回审计日志汇总 |
| `/audit/user/{user_id}/activity` | GET | 获取用户活动 | 返回用户活动历史 |
### 6.6 供应商健康检查
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/providers/health` | GET | 获取供应商健康状态 | 返回所有供应商健康状态 |
| `/providers/{id}/health` | GET | 获取单个供应商健康 | 返回供应商健康详情 |
| `/providers/health-check` | POST | 执行健康检查 | 触发所有供应商健康检查 |
### 6.7 模型定价管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/pricing/models` | GET | 获取模型定价 | 返回模型定价列表 |
| `/pricing/models` | POST | 创建/更新定价 | 设置模型定价 |
| `/pricing/calculate` | POST | 计算成本 | 计算模型调用成本 |
---
## 7. Agent 管理 (Agents)
**路由前缀**: `/agents`
### 7.1 模板管理
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/templates` | GET | 获取所有模板 | 从 Agent Manager 获取所有模板 |
| `/templates/platform` | GET | 获取平台模板 | 返回平台 Agent 模板 |
| `/templates/custom` | GET | 获取自定义模板 | 返回自定义 Agent 模板 |
| `/templates/{name}` | GET | 获取模板详情 | 返回指定模板的详细信息 |
### 7.2 Agent CRUD
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/` | POST | 创建 Agent | 创建 Agent,如有模板则在 K8s 创建 Pod |
| `/` | GET | 获取 Agent 列表 | 返回分页的 Agent 列表 |
| `/{agent_id}` | GET | 获取 Agent 详情 | 返回 Agent 详细信息 |
| `/{agent_id}` | DELETE | 删除 Agent | 删除 Agent 和关联的 K8s Pod |
### 7.3 Agent 状态和监控
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/{agent_id}/status` | GET | 获取 Agent 状态 | 从 K8s 获取实时状态 |
| `/{agent_id}/metrics` | GET | 获取 Agent 资源使用 | 返回 CPU/内存使用情况 |
### 7.4 Agent 执行
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/{agent_id}/execute` | POST | 执行 Agent | 执行 MCP 请求,记录计费 |
---
## 8. 工具管理 (Tools)
**路由前缀**: `/tools`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/` | GET | 获取工具列表 | 分页返回工具列表,支持筛选 |
| `/{tool_id}` | GET | 获取工具详情 | 返回工具详细信息 |
| `/` | POST | 创建工具 | 创建新工具 |
| `/{tool_id}` | PUT | 更新工具 | 更新工具配置 |
| `/{tool_id}` | DELETE | 删除工具 | 删除工具 |
| `/categories/list` | GET | 获取工具分类 | 返回所有工具分类 |
---
## 9. 会话管理 (Sessions)
**路由前缀**: `/sessions`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/` | POST | 创建会话 | 创建新的用户会话 |
| `/` | GET | 获取会话列表 | 分页返回用户会话 |
| `/{session_id}` | GET | 获取会话详情 | 返回会话详细信息 |
| `/{session_id}/complete` | PUT | 完成会话 | 标记会话为已完成 |
| `/{session_id}` | DELETE | 删除会话 | 删除会话 |
| `/cleanup` | POST | 清理旧会话 | 清理指定天数前的已完成会话 |
---
## 10. 监控与健康检查 (Monitoring)
### 10.1 健康检查
**路由前缀**: 无
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/health` | GET | 健康检查 | 返回系统健康状态快照 |
### 10.2 监控
**路由前缀**: `/api/v1/monitoring`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/metrics` | GET | 获取系统指标 | 返回 CPU、内存等系统指标 |
| `/stats` | GET | 获取服务统计 | 返回指定子系统的统计数据 |
| `/trends` | GET | 获取性能趋势 | 返回执行或 EU 消耗趋势 |
| `/alerts` | GET | 获取系统告警 | 返回告警列表 |
| `/dashboard` | GET | 获取监控仪表板 | 聚合健康、指标、统计、告警数据 |
---
## 11. WebSocket 接口
**路由前缀**: 无
| 接口 | 协议 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/ws/{agent_name_or_id}` | WebSocket | Agent 实时交互 | 支持连接池、消息队列、心跳机制的 MCP 交互 |
**消息类型**:
- `ping/pong`: 心跳消息
- `mcp_request`: MCP 请求
- `mcp_response`: MCP 响应
- `error`: 错误消息
- `welcome`: 欢迎消息
- `heartbeat`: 服务端心跳
---
## 12. 前端集成接口 (Frontend Integration)
**路由前缀**: `/api`
> 这些接口主要用于前端开发阶段,部分使用内存存储。
### 12.1 用户仪表板
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/user/dashboard/stats` | GET | 用户仪表板统计 |
| `/user/agents/activity` | GET | Agent 活动记录 |
| `/user/resources/usage` | GET | 资源使用情况 |
### 12.2 服务网关
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/gateway/select` | POST | 选择网关类型 |
| `/gateway/api/create` | POST | 创建网关 API |
| `/gateway/apis` | GET | 获取网关 API 列表 |
| `/gateway/monitoring` | GET | 网关监控 |
### 12.3 工具与数据
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/tools/generate` | POST | 生成工具 |
| `/tools/list` | GET | 获取工具列表 |
| `/data-templates/create` | POST | 创建数据模板 |
### 12.4 Agent 工厂
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/agents/platform` | GET | 获取平台 Agent |
| `/agents/deploy` | POST | 部署 Agent |
| `/agents/deployed` | GET | 获取已部署 Agent |
### 12.5 工作流
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/workflows/create` | POST | 创建工作流 |
| `/workflows/list` | GET | 获取工作流列表 |
| `/workflows/{id}` | PUT | 更新工作流 |
| `/workflows/{id}` | DELETE | 删除工作流 |
| `/workflows/{id}/run` | POST | 运行工作流 |
### 12.6 计费
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/billing/balance` | GET | 获取余额 |
| `/billing/history` | GET | 获取计费历史 |
| `/billing/recharge` | POST | 充值 |
### 12.7 渠道合作伙伴
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/channel/auth/login` | POST | 渠道登录 |
| `/channel/dashboard/stats` | GET | 渠道仪表板统计 |
| `/channel/agents/available` | GET | 可用 Agent |
| `/channel/tenants` | GET | 租户列表 |
| `/channel/tenants/create` | POST | 创建租户 |
| `/channel/tenants/{id}/resources` | PUT | 更新租户资源 |
| `/channel/tenants/{id}/billing` | PUT | 更新租户计费 |
| `/channel/tenants/{id}` | DELETE | 删除租户 |
| `/channel/tenants/{id}/status` | PUT | 更新租户状态 |
| `/channel/tenants/{id}/permissions` | PUT | 更新租户权限 |
| `/channel/resources/agents` | GET | 获取 Agent 资源 |
| `/channel/resources/models` | GET | 获取模型资源 |
| `/channel/resources/apply` | POST | 申请资源 |
| `/channel/billing/stats` | GET | 计费统计 |
| `/channel/admins` | GET | 管理员列表 |
| `/channel/admins/create` | POST | 创建管理员 |
| `/channel/admins/{id}/permissions` | PUT | 更新管理员权限 |
### 12.8 超级管理员
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/admin/auth/login` | POST | 管理员登录 |
| `/admin/dashboard/stats` | GET | 平台统计 |
| `/admin/channels` | GET | 渠道列表 |
| `/admin/channels/create` | POST | 创建渠道 |
| `/admin/channels/{id}/commission` | PUT | 更新佣金 |
| `/admin/channels/{id}/resources` | GET | 获取渠道资源 |
| `/admin/channels/{id}/resources` | PUT | 更新渠道资源 |
| `/admin/channels/applications` | GET | 申请列表 |
| `/admin/channels/applications/{id}/approve` | PUT | 审批申请 |
| `/admin/resources/models` | GET | 模型列表 |
| `/admin/resources/models/add` | POST | 添加模型 |
| `/admin/resources/agents` | GET | Agent 列表 |
| `/admin/resources/agents/{id}` | PUT | 更新 Agent |
| `/admin/monitoring/agents` | GET | Agent 监控 |
| `/admin/billing/overview` | GET | 计费概览 |
| `/admin/roles` | GET | 角色列表 |
| `/admin/channels/{id}/admins` | GET | 渠道管理员 |
| `/admin/admins/create` | POST | 创建管理员 |
| `/admin/providers/stats` | GET | 供应商统计 |
| `/admin/channels/backend/stats` | GET | 后端统计 |
### 12.9 供应商管理
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/providers/auth/login` | POST | 供应商登录 |
| `/providers/models` | GET | 模型列表 |
| `/providers/models/add` | POST | 添加模型 |
| `/providers/data` | GET | 供应商数据 |
---
## 13. 平台 Agent 配额管理
### 13.1 渠道路由
**路由前缀**: `/api/channel`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/available-platform-agents` | GET | 获取可用平台 Agent | 返回所有可申请的模板及当前配额 |
| `/applications/platform-agents` | POST | 申请平台 Agent | 提交配额申请 |
| `/applications/platform-agents` | GET | 获取申请列表 | 返回渠道的申请记录 |
| `/platform-agents` | GET | 获取已分配配额 | 返回渠道的配额列表 |
| `/tenants/{id}/platform-agents` | POST | 分配给租户 | 分配配额并启动 Pod |
### 13.2 管理员路由
**路由前缀**: `/api/admin`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/applications/platform-agents` | GET | 获取所有申请 | 返回所有渠道的申请 |
| `/applications/platform-agents/{id}/review` | PUT | 审批申请 | 批准或拒绝,创建配额 |
| `/platform-agents/templates` | GET | 获取模板列表 | 返回模板及管理员配置 |
| `/platform-agents/templates/{name}/config` | PUT | 配置模板 | 设置资源限制等 |
| `/platform-agents/templates/{name}/config` | GET | 获取模板配置 | 返回管理员配置 |
### 13.3 用户路由
**路由前缀**: `/api/user`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/platform-agents` | GET | 获取配额列表 | 返回用户的平台 Agent 配额 |
| `/platform-agents/{template}/instances` | GET | 获取实例列表 | 返回运行中的实例 |
| `/platform-agents/{agent_name}` | DELETE | 停止 Agent | 停止实例并释放配额 |
| `/platform-agents/quota` | GET | 获取配额使用情况 | 返回配额使用详情 |
| `/platform-agents/{agent_name}/status` | GET | 获取 Agent 状态 | 从 K8s 获取实时状态 |
---
## 14. Data Ingestion 服务
**服务端口**: 8001
### 14.1 健康检查
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/health` | GET | 健康检查 |
### 14.2 RapidAPI 集成
**路由前缀**: `/rapidapi`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/sync` | POST | 同步端点 | 后台同步 RapidAPI 端点 |
| `/test` | POST | 测试端点 | 代理测试 RapidAPI 调用 |
### 14.3 OpenAPI 解析
**路由前缀**: `/openapi`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/parse` | POST | 解析 OpenAPI 规范 | 下载并解析 OpenAPI 文档,生成工具 |
### 14.4 APILLAMA 处理
**路由前缀**: `/apillama`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/process` | POST | 处理 API 文档 | 使用 APILLAMA 转换 API 文档为结构化 Schema |
### 14.5 工具管理
**路由前缀**: `/tools`
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/generate` | POST | 生成工具 | 为 API 端点生成工具定义 |
| `/` | GET | 获取工具列表 | 从 Redis 返回生成的工具 |
| `/{tool_name}` | GET | 获取工具详情 | 返回单个工具定义 |
| `/{tool_name}` | DELETE | 删除工具 | 从 Redis 删除工具 |
### 14.6 统计与缓存
| 接口 | 方法 | 功能描述 | 业务逻辑 |
|------|------|----------|----------|
| `/stats` | GET | 获取统计信息 | 返回工具和缓存统计 |
| `/cache/clear` | POST | 清理缓存 | 清理处理缓存(保留工具注册) |
### 14.7 指标
| 接口 | 方法 | 功能描述 |
|------|------|----------|
| `/metrics` | GET | Prometheus 指标 |
---
## 附录:权限系统
### 角色定义
| 角色 | 描述 | 主要权限 |
|------|------|----------|
| `super_admin` | 超级管理员 | 所有权限 |
| `billing_admin` | 计费管理员 | 完整写入权限,管理租户、计费 |
| `operations_admin` | 运维管理员 | 只读权限,查看和监控 |
| `channel_admin` | 渠道管理员 | 渠道内部管理权限 |
| `user` | 普通用户 | 标准用户权限 |
### 权限列表
- `view:overview` - 查看概览
- `view:tenants` - 查看租户
- `view:resources` - 查看资源
- `view:billing` - 查看计费
- `view:applications` - 查看申请
- `manage:tenants` - 管理租户
- `manage:resources` - 管理资源
- `manage:billing` - 管理计费
- `manage:applications` - 管理申请
- `manage:providers` - 管理供应商
- `manage:channels` - 管理渠道
- `manage:admins` - 管理管理员
---
## 附录:LiteLLM 集成
### 集成点
1. **渠道创建** - 同时创建 LiteLLM Team
2. **渠道资源分配** - 更新 LiteLLM Team 的 models 列表
3. **租户创建** - 创建 LiteLLM Key(关联到渠道 Team)
4. **租户模型分配** - 更新 LiteLLM Key 的 models 权限
5. **模型调用** - 通过 LiteLLM Gateway 代理调用
### LiteLLM 客户端接口
| 方法 | 功能 |
|------|------|
| `create_team()` | 创建 Team |
| `update_team()` | 更新 Team(models、metadata) |
| `delete_team()` | 删除 Team |
| `create_key()` | 创建 Key |
| `update_key()` | 更新 Key(models) |
| `delete_key()` | 删除 Key |
| `list_models()` | 获取可用模型列表 |
---
## 附录:Agent Manager 集成
### 集成点
1. **获取模板列表** - 平台/自定义模板
2. **创建 Agent** - 在 K8s 中创建 Pod
3. **删除 Agent** - 删除 K8s Pod
4. **获取状态** - 获取 Pod 实时状态
5. **获取资源指标** - 获取 CPU/内存使用
### Agent Manager 客户端接口
| 方法 | 功能 |
|------|------|
| `list_templates()` | 获取所有模板 |
| `list_platform_templates()` | 获取平台模板 |
| `list_custom_templates()` | 获取自定义模板 |
| `get_template()` | 获取模板详情 |
| `create_agent()` | 创建 Agent Pod |
| `delete_agent()` | 删除 Agent Pod |
| `get_agent_status()` | 获取 Agent 状态 |
| `get_agent_metrics()` | 获取资源指标 |
| `list_agents()` | 获取所有运行中的 Agent |
---
## 统计
| 模块 | 接口数量 |
|------|----------|
| 认证模块 | 6 |
| 用户侧平台 | ~50 |
| 渠道合作伙伴 | ~40 |
| 超级管理员 | ~50 |
| 供应商管理 | 6 |
| 计费与资源管理 | 20 |
| Agent 管理 | 10 |
| 工具管理 | 6 |
| 会话管理 | 6 |
| 监控与健康检查 | 6 |
| WebSocket | 1 |
| 前端集成 | ~60 |
| 平台 Agent 配额 | 15 |
| Data Ingestion | 10 |
| **总计** | **~286** |
+82 -6
View File
@@ -190,6 +190,7 @@ export class TaijiAPIClient {
static async register( static async register(
email: string, email: string,
password: string, password: string,
verificationCode: string,
username?: string, username?: string,
fullName?: string, fullName?: string,
): Promise<APIResponse<{ token: string; refreshToken?: string; user?: any }>> { ): Promise<APIResponse<{ token: string; refreshToken?: string; user?: any }>> {
@@ -203,6 +204,7 @@ export class TaijiAPIClient {
body: JSON.stringify({ body: JSON.stringify({
email, email,
password, password,
verification_code: verificationCode,
username: username || email.split("@")[0], username: username || email.split("@")[0],
full_name: fullName, full_name: fullName,
}), }),
@@ -236,6 +238,61 @@ export class TaijiAPIClient {
} }
} }
/**
* 发送邮箱验证码
*/
static async sendEmailVerificationCode(
email: string,
): Promise<APIResponse<{ message?: string }>> {
try {
const response = await fetch(`${API_BASE_URLS.mcpServer}/api/auth/send-verification-code`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email }),
signal: AbortSignal.timeout(10000), // 10 second timeout
})
return await handleResponse<APIResponse<{ message?: string }>>(response)
} catch (error: any) {
if (error.name === "AbortError" || error.message?.includes("timeout")) {
throw new Error("请求超时,请检查网络连接或后端服务状态")
}
if (error.message?.includes("Failed to fetch") || error.name === "TypeError") {
throw new Error(
`无法连接到后端服务 (${API_BASE_URLS.mcpServer})。请确保 MCP Server 正在运行。`,
)
}
throw error
}
}
/**
* 验证邮箱验证码
*/
static async verifyEmailCode(
email: string,
code: string,
): Promise<APIResponse<{ verified: boolean }>> {
try {
const response = await fetch(`${API_BASE_URLS.mcpServer}/api/auth/verify-email-code`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, code }),
signal: AbortSignal.timeout(10000), // 10 second timeout
})
return await handleResponse<APIResponse<{ verified: boolean }>>(response)
} catch (error: any) {
if (error.name === "AbortError" || error.message?.includes("timeout")) {
throw new Error("请求超时,请检查网络连接或后端服务状态")
}
if (error.message?.includes("Failed to fetch") || error.name === "TypeError") {
throw new Error(
`无法连接到后端服务 (${API_BASE_URLS.mcpServer})。请确保 MCP Server 正在运行。`,
)
}
throw error
}
}
/** /**
* 用户登录 * 用户登录
*/ */
@@ -1652,12 +1709,17 @@ export class TaijiAPIClient {
* *
* @param tenantId - 租户ID * @param tenantId - 租户ID
* @param newPassword - 新密码 * @param newPassword - 新密码
* @param channelId - 渠道ID(超级管理员必须提供)
*/ */
static async changeTenantPassword(tenantId: string, newPassword: string) { static async changeTenantPassword(tenantId: string, newPassword: string, channelId?: string) {
const body: any = { newPassword }
if (channelId) {
body.channel_id = channelId
}
const response = await fetch(`${API_BASE_URLS.mcpServer}/api/channel/tenants/${tenantId}/password`, { const response = await fetch(`${API_BASE_URLS.mcpServer}/api/channel/tenants/${tenantId}/password`, {
method: "PUT", method: "PUT",
headers: buildHeaders(), headers: buildHeaders(),
body: JSON.stringify({ newPassword }), body: JSON.stringify(body),
}) })
return handleResponse(response) return handleResponse(response)
} }
@@ -2386,10 +2448,24 @@ export class TaijiAPIClient {
* 获取监控仪表盘聚合 * 获取监控仪表盘聚合
*/ */
static async getMonitoringDashboard() { static async getMonitoringDashboard() {
const response = await fetch(`${API_BASE_URLS.mcpServer}/api/v1/monitoring/dashboard`, { try {
headers: buildHeaders(), const response = await fetch(`${API_BASE_URLS.mcpServer}/api/v1/monitoring/dashboard`, {
}) headers: buildHeaders(),
return handleResponse(response) signal: AbortSignal.timeout(10000), // 10 second timeout
})
return await handleResponse(response)
} catch (error: any) {
// 处理网络错误
if (error.name === "AbortError" || error.message?.includes("timeout")) {
throw new Error("请求超时,请检查网络连接或后端服务状态")
}
if (error.message?.includes("Failed to fetch") || error.name === "TypeError") {
throw new Error(
`无法连接到后端服务 (${API_BASE_URLS.mcpServer})。请确保 MCP Server 正在运行。`,
)
}
throw error
}
} }
// ==================== 用户计费模块 API ==================== // ==================== 用户计费模块 API ====================