From 1320a10a8ee04f35a339302eb93d14f6f6486ce9 Mon Sep 17 00:00:00 2001 From: lizb Date: Thu, 15 May 2025 11:07:37 +0800 Subject: [PATCH] add service api of get workflow run node executions --- api/controllers/service_api/app/workflow.py | 18 ++++ .../develop/template/template_workflow.en.mdx | 86 +++++++++++++++++++ .../develop/template/template_workflow.ja.mdx | 86 +++++++++++++++++++ .../develop/template/template_workflow.zh.mdx | 86 +++++++++++++++++++ 4 files changed, 276 insertions(+) diff --git a/api/controllers/service_api/app/workflow.py b/api/controllers/service_api/app/workflow.py index e9bb2b046a..6600018dc9 100644 --- a/api/controllers/service_api/app/workflow.py +++ b/api/controllers/service_api/app/workflow.py @@ -26,6 +26,7 @@ from core.errors.error import ( from core.model_runtime.errors.invoke import InvokeError from extensions.ext_database import db from fields.workflow_app_log_fields import workflow_app_log_pagination_fields +from fields.workflow_run_fields import workflow_run_node_execution_list_fields from libs import helper from libs.helper import TimestampField from models.model import App, AppMode, EndUser @@ -33,6 +34,7 @@ from models.workflow import WorkflowRun, WorkflowRunStatus from services.app_generate_service import AppGenerateService from services.errors.llm import InvokeRateLimitError from services.workflow_app_service import WorkflowAppService +from services.workflow_run_service import WorkflowRunService logger = logging.getLogger(__name__) @@ -162,7 +164,23 @@ class WorkflowAppLogApi(Resource): return workflow_app_log_pagination +class WorkflowRunNodeExecutionListServiceApi(Resource): + @validate_app_token + @marshal_with(workflow_run_node_execution_list_fields) + def get(self, app_model: App, workflow_run_id: str): + """ + Get workflow run node execution list + """ + run_id = str(workflow_run_id) + + workflow_run_service = WorkflowRunService() + node_executions = workflow_run_service.get_workflow_run_node_executions(app_model=app_model, run_id=run_id) + + return {"data": node_executions} + + api.add_resource(WorkflowRunApi, "/workflows/run") api.add_resource(WorkflowRunDetailApi, "/workflows/run/") api.add_resource(WorkflowTaskStopApi, "/workflows/tasks//stop") api.add_resource(WorkflowAppLogApi, "/workflows/logs") +api.add_resource(WorkflowRunNodeExecutionListServiceApi, "/workflows/run//node-executions") diff --git a/web/app/components/develop/template/template_workflow.en.mdx b/web/app/components/develop/template/template_workflow.en.mdx index 2afcedc88c..129be993bd 100644 --- a/web/app/components/develop/template/template_workflow.en.mdx +++ b/web/app/components/develop/template/template_workflow.en.mdx @@ -611,6 +611,92 @@ Workflow applications offers non-session support and is ideal for translation, a --- + + + + Returns the node execution information of a workflow in descending order + + ### Response + - `data` (array[object]) + - `id` (string) Identifier + - `created_at` (timestamp) Creation time + - `created_by_account` (object) Account information that created the node + - `email` (string) Email + - `id` (string) Identifier + - `name` (string) Name + - `created_by_end_user` (object|null) End user + - `created_by_role` (string) Role, e.g. `account` + - `elapsed_time` (float) Elapsed time in seconds + - `error` (string|null) Error message + - `execution_metadata` (object|null) Execution metadata + - `extras` (object) Additional information + - `finished_at` (timestamp) Finish time + - `index` (int) Node index + - `inputs` (any|null) Input data + - `node_id` (string) Node identifier + - `node_type` (string) Node type, e.g. `end` + - `outputs` (any|null) Output data + - `predecessor_node_id` (string|null) Predecessor node identifier + - `process_data` (object|null) Processing data + - `status` (string) Execution status, `running` / `succeeded` / `failed` / `stopped` + - `title` (string) Node title + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id/node-executions' + --header 'Authorization: Bearer {api_key}' + ``` + + + ### Response Example + + ```json {{ title: 'Response' }} + { + "data": [ + { + "created_at": 1747244722, + "created_by_account": + { + "email": "lizb@test.com", + "id": "17f71940-a7b5-4c77-b60f-2bd645c1ffa0", + "name": "lizb" + }, + "created_by_end_user": None, + "created_by_role": "account", + "elapsed_time": 0.838795, + "error": None, + "execution_metadata": None, + "extras": {}, + "finished_at": 1747244722, + "id": "bffa2838-0e2c-4cba-bc9c-9abbcc38d001", + "index": 3, + "inputs": None, + "node_id": "1747273509709", + "node_type": "end", + "outputs": None, + "predecessor_node_id": "1745917690204", + "process_data": None, + "status": "succeeded", + "title": "Finish", + }, + ... + ] + } + + ``` + + + +--- + --- + + + + ワークフローのノード実行情報を降順で返します + + ### Response + - `data` (array[object]) + - `id` (string) 識別子 + - `created_at` (timestamp) 作成時間 + - `created_by_account` (object) このノードを作成したアカウント情報 + - `email` (string) メールアドレス + - `id` (string) 識別子 + - `name` (string) 名前 + - `created_by_end_user` (object|null) ユーザー + - `created_by_role` (string) 役割、例:'account` + - `elapsed_time` (float) 経過時間(単位:秒) + - `error` (string|null) エラーメッセージ + - `execution_metadata` (object|null) 実行メタデータ + - `extras` (object) 追加情報 + - `finished_at` (timestamp) 終了時間 + - `index` (int) ノードインデックス + - `inputs` (any|null) 入力データ + - `node_id` (string) ノード識別子 + - `node_type` (string) ノードタイプ、例:'end` + - `outputs` (any|null) 出力データ + - `predecessor_node_id` (string|null) 先行ノード識別子 + - `process_data` (object|null) 処理データ + - `status` (string) 実行状態、'running` / `succeeded` / `failed` / `stopped` + - `title` (string) ノードのタイトル + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id/node-executions' + --header 'Authorization: Bearer {api_key}' + ``` + + + ### Response Example + + ```json {{ title: 'Response' }} + { + "data": [ + { + "created_at": 1747244722, + "created_by_account": + { + "email": "lizb@test.com", + "id": "17f71940-a7b5-4c77-b60f-2bd645c1ffa0", + "name": "lizb" + }, + "created_by_end_user": None, + "created_by_role": "account", + "elapsed_time": 0.838795, + "error": None, + "execution_metadata": None, + "extras": {}, + "finished_at": 1747244722, + "id": "bffa2838-0e2c-4cba-bc9c-9abbcc38d001", + "index": 3, + "inputs": None, + "node_id": "1747273509709", + "node_type": "end", + "outputs": None, + "predecessor_node_id": "1745917690204", + "process_data": None, + "status": "succeeded", + "title": "Finish", + }, + ... + ] + } + + ``` + + + +--- + --- + + + + 倒序返回workflow的节点执行情况 + + ### Response + - `data` (array[object]) + - `id` (string) 标识 + - `created_at` (timestamp) 创建时间 + - `created_by_account` (object) 创建该节点的账户信息 + - `email` (string) 邮箱 + - `id` (string) 标识 + - `name` (string) 名称 + - `created_by_end_user` (object|null) 用户 + - `created_by_role` (string) 角色,例如 `account` + - `elapsed_time` (float) 耗时,单位秒 + - `error` (string|null) 错误信息 + - `execution_metadata` (object|null) 执行元数据 + - `extras` (object) 附加信息 + - `finished_at` (timestamp) 结束时间 + - `index` (int) 节点索引 + - `inputs` (any|null) 输入数据 + - `node_id` (string) 节点标识 + - `node_type` (string) 节点类型,例如 `end` + - `outputs` (any|null) 输出数据 + - `predecessor_node_id` (string|null) 前置节点标识 + - `process_data` (object|null) 处理数据 + - `status` (string) 执行状态,'running` / `succeeded` / `failed` / `stopped` + - `title` (string) 节点标题 + + + + + + ```bash {{ title: 'cURL' }} + curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id/node-executions' + --header 'Authorization: Bearer {api_key}' + ``` + + + ### Response Example + + ```json {{ title: 'Response' }} + { + "data": [ + { + "created_at": 1747244722, + "created_by_account": + { + "email": "lizb@test.com", + "id": "17f71940-a7b5-4c77-b60f-2bd645c1ffa0", + "name": "lizb" + }, + "created_by_end_user": None, + "created_by_role": "account", + "elapsed_time": 0.838795, + "error": None, + "execution_metadata": None, + "extras": {}, + "finished_at": 1747244722, + "id": "bffa2838-0e2c-4cba-bc9c-9abbcc38d001", + "index": 3, + "inputs": None, + "node_id": "1747273509709", + "node_type": "end", + "outputs": None, + "predecessor_node_id": "1745917690204", + "process_data": None, + "status": "succeeded", + "title": "Finish", + }, + ... + ] + } + + ``` + + + +--- +