From 59d403318112a96cb666b4fb4ac6555379af562d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=98=BC?= <33648082+LibraTang@users.noreply.github.com> Date: Tue, 22 Sep 2026 19:33:31 +0800 Subject: [PATCH 1/2] docs: add QCA Realtime integration recipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 如昼 <33648082+LibraTang@users.noreply.github.com> --- .../recipes/integrate-qca-realtime/index.md | 295 ++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 content/zh-CN/recipes/integrate-qca-realtime/index.md diff --git a/content/zh-CN/recipes/integrate-qca-realtime/index.md b/content/zh-CN/recipes/integrate-qca-realtime/index.md new file mode 100644 index 0000000..c95a273 --- /dev/null +++ b/content/zh-CN/recipes/integrate-qca-realtime/index.md @@ -0,0 +1,295 @@ +--- +schema_version: 1 +slug: integrate-qca-realtime +title: 为 Web 应用接入 QCA Realtime +summary: 为 Web 应用接入 QCA Realtime,完成会话创建、WebSocket 连接、音频收发、任务反馈及断线恢复。 +type: recipe +category: build-deploy +tags: + - forward + - multimodal + - event-stream + - background-task +author: + name: 如昼 +locale: zh-CN +source_url: https://mp.weixin.qq.com/s/xqGxH3dbtGfcgOSx51z8dw +--- + +## 目标与适用场景 + +本文介绍如何为已有 Forward Template 的 Web 应用接入实时语音: + +- 语音 Agent 负责交互与结果讲解。 +- 任务 Agent 使用 Template 的工具和运行环境执行任务。 + +| 概念 | 用途 | +| --- | --- | +| Identity | 应用用户在 Forward 中的身份,创建 Conversation 时关联 | +| Template | 任务 Agent 的模型、指令、工具和运行环境配置 | +| Conversation | 可再次连接的语音对话,应用应保存其 ID | +| Work | 对话中委派的后台任务,通过 `work.*` 事件反馈进度与结果 | + +浏览器通过应用服务端创建对话、收发实时事件,服务端负责上游鉴权: + +```mermaid +sequenceDiagram + participant B as 浏览器 + participant S as 应用服务端 + participant R as QCA Realtime + participant A as 任务 Agent + B->>S: 开始对话 + S->>R: 创建 Conversation + R-->>S: 返回 conversation_id + S-->>B: 返回 conversation_id + B->>S: 建立应用 WebSocket + S->>R: 携带 Bearer Token 建立上游连接 + R-->>S: voice.ready + S-->>B: voice.ready + B->>S: 文字或音频 + S->>R: 转发输入 + R->>A: 按需委派任务 + A-->>R: 执行进展与结果 + R-->>S: 字幕、音频和 Work 事件 + S-->>B: 转发事件 +``` + +开始前准备: + +- 凭据与资源:同一环境下的 PAT 或 SAT、Identity、Template;Service Account Key 须先换取 SAT。 +- 执行环境:Template 已配置工具权限和运行环境,并能完成目标任务。 +- 应用环境:服务端支持 WebSocket,浏览器支持麦克风和 Web Audio,部署页面使用 HTTPS。 +- 示例工具:curl 和 Node.js;应用服务端不限语言。 + +Realtime 处于 Beta。模型、沙箱及工具调用按实际计费规则收费。 + +## 操作步骤 + +[官方 Quickstart](https://github.com/QoderAI/forward-quickstart) 提供完整接入示例。 + +### 第一步:创建 Conversation + +由应用服务端创建 Conversation。以下 curl 展示请求格式,将占位值替换为实际凭据和资源 ID: + +```bash +export QODER_ACCESS_TOKEN="" +export IDENTITY_ID="" +export TEMPLATE_ID="