backend-api-test-doc-official-site-agent-display.md
10.3 KB
鎺ュ彛娴嬭瘯鏂囨。 鈥?official-site-agent-display
1. 妯″潡姒傝
| 瀛楁 | 鍊? |
|---|---|
| 妯″潡鍚嶇О | official-site-agent-display |
| 妯″潡璇存槑 | 瀹樼綉Agent灞曠ず閰嶇疆 鈥?鍙敤Agent鍒楄〃銆侀厤缃繚瀛樸€佸凡閰嶇疆鍒楄〃銆佸垹闄ら厤缃? |
| 璺敱鍓嶇紑 | /api/v1/official-site/tabs |
| 鏁版嵁搴撹〃 | official_site_agent_display |
| 澶栭儴渚濊禆 | H5CacheManager锛堢紦瀛樺け鏁堬級 |
2. 鎺ュ彛鍒楄〃
| 搴忓彿 | 鏂规硶 | 璺緞 | 璇存槑 |
|---|---|---|---|
| 1 | GET | /api/v1/official-site/tabs/{tab_id}/agents/available |
鏌ヨ鍙敤Agent鍒楄〃 |
| 2 | POST | /api/v1/official-site/tabs/{tab_id}/agents/{agent_id}/config |
淇濆瓨Agent閰嶇疆 |
| 3 | GET | /api/v1/official-site/tabs/{tab_id}/agents/configured |
鏌ヨ宸查厤缃瓵gent鍒楄〃 |
| 4 | DELETE | /api/v1/official-site/tabs/{tab_id}/agents/{agent_id}/config |
鍒犻櫎Agent閰嶇疆 |
3. 鎺ュ彛璇︾粏璇存槑
3.1 鏌ヨ鍙敤Agent鍒楄〃
| 瀛楁 | 鍊? |
|---|---|
| 鏂规硶 | GET |
| 璺緞 | /api/v1/official-site/tabs/{tab_id}/agents/available |
璇锋眰鍙傛暟
| 鍙傛暟鍚? | 浣嶇疆 | 绫诲瀷 | 蹇呭~ | 璇存槑 |
|---|---|---|---|---|
| tab_id | path | integer | 鏄? | Tab ID |
鍝嶅簲鍙傛暟
| 瀛楁璺緞 | 绫诲瀷 | 璇存槑 |
|---|---|---|
| tab_id | integer | Tab ID |
| position_name | string | 宀椾綅鍚嶇О |
| qrcode_id | integer | 娲荤爜ID |
| available_agents | array | 鍙厤缃瓵gent鍒楄〃锛堟帓闄ょ瀹禔gent锛? |
| available_agents[].agent_id | integer | Agent ID |
| available_agents[].agent_name | string | Agent鍚嶇О |
| available_agents[].agent_code | string | Agent缂栫爜 |
| available_agents[].is_configured | boolean | 鏄惁宸查厤缃? |
| available_agents[].is_steward | boolean | 鏄惁绠″Agent |
| steward_agent | object | 绠″Agent淇℃伅 |
| steward_agent.agent_id | integer | Agent ID |
| steward_agent.note | string | 璇存槑鏂囨湰 |
*閿欒鐮?
| HTTP 鐘舵€佺爜 | 瑙﹀彂鏉′欢 |
|---|---|
| 404 | Tab涓嶅瓨鍦? |
3.2 淇濆瓨Agent閰嶇疆
| 瀛楁 | 鍊? |
|---|---|
| 鏂规硶 | POST |
| 璺緞 | /api/v1/official-site/tabs/{tab_id}/agents/{agent_id}/config |
璇锋眰鍙傛暟
| 鍙傛暟鍚? | 浣嶇疆 | 绫诲瀷 | 蹇呭~ | 璇存槑 |
|---|---|---|---|---|
| tab_id | path | integer | 鏄? | Tab ID |
| agent_id | path | integer | 鏄? | Agent ID |
| media_url | body | string | 鏄? | 绱犳潗URL锛屾渶闀?00 |
| media_type | body | string | 鏄? | 绱犳潗鏍煎紡锛歡if/mp4 |
| media_size | body | integer | 鍚? | 绱犳潗澶у皬(bytes) |
| speech_title | body | string | 鏄? | 璇濇湳鏍囬 |
| speech_content | body | string | 鏄? | 璇濇湳姝f枃 |
| display_status | body | string | 鍚? | 榛樿"enable" |
| sort_order | body | integer | 鍚? | 鎺掑簭锛岄粯璁? |
鍝嶅簲鍙傛暟
| 瀛楁璺緞 | 绫诲瀷 | 璇存槑 |
|---|---|---|
| config_id | integer | 閰嶇疆ID锛屾洿鏂版椂涓嶅彉 |
| tab_id | integer | Tab ID |
| agent_id | integer | Agent ID |
| updated_at | string | 鏇存柊鏃堕棿 |
*閿欒鐮?
| HTTP 鐘舵€佺爜 | 瑙﹀彂鏉′欢 |
|---|---|
| 400 | Agent涓嶅湪鍙厤缃垪琛ㄤ腑 / 绱犳潗鏍煎紡鏃犳晥 / 绱犳潗杩囧ぇ / 璇濇湳鏍囬杩囬暱 |
| 404 | Tab涓嶅瓨鍦? |
3.3 鏌ヨ宸查厤缃瓵gent鍒楄〃
| 瀛楁 | 鍊? |
|---|---|
| 鏂规硶 | GET |
| 璺緞 | /api/v1/official-site/tabs/{tab_id}/agents/configured |
鍝嶅簲鍙傛暟
| 瀛楁璺緞 | 绫诲瀷 | 璇存槑 |
|---|---|---|
| tab_id | integer | Tab ID |
| configured_agents | array | 宸查厤缃瓵gent鍒楄〃锛屾寜sort_order鎺掑簭 |
| configured_agents[].config_id | integer | 閰嶇疆ID |
| configured_agents[].agent_id | integer | Agent ID |
| configured_agents[].agent_name | string | Agent鍚嶇О |
| configured_agents[].display_status | string | 灞曠ず鐘舵€? |
| configured_agents[].sort_order | integer | 鎺掑簭 |
| configured_agents[].agent_status | string | Agent鍚敤鐘舵€? |
3.4 鍒犻櫎Agent閰嶇疆
| 瀛楁 | 鍊? |
|---|---|
| 鏂规硶 | DELETE |
| 璺緞 | /api/v1/official-site/tabs/{tab_id}/agents/{agent_id}/config |
鍝嶅簲鍙傛暟
| 瀛楁璺緞 | 绫诲瀷 | 璇存槑 |
|---|---|---|
| success | boolean | 鏄惁鎴愬姛 |
| deleted_at | string | 鍒犻櫎鏃堕棿 |
*閿欒鐮?
| HTTP 鐘舵€佺爜 | 瑙﹀彂鏉′欢 |
|---|---|
| 400/404 | 閰嶇疆涓嶅瓨鍦? |
4. 娴嬭瘯鍦烘櫙
4.1 鍙敤Agent鍒楄〃
| 搴忓彿 | 鍦烘櫙鍚嶇О | 棰勬湡缁撴灉 |
|---|---|---|
| 1 | 鎺掗櫎绠″Agent | steward.id 涓嶅湪 available_agents 鐨?agent_ids 涓? |
| 2 | 绠″Agent淇℃伅杩斿洖 | steward_agent 鍚?绠″" |
| 3 | is_configured鏍囪姝g‘ | 宸查厤缃殑agent is_configured=True |
| 4 | Tab涓嶅瓨鍦? | ValueError "Tab涓嶅瓨鍦? |
4.2 淇濆瓨閰嶇疆
| 搴忓彿 | 鍦烘櫙鍚嶇О | 棰勬湡缁撴灉 |
|---|---|---|
| 1 | 鏂板缓鎴愬姛 | config_id>0 |
| 2 | 鏇存柊宸叉湁閰嶇疆 | config_id涓嶅彉锛孌B涓粎1鏉¤褰? |
| 3 | Agent涓嶅湪鍙厤缃垪琛? | ValueError "涓嶅湪鍙厤缃垪琛ㄤ腑" |
| 4 | 绱犳潗鏍煎紡鏃犳晥(png) | ValueError "绱犳潗鏍煎紡" |
| 5 | 绱犳潗杩囧ぇ | ValueError "澶у皬" |
| 6 | 璇濇湳鏍囬杩囬暱 | ValueError "璇濇湳" |
| 7 | 淇濆瓨鍚庣紦瀛樺け鏁? | cache.was_invalidated() |
4.3 宸查厤缃瓵gent鍒楄〃
| 搴忓彿 | 鍦烘櫙鍚嶇О | 棰勬湡缁撴灉 |
|---|---|---|
| 1 | 姝e父鍒楀嚭 | configured_agents 闀垮害=1, agent_status="enable" |
| 2 | 鎸塻ort_order鎺掑簭 | sort_order灏忕殑鍦ㄥ墠 |
| 3 | Tab涓嶅瓨鍦? | ValueError |
4.4 鍒犻櫎閰嶇疆
| 搴忓彿 | 鍦烘櫙鍚嶇О | 棰勬湡缁撴灉 |
|---|---|---|
| 1 | 鍒犻櫎鎴愬姛 | success=True, DB涓閰嶇疆宸茬Щ闄? Agent鏈韩鏈垹闄? |
| 2 | 閰嶇疆涓嶅瓨鍦? | ValueError "閰嶇疆涓嶅瓨鍦? |
| 3 | 鍒犻櫎鍚庣紦瀛樺け鏁? | cache.was_invalidated() |
4.5 闆嗘垚娴佺▼
| 搴忓彿 | 鍦烘櫙鍚嶇О | 棰勬湡缁撴灉 |
|---|---|---|
| 1 | 鏌ュ彲鐢ㄢ啋淇濆瓨鈫掓煡宸查厤缃啋鍒犻櫎鈫掓煡宸查厤缃┖ | 鍏ㄦ祦绋嬮€氳繃 |
5. 瀵瑰簲娴嬭瘯浠g爜
娴嬭瘯鏂囦欢锛歚backend/tests/test_official_site_agent_display_api.py`
| 娴嬭瘯绫? | 娴嬭瘯鏂规硶 | 瀵瑰簲鍦烘櫙 |
|---|---|---|
| TestAvailableAgents | test_returns_available_agents_excluding_steward | 4.1-1 |
| TestAvailableAgents | test_steward_info_returned | 4.1-2 |
| TestAvailableAgents | test_is_configured_marked_correctly | 4.1-3 |
| TestAvailableAgents | test_tab_not_found | 4.1-4 |
| TestSaveAgentConfig | test_save_new_config | 4.2-1 |
| TestSaveAgentConfig | test_update_existing_config | 4.2-2 |
| TestSaveAgentConfig | test_agent_not_in_available_list | 4.2-3 |
| TestSaveAgentConfig | test_invalid_media_format | 4.2-4 |
| TestSaveAgentConfig | test_media_too_large | 4.2-5 |
| TestSaveAgentConfig | test_speech_title_too_long | 4.2-6 |
| TestSaveAgentConfig | test_save_invalidates_cache | 4.2-7 |
| TestConfiguredAgents | test_list_configured | 4.3-1 |
| TestConfiguredAgents | test_sort_order_respected | 4.3-2 |
| TestConfiguredAgents | test_tab_not_found | 4.3-3 |
| TestDeleteAgentConfig | test_delete_config | 4.4-1 |
| TestDeleteAgentConfig | test_agent_not_deleted | 4.4-1 |
| TestDeleteAgentConfig | test_config_not_found | 4.4-2 |
| TestDeleteAgentConfig | test_delete_invalidates_cache | 4.4-3 |
| TestIntegrationFlow | test_full_flow | 4.5-1 |
附录A 字段说明
A.1 通用响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| code | integer | 业务响应码。200 表示成功,400 表示请求参数错误,401 表示未授权,403 表示无权限,404 表示资源不存在,409 表示资源冲突,500 表示服务器内部错误。 |
| message | string | 响应说明。成功时固定为 success,失败时为具体错误原因。 |
| data | object/null | 实际业务数据。成功时返回对象或分页结构,失败时固定为 null。 |
A.2 分页字段
如果接口是列表查询,则 data 一般使用分页结构:
| 字段 | 类型 | 说明 |
|---|---|---|
| total | integer | 总记录数。 |
| page | integer | 当前页码,默认从 1 开始。 |
| page_size | integer | 每页数量,默认 20,最大 100。 |
| list | array | 当前页数据列表。 |
A.3 常见时间字段
| 字段类型 | 格式 | 说明 |
|---|---|---|
| created_at | ISO 8601 string | 创建时间。 |
| updated_at | ISO 8601 string | 更新时间。 |
| deleted_at | ISO 8601 string | 删除时间,仅删除类接口出现。 |
| archived_at | ISO 8601 string | 归档时间,仅归档类接口出现。 |
| triggered_at | ISO 8601 string | 触发时间,仅任务或同步类接口出现。 |
A.4 常见布尔与状态字段
| 字段 | 类型 | 说明 |
|---|---|---|
| success | boolean | 是否成功,通常用于删除、归档、状态切换等动作接口。 |
| status | string | 业务状态字段,具体取值以各接口正文说明为准,例如 enable、disable、active、archived、failed。 |
A.5 ID 与编码字段
| 字段类型 | 说明 |
|---|---|
*_id |
业务主键或外部主键。不同模块含义不同,需结合接口正文说明理解。 |
*_code |
业务编码字段,通常用于唯一标识某类对象,稳定性高于展示名称。 |
A.6 说明约定
- 具体接口字段的业务含义,以各文档正文中的“请求参数”“响应参数”“示例响应”为准。
- 本附录用于统一解释所有文档里重复出现的通用字段,避免重复写相同说明。
- 如果某个接口没有分页能力,则不会返回
total / page / page_size / list。