WEB/workflows/api-doc-agent/docs/修改接口.md
2026-04-16 20:59:44 +08:00

52 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 修改接口(Agent 自动执行工作流)
当用户输入 `更新接口`,Agent 必须全自动执行本流程,完成后端接口变更到前端 `src/api` 的对齐更新,无需用户干预。
## 0. 模式开关(先检查)
1. 读取 `workflows/api-doc-system/system/workflow-mode.json`。
2. 若 `mode=test`,只输出:`测试更新接口`,然后立即结束。
3. 只有 `mode=work` 才执行后续所有动作。
## 1. 核心数据源
- 前端 API 目录:`src/api`
- 待更新清单:`workflows/api-doc-system/data/pending-updates.json`
- 模块总览:`workflows/api-doc-system/data/module-list/module-list.json`
- 模块明细:`workflows/api-doc-system/data/module/<folder>/module.json`
- 接口维护表:`workflows/api-doc-agent/config/接口.md`
## 2. 自动执行步骤(严格顺序)
1. 读取 `pending-updates.json`。
2. 若 `pending-updates.json` 为 `{}`,先执行 `npm run apiconfig`。
3. 无论 `pending-updates.json` 是否为 `{}`,都必须读取 `module-list.json`,并更新 `src/api` 的模块与接口结构,保证与 `module` 对齐。
4. 若 `pending-updates.json` 存在变更项(接口增删、`Params/Response` 变化),按“增删优先”原则更新 `src/api`:新增模块/接口即创建,删除模块/接口即在 `config/接口.md` 标记 `启用=否`,并读取对应 `module.json` 的 `params` 生成或修改接口定义。
5. 完成接口改动后,执行 `npm run apiagent -- --script api-list-update`。
## 3. `config/接口.md` 维护规则(必须遵守)
- `启用`、`占位`、`备注` 三列属于人工维护字段,更新脚本不得覆盖。
- 新增接口默认值:
- `启用=是`
- `占位=否`
- 删除的接口/模块不做硬清理,统一通过 `config/接口.md` 中 `启用=否` 标记软删除,便于后续恢复。
## 4. 完成判定
以下条件同时满足才算完成:
1. `src/api` 的文件数与模块结构和 `module` 数据一致。
2. `src/api` 中接口定义满足对应 `module` 的 `params` 传参要求。
3. `npm run apiagent -- --script api-list-update` 执行成功。
4. `pending-updates.json` 已被清空为 `{}`。
## 5. 结果输出
返回以下信息:
- 更新统计:模块变更数量、接口变更数量
- 实际改动文件:`src/api/...`
- 异常接口列表(若有)
- 收尾结果:`api-list-update` 与 `clear-pending` 执行状态