From 90e9c4f7dbc925a71a80974b8c2d63e232de797a Mon Sep 17 00:00:00 2001 From: RiskeyL <7a8y@163.com> Date: Tue, 26 May 2026 14:16:55 +0800 Subject: [PATCH 1/3] docs: document streaming SSE events for chat and chatflow APIs --- en/api-reference/openapi_chat.json | 4 ++-- en/api-reference/openapi_chatflow.json | 2 +- ja/api-reference/openapi_chat.json | 4 ++-- ja/api-reference/openapi_chatflow.json | 2 +- zh/api-reference/openapi_chat.json | 4 ++-- zh/api-reference/openapi_chatflow.json | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/en/api-reference/openapi_chat.json b/en/api-reference/openapi_chat.json index a418995ff..a0490dc64 100644 --- a/en/api-reference/openapi_chat.json +++ b/en/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "A stream of Server-Sent Events (SSE). Each event is a JSON object prefixed with `data: ` and terminated by two newlines. See `ChunkChatEvent` for possible event structures.\n\n**SSE Parsing Guide:** Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing JSON. The `event` field inside the JSON determines the event type. The stream ends when a `message_end` event is received. Ignore `ping` events (sent every 10 seconds to keep the connection alive). If an `error` event is received mid-stream, the stream terminates — parse the error object for details. Note that the HTTP status code is always `200` even when an error event occurs within the stream." + "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: The reply streams as `message` events (Chatbot apps), or as `agent_thought` and `agent_message` events (Agent apps), and ends with `message_end`. When text-to-speech auto-play is enabled, `tts_message` events interleave and `tts_message_end` becomes the final event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`.\n\n**Reply events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `message` | Chatbot | each answer chunk (concatenate in order) | `answer` |\n| `agent_message` | Agent | each answer chunk (concatenate in order) | `answer` |\n| `agent_thought` | Agent | each reasoning or tool-call step | `position`, `thought`, `tool`, `tool_input` (JSON), `observation`, `message_files` |\n| `message_replace` | Chatbot, Agent | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | Chatbot, Agent | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | Chatbot, Agent | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | Chatbot, Agent | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Transport events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `error` | Chatbot, Agent | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | Chatbot, Agent | keep-alive every 10 seconds | none |" }, "examples": { "streamingResponseBasic": { @@ -2664,7 +2664,7 @@ }, "mode": { "type": "string", - "description": "App mode, fixed as `chat`." + "description": "App mode. `chat` for Chatbot apps, `agent-chat` for Agent apps." }, "answer": { "type": "string", diff --git a/en/api-reference/openapi_chatflow.json b/en/api-reference/openapi_chatflow.json index 6c1e08125..fb868eae6 100644 --- a/en/api-reference/openapi_chatflow.json +++ b/en/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each line begins with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which fire every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: `message_end` signals the end of the chat message, but the stream continues with workflow lifecycle events. The stream closes when `workflow_finished`, `workflow_paused`, or `error` is received. Errors are delivered in-stream with HTTP status `200`; inspect the event payload for details rather than relying on the status code.\n\n**Human Input events**:\n- `human_input_required`: Fires together with `workflow_paused` when the workflow reaches a Human Input node. Use the `form_token` from the payload to drive the form-handling flow via the [Human Input API](/api-reference/human-input/get-human-input-form).\n- `human_input_form_filled`: A recipient submitted the form; workflow execution resumes.\n- `human_input_form_timeout`: The form expired without a response. Workflow follows the timeout fallback edge if defined." + "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: Workflow progress streams as `workflow_started`, node events (`node_started` and `node_finished`, plus iteration and loop variants), and the reply as `message` events. The closing sequence depends on the outcome:\n- **Success**: `message_end`, then `workflow_finished`\n- **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`\n- **Pause**: `human_input_required`, then `workflow_paused`, then `message_end` (the stream ends here; the run resumes separately)\n\nWhen text-to-speech auto-play is enabled, `tts_message_end` trails the closing event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`. Workflow, node, and human-input events also carry a top-level `workflow_run_id` and nest their payload under `data`.\n\n**Reply events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `message` | each answer chunk (concatenate in order) | `answer` |\n| `message_replace` | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Workflow and node events**\n\nEach event carries `workflow_run_id` and a `data` object.\n\n| Event | Fires on | Key `data` fields |\n|:---|:---|:---|\n| `workflow_started` | the run begins | `inputs` |\n| `node_started` | a node begins | `node_id`, `node_type`, `title` |\n| `node_finished` | a node ends | `status`, `outputs`, `execution_metadata` |\n| `node_retry` | a node retries after a failure | `retry_index` |\n| `iteration_started`, `iteration_next`, `iteration_completed` | Iteration node progress (informational) | `data` |\n| `loop_started`, `loop_next`, `loop_completed` | Loop node progress (informational) | `data` |\n| `agent_log` | an Agent node step log (informational; no `workflow_run_id`) | `data` |\n| `workflow_finished` | the run ends | `status` (`succeeded`, `failed`, `partial-succeeded`, `stopped`), `outputs`, `total_tokens` |\n| `workflow_paused` | the run pauses | `paused_nodes`, `reasons` |\n| `human_input_required` | the run reaches a Human Input node | `form_token`, `form_content`, `expiration_time` |\n\nAfter a pause this stream ends at `message_end`. Submit the form via [Submit Human Input Form](/api-reference/human-input/submit-human-input-form) or let it time out; the resumed run, including `human_input_form_filled`/`human_input_form_timeout` through `workflow_finished`, streams from [Stream Workflow Events](/api-reference/chatflows/stream-workflow-events).\n\n**Transport events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `error` | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | keep-alive every 10 seconds | none |" }, "examples": { "streamingResponseBasic": { diff --git a/ja/api-reference/openapi_chat.json b/ja/api-reference/openapi_chat.json index 98513f516..2f1c3c398 100644 --- a/ja/api-reference/openapi_chat.json +++ b/ja/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "サーバー送信イベント (SSE) のストリームです。各イベントは `data: ` プレフィックス付きの JSON オブジェクトで、2 つの改行で終了します。\n\n**SSE パースガイド:**各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去してください。JSON 内の `event` フィールドがイベントタイプを決定します。終了イベント(`message_end`、`workflow_finished`、`error` など)を受信するとストリームは終了します。`ping` イベント(10 秒ごとに接続維持のために送信)は無視してください。ストリーム内でエラーイベントが発生しても HTTP ステータスコードは常に `200` です。" + "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:回答は `message` イベント(チャットボットアプリ)、または `agent_thought` と `agent_message` イベント(Agent アプリ)としてストリーミングされ、`message_end` で終了します。テキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message` イベントが間に挟まり、`tts_message_end` が最後のイベントになります。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。\n\n**応答イベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `message` | チャットボット | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_message` | Agent | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_thought` | Agent | 推論またはツール呼び出しの各ステップ | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | チャットボット、Agent | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | チャットボット、Agent | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | チャットボット、Agent | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | チャットボット、Agent | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**トランスポートイベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `error` | チャットボット、Agent | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | チャットボット、Agent | 10 秒ごとのキープアライブ | なし |" }, "examples": { "streamingResponseBasic": { @@ -2664,7 +2664,7 @@ }, "mode": { "type": "string", - "description": "アプリモード、`chat` 固定です。" + "description": "アプリモード。`chat` はチャットボットアプリ、`agent-chat` は Agent アプリです。" }, "answer": { "type": "string", diff --git a/ja/api-reference/openapi_chatflow.json b/ja/api-reference/openapi_chatflow.json index cf1c85557..1288e4882 100644 --- a/ja/api-reference/openapi_chatflow.json +++ b/ja/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "Server-Sent Events (SSE) のストリーム。\n\n**パース**:各行は `data: ` で始まり JSON オブジェクトが続き、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベント(接続維持のため 10 秒ごとに送信)は無視してください。\n\n**ストリームライフサイクル**:`message_end` はチャットメッセージの終了を示しますが、ストリームはワークフローライフサイクルイベントを送信し続けます。`workflow_finished`、`workflow_paused`、または `error` を受信するとストリームが閉じます。エラーはストリーム内の `error` イベントとして HTTP ステータス `200` で配信されます。ステータスコードではなくイベントペイロードを確認して詳細を取得してください。\n\n**人間の入力イベント**:\n- `human_input_required`:ワークフローが人間の入力ノードに到達した際に `workflow_paused` と同時に発行されます。ペイロードの `form_token` を使用して、[人間の入力 API](/api-reference/人間の入力/人間の入力フォームを取得) でフォーム処理を進めます。\n- `human_input_form_filled`:受信者がフォームを送信し、ワークフロー実行が再開されます。\n- `human_input_form_timeout`:応答がないままフォームが期限切れ。タイムアウトのフォールバックエッジが定義されている場合、ワークフローはそのエッジを通って実行されます。" + "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:ワークフローの進行は `workflow_started`、ノードイベント(`node_started` と `node_finished`、およびイテレーションとループの各バリアント)として、回答は `message` イベントとしてストリーミングされます。終了シーケンスは実行結果によって異なります:\n- **成功**:`message_end`、続いて `workflow_finished`\n- **失敗**:ステータスが `failed` の `workflow_finished`、続いて `error`。`message_end` は送信されません\n- **一時停止**:`human_input_required`、続いて `workflow_paused`、続いて `message_end`(ストリームはここで終了し、実行は別途再開されます)\n\nテキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message_end` が終了イベントの後に続きます。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。ワークフロー、ノード、人間の入力イベントには、トップレベルの `workflow_run_id` も含まれ、ペイロードは `data` の下にネストされます。\n\n**応答イベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `message` | 回答の各チャンク(順番に連結) | `answer` |\n| `message_replace` | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**ワークフロー・ノードイベント**\n\n各イベントには `workflow_run_id` と `data` オブジェクトが含まれます。\n\n| イベント | 発生タイミング | 主な `data` フィールド |\n|:---|:---|:---|\n| `workflow_started` | 実行開始 | `inputs` |\n| `node_started` | ノード開始 | `node_id`、`node_type`、`title` |\n| `node_finished` | ノード終了 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 失敗後にノードを再試行 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | イテレーションノードの進行(情報提供のみ、処理は任意) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | ループノードの進行(情報提供のみ、処理は任意) | `data` |\n| `agent_log` | Agent ノードのステップログ(情報提供のみ、処理は任意、`workflow_run_id` なし) | `data` |\n| `workflow_finished` | 実行終了 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 実行が一時停止 | `paused_nodes`、`reasons` |\n| `human_input_required` | 実行が人間の入力ノードに到達 | `form_token`、`form_content`、`expiration_time` |\n\n一時停止後、このストリームは `message_end` で終了します。[人間の入力フォームを送信](/api-reference/人間の入力/人間の入力フォームを送信) でフォームを送信するか、タイムアウトさせてください。再開後の実行(`human_input_form_filled`/`human_input_form_timeout` から `workflow_finished` までを含む)は、[ワークフローイベントをストリーム](/api-reference/チャットフロー/ワークフローイベントをストリーム) からストリーミングされます。\n\n**トランスポートイベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `error` | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | 10 秒ごとのキープアライブ | なし |" }, "examples": { "streamingResponseBasic": { diff --git a/zh/api-reference/openapi_chat.json b/zh/api-reference/openapi_chat.json index ac6d02e8e..a4eae0bd5 100644 --- a/zh/api-reference/openapi_chat.json +++ b/zh/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "服务器发送事件 (SSE) 流。每个事件是一个以 `data: ` 为前缀的 JSON 对象,以两个换行符终止。\n\n**SSE 解析指南:**每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀。JSON 内的 `event` 字段决定事件类型。当收到终止事件(如 `message_end`、`workflow_finished` 或 `error`)时流结束。忽略 `ping` 事件(每 10 秒发送一次以保持连接活跃)。注意即使流中出现错误事件,HTTP 状态码仍为 `200`。" + "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:回复以 `message` 事件(聊天助手应用)或 `agent_thought` 与 `agent_message` 事件(Agent 应用)的形式流式返回,并以 `message_end` 结束。开启文本转语音(TTS)自动播放时,`tts_message` 事件会穿插其间,`tts_message_end` 成为最后一个事件。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。\n\n**回复事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `message` | 聊天助手 | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_message` | Agent | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_thought` | Agent | 每个推理或工具调用步骤 | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | 聊天助手、Agent | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 聊天助手、Agent | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 聊天助手、Agent | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 聊天助手、Agent | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**传输事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `error` | 聊天助手、Agent | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 聊天助手、Agent | 每 10 秒保持连接 | 无 |" }, "examples": { "streamingResponseBasic": { @@ -2664,7 +2664,7 @@ }, "mode": { "type": "string", - "description": "应用模式,固定为 `chat`。" + "description": "应用模式。`chat` 表示聊天助手应用,`agent-chat` 表示 Agent 应用。" }, "answer": { "type": "string", diff --git a/zh/api-reference/openapi_chatflow.json b/zh/api-reference/openapi_chatflow.json index b815a39ee..7066251b5 100644 --- a/zh/api-reference/openapi_chatflow.json +++ b/zh/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每行以 `data: ` 开头,后接一个 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,该事件每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:`message_end` 标志聊天消息的结束,但流会继续发送工作流生命周期事件。收到 `workflow_finished`、`workflow_paused` 或 `error` 时流关闭。错误以流内 `error` 事件的形式返回,HTTP 状态码始终为 `200`;请检查事件载荷获取详情,不要依赖状态码判断。\n\n**人工介入事件**:\n- `human_input_required`:工作流到达人工介入节点时与 `workflow_paused` 一同触发。使用载荷中的 `form_token` 通过 [人工介入 API](/api-reference/人工介入/获取人工介入表单) 处理表单。\n- `human_input_form_filled`:接收者提交了表单,工作流恢复执行。\n- `human_input_form_timeout`:表单超时未响应。如定义了超时回退分支,工作流将沿该分支执行。" + "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:工作流进度以 `workflow_started`、节点事件(`node_started` 和 `node_finished`,以及迭代和循环的相应变体)流式返回,回复则以 `message` 事件返回。结束序列取决于运行结果:\n- **成功**:`message_end`,随后 `workflow_finished`\n- **失败**:`workflow_finished`(状态为 `failed`),随后 `error`;不发送 `message_end`\n- **暂停**:`human_input_required`,随后 `workflow_paused`,随后 `message_end`(流到此结束,运行将另行恢复)\n\n开启文本转语音(TTS)自动播放时,`tts_message_end` 跟随在结束事件之后。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。工作流、节点和人工介入事件还带有顶层 `workflow_run_id`,并将载荷嵌套在 `data` 中。\n\n**回复事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `message` | 每个回答片段(按顺序拼接) | `answer` |\n| `message_replace` | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**工作流与节点事件**\n\n每个事件都带有 `workflow_run_id` 和一个 `data` 对象。\n\n| 事件 | 触发时机 | 关键 `data` 字段 |\n|:---|:---|:---|\n| `workflow_started` | 运行开始 | `inputs` |\n| `node_started` | 节点开始 | `node_id`、`node_type`、`title` |\n| `node_finished` | 节点结束 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 节点失败后重试 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | 迭代节点进度(信息性,可不处理) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | 循环节点进度(信息性,可不处理) | `data` |\n| `agent_log` | Agent 节点步骤日志(信息性,可不处理;无 `workflow_run_id`) | `data` |\n| `workflow_finished` | 运行结束 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 运行暂停 | `paused_nodes`、`reasons` |\n| `human_input_required` | 运行到达人工介入节点 | `form_token`、`form_content`、`expiration_time` |\n\n暂停后,本流在 `message_end` 处结束。通过 [提交人工介入表单](/api-reference/人工介入/提交人工介入表单) 提交表单,或等待其超时;恢复后的运行(包括从 `human_input_form_filled`/`human_input_form_timeout` 到 `workflow_finished` 的事件)由 [流式获取工作流事件](/api-reference/对话流/流式获取工作流事件) 流式返回。\n\n**传输事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `error` | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 每 10 秒保持连接 | 无 |" }, "examples": { "streamingResponseBasic": { From 399f138fd7a53958126d844b1357b6f80bab3142 Mon Sep 17 00:00:00 2001 From: RiskeyL <7a8y@163.com> Date: Tue, 26 May 2026 18:54:03 +0800 Subject: [PATCH 2/3] fix: reconcile streaming response docs, schemas, and examples --- en/api-reference/openapi_chat.json | 14 ++++++-------- en/api-reference/openapi_chatflow.json | 16 +++++++--------- ja/api-reference/openapi_chat.json | 14 ++++++-------- ja/api-reference/openapi_chatflow.json | 16 +++++++--------- zh/api-reference/openapi_chat.json | 14 ++++++-------- zh/api-reference/openapi_chatflow.json | 16 +++++++--------- 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/en/api-reference/openapi_chat.json b/en/api-reference/openapi_chat.json index a0490dc64..df89bf5c9 100644 --- a/en/api-reference/openapi_chat.json +++ b/en/api-reference/openapi_chat.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "Successful response. The content type and structure depend on the `response_mode` parameter in the request.\n\n- If `response_mode` is `blocking`, returns `application/json` with a `ChatCompletionResponse` object.\n- If `response_mode` is `streaming`, returns `text/event-stream` with a stream of `ChunkChatEvent` objects.", + "description": "Successful response. The content type and structure depend on the `response_mode` parameter in the request.\n\n- If `response_mode` is `blocking`, returns `application/json` with a `ChatCompletionResponse` object.\n- If `response_mode` is `streaming`, returns `text/event-stream` with a stream of Server-Sent Events.", "content": { "application/json": { "schema": { @@ -137,7 +137,7 @@ }, "streamingResponseAgent": { "summary": "Response Example - Streaming (Agent)", - "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"conversation_id\": \"conv123\"} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" + "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"created_at\": 1705395332} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" } } } @@ -2889,6 +2889,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "Message file event, a new file created by a tool.", @@ -2910,11 +2913,6 @@ "type": "string", "format": "url", "description": "Remote URL of the file." - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "Conversation ID." } } } @@ -3016,7 +3014,7 @@ }, { "type": "object", - "description": "Ping event to keep connection alive." + "description": "Ping event to keep connection alive. Delivered as an `event: ping` line with no `data:` payload." } ] }, diff --git a/en/api-reference/openapi_chatflow.json b/en/api-reference/openapi_chatflow.json index fb868eae6..c63d55e93 100644 --- a/en/api-reference/openapi_chatflow.json +++ b/en/api-reference/openapi_chatflow.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "Successful response. The content type and structure depend on the `response_mode` parameter in the request.\n\n- If `response_mode` is `blocking`, returns `application/json` with a `ChatCompletionResponse` object.\n- If `response_mode` is `streaming`, returns `text/event-stream` with a stream of `ChunkChatEvent` objects.", + "description": "Successful response. The content type and structure depend on the `response_mode` parameter in the request.\n\n- If `response_mode` is `blocking`, returns `application/json` with a `ChatCompletionResponse` object.\n- If `response_mode` is `streaming`, returns `text/event-stream` with a stream of Server-Sent Events.", "content": { "application/json": { "schema": { @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: Workflow progress streams as `workflow_started`, node events (`node_started` and `node_finished`, plus iteration and loop variants), and the reply as `message` events. The closing sequence depends on the outcome:\n- **Success**: `message_end`, then `workflow_finished`\n- **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`\n- **Pause**: `human_input_required`, then `workflow_paused`, then `message_end` (the stream ends here; the run resumes separately)\n\nWhen text-to-speech auto-play is enabled, `tts_message_end` trails the closing event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`. Workflow, node, and human-input events also carry a top-level `workflow_run_id` and nest their payload under `data`.\n\n**Reply events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `message` | each answer chunk (concatenate in order) | `answer` |\n| `message_replace` | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Workflow and node events**\n\nEach event carries `workflow_run_id` and a `data` object.\n\n| Event | Fires on | Key `data` fields |\n|:---|:---|:---|\n| `workflow_started` | the run begins | `inputs` |\n| `node_started` | a node begins | `node_id`, `node_type`, `title` |\n| `node_finished` | a node ends | `status`, `outputs`, `execution_metadata` |\n| `node_retry` | a node retries after a failure | `retry_index` |\n| `iteration_started`, `iteration_next`, `iteration_completed` | Iteration node progress (informational) | `data` |\n| `loop_started`, `loop_next`, `loop_completed` | Loop node progress (informational) | `data` |\n| `agent_log` | an Agent node step log (informational; no `workflow_run_id`) | `data` |\n| `workflow_finished` | the run ends | `status` (`succeeded`, `failed`, `partial-succeeded`, `stopped`), `outputs`, `total_tokens` |\n| `workflow_paused` | the run pauses | `paused_nodes`, `reasons` |\n| `human_input_required` | the run reaches a Human Input node | `form_token`, `form_content`, `expiration_time` |\n\nAfter a pause this stream ends at `message_end`. Submit the form via [Submit Human Input Form](/api-reference/human-input/submit-human-input-form) or let it time out; the resumed run, including `human_input_form_filled`/`human_input_form_timeout` through `workflow_finished`, streams from [Stream Workflow Events](/api-reference/chatflows/stream-workflow-events).\n\n**Transport events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `error` | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | keep-alive every 10 seconds | none |" + "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: Workflow progress streams as `workflow_started`, node events (`node_started` and `node_finished`, plus iteration and loop variants), and the reply as `message` events. The closing sequence depends on the outcome:\n- **Success**: `message_end`, then `workflow_finished`\n- **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`\n- **Pause**: `human_input_required`, then `workflow_paused`, then `message_end` (the stream ends here; the run resumes separately)\n\nWhen text-to-speech auto-play is enabled, `tts_message_end` trails the closing event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`. Workflow, node, and human-input events also nest their payload under `data` and, except for `agent_log`, carry a top-level `workflow_run_id`.\n\n**Reply events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `message` | each answer chunk (concatenate in order) | `answer` |\n| `message_replace` | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Workflow and node events**\n\nEach event nests its payload under a `data` object.\n\n| Event | Fires on | Key `data` fields |\n|:---|:---|:---|\n| `workflow_started` | the run begins | `inputs` |\n| `node_started` | a node begins | `node_id`, `node_type`, `title` |\n| `node_finished` | a node ends | `status`, `outputs`, `execution_metadata` |\n| `node_retry` | a node retries after a failure | `retry_index` |\n| `iteration_started`, `iteration_next`, `iteration_completed` | Iteration node progress (informational) | `data` |\n| `loop_started`, `loop_next`, `loop_completed` | Loop node progress (informational) | `data` |\n| `agent_log` | an Agent node step log (informational; no `workflow_run_id`) | `data` |\n| `workflow_finished` | the run ends | `status` (`succeeded`, `failed`, `partial-succeeded`, `stopped`), `outputs`, `total_tokens` |\n| `workflow_paused` | the run pauses | `paused_nodes`, `reasons` |\n| `human_input_required` | the run reaches a Human Input node | `form_token`, `form_content`, `expiration_time` |\n\nAfter a pause this stream ends at `message_end`. Submit the form via [Submit Human Input Form](/api-reference/human-input/submit-human-input-form) or let it time out; the resumed run, including `human_input_form_filled`/`human_input_form_timeout` through `workflow_finished`, streams from [Stream Workflow Events](/api-reference/chatflows/stream-workflow-events).\n\n**Transport events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `error` | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | keep-alive every 10 seconds | none |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "Response Example - Human Input pause", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" } } } @@ -3549,6 +3549,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "Message file event, a new file created by a tool.", @@ -3573,11 +3576,6 @@ "type": "string", "format": "url", "description": "Remote URL of the file." - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "Conversation ID." } } } @@ -3679,7 +3677,7 @@ }, { "type": "object", - "description": "Ping event to keep connection alive." + "description": "Ping event to keep connection alive. Delivered as an `event: ping` line with no `data:` payload." } ] }, diff --git a/ja/api-reference/openapi_chat.json b/ja/api-reference/openapi_chat.json index 2f1c3c398..d892db442 100644 --- a/ja/api-reference/openapi_chat.json +++ b/ja/api-reference/openapi_chat.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "リクエスト成功。コンテンツタイプと構造はリクエストの `response_mode` パラメータに依存します。\n\n- `response_mode` が `blocking` の場合、 `application/json` で `ChatCompletionResponse` オブジェクトを返します。\n- `response_mode` が `streaming` の場合、 `text/event-stream` で `ChunkChatEvent` オブジェクトのストリームを返します。", + "description": "リクエスト成功。コンテンツタイプと構造はリクエストの `response_mode` パラメータに依存します。\n\n- `response_mode` が `blocking` の場合、 `application/json` で `ChatCompletionResponse` オブジェクトを返します。\n- `response_mode` が `streaming` の場合、`text/event-stream` でサーバー送信イベントのストリームを返します。", "content": { "application/json": { "schema": { @@ -137,7 +137,7 @@ }, "streamingResponseAgent": { "summary": "Response Example - Streaming (Agent)", - "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"conversation_id\": \"conv123\"} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" + "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"created_at\": 1705395332} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" } } } @@ -2889,6 +2889,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "メッセージファイルイベント。ツールによって作成された新しいファイルです。", @@ -2910,11 +2913,6 @@ "type": "string", "format": "url", "description": "ファイルのリモート URL。" - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "会話 ID。" } } } @@ -3016,7 +3014,7 @@ }, { "type": "object", - "description": "接続を維持するための Ping イベント。" + "description": "接続を維持するための Ping イベント。`event: ping` 行として送信され、`data:` ペイロードはありません。" } ] }, diff --git a/ja/api-reference/openapi_chatflow.json b/ja/api-reference/openapi_chatflow.json index 1288e4882..424da1bd5 100644 --- a/ja/api-reference/openapi_chatflow.json +++ b/ja/api-reference/openapi_chatflow.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "リクエスト成功。コンテンツタイプと構造はリクエストの `response_mode` パラメータに依存します。\n\n- `response_mode` が `blocking` の場合、 `application/json` で `ChatCompletionResponse` オブジェクトを返します。\n- `response_mode` が `streaming` の場合、 `text/event-stream` で `ChunkChatEvent` オブジェクトのストリームを返します。", + "description": "リクエスト成功。コンテンツタイプと構造はリクエストの `response_mode` パラメータに依存します。\n\n- `response_mode` が `blocking` の場合、 `application/json` で `ChatCompletionResponse` オブジェクトを返します。\n- `response_mode` が `streaming` の場合、`text/event-stream` でサーバー送信イベントのストリームを返します。", "content": { "application/json": { "schema": { @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:ワークフローの進行は `workflow_started`、ノードイベント(`node_started` と `node_finished`、およびイテレーションとループの各バリアント)として、回答は `message` イベントとしてストリーミングされます。終了シーケンスは実行結果によって異なります:\n- **成功**:`message_end`、続いて `workflow_finished`\n- **失敗**:ステータスが `failed` の `workflow_finished`、続いて `error`。`message_end` は送信されません\n- **一時停止**:`human_input_required`、続いて `workflow_paused`、続いて `message_end`(ストリームはここで終了し、実行は別途再開されます)\n\nテキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message_end` が終了イベントの後に続きます。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。ワークフロー、ノード、人間の入力イベントには、トップレベルの `workflow_run_id` も含まれ、ペイロードは `data` の下にネストされます。\n\n**応答イベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `message` | 回答の各チャンク(順番に連結) | `answer` |\n| `message_replace` | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**ワークフロー・ノードイベント**\n\n各イベントには `workflow_run_id` と `data` オブジェクトが含まれます。\n\n| イベント | 発生タイミング | 主な `data` フィールド |\n|:---|:---|:---|\n| `workflow_started` | 実行開始 | `inputs` |\n| `node_started` | ノード開始 | `node_id`、`node_type`、`title` |\n| `node_finished` | ノード終了 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 失敗後にノードを再試行 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | イテレーションノードの進行(情報提供のみ、処理は任意) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | ループノードの進行(情報提供のみ、処理は任意) | `data` |\n| `agent_log` | Agent ノードのステップログ(情報提供のみ、処理は任意、`workflow_run_id` なし) | `data` |\n| `workflow_finished` | 実行終了 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 実行が一時停止 | `paused_nodes`、`reasons` |\n| `human_input_required` | 実行が人間の入力ノードに到達 | `form_token`、`form_content`、`expiration_time` |\n\n一時停止後、このストリームは `message_end` で終了します。[人間の入力フォームを送信](/api-reference/人間の入力/人間の入力フォームを送信) でフォームを送信するか、タイムアウトさせてください。再開後の実行(`human_input_form_filled`/`human_input_form_timeout` から `workflow_finished` までを含む)は、[ワークフローイベントをストリーム](/api-reference/チャットフロー/ワークフローイベントをストリーム) からストリーミングされます。\n\n**トランスポートイベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `error` | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | 10 秒ごとのキープアライブ | なし |" + "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:ワークフローの進行は `workflow_started`、ノードイベント(`node_started` と `node_finished`、およびイテレーションとループの各バリアント)として、回答は `message` イベントとしてストリーミングされます。終了シーケンスは実行結果によって異なります:\n- **成功**:`message_end`、続いて `workflow_finished`\n- **失敗**:ステータスが `failed` の `workflow_finished`、続いて `error`。`message_end` は送信されません\n- **一時停止**:`human_input_required`、続いて `workflow_paused`、続いて `message_end`(ストリームはここで終了し、実行は別途再開されます)\n\nテキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message_end` が終了イベントの後に続きます。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。ワークフロー、ノード、人間の入力イベントは、ペイロードを `data` の下にネストし、`agent_log` を除いてトップレベルの `workflow_run_id` を持ちます。\n\n**応答イベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `message` | 回答の各チャンク(順番に連結) | `answer` |\n| `message_replace` | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**ワークフロー・ノードイベント**\n\n各イベントはペイロードを `data` オブジェクトの下にネストします。\n\n| イベント | 発生タイミング | 主な `data` フィールド |\n|:---|:---|:---|\n| `workflow_started` | 実行開始 | `inputs` |\n| `node_started` | ノード開始 | `node_id`、`node_type`、`title` |\n| `node_finished` | ノード終了 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 失敗後にノードを再試行 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | イテレーションノードの進行(情報提供のみ、処理は任意) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | ループノードの進行(情報提供のみ、処理は任意) | `data` |\n| `agent_log` | Agent ノードのステップログ(情報提供のみ、処理は任意、`workflow_run_id` なし) | `data` |\n| `workflow_finished` | 実行終了 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 実行が一時停止 | `paused_nodes`、`reasons` |\n| `human_input_required` | 実行が人間の入力ノードに到達 | `form_token`、`form_content`、`expiration_time` |\n\n一時停止後、このストリームは `message_end` で終了します。[人間の入力フォームを送信](/api-reference/人間の入力/人間の入力フォームを送信) でフォームを送信するか、タイムアウトさせてください。再開後の実行(`human_input_form_filled`/`human_input_form_timeout` から `workflow_finished` までを含む)は、[ワークフローイベントをストリーム](/api-reference/チャットフロー/ワークフローイベントをストリーム) からストリーミングされます。\n\n**トランスポートイベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `error` | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | 10 秒ごとのキープアライブ | なし |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "レスポンス例 - 人間の入力での一時停止", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" } } } @@ -3549,6 +3549,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "メッセージファイルイベント。ツールによって作成された新しいファイルです。", @@ -3573,11 +3576,6 @@ "type": "string", "format": "url", "description": "ファイルのリモート URL。" - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "会話 ID。" } } } @@ -3679,7 +3677,7 @@ }, { "type": "object", - "description": "接続を維持するための Ping イベント。" + "description": "接続を維持するための Ping イベント。`event: ping` 行として送信され、`data:` ペイロードはありません。" } ] }, diff --git a/zh/api-reference/openapi_chat.json b/zh/api-reference/openapi_chat.json index a4eae0bd5..aaa9aa83d 100644 --- a/zh/api-reference/openapi_chat.json +++ b/zh/api-reference/openapi_chat.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "请求成功。内容类型和结构取决于请求中的 `response_mode` 参数。\n\n- 如果 `response_mode` 为 `blocking`,返回 `application/json` 和 `ChatCompletionResponse` 对象。\n- 如果 `response_mode` 为 `streaming`,返回 `text/event-stream` 和 `ChunkChatEvent` 对象流。", + "description": "请求成功。内容类型和结构取决于请求中的 `response_mode` 参数。\n\n- 如果 `response_mode` 为 `blocking`,返回 `application/json` 和 `ChatCompletionResponse` 对象。\n- 如果 `response_mode` 为 `streaming`,返回 `text/event-stream` 和服务器发送事件流。", "content": { "application/json": { "schema": { @@ -137,7 +137,7 @@ }, "streamingResponseAgent": { "summary": "Response Example - Streaming (Agent)", - "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"conversation_id\": \"conv123\"} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" + "value": "data: {\"event\": \"agent_thought\", \"id\": \"agent_thought_id_1\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"position\": 1, \"thought\": \"Thinking about calling a tool...\", \"tool\": \"dalle3\", \"tool_input\": \"{\\\"dalle3\\\": {\\\"prompt\\\": \\\"a cute cat\\\"}}\", \"created_at\": 1705395332} data: {\"event\": \"message_file\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"id\": \"file_id_1\", \"type\": \"image\", \"belongs_to\": \"assistant\", \"url\": \"https://example.com/cat.png\", \"created_at\": 1705395332} data: {\"event\": \"agent_message\", \"task_id\": \"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"answer\": \"Here is the image: \", \"created_at\": 1705395333} data: {\"event\": \"message_end\", \"task_id\":\"task123\", \"message_id\": \"msg123\", \"conversation_id\": \"conv123\", \"metadata\": {\"usage\": {\"total_tokens\": 50, \"latency\": 2.5}}}" } } } @@ -2889,6 +2889,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "消息文件事件,由工具创建的新文件。", @@ -2910,11 +2913,6 @@ "type": "string", "format": "url", "description": "文件的远程 URL。" - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "会话 ID。" } } } @@ -3016,7 +3014,7 @@ }, { "type": "object", - "description": "Ping 事件,用于保持连接活跃。" + "description": "Ping 事件,用于保持连接活跃。以 `event: ping` 行的形式送达,无 `data:` 载荷。" } ] }, diff --git a/zh/api-reference/openapi_chatflow.json b/zh/api-reference/openapi_chatflow.json index 7066251b5..48df8d280 100644 --- a/zh/api-reference/openapi_chatflow.json +++ b/zh/api-reference/openapi_chatflow.json @@ -75,7 +75,7 @@ }, "responses": { "200": { - "description": "请求成功。内容类型和结构取决于请求中的 `response_mode` 参数。\n\n- 如果 `response_mode` 为 `blocking`,返回 `application/json` 和 `ChatCompletionResponse` 对象。\n- 如果 `response_mode` 为 `streaming`,返回 `text/event-stream` 和 `ChunkChatEvent` 对象流。", + "description": "请求成功。内容类型和结构取决于请求中的 `response_mode` 参数。\n\n- 如果 `response_mode` 为 `blocking`,返回 `application/json` 和 `ChatCompletionResponse` 对象。\n- 如果 `response_mode` 为 `streaming`,返回 `text/event-stream` 和服务器发送事件流。", "content": { "application/json": { "schema": { @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:工作流进度以 `workflow_started`、节点事件(`node_started` 和 `node_finished`,以及迭代和循环的相应变体)流式返回,回复则以 `message` 事件返回。结束序列取决于运行结果:\n- **成功**:`message_end`,随后 `workflow_finished`\n- **失败**:`workflow_finished`(状态为 `failed`),随后 `error`;不发送 `message_end`\n- **暂停**:`human_input_required`,随后 `workflow_paused`,随后 `message_end`(流到此结束,运行将另行恢复)\n\n开启文本转语音(TTS)自动播放时,`tts_message_end` 跟随在结束事件之后。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。工作流、节点和人工介入事件还带有顶层 `workflow_run_id`,并将载荷嵌套在 `data` 中。\n\n**回复事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `message` | 每个回答片段(按顺序拼接) | `answer` |\n| `message_replace` | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**工作流与节点事件**\n\n每个事件都带有 `workflow_run_id` 和一个 `data` 对象。\n\n| 事件 | 触发时机 | 关键 `data` 字段 |\n|:---|:---|:---|\n| `workflow_started` | 运行开始 | `inputs` |\n| `node_started` | 节点开始 | `node_id`、`node_type`、`title` |\n| `node_finished` | 节点结束 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 节点失败后重试 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | 迭代节点进度(信息性,可不处理) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | 循环节点进度(信息性,可不处理) | `data` |\n| `agent_log` | Agent 节点步骤日志(信息性,可不处理;无 `workflow_run_id`) | `data` |\n| `workflow_finished` | 运行结束 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 运行暂停 | `paused_nodes`、`reasons` |\n| `human_input_required` | 运行到达人工介入节点 | `form_token`、`form_content`、`expiration_time` |\n\n暂停后,本流在 `message_end` 处结束。通过 [提交人工介入表单](/api-reference/人工介入/提交人工介入表单) 提交表单,或等待其超时;恢复后的运行(包括从 `human_input_form_filled`/`human_input_form_timeout` 到 `workflow_finished` 的事件)由 [流式获取工作流事件](/api-reference/对话流/流式获取工作流事件) 流式返回。\n\n**传输事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `error` | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 每 10 秒保持连接 | 无 |" + "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:工作流进度以 `workflow_started`、节点事件(`node_started` 和 `node_finished`,以及迭代和循环的相应变体)流式返回,回复则以 `message` 事件返回。结束序列取决于运行结果:\n- **成功**:`message_end`,随后 `workflow_finished`\n- **失败**:`workflow_finished`(状态为 `failed`),随后 `error`;不发送 `message_end`\n- **暂停**:`human_input_required`,随后 `workflow_paused`,随后 `message_end`(流到此结束,运行将另行恢复)\n\n开启文本转语音(TTS)自动播放时,`tts_message_end` 跟随在结束事件之后。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。工作流、节点和人工介入事件还将载荷嵌套在 `data` 中,且除 `agent_log` 外都带有顶层 `workflow_run_id`。\n\n**回复事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `message` | 每个回答片段(按顺序拼接) | `answer` |\n| `message_replace` | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**工作流与节点事件**\n\n每个事件都将载荷嵌套在 `data` 对象中。\n\n| 事件 | 触发时机 | 关键 `data` 字段 |\n|:---|:---|:---|\n| `workflow_started` | 运行开始 | `inputs` |\n| `node_started` | 节点开始 | `node_id`、`node_type`、`title` |\n| `node_finished` | 节点结束 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 节点失败后重试 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | 迭代节点进度(信息性,可不处理) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | 循环节点进度(信息性,可不处理) | `data` |\n| `agent_log` | Agent 节点步骤日志(信息性,可不处理;无 `workflow_run_id`) | `data` |\n| `workflow_finished` | 运行结束 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 运行暂停 | `paused_nodes`、`reasons` |\n| `human_input_required` | 运行到达人工介入节点 | `form_token`、`form_content`、`expiration_time` |\n\n暂停后,本流在 `message_end` 处结束。通过 [提交人工介入表单](/api-reference/人工介入/提交人工介入表单) 提交表单,或等待其超时;恢复后的运行(包括从 `human_input_form_filled`/`human_input_form_timeout` 到 `workflow_finished` 的事件)由 [流式获取工作流事件](/api-reference/对话流/流式获取工作流事件) 流式返回。\n\n**传输事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `error` | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 每 10 秒保持连接 | 无 |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "响应示例 - 人工介入暂停", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" } } } @@ -3549,6 +3549,9 @@ { "$ref": "#/components/schemas/ChunkChatEvent" }, + { + "$ref": "#/components/schemas/StreamEventBase" + }, { "type": "object", "description": "消息文件事件,由工具创建的新文件。", @@ -3573,11 +3576,6 @@ "type": "string", "format": "url", "description": "文件的远程 URL。" - }, - "conversation_id": { - "type": "string", - "format": "uuid", - "description": "会话 ID。" } } } @@ -3679,7 +3677,7 @@ }, { "type": "object", - "description": "Ping 事件,用于保持连接活跃。" + "description": "Ping 事件,用于保持连接活跃。以 `event: ping` 行的形式送达,无 `data:` 载荷。" } ] }, From d97b5d0a6e84dc0006025a11bf5d47c4a6b02120 Mon Sep 17 00:00:00 2001 From: RiskeyL <7a8y@163.com> Date: Fri, 29 May 2026 16:38:05 +0800 Subject: [PATCH 3/3] fix: correct streaming SSE event details for chat and chatflow --- en/api-reference/openapi_chat.json | 2 +- en/api-reference/openapi_chatflow.json | 4 ++-- ja/api-reference/openapi_chat.json | 2 +- ja/api-reference/openapi_chatflow.json | 4 ++-- zh/api-reference/openapi_chat.json | 2 +- zh/api-reference/openapi_chatflow.json | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/en/api-reference/openapi_chat.json b/en/api-reference/openapi_chat.json index df89bf5c9..ff1564b72 100644 --- a/en/api-reference/openapi_chat.json +++ b/en/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: The reply streams as `message` events (Chatbot apps), or as `agent_thought` and `agent_message` events (Agent apps), and ends with `message_end`. When text-to-speech auto-play is enabled, `tts_message` events interleave and `tts_message_end` becomes the final event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`.\n\n**Reply events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `message` | Chatbot | each answer chunk (concatenate in order) | `answer` |\n| `agent_message` | Agent | each answer chunk (concatenate in order) | `answer` |\n| `agent_thought` | Agent | each reasoning or tool-call step | `position`, `thought`, `tool`, `tool_input` (JSON), `observation`, `message_files` |\n| `message_replace` | Chatbot, Agent | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | Chatbot, Agent | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | Chatbot, Agent | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | Chatbot, Agent | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Transport events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `error` | Chatbot, Agent | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | Chatbot, Agent | keep-alive every 10 seconds | none |" + "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: The reply streams as `message` events (Chatbot apps), or as `agent_thought` and `agent_message` events (Agent apps), and ends with `message_end`. When text-to-speech auto-play is enabled, `tts_message` events interleave and `tts_message_end` becomes the final event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`.\n\n**Reply events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `message` | Chatbot | each answer chunk (concatenate in order) | `answer` |\n| `agent_message` | Agent | each answer chunk (concatenate in order) | `answer` |\n| `agent_thought` | Agent | each reasoning or tool-call step | `position`, `thought`, `tool`, `tool_input` (JSON), `observation`, `message_files` |\n| `message_replace` | Chatbot, Agent | output moderation replaces the answer so far | `answer` |\n| `message_file` | Chatbot, Agent | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | Chatbot, Agent | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | Chatbot, Agent | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Transport events**\n\n| Event | App | Fires on | Key fields |\n|:---|:---|:---|:---|\n| `error` | Chatbot, Agent | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | Chatbot, Agent | keep-alive every 10 seconds | none |" }, "examples": { "streamingResponseBasic": { diff --git a/en/api-reference/openapi_chatflow.json b/en/api-reference/openapi_chatflow.json index c63d55e93..4728474f2 100644 --- a/en/api-reference/openapi_chatflow.json +++ b/en/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: Workflow progress streams as `workflow_started`, node events (`node_started` and `node_finished`, plus iteration and loop variants), and the reply as `message` events. The closing sequence depends on the outcome:\n- **Success**: `message_end`, then `workflow_finished`\n- **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`\n- **Pause**: `human_input_required`, then `workflow_paused`, then `message_end` (the stream ends here; the run resumes separately)\n\nWhen text-to-speech auto-play is enabled, `tts_message_end` trails the closing event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`. Workflow, node, and human-input events also nest their payload under `data` and, except for `agent_log`, carry a top-level `workflow_run_id`.\n\n**Reply events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `message` | each answer chunk (concatenate in order) | `answer` |\n| `message_replace` | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_file` | the assistant returns a file | `type`, `belongs_to`, `url` |\n| `message_end` | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Workflow and node events**\n\nEach event nests its payload under a `data` object.\n\n| Event | Fires on | Key `data` fields |\n|:---|:---|:---|\n| `workflow_started` | the run begins | `inputs` |\n| `node_started` | a node begins | `node_id`, `node_type`, `title` |\n| `node_finished` | a node ends | `status`, `outputs`, `execution_metadata` |\n| `node_retry` | a node retries after a failure | `retry_index` |\n| `iteration_started`, `iteration_next`, `iteration_completed` | Iteration node progress (informational) | `data` |\n| `loop_started`, `loop_next`, `loop_completed` | Loop node progress (informational) | `data` |\n| `agent_log` | an Agent node step log (informational; no `workflow_run_id`) | `data` |\n| `workflow_finished` | the run ends | `status` (`succeeded`, `failed`, `partial-succeeded`, `stopped`), `outputs`, `total_tokens` |\n| `workflow_paused` | the run pauses | `paused_nodes`, `reasons` |\n| `human_input_required` | the run reaches a Human Input node | `form_token`, `form_content`, `expiration_time` |\n\nAfter a pause this stream ends at `message_end`. Submit the form via [Submit Human Input Form](/api-reference/human-input/submit-human-input-form) or let it time out; the resumed run, including `human_input_form_filled`/`human_input_form_timeout` through `workflow_finished`, streams from [Stream Workflow Events](/api-reference/chatflows/stream-workflow-events).\n\n**Transport events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `error` | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | keep-alive every 10 seconds | none |" + "description": "A stream of Server-Sent Events (SSE).\n\n**Parsing**: Each event is a line prefixed with `data: ` followed by a JSON object, terminated by `\\n\\n`. Strip the `data: ` prefix before parsing the JSON, then read the `event` field to determine the event type. Ignore `ping` events, which arrive as `event: ping` lines (no `data:` payload) every 10 seconds to keep the connection alive.\n\n**Stream lifecycle**: Workflow progress streams as `workflow_started`, node events (`node_started` and `node_finished`, plus iteration and loop variants), and the reply as `message` events. The closing sequence depends on the outcome:\n- **Success**: `message_end`, then `workflow_finished`\n- **Failure**: `workflow_finished` with status `failed`, then `error`; no `message_end`\n- **Pause**: `human_input_required`, then `workflow_paused` (the stream ends here; the run resumes separately)\n\nWhen text-to-speech auto-play is enabled, `tts_message_end` trails the closing event.\n\n**Events**: Apart from `ping`, every event includes `conversation_id`, `message_id`, and `created_at` (Unix epoch seconds); all but `error` also include `task_id`. Workflow, node, and human-input events also nest their payload under `data` and, except for `agent_log`, carry a top-level `workflow_run_id`.\n\n**Reply events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `message` | each answer chunk (concatenate in order) | `answer` |\n| `message_replace` | output moderation replaces the answer so far | `answer`, `reason` |\n| `message_end` | the answer is complete | `metadata` (`usage`, `retriever_resources`) |\n| `tts_message`, `tts_message_end` | audio chunk / end, when TTS auto-play is on | `audio` |\n\n**Workflow and node events**\n\nEach event nests its payload under a `data` object.\n\n| Event | Fires on | Key `data` fields |\n|:---|:---|:---|\n| `workflow_started` | the run begins | `inputs` |\n| `node_started` | a node begins | `node_id`, `node_type`, `title` |\n| `node_finished` | a node ends | `status`, `outputs`, `execution_metadata` |\n| `node_retry` | a node retries after a failure | `retry_index` |\n| `iteration_started`, `iteration_next`, `iteration_completed` | Iteration node progress (informational) | `data` |\n| `loop_started`, `loop_next`, `loop_completed` | Loop node progress (informational) | `data` |\n| `agent_log` | an Agent node step log (informational; no `workflow_run_id`) | `data` |\n| `workflow_finished` | the run ends | `status` (`succeeded`, `failed`, `partial-succeeded`, `stopped`), `outputs`, `total_tokens` |\n| `workflow_paused` | the run pauses | `paused_nodes`, `reasons` |\n| `human_input_required` | the run reaches a Human Input node | `form_token`, `form_content`, `expiration_time` |\n\nAfter a pause this stream ends at `workflow_paused`. Submit the form via [Submit Human Input Form](/api-reference/human-input/submit-human-input-form) or let it time out; the resumed run, including `human_input_form_filled`/`human_input_form_timeout` through `workflow_finished`, streams from [Stream Workflow Events](/api-reference/chatflows/stream-workflow-events).\n\n**Transport events**\n\n| Event | Fires on | Key fields |\n|:---|:---|:---|\n| `error` | a failure ends the stream; HTTP stays `200` | `status` (e.g. `400`), `code` (e.g. `invalid_param`), `message` |\n| `ping` | keep-alive every 10 seconds | none |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "Response Example - Human Input pause", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"paused_nodes\": [\"approval_node\"], \"outputs\": {}, \"reasons\": [{\"TYPE\": \"human_input_required\", \"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"resolved_default_values\": {\"comment\": \"\"}, \"form_token\": \"tok_abc123\", \"expiration_time\": 1705494029}], \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5, \"total_tokens\": 0, \"total_steps\": 1}}" } } } diff --git a/ja/api-reference/openapi_chat.json b/ja/api-reference/openapi_chat.json index d892db442..4e2e6a081 100644 --- a/ja/api-reference/openapi_chat.json +++ b/ja/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:回答は `message` イベント(チャットボットアプリ)、または `agent_thought` と `agent_message` イベント(Agent アプリ)としてストリーミングされ、`message_end` で終了します。テキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message` イベントが間に挟まり、`tts_message_end` が最後のイベントになります。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。\n\n**応答イベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `message` | チャットボット | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_message` | Agent | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_thought` | Agent | 推論またはツール呼び出しの各ステップ | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | チャットボット、Agent | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | チャットボット、Agent | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | チャットボット、Agent | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | チャットボット、Agent | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**トランスポートイベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `error` | チャットボット、Agent | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | チャットボット、Agent | 10 秒ごとのキープアライブ | なし |" + "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:回答は `message` イベント(チャットボットアプリ)、または `agent_thought` と `agent_message` イベント(Agent アプリ)としてストリーミングされ、`message_end` で終了します。テキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message` イベントが間に挟まり、`tts_message_end` が最後のイベントになります。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。\n\n**応答イベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `message` | チャットボット | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_message` | Agent | 回答の各チャンク(順番に連結) | `answer` |\n| `agent_thought` | Agent | 推論またはツール呼び出しの各ステップ | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | チャットボット、Agent | 出力モデレーションがそれまでの回答を置き換える | `answer` |\n| `message_file` | チャットボット、Agent | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | チャットボット、Agent | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | チャットボット、Agent | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**トランスポートイベント**\n\n| イベント | アプリ | 発生タイミング | 主なフィールド |\n|:---|:---|:---|:---|\n| `error` | チャットボット、Agent | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | チャットボット、Agent | 10 秒ごとのキープアライブ | なし |" }, "examples": { "streamingResponseBasic": { diff --git a/ja/api-reference/openapi_chatflow.json b/ja/api-reference/openapi_chatflow.json index 424da1bd5..f16b0badf 100644 --- a/ja/api-reference/openapi_chatflow.json +++ b/ja/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:ワークフローの進行は `workflow_started`、ノードイベント(`node_started` と `node_finished`、およびイテレーションとループの各バリアント)として、回答は `message` イベントとしてストリーミングされます。終了シーケンスは実行結果によって異なります:\n- **成功**:`message_end`、続いて `workflow_finished`\n- **失敗**:ステータスが `failed` の `workflow_finished`、続いて `error`。`message_end` は送信されません\n- **一時停止**:`human_input_required`、続いて `workflow_paused`、続いて `message_end`(ストリームはここで終了し、実行は別途再開されます)\n\nテキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message_end` が終了イベントの後に続きます。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。ワークフロー、ノード、人間の入力イベントは、ペイロードを `data` の下にネストし、`agent_log` を除いてトップレベルの `workflow_run_id` を持ちます。\n\n**応答イベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `message` | 回答の各チャンク(順番に連結) | `answer` |\n| `message_replace` | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_file` | アシスタントがファイルを返す | `type`、`belongs_to`、`url` |\n| `message_end` | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**ワークフロー・ノードイベント**\n\n各イベントはペイロードを `data` オブジェクトの下にネストします。\n\n| イベント | 発生タイミング | 主な `data` フィールド |\n|:---|:---|:---|\n| `workflow_started` | 実行開始 | `inputs` |\n| `node_started` | ノード開始 | `node_id`、`node_type`、`title` |\n| `node_finished` | ノード終了 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 失敗後にノードを再試行 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | イテレーションノードの進行(情報提供のみ、処理は任意) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | ループノードの進行(情報提供のみ、処理は任意) | `data` |\n| `agent_log` | Agent ノードのステップログ(情報提供のみ、処理は任意、`workflow_run_id` なし) | `data` |\n| `workflow_finished` | 実行終了 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 実行が一時停止 | `paused_nodes`、`reasons` |\n| `human_input_required` | 実行が人間の入力ノードに到達 | `form_token`、`form_content`、`expiration_time` |\n\n一時停止後、このストリームは `message_end` で終了します。[人間の入力フォームを送信](/api-reference/人間の入力/人間の入力フォームを送信) でフォームを送信するか、タイムアウトさせてください。再開後の実行(`human_input_form_filled`/`human_input_form_timeout` から `workflow_finished` までを含む)は、[ワークフローイベントをストリーム](/api-reference/チャットフロー/ワークフローイベントをストリーム) からストリーミングされます。\n\n**トランスポートイベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `error` | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | 10 秒ごとのキープアライブ | なし |" + "description": "サーバー送信イベント (SSE) のストリームです。\n\n**パース**:各イベントは `data: ` プレフィックス付きの JSON オブジェクトの行で、`\\n\\n` で終了します。JSON をパースする前に `data: ` プレフィックスを除去し、`event` フィールドを読み取ってイベントタイプを判定してください。`ping` イベントは `event: ping` 行(`data:` ペイロードなし)として 10 秒ごとに接続維持のために送信されるため、無視してください。\n\n**ストリームライフサイクル**:ワークフローの進行は `workflow_started`、ノードイベント(`node_started` と `node_finished`、およびイテレーションとループの各バリアント)として、回答は `message` イベントとしてストリーミングされます。終了シーケンスは実行結果によって異なります:\n- **成功**:`message_end`、続いて `workflow_finished`\n- **失敗**:ステータスが `failed` の `workflow_finished`、続いて `error`。`message_end` は送信されません\n- **一時停止**:`human_input_required`、続いて `workflow_paused`(ストリームはここで終了し、実行は別途再開されます)\n\nテキスト読み上げ(TTS)の自動再生が有効な場合、`tts_message_end` が終了イベントの後に続きます。\n\n**イベント**:`ping` を除き、すべてのイベントには `conversation_id`、`message_id`、`created_at`(Unix エポック秒)が含まれます。`error` を除くイベントには `task_id` も含まれます。ワークフロー、ノード、人間の入力イベントは、ペイロードを `data` の下にネストし、`agent_log` を除いてトップレベルの `workflow_run_id` を持ちます。\n\n**応答イベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `message` | 回答の各チャンク(順番に連結) | `answer` |\n| `message_replace` | 出力モデレーションがそれまでの回答を置き換える | `answer`、`reason` |\n| `message_end` | 回答が完了 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音声チャンク/終了(TTS 自動再生が有効な場合) | `audio` |\n\n**ワークフロー・ノードイベント**\n\n各イベントはペイロードを `data` オブジェクトの下にネストします。\n\n| イベント | 発生タイミング | 主な `data` フィールド |\n|:---|:---|:---|\n| `workflow_started` | 実行開始 | `inputs` |\n| `node_started` | ノード開始 | `node_id`、`node_type`、`title` |\n| `node_finished` | ノード終了 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 失敗後にノードを再試行 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | イテレーションノードの進行(情報提供のみ、処理は任意) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | ループノードの進行(情報提供のみ、処理は任意) | `data` |\n| `agent_log` | Agent ノードのステップログ(情報提供のみ、処理は任意、`workflow_run_id` なし) | `data` |\n| `workflow_finished` | 実行終了 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 実行が一時停止 | `paused_nodes`、`reasons` |\n| `human_input_required` | 実行が人間の入力ノードに到達 | `form_token`、`form_content`、`expiration_time` |\n\n一時停止後、このストリームは `workflow_paused` で終了します。[人間の入力フォームを送信](/api-reference/人間の入力/人間の入力フォームを送信) でフォームを送信するか、タイムアウトさせてください。再開後の実行(`human_input_form_filled`/`human_input_form_timeout` から `workflow_finished` までを含む)は、[ワークフローイベントをストリーム](/api-reference/チャットフロー/ワークフローイベントをストリーム) からストリーミングされます。\n\n**トランスポートイベント**\n\n| イベント | 発生タイミング | 主なフィールド |\n|:---|:---|:---|\n| `error` | 失敗によりストリームが終了。HTTP は `200` のまま | `status`(例:`400`)、`code`(例:`invalid_param`)、`message` |\n| `ping` | 10 秒ごとのキープアライブ | なし |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "レスポンス例 - 人間の入力での一時停止", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"paused_nodes\": [\"approval_node\"], \"outputs\": {}, \"reasons\": [{\"TYPE\": \"human_input_required\", \"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"resolved_default_values\": {\"comment\": \"\"}, \"form_token\": \"tok_abc123\", \"expiration_time\": 1705494029}], \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5, \"total_tokens\": 0, \"total_steps\": 1}}" } } } diff --git a/zh/api-reference/openapi_chat.json b/zh/api-reference/openapi_chat.json index aaa9aa83d..61487eb18 100644 --- a/zh/api-reference/openapi_chat.json +++ b/zh/api-reference/openapi_chat.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:回复以 `message` 事件(聊天助手应用)或 `agent_thought` 与 `agent_message` 事件(Agent 应用)的形式流式返回,并以 `message_end` 结束。开启文本转语音(TTS)自动播放时,`tts_message` 事件会穿插其间,`tts_message_end` 成为最后一个事件。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。\n\n**回复事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `message` | 聊天助手 | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_message` | Agent | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_thought` | Agent | 每个推理或工具调用步骤 | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | 聊天助手、Agent | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 聊天助手、Agent | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 聊天助手、Agent | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 聊天助手、Agent | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**传输事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `error` | 聊天助手、Agent | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 聊天助手、Agent | 每 10 秒保持连接 | 无 |" + "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:回复以 `message` 事件(聊天助手应用)或 `agent_thought` 与 `agent_message` 事件(Agent 应用)的形式流式返回,并以 `message_end` 结束。开启文本转语音(TTS)自动播放时,`tts_message` 事件会穿插其间,`tts_message_end` 成为最后一个事件。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。\n\n**回复事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `message` | 聊天助手 | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_message` | Agent | 每个回答片段(按顺序拼接) | `answer` |\n| `agent_thought` | Agent | 每个推理或工具调用步骤 | `position`、`thought`、`tool`、`tool_input`(JSON)、`observation`、`message_files` |\n| `message_replace` | 聊天助手、Agent | 内容审核替换已生成的回答 | `answer` |\n| `message_file` | 聊天助手、Agent | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 聊天助手、Agent | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 聊天助手、Agent | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**传输事件**\n\n| 事件 | 应用 | 触发时机 | 关键字段 |\n|:---|:---|:---|:---|\n| `error` | 聊天助手、Agent | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 聊天助手、Agent | 每 10 秒保持连接 | 无 |" }, "examples": { "streamingResponseBasic": { diff --git a/zh/api-reference/openapi_chatflow.json b/zh/api-reference/openapi_chatflow.json index 48df8d280..824a79b40 100644 --- a/zh/api-reference/openapi_chatflow.json +++ b/zh/api-reference/openapi_chatflow.json @@ -128,7 +128,7 @@ "text/event-stream": { "schema": { "type": "string", - "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:工作流进度以 `workflow_started`、节点事件(`node_started` 和 `node_finished`,以及迭代和循环的相应变体)流式返回,回复则以 `message` 事件返回。结束序列取决于运行结果:\n- **成功**:`message_end`,随后 `workflow_finished`\n- **失败**:`workflow_finished`(状态为 `failed`),随后 `error`;不发送 `message_end`\n- **暂停**:`human_input_required`,随后 `workflow_paused`,随后 `message_end`(流到此结束,运行将另行恢复)\n\n开启文本转语音(TTS)自动播放时,`tts_message_end` 跟随在结束事件之后。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。工作流、节点和人工介入事件还将载荷嵌套在 `data` 中,且除 `agent_log` 外都带有顶层 `workflow_run_id`。\n\n**回复事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `message` | 每个回答片段(按顺序拼接) | `answer` |\n| `message_replace` | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_file` | 助手返回文件 | `type`、`belongs_to`、`url` |\n| `message_end` | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**工作流与节点事件**\n\n每个事件都将载荷嵌套在 `data` 对象中。\n\n| 事件 | 触发时机 | 关键 `data` 字段 |\n|:---|:---|:---|\n| `workflow_started` | 运行开始 | `inputs` |\n| `node_started` | 节点开始 | `node_id`、`node_type`、`title` |\n| `node_finished` | 节点结束 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 节点失败后重试 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | 迭代节点进度(信息性,可不处理) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | 循环节点进度(信息性,可不处理) | `data` |\n| `agent_log` | Agent 节点步骤日志(信息性,可不处理;无 `workflow_run_id`) | `data` |\n| `workflow_finished` | 运行结束 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 运行暂停 | `paused_nodes`、`reasons` |\n| `human_input_required` | 运行到达人工介入节点 | `form_token`、`form_content`、`expiration_time` |\n\n暂停后,本流在 `message_end` 处结束。通过 [提交人工介入表单](/api-reference/人工介入/提交人工介入表单) 提交表单,或等待其超时;恢复后的运行(包括从 `human_input_form_filled`/`human_input_form_timeout` 到 `workflow_finished` 的事件)由 [流式获取工作流事件](/api-reference/对话流/流式获取工作流事件) 流式返回。\n\n**传输事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `error` | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 每 10 秒保持连接 | 无 |" + "description": "服务器发送事件 (SSE) 流。\n\n**解析**:每个事件是一行以 `data: ` 为前缀的 JSON 对象,以 `\\n\\n` 终止。解析 JSON 前先去除 `data: ` 前缀,再读取 `event` 字段确定事件类型。忽略 `ping` 事件,它以 `event: ping` 行的形式(无 `data:` 载荷)每 10 秒发送一次以保持连接活跃。\n\n**流生命周期**:工作流进度以 `workflow_started`、节点事件(`node_started` 和 `node_finished`,以及迭代和循环的相应变体)流式返回,回复则以 `message` 事件返回。结束序列取决于运行结果:\n- **成功**:`message_end`,随后 `workflow_finished`\n- **失败**:`workflow_finished`(状态为 `failed`),随后 `error`;不发送 `message_end`\n- **暂停**:`human_input_required`,随后 `workflow_paused`(流到此结束,运行将另行恢复)\n\n开启文本转语音(TTS)自动播放时,`tts_message_end` 跟随在结束事件之后。\n\n**事件**:除 `ping` 外,每个事件都包含 `conversation_id`、`message_id` 和 `created_at`(Unix 纪元秒);除 `error` 外,其余事件还包含 `task_id`。工作流、节点和人工介入事件还将载荷嵌套在 `data` 中,且除 `agent_log` 外都带有顶层 `workflow_run_id`。\n\n**回复事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `message` | 每个回答片段(按顺序拼接) | `answer` |\n| `message_replace` | 内容审核替换已生成的回答 | `answer`、`reason` |\n| `message_end` | 回答完成 | `metadata`(`usage`、`retriever_resources`) |\n| `tts_message`、`tts_message_end` | 音频片段/结束,开启 TTS 自动播放时 | `audio` |\n\n**工作流与节点事件**\n\n每个事件都将载荷嵌套在 `data` 对象中。\n\n| 事件 | 触发时机 | 关键 `data` 字段 |\n|:---|:---|:---|\n| `workflow_started` | 运行开始 | `inputs` |\n| `node_started` | 节点开始 | `node_id`、`node_type`、`title` |\n| `node_finished` | 节点结束 | `status`、`outputs`、`execution_metadata` |\n| `node_retry` | 节点失败后重试 | `retry_index` |\n| `iteration_started`、`iteration_next`、`iteration_completed` | 迭代节点进度(信息性,可不处理) | `data` |\n| `loop_started`、`loop_next`、`loop_completed` | 循环节点进度(信息性,可不处理) | `data` |\n| `agent_log` | Agent 节点步骤日志(信息性,可不处理;无 `workflow_run_id`) | `data` |\n| `workflow_finished` | 运行结束 | `status`(`succeeded`、`failed`、`partial-succeeded`、`stopped`)、`outputs`、`total_tokens` |\n| `workflow_paused` | 运行暂停 | `paused_nodes`、`reasons` |\n| `human_input_required` | 运行到达人工介入节点 | `form_token`、`form_content`、`expiration_time` |\n\n暂停后,本流在 `workflow_paused` 处结束。通过 [提交人工介入表单](/api-reference/人工介入/提交人工介入表单) 提交表单,或等待其超时;恢复后的运行(包括从 `human_input_form_filled`/`human_input_form_timeout` 到 `workflow_finished` 的事件)由 [流式获取工作流事件](/api-reference/对话流/流式获取工作流事件) 流式返回。\n\n**传输事件**\n\n| 事件 | 触发时机 | 关键字段 |\n|:---|:---|:---|\n| `error` | 失败导致流结束;HTTP 仍为 `200` | `status`(如 `400`)、`code`(如 `invalid_param`)、`message` |\n| `ping` | 每 10 秒保持连接 | 无 |" }, "examples": { "streamingResponseBasic": { @@ -141,7 +141,7 @@ }, "humanInputPause": { "summary": "响应示例 - 人工介入暂停", - "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5}} data: {\"event\": \"message_end\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"metadata\": {}}" + "value": "data: {\"event\": \"workflow_started\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"workflow_id\": \"7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345\", \"inputs\": {\"draft\": \"Hello\"}, \"created_at\": 1705407629, \"reason\": \"initial\"}} data: {\"event\": \"human_input_required\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_token\": \"tok_abc123\", \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"display_in_ui\": false, \"resolved_default_values\": {\"comment\": \"\"}, \"expiration_time\": 1705494029}} data: {\"event\": \"workflow_paused\", \"task_id\": \"c3800678-a077-43df-a102-53f23ed20b88\", \"message_id\": \"2e4f6a8b-1c3d-5e7f-9a0b-2c4d6e8f0a1b\", \"conversation_id\": \"9d3a2f1b-6c7d-4e8f-a0b1-c2d3e4f5a6b7\", \"created_at\": 1705407629, \"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"data\": {\"workflow_run_id\": \"fb47b2e6-5e43-4f90-be01-d5c5a088d156\", \"paused_nodes\": [\"approval_node\"], \"outputs\": {}, \"reasons\": [{\"TYPE\": \"human_input_required\", \"form_id\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\", \"form_content\": \"Please review the draft.\", \"inputs\": [{\"type\": \"text_input\", \"output_variable_name\": \"comment\", \"default\": null}], \"actions\": [{\"id\": \"approve\", \"title\": \"Approve\", \"button_style\": \"primary\"}], \"node_id\": \"approval_node\", \"node_title\": \"Approval\", \"resolved_default_values\": {\"comment\": \"\"}, \"form_token\": \"tok_abc123\", \"expiration_time\": 1705494029}], \"status\": \"paused\", \"created_at\": 1705407629, \"elapsed_time\": 0.5, \"total_tokens\": 0, \"total_steps\": 1}}" } } }