@d-id/client-sdk 2.0.7 → 2.0.8-staging.406
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 +21 -20
- package/dist/{index-DeKPoqBL.js → index-DUjMi4Bk.js} +2286 -2270
- package/dist/index.js +22 -21
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-D7YZEQiJ.js → livekit-manager-6LqByuLV.js} +205 -186
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +2 -1
- package/dist/src/services/socket-manager/message-queue.d.ts +1 -1
- package/dist/src/services/streaming-manager/stats/poll.d.ts +1 -1
- package/dist/src/services/streaming-manager/stats/report.d.ts +1 -1
- package/dist/src/types/entities/agents/manager.d.ts +2 -1
- package/dist/src/types/stream/stream.d.ts +19 -0
- package/dist/src/utils/stream-end.d.ts +5 -0
- package/dist/src/utils/stream-end.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,94 +1,96 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
function
|
|
1
|
+
import { c as Qe, C as J, S as l, a as We, b as qe, A as C, d as Ge, l as pe, e as He, t as Xe, f as A, g as U, h as Ze, D as me, i as Ye, j as b, n as en } from "./index-DUjMi4Bk.js";
|
|
2
|
+
function nn() {
|
|
3
3
|
try {
|
|
4
4
|
return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
|
|
5
5
|
} catch {
|
|
6
6
|
return "";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function tn() {
|
|
10
10
|
if (typeof navigator > "u")
|
|
11
11
|
return "";
|
|
12
|
-
const
|
|
12
|
+
const f = navigator.userAgent ?? "", S = (navigator.platform ?? "").toLowerCase();
|
|
13
13
|
let u = "Unknown";
|
|
14
|
-
/android/i.test(
|
|
15
|
-
const i = u === "Android" || u === "iOS" || /Mobi/i.test(
|
|
14
|
+
/android/i.test(f) ? u = "Android" : /iphone|ipad|ipod/i.test(f) ? u = "iOS" : S.includes("win") ? u = "Windows" : S.includes("mac") ? u = "Mac OS X" : S.includes("linux") && (u = "Linux");
|
|
15
|
+
const i = u === "Android" || u === "iOS" || /Mobi/i.test(f);
|
|
16
16
|
return `${u}, ${i ? "Mobile" : "Desktop"}`;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const u =
|
|
22
|
-
return u && (
|
|
18
|
+
function on() {
|
|
19
|
+
const f = {}, S = nn();
|
|
20
|
+
S && (f.timezone = S);
|
|
21
|
+
const u = tn();
|
|
22
|
+
return u && (f.device = u), f;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const k =
|
|
24
|
+
function rn(f, S, u, i) {
|
|
25
|
+
const k = Qe(f, `${S}/v2/agents/${u}`, i);
|
|
26
26
|
return {
|
|
27
27
|
async createStream(g) {
|
|
28
28
|
return k.post("/sessions", g);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
},
|
|
36
|
-
async function
|
|
32
|
+
const an = {
|
|
33
|
+
[l.ChatAnswer]: J.Answer,
|
|
34
|
+
[l.ChatPartial]: J.Partial
|
|
35
|
+
}, Ce = 2e4, cn = [];
|
|
36
|
+
async function sn() {
|
|
37
37
|
try {
|
|
38
|
-
return await import("./index-
|
|
38
|
+
return await import("./index-DUjMi4Bk.js").then((f) => f.G);
|
|
39
39
|
} catch {
|
|
40
40
|
throw new Error(
|
|
41
41
|
"LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
const
|
|
45
|
+
const un = {
|
|
46
46
|
excellent: U.Strong,
|
|
47
47
|
good: U.Strong,
|
|
48
48
|
poor: U.Weak,
|
|
49
49
|
lost: U.Unknown,
|
|
50
50
|
unknown: U.Unknown
|
|
51
|
-
},
|
|
52
|
-
function
|
|
51
|
+
}, j = (f = "Stream Error") => new He(f);
|
|
52
|
+
function Se(f, S, u) {
|
|
53
53
|
var i, k;
|
|
54
|
-
throw
|
|
54
|
+
throw S("Failed to connect to LiveKit room:", f), (i = u.onConnectionStateChange) == null || i.call(u, A.Fail, "internal:init-error"), (k = u.onError) == null || k.call(u, f, { sessionId: "" }), f;
|
|
55
55
|
}
|
|
56
|
-
async function
|
|
57
|
-
var
|
|
58
|
-
const i =
|
|
56
|
+
async function ln(f, S, u) {
|
|
57
|
+
var de;
|
|
58
|
+
const i = We(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: g, ConnectionState: I, Track: ee } = await sn(), { callbacks: n, auth: Te, baseURL: ve, analytics: ne } = u;
|
|
59
59
|
let a = null, E = !1;
|
|
60
|
-
const
|
|
60
|
+
const te = qe.Fluent;
|
|
61
61
|
let L = null;
|
|
62
62
|
const P = { isPublishing: !1, publication: null }, Q = { isPublishing: !1, publication: null };
|
|
63
|
-
let
|
|
63
|
+
let p = null, T = null, O = null, K = !1;
|
|
64
64
|
a = new k({
|
|
65
65
|
adaptiveStream: !1,
|
|
66
66
|
// Must be false to use mediaStreamTrack directly
|
|
67
67
|
dynacast: !0
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let
|
|
72
|
-
const
|
|
73
|
-
let
|
|
69
|
+
for (const [e, t] of u.rpcMethods ?? [])
|
|
70
|
+
a.registerRpcMethod(e, t);
|
|
71
|
+
let R = null, M = C.Idle, W = !0;
|
|
72
|
+
const v = /* @__PURE__ */ new Map();
|
|
73
|
+
let x = null, q = null;
|
|
74
|
+
const ye = rn(Te, ve || Ge, f, n.onError);
|
|
75
|
+
let y, _, $, ie = !0;
|
|
74
76
|
try {
|
|
75
|
-
const e = await
|
|
76
|
-
transport:
|
|
77
|
-
chat_persist:
|
|
77
|
+
const e = await ye.createStream({
|
|
78
|
+
transport: S.transport,
|
|
79
|
+
chat_persist: S.chat_persist ?? !0,
|
|
78
80
|
verbose: u.verbose ?? !1
|
|
79
81
|
}), { id: t, session_token: o, session_url: r, interrupt_enabled: c } = e;
|
|
80
|
-
(
|
|
82
|
+
(de = n.onStreamCreated) == null || de.call(n, { session_id: t, stream_id: t, agent_id: f }), y = t, _ = o, $ = r, ie = c ?? !0, await a.prepareConnection($, _);
|
|
81
83
|
} catch (e) {
|
|
82
|
-
|
|
84
|
+
Se(e, i, n);
|
|
83
85
|
}
|
|
84
|
-
if (!$ || !_ || !
|
|
86
|
+
if (!$ || !_ || !y)
|
|
85
87
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
86
|
-
a.on(g.ConnectionStateChanged,
|
|
87
|
-
function
|
|
88
|
+
a.on(g.ConnectionStateChanged, Ee).on(g.ConnectionQualityChanged, Re).on(g.ParticipantConnected, be).on(g.ParticipantDisconnected, Le).on(g.TrackSubscribed, Me).on(g.TrackUnsubscribed, ke).on(g.DataReceived, Ve).on(g.MediaDevicesError, Fe).on(g.TranscriptionReceived, we).on(g.EncryptionError, Ue).on(g.TrackSubscriptionFailed, je);
|
|
89
|
+
function we(e, t) {
|
|
88
90
|
t != null && t.isLocal && pe.update();
|
|
89
91
|
}
|
|
90
|
-
async function
|
|
91
|
-
const e =
|
|
92
|
+
async function Ae() {
|
|
93
|
+
const e = on();
|
|
92
94
|
if (!(!a || Object.keys(e).length === 0))
|
|
93
95
|
try {
|
|
94
96
|
await a.localParticipant.setAttributes(e);
|
|
@@ -97,24 +99,24 @@ async function un(l, C, u) {
|
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
try {
|
|
100
|
-
await a.connect($, _), i("LiveKit room joined successfully"),
|
|
102
|
+
await a.connect($, _), i("LiveKit room joined successfully"), Ae(), R = setTimeout(() => {
|
|
101
103
|
var t;
|
|
102
104
|
i(
|
|
103
|
-
`Track subscription timeout - no track subscribed within ${
|
|
105
|
+
`Track subscription timeout - no track subscribed within ${Ce / 1e3} seconds after connect`
|
|
104
106
|
), R = null;
|
|
105
|
-
const e =
|
|
106
|
-
|
|
107
|
-
error:
|
|
108
|
-
sessionId:
|
|
109
|
-
}), (t = n.onError) == null || t.call(n, e, { sessionId:
|
|
110
|
-
},
|
|
107
|
+
const e = j("Track subscription timeout");
|
|
108
|
+
ne.track("connectivity-error", {
|
|
109
|
+
error: Xe(e),
|
|
110
|
+
sessionId: y
|
|
111
|
+
}), (t = n.onError) == null || t.call(n, e, { sessionId: y }), Y("internal:track-subscription-timeout");
|
|
112
|
+
}, Ce);
|
|
111
113
|
} catch (e) {
|
|
112
|
-
|
|
114
|
+
Se(e, i, n);
|
|
113
115
|
}
|
|
114
|
-
|
|
115
|
-
"stream-type":
|
|
116
|
+
ne.enrich({
|
|
117
|
+
"stream-type": te
|
|
116
118
|
});
|
|
117
|
-
function
|
|
119
|
+
function Ee(e) {
|
|
118
120
|
var t, o, r, c;
|
|
119
121
|
switch (i("Connection state changed:", e), e) {
|
|
120
122
|
case I.Connecting:
|
|
@@ -124,7 +126,11 @@ async function un(l, C, u) {
|
|
|
124
126
|
i("LiveKit room connected successfully"), E = !0;
|
|
125
127
|
break;
|
|
126
128
|
case I.Disconnected:
|
|
127
|
-
i("LiveKit room disconnected"), E = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(
|
|
129
|
+
i("LiveKit room disconnected"), E = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(
|
|
130
|
+
n,
|
|
131
|
+
A.Disconnected,
|
|
132
|
+
q ?? "livekit:disconnected"
|
|
133
|
+
);
|
|
128
134
|
break;
|
|
129
135
|
case I.Reconnecting:
|
|
130
136
|
i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, A.Connecting, "livekit:reconnecting");
|
|
@@ -134,25 +140,25 @@ async function un(l, C, u) {
|
|
|
134
140
|
break;
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
|
-
function
|
|
143
|
+
function Re(e, t) {
|
|
138
144
|
var o;
|
|
139
|
-
i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n,
|
|
145
|
+
i("Connection quality:", e), t != null && t.isLocal && ((o = n.onConnectivityStateChange) == null || o.call(n, un[e]));
|
|
140
146
|
}
|
|
141
|
-
function
|
|
147
|
+
function be(e) {
|
|
142
148
|
i("Participant connected:", e.identity);
|
|
143
149
|
}
|
|
144
|
-
function
|
|
145
|
-
i("Participant disconnected:", e.identity),
|
|
150
|
+
function Le(e) {
|
|
151
|
+
i("Participant disconnected:", e.identity), Y("livekit:participant-disconnected");
|
|
146
152
|
}
|
|
147
|
-
function
|
|
153
|
+
function Pe() {
|
|
148
154
|
var e;
|
|
149
|
-
|
|
155
|
+
O !== b.Start && (i("CALLBACK: onVideoStateChange(Start)"), O = b.Start, (e = n.onVideoStateChange) == null || e.call(n, b.Start));
|
|
150
156
|
}
|
|
151
|
-
function
|
|
157
|
+
function oe(e) {
|
|
152
158
|
var t;
|
|
153
|
-
|
|
159
|
+
O !== b.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), O = b.Stop, (t = n.onVideoStateChange) == null || t.call(n, b.Stop, e));
|
|
154
160
|
}
|
|
155
|
-
function
|
|
161
|
+
function Me(e, t, o) {
|
|
156
162
|
var c, d, s;
|
|
157
163
|
i(`Track subscribed: ${e.kind} from ${o.identity}`);
|
|
158
164
|
const r = e.mediaStreamTrack;
|
|
@@ -160,41 +166,41 @@ async function un(l, C, u) {
|
|
|
160
166
|
i(`No mediaStreamTrack available for ${e.kind}`);
|
|
161
167
|
return;
|
|
162
168
|
}
|
|
163
|
-
L ? (L.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (L = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (
|
|
169
|
+
L ? (L.addTrack(r), i(`Added ${e.kind} track to shared MediaStream`)) : (L = new MediaStream([r]), i(`Created shared MediaStream with ${e.kind} track`)), e.kind === "audio" && (T = Ye(
|
|
164
170
|
() => e.getRTCStatsReport(),
|
|
165
|
-
({ sttLatency:
|
|
166
|
-
var
|
|
171
|
+
({ sttLatency: h, serviceLatency: m }) => {
|
|
172
|
+
var le, fe, he;
|
|
167
173
|
const V = pe.get(!0);
|
|
168
174
|
let F = 0;
|
|
169
|
-
if (
|
|
170
|
-
const
|
|
171
|
-
F =
|
|
175
|
+
if (h) {
|
|
176
|
+
const ge = ((fe = (le = p == null ? void 0 : p.getReport()) == null ? void 0 : le.webRTCStats) == null ? void 0 : fe.avgRtt) ?? 0;
|
|
177
|
+
F = ge > 0 ? Math.round(ge * 1e3) : 0;
|
|
172
178
|
}
|
|
173
|
-
const D = V > 0 ? V + (
|
|
174
|
-
(
|
|
179
|
+
const D = V > 0 ? V + (h ?? 0) + F : void 0, w = D !== void 0 && m !== void 0 ? D - m : void 0;
|
|
180
|
+
(he = n.onFirstAudioDetected) == null || he.call(n, { latency: D, networkLatency: w });
|
|
175
181
|
}
|
|
176
|
-
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, A.Connected, "livekit:track-subscribed")),
|
|
182
|
+
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, A.Connected, "livekit:track-subscribed")), p = Ze(
|
|
177
183
|
() => e.getRTCStatsReport(),
|
|
178
184
|
() => E,
|
|
179
|
-
|
|
180
|
-
(
|
|
181
|
-
i(`Video state change: ${
|
|
185
|
+
en,
|
|
186
|
+
(h, m) => {
|
|
187
|
+
i(`Video state change: ${h}`), h === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")), Pe()) : h === b.Stop && oe(m);
|
|
182
188
|
}
|
|
183
|
-
),
|
|
189
|
+
), p.start());
|
|
184
190
|
}
|
|
185
|
-
function
|
|
186
|
-
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (
|
|
191
|
+
function ke(e, t, o) {
|
|
192
|
+
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (T == null || T.destroy(), T = null), e.kind === "video" && (oe((p == null ? void 0 : p.getReport()) ?? void 0), p == null || p.stop(), p = null);
|
|
187
193
|
}
|
|
188
|
-
function
|
|
194
|
+
function re(e, t) {
|
|
189
195
|
var r;
|
|
190
|
-
const o =
|
|
196
|
+
const o = an[e];
|
|
191
197
|
o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
|
|
192
198
|
}
|
|
193
|
-
function
|
|
199
|
+
function G(e, t) {
|
|
194
200
|
var o, r, c, d;
|
|
195
|
-
if (e ===
|
|
201
|
+
if (e === l.ToolCallStarted) {
|
|
196
202
|
const s = t;
|
|
197
|
-
|
|
203
|
+
v.set(s.call_id, {
|
|
198
204
|
call: {
|
|
199
205
|
callId: s.call_id,
|
|
200
206
|
name: s.name,
|
|
@@ -202,115 +208,128 @@ async function un(l, C, u) {
|
|
|
202
208
|
},
|
|
203
209
|
interruptible: s.interruptible === !0,
|
|
204
210
|
turnId: s.turn_id ?? x
|
|
205
|
-
}), N(), z(), M =
|
|
211
|
+
}), N(), z(), M = C.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, C.ToolActive), (r = n.onToolEvent) == null || r.call(n, l.ToolCallStarted, s);
|
|
206
212
|
return;
|
|
207
213
|
}
|
|
208
|
-
if (e ===
|
|
214
|
+
if (e === l.ToolCallDone) {
|
|
209
215
|
const s = t;
|
|
210
|
-
|
|
216
|
+
ae(s.call_id), (c = n.onToolEvent) == null || c.call(n, l.ToolCallDone, s);
|
|
211
217
|
return;
|
|
212
218
|
}
|
|
213
|
-
if (e ===
|
|
219
|
+
if (e === l.ToolCallError) {
|
|
214
220
|
const s = t;
|
|
215
|
-
|
|
221
|
+
ae(s.call_id), (d = n.onToolEvent) == null || d.call(n, l.ToolCallError, s);
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
|
-
function
|
|
219
|
-
|
|
224
|
+
function ae(e) {
|
|
225
|
+
v.delete(e) && (N(), z());
|
|
220
226
|
}
|
|
221
|
-
function
|
|
227
|
+
function Ie(e) {
|
|
222
228
|
let t = !1;
|
|
223
|
-
for (const [o, r] of
|
|
224
|
-
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (
|
|
229
|
+
for (const [o, r] of v)
|
|
230
|
+
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (v.delete(o), t = !0));
|
|
225
231
|
t && (N(), z());
|
|
226
232
|
}
|
|
227
233
|
function N() {
|
|
228
234
|
var t;
|
|
229
|
-
const e = ![...
|
|
235
|
+
const e = ![...v.values()].some(({ call: o }) => o.executionMode === "blocking");
|
|
230
236
|
e !== W && (W = e, (t = n.onInterruptibleChange) == null || t.call(n, e));
|
|
231
237
|
}
|
|
232
238
|
function z() {
|
|
233
239
|
var e;
|
|
234
240
|
(e = n.onRunningToolCallsChange) == null || e.call(
|
|
235
241
|
n,
|
|
236
|
-
|
|
242
|
+
v.size === 0 ? cn : [...v.values()].map(({ call: t }) => t)
|
|
237
243
|
);
|
|
238
244
|
}
|
|
239
|
-
function
|
|
245
|
+
function _e(e, t) {
|
|
240
246
|
var o, r, c;
|
|
241
|
-
if (e ===
|
|
242
|
-
M =
|
|
247
|
+
if (e === l.StreamVideoCreated) {
|
|
248
|
+
M = C.Talking, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Talking), T == null || T.arm({
|
|
243
249
|
sttLatency: (r = t == null ? void 0 : t.stt) == null ? void 0 : r.latency,
|
|
244
250
|
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
245
251
|
});
|
|
246
252
|
return;
|
|
247
253
|
}
|
|
248
|
-
if (
|
|
249
|
-
M !==
|
|
254
|
+
if (v.size > 0) {
|
|
255
|
+
M !== C.ToolActive && (M = C.ToolActive, (c = n.onAgentActivityStateChange) == null || c.call(n, C.ToolActive));
|
|
250
256
|
return;
|
|
251
257
|
}
|
|
252
258
|
}
|
|
253
259
|
function B(e, t) {
|
|
254
|
-
var d, s,
|
|
255
|
-
const o = ((s = (d =
|
|
256
|
-
u.debug && ((
|
|
260
|
+
var d, s, h, m;
|
|
261
|
+
const o = ((s = (d = p == null ? void 0 : p.getReport()) == null ? void 0 : d.webRTCStats) == null ? void 0 : s.avgRtt) ?? 0, r = o > 0 ? Math.round(o / 2 * 1e3) : 0, c = { ...t, downstreamNetworkLatency: r };
|
|
262
|
+
u.debug && ((h = t == null ? void 0 : t.metadata) != null && h.sentiment) && (c.sentiment = {
|
|
257
263
|
id: t.metadata.sentiment.id,
|
|
258
264
|
name: t.metadata.sentiment.sentiment
|
|
259
|
-
}), (
|
|
265
|
+
}), (m = n.onMessage) == null || m.call(n, e, c), _e(e, t);
|
|
260
266
|
}
|
|
261
|
-
function
|
|
267
|
+
function $e(e, t) {
|
|
262
268
|
var o;
|
|
263
269
|
(o = n.onMessage) == null || o.call(n, J.Transcribe, { event: J.Transcribe, ...t }), queueMicrotask(() => {
|
|
264
270
|
var r;
|
|
265
|
-
(r = n.onAgentActivityStateChange) == null || r.call(n,
|
|
271
|
+
(r = n.onAgentActivityStateChange) == null || r.call(n, C.Loading);
|
|
266
272
|
});
|
|
267
273
|
}
|
|
268
|
-
function
|
|
274
|
+
function De(e, t) {
|
|
269
275
|
var o;
|
|
270
|
-
x = (t == null ? void 0 : t.turn_id) ?? null, M =
|
|
276
|
+
x = (t == null ? void 0 : t.turn_id) ?? null, M = C.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Loading);
|
|
271
277
|
}
|
|
272
|
-
function
|
|
278
|
+
function Ke(e, t) {
|
|
273
279
|
var r;
|
|
274
280
|
const o = (t == null ? void 0 : t.turn_id) ?? null;
|
|
275
|
-
x !== null && o !== null && o < x || (
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
[
|
|
282
|
-
[
|
|
283
|
-
[
|
|
284
|
-
[
|
|
285
|
-
[
|
|
286
|
-
[
|
|
287
|
-
[
|
|
288
|
-
[
|
|
289
|
-
[
|
|
281
|
+
x !== null && o !== null && o < x || (Ie(o), M = C.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, C.Idle));
|
|
282
|
+
}
|
|
283
|
+
function ce(e, t) {
|
|
284
|
+
q = (t == null ? void 0 : t.reason) ?? null;
|
|
285
|
+
}
|
|
286
|
+
const xe = {
|
|
287
|
+
[l.ChatAnswer]: re,
|
|
288
|
+
[l.ChatPartial]: re,
|
|
289
|
+
[l.ToolCallStarted]: G,
|
|
290
|
+
[l.ToolCallDone]: G,
|
|
291
|
+
[l.ToolCallError]: G,
|
|
292
|
+
[l.StreamVideoCreated]: B,
|
|
293
|
+
[l.StreamVideoDone]: B,
|
|
294
|
+
[l.StreamVideoError]: B,
|
|
295
|
+
[l.StreamVideoRejected]: B,
|
|
296
|
+
[l.ChatAudioTranscribed]: $e,
|
|
297
|
+
[l.TurnStarted]: De,
|
|
298
|
+
[l.TurnEnded]: Ke,
|
|
299
|
+
[l.StreamDone]: ce,
|
|
300
|
+
[l.StreamFailed]: ce
|
|
290
301
|
};
|
|
291
|
-
function
|
|
302
|
+
function Ve(e, t, o, r) {
|
|
292
303
|
const c = new TextDecoder().decode(e);
|
|
304
|
+
let d;
|
|
293
305
|
try {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
} catch (d) {
|
|
299
|
-
i("Failed to parse data channel message:", d);
|
|
306
|
+
d = JSON.parse(c);
|
|
307
|
+
} catch (m) {
|
|
308
|
+
i("Failed to parse data channel message:", m);
|
|
309
|
+
return;
|
|
300
310
|
}
|
|
311
|
+
const s = r || d.subject;
|
|
312
|
+
if (i("Data received:", { subject: s, data: d }), !s) return;
|
|
313
|
+
const h = xe[s];
|
|
314
|
+
if (h)
|
|
315
|
+
try {
|
|
316
|
+
h(s, d);
|
|
317
|
+
} catch (m) {
|
|
318
|
+
console.warn("[LiveKitStreamingManager] Data channel handler failed", { subject: s, error: m });
|
|
319
|
+
}
|
|
301
320
|
}
|
|
302
|
-
function
|
|
321
|
+
function Fe(e) {
|
|
303
322
|
var t;
|
|
304
|
-
i("Media devices error:", e), (t = n.onError) == null || t.call(n,
|
|
323
|
+
i("Media devices error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: y });
|
|
305
324
|
}
|
|
306
|
-
function
|
|
325
|
+
function Ue(e) {
|
|
307
326
|
var t;
|
|
308
|
-
i("Encryption error:", e), (t = n.onError) == null || t.call(n,
|
|
327
|
+
i("Encryption error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: y });
|
|
309
328
|
}
|
|
310
|
-
function
|
|
329
|
+
function je(e, t, o) {
|
|
311
330
|
i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
|
|
312
331
|
}
|
|
313
|
-
function
|
|
332
|
+
function Oe(e, t, o) {
|
|
314
333
|
for (const [r, c] of o)
|
|
315
334
|
if (c.source === t && c.track) {
|
|
316
335
|
const d = c.track.mediaStreamTrack;
|
|
@@ -319,7 +338,7 @@ async function un(l, C, u) {
|
|
|
319
338
|
}
|
|
320
339
|
return null;
|
|
321
340
|
}
|
|
322
|
-
async function
|
|
341
|
+
async function se(e, t, o, r, c, d) {
|
|
323
342
|
var V, F, D;
|
|
324
343
|
if (!E || !a)
|
|
325
344
|
throw i(`Room is not connected, cannot publish ${r} stream`), new Error("Room is not connected");
|
|
@@ -330,28 +349,28 @@ async function un(l, C, u) {
|
|
|
330
349
|
const s = o(t);
|
|
331
350
|
if (s.length === 0)
|
|
332
351
|
throw new Error(`No ${r} track found in the provided MediaStream`);
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
352
|
+
const h = s[0], m = Oe(h, r, c());
|
|
353
|
+
if (m) {
|
|
335
354
|
i(`${r} track is already published, skipping`, {
|
|
336
|
-
trackId:
|
|
337
|
-
publishedTrackId: (F = (V =
|
|
338
|
-
}), e.publication =
|
|
355
|
+
trackId: h.id,
|
|
356
|
+
publishedTrackId: (F = (V = m.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : F.id
|
|
357
|
+
}), e.publication = m;
|
|
339
358
|
return;
|
|
340
359
|
}
|
|
341
360
|
if ((D = e.publication) != null && D.track) {
|
|
342
361
|
const w = e.publication.track.mediaStreamTrack;
|
|
343
|
-
w !==
|
|
362
|
+
w !== h && (w == null ? void 0 : w.id) !== h.id && (i(`Unpublishing existing ${r} track before publishing new one`), await d());
|
|
344
363
|
}
|
|
345
|
-
i(`Publishing ${r} track from provided MediaStream`, { trackId:
|
|
364
|
+
i(`Publishing ${r} track from provided MediaStream`, { trackId: h.id }), e.isPublishing = !0;
|
|
346
365
|
try {
|
|
347
|
-
e.publication = await a.localParticipant.publishTrack(
|
|
366
|
+
e.publication = await a.localParticipant.publishTrack(h, { source: r }), i(`${r} track published successfully`, { trackSid: e.publication.trackSid });
|
|
348
367
|
} catch (w) {
|
|
349
368
|
throw i(`Failed to publish ${r} track:`, w), w;
|
|
350
369
|
} finally {
|
|
351
370
|
e.isPublishing = !1;
|
|
352
371
|
}
|
|
353
372
|
}
|
|
354
|
-
async function
|
|
373
|
+
async function ue(e, t) {
|
|
355
374
|
if (!(!e.publication || !e.publication.track))
|
|
356
375
|
try {
|
|
357
376
|
a && (await a.localParticipant.unpublishTrack(e.publication.track, !1), i(`${t} track unpublished`));
|
|
@@ -361,20 +380,20 @@ async function un(l, C, u) {
|
|
|
361
380
|
e.publication = null;
|
|
362
381
|
}
|
|
363
382
|
}
|
|
364
|
-
async function
|
|
365
|
-
return
|
|
383
|
+
async function Ne(e) {
|
|
384
|
+
return se(
|
|
366
385
|
P,
|
|
367
386
|
e,
|
|
368
387
|
(t) => t.getAudioTracks(),
|
|
369
|
-
|
|
388
|
+
ee.Source.Microphone,
|
|
370
389
|
() => a.localParticipant.audioTrackPublications,
|
|
371
|
-
|
|
390
|
+
H
|
|
372
391
|
);
|
|
373
392
|
}
|
|
374
|
-
async function
|
|
375
|
-
return
|
|
393
|
+
async function H() {
|
|
394
|
+
return ue(P, "Microphone");
|
|
376
395
|
}
|
|
377
|
-
async function
|
|
396
|
+
async function ze(e) {
|
|
378
397
|
if (!E || !a)
|
|
379
398
|
throw i("Cannot replace microphone track: room is not connected"), new Error("Room is not connected");
|
|
380
399
|
if (e.kind !== "audio")
|
|
@@ -390,46 +409,46 @@ async function un(l, C, u) {
|
|
|
390
409
|
P.isPublishing = !1;
|
|
391
410
|
}
|
|
392
411
|
}
|
|
393
|
-
async function
|
|
394
|
-
return
|
|
412
|
+
async function Be(e) {
|
|
413
|
+
return se(
|
|
395
414
|
Q,
|
|
396
415
|
e,
|
|
397
416
|
(t) => t.getVideoTracks(),
|
|
398
|
-
|
|
417
|
+
ee.Source.Camera,
|
|
399
418
|
() => a.localParticipant.videoTrackPublications,
|
|
400
|
-
|
|
419
|
+
X
|
|
401
420
|
);
|
|
402
421
|
}
|
|
403
|
-
async function
|
|
404
|
-
return
|
|
422
|
+
async function X() {
|
|
423
|
+
return ue(Q, "Camera");
|
|
405
424
|
}
|
|
406
|
-
function
|
|
425
|
+
function Je() {
|
|
407
426
|
L && (L.getTracks().forEach((e) => e.stop()), L = null);
|
|
408
427
|
}
|
|
409
|
-
async function
|
|
428
|
+
async function Z(e, t) {
|
|
410
429
|
var o, r;
|
|
411
430
|
if (!E || !a) {
|
|
412
|
-
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n,
|
|
413
|
-
sessionId:
|
|
431
|
+
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, j(), {
|
|
432
|
+
sessionId: y
|
|
414
433
|
});
|
|
415
434
|
return;
|
|
416
435
|
}
|
|
417
436
|
try {
|
|
418
437
|
await a.localParticipant.sendText(t, { topic: e }), i("Message sent successfully:", t);
|
|
419
438
|
} catch (c) {
|
|
420
|
-
i("Failed to send message:", c), (r = n.onError) == null || r.call(n,
|
|
439
|
+
i("Failed to send message:", c), (r = n.onError) == null || r.call(n, j(), { sessionId: y });
|
|
421
440
|
}
|
|
422
441
|
}
|
|
423
|
-
async function
|
|
442
|
+
async function Y(e) {
|
|
424
443
|
var t, o;
|
|
425
|
-
R && (clearTimeout(R), R = null),
|
|
444
|
+
R && (clearTimeout(R), R = null), T == null || T.destroy(), T = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, A.Disconnecting, e), await Promise.all([H(), X()]), await a.disconnect()), Je(), E = !1, K = !1, v.size > 0 && (v.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Idle), M = C.Idle;
|
|
426
445
|
}
|
|
427
446
|
return {
|
|
428
447
|
speak(e) {
|
|
429
448
|
const t = typeof e == "string" ? e : JSON.stringify(e);
|
|
430
|
-
return
|
|
449
|
+
return Z(me.Speak, t);
|
|
431
450
|
},
|
|
432
|
-
disconnect: () =>
|
|
451
|
+
disconnect: () => Y("user:disconnect"),
|
|
433
452
|
async reconnect() {
|
|
434
453
|
var e, t;
|
|
435
454
|
if ((a == null ? void 0 : a.state) === I.Connected) {
|
|
@@ -438,7 +457,7 @@ async function un(l, C, u) {
|
|
|
438
457
|
}
|
|
439
458
|
if (!a || !$ || !_)
|
|
440
459
|
throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
441
|
-
i("Reconnecting to LiveKit room, state:", a.state), K = !1, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
|
|
460
|
+
i("Reconnecting to LiveKit room, state:", a.state), K = !1, q = null, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
|
|
442
461
|
try {
|
|
443
462
|
if (await a.connect($, _), i("Room reconnected"), E = !0, a.remoteParticipants.size === 0) {
|
|
444
463
|
if (i("Waiting for agent to join..."), !await new Promise((r) => {
|
|
@@ -456,14 +475,14 @@ async function un(l, C, u) {
|
|
|
456
475
|
throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, A.Fail, "user:reconnect-failed"), o;
|
|
457
476
|
}
|
|
458
477
|
},
|
|
459
|
-
sendDataChannelMessage:
|
|
460
|
-
publishMicrophoneStream:
|
|
461
|
-
unpublishMicrophoneStream:
|
|
462
|
-
replaceMicrophoneTrack:
|
|
463
|
-
publishCameraStream:
|
|
464
|
-
unpublishCameraStream:
|
|
478
|
+
sendDataChannelMessage: Z,
|
|
479
|
+
publishMicrophoneStream: Ne,
|
|
480
|
+
unpublishMicrophoneStream: H,
|
|
481
|
+
replaceMicrophoneTrack: ze,
|
|
482
|
+
publishCameraStream: Be,
|
|
483
|
+
unpublishCameraStream: X,
|
|
465
484
|
interrupt(e) {
|
|
466
|
-
e !== "text" &&
|
|
485
|
+
e !== "text" && Z(me.Interrupt, "");
|
|
467
486
|
},
|
|
468
487
|
registerRpcMethod(e, t) {
|
|
469
488
|
a == null || a.registerRpcMethod(e, t);
|
|
@@ -471,14 +490,14 @@ async function un(l, C, u) {
|
|
|
471
490
|
unregisterRpcMethod(e) {
|
|
472
491
|
a == null || a.unregisterRpcMethod(e);
|
|
473
492
|
},
|
|
474
|
-
sessionId:
|
|
475
|
-
streamId:
|
|
476
|
-
streamType:
|
|
477
|
-
interruptAvailable:
|
|
493
|
+
sessionId: y,
|
|
494
|
+
streamId: y,
|
|
495
|
+
streamType: te,
|
|
496
|
+
interruptAvailable: ie,
|
|
478
497
|
isInterruptible: W
|
|
479
498
|
};
|
|
480
499
|
}
|
|
481
500
|
export {
|
|
482
|
-
|
|
483
|
-
|
|
501
|
+
ln as createLiveKitStreamingManager,
|
|
502
|
+
Se as handleInitError
|
|
484
503
|
};
|