mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 10:29:19 +08:00
feat: 公司支持多模型提供商与会话消歧选型
This commit is contained in:
+29
-25
@@ -30,12 +30,13 @@
|
||||
```text
|
||||
[ web-antd ]
|
||||
│ JWT
|
||||
├─► 模型管理页 → 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)
|
||||
├─► 模型管理页 → Server /api/company/agent-llm-providers* (多提供商 CRUD)
|
||||
├─► 聊天页 → Server GET /api/company/agent-llm-models (启用列表,含 providerId)
|
||||
└─► 聊天页 → Agent /api/agent/sessions|chat|memories (Mongo;会话含 llm_provider_id + llm_model)
|
||||
│
|
||||
├─ Redis agent:llm:rt:{companyId}:{model} 或 Server /api/internal/agent/llm-runtime?model=
|
||||
├─ ChatOpenAI(base_url, api_key, model) 按会话模型注入
|
||||
├─ Redis agent:llm:rt:{companyId}:{providerId}:{model}
|
||||
├─ Server /api/internal/agent/llm-runtime?companyId=&providerId=&model=
|
||||
├─ ChatOpenAI(base_url, api_key, model) 按会话选型注入
|
||||
└─ MCP /mcp + X-Agent-Company-Id / X-Agent-User-Id → BI tools
|
||||
```
|
||||
|
||||
@@ -69,11 +70,12 @@
|
||||
|
||||
约束:
|
||||
|
||||
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 时)。
|
||||
1. **真相源**:MySQL `agent_company_llm_provider`(多行/公司)+ `agent_company_llm_model`(挂 `provider_id`);`api_key` **AES-GCM 加密**。
|
||||
2. **缓存**:Redis `agent:llm:rt:{company_id}:{provider_id}:{model}`;配置变更按公司前缀 DEL;**Agent 与 Server 须同 Redis DB**。
|
||||
3. **注入**:Agent 按会话 **`llm_provider_id` + `llm_model`** 解析;跨提供商允许同名 model。
|
||||
4. **权限**:写配置靠 `agent:llm-settings`;聊天选模靠 `agent:chat`。
|
||||
5. **缺省**:未配置时聊天返回明确错误;`LLM_FALLBACK_*` 仅本地开发(且未指定选型时)。
|
||||
6. **启用列表写入**:按 `(provider_id, model)` **增量 upsert**(更新已有、插入新增、删除取消勾选),禁止整表删建,以免破坏会话引用。
|
||||
|
||||
---
|
||||
|
||||
@@ -121,7 +123,8 @@ apps/agent/
|
||||
| `title` | 可空,首轮后可自动生成 |
|
||||
| `status` | `active` / `archived` / `deleted` |
|
||||
| `summary` | 会话滚动摘要(可选) |
|
||||
| `llm_model` | 会话选用的模型 id(公司启用列表内);空则对话时回落默认并回写 |
|
||||
| `llm_provider_id` | 会话选用的提供商 id |
|
||||
| `llm_model` | 会话选用的模型 id;与 provider 一起消歧;空则对话时回落公司默认并回写 |
|
||||
| `created_at`, `updated_at`, `last_message_at` | |
|
||||
|
||||
唯一索引:`(company_id, user_id, thread_id)`
|
||||
@@ -177,18 +180,19 @@ apps/agent/
|
||||
|
||||
### 4.2.1 公司模型配置(MySQL,不在 Mongo)
|
||||
|
||||
见 `apps/server/sql/design/agent/agent_company_llm_provider_models_design.sql` 与迁移 `V20260920b__agent_llm_provider_models.sql`(旧单表迁入后改名为 `_deprecated`)。
|
||||
见 `apps/server/sql/design/agent/agent_company_llm_provider_models_design.sql` 与迁移 `V20260920b` / `V20260920d`(多提供商)。
|
||||
|
||||
| 表 | 说明 |
|
||||
|----|------|
|
||||
| `agent_company_llm_provider` | 公司一套 `base_url` + 加密 Key(UNIQUE company) |
|
||||
| `agent_company_llm_model` | 已启用模型多行;`is_default=1` 供 Agent 注入 |
|
||||
| `agent_company_llm_provider` | 公司多套 `base_url` + 加密 Key |
|
||||
| `agent_company_llm_model` | 挂 `provider_id`;`UNIQUE(provider_id, model)`;公司级全局一条 `is_default=1` |
|
||||
|
||||
浏览器:
|
||||
- `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)
|
||||
- `GET/POST /api/company/agent-llm-providers`;`GET/PUT/DELETE .../providers/{id}`;`PUT .../providers/{id}/models`(增量 upsert)
|
||||
- `POST /api/company/agent-llm-settings/probe-models`(可带 `providerId` + `useStoredKey`)
|
||||
- `GET /api/company/agent-llm-models`:`{ items: [{ providerId, providerDisplayName, model, label, contextWindow, isDefault }] }`
|
||||
|
||||
Agent 内部:`GET /api/internal/agent/llm-runtime?companyId=&model=` —— `model` 空取默认;有值须在启用列表中,否则 400;返回明文凭证 + `contextWindow`。
|
||||
Agent 内部:`GET /api/internal/agent/llm-runtime?companyId=&providerId=&model=`。
|
||||
|
||||
### 4.3 与 LangGraph 的关系
|
||||
|
||||
@@ -218,17 +222,17 @@ Agent 内部:`GET /api/internal/agent/llm-runtime?companyId=&model=` —— `m
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| GET | `/sessions` | 当前用户会话列表(含 `llmModel`) |
|
||||
| POST | `/sessions` | 新建会话(可带 `llmModel`;缺省写公司默认) |
|
||||
| PATCH | `/sessions/{thread_id}` | 改标题 / `llmModel` |
|
||||
| GET | `/sessions` | 当前用户会话列表(含 `llmProviderId` / `llmModel`) |
|
||||
| POST | `/sessions` | 新建会话(可带选型;缺省写公司默认) |
|
||||
| PATCH | `/sessions/{thread_id}` | 改标题;或同时改 `llmProviderId`+`llmModel` |
|
||||
| GET | `/sessions/{thread_id}/messages` | 历史消息(分页/游标) |
|
||||
| POST | `/sessions/{thread_id}/chat` | **流式**发消息(SSE);按会话 `llm_model` 解析 runtime |
|
||||
| POST | `/sessions/{thread_id}/chat` | **流式**发消息(SSE);按会话选型解析 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`;聊天只读 `GET /api/company/agent-llm-models`。
|
||||
公司 LLM 配置在 **Server**:按提供商 CRUD + `PUT .../models` 增量 upsert;聊天只读 `GET /api/company/agent-llm-models`。
|
||||
|
||||
鉴权:`Authorization: Bearer <用户 JWT>`;Agent 用与 server 共享的 `JWT_SECRET` 校验 HS512。JWT:`sub` = userId,claim `companyId` 等与 Java `JwtUtils` 一致。
|
||||
|
||||
@@ -250,9 +254,9 @@ SSE 事件:`token`(正文,可落库)/ `tool`(`{phase,name,label}` 状
|
||||
### 7.1 页面
|
||||
|
||||
- 聊天:`/agent/chat`,菜单「智能助手」(仅 `agent:chat`)
|
||||
- 模型管理:`/agent/llm-settings`,一级菜单「模型管理」(仅 `agent:llm-settings`)
|
||||
- 模型管理:`/agent/llm-settings`,一级菜单「模型管理」(仅 `agent:llm-settings`);多提供商卡片
|
||||
- 我的记忆:`/agent/memories`,头像下拉入口(有 `agent:chat` 时显示;静态路由)
|
||||
- 聊天顶栏:`Select` 切换当前会话模型(PATCH `llmModel`);新对话草稿本地暂存,创建时带上
|
||||
- 聊天顶栏:按提供商分组 `Select`;切换即 PATCH `llmProviderId`+`llmModel`
|
||||
- 布局:**左会话列表 + 右消息区 + 底输入**;全页 `flex` + `min-h-0` 滚动(遵守现有 Spin/滚动规范)
|
||||
|
||||
### 7.2 组件(自建,不引入 AI UI 库)
|
||||
@@ -262,7 +266,7 @@ views/agent/chat/
|
||||
index.vue # 聊天:会话列表 + 消息 + 顶栏选模型
|
||||
catalog-cite*.vue/ts # 店铺/商品引用输入
|
||||
views/agent/llm-settings/
|
||||
index.vue # 模型管理:凭证 / 启用列表
|
||||
index.vue # 模型管理:多提供商 CRUD + 启用列表增量保存
|
||||
views/agent/memories/
|
||||
index.vue # 我的记忆:列表 / 删除(用户中心入口)
|
||||
api/agent/ # 调 Agent + Server 公司 LLM API
|
||||
|
||||
Reference in New Issue
Block a user