Files
taiji-AI-PAD/services/mcp-server/app/routes/__init__.py
T
chenchenandClaude Opus 4.7 610fde5d03 feat(mcp-server): Heicode integration + register transaction hardening
== Heicode integration (~41 endpoints across 5 modules) ==
- §2 ResourceBinding (5 endpoints) — resources.py / resource_grants.py
- §4 NewAPI metadata proxy (4 endpoints) — heicode_proxy.py + heicode_client.py
- §5 Agnet platform stub (12 endpoints, in-memory mock) — agnet_stub.py
- §6 Task orchestration (5 endpoints + 3 extension endpoints) — heicode_tasks.py
  6.1-6.5: intent / list / get / answer / messages
  6.6-6.8: execution / delivery / audit?tab=... (Slice 8/9/10)
- §7 SSE single channel + approvals (4 endpoints + 5 event types) —
  heicode_events.py + event_bus.py
- §7.8.1 internal billing-provider PUT endpoint — auth.py (routes)

== Schema changes ==
- migrations/026 heicode_tasks (orchestration state)
- migrations/027 users.billing_provider (litellm | newapi switch)
- migrations/028 heicode_approvals (high-risk approval queue)

== Register transaction hardening (P0 + P1 + P2) ==
routes/auth.py register():
- Pre-existing P0: failed register returned IntegrityError str verbatim
  (leaking SQL params + ~50 plaintext LiteLLM keys per attempt).
  Now logs exc_info, returns {code: REGISTER_FAILED, message: ...}.
- Pre-existing P0: model dedupe — two ModelProvider rows with overlapping
  supported_models (e.g. taiji/gpt-4o-mini in both taiji and azure providers)
  collide on uq_tenant_model. seen_models set deduplicates within the loop.
- New P1: track created_litellm_keys; on any failure call delete_key() for
  each — prevents remote orphan keys when DB rollback fires.
- New P1: replace verify_code with peek_verification_code at the start;
  only call verify_code (which consumes) after commit succeeds. Failed
  registrations no longer burn the user's one-shot code.
- New P2: narrow inner `except (LiteLLMClientError, Exception)` to just
  LiteLLMClientError so SQLAlchemy errors bubble to the outer rollback
  instead of being silently swallowed into a half-allocated 200 response.
- New P2: same narrowing on outer `except (AgentManagerError, Exception)`.

== Auth middleware ==
- app/auth.py: allow /api/auth/internal/billing-provider and
  /api/auth/internal/approvals to bypass user JWT (service-token auth
  via HEICODE_INTERNAL_SERVICE_TOKEN, validated in-route).

== Docs ==
- Heicode-接口契约文档.md v2.2 (41 endpoints + SSE schema + 6.6-6.8)
- Heicode-对接进度与待办.md (through §7.14 SSE + 7.8.2 delivery回执)
- Heicode-完整调用流程图.md (sequence + routing diagrams)
- Agent-Manager-Heicode对接需求文档.md
- HEICODE_API_INTEGRATION.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 15:43:10 +08:00

70 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Attach all FastAPI routers for the MCP server."""
from fastapi import FastAPI
from . import (
agents, frontend_integration, health, metrics, monitoring, tools, websocket,
auth, user, channel, admin, providers, billing_admin, sessions,
quota_management, pricing_management, # 阶段一:配额管理和定价管理
resource_monitoring, event_management, # 阶段二:资源监控和事件管理
trace_management, audit_management, # 阶段三:追踪和审计管理
provider_health_management, # 阶段四:供应商健康检查管理
platform_agent_quota, # 平台 Agent 配额管理
billing_webhook, # LiteLLM Token计费webhook
external_tools, # 外部数据工具管理
paypal, # PayPal 支付集成
resources, resource_grants, # Heicode P1:资源绑定与授权
heicode_proxy, # Heicode P4:NewAPI 用户视角元数据透传
agnet_stub, # Heicode P5:Agnet 平台本地 stub(12 个 /api/agnet/* 端点)
heicode_tasks, # Heicode 任务编排(5 个 /api/user/tasks/* 端点)
heicode_events, # Heicode §7.8.3:SSE 单通道 + Approval REST
)
def register_routes(app: FastAPI) -> None:
for router in (
health.router,
auth.router,
user.router,
channel.router,
admin.router,
providers.router,
billing_admin.router, # 计费与资源管理路由
billing_webhook.router, # LiteLLM Token计费webhook
quota_management.router, # 配额管理路由
pricing_management.router, # 定价管理路由
resource_monitoring.router, # 资源监控路由
event_management.router, # 事件管理路由
trace_management.router, # 追踪管理路由
audit_management.router, # 审计管理路由
provider_health_management.router, # 供应商健康检查管理路由
frontend_integration.router,
agents.router,
sessions.router, # 会话管理路由
tools.router,
external_tools.router, # 外部数据工具管理路由
external_tools.toolkit_router, # 外部数据工具集管理路由
monitoring.router,
metrics.router,
websocket.router,
# 平台 Agent 配额管理路由
platform_agent_quota.channel_router, # 渠道平台 Agent 配额管理
platform_agent_quota.admin_router, # 管理员平台 Agent 配额管理
platform_agent_quota.user_router, # 用户平台 Agent 配额管理
# PayPal 支付路由
paypal.router, # PayPal 用户支付路由(需要认证)
paypal.webhook_router, # PayPal Webhook 回调路由(无需认证,在 whitelist 路径下)
# Heicode P1: 资源绑定与授权
resources.router,
resource_grants.router,
# Heicode P4: NewAPI 元数据透传
heicode_proxy.router,
# Heicode P5: Agnet 平台本地 stub
agnet_stub.router,
# Heicode 任务编排
heicode_tasks.router,
# Heicode §7.8.3 SSE + Approval
heicode_events.router,
):
app.include_router(router)