模块 2 · 对话与鉴权

ChatPanel / useChatPanel:
三条 API 线的头不一样

对话 UI 统一用 ChatPanel + useChatPanel,但后端入口分三条: /api/chat(四 Agent)、/api/analyst/*(问数平台)、风控台账 REST。 指挥 AI 接新页面时,先对表再写 headers。

鉴权差异对照

前端模块APIAuthorizationX-Agent-Type
api/chat.ts/api/chat, /stream, sessionsBearer必须(与 prop agentType 一致)
api/analyst.ts/api/analyst/chat 等Bearer(apiFetch)不要
api/risk.ts/api/risk/*Bearer必须 risk
持仓/产品页/api/customers/* 等Bearer不要
真实 bug: risk.ts 曾漏 X-Agent-Type: risk,JWT 正确也 401。接新风控页先 grep 这个头。

数据流:理财师打开顾问助手

💬ChatPanel
🪝useChatPanel
📡api/chat.ts
🚪对话 HTTP 入口(chat.py)

对比:问数走 analyst.ts,无 X-Agent-Type

chat.ts vs analyst.ts
// chat.ts — 对话线
function chatHeaders(token, agentType) {
  return {
    Authorization: `Bearer ${token}`,
    'X-Agent-Type': agentType,
  }
}

// analyst.ts — 问数平台线
apiFetch('/api/analyst/chat', { method: 'POST', token, body })
// apiFetch 只加 Authorization,不加 X-Agent-Type
白话

Chat 相关请求:token 证明身份,agentType 证明走哪条 Agent 线。

useChatPanel 把 agentType 从页面 prop 一路传到每次 list/send/close。

问数用 apiFetch 通用封装,后端走 get_platform_auth_context,不需要 Agent 头。

customer 线 mode 常用 sync(后端 LangGraph 整图跑完再推);advisor/risk 用 stream SSE。

RiskChatPage 发消息,请求头应长什么样?