mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 18:29:19 +08:00
feat: 模型管理独立页与会话级选模型
This commit is contained in:
+33
-31
@@ -20,20 +20,22 @@
|
||||
|
||||
| 层 | 职责 | 不做什么 |
|
||||
|----|------|----------|
|
||||
| `apps/web` 聊天页 | UI、会话列表、流式展示;公司 LLM 配置表单(调 Server) | 不编排 LLM、不调 MCP、不持有明文长期 Key(仅提交时传一次) |
|
||||
| `apps/agent` | 会话/记忆/编排/流式 API、调 MCP、注入租户 LLM 凭证 | 不持久业务单据、不实现业务规则、**不存模型 Key** |
|
||||
| `apps/web` 聊天页 | UI、会话列表、流式展示、**会话级选模型** | 不编排 LLM、不调 MCP、不持有明文 Key |
|
||||
| `apps/web` 模型管理页 | 凭证 CRUD、启用模型列表、记忆管理(`agent:llm-settings`) | 不发聊天 |
|
||||
| `apps/agent` | 会话/记忆/编排/流式 API、调 MCP、按会话模型注入凭证 | 不持久业务单据、不实现业务规则、**不存模型 Key** |
|
||||
| `apps/server` | MySQL 存公司模型配置;MCP `@McpTool`;内部 llm-runtime | 不存聊天记录(对话在 Agent Mongo) |
|
||||
|
||||
### 1.3 数据流
|
||||
|
||||
```text
|
||||
[ web-antd 聊天页 ]
|
||||
[ web-antd ]
|
||||
│ JWT
|
||||
├─► Server GET/PUT /api/company/agent-llm-settings (MySQL 加密 Key)
|
||||
└─► Agent /api/agent/sessions|chat|memories (Mongo 会话/记忆)
|
||||
├─► 模型管理页 → Server GET/PUT /api/company/agent-llm-settings (MySQL 加密 Key)
|
||||
├─► 聊天页 → Server GET /api/company/agent-llm-models (启用列表,无 Key)
|
||||
└─► 聊天页 → Agent /api/agent/sessions|chat|memories (Mongo;会话含 llm_model)
|
||||
│
|
||||
├─ Redis agent:llm:rt:{companyId} 或 Server /api/internal/agent/llm-runtime
|
||||
├─ ChatOpenAI(base_url, api_key, model) 按租户注入
|
||||
├─ Redis agent:llm:rt:{companyId}:{model} 或 Server /api/internal/agent/llm-runtime?model=
|
||||
├─ ChatOpenAI(base_url, api_key, model) 按会话模型注入
|
||||
└─ MCP /mcp + X-Agent-Company-Id / X-Agent-User-Id → BI tools
|
||||
```
|
||||
|
||||
@@ -67,11 +69,11 @@
|
||||
|
||||
约束:
|
||||
|
||||
1. **真相源**:MySQL `agent_company_llm_settings`(见 `apps/server/sql/design/agent/`);`api_key` **AES-GCM 加密**(`ecom.agent.llm.secret` 或派生自 `jwt.secret`)。
|
||||
2. **缓存**:Redis `agent:llm:rt:{company_id}` → `{base_url, api_key, model, …}`,TTL;配置变更时 DEL;**Agent 与 Server 须同 Redis DB**。
|
||||
3. **注入**:Agent 只读 Redis / 内部接口明文;**禁止**下发完整 Key 给前端(读接口只返回 `apiKeyMasked`)。
|
||||
4. **权限**:更新需公司 owner(或超管);权限码 `agent:llm-settings`。
|
||||
5. **缺省**:未配置时聊天返回明确错误;`LLM_FALLBACK_*` 仅本地开发。
|
||||
1. **真相源**:MySQL `agent_company_llm_provider` + `agent_company_llm_model`;`api_key` **AES-GCM 加密**(`ecom.agent.llm.secret` 或派生自 `jwt.secret`)。
|
||||
2. **缓存**:Redis `agent:llm:rt:{company_id}:{model}` → `{base_url, api_key, model, context_window, …}`,TTL;配置变更时按公司前缀 DEL;**Agent 与 Server 须同 Redis DB**。
|
||||
3. **注入**:Agent 按**会话 `llm_model`** 读 Redis / 内部接口明文;**禁止**下发完整 Key 给前端(读接口只返回 `apiKeyMasked`;聊天仅 `GET /agent-llm-models`)。
|
||||
4. **权限**:写配置靠 `agent:llm-settings`(不限 owner);聊天选模靠 `agent:chat`。
|
||||
5. **缺省**:未配置时聊天返回明确错误;`LLM_FALLBACK_*` 仅本地开发(且仅在无指定 model 时)。
|
||||
|
||||
---
|
||||
|
||||
@@ -119,6 +121,7 @@ apps/agent/
|
||||
| `title` | 可空,首轮后可自动生成 |
|
||||
| `status` | `active` / `archived` / `deleted` |
|
||||
| `summary` | 会话滚动摘要(可选) |
|
||||
| `llm_model` | 会话选用的模型 id(公司启用列表内);空则对话时回落默认并回写 |
|
||||
| `created_at`, `updated_at`, `last_message_at` | |
|
||||
|
||||
唯一索引:`(company_id, user_id, thread_id)`
|
||||
@@ -181,7 +184,11 @@ apps/agent/
|
||||
| `agent_company_llm_provider` | 公司一套 `base_url` + 加密 Key(UNIQUE company) |
|
||||
| `agent_company_llm_model` | 已启用模型多行;`is_default=1` 供 Agent 注入 |
|
||||
|
||||
浏览器:`GET/PUT /api/company/agent-llm-settings`;`POST .../probe-models` 代理 `{baseUrl}/v1/models`(不落库)。Agent 内部:`/api/internal/agent/llm-runtime` 返回**默认模型**明文(含 `contextWindow`)。
|
||||
浏览器:
|
||||
- `GET/PUT /api/company/agent-llm-settings` + `POST .../probe-models`(需 `agent:llm-settings`)
|
||||
- `GET /api/company/agent-llm-models`:启用列表 `{ items: [{ model, label, contextWindow, isDefault }] }`(需 `agent:chat`,无 Key)
|
||||
|
||||
Agent 内部:`GET /api/internal/agent/llm-runtime?companyId=&model=` —— `model` 空取默认;有值须在启用列表中,否则 400;返回明文凭证 + `contextWindow`。
|
||||
|
||||
### 4.3 与 LangGraph 的关系
|
||||
|
||||
@@ -211,17 +218,17 @@ apps/agent/
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/sessions` | 当前用户会话列表 |
|
||||
| POST | `/sessions` | 新建会话 |
|
||||
| PATCH | `/sessions/{thread_id}` | 改标题/归档 |
|
||||
| GET | `/sessions` | 当前用户会话列表(含 `llmModel`) |
|
||||
| POST | `/sessions` | 新建会话(可带 `llmModel`;缺省写公司默认) |
|
||||
| PATCH | `/sessions/{thread_id}` | 改标题 / `llmModel` |
|
||||
| GET | `/sessions/{thread_id}/messages` | 历史消息(分页/游标) |
|
||||
| POST | `/sessions/{thread_id}/chat` | **流式**发消息(SSE) |
|
||||
| POST | `/sessions/{thread_id}/chat` | **流式**发消息(SSE);按会话 `llm_model` 解析 runtime |
|
||||
| GET | `/memories` | 查看自己的记忆条目(可透明) |
|
||||
| DELETE | `/memories/{id}` | 用户删除某条记忆 |
|
||||
|
||||
SSE 事件:`token`(正文,可落库)/ `tool`(`{phase,name,label}` 状态条,不进正文)/ `done` / `error`。工具名经 `agent/tools/labels.py` 映射为中文 label。
|
||||
|
||||
公司 LLM 配置在 **Server**:`GET/PUT /api/company/agent-llm-settings`(凭证 + 启用模型列表);`POST .../probe-models` 拉提供商模型目录(不经 Agent)。
|
||||
公司 LLM 配置在 **Server**:`GET/PUT /api/company/agent-llm-settings`(凭证 + 启用模型);`POST .../probe-models`;聊天只读 `GET /api/company/agent-llm-models`。
|
||||
|
||||
鉴权:`Authorization: Bearer <用户 JWT>`;Agent 用与 server 共享的 `JWT_SECRET` 校验 HS512。JWT:`sub` = userId,claim `companyId` 等与 Java `JwtUtils` 一致。
|
||||
|
||||
@@ -242,25 +249,20 @@ SSE 事件:`token`(正文,可落库)/ `tool`(`{phase,name,label}` 状
|
||||
|
||||
### 7.1 页面
|
||||
|
||||
- 路由示例:`/agent/chat`
|
||||
- 菜单:一级「智能助手」
|
||||
- 另:公司配置入口「模型 API」(或聊天页设置抽屉)维护 OpenAI Compatible 凭证
|
||||
- 聊天:`/agent/chat`,菜单「智能助手」(仅 `agent:chat`)
|
||||
- 模型管理:`/agent/llm-settings`,一级菜单「模型管理」(仅 `agent:llm-settings`)
|
||||
- 聊天顶栏:`Select` 切换当前会话模型(PATCH `llmModel`);新对话草稿本地暂存,创建时带上
|
||||
- 布局:**左会话列表 + 右消息区 + 底输入**;全页 `flex` + `min-h-0` 滚动(遵守现有 Spin/滚动规范)
|
||||
|
||||
### 7.2 组件(自建,不引入 AI UI 库)
|
||||
|
||||
```text
|
||||
views/agent/chat/
|
||||
index.vue # 页壳
|
||||
components/
|
||||
SessionSidebar.vue
|
||||
MessageList.vue
|
||||
MessageBubble.vue
|
||||
ChatComposer.vue
|
||||
ToolCallBlock.vue # 可选:折叠展示 tool 结果
|
||||
composables/
|
||||
useAgentChat.ts # 流式消费、本地消息缓冲
|
||||
api/agent/ # 调 Agent 服务,非调 Java /api
|
||||
index.vue # 聊天:会话列表 + 消息 + 顶栏选模型
|
||||
catalog-cite*.vue/ts # 店铺/商品引用输入
|
||||
views/agent/llm-settings/
|
||||
index.vue # 模型管理:凭证 / 启用列表 / 记忆
|
||||
api/agent/ # 调 Agent + Server 公司 LLM API
|
||||
```
|
||||
|
||||
### 7.3 配置
|
||||
|
||||
Reference in New Issue
Block a user