@devicai/ui 0.61.1 → 0.62.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/README.md +1 -1
- package/dist/cjs/api/client.js +3 -2
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js +10 -2
- package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/ChatInput.js +8 -2
- package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -1
- package/dist/cjs/components/ChatDrawer/LiveVoicePanel.js +20 -72
- package/dist/cjs/components/ChatDrawer/LiveVoicePanel.js.map +1 -1
- package/dist/cjs/hooks/useDevicLiveVoice.js +1 -0
- package/dist/cjs/hooks/useDevicLiveVoice.js.map +1 -1
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/styles.css +1 -1
- package/dist/cjs/utils/voiceInvitation.js +33 -0
- package/dist/cjs/utils/voiceInvitation.js.map +1 -0
- package/dist/cjs/voice/LiveVoiceController.js +98 -2
- package/dist/cjs/voice/LiveVoiceController.js.map +1 -1
- package/dist/esm/api/client.d.ts +2 -1
- package/dist/esm/api/client.js +3 -2
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api/liveVoice.types.d.ts +5 -0
- package/dist/esm/components/ChatDrawer/ChatDrawer.js +10 -2
- package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
- package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +31 -1
- package/dist/esm/components/ChatDrawer/ChatInput.js +8 -2
- package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -1
- package/dist/esm/components/ChatDrawer/LiveVoicePanel.d.ts +11 -9
- package/dist/esm/components/ChatDrawer/LiveVoicePanel.js +20 -72
- package/dist/esm/components/ChatDrawer/LiveVoicePanel.js.map +1 -1
- package/dist/esm/hooks/useDevicLiveVoice.d.ts +2 -0
- package/dist/esm/hooks/useDevicLiveVoice.js +1 -0
- package/dist/esm/hooks/useDevicLiveVoice.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/styles.css +1 -1
- package/dist/esm/utils/voiceInvitation.d.ts +3 -0
- package/dist/esm/utils/voiceInvitation.js +29 -0
- package/dist/esm/utils/voiceInvitation.js.map +1 -0
- package/dist/esm/voice/LiveVoiceController.d.ts +10 -0
- package/dist/esm/voice/LiveVoiceController.js +98 -2
- package/dist/esm/voice/LiveVoiceController.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether the person closed the voice invitation for an assistant. Kept in
|
|
5
|
+
* localStorage, per assistant, so it stays closed across conversations and
|
|
6
|
+
* page loads; storage that is missing, full or blocked counts as "not hidden".
|
|
7
|
+
*/
|
|
8
|
+
const key = (assistantId) => `devic-ui:voice-invitation-hidden:${assistantId}`;
|
|
9
|
+
function isVoiceInvitationHidden(assistantId) {
|
|
10
|
+
try {
|
|
11
|
+
return typeof localStorage !== 'undefined' && localStorage.getItem(key(assistantId)) === '1';
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function hideVoiceInvitation(assistantId) {
|
|
18
|
+
try {
|
|
19
|
+
localStorage.setItem(key(assistantId), '1');
|
|
20
|
+
}
|
|
21
|
+
catch { /* Private mode or quota: the card comes back next load. */ }
|
|
22
|
+
}
|
|
23
|
+
function showVoiceInvitation(assistantId) {
|
|
24
|
+
try {
|
|
25
|
+
localStorage.removeItem(key(assistantId));
|
|
26
|
+
}
|
|
27
|
+
catch { /* Nothing to undo. */ }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.hideVoiceInvitation = hideVoiceInvitation;
|
|
31
|
+
exports.isVoiceInvitationHidden = isVoiceInvitationHidden;
|
|
32
|
+
exports.showVoiceInvitation = showVoiceInvitation;
|
|
33
|
+
//# sourceMappingURL=voiceInvitation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voiceInvitation.js","sources":["../../../../src/utils/voiceInvitation.ts"],"sourcesContent":["/**\n * Whether the person closed the voice invitation for an assistant. Kept in\n * localStorage, per assistant, so it stays closed across conversations and\n * page loads; storage that is missing, full or blocked counts as \"not hidden\".\n */\nconst key = (assistantId: string) => `devic-ui:voice-invitation-hidden:${assistantId}`;\n\nexport function isVoiceInvitationHidden(assistantId: string): boolean {\n try { return typeof localStorage !== 'undefined' && localStorage.getItem(key(assistantId)) === '1'; }\n catch { return false; }\n}\n\nexport function hideVoiceInvitation(assistantId: string): void {\n try { localStorage.setItem(key(assistantId), '1'); } catch { /* Private mode or quota: the card comes back next load. */ }\n}\n\nexport function showVoiceInvitation(assistantId: string): void {\n try { localStorage.removeItem(key(assistantId)); } catch { /* Nothing to undo. */ }\n}\n"],"names":[],"mappings":";;AAAA;;;;AAIG;AACH,MAAM,GAAG,GAAG,CAAC,WAAmB,KAAK,CAAA,iCAAA,EAAoC,WAAW,CAAA,CAAE;AAEhF,SAAU,uBAAuB,CAAC,WAAmB,EAAA;AACzD,IAAA,IAAI;AAAE,QAAA,OAAO,OAAO,YAAY,KAAK,WAAW,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,KAAK,GAAG;IAAE;AACpG,IAAA,MAAM;AAAE,QAAA,OAAO,KAAK;IAAE;AACxB;AAEM,SAAU,mBAAmB,CAAC,WAAmB,EAAA;AACrD,IAAA,IAAI;QAAE,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IAAE;AAAE,IAAA,MAAM,8DAA8D;AAC3H;AAEM,SAAU,mBAAmB,CAAC,WAAmB,EAAA;AACrD,IAAA,IAAI;QAAE,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAAE;AAAE,IAAA,MAAM,yBAAyB;AACpF;;;;;;"}
|
|
@@ -14,6 +14,8 @@ class LiveVoiceController {
|
|
|
14
14
|
this.attempts = 0;
|
|
15
15
|
this.disposeTransport = () => { };
|
|
16
16
|
this.disposed = false;
|
|
17
|
+
/** Last moment anyone spoke, or the person confirmed presence. */
|
|
18
|
+
this.lastActivity = 0;
|
|
17
19
|
}
|
|
18
20
|
update(patch) {
|
|
19
21
|
this.snapshot = { ...this.snapshot, ...patch };
|
|
@@ -33,6 +35,15 @@ class LiveVoiceController {
|
|
|
33
35
|
this.update({ playbackBlocked: true });
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
/** The person is still there: restart the idle clock here and on the server. */
|
|
39
|
+
stillHere() {
|
|
40
|
+
this.lastActivity = Date.now();
|
|
41
|
+
if (this.snapshot.idleEndsAt)
|
|
42
|
+
this.update({ idleEndsAt: undefined });
|
|
43
|
+
const id = this.snapshot.sessionId;
|
|
44
|
+
if (id && this.snapshot.state === 'connected')
|
|
45
|
+
void this.client.getLiveSessionStatus(this.assistantId, id, true).catch(() => { });
|
|
46
|
+
}
|
|
36
47
|
async start(chatUid, recovering = false) {
|
|
37
48
|
if (this.disposed || this.closing || (!recovering && !['idle', 'error'].includes(this.snapshot.state)))
|
|
38
49
|
return;
|
|
@@ -41,7 +52,8 @@ class LiveVoiceController {
|
|
|
41
52
|
if (!recovering)
|
|
42
53
|
this.attempts = 0;
|
|
43
54
|
this.update({ state: 'connecting', error: undefined, chatUid, sessionId: undefined,
|
|
44
|
-
seconds: 0, ...(recovering ? {} : { transcript: [], muted: false }) });
|
|
55
|
+
seconds: 0, idleEndsAt: undefined, endReason: undefined, ...(recovering ? {} : { transcript: [], muted: false }) });
|
|
56
|
+
this.lastActivity = Date.now();
|
|
45
57
|
let media;
|
|
46
58
|
let peer;
|
|
47
59
|
let channel;
|
|
@@ -54,10 +66,23 @@ class LiveVoiceController {
|
|
|
54
66
|
let sessionId;
|
|
55
67
|
let connectionLostAt = 0;
|
|
56
68
|
let healthFailures = 0;
|
|
69
|
+
let micCheck;
|
|
70
|
+
let micContext;
|
|
71
|
+
let micAnalyser;
|
|
72
|
+
let micQuiet = 0;
|
|
57
73
|
const cleanup = () => {
|
|
58
74
|
clearInterval(health);
|
|
59
75
|
clearTimeout(deadline);
|
|
60
76
|
clearTimeout(connectDeadline);
|
|
77
|
+
clearInterval(micCheck);
|
|
78
|
+
if (micContext) {
|
|
79
|
+
try {
|
|
80
|
+
void micContext.close().catch(() => { });
|
|
81
|
+
}
|
|
82
|
+
catch { /* Already closed. */ }
|
|
83
|
+
micContext = undefined;
|
|
84
|
+
micAnalyser = undefined;
|
|
85
|
+
}
|
|
61
86
|
media?.getTracks().forEach(track => track.stop());
|
|
62
87
|
if (channel) {
|
|
63
88
|
channel.onclose = null;
|
|
@@ -82,8 +107,64 @@ class LiveVoiceController {
|
|
|
82
107
|
return;
|
|
83
108
|
clearTimeout(connectDeadline);
|
|
84
109
|
media?.getAudioTracks().forEach(track => { track.enabled = !this.snapshot.muted; });
|
|
110
|
+
if (this.snapshot.state !== 'connected') {
|
|
111
|
+
this.lastActivity = Date.now();
|
|
112
|
+
watchMicrophone();
|
|
113
|
+
}
|
|
85
114
|
this.update({ state: 'connected' });
|
|
86
115
|
};
|
|
116
|
+
// A microphone that delivers nothing — ended track, system mute, or a
|
|
117
|
+
// stream of exact digital silence — would otherwise keep a paid call open
|
|
118
|
+
// with nobody able to speak. Analyse only; never route audio.
|
|
119
|
+
const watchMicrophone = () => {
|
|
120
|
+
if (micCheck)
|
|
121
|
+
return;
|
|
122
|
+
const track = media?.getAudioTracks()[0];
|
|
123
|
+
if (!track)
|
|
124
|
+
return;
|
|
125
|
+
const samples = new Uint8Array(256);
|
|
126
|
+
try {
|
|
127
|
+
if (typeof AudioContext !== 'undefined') {
|
|
128
|
+
micContext = new AudioContext();
|
|
129
|
+
micAnalyser = micContext.createAnalyser();
|
|
130
|
+
micAnalyser.fftSize = 256;
|
|
131
|
+
micContext.createMediaStreamSource(media).connect(micAnalyser);
|
|
132
|
+
void micContext.resume().catch(() => { });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
micAnalyser = undefined;
|
|
137
|
+
}
|
|
138
|
+
micCheck = setInterval(() => {
|
|
139
|
+
if (!current() || this.snapshot.state !== 'connected')
|
|
140
|
+
return;
|
|
141
|
+
const fail = () => {
|
|
142
|
+
this.update({ error: new Error('No microphone signal. Check your microphone and start again.') });
|
|
143
|
+
void this.stop();
|
|
144
|
+
};
|
|
145
|
+
if (track.readyState === 'ended') {
|
|
146
|
+
fail();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (this.snapshot.muted) {
|
|
150
|
+
micQuiet = 0;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let silent = track.muted === true;
|
|
154
|
+
if (micAnalyser && !silent) {
|
|
155
|
+
try {
|
|
156
|
+
micAnalyser.getByteTimeDomainData(samples);
|
|
157
|
+
silent = samples.every(sample => sample === 128);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
silent = false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
micQuiet = silent ? micQuiet + 1 : 0;
|
|
164
|
+
if (micQuiet >= 15)
|
|
165
|
+
fail();
|
|
166
|
+
}, 1000);
|
|
167
|
+
};
|
|
87
168
|
const recover = async () => {
|
|
88
169
|
if (!current())
|
|
89
170
|
return;
|
|
@@ -157,6 +238,9 @@ class LiveVoiceController {
|
|
|
157
238
|
}
|
|
158
239
|
if (['session.input_transcript.delta', 'session.output_transcript.delta'].includes(event.type) && typeof event.delta === 'string') {
|
|
159
240
|
lastTranscript = Date.now();
|
|
241
|
+
this.lastActivity = lastTranscript;
|
|
242
|
+
if (this.snapshot.idleEndsAt)
|
|
243
|
+
this.update({ idleEndsAt: undefined });
|
|
160
244
|
const role = event.type === 'session.input_transcript.delta' ? 'user' : 'assistant';
|
|
161
245
|
const turns = this.snapshot.transcript.slice(-3).map(turn => ({ ...turn }));
|
|
162
246
|
if (turns[turns.length - 1]?.role === role)
|
|
@@ -169,6 +253,8 @@ class LiveVoiceController {
|
|
|
169
253
|
void this.client.getLiveSessionStatus(this.assistantId, sessionId).then(state => {
|
|
170
254
|
if (!current())
|
|
171
255
|
return;
|
|
256
|
+
if (state.endReason)
|
|
257
|
+
this.update({ endReason: state.endReason });
|
|
172
258
|
if (state.restartRequested)
|
|
173
259
|
void recover();
|
|
174
260
|
else
|
|
@@ -213,7 +299,7 @@ class LiveVoiceController {
|
|
|
213
299
|
void this.client.closeLiveSession(this.assistantId, sessionId).catch(() => { });
|
|
214
300
|
return;
|
|
215
301
|
}
|
|
216
|
-
this.update({ sessionId, chatUid: result.chatUid });
|
|
302
|
+
this.update({ sessionId, chatUid: result.chatUid, idleTimeoutSeconds: result.idleTimeoutSeconds || 0 });
|
|
217
303
|
this.created(result.chatUid);
|
|
218
304
|
deadline = setTimeout(() => { void this.stop(); }, Math.max(1, Math.min(6000, result.maxDurationSeconds || 6000)) * 1000);
|
|
219
305
|
await peer.setRemoteDescription({ type: 'answer', sdp: result.sdp });
|
|
@@ -228,6 +314,16 @@ class LiveVoiceController {
|
|
|
228
314
|
return;
|
|
229
315
|
healthFailures = 0;
|
|
230
316
|
this.update({ seconds: state.seconds });
|
|
317
|
+
// The server ends a silent call at idleTimeoutSeconds; warn for the
|
|
318
|
+
// last 30 s (or half the window when it is short) so the person can
|
|
319
|
+
// say "I'm here" instead of losing the call.
|
|
320
|
+
const idle = this.snapshot.idleTimeoutSeconds || 0;
|
|
321
|
+
if (idle > 0 && this.snapshot.state === 'connected') {
|
|
322
|
+
const endsAt = this.lastActivity + idle * 1000;
|
|
323
|
+
const warn = Date.now() >= endsAt - Math.min(30000, idle * 500);
|
|
324
|
+
if (warn ? this.snapshot.idleEndsAt !== endsAt : !!this.snapshot.idleEndsAt)
|
|
325
|
+
this.update({ idleEndsAt: warn ? endsAt : undefined });
|
|
326
|
+
}
|
|
231
327
|
if (state.interrupted || state.restartRequested || (connectionLostAt && Date.now() - connectionLostAt > 5000)) {
|
|
232
328
|
void recover();
|
|
233
329
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveVoiceController.js","sources":["../../../../src/voice/LiveVoiceController.ts"],"sourcesContent":["import type { DevicApiClient } from '../api/client';\nimport type { LiveVoiceContext, LiveVoiceTurn } from '../api/liveVoice.types';\n\nexport type LiveVoiceState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'closing' | 'error';\nexport interface LiveVoiceSnapshot {\n state: LiveVoiceState;\n chatUid?: string;\n sessionId?: string;\n muted: boolean;\n seconds: number;\n transcript: LiveVoiceTurn[];\n input?: MediaStream;\n output?: MediaStream;\n error?: Error;\n playbackBlocked?: boolean;\n}\nexport const initialVoiceSnapshot = (): LiveVoiceSnapshot => ({ state: 'idle', muted: false, seconds: 0, transcript: [] });\n\n/** No browser globals at import/constructor time; loaded only by start(). */\nexport class LiveVoiceController {\n private snapshot = initialVoiceSnapshot();\n private generation = 0;\n private attempts = 0;\n private disposeTransport: () => void = () => {};\n private audio?: HTMLAudioElement;\n private closing?: Promise<void>;\n private disposed = false;\n constructor(private client: DevicApiClient, private assistantId: string,\n private context: LiveVoiceContext, private changed: (value: LiveVoiceSnapshot) => void,\n private created: (chatUid: string) => void) {}\n\n private update(patch: Partial<LiveVoiceSnapshot>) {\n this.snapshot = { ...this.snapshot, ...patch };\n if (!this.disposed) this.changed(this.snapshot);\n }\n mute(muted: boolean) {\n this.snapshot.input?.getAudioTracks().forEach(track => { track.enabled = !muted && this.snapshot.state === 'connected'; });\n this.update({ muted });\n }\n async play() {\n try { await this.audio?.play(); this.update({ playbackBlocked: false }); }\n catch { this.update({ playbackBlocked: true }); }\n }\n async start(chatUid?: string, recovering = false): Promise<void> {\n if (this.disposed || this.closing || (!recovering && !['idle', 'error'].includes(this.snapshot.state))) return;\n const generation = ++this.generation;\n const current = () => generation === this.generation && !this.disposed;\n if (!recovering) this.attempts = 0;\n this.update({ state: 'connecting', error: undefined, chatUid, sessionId: undefined,\n seconds: 0, ...(recovering ? {} : { transcript: [], muted: false }) });\n let media: MediaStream | undefined;\n let peer: RTCPeerConnection | undefined;\n let channel: RTCDataChannel | undefined;\n let audio: HTMLAudioElement | undefined;\n let health: ReturnType<typeof setInterval> | undefined;\n let deadline: ReturnType<typeof setTimeout> | undefined;\n let connectDeadline: ReturnType<typeof setTimeout> | undefined;\n let backendReady = false;\n let lastTranscript = 0;\n let sessionId: string | undefined;\n let connectionLostAt = 0;\n let healthFailures = 0;\n const cleanup = () => {\n clearInterval(health); clearTimeout(deadline); clearTimeout(connectDeadline);\n media?.getTracks().forEach(track => track.stop());\n if (channel) { channel.onclose = null; channel.onmessage = null; channel.close(); }\n if (peer) { peer.onconnectionstatechange = null; peer.ontrack = null; peer.close(); }\n if (audio) { audio.pause(); audio.srcObject = null; }\n this.audio = undefined;\n this.update({ input: undefined, output: undefined });\n };\n this.disposeTransport = cleanup;\n const ready = () => {\n if (!current() || !backendReady || peer?.connectionState !== 'connected') return;\n clearTimeout(connectDeadline);\n media?.getAudioTracks().forEach(track => { track.enabled = !this.snapshot.muted; });\n this.update({ state: 'connected' });\n };\n const recover = async () => {\n if (!current()) return;\n ++this.generation;\n const ticket = this.generation;\n cleanup();\n this.update({ state: 'reconnecting' });\n try {\n if (!sessionId || ++this.attempts > 3) throw new Error('Voice connection interrupted. Please start again.');\n await this.client.closeLiveSession(this.assistantId, sessionId);\n // Never open another paid transport before the old one is confirmed closed.\n for (let i = 0; i < 35 && ticket === this.generation && !this.disposed; i++) {\n const state = await this.client.getLiveSessionStatus(this.assistantId, sessionId);\n if (state.status === 'closed') {\n if (ticket === this.generation && !this.disposed) await this.start(this.snapshot.chatUid, true);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 2000));\n }\n if (ticket === this.generation) throw new Error('Could not confirm the previous voice session closed.');\n } catch (error) {\n if (ticket === this.generation) this.update({ state: 'error', error: error as Error });\n }\n };\n try {\n if (typeof navigator === 'undefined' || !navigator.mediaDevices?.getUserMedia || typeof RTCPeerConnection === 'undefined')\n throw new Error('Voice requires microphone access on HTTPS or localhost.');\n media = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true }, video: false });\n if (!current()) { media.getTracks().forEach(track => track.stop()); return; }\n media.getAudioTracks().forEach(track => { track.enabled = false; });\n this.update({ input: media });\n peer = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });\n audio = new Audio(); this.audio = audio; audio.autoplay = true;\n peer.ontrack = event => {\n if (!current()) return;\n const output = new MediaStream([event.track]);\n audio!.srcObject = output;\n this.update({ output }); void this.play();\n };\n peer.onconnectionstatechange = () => {\n ready();\n if (peer?.connectionState === 'disconnected') connectionLostAt ||= Date.now();\n else connectionLostAt = 0;\n if (peer?.connectionState === 'failed') void recover();\n };\n media.getTracks().forEach(track => peer!.addTrack(track, media!));\n channel = peer.createDataChannel('oai-events');\n channel.onmessage = message => {\n if (!current()) return;\n try {\n const event = JSON.parse(message.data);\n if (event.type === 'session.started') { backendReady = true; ready(); }\n if (['session.input_transcript.delta', 'session.output_transcript.delta'].includes(event.type) && typeof event.delta === 'string') {\n lastTranscript = Date.now();\n const role = event.type === 'session.input_transcript.delta' ? 'user' : 'assistant';\n const turns = this.snapshot.transcript.slice(-3).map(turn => ({ ...turn }));\n if (turns[turns.length - 1]?.role === role) turns[turns.length - 1].text = (turns[turns.length - 1].text + event.delta).slice(-2000);\n else turns.push({ role, text: event.delta.slice(-2000) });\n this.update({ transcript: turns });\n }\n if (event.type === 'session.closed' && sessionId) {\n void this.client.getLiveSessionStatus(this.assistantId, sessionId).then(state => {\n if (!current()) return;\n if (state.restartRequested) void recover(); else void this.stop();\n }).catch(() => { if (current()) void this.stop(); });\n }\n if (event.type === 'error') { this.update({ error: new Error('Voice session failed.') }); void this.stop(); }\n } catch { /* Only lifecycle and spoken transcript events are accepted. */ }\n };\n channel.onclose = () => { if (current()) void recover(); };\n connectDeadline = setTimeout(() => {\n if (current()) { this.update({ error: new Error('Voice connection timed out.') }); void this.stop(); }\n }, 30000);\n await peer.setLocalDescription(await peer.createOffer());\n await new Promise<void>((resolve, reject) => {\n if (peer!.iceGatheringState === 'complete') return resolve();\n const done = () => {\n if (peer!.iceGatheringState !== 'complete') return;\n clearTimeout(timer); peer!.removeEventListener('icegatheringstatechange', done); resolve();\n };\n const timer = setTimeout(() => { peer!.removeEventListener('icegatheringstatechange', done); reject(new Error('Could not prepare the audio connection.')); }, 10000);\n peer!.addEventListener('icegatheringstatechange', done);\n });\n if (!current()) return;\n const result = await this.client.createLiveSession(this.assistantId, { ...this.context, chatUid, sdp: peer.localDescription!.sdp });\n sessionId = result.sessionId;\n if (!current()) { void this.client.closeLiveSession(this.assistantId, sessionId).catch(() => {}); return; }\n this.update({ sessionId, chatUid: result.chatUid }); this.created(result.chatUid);\n deadline = setTimeout(() => { void this.stop(); }, Math.max(1, Math.min(6000, result.maxDurationSeconds || 6000)) * 1000);\n await peer.setRemoteDescription({ type: 'answer', sdp: result.sdp });\n let busy = false;\n health = setInterval(async () => {\n if (!current() || busy) return;\n busy = true;\n try {\n const state = await this.client.getLiveSessionStatus(this.assistantId, sessionId!);\n if (!current()) return;\n healthFailures = 0;\n this.update({ seconds: state.seconds });\n if (state.interrupted || state.restartRequested || (connectionLostAt && Date.now() - connectionLostAt > 5000)) { void recover(); return; }\n if (state.status === 'closed') { void this.stop(); return; }\n backendReady = state.connected; ready();\n if (Date.now() - lastTranscript > 1500 && state.transcript?.length)\n this.update({ transcript: state.transcript.slice(-4).filter(t => t.role === 'user' || t.role === 'assistant').map(t => ({ role: t.role, text: t.text.slice(-2000) })) });\n } catch {\n if (current() && ++healthFailures >= 5) { this.update({ error: new Error('Voice status unavailable. Session stopped.')} ); void this.stop(); }\n } finally { busy = false; }\n }, 1000);\n } catch (error) {\n if (!current()) return;\n this.update({ error: error instanceof Error ? error : new Error(String(error)) });\n await this.stop();\n }\n }\n stop(): Promise<void> {\n if (this.closing) return this.closing;\n ++this.generation;\n this.disposeTransport();\n const id = this.snapshot.sessionId;\n this.update({ state: id ? 'closing' : (this.snapshot.error ? 'error' : 'idle') });\n this.closing = (async () => {\n if (id) {\n try { await this.client.closeLiveSession(this.assistantId, id); }\n catch (error) { this.update({ error: error as Error }); }\n }\n this.update({ state: this.snapshot.error ? 'error' : 'idle', sessionId: undefined });\n })().finally(() => { this.closing = undefined; });\n return this.closing;\n }\n dispose() { this.disposed = true; void this.stop(); }\n}\n"],"names":[],"mappings":";;AAgBO,MAAM,oBAAoB,GAAG,OAA0B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;AAEzH;MACa,mBAAmB,CAAA;IAQ9B,WAAA,CAAoB,MAAsB,EAAU,WAAmB,EAC7D,OAAyB,EAAU,OAA2C,EAC9E,OAAkC,EAAA;QAFxB,IAAA,CAAA,MAAM,GAAN,MAAM;QAA0B,IAAA,CAAA,WAAW,GAAX,WAAW;QACrD,IAAA,CAAA,OAAO,GAAP,OAAO;QAA4B,IAAA,CAAA,OAAO,GAAP,OAAO;QAC1C,IAAA,CAAA,OAAO,GAAP,OAAO;QATT,IAAA,CAAA,QAAQ,GAAG,oBAAoB,EAAE;QACjC,IAAA,CAAA,UAAU,GAAG,CAAC;QACd,IAAA,CAAA,QAAQ,GAAG,CAAC;AACZ,QAAA,IAAA,CAAA,gBAAgB,GAAe,MAAK,EAAE,CAAC;QAGvC,IAAA,CAAA,QAAQ,GAAG,KAAK;IAGuB;AAEvC,IAAA,MAAM,CAAC,KAAiC,EAAA;AAC9C,QAAA,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,KAAK,EAAE;QAC9C,IAAI,CAAC,IAAI,CAAC,QAAQ;AAAE,YAAA,IAAI,CAAC,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,oBAAA,MAAM,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBAAE;gBAChE,OAAO,KAAK,EAAE;oBAAE,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;gBAAE;YAC1D;YACA,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACtF,QAAA,CAAC,GAAG,CAAC,OAAO,CAAC,MAAK,EAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,OAAO;IACrB;AACA,IAAA,OAAO,GAAA,EAAK,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACrD;;;;;"}
|
|
1
|
+
{"version":3,"file":"LiveVoiceController.js","sources":["../../../../src/voice/LiveVoiceController.ts"],"sourcesContent":["import type { DevicApiClient } from '../api/client';\nimport type { LiveVoiceContext, LiveVoiceTurn } from '../api/liveVoice.types';\n\nexport type LiveVoiceState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'closing' | 'error';\nexport interface LiveVoiceSnapshot {\n state: LiveVoiceState;\n chatUid?: string;\n sessionId?: string;\n muted: boolean;\n seconds: number;\n transcript: LiveVoiceTurn[];\n input?: MediaStream;\n output?: MediaStream;\n error?: Error;\n playbackBlocked?: boolean;\n /** Seconds of silence after which the server ends the call; 0 = never. */\n idleTimeoutSeconds?: number;\n /** Set while the call is about to end for silence: when it will, so a UI can count down. */\n idleEndsAt?: number;\n /** Why the server ended the last call, e.g. `idle`. */\n endReason?: string;\n}\nexport const initialVoiceSnapshot = (): LiveVoiceSnapshot => ({ state: 'idle', muted: false, seconds: 0, transcript: [] });\n\n/** No browser globals at import/constructor time; loaded only by start(). */\nexport class LiveVoiceController {\n private snapshot = initialVoiceSnapshot();\n private generation = 0;\n private attempts = 0;\n private disposeTransport: () => void = () => {};\n private audio?: HTMLAudioElement;\n private closing?: Promise<void>;\n private disposed = false;\n /** Last moment anyone spoke, or the person confirmed presence. */\n private lastActivity = 0;\n constructor(private client: DevicApiClient, private assistantId: string,\n private context: LiveVoiceContext, private changed: (value: LiveVoiceSnapshot) => void,\n private created: (chatUid: string) => void) {}\n\n private update(patch: Partial<LiveVoiceSnapshot>) {\n this.snapshot = { ...this.snapshot, ...patch };\n if (!this.disposed) this.changed(this.snapshot);\n }\n mute(muted: boolean) {\n this.snapshot.input?.getAudioTracks().forEach(track => { track.enabled = !muted && this.snapshot.state === 'connected'; });\n this.update({ muted });\n }\n async play() {\n try { await this.audio?.play(); this.update({ playbackBlocked: false }); }\n catch { this.update({ playbackBlocked: true }); }\n }\n /** The person is still there: restart the idle clock here and on the server. */\n stillHere() {\n this.lastActivity = Date.now();\n if (this.snapshot.idleEndsAt) this.update({ idleEndsAt: undefined });\n const id = this.snapshot.sessionId;\n if (id && this.snapshot.state === 'connected') void this.client.getLiveSessionStatus(this.assistantId, id, true).catch(() => {});\n }\n async start(chatUid?: string, recovering = false): Promise<void> {\n if (this.disposed || this.closing || (!recovering && !['idle', 'error'].includes(this.snapshot.state))) return;\n const generation = ++this.generation;\n const current = () => generation === this.generation && !this.disposed;\n if (!recovering) this.attempts = 0;\n this.update({ state: 'connecting', error: undefined, chatUid, sessionId: undefined,\n seconds: 0, idleEndsAt: undefined, endReason: undefined, ...(recovering ? {} : { transcript: [], muted: false }) });\n this.lastActivity = Date.now();\n let media: MediaStream | undefined;\n let peer: RTCPeerConnection | undefined;\n let channel: RTCDataChannel | undefined;\n let audio: HTMLAudioElement | undefined;\n let health: ReturnType<typeof setInterval> | undefined;\n let deadline: ReturnType<typeof setTimeout> | undefined;\n let connectDeadline: ReturnType<typeof setTimeout> | undefined;\n let backendReady = false;\n let lastTranscript = 0;\n let sessionId: string | undefined;\n let connectionLostAt = 0;\n let healthFailures = 0;\n let micCheck: ReturnType<typeof setInterval> | undefined;\n let micContext: AudioContext | undefined;\n let micAnalyser: AnalyserNode | undefined;\n let micQuiet = 0;\n const cleanup = () => {\n clearInterval(health); clearTimeout(deadline); clearTimeout(connectDeadline); clearInterval(micCheck);\n if (micContext) { try { void micContext.close().catch(() => {}); } catch { /* Already closed. */ } micContext = undefined; micAnalyser = undefined; }\n media?.getTracks().forEach(track => track.stop());\n if (channel) { channel.onclose = null; channel.onmessage = null; channel.close(); }\n if (peer) { peer.onconnectionstatechange = null; peer.ontrack = null; peer.close(); }\n if (audio) { audio.pause(); audio.srcObject = null; }\n this.audio = undefined;\n this.update({ input: undefined, output: undefined });\n };\n this.disposeTransport = cleanup;\n const ready = () => {\n if (!current() || !backendReady || peer?.connectionState !== 'connected') return;\n clearTimeout(connectDeadline);\n media?.getAudioTracks().forEach(track => { track.enabled = !this.snapshot.muted; });\n if (this.snapshot.state !== 'connected') { this.lastActivity = Date.now(); watchMicrophone(); }\n this.update({ state: 'connected' });\n };\n // A microphone that delivers nothing — ended track, system mute, or a\n // stream of exact digital silence — would otherwise keep a paid call open\n // with nobody able to speak. Analyse only; never route audio.\n const watchMicrophone = () => {\n if (micCheck) return;\n const track = media?.getAudioTracks()[0];\n if (!track) return;\n const samples = new Uint8Array(256);\n try {\n if (typeof AudioContext !== 'undefined') {\n micContext = new AudioContext(); micAnalyser = micContext.createAnalyser(); micAnalyser.fftSize = 256;\n micContext.createMediaStreamSource(media!).connect(micAnalyser); void micContext.resume().catch(() => {});\n }\n } catch { micAnalyser = undefined; }\n micCheck = setInterval(() => {\n if (!current() || this.snapshot.state !== 'connected') return;\n const fail = () => {\n this.update({ error: new Error('No microphone signal. Check your microphone and start again.') });\n void this.stop();\n };\n if (track.readyState === 'ended') { fail(); return; }\n if (this.snapshot.muted) { micQuiet = 0; return; }\n let silent = track.muted === true;\n if (micAnalyser && !silent) {\n try {\n micAnalyser.getByteTimeDomainData(samples);\n silent = samples.every(sample => sample === 128);\n } catch { silent = false; }\n }\n micQuiet = silent ? micQuiet + 1 : 0;\n if (micQuiet >= 15) fail();\n }, 1000);\n };\n const recover = async () => {\n if (!current()) return;\n ++this.generation;\n const ticket = this.generation;\n cleanup();\n this.update({ state: 'reconnecting' });\n try {\n if (!sessionId || ++this.attempts > 3) throw new Error('Voice connection interrupted. Please start again.');\n await this.client.closeLiveSession(this.assistantId, sessionId);\n // Never open another paid transport before the old one is confirmed closed.\n for (let i = 0; i < 35 && ticket === this.generation && !this.disposed; i++) {\n const state = await this.client.getLiveSessionStatus(this.assistantId, sessionId);\n if (state.status === 'closed') {\n if (ticket === this.generation && !this.disposed) await this.start(this.snapshot.chatUid, true);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 2000));\n }\n if (ticket === this.generation) throw new Error('Could not confirm the previous voice session closed.');\n } catch (error) {\n if (ticket === this.generation) this.update({ state: 'error', error: error as Error });\n }\n };\n try {\n if (typeof navigator === 'undefined' || !navigator.mediaDevices?.getUserMedia || typeof RTCPeerConnection === 'undefined')\n throw new Error('Voice requires microphone access on HTTPS or localhost.');\n media = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true }, video: false });\n if (!current()) { media.getTracks().forEach(track => track.stop()); return; }\n media.getAudioTracks().forEach(track => { track.enabled = false; });\n this.update({ input: media });\n peer = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });\n audio = new Audio(); this.audio = audio; audio.autoplay = true;\n peer.ontrack = event => {\n if (!current()) return;\n const output = new MediaStream([event.track]);\n audio!.srcObject = output;\n this.update({ output }); void this.play();\n };\n peer.onconnectionstatechange = () => {\n ready();\n if (peer?.connectionState === 'disconnected') connectionLostAt ||= Date.now();\n else connectionLostAt = 0;\n if (peer?.connectionState === 'failed') void recover();\n };\n media.getTracks().forEach(track => peer!.addTrack(track, media!));\n channel = peer.createDataChannel('oai-events');\n channel.onmessage = message => {\n if (!current()) return;\n try {\n const event = JSON.parse(message.data);\n if (event.type === 'session.started') { backendReady = true; ready(); }\n if (['session.input_transcript.delta', 'session.output_transcript.delta'].includes(event.type) && typeof event.delta === 'string') {\n lastTranscript = Date.now(); this.lastActivity = lastTranscript;\n if (this.snapshot.idleEndsAt) this.update({ idleEndsAt: undefined });\n const role = event.type === 'session.input_transcript.delta' ? 'user' : 'assistant';\n const turns = this.snapshot.transcript.slice(-3).map(turn => ({ ...turn }));\n if (turns[turns.length - 1]?.role === role) turns[turns.length - 1].text = (turns[turns.length - 1].text + event.delta).slice(-2000);\n else turns.push({ role, text: event.delta.slice(-2000) });\n this.update({ transcript: turns });\n }\n if (event.type === 'session.closed' && sessionId) {\n void this.client.getLiveSessionStatus(this.assistantId, sessionId).then(state => {\n if (!current()) return;\n if (state.endReason) this.update({ endReason: state.endReason });\n if (state.restartRequested) void recover(); else void this.stop();\n }).catch(() => { if (current()) void this.stop(); });\n }\n if (event.type === 'error') { this.update({ error: new Error('Voice session failed.') }); void this.stop(); }\n } catch { /* Only lifecycle and spoken transcript events are accepted. */ }\n };\n channel.onclose = () => { if (current()) void recover(); };\n connectDeadline = setTimeout(() => {\n if (current()) { this.update({ error: new Error('Voice connection timed out.') }); void this.stop(); }\n }, 30000);\n await peer.setLocalDescription(await peer.createOffer());\n await new Promise<void>((resolve, reject) => {\n if (peer!.iceGatheringState === 'complete') return resolve();\n const done = () => {\n if (peer!.iceGatheringState !== 'complete') return;\n clearTimeout(timer); peer!.removeEventListener('icegatheringstatechange', done); resolve();\n };\n const timer = setTimeout(() => { peer!.removeEventListener('icegatheringstatechange', done); reject(new Error('Could not prepare the audio connection.')); }, 10000);\n peer!.addEventListener('icegatheringstatechange', done);\n });\n if (!current()) return;\n const result = await this.client.createLiveSession(this.assistantId, { ...this.context, chatUid, sdp: peer.localDescription!.sdp });\n sessionId = result.sessionId;\n if (!current()) { void this.client.closeLiveSession(this.assistantId, sessionId).catch(() => {}); return; }\n this.update({ sessionId, chatUid: result.chatUid, idleTimeoutSeconds: result.idleTimeoutSeconds || 0 }); this.created(result.chatUid);\n deadline = setTimeout(() => { void this.stop(); }, Math.max(1, Math.min(6000, result.maxDurationSeconds || 6000)) * 1000);\n await peer.setRemoteDescription({ type: 'answer', sdp: result.sdp });\n let busy = false;\n health = setInterval(async () => {\n if (!current() || busy) return;\n busy = true;\n try {\n const state = await this.client.getLiveSessionStatus(this.assistantId, sessionId!);\n if (!current()) return;\n healthFailures = 0;\n this.update({ seconds: state.seconds });\n // The server ends a silent call at idleTimeoutSeconds; warn for the\n // last 30 s (or half the window when it is short) so the person can\n // say \"I'm here\" instead of losing the call.\n const idle = this.snapshot.idleTimeoutSeconds || 0;\n if (idle > 0 && this.snapshot.state === 'connected') {\n const endsAt = this.lastActivity + idle * 1000;\n const warn = Date.now() >= endsAt - Math.min(30000, idle * 500);\n if (warn ? this.snapshot.idleEndsAt !== endsAt : !!this.snapshot.idleEndsAt) this.update({ idleEndsAt: warn ? endsAt : undefined });\n }\n if (state.interrupted || state.restartRequested || (connectionLostAt && Date.now() - connectionLostAt > 5000)) { void recover(); return; }\n if (state.status === 'closed') { void this.stop(); return; }\n backendReady = state.connected; ready();\n if (Date.now() - lastTranscript > 1500 && state.transcript?.length)\n this.update({ transcript: state.transcript.slice(-4).filter(t => t.role === 'user' || t.role === 'assistant').map(t => ({ role: t.role, text: t.text.slice(-2000) })) });\n } catch {\n if (current() && ++healthFailures >= 5) { this.update({ error: new Error('Voice status unavailable. Session stopped.')} ); void this.stop(); }\n } finally { busy = false; }\n }, 1000);\n } catch (error) {\n if (!current()) return;\n this.update({ error: error instanceof Error ? error : new Error(String(error)) });\n await this.stop();\n }\n }\n stop(): Promise<void> {\n if (this.closing) return this.closing;\n ++this.generation;\n this.disposeTransport();\n const id = this.snapshot.sessionId;\n this.update({ state: id ? 'closing' : (this.snapshot.error ? 'error' : 'idle') });\n this.closing = (async () => {\n if (id) {\n try { await this.client.closeLiveSession(this.assistantId, id); }\n catch (error) { this.update({ error: error as Error }); }\n }\n this.update({ state: this.snapshot.error ? 'error' : 'idle', sessionId: undefined });\n })().finally(() => { this.closing = undefined; });\n return this.closing;\n }\n dispose() { this.disposed = true; void this.stop(); }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,oBAAoB,GAAG,OAA0B,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;AAEzH;MACa,mBAAmB,CAAA;IAU9B,WAAA,CAAoB,MAAsB,EAAU,WAAmB,EAC7D,OAAyB,EAAU,OAA2C,EAC9E,OAAkC,EAAA;QAFxB,IAAA,CAAA,MAAM,GAAN,MAAM;QAA0B,IAAA,CAAA,WAAW,GAAX,WAAW;QACrD,IAAA,CAAA,OAAO,GAAP,OAAO;QAA4B,IAAA,CAAA,OAAO,GAAP,OAAO;QAC1C,IAAA,CAAA,OAAO,GAAP,OAAO;QAXT,IAAA,CAAA,QAAQ,GAAG,oBAAoB,EAAE;QACjC,IAAA,CAAA,UAAU,GAAG,CAAC;QACd,IAAA,CAAA,QAAQ,GAAG,CAAC;AACZ,QAAA,IAAA,CAAA,gBAAgB,GAAe,MAAK,EAAE,CAAC;QAGvC,IAAA,CAAA,QAAQ,GAAG,KAAK;;QAEhB,IAAA,CAAA,YAAY,GAAG,CAAC;IAGuB;AAEvC,IAAA,MAAM,CAAC,KAAiC,EAAA;AAC9C,QAAA,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,KAAK,EAAE;QAC9C,IAAI,CAAC,IAAI,CAAC,QAAQ;AAAE,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjD;AACA,IAAA,IAAI,CAAC,KAAc,EAAA;AACjB,QAAA,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,OAAO,CAAC,KAAK,MAAM,KAAK,CAAC,OAAO,GAAG,CAAC,KAAK,IAAI,IA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CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACtF,QAAA,CAAC,GAAG,CAAC,OAAO,CAAC,MAAK,EAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,OAAO;IACrB;AACA,IAAA,OAAO,GAAA,EAAK,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AACrD;;;;;"}
|
package/dist/esm/api/client.d.ts
CHANGED
|
@@ -85,7 +85,8 @@ export declare class DevicApiClient {
|
|
|
85
85
|
private request;
|
|
86
86
|
private liveRequest;
|
|
87
87
|
createLiveSession(assistantId: string, body: CreateLiveSessionRequest): Promise<LiveVoiceSession>;
|
|
88
|
-
|
|
88
|
+
/** `touch`: the person confirmed they are still on the call; the server restarts its idle clock. */
|
|
89
|
+
getLiveSessionStatus(assistantId: string, sessionId: string, touch?: boolean): Promise<LiveVoiceSessionStatus>;
|
|
89
90
|
closeLiveSession(assistantId: string, sessionId: string): Promise<{
|
|
90
91
|
closing: boolean;
|
|
91
92
|
chatUid: string;
|
package/dist/esm/api/client.js
CHANGED
|
@@ -184,8 +184,9 @@ class DevicApiClient {
|
|
|
184
184
|
method: 'POST', body: JSON.stringify(body),
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
/** `touch`: the person confirmed they are still on the call; the server restarts its idle clock. */
|
|
188
|
+
getLiveSessionStatus(assistantId, sessionId, touch = false) {
|
|
189
|
+
return this.liveRequest(`/api/v1/assistants/${encodeURIComponent(assistantId)}/live/sessions/${encodeURIComponent(sessionId)}${touch ? '?touch=1' : ''}`);
|
|
189
190
|
}
|
|
190
191
|
closeLiveSession(assistantId, sessionId) {
|
|
191
192
|
return this.liveRequest(`/api/v1/assistants/${encodeURIComponent(assistantId)}/live/sessions/${encodeURIComponent(sessionId)}`, { method: 'DELETE', keepalive: true });
|