@mgamadeus/ddd-agents 0.5.17 → 0.6.1
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/README.md +162 -6
- package/boundary.json +13 -0
- package/dist/chat.js +148 -773
- package/dist/chat.js.map +1 -1
- package/dist/chunks/{canvas-title-slot-context-DK4sfhkl.js → ConversationMarkdown-BsCjyhj4.js} +14 -43
- package/dist/chunks/ConversationMarkdown-BsCjyhj4.js.map +1 -0
- package/dist/chunks/{ConversationMessageInputComposerWidgets-B3Zf69rD.js → ConversationMessageInputComposerWidgets-CE8LpyXY.js} +10 -37
- package/dist/chunks/ConversationMessageInputComposerWidgets-CE8LpyXY.js.map +1 -0
- package/dist/chunks/VoiceBarsIcon-BIcURsBF.js +643 -0
- package/dist/chunks/VoiceBarsIcon-BIcURsBF.js.map +1 -0
- package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js → WebSearchResultsConversationWidget-DXhfSikV.js} +2 -2
- package/dist/chunks/{WebSearchResultsConversationWidget-887v8Wen.js.map → WebSearchResultsConversationWidget-DXhfSikV.js.map} +1 -1
- package/dist/chunks/{browser-request-interception-BdKjYz31.js → browser-request-interception-BnzFbH0m.js} +2 -2
- package/dist/chunks/{browser-request-interception-BdKjYz31.js.map → browser-request-interception-BnzFbH0m.js.map} +1 -1
- package/dist/chunks/{canvas-reducers-CwFA3rQ6.js → canvas-reducers-D-YxAR4B.js} +2 -2
- package/dist/chunks/{canvas-reducers-CwFA3rQ6.js.map → canvas-reducers-D-YxAR4B.js.map} +1 -1
- package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js +36 -0
- package/dist/chunks/canvas-title-slot-context-D6UXrkdJ.js.map +1 -0
- package/dist/chunks/{canvasBodies-C7qqThc9.js → canvasBodies-CQEBkIVw.js} +4 -4
- package/dist/chunks/{canvasBodies-C7qqThc9.js.map → canvasBodies-CQEBkIVw.js.map} +1 -1
- package/dist/chunks/{canvasStorage-i2wKVSBf.js → canvasStorage-BbEI3h-8.js} +2 -2
- package/dist/chunks/{canvasStorage-i2wKVSBf.js.map → canvasStorage-BbEI3h-8.js.map} +1 -1
- package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js +10 -0
- package/dist/chunks/format-agent-voice-call-duration-C-3hRc9p.js.map +1 -0
- package/dist/chunks/{link-navigation-CNX8Am2L.js → link-navigation-BUcy5qWW.js} +2 -2
- package/dist/chunks/{link-navigation-CNX8Am2L.js.map → link-navigation-BUcy5qWW.js.map} +1 -1
- package/dist/chunks/{realtime-arrival-BTLE3jjt.js → realtime-arrival-BfsAPwqQ.js} +8 -3
- package/dist/chunks/realtime-arrival-BfsAPwqQ.js.map +1 -0
- package/dist/chunks/use-agents-chat-store-CuIkCz9v.js +34 -0
- package/dist/chunks/use-agents-chat-store-CuIkCz9v.js.map +1 -0
- package/dist/chunks/{widget-name-resolver-BVEuAsW5.js → widget-name-resolver-B9k-s_cF.js} +3 -3
- package/dist/chunks/{widget-name-resolver-BVEuAsW5.js.map → widget-name-resolver-B9k-s_cF.js.map} +1 -1
- package/dist/chunks/withPollingChangeSubscription-CnQnubfK.js.map +1 -1
- package/dist/client-testing.js +4 -4
- package/dist/client.js +14 -3
- package/dist/client.js.map +1 -1
- package/dist/files/i18n-keys.json +1128 -100
- package/dist/image-render.js +7 -7
- package/dist/index.js +6 -6
- package/dist/kit.js +2 -2
- package/dist/preview.js +7 -7
- package/dist/provider.js +1 -1
- package/dist/renderer.js +25 -24
- package/dist/renderer.js.map +1 -1
- package/dist/styles.css +531 -93
- package/dist/types/client/AgentsConversationClient.d.ts +4 -1
- package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +2 -1
- package/dist/types/entries/voice-admin.d.ts +7 -0
- package/dist/types/entries/voice.d.ts +24 -0
- package/dist/types/ui/account-realtime.d.ts +50 -11
- package/dist/types/voice/AgentVoiceCallBand/AgentVoiceCallBand.d.ts +49 -0
- package/dist/types/voice/AgentVoiceCallBand/agent-voice-call-outcome-title-text-key.d.ts +8 -0
- package/dist/types/voice/AgentVoiceCallCaptions/AgentVoiceCallCaptions.d.ts +15 -0
- package/dist/types/voice/AgentVoiceCallCaptions/saved-messages-of-agent-voice-chat.d.ts +12 -0
- package/dist/types/voice/AgentVoiceCallProvider/AgentVoiceCallProvider.d.ts +21 -0
- package/dist/types/voice/AgentVoiceCallProvider/agent-voice-call-context.d.ts +17 -0
- package/dist/types/voice/AgentVoiceChatStartButton/AgentVoiceChatStartButton.d.ts +15 -0
- package/dist/types/voice/AgentVoiceIcons/AgentVoiceIcons.d.ts +10 -0
- package/dist/types/voice/AgentVoiceIncomingCall/AgentVoiceIncomingCall.d.ts +28 -0
- package/dist/types/voice/AgentVoiceInputGlow/AgentVoiceInputGlow.d.ts +11 -0
- package/dist/types/voice/AgentVoiceInputGlow/agent-voice-input-glow-voice.d.ts +8 -0
- package/dist/types/voice/admin/AgentVoiceCallConversationLink/AgentVoiceCallConversationLink.d.ts +10 -0
- package/dist/types/voice/admin/AgentVoiceCallDetailScreen/AgentVoiceCallDetailScreen.d.ts +27 -0
- package/dist/types/voice/admin/AgentVoiceCallStateBadges/AgentVoiceCallStateBadges.d.ts +12 -0
- package/dist/types/voice/admin/AgentVoiceCallsScreen/AgentVoiceCallsScreen.d.ts +33 -0
- package/dist/types/voice/admin/agent-voice-admin-api.d.ts +59 -0
- package/dist/types/voice/admin/agent-voice-admin-format.d.ts +39 -0
- package/dist/types/voice/admin/agent-voice-admin-types.d.ts +114 -0
- package/dist/types/voice/agent-voice-api.d.ts +114 -0
- package/dist/types/voice/call/agent-voice-call-elapsed-seconds.d.ts +6 -0
- package/dist/types/voice/call/agent-voice-call-end-reasons.d.ts +3 -0
- package/dist/types/voice/call/agent-voice-call-store.d.ts +111 -0
- package/dist/types/voice/call/agent-voice-call-turn.d.ts +4 -0
- package/dist/types/voice/call/build-unsaved-agent-voice-call-lines.d.ts +14 -0
- package/dist/types/voice/call/format-agent-voice-call-duration.d.ts +2 -0
- package/dist/types/voice/call/use-agent-voice-call-elapsed-seconds.d.ts +3 -0
- package/dist/types/voice/call/use-agent-voice-call-server-end.d.ts +15 -0
- package/dist/types/voice/call/use-agent-voice-call.d.ts +12 -0
- package/dist/types/voice/call/use-follow-agent-voice-call-conversation.d.ts +9 -0
- package/dist/types/voice/ring/agent-voice-caller-label.d.ts +21 -0
- package/dist/types/voice/ring/agent-voice-incoming-ring-list.d.ts +10 -0
- package/dist/types/voice/ring/agent-voice-incoming-ring-store.d.ts +47 -0
- package/dist/types/voice/ring/agent-voice-ring-source.d.ts +60 -0
- package/dist/types/voice/ring/agent-voice-ring.d.ts +35 -0
- package/dist/types/voice/ring/answer-incoming-agent-voice-call.d.ts +13 -0
- package/dist/types/voice/ring/use-agent-voice-incoming-rings.d.ts +14 -0
- package/dist/types/voice/ring/use-agent-voice-ring-tone.d.ts +6 -0
- package/dist/ui.js +82 -19
- package/dist/ui.js.map +1 -1
- package/dist/voice-admin.js +738 -0
- package/dist/voice-admin.js.map +1 -0
- package/dist/voice.js +1568 -0
- package/dist/voice.js.map +1 -0
- package/dist/widgets.js +4 -4
- package/package.json +27 -1
- package/public-api.json +155 -0
- package/dist/chunks/ConversationMessageInputComposerWidgets-B3Zf69rD.js.map +0 -1
- package/dist/chunks/canvas-title-slot-context-DK4sfhkl.js.map +0 -1
- package/dist/chunks/realtime-arrival-BTLE3jjt.js.map +0 -1
package/dist/voice.js
ADDED
|
@@ -0,0 +1,1568 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore, useState, useEffect, useMemo, useRef, useCallback, createContext, useContext, useId } from "react";
|
|
3
|
+
import { t as textKey } from "./chunks/text-key-DnoZ4lAk.js";
|
|
4
|
+
import { f as formatAgentVoiceCallDuration } from "./chunks/format-agent-voice-call-duration-C-3hRc9p.js";
|
|
5
|
+
import { a as useOptionalAgentsConversationClient } from "./chunks/AgentsConversationClientContext-C4T7g_Qk.js";
|
|
6
|
+
import { c as DEFAULT_AGENTS_TEXTS, ab as useAgentsTexts, K as getAgentDisplayName } from "./chunks/link-navigation-BUcy5qWW.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { V as VoiceBarsIcon, C as ConversationMessageWidgets, a as ConversationMessageUser } from "./chunks/VoiceBarsIcon-BIcURsBF.js";
|
|
9
|
+
import { a as useOptionalAgentsChatStore, u as useAgentsChatSelector } from "./chunks/use-agents-chat-store-CuIkCz9v.js";
|
|
10
|
+
class AgentVoiceApiError extends Error {
|
|
11
|
+
constructor(code, httpStatus) {
|
|
12
|
+
super(code);
|
|
13
|
+
this.name = "AgentVoiceApiError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.httpStatus = httpStatus;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const readString = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
19
|
+
const readAgentVoiceErrorCode = (failure) => {
|
|
20
|
+
if (typeof failure !== "object" || failure === null) return void 0;
|
|
21
|
+
const failureFields = failure;
|
|
22
|
+
const errorBody = typeof failureFields.data === "object" && failureFields.data !== null ? failureFields.data : void 0;
|
|
23
|
+
return readString(failureFields.error) ?? readString(errorBody?.error) ?? readString(failureFields.code) ?? readString(failureFields.message);
|
|
24
|
+
};
|
|
25
|
+
const trimApiPrefix = (apiPrefix) => apiPrefix.replace(/\/+$/, "");
|
|
26
|
+
const callPath = (callId) => `/${encodeURIComponent(String(callId))}`;
|
|
27
|
+
const buildAgentVoiceRequests = (apiPrefix) => {
|
|
28
|
+
const prefix = trimApiPrefix(apiPrefix);
|
|
29
|
+
return {
|
|
30
|
+
openSession: ({
|
|
31
|
+
agentSpaceId,
|
|
32
|
+
sdpOffer,
|
|
33
|
+
conversationId,
|
|
34
|
+
callId
|
|
35
|
+
}) => ({
|
|
36
|
+
url: `${prefix}/open`,
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: { agentSpaceId, sdpOffer, conversationId, callId }
|
|
39
|
+
}),
|
|
40
|
+
hangUp: ({ callId, reason }) => ({
|
|
41
|
+
url: `${prefix}${callPath(callId)}/hangUp`,
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: { reason }
|
|
44
|
+
}),
|
|
45
|
+
reportDeviceStatus: ({
|
|
46
|
+
callId,
|
|
47
|
+
status: status2,
|
|
48
|
+
iceCandidateType,
|
|
49
|
+
roundTripTimeMs,
|
|
50
|
+
detail: detail2,
|
|
51
|
+
occurredAtUnixMs
|
|
52
|
+
}) => ({
|
|
53
|
+
url: `${prefix}${callPath(callId)}/deviceStatus`,
|
|
54
|
+
method: "POST",
|
|
55
|
+
body: { status: status2, iceCandidateType, roundTripTimeMs, detail: detail2, occurredAtUnixMs }
|
|
56
|
+
}),
|
|
57
|
+
readCallState: ({ callId }) => ({
|
|
58
|
+
url: `${prefix}${callPath(callId)}`
|
|
59
|
+
}),
|
|
60
|
+
answerRing: ({ callId, answerToken }) => ({
|
|
61
|
+
url: `${prefix}${callPath(callId)}/answer`,
|
|
62
|
+
method: "POST",
|
|
63
|
+
body: { answerToken }
|
|
64
|
+
}),
|
|
65
|
+
declineRing: ({ callId, answerToken }) => ({
|
|
66
|
+
url: `${prefix}${callPath(callId)}/decline`,
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: { answerToken }
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER = "invalid_open_answer";
|
|
73
|
+
const createAgentVoiceApi = ({ baseApi, apiPrefix }) => {
|
|
74
|
+
const requests = buildAgentVoiceRequests(apiPrefix);
|
|
75
|
+
return {
|
|
76
|
+
openSession: async (args) => {
|
|
77
|
+
const openAnswer = await baseApi.request(requests.openSession(args));
|
|
78
|
+
const callId = openAnswer?.agentVoiceCall?.id ?? args.callId;
|
|
79
|
+
const conversationId = openAnswer?.conversationId ?? args.conversationId;
|
|
80
|
+
if (callId === void 0 || conversationId === void 0)
|
|
81
|
+
throw new AgentVoiceApiError(AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER);
|
|
82
|
+
return { callId, sdpAnswer: openAnswer?.sdpAnswer ?? "", conversationId };
|
|
83
|
+
},
|
|
84
|
+
hangUp: async (args) => {
|
|
85
|
+
await baseApi.request(requests.hangUp(args));
|
|
86
|
+
},
|
|
87
|
+
reportDeviceStatus: async (args) => {
|
|
88
|
+
await baseApi.request(requests.reportDeviceStatus(args));
|
|
89
|
+
},
|
|
90
|
+
readCallState: async (args) => {
|
|
91
|
+
const callState = await baseApi.request(requests.readCallState(args));
|
|
92
|
+
return {
|
|
93
|
+
callId: callState?.callId ?? args.callId,
|
|
94
|
+
endedAt: callState?.endedAt ?? void 0,
|
|
95
|
+
endReason: callState?.endReason ?? void 0
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
answerRing: async (args) => {
|
|
99
|
+
const ringAnswer = await baseApi.request(requests.answerRing(args));
|
|
100
|
+
return { won: ringAnswer?.won === true, conversationId: ringAnswer?.conversationId ?? void 0 };
|
|
101
|
+
},
|
|
102
|
+
declineRing: async (args) => {
|
|
103
|
+
await baseApi.request(requests.declineRing(args));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const readJsonBody = async (response) => {
|
|
108
|
+
const bodyText = await response.text();
|
|
109
|
+
if (bodyText === "") return void 0;
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(bodyText);
|
|
112
|
+
} catch {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const createAgentVoiceFetchBaseApi = (options = {}) => ({
|
|
117
|
+
request: async (request) => {
|
|
118
|
+
const fetchFunction = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
119
|
+
const fetchOptions = typeof options.fetchOptions === "function" ? await options.fetchOptions() : options.fetchOptions ?? {};
|
|
120
|
+
const headers = new Headers(fetchOptions.headers);
|
|
121
|
+
if (!headers.has("Accept")) headers.set("Accept", "application/json");
|
|
122
|
+
if (request.body !== void 0 && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
123
|
+
const response = await fetchFunction(request.url, {
|
|
124
|
+
...fetchOptions,
|
|
125
|
+
headers,
|
|
126
|
+
method: request.method ?? "GET",
|
|
127
|
+
body: request.body === void 0 ? void 0 : JSON.stringify(request.body)
|
|
128
|
+
});
|
|
129
|
+
const responseBody = await readJsonBody(response);
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
throw new AgentVoiceApiError(readAgentVoiceErrorCode(responseBody) ?? `http_${response.status}`, response.status);
|
|
132
|
+
}
|
|
133
|
+
return responseBody;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT = "ENDED_BY_AGENT";
|
|
137
|
+
const AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED = "LIMIT_REACHED";
|
|
138
|
+
const SESSION_START_TIMEOUT_MS = 15e3;
|
|
139
|
+
const AUDIO_FLOW_CHECK_INTERVAL_MS = 1e3;
|
|
140
|
+
const AUDIO_FLOW_CHECK_ATTEMPTS = 10;
|
|
141
|
+
const LOG_PREFIX = "[AgentVoiceCall]";
|
|
142
|
+
const AGENT_SPEAKING_HOLD_MS = 900;
|
|
143
|
+
const OWNER_SPEAKING_HOLD_MS = 900;
|
|
144
|
+
const SILENT_MICROPHONE_LEVEL = 0.01;
|
|
145
|
+
const SILENT_MICROPHONE_WINDOW_SAMPLES = 6;
|
|
146
|
+
const SILENT_AFTER_HEARD_MS = 6e4;
|
|
147
|
+
const ICE_GATHERING_TIMEOUT_MS = 2e3;
|
|
148
|
+
const ICE_DISCONNECT_GRACE_MS = 5e3;
|
|
149
|
+
const DATA_CHANNEL_LABEL = "oai-events";
|
|
150
|
+
const AGENT_VOICE_CALL_END_REASON_FAILED = "FAILED";
|
|
151
|
+
const PROVIDER_CLOSED_END_REASON = "PROVIDER_CLOSED";
|
|
152
|
+
const SESSION_CLOSED_RECHECK_MS = 1500;
|
|
153
|
+
const CONNECTION_DROPPED_TEXT_KEY = textKey("The connection to %agentName% dropped. Please try again.");
|
|
154
|
+
const OPEN_ERROR_TEXT_KEYS = {
|
|
155
|
+
feature_not_available: textKey("Voice chats with %agentName% are not available here."),
|
|
156
|
+
no_ai_budget: textKey("Your AI budget is used up, so %agentName% cannot talk right now."),
|
|
157
|
+
daily_limit_reached: textKey("The time for voice chats with %agentName% is used up for today. Please try again tomorrow."),
|
|
158
|
+
call_already_running: textKey("You are already in a voice chat with %agentName%. End it first, then start a new one."),
|
|
159
|
+
conversation_not_found: textKey(
|
|
160
|
+
"This conversation cannot take a voice chat. Start a new chat and talk to %agentName% from there."
|
|
161
|
+
),
|
|
162
|
+
provider_unavailable: textKey("The voice of %agentName% is not reachable right now. Please try again in a minute."),
|
|
163
|
+
invalid_sdp: textKey("Your browser could not set up the voice chat. Please try again.")
|
|
164
|
+
};
|
|
165
|
+
const IDLE_AGENT_VOICE_CALL = {
|
|
166
|
+
phase: "idle",
|
|
167
|
+
isMuted: false,
|
|
168
|
+
isMicrophoneSilent: false,
|
|
169
|
+
isAgentSpeaking: false,
|
|
170
|
+
isOwnerSpeaking: false,
|
|
171
|
+
lines: []
|
|
172
|
+
};
|
|
173
|
+
let snapshot$1 = IDLE_AGENT_VOICE_CALL;
|
|
174
|
+
const listeners$1 = /* @__PURE__ */ new Set();
|
|
175
|
+
let voiceApi;
|
|
176
|
+
let peerConnection;
|
|
177
|
+
let microphoneStream;
|
|
178
|
+
let remoteAudioElement;
|
|
179
|
+
let providerEventChannel;
|
|
180
|
+
let audioFlowTimer;
|
|
181
|
+
let agentSpeakingTimer;
|
|
182
|
+
let ownerSpeakingTimer;
|
|
183
|
+
let ownerLastHeardAtMs;
|
|
184
|
+
let sessionStartTimer;
|
|
185
|
+
let iceDisconnectTimer;
|
|
186
|
+
let mediaConnectedReported = false;
|
|
187
|
+
let pageHideListenerRegistered = false;
|
|
188
|
+
let callStateCheckInFlight;
|
|
189
|
+
let sessionClosedRecheckTimer;
|
|
190
|
+
const replaceSnapshot = (nextSnapshot) => {
|
|
191
|
+
snapshot$1 = nextSnapshot;
|
|
192
|
+
listeners$1.forEach((listener) => listener());
|
|
193
|
+
};
|
|
194
|
+
const updateSnapshot$1 = (changes) => replaceSnapshot({ ...snapshot$1, ...changes });
|
|
195
|
+
const subscribe$1 = (listener) => {
|
|
196
|
+
listeners$1.add(listener);
|
|
197
|
+
return () => {
|
|
198
|
+
listeners$1.delete(listener);
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const getSnapshot$1 = () => snapshot$1;
|
|
202
|
+
const bindAgentVoiceApi = (api) => {
|
|
203
|
+
voiceApi = api;
|
|
204
|
+
};
|
|
205
|
+
const readBoundAgentVoiceApi = () => voiceApi;
|
|
206
|
+
const readAgentVoiceCallSnapshot = () => snapshot$1;
|
|
207
|
+
const useAgentVoiceCallSnapshot = () => useSyncExternalStore(subscribe$1, getSnapshot$1, getSnapshot$1);
|
|
208
|
+
const useAgentVoiceCallValue = (selectValue) => useSyncExternalStore(
|
|
209
|
+
subscribe$1,
|
|
210
|
+
() => selectValue(snapshot$1),
|
|
211
|
+
() => selectValue(snapshot$1)
|
|
212
|
+
);
|
|
213
|
+
const isAgentVoiceCallActive = (phase) => phase === "connecting" || phase === "live";
|
|
214
|
+
const isAgentVoiceCallShownInAgentSpace = (call, agentSpaceId) => agentSpaceId === void 0 || call.agentSpaceId === void 0 || call.agentSpaceId === agentSpaceId;
|
|
215
|
+
const useIsAgentVoiceCallActive = (agentSpaceId) => useAgentVoiceCallValue((call) => isAgentVoiceCallActive(call.phase) && isAgentVoiceCallShownInAgentSpace(call, agentSpaceId));
|
|
216
|
+
const dismissAgentVoiceCallOutcome = () => {
|
|
217
|
+
if (isAgentVoiceCallActive(snapshot$1.phase)) return;
|
|
218
|
+
replaceSnapshot(IDLE_AGENT_VOICE_CALL);
|
|
219
|
+
};
|
|
220
|
+
const clearTimers = () => {
|
|
221
|
+
window.clearTimeout(sessionStartTimer);
|
|
222
|
+
window.clearTimeout(iceDisconnectTimer);
|
|
223
|
+
window.clearInterval(audioFlowTimer);
|
|
224
|
+
window.clearTimeout(agentSpeakingTimer);
|
|
225
|
+
window.clearTimeout(ownerSpeakingTimer);
|
|
226
|
+
window.clearTimeout(sessionClosedRecheckTimer);
|
|
227
|
+
sessionStartTimer = void 0;
|
|
228
|
+
iceDisconnectTimer = void 0;
|
|
229
|
+
audioFlowTimer = void 0;
|
|
230
|
+
sessionClosedRecheckTimer = void 0;
|
|
231
|
+
};
|
|
232
|
+
const releaseMedia = () => {
|
|
233
|
+
clearTimers();
|
|
234
|
+
microphoneStream?.getTracks().forEach((track) => track.stop());
|
|
235
|
+
providerEventChannel?.close();
|
|
236
|
+
peerConnection?.close();
|
|
237
|
+
if (remoteAudioElement) {
|
|
238
|
+
remoteAudioElement.pause();
|
|
239
|
+
remoteAudioElement.srcObject = null;
|
|
240
|
+
}
|
|
241
|
+
microphoneStream = void 0;
|
|
242
|
+
providerEventChannel = void 0;
|
|
243
|
+
peerConnection = void 0;
|
|
244
|
+
remoteAudioElement = void 0;
|
|
245
|
+
};
|
|
246
|
+
const reportDeviceStatus = (status2, detail2) => {
|
|
247
|
+
const callId = snapshot$1.callId;
|
|
248
|
+
if (callId === void 0 || !voiceApi) return;
|
|
249
|
+
voiceApi.reportDeviceStatus({ callId, status: status2, detail: detail2, occurredAtUnixMs: Date.now() }).catch(() => void 0);
|
|
250
|
+
};
|
|
251
|
+
const sendHangUp = (callId, reason) => {
|
|
252
|
+
if (callId === void 0 || !voiceApi) return;
|
|
253
|
+
voiceApi.hangUp({ callId, reason }).catch(() => void 0);
|
|
254
|
+
};
|
|
255
|
+
const sendSessionClose = () => {
|
|
256
|
+
if (providerEventChannel?.readyState !== "open") return;
|
|
257
|
+
providerEventChannel.send(JSON.stringify({ type: "session.close" }));
|
|
258
|
+
};
|
|
259
|
+
const failCall = (failureTextKey, detail2) => {
|
|
260
|
+
if (!isAgentVoiceCallActive(snapshot$1.phase)) return;
|
|
261
|
+
console.warn(LOG_PREFIX, "call failed:", detail2);
|
|
262
|
+
reportDeviceStatus("MEDIA_FAILED", detail2);
|
|
263
|
+
sendSessionClose();
|
|
264
|
+
sendHangUp(snapshot$1.callId, "MEDIA_FAILED");
|
|
265
|
+
releaseMedia();
|
|
266
|
+
updateSnapshot$1({
|
|
267
|
+
phase: "failed",
|
|
268
|
+
failureTextKey,
|
|
269
|
+
endedAtMs: Date.now(),
|
|
270
|
+
isAgentSpeaking: false,
|
|
271
|
+
isOwnerSpeaking: false
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
const endAgentVoiceCallFromServer = (callId, endReason) => {
|
|
275
|
+
if (!isAgentVoiceCallActive(snapshot$1.phase) || snapshot$1.callId !== callId) return;
|
|
276
|
+
console.info(LOG_PREFIX, "call ended by the server:", endReason ?? "unknown reason");
|
|
277
|
+
reportDeviceStatus("SERVER_END_SEEN", endReason);
|
|
278
|
+
if (endReason !== AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT) sendSessionClose();
|
|
279
|
+
releaseMedia();
|
|
280
|
+
if (endReason === AGENT_VOICE_CALL_END_REASON_FAILED) {
|
|
281
|
+
updateSnapshot$1({
|
|
282
|
+
phase: "failed",
|
|
283
|
+
failureTextKey: CONNECTION_DROPPED_TEXT_KEY,
|
|
284
|
+
endedAtMs: Date.now(),
|
|
285
|
+
isAgentSpeaking: false,
|
|
286
|
+
isOwnerSpeaking: false
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
updateSnapshot$1({
|
|
291
|
+
phase: "ended",
|
|
292
|
+
endReason,
|
|
293
|
+
endedAtMs: Date.now(),
|
|
294
|
+
isAgentSpeaking: false,
|
|
295
|
+
isOwnerSpeaking: false
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
const readCallStateAndEndWhenEndedOnServer = async (callId) => {
|
|
299
|
+
if (!voiceApi) return false;
|
|
300
|
+
try {
|
|
301
|
+
const callState = await voiceApi.readCallState({ callId });
|
|
302
|
+
if (!callState?.endedAt) return false;
|
|
303
|
+
endAgentVoiceCallFromServer(callId, callState.endReason ?? void 0);
|
|
304
|
+
return true;
|
|
305
|
+
} catch {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const checkAgentVoiceCallEndedOnServer = () => {
|
|
310
|
+
const callId = snapshot$1.callId;
|
|
311
|
+
if (callId === void 0 || !isAgentVoiceCallActive(snapshot$1.phase)) return Promise.resolve(false);
|
|
312
|
+
if (callStateCheckInFlight?.callId === callId) return callStateCheckInFlight.endedOnServer;
|
|
313
|
+
const endedOnServer = readCallStateAndEndWhenEndedOnServer(callId).finally(() => {
|
|
314
|
+
if (callStateCheckInFlight?.callId === callId) callStateCheckInFlight = void 0;
|
|
315
|
+
});
|
|
316
|
+
callStateCheckInFlight = { callId, endedOnServer };
|
|
317
|
+
return endedOnServer;
|
|
318
|
+
};
|
|
319
|
+
const endCallAfterProviderClosedSession = async () => {
|
|
320
|
+
const callId = snapshot$1.callId;
|
|
321
|
+
if (callId === void 0) {
|
|
322
|
+
hangUpAgentVoiceCall(PROVIDER_CLOSED_END_REASON);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (await checkAgentVoiceCallEndedOnServer()) return;
|
|
326
|
+
window.clearTimeout(sessionClosedRecheckTimer);
|
|
327
|
+
sessionClosedRecheckTimer = window.setTimeout(async () => {
|
|
328
|
+
if (await checkAgentVoiceCallEndedOnServer()) return;
|
|
329
|
+
endAgentVoiceCallFromServer(callId, PROVIDER_CLOSED_END_REASON);
|
|
330
|
+
}, SESSION_CLOSED_RECHECK_MS);
|
|
331
|
+
};
|
|
332
|
+
const failCallUnlessEndedOnServer = async (connection, detail2) => {
|
|
333
|
+
if (await checkAgentVoiceCallEndedOnServer()) return;
|
|
334
|
+
if (connection !== peerConnection) return;
|
|
335
|
+
failCall(CONNECTION_DROPPED_TEXT_KEY, detail2);
|
|
336
|
+
};
|
|
337
|
+
const hangUpAgentVoiceCall = (reason = "USER_ENDED") => {
|
|
338
|
+
if (!isAgentVoiceCallActive(snapshot$1.phase)) return;
|
|
339
|
+
if (reason === "USER_ENDED") reportDeviceStatus("ENDED_BY_USER");
|
|
340
|
+
if (reason !== "PROVIDER_CLOSED") sendSessionClose();
|
|
341
|
+
sendHangUp(snapshot$1.callId, reason);
|
|
342
|
+
releaseMedia();
|
|
343
|
+
updateSnapshot$1({
|
|
344
|
+
phase: "ended",
|
|
345
|
+
endedAtMs: Date.now(),
|
|
346
|
+
isAgentSpeaking: false,
|
|
347
|
+
isOwnerSpeaking: false
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
const toggleAgentVoiceCallMute = () => {
|
|
351
|
+
const isMuted = !snapshot$1.isMuted;
|
|
352
|
+
if (!isMuted && ownerLastHeardAtMs !== void 0) ownerLastHeardAtMs = Date.now();
|
|
353
|
+
microphoneStream?.getAudioTracks().forEach((track) => {
|
|
354
|
+
track.enabled = !isMuted;
|
|
355
|
+
});
|
|
356
|
+
updateSnapshot$1({ isMuted });
|
|
357
|
+
};
|
|
358
|
+
const appendTranscriptDelta = (speaker, delta) => {
|
|
359
|
+
if (typeof delta !== "string" || delta === "") return;
|
|
360
|
+
const lastLine = snapshot$1.lines[snapshot$1.lines.length - 1];
|
|
361
|
+
const lines = lastLine !== void 0 && lastLine.speaker === speaker ? [...snapshot$1.lines.slice(0, -1), { ...lastLine, text: `${lastLine.text}${delta}` }] : [...snapshot$1.lines, { id: (lastLine?.id ?? 0) + 1, speaker, text: delta.trimStart() }].slice(-40);
|
|
362
|
+
if (speaker === "owner") {
|
|
363
|
+
ownerLastHeardAtMs = Date.now();
|
|
364
|
+
updateSnapshot$1({ lines, lastSpeaker: speaker, isOwnerSpeaking: true });
|
|
365
|
+
window.clearTimeout(ownerSpeakingTimer);
|
|
366
|
+
ownerSpeakingTimer = window.setTimeout(() => updateSnapshot$1({ isOwnerSpeaking: false }), OWNER_SPEAKING_HOLD_MS);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
updateSnapshot$1({ lines, lastSpeaker: speaker, isAgentSpeaking: true });
|
|
370
|
+
window.clearTimeout(agentSpeakingTimer);
|
|
371
|
+
agentSpeakingTimer = window.setTimeout(() => updateSnapshot$1({ isAgentSpeaking: false }), AGENT_SPEAKING_HOLD_MS);
|
|
372
|
+
};
|
|
373
|
+
const readProviderEvent = (messageEvent) => {
|
|
374
|
+
let providerEvent;
|
|
375
|
+
try {
|
|
376
|
+
providerEvent = JSON.parse(String(messageEvent.data));
|
|
377
|
+
} catch {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (!providerEvent.type?.endsWith(".delta")) console.info(LOG_PREFIX, "provider event", providerEvent.type);
|
|
381
|
+
switch (providerEvent.type) {
|
|
382
|
+
case "session.started":
|
|
383
|
+
if (snapshot$1.phase !== "connecting") return;
|
|
384
|
+
window.clearTimeout(sessionStartTimer);
|
|
385
|
+
updateSnapshot$1({ phase: "live", connectedAtMs: Date.now() });
|
|
386
|
+
reportDeviceStatus("SESSION_STARTED_SEEN");
|
|
387
|
+
watchAudioFlow();
|
|
388
|
+
return;
|
|
389
|
+
case "session.output_transcript.delta":
|
|
390
|
+
appendTranscriptDelta("agent", providerEvent.delta);
|
|
391
|
+
return;
|
|
392
|
+
case "session.input_transcript.delta":
|
|
393
|
+
appendTranscriptDelta("owner", providerEvent.delta);
|
|
394
|
+
return;
|
|
395
|
+
case "session.closed":
|
|
396
|
+
void endCallAfterProviderClosedSession();
|
|
397
|
+
return;
|
|
398
|
+
default:
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
const watchAudioFlow = () => {
|
|
403
|
+
const connection = peerConnection;
|
|
404
|
+
if (!connection) return;
|
|
405
|
+
const microphoneTrack = microphoneStream?.getAudioTracks()[0];
|
|
406
|
+
console.info(
|
|
407
|
+
LOG_PREFIX,
|
|
408
|
+
`microphone "${microphoneTrack?.label}" enabled=${microphoneTrack?.enabled} muted=${microphoneTrack?.muted} state=${microphoneTrack?.readyState}`
|
|
409
|
+
);
|
|
410
|
+
let firstAudioSentReported = false;
|
|
411
|
+
let firstAudioPlayedReported = false;
|
|
412
|
+
let silentMicrophoneReported = false;
|
|
413
|
+
let attempts = 0;
|
|
414
|
+
const recentMicrophoneLevels = [];
|
|
415
|
+
window.clearInterval(audioFlowTimer);
|
|
416
|
+
audioFlowTimer = window.setInterval(async () => {
|
|
417
|
+
if (connection !== peerConnection) return;
|
|
418
|
+
attempts += 1;
|
|
419
|
+
const stats = await connection.getStats();
|
|
420
|
+
stats.forEach((report) => {
|
|
421
|
+
if (report.type === "outbound-rtp" && report.kind === "audio" && report.bytesSent > 0 && !firstAudioSentReported) {
|
|
422
|
+
firstAudioSentReported = true;
|
|
423
|
+
reportDeviceStatus("FIRST_AUDIO_SENT");
|
|
424
|
+
}
|
|
425
|
+
if (report.type === "inbound-rtp" && report.kind === "audio" && report.bytesReceived > 0 && !firstAudioPlayedReported) {
|
|
426
|
+
firstAudioPlayedReported = true;
|
|
427
|
+
reportDeviceStatus("FIRST_AUDIO_PLAYED");
|
|
428
|
+
}
|
|
429
|
+
if (report.type === "media-source" && report.kind === "audio" && typeof report.audioLevel === "number") {
|
|
430
|
+
recentMicrophoneLevels.push(report.audioLevel);
|
|
431
|
+
if (report.audioLevel >= SILENT_MICROPHONE_LEVEL) ownerLastHeardAtMs = Date.now();
|
|
432
|
+
if (recentMicrophoneLevels.length > SILENT_MICROPHONE_WINDOW_SAMPLES) recentMicrophoneLevels.shift();
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
if (attempts === AUDIO_FLOW_CHECK_ATTEMPTS) {
|
|
436
|
+
console.info(LOG_PREFIX, `audio flow sent=${firstAudioSentReported} played=${firstAudioPlayedReported}`);
|
|
437
|
+
if (!firstAudioSentReported) reportDeviceStatus("MEDIA_FAILED", "no outbound audio bytes 10s after session.started");
|
|
438
|
+
}
|
|
439
|
+
const loudestRecentLevel = Math.max(0, ...recentMicrophoneLevels);
|
|
440
|
+
const isSilentSinceStart = ownerLastHeardAtMs === void 0 && recentMicrophoneLevels.length === SILENT_MICROPHONE_WINDOW_SAMPLES && loudestRecentLevel < SILENT_MICROPHONE_LEVEL;
|
|
441
|
+
const isSilentSinceLastHeard = ownerLastHeardAtMs !== void 0 && Date.now() - ownerLastHeardAtMs >= SILENT_AFTER_HEARD_MS;
|
|
442
|
+
const isMicrophoneSilent = !snapshot$1.isMuted && (isSilentSinceStart || isSilentSinceLastHeard);
|
|
443
|
+
if (isMicrophoneSilent !== snapshot$1.isMicrophoneSilent) {
|
|
444
|
+
console.info(LOG_PREFIX, `microphone silent=${isMicrophoneSilent} loudest level=${loudestRecentLevel}`);
|
|
445
|
+
updateSnapshot$1({ isMicrophoneSilent });
|
|
446
|
+
}
|
|
447
|
+
if (isMicrophoneSilent && !silentMicrophoneReported) {
|
|
448
|
+
silentMicrophoneReported = true;
|
|
449
|
+
reportDeviceStatus("INTERRUPTED", `microphone "${microphoneTrack?.label}" silent, loudest level ${loudestRecentLevel}`);
|
|
450
|
+
}
|
|
451
|
+
}, AUDIO_FLOW_CHECK_INTERVAL_MS);
|
|
452
|
+
};
|
|
453
|
+
const watchIceConnection = (connection) => {
|
|
454
|
+
connection.oniceconnectionstatechange = () => {
|
|
455
|
+
if (connection !== peerConnection) return;
|
|
456
|
+
const iceConnectionState = connection.iceConnectionState;
|
|
457
|
+
if (iceConnectionState === "connected" || iceConnectionState === "completed") {
|
|
458
|
+
window.clearTimeout(iceDisconnectTimer);
|
|
459
|
+
if (!mediaConnectedReported) {
|
|
460
|
+
mediaConnectedReported = true;
|
|
461
|
+
reportDeviceStatus("MEDIA_CONNECTED");
|
|
462
|
+
}
|
|
463
|
+
} else if (iceConnectionState === "disconnected") {
|
|
464
|
+
void checkAgentVoiceCallEndedOnServer();
|
|
465
|
+
window.clearTimeout(iceDisconnectTimer);
|
|
466
|
+
iceDisconnectTimer = window.setTimeout(
|
|
467
|
+
() => void failCallUnlessEndedOnServer(connection, "ice disconnected for 5s"),
|
|
468
|
+
ICE_DISCONNECT_GRACE_MS
|
|
469
|
+
);
|
|
470
|
+
} else if (iceConnectionState === "failed") {
|
|
471
|
+
void failCallUnlessEndedOnServer(connection, "ice failed");
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
const waitForIceGathering = (connection) => new Promise((resolve) => {
|
|
476
|
+
if (connection.iceGatheringState === "complete") {
|
|
477
|
+
resolve();
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const timer = window.setTimeout(resolve, ICE_GATHERING_TIMEOUT_MS);
|
|
481
|
+
connection.addEventListener("icegatheringstatechange", () => {
|
|
482
|
+
if (connection.iceGatheringState === "complete") {
|
|
483
|
+
window.clearTimeout(timer);
|
|
484
|
+
resolve();
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
const registerPageHideHangUp = () => {
|
|
489
|
+
if (pageHideListenerRegistered) return;
|
|
490
|
+
pageHideListenerRegistered = true;
|
|
491
|
+
window.addEventListener("pagehide", () => hangUpAgentVoiceCall("APP_BACKGROUNDED"));
|
|
492
|
+
};
|
|
493
|
+
const startAgentVoiceCall = async (params = {}) => {
|
|
494
|
+
const { agentSpaceId, conversationId, callId: answeredCallId } = params;
|
|
495
|
+
if (isAgentVoiceCallActive(snapshot$1.phase)) return;
|
|
496
|
+
const api = voiceApi;
|
|
497
|
+
if (!api) {
|
|
498
|
+
console.warn(LOG_PREFIX, "no adapter bound: mount AgentVoiceCallProvider before starting a voice chat");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
mediaConnectedReported = false;
|
|
502
|
+
ownerLastHeardAtMs = void 0;
|
|
503
|
+
registerPageHideHangUp();
|
|
504
|
+
replaceSnapshot({ ...IDLE_AGENT_VOICE_CALL, phase: "connecting", agentSpaceId, conversationId, callId: answeredCallId });
|
|
505
|
+
try {
|
|
506
|
+
microphoneStream = await navigator.mediaDevices.getUserMedia({
|
|
507
|
+
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true }
|
|
508
|
+
});
|
|
509
|
+
} catch {
|
|
510
|
+
releaseMedia();
|
|
511
|
+
sendHangUp(answeredCallId, "MEDIA_FAILED");
|
|
512
|
+
updateSnapshot$1({
|
|
513
|
+
phase: "failed",
|
|
514
|
+
failureTextKey: textKey("%agentName% needs your microphone. Allow microphone access in your browser, then try again.")
|
|
515
|
+
});
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const connection = new RTCPeerConnection();
|
|
519
|
+
peerConnection = connection;
|
|
520
|
+
remoteAudioElement = new Audio();
|
|
521
|
+
remoteAudioElement.autoplay = true;
|
|
522
|
+
connection.ontrack = (trackEvent) => {
|
|
523
|
+
if (remoteAudioElement) remoteAudioElement.srcObject = trackEvent.streams[0] ?? null;
|
|
524
|
+
};
|
|
525
|
+
microphoneStream.getTracks().forEach((track) => connection.addTrack(track, microphoneStream));
|
|
526
|
+
const eventChannel = connection.createDataChannel(DATA_CHANNEL_LABEL);
|
|
527
|
+
providerEventChannel = eventChannel;
|
|
528
|
+
eventChannel.onmessage = readProviderEvent;
|
|
529
|
+
eventChannel.onclose = () => {
|
|
530
|
+
if (eventChannel !== providerEventChannel) return;
|
|
531
|
+
void checkAgentVoiceCallEndedOnServer();
|
|
532
|
+
};
|
|
533
|
+
watchIceConnection(connection);
|
|
534
|
+
try {
|
|
535
|
+
await connection.setLocalDescription(await connection.createOffer());
|
|
536
|
+
await waitForIceGathering(connection);
|
|
537
|
+
const sdpOffer = connection.localDescription?.sdp ?? "";
|
|
538
|
+
const openAnswer = await api.openSession({ agentSpaceId, sdpOffer, conversationId, callId: answeredCallId });
|
|
539
|
+
const callId = openAnswer.callId ?? void 0;
|
|
540
|
+
if (connection !== peerConnection) {
|
|
541
|
+
sendHangUp(callId, "USER_ENDED");
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
updateSnapshot$1({ callId, conversationId: openAnswer.conversationId ?? conversationId });
|
|
545
|
+
if (!openAnswer.sdpAnswer) {
|
|
546
|
+
failCall(
|
|
547
|
+
textKey("The voice of %agentName% is not reachable right now. Please try again in a minute."),
|
|
548
|
+
"open returned no SDP answer"
|
|
549
|
+
);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
await connection.setRemoteDescription({ type: "answer", sdp: openAnswer.sdpAnswer });
|
|
553
|
+
reportDeviceStatus("ANSWER_APPLIED");
|
|
554
|
+
sessionStartTimer = window.setTimeout(
|
|
555
|
+
() => failCall(textKey("%agentName% could not join the voice chat. Please try again."), "no session.started within 15s"),
|
|
556
|
+
SESSION_START_TIMEOUT_MS
|
|
557
|
+
);
|
|
558
|
+
} catch (openError) {
|
|
559
|
+
if (connection !== peerConnection) return;
|
|
560
|
+
const errorCode = readAgentVoiceErrorCode(openError);
|
|
561
|
+
const isKnownErrorCode = errorCode !== void 0 && Object.prototype.hasOwnProperty.call(OPEN_ERROR_TEXT_KEYS, errorCode);
|
|
562
|
+
releaseMedia();
|
|
563
|
+
sendHangUp(answeredCallId, "MEDIA_FAILED");
|
|
564
|
+
updateSnapshot$1({
|
|
565
|
+
phase: "failed",
|
|
566
|
+
failureTextKey: isKnownErrorCode ? OPEN_ERROR_TEXT_KEYS[errorCode] : textKey("The voice chat could not be started. Please try again."),
|
|
567
|
+
endedAtMs: Date.now()
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
const agentVoiceCallElapsedSecondsAt = (call, nowMs) => {
|
|
572
|
+
if (call.connectedAtMs === void 0) return 0;
|
|
573
|
+
return Math.max(0, Math.floor(((call.endedAtMs ?? nowMs) - call.connectedAtMs) / 1e3));
|
|
574
|
+
};
|
|
575
|
+
const useAgentVoiceCallElapsedSeconds = (call) => {
|
|
576
|
+
const [nowMs, setNowMs] = useState(() => Date.now());
|
|
577
|
+
useEffect(() => {
|
|
578
|
+
if (call.phase !== "live") return;
|
|
579
|
+
const timer = window.setInterval(() => setNowMs(Date.now()), 1e3);
|
|
580
|
+
return () => window.clearInterval(timer);
|
|
581
|
+
}, [call.phase]);
|
|
582
|
+
return agentVoiceCallElapsedSecondsAt(call, nowMs);
|
|
583
|
+
};
|
|
584
|
+
const useAgentVoiceCall = () => {
|
|
585
|
+
const call = useAgentVoiceCallSnapshot();
|
|
586
|
+
const elapsedSeconds = useAgentVoiceCallElapsedSeconds(call);
|
|
587
|
+
return useMemo(() => ({ ...call, elapsedSeconds }), [call, elapsedSeconds]);
|
|
588
|
+
};
|
|
589
|
+
const turnOfAgentVoiceCall = (call) => {
|
|
590
|
+
if (call.phase === "connecting") return "connecting";
|
|
591
|
+
if (call.isMuted) return "muted";
|
|
592
|
+
if (call.isMicrophoneSilent) return "silentMicrophone";
|
|
593
|
+
if (call.isAgentSpeaking) return "agent";
|
|
594
|
+
if (call.isOwnerSpeaking) return "owner";
|
|
595
|
+
if (call.lastSpeaker === "owner") return "thinking";
|
|
596
|
+
return "listening";
|
|
597
|
+
};
|
|
598
|
+
const CALL_STATE_READ_THROTTLE_MS = 1200;
|
|
599
|
+
const useAgentVoiceCallServerEnd = (subscribeToConversationChanges) => {
|
|
600
|
+
const conversationClient = useOptionalAgentsConversationClient();
|
|
601
|
+
const isCallActive = useAgentVoiceCallValue((call) => isAgentVoiceCallActive(call.phase));
|
|
602
|
+
const callConversationId = useAgentVoiceCallValue((call) => call.conversationId);
|
|
603
|
+
const callId = useAgentVoiceCallValue((call) => call.callId);
|
|
604
|
+
useEffect(() => {
|
|
605
|
+
if (!isCallActive || callConversationId === void 0 || callId === void 0) return;
|
|
606
|
+
let lastReadAtMs = Number.NEGATIVE_INFINITY;
|
|
607
|
+
let trailingReadTimer;
|
|
608
|
+
const readCallState = () => {
|
|
609
|
+
lastReadAtMs = Date.now();
|
|
610
|
+
void checkAgentVoiceCallEndedOnServer();
|
|
611
|
+
};
|
|
612
|
+
const readCallStateThrottled = () => {
|
|
613
|
+
const waitMs = lastReadAtMs + CALL_STATE_READ_THROTTLE_MS - Date.now();
|
|
614
|
+
if (waitMs <= 0) {
|
|
615
|
+
readCallState();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (trailingReadTimer !== void 0) return;
|
|
619
|
+
trailingReadTimer = window.setTimeout(() => {
|
|
620
|
+
trailingReadTimer = void 0;
|
|
621
|
+
readCallState();
|
|
622
|
+
}, waitMs);
|
|
623
|
+
};
|
|
624
|
+
const unsubscribe = subscribeToConversationChanges !== void 0 ? subscribeToConversationChanges(callConversationId, readCallStateThrottled) : conversationClient?.subscribeToConversationChanges?.(
|
|
625
|
+
callConversationId,
|
|
626
|
+
readCallStateThrottled,
|
|
627
|
+
readCallStateThrottled
|
|
628
|
+
);
|
|
629
|
+
return () => {
|
|
630
|
+
window.clearTimeout(trailingReadTimer);
|
|
631
|
+
unsubscribe?.();
|
|
632
|
+
};
|
|
633
|
+
}, [isCallActive, callConversationId, callId, subscribeToConversationChanges, conversationClient]);
|
|
634
|
+
};
|
|
635
|
+
const SENTENCE_PATTERN = /[^.!?…]+[.!?…]*\s*/g;
|
|
636
|
+
const normalizeForMatching = (text) => text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
|
|
637
|
+
const buildUnsavedAgentVoiceCallLines = (lines, savedMessages) => {
|
|
638
|
+
const savedStreamBySpeaker = { agent: "", owner: "" };
|
|
639
|
+
savedMessages.forEach((savedMessage) => {
|
|
640
|
+
savedStreamBySpeaker[savedMessage.speaker] += normalizeForMatching(savedMessage.text);
|
|
641
|
+
});
|
|
642
|
+
const matchedUntilBySpeaker = { agent: 0, owner: 0 };
|
|
643
|
+
return lines.flatMap((line2) => {
|
|
644
|
+
const sentences = line2.text.match(SENTENCE_PATTERN) ?? [];
|
|
645
|
+
const unsavedSentences = sentences.filter((sentence) => {
|
|
646
|
+
const normalizedSentence = normalizeForMatching(sentence);
|
|
647
|
+
if (normalizedSentence === "") return false;
|
|
648
|
+
const foundAt = savedStreamBySpeaker[line2.speaker].indexOf(normalizedSentence, matchedUntilBySpeaker[line2.speaker]);
|
|
649
|
+
if (foundAt === -1) return true;
|
|
650
|
+
matchedUntilBySpeaker[line2.speaker] = foundAt + normalizedSentence.length;
|
|
651
|
+
return false;
|
|
652
|
+
});
|
|
653
|
+
const unsavedText = unsavedSentences.join("").trim();
|
|
654
|
+
return unsavedText === "" ? [] : [{ ...line2, text: unsavedText }];
|
|
655
|
+
});
|
|
656
|
+
};
|
|
657
|
+
const AGENT_VOICE_RING_MESSAGE_TYPE = "agent.voice.ring";
|
|
658
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
659
|
+
const readAgentVoiceRingOfRealtimeMessage = (message) => {
|
|
660
|
+
if (message.messageType !== AGENT_VOICE_RING_MESSAGE_TYPE) return null;
|
|
661
|
+
let payload;
|
|
662
|
+
try {
|
|
663
|
+
payload = JSON.parse(message.payloadJson);
|
|
664
|
+
} catch {
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
if (!isRecord(payload)) return null;
|
|
668
|
+
const { callId, conversationId, answerToken, ringExpiresAt, ringExpiresAtUnixMs, callerLabelKey, callerContext, agentSpaceId } = payload;
|
|
669
|
+
if (typeof callId !== "number" || typeof answerToken !== "string" || typeof ringExpiresAtUnixMs !== "number") return null;
|
|
670
|
+
return {
|
|
671
|
+
callId,
|
|
672
|
+
conversationId: typeof conversationId === "number" ? conversationId : null,
|
|
673
|
+
answerToken,
|
|
674
|
+
ringExpiresAt: typeof ringExpiresAt === "string" ? ringExpiresAt : "",
|
|
675
|
+
ringExpiresAtUnixMs,
|
|
676
|
+
callerLabelKey: typeof callerLabelKey === "string" ? callerLabelKey : "",
|
|
677
|
+
callerContext: isRecord(callerContext) ? callerContext : {},
|
|
678
|
+
agentSpaceId: typeof agentSpaceId === "number" ? agentSpaceId : void 0
|
|
679
|
+
};
|
|
680
|
+
};
|
|
681
|
+
const pickRingingAgentVoiceCall = (rings, nowMs, handledCallIds) => rings.filter((ring) => ring.ringExpiresAtUnixMs > nowMs && !handledCallIds.has(ring.callId)).sort((left, right) => right.callId - left.callId)[0];
|
|
682
|
+
class AgentVoiceAccountRealtimeRingSource {
|
|
683
|
+
constructor(accountRealtimePoll) {
|
|
684
|
+
this.subscribers = /* @__PURE__ */ new Set();
|
|
685
|
+
this.knownRingsByCallId = /* @__PURE__ */ new Map();
|
|
686
|
+
this.accountRealtimePoll = accountRealtimePoll;
|
|
687
|
+
}
|
|
688
|
+
subscribe(onRing, onRingCleared) {
|
|
689
|
+
const subscriber = { onRing, onRingCleared };
|
|
690
|
+
this.subscribers.add(subscriber);
|
|
691
|
+
const nowMs = Date.now();
|
|
692
|
+
this.knownRingsByCallId.forEach((knownRing) => {
|
|
693
|
+
if (knownRing.ring.ringExpiresAtUnixMs > nowMs) this.handRing(knownRing, subscriber);
|
|
694
|
+
});
|
|
695
|
+
if (this.unsubscribeFromAccountRealtimePoll === void 0) this.listenToAccountRealtimePoll();
|
|
696
|
+
return () => {
|
|
697
|
+
this.subscribers.delete(subscriber);
|
|
698
|
+
if (this.subscribers.size === 0) this.leaveAccountRealtimePoll();
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
/** Takes one message of the account's realtime messages; returns whether it was a ring. */
|
|
702
|
+
acceptRealtimeMessage(message) {
|
|
703
|
+
const ring = readAgentVoiceRingOfRealtimeMessage(message);
|
|
704
|
+
if (ring === null) return false;
|
|
705
|
+
const knownRing = { ring, handedTo: /* @__PURE__ */ new Set() };
|
|
706
|
+
this.knownRingsByCallId.set(ring.callId, knownRing);
|
|
707
|
+
this.subscribers.forEach((subscriber) => this.handRing(knownRing, subscriber));
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Takes one message the account's realtime messages hold no more; returns whether it was a ring. The clear goes to
|
|
712
|
+
* the subscribers the ring of that call was handed to, and to nobody for a call this source holds no ring of.
|
|
713
|
+
*/
|
|
714
|
+
acceptClearedRealtimeMessage(message) {
|
|
715
|
+
const ring = readAgentVoiceRingOfRealtimeMessage(message);
|
|
716
|
+
if (ring === null) return false;
|
|
717
|
+
const knownRing = this.knownRingsByCallId.get(ring.callId);
|
|
718
|
+
this.knownRingsByCallId.delete(ring.callId);
|
|
719
|
+
this.subscribers.forEach((subscriber) => {
|
|
720
|
+
if (knownRing?.handedTo.has(subscriber)) subscriber.onRingCleared(ring.callId);
|
|
721
|
+
});
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
/** Hands a ring to a subscriber and notes it on the known ring. */
|
|
725
|
+
handRing(knownRing, subscriber) {
|
|
726
|
+
knownRing.handedTo.add(subscriber);
|
|
727
|
+
subscriber.onRing(knownRing.ring);
|
|
728
|
+
}
|
|
729
|
+
/** The poll hands over the messages open now, then every arrival and the clear of every message it handed over. */
|
|
730
|
+
listenToAccountRealtimePoll() {
|
|
731
|
+
this.unsubscribeFromAccountRealtimePoll = this.accountRealtimePoll.subscribe({
|
|
732
|
+
onMessage: (message) => {
|
|
733
|
+
this.acceptRealtimeMessage(message);
|
|
734
|
+
},
|
|
735
|
+
onMessageCleared: (message) => {
|
|
736
|
+
this.acceptClearedRealtimeMessage(message);
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
leaveAccountRealtimePoll() {
|
|
741
|
+
this.unsubscribeFromAccountRealtimePoll?.();
|
|
742
|
+
this.unsubscribeFromAccountRealtimePoll = void 0;
|
|
743
|
+
this.knownRingsByCallId.clear();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const createAgentVoiceRingSource = (accountRealtimePoll) => new AgentVoiceAccountRealtimeRingSource(accountRealtimePoll);
|
|
747
|
+
const AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS = {
|
|
748
|
+
answeredElsewhere: textKey("You already answered %agentName% on another device."),
|
|
749
|
+
ringEnded: textKey("%agentName% stopped asking to talk."),
|
|
750
|
+
failed: textKey("The voice chat could not start. Please try again.")
|
|
751
|
+
};
|
|
752
|
+
const answerIncomingAgentVoiceCall = async (ring) => {
|
|
753
|
+
const api = readBoundAgentVoiceApi();
|
|
754
|
+
if (!api) return "failed";
|
|
755
|
+
let conversationIdOfAnswer;
|
|
756
|
+
try {
|
|
757
|
+
const ringAnswer = await api.answerRing({ callId: ring.callId, answerToken: ring.answerToken });
|
|
758
|
+
if (!ringAnswer.won) return "answeredElsewhere";
|
|
759
|
+
conversationIdOfAnswer = ringAnswer.conversationId;
|
|
760
|
+
} catch (answerError) {
|
|
761
|
+
const errorCode = readAgentVoiceErrorCode(answerError);
|
|
762
|
+
if (errorCode === "already_answered") return "answeredElsewhere";
|
|
763
|
+
if (errorCode === "ring_expired" || errorCode === "call_not_found") return "ringEnded";
|
|
764
|
+
return "failed";
|
|
765
|
+
}
|
|
766
|
+
void startAgentVoiceCall({
|
|
767
|
+
agentSpaceId: ring.agentSpaceId,
|
|
768
|
+
conversationId: conversationIdOfAnswer ?? ring.conversationId ?? void 0,
|
|
769
|
+
callId: ring.callId
|
|
770
|
+
});
|
|
771
|
+
return void 0;
|
|
772
|
+
};
|
|
773
|
+
const declineIncomingAgentVoiceCall = (ring) => {
|
|
774
|
+
const api = readBoundAgentVoiceApi();
|
|
775
|
+
if (!api) return Promise.resolve();
|
|
776
|
+
return api.declineRing({ callId: ring.callId, answerToken: ring.answerToken }).catch(() => void 0);
|
|
777
|
+
};
|
|
778
|
+
const REFUSAL_SHOWN_MS = 4e3;
|
|
779
|
+
let snapshot = {
|
|
780
|
+
handledCallIds: /* @__PURE__ */ new Set(),
|
|
781
|
+
isAnswering: false,
|
|
782
|
+
bandHostCount: 0,
|
|
783
|
+
ringCoverCount: 0
|
|
784
|
+
};
|
|
785
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
786
|
+
let refusalTimer;
|
|
787
|
+
const updateSnapshot = (changes) => {
|
|
788
|
+
snapshot = { ...snapshot, ...changes };
|
|
789
|
+
listeners.forEach((listener) => listener());
|
|
790
|
+
};
|
|
791
|
+
const subscribe = (listener) => {
|
|
792
|
+
listeners.add(listener);
|
|
793
|
+
return () => {
|
|
794
|
+
listeners.delete(listener);
|
|
795
|
+
};
|
|
796
|
+
};
|
|
797
|
+
const getSnapshot = () => snapshot;
|
|
798
|
+
const useAgentVoiceIncomingRing = () => useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
799
|
+
const readAgentVoiceIncomingRingSnapshot = () => snapshot;
|
|
800
|
+
const pickAgentVoiceIncomingCard = (state) => {
|
|
801
|
+
if (state.bandHostCount > 0 && state.ringCoverCount === 0) return void 0;
|
|
802
|
+
if (state.ring !== void 0) return "ring";
|
|
803
|
+
return state.refusal !== void 0 ? "refusal" : void 0;
|
|
804
|
+
};
|
|
805
|
+
const publishAgentVoiceIncomingRing = (ring, callerLabel) => {
|
|
806
|
+
if (ring?.callId === snapshot.ring?.callId && ring?.ringExpiresAtUnixMs === snapshot.ring?.ringExpiresAtUnixMs && callerLabel?.text === snapshot.callerLabel?.text && callerLabel?.detail === snapshot.callerLabel?.detail)
|
|
807
|
+
return;
|
|
808
|
+
updateSnapshot({ ring, callerLabel: ring === void 0 ? void 0 : callerLabel });
|
|
809
|
+
};
|
|
810
|
+
const markHandled = (handledRing) => {
|
|
811
|
+
const isShownRing = snapshot.ring?.callId === handledRing.callId;
|
|
812
|
+
updateSnapshot({
|
|
813
|
+
handledCallIds: new Set(snapshot.handledCallIds).add(handledRing.callId),
|
|
814
|
+
ring: isShownRing ? void 0 : snapshot.ring,
|
|
815
|
+
callerLabel: isShownRing ? void 0 : snapshot.callerLabel
|
|
816
|
+
});
|
|
817
|
+
};
|
|
818
|
+
const showRefusal = (refusal) => {
|
|
819
|
+
window.clearTimeout(refusalTimer);
|
|
820
|
+
updateSnapshot({ refusal });
|
|
821
|
+
if (refusal === void 0) return;
|
|
822
|
+
refusalTimer = window.setTimeout(() => updateSnapshot({ refusal: void 0 }), REFUSAL_SHOWN_MS);
|
|
823
|
+
};
|
|
824
|
+
const acceptAgentVoiceIncomingRing = async () => {
|
|
825
|
+
const acceptedRing = snapshot.ring;
|
|
826
|
+
if (!acceptedRing || snapshot.isAnswering) return;
|
|
827
|
+
updateSnapshot({ isAnswering: true });
|
|
828
|
+
const answerRefusal = await answerIncomingAgentVoiceCall(acceptedRing);
|
|
829
|
+
markHandled(acceptedRing);
|
|
830
|
+
updateSnapshot({ isAnswering: false });
|
|
831
|
+
showRefusal(answerRefusal);
|
|
832
|
+
};
|
|
833
|
+
const declineAgentVoiceIncomingRing = () => {
|
|
834
|
+
const declinedRing = snapshot.ring;
|
|
835
|
+
if (!declinedRing || snapshot.isAnswering) return;
|
|
836
|
+
markHandled(declinedRing);
|
|
837
|
+
void declineIncomingAgentVoiceCall(declinedRing);
|
|
838
|
+
};
|
|
839
|
+
const useAgentVoiceRingBandHost = (isHosting) => {
|
|
840
|
+
useEffect(() => {
|
|
841
|
+
if (!isHosting) return;
|
|
842
|
+
updateSnapshot({ bandHostCount: snapshot.bandHostCount + 1 });
|
|
843
|
+
return () => updateSnapshot({ bandHostCount: snapshot.bandHostCount - 1 });
|
|
844
|
+
}, [isHosting]);
|
|
845
|
+
};
|
|
846
|
+
const useAgentVoiceRingCover = (isCovering) => {
|
|
847
|
+
useEffect(() => {
|
|
848
|
+
if (!isCovering) return;
|
|
849
|
+
updateSnapshot({ ringCoverCount: snapshot.ringCoverCount + 1 });
|
|
850
|
+
return () => updateSnapshot({ ringCoverCount: snapshot.ringCoverCount - 1 });
|
|
851
|
+
}, [isCovering]);
|
|
852
|
+
};
|
|
853
|
+
const DEFAULT_CALLER_LABEL_TEXT_KEY = textKey("%agentName% wants to talk");
|
|
854
|
+
const CALLER_LABEL_TEXT_KEYS_BY_KEY = {
|
|
855
|
+
"%agentName% is calling you": DEFAULT_CALLER_LABEL_TEXT_KEY,
|
|
856
|
+
"%agentName% wants to talk": DEFAULT_CALLER_LABEL_TEXT_KEY
|
|
857
|
+
};
|
|
858
|
+
const pickAgentVoiceCallerLabelTextKey = (callerLabelKey) => {
|
|
859
|
+
if (callerLabelKey === "") return { labelTextKey: DEFAULT_CALLER_LABEL_TEXT_KEY, isTranslatable: true };
|
|
860
|
+
return Object.prototype.hasOwnProperty.call(CALLER_LABEL_TEXT_KEYS_BY_KEY, callerLabelKey) ? { labelTextKey: CALLER_LABEL_TEXT_KEYS_BY_KEY[callerLabelKey], isTranslatable: true } : { labelTextKey: callerLabelKey, isTranslatable: false };
|
|
861
|
+
};
|
|
862
|
+
const buildAgentVoiceCallerLabel = (ring, translate, agentName) => {
|
|
863
|
+
const { labelTextKey, isTranslatable } = pickAgentVoiceCallerLabelTextKey(ring.callerLabelKey);
|
|
864
|
+
return { text: isTranslatable ? translate(labelTextKey) : DEFAULT_AGENTS_TEXTS.translate(labelTextKey, { agentName }) };
|
|
865
|
+
};
|
|
866
|
+
const RING_BURST_SECONDS = 1.2;
|
|
867
|
+
const RING_PERIOD_MS = 3e3;
|
|
868
|
+
const RING_FREQUENCIES_HZ = [440, 480];
|
|
869
|
+
const RING_VOLUME = 0.06;
|
|
870
|
+
const useAgentVoiceRingTone = (isRinging) => {
|
|
871
|
+
useEffect(() => {
|
|
872
|
+
if (!isRinging) return;
|
|
873
|
+
const userActivation = navigator.userActivation;
|
|
874
|
+
if (userActivation !== void 0 && !userActivation.hasBeenActive) return;
|
|
875
|
+
if (typeof AudioContext === "undefined") return;
|
|
876
|
+
const audioContext = new AudioContext();
|
|
877
|
+
if (audioContext.state === "suspended") void audioContext.resume().catch(() => void 0);
|
|
878
|
+
const playRingBurst = () => {
|
|
879
|
+
if (audioContext.state !== "running") return;
|
|
880
|
+
const startsAt = audioContext.currentTime;
|
|
881
|
+
const gain = audioContext.createGain();
|
|
882
|
+
gain.gain.setValueAtTime(RING_VOLUME, startsAt);
|
|
883
|
+
gain.gain.setValueAtTime(RING_VOLUME, startsAt + RING_BURST_SECONDS - 0.05);
|
|
884
|
+
gain.gain.linearRampToValueAtTime(0, startsAt + RING_BURST_SECONDS);
|
|
885
|
+
gain.connect(audioContext.destination);
|
|
886
|
+
RING_FREQUENCIES_HZ.forEach((frequencyHz) => {
|
|
887
|
+
const oscillator = audioContext.createOscillator();
|
|
888
|
+
oscillator.frequency.value = frequencyHz;
|
|
889
|
+
oscillator.connect(gain);
|
|
890
|
+
oscillator.start(startsAt);
|
|
891
|
+
oscillator.stop(startsAt + RING_BURST_SECONDS);
|
|
892
|
+
});
|
|
893
|
+
};
|
|
894
|
+
playRingBurst();
|
|
895
|
+
const ringTimer = window.setInterval(playRingBurst, RING_PERIOD_MS);
|
|
896
|
+
return () => {
|
|
897
|
+
window.clearInterval(ringTimer);
|
|
898
|
+
void audioContext.close().catch(() => void 0);
|
|
899
|
+
};
|
|
900
|
+
}, [isRinging]);
|
|
901
|
+
};
|
|
902
|
+
const useFollowAgentVoiceCallConversation = (onConversationOfCallChanged) => {
|
|
903
|
+
const callPhase = useAgentVoiceCallValue((call) => call.phase);
|
|
904
|
+
const callId = useAgentVoiceCallValue((call) => call.callId);
|
|
905
|
+
const callConversationId = useAgentVoiceCallValue((call) => call.conversationId);
|
|
906
|
+
const callAgentSpaceId = useAgentVoiceCallValue((call) => call.agentSpaceId);
|
|
907
|
+
const reportedCallAndConversationRef = useRef(void 0);
|
|
908
|
+
useEffect(() => {
|
|
909
|
+
if (onConversationOfCallChanged === void 0) return;
|
|
910
|
+
if (!isAgentVoiceCallActive(callPhase) || callId === void 0 || callConversationId === void 0) return;
|
|
911
|
+
const callAndConversation = `${callId}:${callConversationId}`;
|
|
912
|
+
if (reportedCallAndConversationRef.current === callAndConversation) return;
|
|
913
|
+
reportedCallAndConversationRef.current = callAndConversation;
|
|
914
|
+
onConversationOfCallChanged(callConversationId, callAgentSpaceId);
|
|
915
|
+
}, [callPhase, callId, callConversationId, callAgentSpaceId, onConversationOfCallChanged]);
|
|
916
|
+
};
|
|
917
|
+
const AgentVoiceCallContext = createContext({ ringSource: void 0 });
|
|
918
|
+
const useAgentVoiceRingSource = () => useContext(AgentVoiceCallContext).ringSource;
|
|
919
|
+
const useAgentVoiceTranslateText = () => {
|
|
920
|
+
const texts = useAgentsTexts();
|
|
921
|
+
return useCallback(
|
|
922
|
+
(key, replacements) => texts.translate(key, { agentName: getAgentDisplayName(), ...replacements }),
|
|
923
|
+
[texts]
|
|
924
|
+
);
|
|
925
|
+
};
|
|
926
|
+
const AgentVoiceCallProvider = (props) => {
|
|
927
|
+
const { api, ringSource, onConversationOfCallChanged, children } = props;
|
|
928
|
+
useEffect(() => {
|
|
929
|
+
bindAgentVoiceApi(api);
|
|
930
|
+
}, [api]);
|
|
931
|
+
useAgentVoiceCallServerEnd();
|
|
932
|
+
useFollowAgentVoiceCallConversation(onConversationOfCallChanged);
|
|
933
|
+
const contextValue = useMemo(() => ({ ringSource }), [ringSource]);
|
|
934
|
+
return /* @__PURE__ */ jsx(AgentVoiceCallContext.Provider, { value: contextValue, children });
|
|
935
|
+
};
|
|
936
|
+
const startButton = "agents_startButton_DMqIXK";
|
|
937
|
+
const styles$5 = {
|
|
938
|
+
startButton
|
|
939
|
+
};
|
|
940
|
+
const AgentVoiceChatStartButton = (props) => {
|
|
941
|
+
const { agentSpaceId, conversationId, disabled = false, testId = "agent-voice-chat-start" } = props;
|
|
942
|
+
const translateText = useAgentVoiceTranslateText();
|
|
943
|
+
const isCallActive = useIsAgentVoiceCallActive();
|
|
944
|
+
const label2 = translateText("Talk to %agentName%");
|
|
945
|
+
return /* @__PURE__ */ jsx(
|
|
946
|
+
"button",
|
|
947
|
+
{
|
|
948
|
+
type: "button",
|
|
949
|
+
className: styles$5.startButton,
|
|
950
|
+
onClick: () => void startAgentVoiceCall({ agentSpaceId, conversationId }),
|
|
951
|
+
disabled: disabled || isCallActive,
|
|
952
|
+
"aria-label": label2,
|
|
953
|
+
title: label2,
|
|
954
|
+
"data-testid": testId,
|
|
955
|
+
children: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 18 })
|
|
956
|
+
}
|
|
957
|
+
);
|
|
958
|
+
};
|
|
959
|
+
const icon = "agents_icon_VX-p0I";
|
|
960
|
+
const styles$4 = {
|
|
961
|
+
icon
|
|
962
|
+
};
|
|
963
|
+
const renderLineIcon = (size, paths) => /* @__PURE__ */ jsx("svg", { className: styles$4.icon, width: size, height: size, viewBox: "0 0 24 24", "aria-hidden": true, focusable: "false", children: paths });
|
|
964
|
+
const AgentVoiceMicrophoneIcon = (props) => renderLineIcon(
|
|
965
|
+
props.size ?? 16,
|
|
966
|
+
/* @__PURE__ */ jsx("path", { d: "M12 3.5a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0v-5a3 3 0 0 0-3-3ZM5.5 11.5a6.5 6.5 0 0 0 13 0M12 18v2.5" })
|
|
967
|
+
);
|
|
968
|
+
const AgentVoiceHangUpIcon = (props) => renderLineIcon(
|
|
969
|
+
props.size ?? 16,
|
|
970
|
+
/* @__PURE__ */ jsx("path", { d: "M3.5 14.5c4.7-4.7 12.3-4.7 17 0l-2.2 2.2-3.1-1.4v-2.4a9.6 9.6 0 0 0-6.4 0v2.4l-3.1 1.4-2.2-2.2Z" })
|
|
971
|
+
);
|
|
972
|
+
const AgentVoiceCloseIcon = (props) => renderLineIcon(props.size ?? 16, /* @__PURE__ */ jsx("path", { d: "M6 6l12 12M18 6 6 18" }));
|
|
973
|
+
const endedAgentVoiceCallTitleTextKey = (call) => {
|
|
974
|
+
if (call.endReason === AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT) return textKey("%agentName% ended the voice chat");
|
|
975
|
+
if (call.endReason === AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED) return textKey("Voice chat limit reached");
|
|
976
|
+
return textKey("Voice chat ended");
|
|
977
|
+
};
|
|
978
|
+
const agentVoiceCallOutcomeTitleTextKey = (call) => {
|
|
979
|
+
if (call.phase === "failed") return textKey("Voice chat failed");
|
|
980
|
+
return call.connectedAtMs !== void 0 ? endedAgentVoiceCallTitleTextKey(call) : textKey("Voice chat cancelled");
|
|
981
|
+
};
|
|
982
|
+
const band = "agents_band_zaFYNK";
|
|
983
|
+
const content = "agents_content_q4jRea";
|
|
984
|
+
const spot$1 = "agents_spot_wdOO-R";
|
|
985
|
+
const who = "agents_who_SEmzYy";
|
|
986
|
+
const status = "agents_status_saTxLl";
|
|
987
|
+
const title = "agents_title_PBN6ka";
|
|
988
|
+
const time = "agents_time_aaWlsN";
|
|
989
|
+
const actions$1 = "agents_actions_uyJzPl";
|
|
990
|
+
const action$1 = "agents_action_z96Tb1";
|
|
991
|
+
const actionLabel = "agents_actionLabel_ItbQmp";
|
|
992
|
+
const styles$3 = {
|
|
993
|
+
band,
|
|
994
|
+
content,
|
|
995
|
+
spot: spot$1,
|
|
996
|
+
who,
|
|
997
|
+
status,
|
|
998
|
+
title,
|
|
999
|
+
time,
|
|
1000
|
+
actions: actions$1,
|
|
1001
|
+
action: action$1,
|
|
1002
|
+
actionLabel
|
|
1003
|
+
};
|
|
1004
|
+
const TURN_STATUS_TEXT_KEYS = {
|
|
1005
|
+
connecting: textKey("Connecting…"),
|
|
1006
|
+
muted: textKey("You’re muted"),
|
|
1007
|
+
silentMicrophone: textKey("I can’t hear you — is your microphone on?"),
|
|
1008
|
+
agent: textKey("%agentName% is speaking"),
|
|
1009
|
+
owner: textKey("You’re speaking"),
|
|
1010
|
+
thinking: textKey("%agentName% is thinking"),
|
|
1011
|
+
listening: textKey("%agentName% is listening")
|
|
1012
|
+
};
|
|
1013
|
+
const AgentVoiceBandAction = (props) => {
|
|
1014
|
+
const { label: label2, icon: icon2, onClick, testId, iconOnly = false, pressed, variant, disabled = false } = props;
|
|
1015
|
+
return /* @__PURE__ */ jsxs(
|
|
1016
|
+
"button",
|
|
1017
|
+
{
|
|
1018
|
+
type: "button",
|
|
1019
|
+
className: styles$3.action,
|
|
1020
|
+
onClick,
|
|
1021
|
+
"aria-pressed": pressed,
|
|
1022
|
+
disabled,
|
|
1023
|
+
"data-variant": variant,
|
|
1024
|
+
"data-icon-only": iconOnly || void 0,
|
|
1025
|
+
"data-testid": testId,
|
|
1026
|
+
children: [
|
|
1027
|
+
icon2,
|
|
1028
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.actionLabel, children: label2 })
|
|
1029
|
+
]
|
|
1030
|
+
}
|
|
1031
|
+
);
|
|
1032
|
+
};
|
|
1033
|
+
const AgentVoiceCallBandView = (props) => {
|
|
1034
|
+
const { call, elapsedSeconds, onStartVoiceChat, incoming, agentSpot } = props;
|
|
1035
|
+
const translateText = useAgentVoiceTranslateText();
|
|
1036
|
+
const duration = formatAgentVoiceCallDuration(elapsedSeconds);
|
|
1037
|
+
const agentName = getAgentDisplayName();
|
|
1038
|
+
const spot2 = agentSpot === void 0 || agentSpot === null ? null : /* @__PURE__ */ jsx("div", { className: styles$3.spot, children: agentSpot });
|
|
1039
|
+
if (isAgentVoiceCallActive(call.phase)) {
|
|
1040
|
+
return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": call.phase, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
|
|
1041
|
+
spot2,
|
|
1042
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.who, "aria-live": "polite", children: [
|
|
1043
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.title, children: agentName }),
|
|
1044
|
+
call.phase === "live" && /* @__PURE__ */ jsx("span", { className: styles$3.time, children: duration }),
|
|
1045
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-status", children: translateText(TURN_STATUS_TEXT_KEYS[turnOfAgentVoiceCall(call)]) })
|
|
1046
|
+
] }),
|
|
1047
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
|
|
1048
|
+
/* @__PURE__ */ jsx(
|
|
1049
|
+
AgentVoiceBandAction,
|
|
1050
|
+
{
|
|
1051
|
+
label: call.isMuted ? translateText("Unmute") : translateText("Mute"),
|
|
1052
|
+
icon: /* @__PURE__ */ jsx(AgentVoiceMicrophoneIcon, {}),
|
|
1053
|
+
onClick: toggleAgentVoiceCallMute,
|
|
1054
|
+
pressed: call.isMuted,
|
|
1055
|
+
disabled: call.phase !== "live",
|
|
1056
|
+
testId: "agent-voice-call-mute"
|
|
1057
|
+
}
|
|
1058
|
+
),
|
|
1059
|
+
/* @__PURE__ */ jsx(
|
|
1060
|
+
AgentVoiceBandAction,
|
|
1061
|
+
{
|
|
1062
|
+
label: translateText("End"),
|
|
1063
|
+
icon: /* @__PURE__ */ jsx(AgentVoiceHangUpIcon, {}),
|
|
1064
|
+
onClick: () => hangUpAgentVoiceCall(),
|
|
1065
|
+
variant: "end",
|
|
1066
|
+
testId: "agent-voice-call-end"
|
|
1067
|
+
}
|
|
1068
|
+
)
|
|
1069
|
+
] })
|
|
1070
|
+
] }, call.phase) });
|
|
1071
|
+
}
|
|
1072
|
+
if (incoming?.ring) {
|
|
1073
|
+
const callerLabel = incoming.callerLabel ?? buildAgentVoiceCallerLabel(incoming.ring, translateText, agentName);
|
|
1074
|
+
return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": "incoming", children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
|
|
1075
|
+
spot2,
|
|
1076
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.who, role: "alert", children: [
|
|
1077
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.title, children: callerLabel.text }),
|
|
1078
|
+
callerLabel.detail ? /* @__PURE__ */ jsx("span", { className: styles$3.status, children: callerLabel.detail }) : null
|
|
1079
|
+
] }),
|
|
1080
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
|
|
1081
|
+
/* @__PURE__ */ jsx(
|
|
1082
|
+
AgentVoiceBandAction,
|
|
1083
|
+
{
|
|
1084
|
+
label: translateText("Decline"),
|
|
1085
|
+
icon: /* @__PURE__ */ jsx(AgentVoiceCloseIcon, {}),
|
|
1086
|
+
onClick: incoming.onDecline,
|
|
1087
|
+
variant: "end",
|
|
1088
|
+
disabled: incoming.isAnswering,
|
|
1089
|
+
testId: "agent-voice-call-incoming-decline"
|
|
1090
|
+
}
|
|
1091
|
+
),
|
|
1092
|
+
/* @__PURE__ */ jsx(
|
|
1093
|
+
AgentVoiceBandAction,
|
|
1094
|
+
{
|
|
1095
|
+
label: translateText("Accept"),
|
|
1096
|
+
icon: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 16 }),
|
|
1097
|
+
onClick: incoming.onAccept,
|
|
1098
|
+
variant: "accept",
|
|
1099
|
+
disabled: incoming.isAnswering,
|
|
1100
|
+
testId: "agent-voice-call-incoming-accept"
|
|
1101
|
+
}
|
|
1102
|
+
)
|
|
1103
|
+
] })
|
|
1104
|
+
] }, "incoming") });
|
|
1105
|
+
}
|
|
1106
|
+
if (incoming?.refusal && call.phase === "idle") {
|
|
1107
|
+
return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": "refused", children: /* @__PURE__ */ jsx("div", { className: styles$3.content, children: /* @__PURE__ */ jsx("div", { className: styles$3.who, role: "status", children: /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-incoming-refusal", children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[incoming.refusal]) }) }) }, "refused") });
|
|
1108
|
+
}
|
|
1109
|
+
if (call.phase !== "ended" && call.phase !== "failed") return null;
|
|
1110
|
+
const wasConnected = call.connectedAtMs !== void 0;
|
|
1111
|
+
const titleTextKey = agentVoiceCallOutcomeTitleTextKey(call);
|
|
1112
|
+
return /* @__PURE__ */ jsx("div", { className: styles$3.band, "data-testid": "agent-voice-call-band", "data-phase": call.phase, "data-end-reason": call.endReason, children: /* @__PURE__ */ jsxs("div", { className: styles$3.content, children: [
|
|
1113
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.who, "aria-live": "polite", children: [
|
|
1114
|
+
/* @__PURE__ */ jsx(
|
|
1115
|
+
"span",
|
|
1116
|
+
{
|
|
1117
|
+
className: styles$3.title,
|
|
1118
|
+
"data-testid": call.phase === "ended" && wasConnected ? "agent-voice-call-ended-status" : void 0,
|
|
1119
|
+
children: translateText(titleTextKey)
|
|
1120
|
+
}
|
|
1121
|
+
),
|
|
1122
|
+
call.phase === "ended" && wasConnected && /* @__PURE__ */ jsx("span", { className: styles$3.time, children: duration }),
|
|
1123
|
+
call.phase === "failed" && call.failureTextKey && /* @__PURE__ */ jsx("span", { className: styles$3.status, "data-testid": "agent-voice-call-failure", children: translateText(call.failureTextKey) })
|
|
1124
|
+
] }),
|
|
1125
|
+
/* @__PURE__ */ jsxs("div", { className: styles$3.actions, children: [
|
|
1126
|
+
/* @__PURE__ */ jsx(
|
|
1127
|
+
AgentVoiceBandAction,
|
|
1128
|
+
{
|
|
1129
|
+
label: call.phase === "failed" ? translateText("Try again") : translateText("Talk with %agentName% again"),
|
|
1130
|
+
icon: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 16 }),
|
|
1131
|
+
onClick: onStartVoiceChat,
|
|
1132
|
+
variant: "accept",
|
|
1133
|
+
testId: "agent-voice-call-start-again"
|
|
1134
|
+
}
|
|
1135
|
+
),
|
|
1136
|
+
/* @__PURE__ */ jsx(
|
|
1137
|
+
AgentVoiceBandAction,
|
|
1138
|
+
{
|
|
1139
|
+
label: translateText("Close"),
|
|
1140
|
+
icon: /* @__PURE__ */ jsx(AgentVoiceCloseIcon, {}),
|
|
1141
|
+
onClick: dismissAgentVoiceCallOutcome,
|
|
1142
|
+
iconOnly: true,
|
|
1143
|
+
testId: "agent-voice-call-band-close"
|
|
1144
|
+
}
|
|
1145
|
+
)
|
|
1146
|
+
] })
|
|
1147
|
+
] }, call.phase) });
|
|
1148
|
+
};
|
|
1149
|
+
const AgentVoiceCallBand = (props) => {
|
|
1150
|
+
const { renderAgentSpot, agentSpaceId, isPresented = true } = props;
|
|
1151
|
+
const liveCall = useAgentVoiceCallSnapshot();
|
|
1152
|
+
const call = isAgentVoiceCallShownInAgentSpace(liveCall, agentSpaceId) ? liveCall : IDLE_AGENT_VOICE_CALL;
|
|
1153
|
+
const elapsedSeconds = useAgentVoiceCallElapsedSeconds(call);
|
|
1154
|
+
const { ring, callerLabel, isAnswering, refusal } = useAgentVoiceIncomingRing();
|
|
1155
|
+
useAgentVoiceRingBandHost(isPresented);
|
|
1156
|
+
return /* @__PURE__ */ jsx(
|
|
1157
|
+
AgentVoiceCallBandView,
|
|
1158
|
+
{
|
|
1159
|
+
call,
|
|
1160
|
+
elapsedSeconds,
|
|
1161
|
+
agentSpot: renderAgentSpot?.(call),
|
|
1162
|
+
onStartVoiceChat: () => void startAgentVoiceCall({ agentSpaceId: call.agentSpaceId ?? agentSpaceId, conversationId: call.conversationId }),
|
|
1163
|
+
incoming: {
|
|
1164
|
+
ring,
|
|
1165
|
+
callerLabel,
|
|
1166
|
+
isAnswering,
|
|
1167
|
+
refusal,
|
|
1168
|
+
onAccept: () => void acceptAgentVoiceIncomingRing(),
|
|
1169
|
+
onDecline: declineAgentVoiceIncomingRing
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
);
|
|
1173
|
+
};
|
|
1174
|
+
const highestIndexInConversationOf = (messages) => messages.reduce((highestIndex, message) => Math.max(highestIndex, message.indexInConversation ?? -1), -1);
|
|
1175
|
+
const savedMessagesOfTheVoiceChat = (messages, highestIndexBeforeVoiceChat) => [...messages].filter(
|
|
1176
|
+
(message) => (message.role === "ASSISTANT" || message.role === "USER") && typeof message.message === "string" && (message.indexInConversation ?? -1) > highestIndexBeforeVoiceChat
|
|
1177
|
+
).sort((first, second) => (first.indexInConversation ?? 0) - (second.indexInConversation ?? 0)).map((message) => ({ speaker: message.role === "ASSISTANT" ? "agent" : "owner", text: message.message }));
|
|
1178
|
+
const captions = "agents_captions_PCkZmI";
|
|
1179
|
+
const line = "agents_line_411mUr";
|
|
1180
|
+
const styles$2 = {
|
|
1181
|
+
captions,
|
|
1182
|
+
line
|
|
1183
|
+
};
|
|
1184
|
+
const NO_MESSAGES = [];
|
|
1185
|
+
const selectMessages = (state) => state.messages;
|
|
1186
|
+
const AgentVoiceCallCaptionLines = (props) => {
|
|
1187
|
+
const { call, ownerMessageTheme } = props;
|
|
1188
|
+
const chatStore = useOptionalAgentsChatStore();
|
|
1189
|
+
const messages = useAgentsChatSelector(chatStore, selectMessages, null) ?? NO_MESSAGES;
|
|
1190
|
+
const [highestIndexBeforeVoiceChat, setHighestIndexBeforeVoiceChat] = useState(void 0);
|
|
1191
|
+
useEffect(() => {
|
|
1192
|
+
if (highestIndexBeforeVoiceChat === void 0) setHighestIndexBeforeVoiceChat(highestIndexInConversationOf(messages));
|
|
1193
|
+
}, [highestIndexBeforeVoiceChat, messages]);
|
|
1194
|
+
const unsavedLines = useMemo(
|
|
1195
|
+
() => highestIndexBeforeVoiceChat === void 0 ? [] : buildUnsavedAgentVoiceCallLines(call.lines, savedMessagesOfTheVoiceChat(messages, highestIndexBeforeVoiceChat)),
|
|
1196
|
+
[call.lines, messages, highestIndexBeforeVoiceChat]
|
|
1197
|
+
);
|
|
1198
|
+
return /* @__PURE__ */ jsx("div", { className: styles$2.captions, "data-testid": "agent-voice-call-captions", children: unsavedLines.map(
|
|
1199
|
+
(line2) => line2.speaker === "agent" ? /* @__PURE__ */ jsx("div", { className: styles$2.line, "data-testid": "agent-voice-call-caption-agent", children: /* @__PURE__ */ jsx(ConversationMessageWidgets, { message: line2.text, interactive: false, justDelivered: false, hideAssistantMeta: true }) }, line2.id) : /* @__PURE__ */ jsx("div", { className: styles$2.line, "data-testid": "agent-voice-call-caption-owner", children: /* @__PURE__ */ jsx(ConversationMessageUser, { text: line2.text, theme: ownerMessageTheme }) }, line2.id)
|
|
1200
|
+
) });
|
|
1201
|
+
};
|
|
1202
|
+
const AgentVoiceCallCaptions = (props) => {
|
|
1203
|
+
const { agentSpaceId, ownerMessageTheme } = props;
|
|
1204
|
+
const call = useAgentVoiceCallSnapshot();
|
|
1205
|
+
if (!isAgentVoiceCallActive(call.phase) || !isAgentVoiceCallShownInAgentSpace(call, agentSpaceId)) return null;
|
|
1206
|
+
return /* @__PURE__ */ jsx(AgentVoiceCallCaptionLines, { call, ownerMessageTheme });
|
|
1207
|
+
};
|
|
1208
|
+
const glowVoiceOfAgentVoiceCallTurn = (turn) => {
|
|
1209
|
+
if (turn === "agent") return "agent";
|
|
1210
|
+
if (turn === "owner") return "owner";
|
|
1211
|
+
if (turn === "thinking" || turn === "connecting") return "thinking";
|
|
1212
|
+
return "quiet";
|
|
1213
|
+
};
|
|
1214
|
+
const glow = "agents_glow_kSd-yQ";
|
|
1215
|
+
const halo = "agents_halo_KYezvE";
|
|
1216
|
+
const edge = "agents_edge_QQWtWn";
|
|
1217
|
+
const styles$1 = {
|
|
1218
|
+
glow,
|
|
1219
|
+
halo,
|
|
1220
|
+
edge
|
|
1221
|
+
};
|
|
1222
|
+
const CANVAS_PADDING_PX = 200;
|
|
1223
|
+
const REST_REACH_PX = 9;
|
|
1224
|
+
const LOUD_REACH_PX = 42;
|
|
1225
|
+
const EDGE_STEP_PX = 4;
|
|
1226
|
+
const BURST_SECONDS = 1;
|
|
1227
|
+
const BURST_REACH_PX = 22;
|
|
1228
|
+
const AGENT_MS_PER_WORD = 330;
|
|
1229
|
+
const OWNER_MS_PER_SYLLABLE = 260;
|
|
1230
|
+
const GLOW_COLOUR_PROPERTIES = [
|
|
1231
|
+
["--agents-voice-glow-color-1", "#00495d"],
|
|
1232
|
+
["--agents-voice-glow-color-2", "#29ecfa"],
|
|
1233
|
+
["--agents-voice-glow-color-3", "#e0c9fd"],
|
|
1234
|
+
["--agents-voice-glow-color-4", "#12ffff"],
|
|
1235
|
+
["--agents-voice-glow-color-1", "#00495d"]
|
|
1236
|
+
];
|
|
1237
|
+
const AgentVoiceInputGlowCanvases = () => {
|
|
1238
|
+
const voice = useAgentVoiceCallValue(
|
|
1239
|
+
(call) => isAgentVoiceCallActive(call.phase) ? glowVoiceOfAgentVoiceCallTurn(turnOfAgentVoiceCall(call)) : "quiet"
|
|
1240
|
+
);
|
|
1241
|
+
const boxRef = useRef(null);
|
|
1242
|
+
const edgeCanvasRef = useRef(null);
|
|
1243
|
+
const haloCanvasRef = useRef(null);
|
|
1244
|
+
const voiceRef = useRef(voice);
|
|
1245
|
+
voiceRef.current = voice;
|
|
1246
|
+
const burstStartedAtSecondsRef = useRef(Number.NEGATIVE_INFINITY);
|
|
1247
|
+
useEffect(() => {
|
|
1248
|
+
const box = boxRef.current;
|
|
1249
|
+
const edgeCanvas = edgeCanvasRef.current;
|
|
1250
|
+
const haloCanvas = haloCanvasRef.current;
|
|
1251
|
+
const edgeContext = edgeCanvas?.getContext("2d");
|
|
1252
|
+
const haloContext = haloCanvas?.getContext("2d");
|
|
1253
|
+
const maskCanvas = document.createElement("canvas");
|
|
1254
|
+
const maskContext = maskCanvas.getContext("2d");
|
|
1255
|
+
if (!box || !edgeCanvas || !haloCanvas || !edgeContext || !haloContext || !maskContext) return;
|
|
1256
|
+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1257
|
+
const colourProbe = document.createElement("span");
|
|
1258
|
+
box.appendChild(colourProbe);
|
|
1259
|
+
const glowColours = GLOW_COLOUR_PROPERTIES.map(([property, defaultColour]) => {
|
|
1260
|
+
colourProbe.style.color = `var(${property}, ${defaultColour})`;
|
|
1261
|
+
return getComputedStyle(colourProbe).color;
|
|
1262
|
+
});
|
|
1263
|
+
colourProbe.remove();
|
|
1264
|
+
const field = box.parentElement;
|
|
1265
|
+
const startBurst = () => {
|
|
1266
|
+
burstStartedAtSecondsRef.current = performance.now() / 1e3;
|
|
1267
|
+
};
|
|
1268
|
+
field?.addEventListener("focusin", startBurst);
|
|
1269
|
+
let width = 0;
|
|
1270
|
+
let height = 0;
|
|
1271
|
+
let pixelRatio = 1;
|
|
1272
|
+
const resizeCanvases = () => {
|
|
1273
|
+
const boxRect = box.getBoundingClientRect();
|
|
1274
|
+
width = boxRect.width;
|
|
1275
|
+
height = boxRect.height;
|
|
1276
|
+
pixelRatio = Math.min(2, window.devicePixelRatio || 1);
|
|
1277
|
+
[edgeCanvas, haloCanvas, maskCanvas].forEach((canvas) => {
|
|
1278
|
+
canvas.width = Math.round((width + CANVAS_PADDING_PX * 2) * pixelRatio);
|
|
1279
|
+
canvas.height = Math.round((height + CANVAS_PADDING_PX * 2) * pixelRatio);
|
|
1280
|
+
});
|
|
1281
|
+
};
|
|
1282
|
+
let loudness = 0;
|
|
1283
|
+
let soundSide = -1;
|
|
1284
|
+
let colourTurn = 0;
|
|
1285
|
+
let lastFrameSeconds = 0;
|
|
1286
|
+
let animationFrameId = 0;
|
|
1287
|
+
const drawFrame = (frameMs) => {
|
|
1288
|
+
const frameSeconds = frameMs / 1e3;
|
|
1289
|
+
const frameDeltaSeconds = lastFrameSeconds ? Math.min(0.1, frameSeconds - lastFrameSeconds) : 0.016;
|
|
1290
|
+
lastFrameSeconds = frameSeconds;
|
|
1291
|
+
const currentVoice = voiceRef.current;
|
|
1292
|
+
const syllable = (periodMs) => Math.abs(Math.sin(Math.PI * frameMs / periodMs));
|
|
1293
|
+
const targetLoudness = currentVoice === "agent" ? (0.5 + 0.5 * syllable(AGENT_MS_PER_WORD)) * (0.85 + 0.15 * Math.sin(frameSeconds * 23.7)) : currentVoice === "owner" ? 0.42 * (0.55 + 0.45 * syllable(OWNER_MS_PER_SYLLABLE)) : currentVoice === "thinking" ? 0.12 * (0.5 + 0.5 * Math.sin(frameSeconds * 2.4)) : 0;
|
|
1294
|
+
const loudnessTimeConstant = targetLoudness > loudness ? 0.05 : 0.2;
|
|
1295
|
+
loudness += (targetLoudness - loudness) * (1 - Math.exp(-frameDeltaSeconds / loudnessTimeConstant));
|
|
1296
|
+
soundSide += ((currentVoice === "owner" ? 1 : -1) - soundSide) * (1 - Math.exp(-frameDeltaSeconds / 0.35));
|
|
1297
|
+
colourTurn += frameDeltaSeconds * (0.1 + 0.4 * loudness);
|
|
1298
|
+
const burstProgress = (frameSeconds - burstStartedAtSecondsRef.current) / BURST_SECONDS;
|
|
1299
|
+
const burst = burstProgress >= 0 && burstProgress < 1 ? Math.pow(1 - burstProgress, 1.4) * Math.min(1, burstProgress / 0.06) : 0;
|
|
1300
|
+
const cornerRadius = Math.min(24, height / 2);
|
|
1301
|
+
const reachAt = (x, isUpward) => {
|
|
1302
|
+
const distanceFromMiddle = Math.abs(x - width / 2);
|
|
1303
|
+
const nearMiddle = 0.12 + 0.88 * Math.exp(-((distanceFromMiddle / (width * 0.3)) ** 2));
|
|
1304
|
+
const wave = Math.abs(
|
|
1305
|
+
0.6 * Math.sin(distanceFromMiddle * 0.01375 - frameSeconds * 3.2 + (isUpward ? 0 : 1.7)) + 0.4 * Math.sin(distanceFromMiddle * 0.0325 - frameSeconds * 5.1 + 1.3)
|
|
1306
|
+
) * (0.65 + 0.35 * Math.sin(distanceFromMiddle * 475e-5 + frameSeconds * 1.05));
|
|
1307
|
+
const fromThisSide = isUpward ? (1 - soundSide) / 2 : (1 + soundSide) / 2;
|
|
1308
|
+
const loudReach = LOUD_REACH_PX * loudness * nearMiddle * wave * (0.25 + 0.75 * fromThisSide);
|
|
1309
|
+
const burstReach = BURST_REACH_PX * burst * (0.45 + 0.55 * Math.exp(-((distanceFromMiddle / (width * 0.6)) ** 2)));
|
|
1310
|
+
return REST_REACH_PX + loudReach + burstReach;
|
|
1311
|
+
};
|
|
1312
|
+
const canvasWidth = width + CANVAS_PADDING_PX * 2;
|
|
1313
|
+
const canvasHeight = height + CANVAS_PADDING_PX * 2;
|
|
1314
|
+
edgeContext.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
1315
|
+
edgeContext.globalCompositeOperation = "source-over";
|
|
1316
|
+
edgeContext.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
1317
|
+
const colourGradient = edgeContext.createConicGradient(
|
|
1318
|
+
colourTurn * Math.PI * 2,
|
|
1319
|
+
CANVAS_PADDING_PX + width / 2,
|
|
1320
|
+
CANVAS_PADDING_PX + height / 2
|
|
1321
|
+
);
|
|
1322
|
+
glowColours.forEach((colour, index) => colourGradient.addColorStop(index / (glowColours.length - 1), colour));
|
|
1323
|
+
edgeContext.fillStyle = colourGradient;
|
|
1324
|
+
const topEdgePoints = [];
|
|
1325
|
+
const bottomEdgePoints = [];
|
|
1326
|
+
for (let x = -CANVAS_PADDING_PX; x <= width + CANVAS_PADDING_PX; x += EDGE_STEP_PX) {
|
|
1327
|
+
let fieldTop = height / 2;
|
|
1328
|
+
let fieldBottom = height / 2;
|
|
1329
|
+
if (x >= 0 && x <= width) {
|
|
1330
|
+
const cornerInset = x < cornerRadius ? cornerRadius - x : x > width - cornerRadius ? x - (width - cornerRadius) : 0;
|
|
1331
|
+
const cornerDrop = cornerRadius - Math.sqrt(Math.max(0, cornerRadius ** 2 - cornerInset ** 2));
|
|
1332
|
+
fieldTop = cornerDrop;
|
|
1333
|
+
fieldBottom = height - cornerDrop;
|
|
1334
|
+
}
|
|
1335
|
+
const distancePastEnd = x < 0 ? -x : x > width ? x - width : 0;
|
|
1336
|
+
const closing = Math.exp(-distancePastEnd / 10);
|
|
1337
|
+
topEdgePoints.push([CANVAS_PADDING_PX + x, CANVAS_PADDING_PX + fieldTop - reachAt(x, true) * closing]);
|
|
1338
|
+
bottomEdgePoints.push([CANVAS_PADDING_PX + x, CANVAS_PADDING_PX + fieldBottom + reachAt(x, false) * closing]);
|
|
1339
|
+
}
|
|
1340
|
+
edgeContext.beginPath();
|
|
1341
|
+
topEdgePoints.forEach(([x, y], index) => index ? edgeContext.lineTo(x, y) : edgeContext.moveTo(x, y));
|
|
1342
|
+
[...bottomEdgePoints].reverse().forEach(([x, y]) => edgeContext.lineTo(x, y));
|
|
1343
|
+
edgeContext.closePath();
|
|
1344
|
+
edgeContext.fill();
|
|
1345
|
+
maskContext.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
1346
|
+
maskContext.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
1347
|
+
maskContext.shadowColor = "black";
|
|
1348
|
+
maskContext.shadowBlur = ((REST_REACH_PX + LOUD_REACH_PX * loudness + BURST_REACH_PX * burst) * 1.5 + 10) * pixelRatio;
|
|
1349
|
+
maskContext.fillStyle = "black";
|
|
1350
|
+
maskContext.beginPath();
|
|
1351
|
+
maskContext.roundRect(CANVAS_PADDING_PX, CANVAS_PADDING_PX, width, height, cornerRadius);
|
|
1352
|
+
maskContext.fill();
|
|
1353
|
+
edgeContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
1354
|
+
edgeContext.globalCompositeOperation = "destination-in";
|
|
1355
|
+
edgeContext.drawImage(maskCanvas, 0, 0);
|
|
1356
|
+
edgeContext.globalCompositeOperation = "source-over";
|
|
1357
|
+
haloContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
1358
|
+
haloContext.clearRect(0, 0, haloCanvas.width, haloCanvas.height);
|
|
1359
|
+
haloContext.drawImage(edgeCanvas, 0, 0);
|
|
1360
|
+
if (!prefersReducedMotion) animationFrameId = requestAnimationFrame(drawFrame);
|
|
1361
|
+
};
|
|
1362
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
1363
|
+
resizeCanvases();
|
|
1364
|
+
if (prefersReducedMotion) drawFrame(0);
|
|
1365
|
+
});
|
|
1366
|
+
resizeObserver.observe(box);
|
|
1367
|
+
resizeCanvases();
|
|
1368
|
+
animationFrameId = requestAnimationFrame(drawFrame);
|
|
1369
|
+
return () => {
|
|
1370
|
+
cancelAnimationFrame(animationFrameId);
|
|
1371
|
+
resizeObserver.disconnect();
|
|
1372
|
+
field?.removeEventListener("focusin", startBurst);
|
|
1373
|
+
};
|
|
1374
|
+
}, []);
|
|
1375
|
+
return /* @__PURE__ */ jsxs("div", { ref: boxRef, className: styles$1.glow, "aria-hidden": true, "data-testid": "agent-voice-input-glow", children: [
|
|
1376
|
+
/* @__PURE__ */ jsx("canvas", { ref: haloCanvasRef, className: styles$1.halo }),
|
|
1377
|
+
/* @__PURE__ */ jsx("canvas", { ref: edgeCanvasRef, className: styles$1.edge })
|
|
1378
|
+
] });
|
|
1379
|
+
};
|
|
1380
|
+
const AgentVoiceInputGlow = (props) => {
|
|
1381
|
+
const { agentSpaceId } = props;
|
|
1382
|
+
const isCallActiveHere = useIsAgentVoiceCallActive(agentSpaceId);
|
|
1383
|
+
return isCallActiveHere ? /* @__PURE__ */ jsx(AgentVoiceInputGlowCanvases, {}) : null;
|
|
1384
|
+
};
|
|
1385
|
+
const withAgentVoiceIncomingRing = (heldRings, ring) => [...heldRings.filter((heldRing) => heldRing.callId !== ring.callId), ring];
|
|
1386
|
+
const withoutAgentVoiceIncomingRingOfCall = (heldRings, callId) => heldRings.filter((heldRing) => heldRing.callId !== callId);
|
|
1387
|
+
const agentVoiceIncomingRingsInDeadlineAt = (heldRings, nowMs) => {
|
|
1388
|
+
const ringsInDeadline = heldRings.filter((heldRing) => heldRing.ringExpiresAtUnixMs > nowMs);
|
|
1389
|
+
return ringsInDeadline.length === heldRings.length ? heldRings : ringsInDeadline;
|
|
1390
|
+
};
|
|
1391
|
+
const NO_RINGS = [];
|
|
1392
|
+
const useAgentVoiceIncomingRings = (ringSource) => {
|
|
1393
|
+
const [rings, setRings] = useState(NO_RINGS);
|
|
1394
|
+
const [nowMs, setNowMs] = useState(() => Date.now());
|
|
1395
|
+
useEffect(() => {
|
|
1396
|
+
if (ringSource === void 0) return;
|
|
1397
|
+
const unsubscribe = ringSource.subscribe(
|
|
1398
|
+
(ring) => setRings((heldRings) => withAgentVoiceIncomingRing(heldRings, ring)),
|
|
1399
|
+
(callId) => setRings((heldRings) => withoutAgentVoiceIncomingRingOfCall(heldRings, callId))
|
|
1400
|
+
);
|
|
1401
|
+
return () => {
|
|
1402
|
+
unsubscribe();
|
|
1403
|
+
setRings(NO_RINGS);
|
|
1404
|
+
};
|
|
1405
|
+
}, [ringSource]);
|
|
1406
|
+
const hasRings = rings.length > 0;
|
|
1407
|
+
useEffect(() => {
|
|
1408
|
+
if (!hasRings) return;
|
|
1409
|
+
setNowMs(Date.now());
|
|
1410
|
+
const clockTimer = window.setInterval(() => {
|
|
1411
|
+
const tickMs = Date.now();
|
|
1412
|
+
setNowMs(tickMs);
|
|
1413
|
+
setRings((heldRings) => agentVoiceIncomingRingsInDeadlineAt(heldRings, tickMs));
|
|
1414
|
+
}, 1e3);
|
|
1415
|
+
return () => window.clearInterval(clockTimer);
|
|
1416
|
+
}, [hasRings]);
|
|
1417
|
+
return { rings, nowMs };
|
|
1418
|
+
};
|
|
1419
|
+
const incomingCall = "agents_incomingCall_e0NnBQ";
|
|
1420
|
+
const spot = "agents_spot_AWueCe";
|
|
1421
|
+
const mark = "agents_mark_vjUGG5";
|
|
1422
|
+
const caller = "agents_caller_LkgBXQ";
|
|
1423
|
+
const label = "agents_label_jIKQ1p";
|
|
1424
|
+
const detail = "agents_detail_d1wkjv";
|
|
1425
|
+
const actions = "agents_actions_IQWAo5";
|
|
1426
|
+
const action = "agents_action_TQIDH-";
|
|
1427
|
+
const styles = {
|
|
1428
|
+
incomingCall,
|
|
1429
|
+
spot,
|
|
1430
|
+
mark,
|
|
1431
|
+
caller,
|
|
1432
|
+
label,
|
|
1433
|
+
detail,
|
|
1434
|
+
actions,
|
|
1435
|
+
action
|
|
1436
|
+
};
|
|
1437
|
+
const AgentVoiceIncomingCall = (props) => {
|
|
1438
|
+
const { resolveCallerLabel, renderAgentSpot } = props;
|
|
1439
|
+
const translateText = useAgentVoiceTranslateText();
|
|
1440
|
+
const ringSource = useAgentVoiceRingSource();
|
|
1441
|
+
const isCallActive = useAgentVoiceCallValue((call) => isAgentVoiceCallActive(call.phase));
|
|
1442
|
+
const { ring, callerLabel, handledCallIds, isAnswering, refusal, bandHostCount, ringCoverCount } = useAgentVoiceIncomingRing();
|
|
1443
|
+
const { rings, nowMs } = useAgentVoiceIncomingRings(ringSource);
|
|
1444
|
+
const ringingCall = isCallActive ? void 0 : pickRingingAgentVoiceCall(rings, nowMs, handledCallIds);
|
|
1445
|
+
const ringingCallerLabel = ringingCall === void 0 ? void 0 : resolveCallerLabel?.(ringingCall) ?? buildAgentVoiceCallerLabel(ringingCall, translateText, getAgentDisplayName());
|
|
1446
|
+
const ringingCallerLabelText = ringingCallerLabel?.text;
|
|
1447
|
+
const ringingCallerLabelDetail = ringingCallerLabel?.detail;
|
|
1448
|
+
useEffect(() => {
|
|
1449
|
+
publishAgentVoiceIncomingRing(
|
|
1450
|
+
ringingCall,
|
|
1451
|
+
ringingCallerLabelText === void 0 ? void 0 : { text: ringingCallerLabelText, detail: ringingCallerLabelDetail }
|
|
1452
|
+
);
|
|
1453
|
+
}, [ringingCall, ringingCallerLabelText, ringingCallerLabelDetail]);
|
|
1454
|
+
useEffect(() => () => publishAgentVoiceIncomingRing(void 0, void 0), []);
|
|
1455
|
+
useAgentVoiceRingTone(ring !== void 0 && !isAnswering);
|
|
1456
|
+
const card = ringSource !== void 0 ? pickAgentVoiceIncomingCard({ ring, refusal, bandHostCount, ringCoverCount }) : void 0;
|
|
1457
|
+
const callerLabelId = useId();
|
|
1458
|
+
if (card === void 0) return null;
|
|
1459
|
+
if (ring === void 0) {
|
|
1460
|
+
if (refusal === void 0) return null;
|
|
1461
|
+
return /* @__PURE__ */ jsx("div", { className: styles.incomingCall, role: "status", "data-testid": "agent-voice-incoming-call-refusal", children: /* @__PURE__ */ jsx("span", { className: styles.detail, children: translateText(AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS[refusal]) }) });
|
|
1462
|
+
}
|
|
1463
|
+
const shownCallerLabel = callerLabel ?? buildAgentVoiceCallerLabel(ring, translateText, getAgentDisplayName());
|
|
1464
|
+
return /* @__PURE__ */ jsxs(
|
|
1465
|
+
"div",
|
|
1466
|
+
{
|
|
1467
|
+
className: styles.incomingCall,
|
|
1468
|
+
role: "alertdialog",
|
|
1469
|
+
"aria-live": "assertive",
|
|
1470
|
+
"aria-labelledby": callerLabelId,
|
|
1471
|
+
"data-testid": "agent-voice-incoming-call",
|
|
1472
|
+
children: [
|
|
1473
|
+
/* @__PURE__ */ jsx("div", { className: styles.spot, children: renderAgentSpot ? renderAgentSpot() : /* @__PURE__ */ jsx("span", { className: styles.mark, children: /* @__PURE__ */ jsx(VoiceBarsIcon, { size: 24 }) }) }),
|
|
1474
|
+
/* @__PURE__ */ jsxs("div", { className: styles.caller, id: callerLabelId, children: [
|
|
1475
|
+
/* @__PURE__ */ jsx("span", { className: styles.label, children: shownCallerLabel.text }),
|
|
1476
|
+
shownCallerLabel.detail ? /* @__PURE__ */ jsx("span", { className: styles.detail, "data-testid": "agent-voice-incoming-call-detail", children: shownCallerLabel.detail }) : null
|
|
1477
|
+
] }),
|
|
1478
|
+
/* @__PURE__ */ jsxs("div", { className: styles.actions, children: [
|
|
1479
|
+
/* @__PURE__ */ jsxs(
|
|
1480
|
+
"button",
|
|
1481
|
+
{
|
|
1482
|
+
type: "button",
|
|
1483
|
+
className: styles.action,
|
|
1484
|
+
disabled: isAnswering,
|
|
1485
|
+
onClick: declineAgentVoiceIncomingRing,
|
|
1486
|
+
"data-testid": "agent-voice-incoming-call-decline",
|
|
1487
|
+
children: [
|
|
1488
|
+
/* @__PURE__ */ jsx(AgentVoiceCloseIcon, {}),
|
|
1489
|
+
/* @__PURE__ */ jsx("span", { children: translateText("Decline") })
|
|
1490
|
+
]
|
|
1491
|
+
}
|
|
1492
|
+
),
|
|
1493
|
+
/* @__PURE__ */ jsxs(
|
|
1494
|
+
"button",
|
|
1495
|
+
{
|
|
1496
|
+
type: "button",
|
|
1497
|
+
className: styles.action,
|
|
1498
|
+
"data-variant": "accept",
|
|
1499
|
+
disabled: isAnswering,
|
|
1500
|
+
onClick: () => void acceptAgentVoiceIncomingRing(),
|
|
1501
|
+
"data-testid": "agent-voice-incoming-call-accept",
|
|
1502
|
+
children: [
|
|
1503
|
+
/* @__PURE__ */ jsx(AgentVoiceMicrophoneIcon, {}),
|
|
1504
|
+
/* @__PURE__ */ jsx("span", { children: translateText("Accept") })
|
|
1505
|
+
]
|
|
1506
|
+
}
|
|
1507
|
+
)
|
|
1508
|
+
] })
|
|
1509
|
+
]
|
|
1510
|
+
}
|
|
1511
|
+
);
|
|
1512
|
+
};
|
|
1513
|
+
export {
|
|
1514
|
+
AGENT_VOICE_ANSWER_REFUSAL_TEXT_KEYS,
|
|
1515
|
+
AGENT_VOICE_CALL_END_REASON_ENDED_BY_AGENT,
|
|
1516
|
+
AGENT_VOICE_CALL_END_REASON_LIMIT_REACHED,
|
|
1517
|
+
AGENT_VOICE_ERROR_CODE_INVALID_OPEN_ANSWER,
|
|
1518
|
+
AGENT_VOICE_RING_MESSAGE_TYPE,
|
|
1519
|
+
AgentVoiceAccountRealtimeRingSource,
|
|
1520
|
+
AgentVoiceApiError,
|
|
1521
|
+
VoiceBarsIcon as AgentVoiceBarsIcon,
|
|
1522
|
+
AgentVoiceCallBand,
|
|
1523
|
+
AgentVoiceCallBandView,
|
|
1524
|
+
AgentVoiceCallCaptions,
|
|
1525
|
+
AgentVoiceCallProvider,
|
|
1526
|
+
AgentVoiceChatStartButton,
|
|
1527
|
+
AgentVoiceIncomingCall,
|
|
1528
|
+
AgentVoiceInputGlow,
|
|
1529
|
+
IDLE_AGENT_VOICE_CALL,
|
|
1530
|
+
acceptAgentVoiceIncomingRing,
|
|
1531
|
+
bindAgentVoiceApi,
|
|
1532
|
+
buildAgentVoiceCallerLabel,
|
|
1533
|
+
buildAgentVoiceRequests,
|
|
1534
|
+
buildUnsavedAgentVoiceCallLines,
|
|
1535
|
+
checkAgentVoiceCallEndedOnServer,
|
|
1536
|
+
createAgentVoiceApi,
|
|
1537
|
+
createAgentVoiceFetchBaseApi,
|
|
1538
|
+
createAgentVoiceRingSource,
|
|
1539
|
+
declineAgentVoiceIncomingRing,
|
|
1540
|
+
dismissAgentVoiceCallOutcome,
|
|
1541
|
+
endAgentVoiceCallFromServer,
|
|
1542
|
+
formatAgentVoiceCallDuration,
|
|
1543
|
+
hangUpAgentVoiceCall,
|
|
1544
|
+
isAgentVoiceCallActive,
|
|
1545
|
+
isAgentVoiceCallShownInAgentSpace,
|
|
1546
|
+
pickAgentVoiceCallerLabelTextKey,
|
|
1547
|
+
pickAgentVoiceIncomingCard,
|
|
1548
|
+
pickRingingAgentVoiceCall,
|
|
1549
|
+
readAgentVoiceCallSnapshot,
|
|
1550
|
+
readAgentVoiceErrorCode,
|
|
1551
|
+
readAgentVoiceIncomingRingSnapshot,
|
|
1552
|
+
readAgentVoiceRingOfRealtimeMessage,
|
|
1553
|
+
startAgentVoiceCall,
|
|
1554
|
+
toggleAgentVoiceCallMute,
|
|
1555
|
+
turnOfAgentVoiceCall,
|
|
1556
|
+
useAgentVoiceCall,
|
|
1557
|
+
useAgentVoiceCallElapsedSeconds,
|
|
1558
|
+
useAgentVoiceCallServerEnd,
|
|
1559
|
+
useAgentVoiceCallSnapshot,
|
|
1560
|
+
useAgentVoiceCallValue,
|
|
1561
|
+
useAgentVoiceIncomingRing,
|
|
1562
|
+
useAgentVoiceRingBandHost,
|
|
1563
|
+
useAgentVoiceRingCover,
|
|
1564
|
+
useAgentVoiceRingTone,
|
|
1565
|
+
useAgentVoiceTranslateText,
|
|
1566
|
+
useIsAgentVoiceCallActive
|
|
1567
|
+
};
|
|
1568
|
+
//# sourceMappingURL=voice.js.map
|