qwen-audio-agent 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/PRIVACY.md +34 -0
- package/README.md +282 -0
- package/README_EN.md +316 -0
- package/SECURITY.md +32 -0
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/cli/bin/qwenaudio.mjs +10 -0
- package/cli/package.json +13 -0
- package/cli/src/arguments.mjs +247 -0
- package/cli/src/gateway-service.mjs +386 -0
- package/cli/src/instance-lock.mjs +65 -0
- package/cli/src/launcher.mjs +217 -0
- package/cli/src/runtime.mjs +356 -0
- package/cli/src/webui.mjs +61 -0
- package/config/acp/workspace/AGENTS.md +13 -0
- package/config/codebuddy/workspace/.codebuddy/models.json +19 -0
- package/config/codebuddy/workspace/AGENTS.md +13 -0
- package/config/codex/workspace/AGENTS.md +13 -0
- package/config/frontend-agent/PROMPT.md +127 -0
- package/config/hermes/workspace/AGENTS.md +13 -0
- package/config/openclaw/openclaw.json5 +50 -0
- package/config/openclaw/workspace/AGENTS.md +9 -0
- package/config/opencode/agents/qwen-audio-agent-backend.md +65 -0
- package/config/opencode/workspace/AGENTS.md +16 -0
- package/config/qoder/workspace/AGENTS.md +16 -0
- package/docs/architecture-overview-en.png +0 -0
- package/docs/architecture-overview.png +0 -0
- package/docs/architecture.md +332 -0
- package/docs/configuration.md +386 -0
- package/docs/desktop-fluid-orb-thinking.gif +0 -0
- package/docs/desktop-goo-orb-thinking.gif +0 -0
- package/docs/qwen-audio-agent-three-layer-architecture-en.png +0 -0
- package/docs/qwen-audio-agent-three-layer-architecture.png +0 -0
- package/package.json +126 -0
- package/scripts/audit-dependencies.mjs +109 -0
- package/scripts/check-desktop-release-env.mjs +41 -0
- package/scripts/codex-acp +58 -0
- package/scripts/install-global.mjs +66 -0
- package/scripts/openclaw +194 -0
- package/scripts/openclaw-gateway +8 -0
- package/scripts/opencode-acp +6 -0
- package/scripts/opencode-server +179 -0
- package/scripts/prepare-build.mjs +38 -0
- package/scripts/release-check +182 -0
- package/scripts/set-version.mjs +133 -0
- package/scripts/start.mjs +43 -0
- package/scripts/verify-package.mjs +109 -0
- package/server/package.json +18 -0
- package/server/src/agent/acp-backend-adapter.mjs +1138 -0
- package/server/src/agent/acp-backend-profile.mjs +35 -0
- package/server/src/agent/acp-backend-session-utils.mjs +139 -0
- package/server/src/agent/acp-process-client.mjs +447 -0
- package/server/src/agent/acp-session-registry.mjs +106 -0
- package/server/src/agent/acp-session-tools.mjs +257 -0
- package/server/src/agent/agent-client.mjs +218 -0
- package/server/src/agent/backend-adapter.mjs +15 -0
- package/server/src/agent/backend-agent-instructions.mjs +8 -0
- package/server/src/agent/backends/codebuddy.mjs +47 -0
- package/server/src/agent/backends/codex.mjs +62 -0
- package/server/src/agent/backends/generic-acp.mjs +46 -0
- package/server/src/agent/backends/hermes.mjs +29 -0
- package/server/src/agent/backends/openclaw.mjs +101 -0
- package/server/src/agent/backends/opencode.mjs +36 -0
- package/server/src/agent/backends/qoder.mjs +47 -0
- package/server/src/agent/backends/registry.mjs +32 -0
- package/server/src/agent/backends/shared.mjs +46 -0
- package/server/src/agent/coordinator.mjs +308 -0
- package/server/src/agent/openclaw-adapter.mjs +245 -0
- package/server/src/app/bootstrap.mjs +244 -0
- package/server/src/conversation/conversation-sync.mjs +183 -0
- package/server/src/conversation/frontend-agent-context.mjs +162 -0
- package/server/src/conversation/frontend-memory.mjs +328 -0
- package/server/src/conversation/profiled-memory-store.mjs +87 -0
- package/server/src/conversation/task-result-projector.mjs +18 -0
- package/server/src/conversation/user-profile.mjs +234 -0
- package/server/src/core/config.mjs +388 -0
- package/server/src/core/identity.mjs +93 -0
- package/server/src/core/install-paths.mjs +8 -0
- package/server/src/core/package-version.mjs +10 -0
- package/server/src/core/request-security.mjs +80 -0
- package/server/src/index.mjs +67 -0
- package/server/src/process/backend-drivers/codebuddy.mjs +15 -0
- package/server/src/process/backend-drivers/codex.mjs +15 -0
- package/server/src/process/backend-drivers/generic-acp.mjs +18 -0
- package/server/src/process/backend-drivers/hermes.mjs +15 -0
- package/server/src/process/backend-drivers/openclaw.mjs +35 -0
- package/server/src/process/backend-drivers/opencode.mjs +75 -0
- package/server/src/process/backend-drivers/qoder.mjs +15 -0
- package/server/src/process/backend-drivers/registry.mjs +24 -0
- package/server/src/process/backend-drivers/shared.mjs +46 -0
- package/server/src/process/managed-backend.mjs +188 -0
- package/server/src/task/task-manager.mjs +704 -0
- package/server/src/task/task-scheduler.mjs +44 -0
- package/server/src/task/task-store.mjs +167 -0
- package/server/src/voice/active-voice-clients.mjs +58 -0
- package/server/src/voice/announcement/announcement-manager.mjs +402 -0
- package/server/src/voice/announcement/announcement-window.mjs +89 -0
- package/server/src/voice/input-transcript.mjs +9 -0
- package/server/src/voice/realtime-errors.mjs +6 -0
- package/server/src/voice/realtime-gateway.mjs +1366 -0
- package/server/src/voice/realtime-provider.mjs +771 -0
- package/server/src/voice/reconnect-backoff.mjs +30 -0
- package/server/src/voice/response-context.mjs +41 -0
- package/server/src/voice/session-permission-policy.mjs +56 -0
- package/server/src/voice/tools/tool-call-handler.mjs +823 -0
- package/server/src/voice/tools/turn-transcripts.mjs +59 -0
- package/server/src/voice/turn-correlation.mjs +41 -0
- package/shared/backend-catalog.mjs +56 -0
- package/shared/gateway-client.mjs +13 -0
- package/shared/realtime-events.mjs +55 -0
- package/shared/runtime-environment.mjs +422 -0
- package/tui/native/macos-voice-io.swift +552 -0
- package/tui/native/portaudio-voice-io.py +240 -0
- package/tui/package.json +13 -0
- package/tui/src/index.mjs +1217 -0
- package/tui/src/macos-voice-io.mjs +186 -0
- package/tui/src/portaudio-voice-io.mjs +158 -0
- package/web/dist/assets/index-BeamDvsE.js +38 -0
- package/web/dist/assets/index-BuB0EFih.css +1 -0
- package/web/dist/index.html +14 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import WebSocket from 'ws'
|
|
2
|
+
import { randomUUID } from 'crypto'
|
|
3
|
+
import { config, realtimeUrl } from '../core/config.mjs'
|
|
4
|
+
import {
|
|
5
|
+
buildFrontendContext,
|
|
6
|
+
loadFrontendPrompt,
|
|
7
|
+
} from '../conversation/frontend-agent-context.mjs'
|
|
8
|
+
|
|
9
|
+
export const SPAWN_THINKING_TOOL_NAME = 'spawn_thinking'
|
|
10
|
+
export const DELEGATE_TOOL_NAME = SPAWN_THINKING_TOOL_NAME
|
|
11
|
+
export const CANCEL_AGENT_TASK_TOOL_NAME = 'cancel_agent_task'
|
|
12
|
+
export const GET_AGENT_TASK_STATUS_TOOL_NAME = 'get_agent_task_status'
|
|
13
|
+
export const GET_CURRENT_TIME_TOOL_NAME = 'get_current_time'
|
|
14
|
+
export const USER_MEMORY_TOOL_NAME = 'user_memory'
|
|
15
|
+
export const RESPOND_AGENT_PERMISSION_TOOL_NAME = 'respond_agent_permission'
|
|
16
|
+
|
|
17
|
+
const delegateTool = {
|
|
18
|
+
type: 'function',
|
|
19
|
+
function: {
|
|
20
|
+
name: DELEGATE_TOOL_NAME,
|
|
21
|
+
description: '把明确的新执行或调查要求交给后台 Agent。需要当前信息、搜索、检查、工具、文件、屏幕、应用、代码、创作,或要求继续、修改已有工作时调用;询问此前工作的状态、进度、阶段产物或已经发现了什么统一改用 get_agent_task_status。缺少不可推断的核心目标时先问一个必要问题。可以按需先说一句具体行动预告,不要使用“好的、收到”等通用承接语。返回 accepted 只表示已受理;结合本轮已有发言判断是否还需回应,不重复确认或声称完成。',
|
|
22
|
+
parameters: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
objective: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: '必须是已经可以执行的目标,忠实保留本轮用户要求并写明对象、动作、约束和期望结果,不得用“待用户说明主题”等占位内容启动空执行。仅在当前对话已经明确时消解“它、刚才那个”等指代;不要猜测或补造事实。后台 Agent 会同时收到近期对话和后台执行状态,因此这里是意图交接,不是对历史的替代。',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['objective'],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cancelAgentTaskTool = {
|
|
37
|
+
type: 'function',
|
|
38
|
+
function: {
|
|
39
|
+
name: CANCEL_AGENT_TASK_TOOL_NAME,
|
|
40
|
+
description: '取消用户此前交给后台、目前仍在排队或执行的工作。用户明确说取消、停止、别做了、不要继续,或要求取消“刚才那个任务”时必须调用,不要只口头说忽略结果。能够从运行上下文确定 work_id 时传入;用户泛指刚才的工作时可省略,系统会取消最近提交且仍活跃的工作。',
|
|
41
|
+
parameters: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
work_id: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: '要取消的 work_id。仅在运行上下文已明确给出时填写;不得猜造。省略则取消当前语音会话最近提交且仍活跃的工作。',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const getAgentTaskStatusTool = {
|
|
55
|
+
type: 'function',
|
|
56
|
+
function: {
|
|
57
|
+
name: GET_AGENT_TASK_STATUS_TOOL_NAME,
|
|
58
|
+
description: '查询此前交给后台工作的状态、进度或阶段性结果。用户询问“刚才那个怎么样了、还在做吗、做到哪一步、已经发现了什么、是否完成”时统一调用,不要自行判断普通任务或第三层任务,也不要改用 spawn_thinking。系统会直接回答普通任务,并自动查询第三层任务。能够从运行上下文确定 work_id 时传入;省略时查询当前语音会话最近的工作。',
|
|
59
|
+
parameters: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
work_id: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
description: '要查询的 work_id。仅在运行上下文已明确给出时填写,不得猜造;省略则查询当前语音会话最近的工作。',
|
|
65
|
+
},
|
|
66
|
+
question: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
description: '用户本轮对任务状态、进度或阶段结果的原始问题。尽量忠实保留,不要自行改写成另一项任务;省略时系统会使用本轮语音转写。',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const getCurrentTimeTool = {
|
|
77
|
+
type: 'function',
|
|
78
|
+
function: {
|
|
79
|
+
name: GET_CURRENT_TIME_TOOL_NAME,
|
|
80
|
+
description: '获取用户本地时区中的准确当前日期、时间和星期。用户询问当前时间、今天日期、星期或相对日期判断时调用;不用于创建提醒。',
|
|
81
|
+
parameters: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {},
|
|
84
|
+
additionalProperties: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const userMemoryTool = {
|
|
90
|
+
type: 'function',
|
|
91
|
+
function: {
|
|
92
|
+
name: USER_MEMORY_TOOL_NAME,
|
|
93
|
+
description: '管理千问Audio前台持有的用户记忆。profile 用于称呼、时区、语言和稳定交互偏好;long_term 用于用户明确希望跨会话保留的个人事实、喜好、目标和约定;不要保存项目执行历史或后台工作细节。使用 recall 回忆,remember 新增,replace 用新事实替换明确相关的旧记录,forget 遗忘。',
|
|
94
|
+
parameters: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
action: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
enum: ['recall', 'remember', 'replace', 'forget'],
|
|
100
|
+
description: '要执行的记忆操作。',
|
|
101
|
+
},
|
|
102
|
+
scope: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
enum: ['profile', 'long_term', 'all'],
|
|
105
|
+
description: '记忆范围。remember 和 replace 必须使用 profile 或 long_term;recall 和 forget 可以使用 all。',
|
|
106
|
+
},
|
|
107
|
+
content: {
|
|
108
|
+
type: 'string',
|
|
109
|
+
description: 'remember 或 replace 时要保存的完整、简洁事实。',
|
|
110
|
+
},
|
|
111
|
+
query: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
description: 'recall 或 forget 时用于匹配记忆的自然语言查询。',
|
|
114
|
+
},
|
|
115
|
+
memory_ids: {
|
|
116
|
+
type: 'array',
|
|
117
|
+
items: { type: 'string' },
|
|
118
|
+
maxItems: 20,
|
|
119
|
+
description: 'replace 时要被新事实取代的旧记忆 ID;必须来自本轮 recall 结果,不得猜造。',
|
|
120
|
+
},
|
|
121
|
+
all: {
|
|
122
|
+
type: 'boolean',
|
|
123
|
+
description: '仅用于 forget;用户明确要求清空所选范围时设为 true。',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
required: ['action', 'scope'],
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const respondAgentPermissionTool = {
|
|
133
|
+
type: 'function',
|
|
134
|
+
function: {
|
|
135
|
+
name: RESPOND_AGENT_PERMISSION_TOOL_NAME,
|
|
136
|
+
description: '回复当前正在等待用户决定的后台权限请求。由你结合刚提出的具体权限问题和用户本轮原话,智能判断为本会话自动允许、拒绝或尚不明确;不要依赖固定关键词。若刚问的是“是否允许并在本次会话中自动允许后续操作”,用户回答“可以”“行”“好”“允许”“同意”“没问题”等自然肯定表达就是明确同意,应调用 always,不得要求复述固定口令。明确拒绝时调用 reject,不明确时不要调用并继续询问。必须逐字引用本轮用户原话中的证据,不得只口头声称已授权。',
|
|
137
|
+
parameters: {
|
|
138
|
+
type: 'object',
|
|
139
|
+
properties: {
|
|
140
|
+
authorization_id: {
|
|
141
|
+
type: 'string',
|
|
142
|
+
description: '待确认请求的 authorization_id,必须来自当前运行上下文,不得猜造。',
|
|
143
|
+
},
|
|
144
|
+
decision: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
enum: ['always', 'reject'],
|
|
147
|
+
description: 'always 表示允许当前操作,并由 Gateway 在本次前台会话中自动允许后续权限请求;reject 表示拒绝当前操作,后续请求仍继续询问。',
|
|
148
|
+
},
|
|
149
|
+
evidence: {
|
|
150
|
+
type: 'string',
|
|
151
|
+
description: '从本轮用户原话中逐字复制、直接支撑该决定的最短片段;不得改写、概括或补造。',
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
required: ['authorization_id', 'decision', 'evidence'],
|
|
155
|
+
additionalProperties: false,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const TOOLS = [
|
|
161
|
+
delegateTool,
|
|
162
|
+
cancelAgentTaskTool,
|
|
163
|
+
getAgentTaskStatusTool,
|
|
164
|
+
getCurrentTimeTool,
|
|
165
|
+
userMemoryTool,
|
|
166
|
+
respondAgentPermissionTool,
|
|
167
|
+
]
|
|
168
|
+
|
|
169
|
+
const resultResponseInstructions = [
|
|
170
|
+
'这是先前提交工作的最终结果,不是用户的新请求。',
|
|
171
|
+
'把 result 当作事实材料,结合当前对话自然回应;可以按语境概括、合并、承接或询问必要信息,避免重复已经表达过的内容。',
|
|
172
|
+
'输入包含多个 event 时,必须覆盖每个 event 的实质结果;不得只说其中一个,也不得让过程性或状态性内容掩盖真正完成的工作。',
|
|
173
|
+
'开头直接说实际结果、关键发现、阻塞或必要问题,不用“好的、收到、任务完成了”等空泛承接语。',
|
|
174
|
+
'不要朗读协议前缀、字段、执行 ID、路径、URL 或不适合口语的长内容。',
|
|
175
|
+
'不要调用工具,不要添加事件中没有的事实,也不要把未完成说成完成。',
|
|
176
|
+
].join(' ')
|
|
177
|
+
|
|
178
|
+
function speakResponseInstructions(content) {
|
|
179
|
+
return `请以自然口语传达下面的信息,保持事实一致,不调用工具:\n${content}`
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const permissionResponseInstructions = [
|
|
183
|
+
'这是后台 Agent 提交的权限确认请求,不是用户的新指令。',
|
|
184
|
+
'用一句自然、清楚的话说明后台想做的操作,并询问用户是否允许。',
|
|
185
|
+
'必须明确告诉用户:同意后,本次前台会话的后续权限请求会自动允许,不再逐项询问。',
|
|
186
|
+
'不要替用户决定,不要调用工具;等待用户下一轮明确回答。',
|
|
187
|
+
'不要朗读 authorization_id、Session ID 或协议字段。',
|
|
188
|
+
].join(' ')
|
|
189
|
+
|
|
190
|
+
export function buildFrontendInstructions(agentContext = {}) {
|
|
191
|
+
return `${loadFrontendPrompt()}\n\n${buildFrontendContext(agentContext)}`
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function responseId(event) {
|
|
195
|
+
return event.response_id || event.response?.id || ''
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function eventId() {
|
|
199
|
+
return `event_${randomUUID().replaceAll('-', '')}`
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const dashscopeRealtimeProvider = {
|
|
203
|
+
key: 'dashscope',
|
|
204
|
+
label: 'Qwen-Audio-Realtime',
|
|
205
|
+
model: () => config.audioModel,
|
|
206
|
+
voice: () => config.audioVoice,
|
|
207
|
+
inputSampleRate: 16000,
|
|
208
|
+
apiKey: () => config.dashscopeApiKey,
|
|
209
|
+
missingKeyMessage: '请先配置 DASHSCOPE_API_KEY',
|
|
210
|
+
connectTimeoutMessage: '连接 Qwen Audio Realtime 超时',
|
|
211
|
+
url: () => realtimeUrl(config.audioRealtimeBaseUrl, config.audioModel),
|
|
212
|
+
headers: apiKey => ({ Authorization: `Bearer ${apiKey}` }),
|
|
213
|
+
buildSession: ({ configured, agentContext }) => {
|
|
214
|
+
const textOnly = agentContext?.textOnly === true
|
|
215
|
+
const session = {
|
|
216
|
+
instructions: buildFrontendInstructions(agentContext),
|
|
217
|
+
tools: TOOLS,
|
|
218
|
+
}
|
|
219
|
+
if (!configured) {
|
|
220
|
+
session.modalities = textOnly ? ['text'] : ['text', 'audio']
|
|
221
|
+
session.voice = config.audioVoice
|
|
222
|
+
session.input_audio_format = 'pcm'
|
|
223
|
+
session.output_audio_format = 'pcm'
|
|
224
|
+
session.turn_detection = textOnly ? null : { type: 'smart_turn' }
|
|
225
|
+
}
|
|
226
|
+
return session
|
|
227
|
+
},
|
|
228
|
+
buildSpeakResponse: (content, { textOnly = false } = {}) => ({
|
|
229
|
+
conversation: 'none',
|
|
230
|
+
modalities: textOnly ? ['text'] : ['text', 'audio'],
|
|
231
|
+
instructions: speakResponseInstructions(content),
|
|
232
|
+
}),
|
|
233
|
+
buildResultInjection: (content, { textOnly = false } = {}) => ({
|
|
234
|
+
item: {
|
|
235
|
+
type: 'message',
|
|
236
|
+
role: 'user',
|
|
237
|
+
content: [{ type: 'input_text', text: content }],
|
|
238
|
+
},
|
|
239
|
+
response: {
|
|
240
|
+
modalities: textOnly ? ['text'] : ['text', 'audio'],
|
|
241
|
+
tool_choice: 'none',
|
|
242
|
+
instructions: resultResponseInstructions,
|
|
243
|
+
},
|
|
244
|
+
}),
|
|
245
|
+
buildPermissionInjection: (permission, { textOnly = false } = {}) => ({
|
|
246
|
+
item: {
|
|
247
|
+
type: 'message',
|
|
248
|
+
role: 'user',
|
|
249
|
+
content: [{
|
|
250
|
+
type: 'input_text',
|
|
251
|
+
text: [
|
|
252
|
+
'<backend_permission_request>',
|
|
253
|
+
`authorization_id=${permission.id}`,
|
|
254
|
+
`operation=${permission.summary}`,
|
|
255
|
+
'</backend_permission_request>',
|
|
256
|
+
].join('\n'),
|
|
257
|
+
}],
|
|
258
|
+
},
|
|
259
|
+
response: {
|
|
260
|
+
modalities: textOnly ? ['text'] : ['text', 'audio'],
|
|
261
|
+
tool_choice: 'none',
|
|
262
|
+
instructions: permissionResponseInstructions,
|
|
263
|
+
},
|
|
264
|
+
}),
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export const REALTIME_PROVIDERS = {
|
|
268
|
+
dashscope: dashscopeRealtimeProvider,
|
|
269
|
+
// Compatibility alias for internal callers while provider selection moves
|
|
270
|
+
// to stable external names.
|
|
271
|
+
qwen: dashscopeRealtimeProvider,
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function resolveRealtimeProvider() {
|
|
275
|
+
const provider = REALTIME_PROVIDERS[
|
|
276
|
+
config.audioProvider === 'qwen' ? 'dashscope' : config.audioProvider
|
|
277
|
+
]
|
|
278
|
+
if (!provider) {
|
|
279
|
+
throw new Error(`不支持的 Realtime 供应商:${config.audioProvider}`)
|
|
280
|
+
}
|
|
281
|
+
return provider
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function describeActiveRealtime() {
|
|
285
|
+
const provider = resolveRealtimeProvider()
|
|
286
|
+
return {
|
|
287
|
+
provider: provider.key,
|
|
288
|
+
label: provider.label,
|
|
289
|
+
model: provider.model(),
|
|
290
|
+
voice: provider.voice(),
|
|
291
|
+
inputSampleRate: provider.inputSampleRate,
|
|
292
|
+
configured: Boolean(provider.apiKey()),
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export class RealtimeFrontend {
|
|
297
|
+
constructor({
|
|
298
|
+
provider = resolveRealtimeProvider(),
|
|
299
|
+
onEvent,
|
|
300
|
+
onError,
|
|
301
|
+
onClose,
|
|
302
|
+
agentContext = {},
|
|
303
|
+
responseStartTimeoutMs = 30000,
|
|
304
|
+
responseCompletionTimeoutMs = 120000,
|
|
305
|
+
} = {}) {
|
|
306
|
+
this.provider = provider
|
|
307
|
+
this.onEvent = onEvent
|
|
308
|
+
this.onError = onError
|
|
309
|
+
this.onClose = onClose
|
|
310
|
+
this.agentContext = agentContext
|
|
311
|
+
this.ws = null
|
|
312
|
+
this.ready = false
|
|
313
|
+
this.sessionConfigured = false
|
|
314
|
+
this.activeResponses = new Set()
|
|
315
|
+
this.pendingResponses = []
|
|
316
|
+
this.responseWaiters = new Map()
|
|
317
|
+
this.conversationItemWaiters = new Map()
|
|
318
|
+
this.idleWaiters = []
|
|
319
|
+
this.outputQueue = Promise.resolve()
|
|
320
|
+
this.responseQueueGeneration = 0
|
|
321
|
+
this.responseStartTimeoutMs = responseStartTimeoutMs
|
|
322
|
+
this.responseCompletionTimeoutMs = responseCompletionTimeoutMs
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
connect() {
|
|
326
|
+
const apiKey = this.provider.apiKey()
|
|
327
|
+
if (!apiKey) return Promise.reject(new Error(this.provider.missingKeyMessage))
|
|
328
|
+
return new Promise((resolve, reject) => {
|
|
329
|
+
const ws = new WebSocket(this.provider.url(), {
|
|
330
|
+
headers: this.provider.headers(apiKey),
|
|
331
|
+
})
|
|
332
|
+
this.ws = ws
|
|
333
|
+
let settled = false
|
|
334
|
+
const timeout = setTimeout(() => {
|
|
335
|
+
const error = new Error(this.provider.connectTimeoutMessage)
|
|
336
|
+
finish(error)
|
|
337
|
+
ws.terminate()
|
|
338
|
+
}, 25000)
|
|
339
|
+
const finish = error => {
|
|
340
|
+
if (settled) return
|
|
341
|
+
settled = true
|
|
342
|
+
clearTimeout(timeout)
|
|
343
|
+
if (error) reject(error)
|
|
344
|
+
else resolve()
|
|
345
|
+
}
|
|
346
|
+
ws.on('error', error => {
|
|
347
|
+
this.onError?.(error)
|
|
348
|
+
finish(error)
|
|
349
|
+
})
|
|
350
|
+
ws.on('close', () => {
|
|
351
|
+
this.ready = false
|
|
352
|
+
this.sessionConfigured = false
|
|
353
|
+
this.resetResponses()
|
|
354
|
+
finish(new Error(`${this.provider.label} 连接已关闭`))
|
|
355
|
+
this.onClose?.()
|
|
356
|
+
})
|
|
357
|
+
ws.on('message', raw => {
|
|
358
|
+
let event
|
|
359
|
+
try {
|
|
360
|
+
event = JSON.parse(raw.toString())
|
|
361
|
+
} catch {
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
if (event.type === 'session.created') this.updateSession()
|
|
365
|
+
if (event.type === 'session.updated') {
|
|
366
|
+
this.ready = true
|
|
367
|
+
this.sessionConfigured = true
|
|
368
|
+
finish()
|
|
369
|
+
}
|
|
370
|
+
this.handleLifecycle(event)
|
|
371
|
+
this.onEvent?.(event)
|
|
372
|
+
})
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
updateSession() {
|
|
377
|
+
const session = this.provider.buildSession({
|
|
378
|
+
configured: this.sessionConfigured,
|
|
379
|
+
agentContext: this.agentContext,
|
|
380
|
+
})
|
|
381
|
+
this.send({ type: 'session.update', session })
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
updateAgentContext(patch = {}) {
|
|
385
|
+
this.agentContext = { ...this.agentContext, ...patch }
|
|
386
|
+
if (!this.ready) return
|
|
387
|
+
const refresh = async () => {
|
|
388
|
+
await this.whenIdle()
|
|
389
|
+
if (this.ready) this.updateSession()
|
|
390
|
+
}
|
|
391
|
+
this.outputQueue = this.outputQueue.then(refresh, refresh)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
appendAudio(audio) {
|
|
395
|
+
this.send({ type: 'input_audio_buffer.append', audio })
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
sendUserText(text, context = {}, { modalities } = {}) {
|
|
399
|
+
const content = String(text || '').trim()
|
|
400
|
+
if (!content) return Promise.resolve()
|
|
401
|
+
return this.enqueueResponse('model', context, async () => {
|
|
402
|
+
await this.createConversationItem({
|
|
403
|
+
type: 'message',
|
|
404
|
+
role: 'user',
|
|
405
|
+
content: [{ type: 'input_text', text: content }],
|
|
406
|
+
})
|
|
407
|
+
this.send({
|
|
408
|
+
type: 'response.create',
|
|
409
|
+
...(modalities ? { response: { modalities } } : {}),
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
ensureResponse(context = {}, { shouldCreate } = {}) {
|
|
415
|
+
return this.enqueueResponse('agent', context, () => {
|
|
416
|
+
if (shouldCreate && !shouldCreate()) return false
|
|
417
|
+
this.send({ type: 'response.create' })
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
sendFunctionOutput(callId, output, context = {}, {
|
|
422
|
+
createResponse = true,
|
|
423
|
+
response,
|
|
424
|
+
} = {}) {
|
|
425
|
+
const sendOutput = () => this.createConversationItem({
|
|
426
|
+
type: 'function_call_output',
|
|
427
|
+
call_id: callId,
|
|
428
|
+
output: JSON.stringify(output),
|
|
429
|
+
})
|
|
430
|
+
if (!createResponse) return this.enqueueAction(sendOutput)
|
|
431
|
+
return this.enqueueResponse('agent', context, async () => {
|
|
432
|
+
await sendOutput()
|
|
433
|
+
this.send({
|
|
434
|
+
type: 'response.create',
|
|
435
|
+
...(response ? { response } : {}),
|
|
436
|
+
})
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
createConversationItem(item) {
|
|
441
|
+
const id = item.id || `item_${randomUUID().replaceAll('-', '')}`
|
|
442
|
+
return new Promise((resolve, reject) => {
|
|
443
|
+
const waiter = {
|
|
444
|
+
id,
|
|
445
|
+
resolve,
|
|
446
|
+
reject,
|
|
447
|
+
timer: setTimeout(() => {
|
|
448
|
+
if (this.conversationItemWaiters.get(id) !== waiter) return
|
|
449
|
+
this.conversationItemWaiters.delete(id)
|
|
450
|
+
reject(new Error(`Qwen 未确认对话项 ${id}`))
|
|
451
|
+
}, this.responseStartTimeoutMs),
|
|
452
|
+
}
|
|
453
|
+
this.conversationItemWaiters.set(id, waiter)
|
|
454
|
+
this.send({
|
|
455
|
+
type: 'conversation.item.create',
|
|
456
|
+
item: { id, ...item },
|
|
457
|
+
})
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
speak(text, origin = 'agent', context = {}, {
|
|
462
|
+
shouldSpeak,
|
|
463
|
+
} = {}) {
|
|
464
|
+
const content = String(text || '').trim()
|
|
465
|
+
if (!content) return Promise.resolve()
|
|
466
|
+
return this.enqueueResponse(origin, context, () => {
|
|
467
|
+
if (shouldSpeak && !shouldSpeak()) return false
|
|
468
|
+
this.send({
|
|
469
|
+
type: 'response.create',
|
|
470
|
+
response: this.provider.buildSpeakResponse(content, {
|
|
471
|
+
textOnly: this.agentContext.textOnly === true,
|
|
472
|
+
}),
|
|
473
|
+
})
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async injectResult(
|
|
478
|
+
text,
|
|
479
|
+
origin = 'announcement',
|
|
480
|
+
context = {},
|
|
481
|
+
{ injectContext = true } = {},
|
|
482
|
+
) {
|
|
483
|
+
const content = String(text || '').trim()
|
|
484
|
+
if (!content) return
|
|
485
|
+
const injection = this.provider.buildResultInjection(content, {
|
|
486
|
+
textOnly: this.agentContext.textOnly === true,
|
|
487
|
+
})
|
|
488
|
+
let contextInjected = false
|
|
489
|
+
const outcome = await this.enqueueResponse(origin, context, async () => {
|
|
490
|
+
if (injectContext) {
|
|
491
|
+
await this.createConversationItem(injection.item)
|
|
492
|
+
contextInjected = true
|
|
493
|
+
}
|
|
494
|
+
this.send({
|
|
495
|
+
type: 'response.create',
|
|
496
|
+
response: injection.response,
|
|
497
|
+
})
|
|
498
|
+
})
|
|
499
|
+
return {
|
|
500
|
+
...(outcome || {}),
|
|
501
|
+
contextInjected,
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
async injectPermission(permission, context = {}, {
|
|
506
|
+
shouldSpeak,
|
|
507
|
+
} = {}) {
|
|
508
|
+
if (!permission?.id || !permission?.summary) return
|
|
509
|
+
const injection = this.provider.buildPermissionInjection(permission, {
|
|
510
|
+
textOnly: this.agentContext.textOnly === true,
|
|
511
|
+
})
|
|
512
|
+
// Make the permission identity available to the model immediately. The
|
|
513
|
+
// spoken question may wait behind an active response, while the user can
|
|
514
|
+
// already see the actionable permission event in TUI/WebUI and answer it.
|
|
515
|
+
await this.createConversationItem(injection.item)
|
|
516
|
+
return this.enqueueResponse('permission', context, pending => {
|
|
517
|
+
if (pending.settled || (shouldSpeak && !shouldSpeak())) return false
|
|
518
|
+
this.send({
|
|
519
|
+
type: 'response.create',
|
|
520
|
+
response: injection.response,
|
|
521
|
+
})
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
cancel() {
|
|
526
|
+
this.responseQueueGeneration += 1
|
|
527
|
+
const hasResponse = this.activeResponses.size || this.pendingResponses.length
|
|
528
|
+
this.pendingResponses.forEach(item => {
|
|
529
|
+
this.settlePending(item, { cancelled: true, phase: 'start' })
|
|
530
|
+
})
|
|
531
|
+
this.pendingResponses = []
|
|
532
|
+
this.rejectConversationItemWaiters(new Error('Realtime 请求已取消'))
|
|
533
|
+
if (hasResponse) this.send({ type: 'response.cancel' })
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
cancelResponses(predicate) {
|
|
537
|
+
const matches = pending => {
|
|
538
|
+
try {
|
|
539
|
+
return predicate?.(pending.context, pending.origin) === true
|
|
540
|
+
} catch {
|
|
541
|
+
return false
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const retained = []
|
|
545
|
+
for (const pending of this.pendingResponses) {
|
|
546
|
+
if (!matches(pending)) {
|
|
547
|
+
retained.push(pending)
|
|
548
|
+
continue
|
|
549
|
+
}
|
|
550
|
+
this.settlePending(pending, { cancelled: true, phase: 'start' })
|
|
551
|
+
}
|
|
552
|
+
this.pendingResponses = retained
|
|
553
|
+
let cancelledActive = false
|
|
554
|
+
for (const pending of this.responseWaiters.values()) {
|
|
555
|
+
if (!matches(pending)) continue
|
|
556
|
+
cancelledActive = true
|
|
557
|
+
this.settlePending(pending, {
|
|
558
|
+
cancelled: true,
|
|
559
|
+
phase: 'completion',
|
|
560
|
+
})
|
|
561
|
+
}
|
|
562
|
+
if (cancelledActive) this.send({ type: 'response.cancel' })
|
|
563
|
+
return cancelledActive
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
enqueueAction(action) {
|
|
567
|
+
const generation = this.responseQueueGeneration
|
|
568
|
+
const run = async () => {
|
|
569
|
+
await this.whenIdle()
|
|
570
|
+
if (!this.ready || generation !== this.responseQueueGeneration) return
|
|
571
|
+
await action()
|
|
572
|
+
}
|
|
573
|
+
this.outputQueue = this.outputQueue.then(run, run)
|
|
574
|
+
return this.outputQueue
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
enqueueResponse(origin, context, create) {
|
|
578
|
+
const generation = this.responseQueueGeneration
|
|
579
|
+
const run = async () => {
|
|
580
|
+
await this.whenIdle()
|
|
581
|
+
if (!this.ready || generation !== this.responseQueueGeneration) return
|
|
582
|
+
let resolveOutcome
|
|
583
|
+
const outcome = new Promise(resolve => {
|
|
584
|
+
resolveOutcome = resolve
|
|
585
|
+
})
|
|
586
|
+
const pending = {
|
|
587
|
+
origin,
|
|
588
|
+
context,
|
|
589
|
+
resolve: resolveOutcome,
|
|
590
|
+
settled: false,
|
|
591
|
+
timer: null,
|
|
592
|
+
}
|
|
593
|
+
if (this.pendingResponses.length) {
|
|
594
|
+
const error = new Error(
|
|
595
|
+
'Realtime 响应关联冲突:已有响应正在等待 response.created',
|
|
596
|
+
)
|
|
597
|
+
this.settlePending(pending, {
|
|
598
|
+
failed: true,
|
|
599
|
+
phase: 'correlation',
|
|
600
|
+
error: error.message,
|
|
601
|
+
})
|
|
602
|
+
this.onError?.(error)
|
|
603
|
+
return outcome
|
|
604
|
+
}
|
|
605
|
+
this.pendingResponses.push(pending)
|
|
606
|
+
try {
|
|
607
|
+
const created = await create(pending)
|
|
608
|
+
if (created === false) {
|
|
609
|
+
const index = this.pendingResponses.indexOf(pending)
|
|
610
|
+
if (index >= 0) this.pendingResponses.splice(index, 1)
|
|
611
|
+
this.settlePending(pending, {
|
|
612
|
+
skipped: true,
|
|
613
|
+
phase: 'deduplicated',
|
|
614
|
+
})
|
|
615
|
+
return outcome
|
|
616
|
+
}
|
|
617
|
+
} catch (error) {
|
|
618
|
+
const index = this.pendingResponses.indexOf(pending)
|
|
619
|
+
if (index >= 0) this.pendingResponses.splice(index, 1)
|
|
620
|
+
this.settlePending(pending, {
|
|
621
|
+
failed: true,
|
|
622
|
+
phase: 'input',
|
|
623
|
+
error: error.message,
|
|
624
|
+
})
|
|
625
|
+
if (!error.realtimeEvent) this.onError?.(error)
|
|
626
|
+
return outcome
|
|
627
|
+
}
|
|
628
|
+
if (!pending.settled) {
|
|
629
|
+
pending.timer = setTimeout(() => {
|
|
630
|
+
const index = this.pendingResponses.indexOf(pending)
|
|
631
|
+
if (index >= 0) this.pendingResponses.splice(index, 1)
|
|
632
|
+
this.settlePending(pending, { timedOut: true, phase: 'start' })
|
|
633
|
+
}, this.responseStartTimeoutMs)
|
|
634
|
+
}
|
|
635
|
+
return outcome
|
|
636
|
+
}
|
|
637
|
+
this.outputQueue = this.outputQueue.then(run, run)
|
|
638
|
+
return this.outputQueue
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
handleLifecycle(event) {
|
|
642
|
+
if (event.type === 'conversation.item.created') {
|
|
643
|
+
const id = event.item?.id
|
|
644
|
+
const waiter = this.conversationItemWaiters.get(id)
|
|
645
|
+
if (waiter) {
|
|
646
|
+
clearTimeout(waiter.timer)
|
|
647
|
+
this.conversationItemWaiters.delete(id)
|
|
648
|
+
waiter.resolve(event.item)
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (event.type === 'error' && this.conversationItemWaiters.size) {
|
|
652
|
+
const waiter = this.conversationItemWaiters.values().next().value
|
|
653
|
+
clearTimeout(waiter.timer)
|
|
654
|
+
this.conversationItemWaiters.delete(waiter.id)
|
|
655
|
+
const error = new Error(event.error?.message || 'Qwen 创建对话项失败')
|
|
656
|
+
error.realtimeEvent = true
|
|
657
|
+
waiter.reject(error)
|
|
658
|
+
return
|
|
659
|
+
}
|
|
660
|
+
if (event.type === 'response.created') {
|
|
661
|
+
const id = responseId(event)
|
|
662
|
+
const pending = this.pendingResponses.shift()
|
|
663
|
+
clearTimeout(pending?.timer)
|
|
664
|
+
event.__voiceOrigin = pending?.origin || 'model'
|
|
665
|
+
event.__voiceContext = pending?.context || {}
|
|
666
|
+
if (id) {
|
|
667
|
+
this.activeResponses.add(id)
|
|
668
|
+
if (pending) {
|
|
669
|
+
pending.timer = setTimeout(() => {
|
|
670
|
+
if (this.responseWaiters.get(id) !== pending) return
|
|
671
|
+
this.send({ type: 'response.cancel' })
|
|
672
|
+
this.settlePending(pending, {
|
|
673
|
+
timedOut: true,
|
|
674
|
+
phase: 'completion',
|
|
675
|
+
responseId: id,
|
|
676
|
+
})
|
|
677
|
+
const recoveryTimer = setTimeout(() => {
|
|
678
|
+
if (this.responseWaiters.get(id) !== pending) return
|
|
679
|
+
this.responseWaiters.delete(id)
|
|
680
|
+
this.activeResponses.delete(id)
|
|
681
|
+
this.resolveIdle()
|
|
682
|
+
}, 1000)
|
|
683
|
+
recoveryTimer.unref?.()
|
|
684
|
+
}, this.responseCompletionTimeoutMs)
|
|
685
|
+
this.responseWaiters.set(id, pending)
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (event.type === 'response.done' || event.type === 'error') {
|
|
690
|
+
let id = responseId(event)
|
|
691
|
+
let pending = this.responseWaiters.get(id)
|
|
692
|
+
if (event.type === 'error' && !pending && !id && this.pendingResponses.length) {
|
|
693
|
+
pending = this.pendingResponses.shift()
|
|
694
|
+
}
|
|
695
|
+
if (event.type === 'error' && !pending && this.responseWaiters.size === 1) {
|
|
696
|
+
const first = this.responseWaiters.entries().next().value
|
|
697
|
+
id = first[0]
|
|
698
|
+
pending = first[1]
|
|
699
|
+
}
|
|
700
|
+
event.__voiceOrigin = pending?.origin || event.__voiceOrigin
|
|
701
|
+
event.__voiceContext = pending?.context || event.__voiceContext || {}
|
|
702
|
+
if (id) {
|
|
703
|
+
this.activeResponses.delete(id)
|
|
704
|
+
this.responseWaiters.delete(id)
|
|
705
|
+
}
|
|
706
|
+
const status = event.response?.status
|
|
707
|
+
const completed = event.type === 'response.done'
|
|
708
|
+
&& !['failed', 'cancelled', 'incomplete'].includes(status)
|
|
709
|
+
this.settlePending(pending, completed
|
|
710
|
+
? { completed: true, responseId: id }
|
|
711
|
+
: { failed: true, responseId: id, status })
|
|
712
|
+
this.resolveIdle()
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
settlePending(pending, outcome) {
|
|
717
|
+
if (!pending || pending.settled) return
|
|
718
|
+
pending.settled = true
|
|
719
|
+
clearTimeout(pending.timer)
|
|
720
|
+
pending.resolve(outcome)
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
whenIdle() {
|
|
724
|
+
if (!this.activeResponses.size) return Promise.resolve()
|
|
725
|
+
return new Promise(resolve => this.idleWaiters.push(resolve))
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
resolveIdle() {
|
|
729
|
+
if (this.activeResponses.size) return
|
|
730
|
+
while (this.idleWaiters.length) this.idleWaiters.shift()?.()
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
resetResponses() {
|
|
734
|
+
this.responseQueueGeneration += 1
|
|
735
|
+
this.activeResponses.clear()
|
|
736
|
+
this.rejectConversationItemWaiters(new Error('Realtime 会话已重置'))
|
|
737
|
+
this.pendingResponses.forEach(item => this.settlePending(item, { cancelled: true }))
|
|
738
|
+
this.responseWaiters.forEach(item => this.settlePending(item, { cancelled: true }))
|
|
739
|
+
this.pendingResponses = []
|
|
740
|
+
this.responseWaiters.clear()
|
|
741
|
+
this.resolveIdle()
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
rejectConversationItemWaiters(error) {
|
|
745
|
+
this.conversationItemWaiters.forEach(waiter => {
|
|
746
|
+
clearTimeout(waiter.timer)
|
|
747
|
+
waiter.reject(error)
|
|
748
|
+
})
|
|
749
|
+
this.conversationItemWaiters.clear()
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
close() {
|
|
753
|
+
this.ws?.close()
|
|
754
|
+
this.ws = null
|
|
755
|
+
this.ready = false
|
|
756
|
+
this.resetResponses()
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
send(payload) {
|
|
760
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
761
|
+
this.ws.send(JSON.stringify({
|
|
762
|
+
event_id: eventId(),
|
|
763
|
+
...payload,
|
|
764
|
+
}))
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export function createRealtimeFrontend(options = {}) {
|
|
770
|
+
return new RealtimeFrontend({ ...options, provider: resolveRealtimeProvider() })
|
|
771
|
+
}
|