|
|
@@ -0,0 +1,288 @@
|
|
|
+# Web 数据与接口规划
|
|
|
+
|
|
|
+## 数据源总原则
|
|
|
+
|
|
|
+新 Web 使用两层数据源:
|
|
|
+
|
|
|
+1. 生产事实层:FastAPI 后端读取云 MySQL `content_agent_*` 表或后端聚合后的事实数据。
|
|
|
+2. 回放辅助层:本地 `runtime/v1/{run_id}/` JSON / JSONL 兼容导出。
|
|
|
+
|
|
|
+UI 必须明确标识数据来源:
|
|
|
+
|
|
|
+- `生产事实`:来自 DB / 后端聚合。
|
|
|
+- `回放导出`:来自 runtime JSON / JSONL。
|
|
|
+- `缺失`:当前 run 没有该文件或该表无数据。
|
|
|
+- `历史格式`:旧 runtime 文件名或旧结构。
|
|
|
+
|
|
|
+前端不得直接连接 MySQL,也不得直接读取任意文件路径。
|
|
|
+
|
|
|
+## 现有 FastAPI 接口
|
|
|
+
|
|
|
+当前 FastAPI 位于 `content_agent/api.py`。
|
|
|
+
|
|
|
+| Method | Path | 用途 | 当前响应 |
|
|
|
+|---|---|---|---|
|
|
|
+| `POST` | `/runs` | 启动一次运行 | `RunStartResponse` |
|
|
|
+| `GET` | `/runs/{run_id}` | 查询单 run 摘要 | `RunSummaryResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/discovered-content-items` | 查询发现内容 JSONL | `RecordsResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/rule-decisions` | 查询规则判断 JSONL | `RecordsResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/source-path-records` | 查询来源路径 JSONL | `RecordsResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/final-output` | 查询最终输出 JSON | `JsonFileResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/strategy-review` | 查询已有策略复盘 | `JsonFileResponse` |
|
|
|
+| `POST` | `/runs/{run_id}/strategy-review/regenerate` | 显式重新生成策略复盘 | `JsonFileResponse` |
|
|
|
+| `GET` | `/runs/{run_id}/validation` | 查询运行完整性校验 | `ValidationResponse` |
|
|
|
+
|
|
|
+现有缺口:
|
|
|
+
|
|
|
+- 没有 `GET /runs` run 列表。
|
|
|
+- 没有 dashboard 聚合接口。
|
|
|
+- 没有统一 runtime file 白名单读取接口。
|
|
|
+- 没有 Query、Timeline、Content Items 的 Web 聚合视图。
|
|
|
+- 没有 CORS / API base URL 的前端联调配置说明。
|
|
|
+
|
|
|
+## 现有 runtime 文件
|
|
|
+
|
|
|
+当前正式 runtime 文件:
|
|
|
+
|
|
|
+- `source_context.json`
|
|
|
+- `pattern_seed_pack.json`
|
|
|
+- `search_queries.jsonl`
|
|
|
+- `discovered_content_items.jsonl`
|
|
|
+- `content_media_records.jsonl`
|
|
|
+- `pattern_recall_evidence.jsonl`
|
|
|
+- `rule_decisions.jsonl`
|
|
|
+- `walk_actions.jsonl`
|
|
|
+- `run_events.jsonl`
|
|
|
+- `source_path_records.jsonl`
|
|
|
+- `search_clues.jsonl`
|
|
|
+- `final_output.json`
|
|
|
+- `strategy_review.json`
|
|
|
+
|
|
|
+Web 不应该直接绑定本地文件路径。后端如果暴露 runtime 文件,必须按 `RUNTIME_FILENAMES` 白名单读取。
|
|
|
+
|
|
|
+## 当前 DB 可展示实体
|
|
|
+
|
|
|
+当前生产 DB 是 21 张 `content_agent_*` 表。Web 第一版重点展示这些实体:
|
|
|
+
|
|
|
+| 实体 | 表 / 文件 | 用途 |
|
|
|
+|---|---|---|
|
|
|
+| Run | `content_agent_runs` | run 列表、状态、错误、时间 |
|
|
|
+| Source Context | `content_agent_source_contexts` / `source_context.json` | 需求来源和 evidence_pack |
|
|
|
+| Pattern Seed | `content_agent_pattern_seed_packs` / `pattern_seed_pack.json` | seed terms、itemset、category bindings |
|
|
|
+| Query | `content_agent_queries` / `search_queries.jsonl` | Query 文本、生成方式、LLM 变体 |
|
|
|
+| Discovered Content | `content_agent_discovered_content_items` / `discovered_content_items.jsonl` | 发现内容 |
|
|
|
+| Media Record | `content_agent_content_media_records` / `content_media_records.jsonl` | 媒体链接、画像、互动数据 |
|
|
|
+| Pattern Recall | `content_agent_pattern_recall_evidence` / `pattern_recall_evidence.jsonl` | P4 回扣证据 |
|
|
|
+| Rule Decision | `content_agent_rule_decisions` / `rule_decisions.jsonl` | P5 判断结果 |
|
|
|
+| Walk Action | `content_agent_walk_actions` / `walk_actions.jsonl` | P6 游走动作 |
|
|
|
+| Run Event | `content_agent_run_events` / `run_events.jsonl` | 运行事件和失败定位 |
|
|
|
+| Source Path | `content_agent_source_path_records` / `source_path_records.jsonl` | 来源链路 |
|
|
|
+| Search Clue | `content_agent_search_clues` / `search_clues.jsonl` | Query 效果聚合 |
|
|
|
+| Final Output | `content_agent_final_outputs` / `final_output.json` | 最终视图快照 |
|
|
|
+| Strategy Review | `content_agent_strategy_reviews` / `strategy_review.json` | 策略复盘 |
|
|
|
+| Author Asset | `content_agent_author_assets` | 作者资产 |
|
|
|
+| Performance Feedback | `content_agent_performance_feedback` | 后验表现反馈 |
|
|
|
+
|
|
|
+## 新增 Web 友好接口规划
|
|
|
+
|
|
|
+### 1. `GET /runs`
|
|
|
+
|
|
|
+用途:Run 列表页。
|
|
|
+
|
|
|
+查询参数:
|
|
|
+
|
|
|
+- `status`
|
|
|
+- `platform`
|
|
|
+- `platform_mode`
|
|
|
+- `strategy_version`
|
|
|
+- `validation_status`
|
|
|
+- `error_code`
|
|
|
+- `started_from`
|
|
|
+- `started_to`
|
|
|
+- `page`
|
|
|
+- `page_size`
|
|
|
+
|
|
|
+返回建议:
|
|
|
+
|
|
|
+```json
|
|
|
+{
|
|
|
+ "items": [
|
|
|
+ {
|
|
|
+ "run_id": "v1_run_xxx",
|
|
|
+ "policy_run_id": "policy_run_xxx",
|
|
|
+ "status": "success",
|
|
|
+ "platform": "douyin",
|
|
|
+ "platform_mode": "real",
|
|
|
+ "strategy_version": "V1",
|
|
|
+ "validation_status": "pass",
|
|
|
+ "error_code": null,
|
|
|
+ "started_at": "...",
|
|
|
+ "ended_at": "..."
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "page": 1,
|
|
|
+ "page_size": 20,
|
|
|
+ "total": 0
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 2. `GET /runs/{run_id}/dashboard`
|
|
|
+
|
|
|
+用途:Run 总览页一次加载所需摘要。
|
|
|
+
|
|
|
+返回建议:
|
|
|
+
|
|
|
+- `summary`
|
|
|
+- `file_status`
|
|
|
+- `validation`
|
|
|
+- `final_output_summary`
|
|
|
+- `strategy_review_status`
|
|
|
+- `counts`
|
|
|
+- `data_source_label`
|
|
|
+- `data_origin`
|
|
|
+- `links`
|
|
|
+
|
|
|
+其中 `data_origin` 只允许:
|
|
|
+
|
|
|
+- `production_db`
|
|
|
+- `runtime_export`
|
|
|
+- `mixed_with_runtime_export`
|
|
|
+
|
|
|
+### 3. `GET /runs/{run_id}/runtime-files`
|
|
|
+
|
|
|
+用途:Runtime / Validation 调试页。
|
|
|
+
|
|
|
+返回:
|
|
|
+
|
|
|
+- 文件名
|
|
|
+- 是否存在
|
|
|
+- 记录数
|
|
|
+- 文件类型:json / jsonl
|
|
|
+- 当前合同状态
|
|
|
+- 是否历史 alias
|
|
|
+
|
|
|
+### 4. `GET /runs/{run_id}/runtime-files/{filename}`
|
|
|
+
|
|
|
+用途:调试查看原始 runtime artifact。
|
|
|
+
|
|
|
+要求:
|
|
|
+
|
|
|
+- `filename` 必须在 `RUNTIME_FILENAMES` 白名单内。
|
|
|
+- 支持 `limit` / `offset`。
|
|
|
+- 不允许 `../`、绝对路径或任意文件名。
|
|
|
+
|
|
|
+### 5. `GET /runs/{run_id}/queries`
|
|
|
+
|
|
|
+用途:Query 阶段。
|
|
|
+
|
|
|
+聚合:
|
|
|
+
|
|
|
+- `search_queries`
|
|
|
+- `search_clues`
|
|
|
+- `rule_decisions` 聚合计数
|
|
|
+- Query 失败事件
|
|
|
+
|
|
|
+返回每条 Query:
|
|
|
+
|
|
|
+- `search_query_id`
|
|
|
+- `search_query`
|
|
|
+- `search_query_generation_method`
|
|
|
+- `query_source_terms`
|
|
|
+- `result_count`
|
|
|
+- `pooled_content_count`
|
|
|
+- `review_content_count`
|
|
|
+- `pending_content_count`
|
|
|
+- `rejected_content_count`
|
|
|
+- `search_query_effect_status`
|
|
|
+- `walk_next_step`
|
|
|
+- `failure_reason`
|
|
|
+
|
|
|
+### 6. `GET /runs/{run_id}/timeline`
|
|
|
+
|
|
|
+用途:阶段时间线和运行诊断。
|
|
|
+
|
|
|
+聚合:
|
|
|
+
|
|
|
+- `run_events`
|
|
|
+- `walk_actions`
|
|
|
+- `source_path_records`
|
|
|
+
|
|
|
+返回:
|
|
|
+
|
|
|
+- stage
|
|
|
+- event_type
|
|
|
+- status
|
|
|
+- timestamp
|
|
|
+- source artifact
|
|
|
+- target artifact
|
|
|
+- error_code
|
|
|
+- walk_action_id
|
|
|
+
|
|
|
+### 7. `GET /runs/{run_id}/content-items`
|
|
|
+
|
|
|
+用途:Platform、判断和内容详情页。
|
|
|
+
|
|
|
+查询参数:
|
|
|
+
|
|
|
+- `search_query_id`
|
|
|
+- `decision_action`
|
|
|
+- `effect_status`
|
|
|
+- `author_id`
|
|
|
+- `platform_content_id`
|
|
|
+- `page`
|
|
|
+- `page_size`
|
|
|
+
|
|
|
+聚合:
|
|
|
+
|
|
|
+- discovered content
|
|
|
+- content media
|
|
|
+- pattern recall evidence
|
|
|
+- rule decision
|
|
|
+- source path
|
|
|
+
|
|
|
+返回每条内容:
|
|
|
+
|
|
|
+- 内容基础信息
|
|
|
+- 作者信息
|
|
|
+- Query 来源
|
|
|
+- 互动统计
|
|
|
+- Pattern 回扣结果
|
|
|
+- 规则判断结果
|
|
|
+- source path 引用
|
|
|
+
|
|
|
+## 前端 API 配置
|
|
|
+
|
|
|
+Next.js 前端第一版使用:
|
|
|
+
|
|
|
+- `VITE_CONTENTFIND_API_BASE_URL`
|
|
|
+
|
|
|
+如果 Next.js 使用 `NEXT_PUBLIC_*` 命名,技术实现阶段可选择:
|
|
|
+
|
|
|
+- 保留 `VITE_CONTENTFIND_API_BASE_URL` 作为兼容名。
|
|
|
+- 新增 `NEXT_PUBLIC_CONTENTFIND_API_BASE_URL`。
|
|
|
+- 在 `web/.env.example` 同时写两个 key,但 runtime 只使用一个。
|
|
|
+
|
|
|
+本规划默认:实现时使用 `NEXT_PUBLIC_CONTENTFIND_API_BASE_URL`,并在文档中说明旧 `VITE_CONTENTFIND_API_BASE_URL` 是历史/兼容命名。
|
|
|
+
|
|
|
+## 错误与缺失数据展示
|
|
|
+
|
|
|
+Web 必须优雅处理:
|
|
|
+
|
|
|
+- run 不存在。
|
|
|
+- runtime 文件缺失。
|
|
|
+- DB 中某表暂无数据。
|
|
|
+- validation fail。
|
|
|
+- strategy review 未生成。
|
|
|
+- performance feedback missing。
|
|
|
+- DB run 全是 failed。
|
|
|
+- 历史 runtime 旧命名。
|
|
|
+
|
|
|
+页面不得因为缺一个 artifact 整体白屏。
|
|
|
+
|
|
|
+## 不做
|
|
|
+
|
|
|
+- 前端直连 MySQL。
|
|
|
+- 前端读取本地任意文件路径。
|
|
|
+- 在前端拼接 DB SQL。
|
|
|
+- 把 runtime export 当作生产事实。
|
|
|
+- 把 show 静态 demo 当作真实 run。
|