Skip to content

Commit aa938a2

Browse files
authored
feat(web-ui): align platform resources with backend contracts (#22)
1 parent 15586e2 commit aa938a2

9 files changed

Lines changed: 5521 additions & 240 deletions
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Manager Provider Template API Proposal
2+
3+
## 背景
4+
5+
当前前端 `Provider Catalog` 已升级为可视化模板编辑器(字段卡片),不再依赖手写 JSON。
6+
为了让后端可落地实现,需要把前端行为拆成稳定的接口和数据结构。
7+
8+
本提案目标:
9+
10+
- 支持 `category + provider` 维度的模板管理
11+
- 支持模板字段类型化约束(text/number/integer/select)
12+
- 模板字段支持多级路径(dot path,例如 `audio.codec.sample_rate_hz`
13+
- `base_url``access_key` 作为资源顶层必填字段,不放入模板
14+
- 支持资源创建时按模板渲染表单并校验
15+
16+
## UI 侧核心实体
17+
18+
### ProviderTemplate
19+
20+
- `id`: string(uuid)
21+
- `category`: `llm | asr | tts`
22+
- `provider`: string(建议小写,`^[a-z][a-z0-9-]*$`
23+
- `status`: `active | inactive`
24+
- `version`: number(模板版本,>=1)
25+
- `fields`: `ProviderTemplateField[]`
26+
- `created_at` / `updated_at`
27+
28+
### ProviderTemplateField
29+
30+
- `key`: string(建议 `^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$`
31+
- `label`: string
32+
- `type`: `text | number | integer | select`
33+
- `required`: boolean
34+
- `default_value`: string | number | null
35+
- `helper_text`: string
36+
- `placeholder`: string
37+
- `min`: number
38+
- `max`: number
39+
- `step`: number
40+
- `options`: `[{ value: string, label: string }]`(仅 `select`
41+
42+
保留关键字(不允许作为模板字段):
43+
44+
- `base_url`
45+
- `access_key`
46+
47+
## 推荐后端接口(MVP)
48+
49+
统一响应结构继续沿用:
50+
51+
```json
52+
{
53+
"code": "OK",
54+
"message": "",
55+
"data": {}
56+
}
57+
```
58+
59+
### 1) 查询模板(登录可读)
60+
61+
- `GET /api/v1/provider-templates`
62+
- Query:
63+
- `category` 可选
64+
- `provider` 可选
65+
- `status` 可选
66+
67+
返回:
68+
69+
```json
70+
{
71+
"items": [
72+
{
73+
"id": "uuid",
74+
"category": "llm",
75+
"provider": "zhipu",
76+
"status": "active",
77+
"version": 3,
78+
"fields": [
79+
{
80+
"key": "model",
81+
"label": "Model",
82+
"type": "text",
83+
"required": true,
84+
"default_value": "glm-4-flash"
85+
}
86+
],
87+
"created_at": "2026-02-16T10:00:00Z",
88+
"updated_at": "2026-02-16T10:00:00Z"
89+
}
90+
]
91+
}
92+
```
93+
94+
### 2) 创建模板(admin)
95+
96+
- `POST /api/v1/admin/provider-templates`
97+
98+
请求体:
99+
100+
```json
101+
{
102+
"category": "llm",
103+
"provider": "zhipu",
104+
"status": "active",
105+
"fields": [
106+
{
107+
"key": "model",
108+
"label": "Model",
109+
"type": "text",
110+
"required": true,
111+
"default_value": "glm-4-flash"
112+
}
113+
]
114+
}
115+
```
116+
117+
### 3) 更新模板(admin)
118+
119+
- `PATCH /api/v1/admin/provider-templates/:id`
120+
121+
可更新字段:
122+
123+
- `status`
124+
- `fields`(建议全量替换)
125+
126+
语义建议:每次成功更新自动 `version + 1`
127+
128+
### 4) 删除模板(admin)
129+
130+
- `DELETE /api/v1/admin/provider-templates/:id`
131+
132+
建议默认软删除(`status=inactive``deleted_at`),避免影响历史资源。
133+
134+
## 资源接口联动建议
135+
136+
现有 `platform_resources` 接口保留不变,但建议新增字段:
137+
138+
- `provider_template_id`(可选)
139+
- `provider_template_version`(可选)
140+
141+
创建/更新资源时建议请求体包含:
142+
143+
- `base_url`(required)
144+
- `access_key`(create required,edit optional)
145+
146+
并由后端做两步校验:
147+
148+
1. `category + provider` 存在可用模板
149+
2. `config` 满足模板字段规则
150+
151+
这样前端和后端校验逻辑可对齐,减少“前端通过、后端失败”的情况。
152+
153+
## 建议表结构(MVP)
154+
155+
### `provider_templates`
156+
157+
- `id` uuid pk
158+
- `category` text not null
159+
- `provider` text not null
160+
- `status` text not null default `active`
161+
- `version` int not null default 1
162+
- `fields` jsonb not null
163+
- `created_by` uuid not null
164+
- `created_at` timestamptz not null
165+
- `updated_at` timestamptz not null
166+
167+
唯一约束建议:
168+
169+
- 若只允许单活模板:`unique(category, provider)`
170+
- 若允许多版本并存:`unique(category, provider, version)` + status 控制活跃版本
171+
172+
## 错误码建议
173+
174+
- `400 ERR_INVALID_ARGUMENT`:字段结构、类型、范围不合法
175+
- `401 ERR_UNAUTHORIZED`
176+
- `403 ERR_FORBIDDEN`
177+
- `404 ERR_NOT_FOUND`
178+
- `409 ERR_CONFLICT`:同 category/provider 重复冲突
179+
- `422 ERR_TEMPLATE_VALIDATION`:资源 config 不满足模板

docs/voicebot-todo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
- [x] users/auth 模块(注册 + JWT 登录/刷新 + RBAC)
183183
- [x] web-ui 管理后台骨架(登录态、鉴权拦截、RBAC 菜单)
184184
- [x] platform_resources 模块(LLM/ASR/TTS 资源管理)
185+
- [x] web-ui platform_resources 管理页(列表筛选、创建/编辑/禁用、实时刷新、provider 模板化配置表单、provider catalog 面板与模板增删改(后端 API)、`base_url/access_key` 独立必填字段、access key 二次认证明文查看)
185186
- [x] provider_templates 模块(模板字段定义 + CRUD)
186187
- [x] platform_resources 安全改造(移除 credential_ref、access_key 加密存储、reveal 二次认证)
187188
- [ ] tool_market 模块(市场、offer、entitlement、tool repo)

web-ui/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ Manager admin console skeleton built with React + MUI.
99
- Token lifecycle handling (restore from local storage, auto refresh, manual refresh)
1010
- Protected routes and unified auth failure redirect
1111
- Role-based navigation (`admin` vs `normal_user`)
12-
- Basic layout for manager pages (`platform resources`, `tool market`, `voicebots/devices`)
12+
- Platform resources page (`/platform-resources`) with filters + create/edit/disable flow
13+
- Provider-driven resource form templates (fields vary by `category` + `provider`)
14+
- Dedicated required resource fields for `base_url` + `access_key` (not in provider template)
15+
- Provider catalog panel with visual field-schema editor (supports nested path fields, add/edit/delete templates via backend APIs)
16+
- Access key re-auth reveal flow (`POST /api/v1/admin/platform-resources/:id/access-key/reveal`)
17+
- Basic layout for remaining manager pages (`tool market`, `voicebots/devices`)
1318
- Legacy voice chat page available at `/voice-chat`
1419

1520
## Run locally

web-ui/dist/assets/index-B0fN4I-_.js

Lines changed: 0 additions & 227 deletions
This file was deleted.

web-ui/dist/assets/index-DbMv0_9D.js

Lines changed: 229 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-ui/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>小智 · 终端对话</title>
7-
<script type="module" crossorigin src="/assets/index-B0fN4I-_.js"></script>
7+
<script type="module" crossorigin src="/assets/index-DbMv0_9D.js"></script>
88
<link rel="stylesheet" crossorigin href="/assets/index-CCBwXaU3.css">
99
</head>
1010
<body>

0 commit comments

Comments
 (0)