diff --git a/docs/openapi/rohs_check_tools_openapi.json b/docs/openapi/rohs_check_tools_openapi.json index e99018c6..d4431b7a 100644 --- a/docs/openapi/rohs_check_tools_openapi.json +++ b/docs/openapi/rohs_check_tools_openapi.json @@ -7,7 +7,7 @@ }, "servers": [ { - "url": "http://192.168.100.192:8891", + "url": "http://localhost:8890", "description": "HXOPS_TOOLS_API_BASE" } ], @@ -76,7 +76,7 @@ } }, "409": { - "description": "检核进行中,同任务不可重复启动", + "description": "RoHS 检核进行中,全局不可重复启动", "content": { "application/json": { "schema": { @@ -97,6 +97,57 @@ } } }, + "/api/rohs-check/tools/runs": { + "get": { + "operationId": "list_rohs_runs", + "summary": "查询 RoHS 检核批次列表", + "tags": [ + "RoHS Check" + ], + "parameters": [ + { + "name": "task_id", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "example": 12 + }, + "description": "可选;指定检核任务 ID 时只返回该任务批次" + }, + { + "name": "limit", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "default": 20 + }, + "description": "返回条数,最大 100" + } + ], + "responses": { + "200": { + "description": "成功", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ListRunsResponse" + } + } + } + }, + "401": { + "$ref": "#/components/responses/Unauthorized" + }, + "404": { + "$ref": "#/components/responses/TaskNotFound" + } + } + } + }, "/api/rohs-check/tools/runs/{run_id}": { "get": { "operationId": "get_rohs_run", @@ -225,7 +276,7 @@ "BearerAuth": { "type": "http", "scheme": "bearer", - "description": "ROHS_TOOL_API_KEY 或 INTEGRATION_API_KEY" + "description": "ROHS_TOOLS_API_KEY 或 INTEGRATION_API_KEY" }, "IntegrationKey": { "type": "apiKey", @@ -442,7 +493,10 @@ "nullable": true } }, - "description": "task_id 与 task_no 至少提供一个;优先使用 task_id" + "required": [ + "task_id" + ], + "description": "Chatflow Start 节点固定配置 task_id;后端仍兼容 task_no,但 RoHS Chatflow 不使用任务选择流程" }, "RunCheckSuccessResponse": { "type": "object", @@ -507,6 +561,30 @@ } } }, + "ListRunsResponse": { + "type": "object", + "required": [ + "ok", + "runs", + "count" + ], + "properties": { + "ok": { + "type": "boolean", + "example": true + }, + "count": { + "type": "integer", + "example": 2 + }, + "runs": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RunDetail" + } + } + } + }, "ErrorResponse": { "type": "object", "required": [ @@ -556,7 +634,7 @@ } }, "MissingAuth": { - "description": "服务端未配置 ROHS_TOOL_API_KEY / INTEGRATION_API_KEY", + "description": "服务端未配置 ROHS_TOOLS_API_KEY / INTEGRATION_API_KEY", "content": { "application/json": { "schema": { @@ -565,7 +643,7 @@ "example": { "ok": false, "error_code": "missing_auth", - "message": "ROHS_TOOL_API_KEY or INTEGRATION_API_KEY is not configured" + "message": "ROHS_TOOLS_API_KEY or INTEGRATION_API_KEY is not configured" } } } diff --git a/docs/rohs_chatflow_guide.md b/docs/rohs_chatflow_guide.md index 7217fcd6..45961ea1 100644 --- a/docs/rohs_chatflow_guide.md +++ b/docs/rohs_chatflow_guide.md @@ -20,6 +20,8 @@ - **Dify RoHS Workflow** + `RoHSCheckService`:逐条判定合格 / 不合格 / 人工判定 - **本 Chatflow**:编排对话,调用 HXOPS Tool API 发起检核、查结果、展示报告链接;对历史报告类问题调用知识库检索;**不自行做合格判定** +- **当前有效启动方式**:RoHS 检核有且只有一个,Chatflow Start 节点固定配置 `task_id`,发起检核时直接调用 `/api/rohs-check/tools/tasks/run`;不再查询任务列表、不做任务选择。 +- **前端进度展示**:HXOPS 前端通过 Agent `extra_config.capabilities=["tool_run_progress"]` 挂载通用任务进度卡片,不按 Agent 名称硬编码。 **Tool API 基路径**:`/api/rohs-check` **OpenAPI 文件**:[`docs/openapi/rohs_check_tools_openapi.json`](./openapi/rohs_check_tools_openapi.json) @@ -86,12 +88,12 @@ flask db upgrade | 变量 | 必填 | 说明 | | --- | --- | --- | | `HXOPS_TOOLS_API_BASE` | 推荐 | Dify Tool 调用 hxops 的对外根地址(无尾斜杠),用于 OpenAPI、Excel 签名链接;未配置时回退 `PUBLIC_BASE_URL` | -| `ROHS_TOOL_API_KEY` | 推荐 | Chatflow Tool 专用 token;未配置时回退 `INTEGRATION_API_KEY` | +| `ROHS_TOOLS_API_KEY` | 推荐 | Chatflow Tool 专用 token;未配置时回退 `INTEGRATION_API_KEY` | | `INTEGRATION_API_KEY` | 二选一 | 与历史集成接口共用时可复用 | **注意**:token 仅放在 Dify Secret/Credential,不要写入前端或导出 YAML。 -**HXOPS 前端自动注入**:用户经 HXOPS 聊天页调用 RoHS Agent(`RoHS文件检核` / `RoHS文件检核助手` 等)时,`/api/chat/completions` 会把 `HXOPS_TOOLS_API_BASE`、`hxops_tool_api_token` 写入 Dify `inputs`(读 `HXOPS_TOOLS_API_BASE` 或 `HXOPS_TOOL_API_BASE`,token 读 `ROHS_TOOL_API_KEY` 或回退 `INTEGRATION_API_KEY`)。**切换 dev / test / prod 只改 hxops 环境变量,Dify 画布可原样发布**;Dify 直连调试时仍须在 Start「用户输入」里手工填这两项。 +**HXOPS 前端自动注入**:用户经 HXOPS 聊天页调用 RoHS Agent(`RoHS文件检核` / `RoHS文件检核助手` 等)时,`/api/chat/completions` 会把 `HXOPS_TOOLS_API_BASE`、`hxops_tool_api_token` 写入 Dify `inputs`(读 `HXOPS_TOOLS_API_BASE` 或 `HXOPS_TOOLS_API_BASE`,token 读 `ROHS_TOOLS_API_KEY` 或回退 `INTEGRATION_API_KEY`)。**切换 dev / test / prod 只改 hxops 环境变量,Dify 画布可原样发布**;Dify 直连调试时仍须在 Start「用户输入」里手工填这两项。 ### 1.3 创建 Chatflow 应用 @@ -107,7 +109,7 @@ flask db upgrade 1. 下载 [`docs/openapi/rohs_check_tools_openapi.json`](./openapi/rohs_check_tools_openapi.json)(或执行 `python backend/scripts/export_rohs_check_openapi.py` 按环境生成)。 2. 若从仓库下载 JSON,把 `servers[0].url` 设为与部署环境 `HXOPS_TOOLS_API_BASE` 相同;从线上下载 OpenAPI 时会自动注入该值。 3. Chatflow 画布 → 添加 **HTTP Request** 节点 → **从 OpenAPI 导入** → 上传 JSON。 -4. 导入后会出现 5 个 operation;编排建议 **手动建 4 个 HTTP 节点**(见 §3.4 / §3.8 / §3.16 / §3.17),各 HTTP 后接 Code 解析 `body`;Excel 下载由查询接口返回的 `download_url` 提供,无需单独节点。 +4. 导入后会出现多个 operation;当前 Chatflow 启动分支只需要 `run_rohs_check`,查询分支使用 `get_rohs_run` / `get_latest_rohs_run` / `list_rohs_runs`;`list_rohs_tasks` 仅保留为调试接口,不参与画布编排。 **方式 B:URL 导入** @@ -121,7 +123,7 @@ GET {HXOPS_TOOLS_API_BASE}/api/rohs-check/tools/openapi.json 1. Dify → **工具 / 凭据** → 新建 **API Key** 或 **Bearer Token**。 2. 名称:`hxops_rohs_tool`。 -3. 值:与 `ROHS_TOOL_API_KEY` 一致。 +3. 值:与 `ROHS_TOOLS_API_KEY` 一致。 4. 每个 HTTP 节点 Authorization 绑定该 Credential;**不要**把 token 写进 Answer 模板。 ### 1.6 绑定历史检核知识库(历史查询前置) @@ -141,15 +143,36 @@ GET {HXOPS_TOOLS_API_BASE}/api/rohs-check/tools/openapi.json ### 1.7 发布前自检 ```bash -# 检核任务列表(替换 TOKEN;BASE 与 HXOPS_TOOLS_API_BASE 一致) -curl -s -H "Authorization: Bearer $TOKEN" "$HXOPS_TOOLS_API_BASE/api/rohs-check/tools/tasks" - -# 启动检核 +# 启动检核(task_id 来自 Dify Start 节点配置) curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ -d '{"task_id":12,"trigger_source":"dify_chatflow"}' \ "$HXOPS_TOOLS_API_BASE/api/rohs-check/tools/tasks/run" ``` +### 1.8 HXOPS Agent 进度能力配置 + +需要在 RoHS 文件检核 Agent 的 `extra_config` 中配置通用进度能力: + +```json +{ + "capabilities": ["tool_run_progress"], + "tool_run_progress": { + "type": "rohs_check", + "title": "RoHS 文件检核", + "poll_interval_seconds": 2, + "active_url": "/api/workspace/rohs-check/runs/active", + "detail_url_template": "/api/workspace/rohs-check/runs/{run_id}", + "lock_input_when_running": true + } +} +``` + +说明: + +- 前端只判断 `tool_run_progress` 能力,不判断 Agent 名称。 +- `poll_interval_seconds` 默认 2 秒,前端限制在 1-30 秒。 +- 运行中若 `lock_input_when_running=true`,当前 Agent 对话输入、发送和附件上传会被锁定。 + --- ## 2. 编排总览 @@ -161,12 +184,7 @@ flowchart TD A[用户输入] --> B[LLM: 意图识别] B --> C{IF: 意图分类} - C -->|run_check| D[HTTP: 查询检核任务列表] - D --> D2[Code: 解析任务列表响应] - D2 --> E[Code: 选择检核任务] - E --> F{IF: 是否确定任务} - F -->|selected| G[HTTP: 异步启动检核] - F -->|其他| H[Answer: 请求用户选择任务] + C -->|run_check| G[HTTP: 异步启动检核] G --> G2[Code: 解析启动检核响应] G2 --> I{IF: 启动是否成功} I -->|ok=true| J[Answer: 检核已启动] @@ -177,6 +195,7 @@ flowchart TD M --> N{IF: 查询方式} N -->|by_run_id| O[HTTP: 查询指定检核] N -->|latest_by_task| P[HTTP: 查询最近检核] + N -->|all_runs| Y[HTTP: 查询所有检核批次] N -->|missing| Q[Answer: 引导提供查询条件] O --> O2[Code: 解析指定检核查询响应] @@ -185,6 +204,8 @@ flowchart TD P --> P2[Code: 解析最近检核查询响应] P2 --> R2[LLM: 生成最近检核结果说明] R2 --> S2[Answer: 返回最近检核结果] + Y --> Y2[Code: 解析所有检核批次响应] + Y2 --> Y3[Answer: 返回所有检核批次] C -->|history_report_query| V[Knowledge Retrieval: 检索历史检核报告] V --> W[LLM: 生成历史报告回答] @@ -199,16 +220,11 @@ flowchart TD | 1 | Start | 用户输入 | [§3.1](#31-用户输入) | | 2 | LLM | 意图识别 | [§3.2](#32-llm意图识别) | | 3 | IF | 意图分类 | [§3.3](#33-if意图分类) | -| 4 | HTTP | 查询检核任务列表 | [§3.4](#34-http查询检核任务列表) | -| 5 | Code | 解析检核任务列表响应 | [§3.5](#35-code解析检核任务列表响应) | -| 6 | Code | 选择检核任务 | [§3.6](#36-code选择检核任务) | -| 7 | IF | 是否确定检核任务 | [§3.7](#37-if是否确定检核任务) | -| 8 | HTTP | 异步启动检核 | [§3.8](#38-http异步启动检核) | -| 9 | Code | 解析启动检核响应 | [§3.9](#39-code解析启动检核响应) | -| 10 | IF | 启动结果分支 | [§3.10](#310-if启动结果分支) | -| 11 | Answer | 检核已启动 | [§3.11](#311-answer检核已启动) | -| 12 | Answer | 检核进行中 | [§3.12](#312-answer检核进行中) | -| 13 | Answer | 请求用户选择任务 | [§3.13](#313-answer请求用户选择任务) | +| 4 | HTTP | 异步启动检核 | [§3.8](#38-http异步启动检核) | +| 5 | Code | 解析启动检核响应 | [§3.9](#39-code解析启动检核响应) | +| 6 | IF | 启动结果分支 | [§3.10](#310-if启动结果分支) | +| 7 | Answer | 检核已启动 | [§3.11](#311-answer检核已启动) | +| 8 | Answer | 检核进行中 | [§3.12](#312-answer检核进行中) | | 14 | Code | 提取查询参数 | [§3.14](#314-code提取查询参数) | | 15 | IF | 查询方式 | [§3.15](#315-if查询方式) | | 16 | HTTP | 查询指定检核 | [§3.16](#316-http查询指定检核) | @@ -232,7 +248,7 @@ flowchart TD | 用户意图 | 数据来源 | Chatflow 路径 | 说明 | | --- | --- | --- | --- | | 发起一次新检核 | HXOPS Tool API | `run_check` → §3.4 到 §3.13 | 异步启动后台检核任务,不等待逐条判定完成 | -| 查询当前或最近一次检核状态 | HXOPS Tool API | `check_status` → §3.14 到 §3.20 | 查询运行中 / 已完成 / 失败状态、统计、Excel 链接和知识库同步状态 | +| 查询当前、最近或所有检核状态 | HXOPS Tool API | `check_status` → §3.14 到 §3.20 | 查询运行中 / 已完成 / 失败状态、统计、Excel 链接和知识库同步状态;“所有/全部”走批次列表 | | 查询历史报告内容 | Dify 知识库 | `history_report_query` → §3.25 到 §3.27 | 只检索已同步入库的历史检核报告,不代表当前检核实时状态 | **关键约束**: @@ -269,10 +285,8 @@ flowchart TD | 节点名 | 入参(名 · Dify 类型 · 必填 · 绑定) | 出参(名 · Dify 类型 · 说明) | | --- | --- | --- | -| `解析检核任务列表响应` | `body` · **String** · 是 · `查询检核任务列表.body` | `ok` · **Boolean**;`message` · **String**;`tasks_json` · **String** | -| `选择检核任务` | `intent_task_id` / `intent_task_no` / `default_task_id` / `default_task_no` / `tasks_json` · **String** · 后四项否 · 见 §3.6 | `selection_status` · **String** · `selected`/`need_user_select`/`not_found`;`selected_task_id` / `selected_task_no` / `selected_task_name` / `selection_message` · **String** | | `解析启动检核响应` | `body` · **String** · 是 · `异步启动检核.body` | `ok` · **Boolean**;`error_code` / `message` / `run_id` / `run_no` / `run_status` / `task_name` / `started_at` · **String** | -| `提取查询参数` | `user_query` / `intent_run_id` / `intent_task_id` / `default_task_id` · **String** · `user_query` 是,其余否 · 见 §3.14 | `query_mode` · **String** · `by_run_id`/`latest_by_task`/`missing`;`run_id` / `task_id` / `task_no` · **String** | +| `提取查询参数` | `user_query` / `intent_run_id` / `intent_task_id` / `task_id` · **String** · `user_query` 与 `task_id` 是,其余否 · 见 §3.14 | `query_mode` · **String** · `by_run_id`/`latest_by_task`/`all_runs`/`missing`;`run_id` / `task_id` / `task_no` · **String** | | `解析指定检核查询响应` | `body` · **String** · 是 · `查询指定检核.body` | `ok` · **Boolean**;`error_code` / `message` · **String**;`run_json` · **String** | | `解析最近检核查询响应` | `body` · **String** · 是 · `查询最近检核.body` | `ok` · **Boolean**;`error_code` / `message` · **String**;`run_json` · **String** | @@ -304,11 +318,8 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 用户问题: {{#用户输入.query#}} -默认检核任务 ID: -{{#用户输入.default_task_id#}} - -默认检核任务编号: -{{#用户输入.default_task_no#}} +RoHS 检核任务 ID: +{{#用户输入.task_id#}} ``` > 注意:不要使用 `{{节点名.变量名}}`,必须使用 `{{#节点名.变量名#}}`。 @@ -345,12 +356,11 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 | --- | --- | --- | --- | --- | | `query` | String | 是 | `sys.query` | 用户话术 | | `HXOPS_TOOLS_API_BASE` | String | 是 | 部署根地址 | 无尾斜杠,与 hxops `HXOPS_TOOLS_API_BASE` 一致 | -| `hxops_tool_api_token` | Secret | 是 | `ROHS_TOOL_API_KEY` | Tool API token | -| `default_task_id` | String | 否 | `""` | 默认检核任务 ID | -| `default_task_no` | String | 否 | `""` | 默认检核任务编号 | +| `hxops_tool_api_token` | Secret | 是 | `ROHS_TOOLS_API_KEY` | Tool API token | +| `task_id` | String | 是 | `12` | RoHS 检核任务 ID;各环境单独配置 | | `conversation_id` | String | 否 | `sys.conversation_id` | 写入启动检核 Body | -**传出(供下游引用)**:`用户输入.query` · String;`用户输入.HXOPS_TOOLS_API_BASE` · String;`用户输入.hxops_tool_api_token` · Secret;`用户输入.default_task_id` / `default_task_no` / `conversation_id` · String。 +**传出(供下游引用)**:`用户输入.query` · String;`用户输入.HXOPS_TOOLS_API_BASE` · String;`用户输入.hxops_tool_api_token` · Secret;`用户输入.task_id` / `conversation_id` · String。 --- @@ -363,8 +373,7 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 | 变量名 | Dify 类型 | 必填 | 绑定来源 | | --- | --- | --- | --- | | `user_query` | String | 是 | `用户输入.query` | -| `default_task_id` | String | 否 | `用户输入.default_task_id` | -| `default_task_no` | String | 否 | `用户输入.default_task_no` | +| `task_id` | String | 是 | `用户输入.task_id` | **结构化输出**(LLM 节点开启 JSON / 结构化输出) @@ -372,7 +381,7 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 | --- | --- | --- | | `intent` | String | `run_check` / `check_status` / `history_report_query` / `explain_capability` / `other` | | `task_id` | String | 检核任务 ID,无则 `""` | -| `task_no` | String | 检核任务编号,无则 `""` | +| `task_no` | String | 兼容字段;当前 Chatflow 不使用 | | `run_id` | String | 检核批次 ID,无则 `""` | | `confidence` | Number | 0–1 | @@ -439,11 +448,8 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 用户问题: {{#用户输入.query#}} -默认检核任务 ID: -{{#用户输入.default_task_id#}} - -默认检核任务编号: -{{#用户输入.default_task_no#}} +RoHS 检核任务 ID: +{{#用户输入.task_id#}} ``` **下游**:→ [§3.3 IF:意图分类](#33-if意图分类) @@ -458,7 +464,7 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 | 条件 | 下一节点 | | --- | --- | -| `意图识别.intent == "run_check"` | [§3.4 HTTP:查询检核任务列表](#34-http查询检核任务列表) | +| `意图识别.intent == "run_check"` | [§3.8 HTTP:异步启动检核](#38-http异步启动检核) | | `意图识别.intent == "check_status"` | [§3.14 Code:提取查询参数](#314-code提取查询参数) | | `意图识别.intent == "history_report_query"` | [§3.25 Knowledge Retrieval:检索历史检核报告](#325-knowledge-retrieval检索历史检核报告) | | `意图识别.intent == "explain_capability"` | [§3.22 Answer:能力说明](#322-answer能力说明) | @@ -468,6 +474,8 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 ### 3.4 HTTP:查询检核任务列表 +> **已废弃,不参与当前 Chatflow 编排。** RoHS 检核有且只有一个,Start 节点固定配置 `task_id` 后,`run_check` 分支直接进入 [§3.8 HTTP:异步启动检核](#38-http异步启动检核)。本接口仅保留给运维调试或排查配置使用。 + **上游**:IF 意图分类(`run_check` 分支) | 配置项 | 值 | @@ -489,6 +497,8 @@ LLM 节点不像 Code 节点一样通过函数参数声明入参;它的“输 ### 3.5 Code:解析检核任务列表响应 +> **已废弃,不参与当前 Chatflow 编排。** 不需要解析任务列表。 + **上游**:HTTP 查询检核任务列表 **输入变量** @@ -529,6 +539,8 @@ def main(body: str) -> dict: ### 3.6 Code:选择检核任务 +> **已废弃,不参与当前 Chatflow 编排。** 不需要选择检核任务;请直接使用 `用户输入.task_id`。 + **上游**:Code 解析检核任务列表响应、LLM 意图识别、用户输入 **输入变量** @@ -537,7 +549,7 @@ def main(body: str) -> dict: | --- | --- | --- | --- | | `intent_task_id` | String | 否 | `意图识别.task_id` | | `intent_task_no` | String | 否 | `意图识别.task_no` | -| `default_task_id` | String | 否 | `用户输入.default_task_id` | +| `task_id` | String | 是 | `用户输入.task_id` | | `default_task_no` | String | 否 | `用户输入.default_task_no` | | `tasks_json` | String | 是 | `解析检核任务列表响应.tasks_json` | @@ -637,6 +649,8 @@ def _ok(t, msg): ### 3.7 IF:是否确定检核任务 +> **已废弃,不参与当前 Chatflow 编排。** `run_check` 分支直接进入启动检核节点。 + **上游**:Code 选择检核任务 **判定变量**:`选择检核任务.selection_status` · **String** @@ -650,7 +664,7 @@ def _ok(t, msg): ### 3.8 HTTP:异步启动检核 -**上游**:IF 是否确定检核任务(`selected` 分支) +**上游**:IF 意图分类(`run_check` 分支) | 配置项 | 值 | | --- | --- | @@ -663,8 +677,7 @@ def _ok(t, msg): | 字段 | 类型 | 绑定 | | --- | --- | --- | -| `task_id` | integer | `选择检核任务.selected_task_id`(String,Dify 嵌入 JSON 数字) | -| `task_no` | string | `选择检核任务.selected_task_no` | +| `task_id` | integer | `用户输入.task_id`(String,Dify 嵌入 JSON 数字) | | `trigger_source` | string | 常量 `dify_chatflow` | | `conversation_id` | string | `用户输入.conversation_id` | | `user_message` | string | `用户输入.query` | @@ -673,8 +686,7 @@ def _ok(t, msg): ```json { - "task_id": {{#选择检核任务.selected_task_id#}}, - "task_no": "{{#选择检核任务.selected_task_no#}}", + "task_id": {{#用户输入.task_id#}}, "trigger_source": "dify_chatflow", "conversation_id": "{{#用户输入.conversation_id#}}", "user_message": "{{#用户输入.query#}}" @@ -690,7 +702,7 @@ def _ok(t, msg): **注意** - HTTP **409**(`check_running`)时 body 仍有 `error_code` 和 `run`,需在 Dify 勾选「将非 2xx 视为可解析响应」。 -- 相关错误码见 [附录 B](#附录-b错误码总表):`task_not_found`、`check_running`。 +- 相关错误码见 [附录 B](#附录-b错误码总表):`task_id_required`、`task_not_found`、`check_running`。 - `enabled` 仅表示该任务是否参与 cron 定时调度;Chatflow 的“立即执行”不检查此状态。 **下游**:→ [§3.9 Code:解析启动检核响应](#39-code解析启动检核响应) @@ -844,9 +856,9 @@ def main(body: str) -> dict: | 输出名 | Dify 类型 | 说明 | | --- | --- | --- | -| `query_mode` | String | `by_run_id` / `latest_by_task` / `missing` | +| `query_mode` | String | `by_run_id` / `latest_by_task` / `all_runs` / `missing` | | `run_id` | String | 检核批次 ID;非 by_run_id 时为 `""` | -| `task_id` | String | 检核任务 ID;非 latest_by_task 时为 `""` | +| `task_id` | String | 检核任务 ID;仅指定任务时有值 | | `task_no` | String | 预留,当前固定 `""` | **完整 Python 代码** @@ -854,10 +866,15 @@ def main(body: str) -> dict: ```python import re -def main(user_query, intent_run_id, intent_task_id, default_task_id) -> dict: +def main(user_query, intent_run_id, intent_task_id, task_id) -> dict: q = str(user_query or "") run_id = str(intent_run_id or "").strip() + all_keywords = ["所有", "全部", "全量", "列表", "历史记录", "执行记录", "所有文件检核结果", "全部文件检核结果", "all"] + if any(k in q for k in all_keywords): + tid = str(intent_task_id or task_id or "").strip() + return {"query_mode": "all_runs", "run_id": "", "task_id": tid, "task_no": ""} + if not run_id: m = re.search(r'(?:批次\s*ID|run[_\s-]*id|run_id)\s*[::]?\s*(\d+)', q, re.I) if m: @@ -872,11 +889,11 @@ def main(user_query, intent_run_id, intent_task_id, default_task_id) -> dict: latest_keywords = ["最新", "最近", "上一次", "上次", "latest"] if any(k in q for k in latest_keywords): - tid = str(intent_task_id or default_task_id or "").strip() + tid = str(intent_task_id or task_id or "").strip() if tid: return {"query_mode": "latest_by_task", "run_id": "", "task_id": tid, "task_no": ""} - tid = str(intent_task_id or default_task_id or "").strip() + tid = str(intent_task_id or task_id or "").strip() if tid: return {"query_mode": "latest_by_task", "run_id": "", "task_id": tid, "task_no": ""} @@ -897,6 +914,7 @@ def main(user_query, intent_run_id, intent_task_id, default_task_id) -> dict: | --- | --- | | `提取查询参数.query_mode == "by_run_id"` | [§3.16 HTTP:查询指定检核](#316-http查询指定检核) | | `提取查询参数.query_mode == "latest_by_task"` | [§3.17 HTTP:查询最近检核](#317-http查询最近检核) | +| `提取查询参数.query_mode == "all_runs"` | [§3.17A HTTP:查询所有检核批次](#317a-http查询所有检核批次) | | 默认 | [§3.21 Answer:引导提供查询条件](#321-answer引导提供查询条件) | --- @@ -943,9 +961,36 @@ def main(user_query, intent_run_id, intent_task_id, default_task_id) -> dict: --- +### 3.17A HTTP:查询所有检核批次 + +**上游**:IF 查询方式(`all_runs` 分支) + +| 配置项 | 值 | +| --- | --- | +| 方法 | `GET` | +| URL | `{{#用户输入.HXOPS_TOOLS_API_BASE#}}/api/rohs-check/tools/runs?limit=50` | +| Headers | `Authorization: Bearer {{#用户输入.hxops_tool_api_token#}}`(或绑定 §1.5 Credential) | +| Headers | `Accept: application/json` | + +若只查询某个任务的所有批次,URL 可改为: + +```text +{{#用户输入.HXOPS_TOOLS_API_BASE#}}/api/rohs-check/tools/runs?task_id={{#提取查询参数.task_id#}}&limit=50 +``` + +**输出变量**(Dify HTTP 节点固定) + +| 输出名 | Dify 类型 | 说明 | +| --- | --- | --- | +| `body` | String | 原始 JSON 响应体 | + +**下游**:→ [§3.18.3 Code:解析所有检核批次响应](#3183-code解析所有检核批次响应) + +--- + ### 3.18 Code:解析检核查询响应(两个节点) -> 画布中不要把“查询指定检核”和“查询最近检核”两路强行汇入同一个 Code 节点。这里是**同一段配置复制成两个 Code 节点**,分别命名为 `解析指定检核查询响应` 与 `解析最近检核查询响应`。 +> 画布中不要把“查询指定检核”“查询最近检核”“查询所有检核批次”三路强行汇入同一个 Code 节点。指定/最近使用同一段配置复制成两个 Code 节点;所有批次使用 §3.18.3。 #### 3.18.1 Code:解析指定检核查询响应 @@ -1000,6 +1045,68 @@ def main(body: str) -> dict: } ``` +#### 3.18.3 Code:解析所有检核批次响应 + +**上游**:HTTP 查询所有检核批次 + +**输入变量** + +| 变量名 | Dify 类型 | 必填 | 绑定来源 | +| --- | --- | --- | --- | +| `body` | String | 是 | `查询所有检核批次.body` | + +**输出变量** + +| 输出名 | Dify 类型 | 说明 | +| --- | --- | --- | +| `ok` | Boolean | API `ok` 字段 | +| `error_code` | String | 错误码 | +| `message` | String | 错误或提示文案 | +| `runs_json` | String | `runs` 数组 JSON 字符串,供 Answer 展示 | +| `count` | String | 返回批次数 | + +**完整 Python 代码** + +```python +import json + +def main(body: str) -> dict: + empty = {"ok": False, "error_code": "invalid_response", "message": "", "runs_json": "[]", "count": "0"} + if not str(body or "").strip(): + empty["message"] = "无 HTTP 响应体" + return empty + try: + data = json.loads(body or "{}") + except json.JSONDecodeError: + empty["message"] = f"非 JSON 响应:{str(body)[:200]}" + return empty + runs = data.get("runs") or [] + if not isinstance(runs, list): + runs = [] + return { + "ok": bool(data.get("ok")), + "error_code": str(data.get("error_code") or ""), + "message": str(data.get("message") or ""), + "runs_json": json.dumps(runs, ensure_ascii=False), + "count": str(data.get("count") if data.get("count") is not None else len(runs)), + } +``` + +**下游**:→ `Answer:返回所有检核批次` + +#### 3.18.4 Answer:返回所有检核批次 + +**模板** + +```text +共查询到 {{#解析所有检核批次响应.count#}} 条 RoHS 文件检核执行记录: + +{{#解析所有检核批次响应.runs_json#}} + +如需查看某一笔详情,请继续问: +“查询检核批次 ID xxx 的结果”。 +``` + **下游**: - `解析指定检核查询响应` → [§3.19 LLM:生成指定检核结果说明](#319-llm生成结果说明两个节点) @@ -1327,6 +1434,7 @@ def main(body: str) -> dict: | --- | --- | --- | --- | | `list_rohs_tasks` | GET | `/api/rohs-check/tools/tasks` | [§3.4](#34-http查询检核任务列表) + [§3.5](#35-code解析检核任务列表响应) | | `run_rohs_check` | POST | `/api/rohs-check/tools/tasks/run` | [§3.8](#38-http异步启动检核) + [§3.9](#39-code解析启动检核响应) | +| `list_rohs_runs` | GET | `/api/rohs-check/tools/runs` | [§3.17A](#317a-http查询所有检核批次) + [§3.18.3](#3183-code解析所有检核批次响应) | | `get_rohs_run` | GET | `/api/rohs-check/tools/runs/{run_id}` | [§3.16](#316-http查询指定检核) + [§3.18](#318-code解析检核查询响应两个节点) | | `get_latest_rohs_run` | GET | `/api/rohs-check/tools/tasks/{task_id}/latest-run` | [§3.17](#317-http查询最近检核) + [§3.18](#318-code解析检核查询响应两个节点) | | `download_rohs_run_excel` | GET | `/api/rohs-check/tools/runs/{run_id}/excel?token=` | 否(由 `run.excel.download_url` 提供) | @@ -1357,6 +1465,7 @@ def main(body: str) -> dict: | 检核进行中再次启动 | §3.8 409 → §3.9 → §3.12 | | `查询检核批次 ID 88 的结果` | §3.14 → §3.16 → §3.18 → §3.19 → §3.20 | | `查询最新一次 RoHS 检核结果` | §3.14 → §3.17 → §3.18 → §3.19 → §3.20 | +| `查询所有文件检核结果` | §3.14 → §3.17A → §3.18.3 → 返回所有检核批次 | | `上周 RoHS 有哪些不合格` | §3.25 → §3.26 → §3.27 | | `总结最近几次 RoHS 检核异常` | §3.25 → §3.26 → §3.27 | | `查询某供应商历史 RoHS 检核报告` | §3.25 → §3.26 → §3.27 | diff --git a/frontend/src/features/chat/views/ChatView.vue b/frontend/src/features/chat/views/ChatView.vue index e02881e1..85434d9d 100644 --- a/frontend/src/features/chat/views/ChatView.vue +++ b/frontend/src/features/chat/views/ChatView.vue @@ -4085,12 +4085,6 @@ const showChatRating = ref(false);