@d-id/client-sdk 2.0.7-staging.403 → 2.0.7-staging.404
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-Blb-TUoJ.js → index-BIUmlXCc.js} +2093 -2083
- package/dist/index.js +22 -21
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-BW499fIa.js → livekit-manager-CyKx_r7E.js} +158 -149
- package/dist/src/services/socket-manager/message-queue.d.ts +1 -1
- package/dist/src/types/entities/agents/manager.d.ts +2 -1
- package/dist/src/types/stream/stream.d.ts +9 -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,66 +1,66 @@
|
|
|
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 m, d as Ge, l as he, 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-BIUmlXCc.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 ?? "", C = (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" : C.includes("win") ? u = "Windows" : C.includes("mac") ? u = "Mac OS X" : C.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
|
-
C && (
|
|
21
|
-
const u =
|
|
22
|
-
return u && (
|
|
18
|
+
function on() {
|
|
19
|
+
const f = {}, C = nn();
|
|
20
|
+
C && (f.timezone = C);
|
|
21
|
+
const u = tn();
|
|
22
|
+
return u && (f.device = u), f;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const k =
|
|
24
|
+
function rn(f, C, u, i) {
|
|
25
|
+
const k = Qe(f, `${C}/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-BIUmlXCc.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, C, u) {
|
|
53
53
|
var i, k;
|
|
54
|
-
throw C("Failed to connect to LiveKit room:",
|
|
54
|
+
throw C("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, C, 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: ye, 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 h = null, S = null,
|
|
63
|
+
let h = null, S = null, O = null, K = !1;
|
|
64
64
|
a = new k({
|
|
65
65
|
adaptiveStream: !1,
|
|
66
66
|
// Must be false to use mediaStreamTrack directly
|
|
@@ -70,27 +70,27 @@ async function un(l, C, u) {
|
|
|
70
70
|
a.registerRpcMethod(e, t);
|
|
71
71
|
let R = null, M = m.Idle, W = !0;
|
|
72
72
|
const y = /* @__PURE__ */ new Map();
|
|
73
|
-
let x = null;
|
|
74
|
-
const
|
|
75
|
-
let v, _, $,
|
|
73
|
+
let x = null, q = null;
|
|
74
|
+
const ve = rn(Te, ye || Ge, f, n.onError);
|
|
75
|
+
let v, _, $, ie = !0;
|
|
76
76
|
try {
|
|
77
|
-
const e = await
|
|
77
|
+
const e = await ve.createStream({
|
|
78
78
|
transport: C.transport,
|
|
79
79
|
chat_persist: C.chat_persist ?? !0,
|
|
80
80
|
verbose: u.verbose ?? !1
|
|
81
81
|
}), { id: t, session_token: o, session_url: r, interrupt_enabled: c } = e;
|
|
82
|
-
(
|
|
82
|
+
(de = n.onStreamCreated) == null || de.call(n, { session_id: t, stream_id: t, agent_id: f }), v = t, _ = o, $ = r, ie = c ?? !0, await a.prepareConnection($, _);
|
|
83
83
|
} catch (e) {
|
|
84
|
-
|
|
84
|
+
Se(e, i, n);
|
|
85
85
|
}
|
|
86
86
|
if (!$ || !_ || !v)
|
|
87
87
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
88
|
-
a.on(g.ConnectionStateChanged,
|
|
89
|
-
function
|
|
90
|
-
t != null && t.isLocal &&
|
|
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) {
|
|
90
|
+
t != null && t.isLocal && he.update();
|
|
91
91
|
}
|
|
92
|
-
async function
|
|
93
|
-
const e =
|
|
92
|
+
async function Ae() {
|
|
93
|
+
const e = on();
|
|
94
94
|
if (!(!a || Object.keys(e).length === 0))
|
|
95
95
|
try {
|
|
96
96
|
await a.localParticipant.setAttributes(e);
|
|
@@ -99,24 +99,24 @@ async function un(l, C, u) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
try {
|
|
102
|
-
await a.connect($, _), i("LiveKit room joined successfully"),
|
|
102
|
+
await a.connect($, _), i("LiveKit room joined successfully"), Ae(), R = setTimeout(() => {
|
|
103
103
|
var t;
|
|
104
104
|
i(
|
|
105
|
-
`Track subscription timeout - no track subscribed within ${
|
|
105
|
+
`Track subscription timeout - no track subscribed within ${Ce / 1e3} seconds after connect`
|
|
106
106
|
), R = null;
|
|
107
|
-
const e =
|
|
108
|
-
|
|
109
|
-
error:
|
|
107
|
+
const e = j("Track subscription timeout");
|
|
108
|
+
ne.track("connectivity-error", {
|
|
109
|
+
error: Xe(e),
|
|
110
110
|
sessionId: v
|
|
111
|
-
}), (t = n.onError) == null || t.call(n, e, { sessionId: v }),
|
|
112
|
-
},
|
|
111
|
+
}), (t = n.onError) == null || t.call(n, e, { sessionId: v }), Y("internal:track-subscription-timeout");
|
|
112
|
+
}, Ce);
|
|
113
113
|
} catch (e) {
|
|
114
|
-
|
|
114
|
+
Se(e, i, n);
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
"stream-type":
|
|
116
|
+
ne.enrich({
|
|
117
|
+
"stream-type": te
|
|
118
118
|
});
|
|
119
|
-
function
|
|
119
|
+
function Ee(e) {
|
|
120
120
|
var t, o, r, c;
|
|
121
121
|
switch (i("Connection state changed:", e), e) {
|
|
122
122
|
case I.Connecting:
|
|
@@ -126,7 +126,11 @@ async function un(l, C, u) {
|
|
|
126
126
|
i("LiveKit room connected successfully"), E = !0;
|
|
127
127
|
break;
|
|
128
128
|
case I.Disconnected:
|
|
129
|
-
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
|
+
);
|
|
130
134
|
break;
|
|
131
135
|
case I.Reconnecting:
|
|
132
136
|
i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, A.Connecting, "livekit:reconnecting");
|
|
@@ -136,25 +140,25 @@ async function un(l, C, u) {
|
|
|
136
140
|
break;
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
|
-
function
|
|
143
|
+
function Re(e, t) {
|
|
140
144
|
var o;
|
|
141
|
-
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]));
|
|
142
146
|
}
|
|
143
|
-
function
|
|
147
|
+
function be(e) {
|
|
144
148
|
i("Participant connected:", e.identity);
|
|
145
149
|
}
|
|
146
|
-
function
|
|
147
|
-
i("Participant disconnected:", e.identity),
|
|
150
|
+
function Le(e) {
|
|
151
|
+
i("Participant disconnected:", e.identity), Y("livekit:participant-disconnected");
|
|
148
152
|
}
|
|
149
|
-
function
|
|
153
|
+
function Pe() {
|
|
150
154
|
var e;
|
|
151
|
-
|
|
155
|
+
O !== b.Start && (i("CALLBACK: onVideoStateChange(Start)"), O = b.Start, (e = n.onVideoStateChange) == null || e.call(n, b.Start));
|
|
152
156
|
}
|
|
153
|
-
function
|
|
157
|
+
function oe(e) {
|
|
154
158
|
var t;
|
|
155
|
-
|
|
159
|
+
O !== b.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), O = b.Stop, (t = n.onVideoStateChange) == null || t.call(n, b.Stop, e));
|
|
156
160
|
}
|
|
157
|
-
function
|
|
161
|
+
function Me(e, t, o) {
|
|
158
162
|
var c, d, s;
|
|
159
163
|
i(`Track subscribed: ${e.kind} from ${o.identity}`);
|
|
160
164
|
const r = e.mediaStreamTrack;
|
|
@@ -162,39 +166,39 @@ async function un(l, C, u) {
|
|
|
162
166
|
i(`No mediaStreamTrack available for ${e.kind}`);
|
|
163
167
|
return;
|
|
164
168
|
}
|
|
165
|
-
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" && (S =
|
|
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" && (S = Ye(
|
|
166
170
|
() => e.getRTCStatsReport(),
|
|
167
171
|
({ sttLatency: p, serviceLatency: T }) => {
|
|
168
|
-
var
|
|
169
|
-
const V =
|
|
172
|
+
var le, fe, pe;
|
|
173
|
+
const V = he.get(!0);
|
|
170
174
|
let F = 0;
|
|
171
175
|
if (p) {
|
|
172
|
-
const
|
|
173
|
-
F =
|
|
176
|
+
const ge = ((fe = (le = h == null ? void 0 : h.getReport()) == null ? void 0 : le.webRTCStats) == null ? void 0 : fe.avgRtt) ?? 0;
|
|
177
|
+
F = ge > 0 ? Math.round(ge * 1e3) : 0;
|
|
174
178
|
}
|
|
175
179
|
const D = V > 0 ? V + (p ?? 0) + F : void 0, w = D !== void 0 && T !== void 0 ? D - T : void 0;
|
|
176
|
-
(
|
|
180
|
+
(pe = n.onFirstAudioDetected) == null || pe.call(n, { latency: D, networkLatency: w });
|
|
177
181
|
}
|
|
178
|
-
)), 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")), h =
|
|
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")), h = Ze(
|
|
179
183
|
() => e.getRTCStatsReport(),
|
|
180
184
|
() => E,
|
|
181
|
-
|
|
185
|
+
en,
|
|
182
186
|
(p, T) => {
|
|
183
|
-
i(`Video state change: ${p}`), p === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")),
|
|
187
|
+
i(`Video state change: ${p}`), p === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")), Pe()) : p === b.Stop && oe(T);
|
|
184
188
|
}
|
|
185
189
|
), h.start());
|
|
186
190
|
}
|
|
187
|
-
function
|
|
188
|
-
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (
|
|
191
|
+
function ke(e, t, o) {
|
|
192
|
+
i(`Track unsubscribed: ${e.kind} from ${o.identity}`), e.kind === "audio" && (S == null || S.destroy(), S = null), e.kind === "video" && (oe(h == null ? void 0 : h.getReport()), h == null || h.stop(), h = null);
|
|
189
193
|
}
|
|
190
|
-
function
|
|
194
|
+
function re(e, t) {
|
|
191
195
|
var r;
|
|
192
|
-
const o =
|
|
196
|
+
const o = an[e];
|
|
193
197
|
o && ((r = n.onMessage) == null || r.call(n, o, { event: o, ...t }));
|
|
194
198
|
}
|
|
195
|
-
function
|
|
199
|
+
function G(e, t) {
|
|
196
200
|
var o, r, c, d;
|
|
197
|
-
if (e ===
|
|
201
|
+
if (e === l.ToolCallStarted) {
|
|
198
202
|
const s = t;
|
|
199
203
|
y.set(s.call_id, {
|
|
200
204
|
call: {
|
|
@@ -204,23 +208,23 @@ async function un(l, C, u) {
|
|
|
204
208
|
},
|
|
205
209
|
interruptible: s.interruptible === !0,
|
|
206
210
|
turnId: s.turn_id ?? x
|
|
207
|
-
}), N(), z(), M = m.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, m.ToolActive), (r = n.onToolEvent) == null || r.call(n,
|
|
211
|
+
}), N(), z(), M = m.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, m.ToolActive), (r = n.onToolEvent) == null || r.call(n, l.ToolCallStarted, s);
|
|
208
212
|
return;
|
|
209
213
|
}
|
|
210
|
-
if (e ===
|
|
214
|
+
if (e === l.ToolCallDone) {
|
|
211
215
|
const s = t;
|
|
212
|
-
|
|
216
|
+
ae(s.call_id), (c = n.onToolEvent) == null || c.call(n, l.ToolCallDone, s);
|
|
213
217
|
return;
|
|
214
218
|
}
|
|
215
|
-
if (e ===
|
|
219
|
+
if (e === l.ToolCallError) {
|
|
216
220
|
const s = t;
|
|
217
|
-
|
|
221
|
+
ae(s.call_id), (d = n.onToolEvent) == null || d.call(n, l.ToolCallError, s);
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
|
-
function
|
|
224
|
+
function ae(e) {
|
|
221
225
|
y.delete(e) && (N(), z());
|
|
222
226
|
}
|
|
223
|
-
function
|
|
227
|
+
function Ie(e) {
|
|
224
228
|
let t = !1;
|
|
225
229
|
for (const [o, r] of y)
|
|
226
230
|
r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (y.delete(o), t = !0));
|
|
@@ -235,12 +239,12 @@ async function un(l, C, u) {
|
|
|
235
239
|
var e;
|
|
236
240
|
(e = n.onRunningToolCallsChange) == null || e.call(
|
|
237
241
|
n,
|
|
238
|
-
y.size === 0 ?
|
|
242
|
+
y.size === 0 ? cn : [...y.values()].map(({ call: t }) => t)
|
|
239
243
|
);
|
|
240
244
|
}
|
|
241
|
-
function
|
|
245
|
+
function _e(e, t) {
|
|
242
246
|
var o, r, c;
|
|
243
|
-
if (e ===
|
|
247
|
+
if (e === l.StreamVideoCreated) {
|
|
244
248
|
M = m.Talking, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Talking), S == null || S.arm({
|
|
245
249
|
sttLatency: (r = t == null ? void 0 : t.stt) == null ? void 0 : r.latency,
|
|
246
250
|
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
@@ -258,61 +262,66 @@ async function un(l, C, u) {
|
|
|
258
262
|
u.debug && ((p = t == null ? void 0 : t.metadata) != null && p.sentiment) && (c.sentiment = {
|
|
259
263
|
id: t.metadata.sentiment.id,
|
|
260
264
|
name: t.metadata.sentiment.sentiment
|
|
261
|
-
}), (T = n.onMessage) == null || T.call(n, e, c),
|
|
265
|
+
}), (T = n.onMessage) == null || T.call(n, e, c), _e(e, t);
|
|
262
266
|
}
|
|
263
|
-
function
|
|
267
|
+
function $e(e, t) {
|
|
264
268
|
var o;
|
|
265
269
|
(o = n.onMessage) == null || o.call(n, J.Transcribe, { event: J.Transcribe, ...t }), queueMicrotask(() => {
|
|
266
270
|
var r;
|
|
267
271
|
(r = n.onAgentActivityStateChange) == null || r.call(n, m.Loading);
|
|
268
272
|
});
|
|
269
273
|
}
|
|
270
|
-
function
|
|
274
|
+
function De(e, t) {
|
|
271
275
|
var o;
|
|
272
276
|
x = (t == null ? void 0 : t.turn_id) ?? null, M = m.Loading, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Loading);
|
|
273
277
|
}
|
|
274
|
-
function
|
|
278
|
+
function Ke(e, t) {
|
|
275
279
|
var r;
|
|
276
280
|
const o = (t == null ? void 0 : t.turn_id) ?? null;
|
|
277
|
-
x !== null && o !== null && o < x || (
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
[
|
|
284
|
-
[
|
|
285
|
-
[
|
|
286
|
-
[
|
|
287
|
-
[
|
|
288
|
-
[
|
|
289
|
-
[
|
|
290
|
-
[
|
|
291
|
-
[
|
|
281
|
+
x !== null && o !== null && o < x || (Ie(o), M = m.Idle, (r = n.onAgentActivityStateChange) == null || r.call(n, m.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
|
|
292
301
|
};
|
|
293
|
-
function
|
|
302
|
+
function Ve(e, t, o, r) {
|
|
294
303
|
const c = new TextDecoder().decode(e);
|
|
295
304
|
try {
|
|
296
305
|
const d = JSON.parse(c), s = r || d.subject;
|
|
297
306
|
if (i("Data received:", { subject: s, data: d }), !s) return;
|
|
298
|
-
const p =
|
|
307
|
+
const p = xe[s];
|
|
299
308
|
p == null || p(s, d);
|
|
300
309
|
} catch (d) {
|
|
301
310
|
i("Failed to parse data channel message:", d);
|
|
302
311
|
}
|
|
303
312
|
}
|
|
304
|
-
function
|
|
313
|
+
function Fe(e) {
|
|
305
314
|
var t;
|
|
306
|
-
i("Media devices error:", e), (t = n.onError) == null || t.call(n,
|
|
315
|
+
i("Media devices error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
|
|
307
316
|
}
|
|
308
|
-
function
|
|
317
|
+
function Ue(e) {
|
|
309
318
|
var t;
|
|
310
|
-
i("Encryption error:", e), (t = n.onError) == null || t.call(n,
|
|
319
|
+
i("Encryption error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
|
|
311
320
|
}
|
|
312
|
-
function
|
|
321
|
+
function je(e, t, o) {
|
|
313
322
|
i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
|
|
314
323
|
}
|
|
315
|
-
function
|
|
324
|
+
function Oe(e, t, o) {
|
|
316
325
|
for (const [r, c] of o)
|
|
317
326
|
if (c.source === t && c.track) {
|
|
318
327
|
const d = c.track.mediaStreamTrack;
|
|
@@ -321,7 +330,7 @@ async function un(l, C, u) {
|
|
|
321
330
|
}
|
|
322
331
|
return null;
|
|
323
332
|
}
|
|
324
|
-
async function
|
|
333
|
+
async function se(e, t, o, r, c, d) {
|
|
325
334
|
var V, F, D;
|
|
326
335
|
if (!E || !a)
|
|
327
336
|
throw i(`Room is not connected, cannot publish ${r} stream`), new Error("Room is not connected");
|
|
@@ -332,7 +341,7 @@ async function un(l, C, u) {
|
|
|
332
341
|
const s = o(t);
|
|
333
342
|
if (s.length === 0)
|
|
334
343
|
throw new Error(`No ${r} track found in the provided MediaStream`);
|
|
335
|
-
const p = s[0], T =
|
|
344
|
+
const p = s[0], T = Oe(p, r, c());
|
|
336
345
|
if (T) {
|
|
337
346
|
i(`${r} track is already published, skipping`, {
|
|
338
347
|
trackId: p.id,
|
|
@@ -353,7 +362,7 @@ async function un(l, C, u) {
|
|
|
353
362
|
e.isPublishing = !1;
|
|
354
363
|
}
|
|
355
364
|
}
|
|
356
|
-
async function
|
|
365
|
+
async function ue(e, t) {
|
|
357
366
|
if (!(!e.publication || !e.publication.track))
|
|
358
367
|
try {
|
|
359
368
|
a && (await a.localParticipant.unpublishTrack(e.publication.track, !1), i(`${t} track unpublished`));
|
|
@@ -363,20 +372,20 @@ async function un(l, C, u) {
|
|
|
363
372
|
e.publication = null;
|
|
364
373
|
}
|
|
365
374
|
}
|
|
366
|
-
async function
|
|
367
|
-
return
|
|
375
|
+
async function Ne(e) {
|
|
376
|
+
return se(
|
|
368
377
|
P,
|
|
369
378
|
e,
|
|
370
379
|
(t) => t.getAudioTracks(),
|
|
371
|
-
|
|
380
|
+
ee.Source.Microphone,
|
|
372
381
|
() => a.localParticipant.audioTrackPublications,
|
|
373
|
-
|
|
382
|
+
H
|
|
374
383
|
);
|
|
375
384
|
}
|
|
376
|
-
async function
|
|
377
|
-
return
|
|
385
|
+
async function H() {
|
|
386
|
+
return ue(P, "Microphone");
|
|
378
387
|
}
|
|
379
|
-
async function
|
|
388
|
+
async function ze(e) {
|
|
380
389
|
if (!E || !a)
|
|
381
390
|
throw i("Cannot replace microphone track: room is not connected"), new Error("Room is not connected");
|
|
382
391
|
if (e.kind !== "audio")
|
|
@@ -392,26 +401,26 @@ async function un(l, C, u) {
|
|
|
392
401
|
P.isPublishing = !1;
|
|
393
402
|
}
|
|
394
403
|
}
|
|
395
|
-
async function
|
|
396
|
-
return
|
|
404
|
+
async function Be(e) {
|
|
405
|
+
return se(
|
|
397
406
|
Q,
|
|
398
407
|
e,
|
|
399
408
|
(t) => t.getVideoTracks(),
|
|
400
|
-
|
|
409
|
+
ee.Source.Camera,
|
|
401
410
|
() => a.localParticipant.videoTrackPublications,
|
|
402
|
-
|
|
411
|
+
X
|
|
403
412
|
);
|
|
404
413
|
}
|
|
405
|
-
async function
|
|
406
|
-
return
|
|
414
|
+
async function X() {
|
|
415
|
+
return ue(Q, "Camera");
|
|
407
416
|
}
|
|
408
|
-
function
|
|
417
|
+
function Je() {
|
|
409
418
|
L && (L.getTracks().forEach((e) => e.stop()), L = null);
|
|
410
419
|
}
|
|
411
|
-
async function
|
|
420
|
+
async function Z(e, t) {
|
|
412
421
|
var o, r;
|
|
413
422
|
if (!E || !a) {
|
|
414
|
-
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n,
|
|
423
|
+
i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, j(), {
|
|
415
424
|
sessionId: v
|
|
416
425
|
});
|
|
417
426
|
return;
|
|
@@ -419,19 +428,19 @@ async function un(l, C, u) {
|
|
|
419
428
|
try {
|
|
420
429
|
await a.localParticipant.sendText(t, { topic: e }), i("Message sent successfully:", t);
|
|
421
430
|
} catch (c) {
|
|
422
|
-
i("Failed to send message:", c), (r = n.onError) == null || r.call(n,
|
|
431
|
+
i("Failed to send message:", c), (r = n.onError) == null || r.call(n, j(), { sessionId: v });
|
|
423
432
|
}
|
|
424
433
|
}
|
|
425
|
-
async function
|
|
434
|
+
async function Y(e) {
|
|
426
435
|
var t, o;
|
|
427
|
-
R && (clearTimeout(R), R = null), S == null || S.destroy(), S = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, A.Disconnecting, e), await Promise.all([
|
|
436
|
+
R && (clearTimeout(R), R = null), S == null || S.destroy(), S = 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, y.size > 0 && (y.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, m.Idle), M = m.Idle;
|
|
428
437
|
}
|
|
429
438
|
return {
|
|
430
439
|
speak(e) {
|
|
431
440
|
const t = typeof e == "string" ? e : JSON.stringify(e);
|
|
432
|
-
return
|
|
441
|
+
return Z(me.Speak, t);
|
|
433
442
|
},
|
|
434
|
-
disconnect: () =>
|
|
443
|
+
disconnect: () => Y("user:disconnect"),
|
|
435
444
|
async reconnect() {
|
|
436
445
|
var e, t;
|
|
437
446
|
if ((a == null ? void 0 : a.state) === I.Connected) {
|
|
@@ -440,7 +449,7 @@ async function un(l, C, u) {
|
|
|
440
449
|
}
|
|
441
450
|
if (!a || !$ || !_)
|
|
442
451
|
throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
443
|
-
i("Reconnecting to LiveKit room, state:", a.state), K = !1, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
|
|
452
|
+
i("Reconnecting to LiveKit room, state:", a.state), K = !1, q = null, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
|
|
444
453
|
try {
|
|
445
454
|
if (await a.connect($, _), i("Room reconnected"), E = !0, a.remoteParticipants.size === 0) {
|
|
446
455
|
if (i("Waiting for agent to join..."), !await new Promise((r) => {
|
|
@@ -458,14 +467,14 @@ async function un(l, C, u) {
|
|
|
458
467
|
throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, A.Fail, "user:reconnect-failed"), o;
|
|
459
468
|
}
|
|
460
469
|
},
|
|
461
|
-
sendDataChannelMessage:
|
|
462
|
-
publishMicrophoneStream:
|
|
463
|
-
unpublishMicrophoneStream:
|
|
464
|
-
replaceMicrophoneTrack:
|
|
465
|
-
publishCameraStream:
|
|
466
|
-
unpublishCameraStream:
|
|
470
|
+
sendDataChannelMessage: Z,
|
|
471
|
+
publishMicrophoneStream: Ne,
|
|
472
|
+
unpublishMicrophoneStream: H,
|
|
473
|
+
replaceMicrophoneTrack: ze,
|
|
474
|
+
publishCameraStream: Be,
|
|
475
|
+
unpublishCameraStream: X,
|
|
467
476
|
interrupt(e) {
|
|
468
|
-
e !== "text" &&
|
|
477
|
+
e !== "text" && Z(me.Interrupt, "");
|
|
469
478
|
},
|
|
470
479
|
registerRpcMethod(e, t) {
|
|
471
480
|
a == null || a.registerRpcMethod(e, t);
|
|
@@ -475,12 +484,12 @@ async function un(l, C, u) {
|
|
|
475
484
|
},
|
|
476
485
|
sessionId: v,
|
|
477
486
|
streamId: v,
|
|
478
|
-
streamType:
|
|
479
|
-
interruptAvailable:
|
|
487
|
+
streamType: te,
|
|
488
|
+
interruptAvailable: ie,
|
|
480
489
|
isInterruptible: W
|
|
481
490
|
};
|
|
482
491
|
}
|
|
483
492
|
export {
|
|
484
|
-
|
|
485
|
-
|
|
493
|
+
ln as createLiveKitStreamingManager,
|
|
494
|
+
Se as handleInitError
|
|
486
495
|
};
|
|
@@ -6,7 +6,7 @@ export interface ChatEventQueue {
|
|
|
6
6
|
[sequence: number]: string;
|
|
7
7
|
answer?: string;
|
|
8
8
|
}
|
|
9
|
-
export declare function createMessageEventQueue(analytics: Analytics, items: AgentManagerItems, options: AgentManagerOptions, agentEntity: Agent, onStreamDone: () => void): {
|
|
9
|
+
export declare function createMessageEventQueue(analytics: Analytics, items: AgentManagerItems, options: AgentManagerOptions, agentEntity: Agent, onStreamDone: (reason?: string) => void): {
|
|
10
10
|
clearQueue: () => void;
|
|
11
11
|
onMessage: (event: ChatProgress | StreamEvents, data: any) => void;
|
|
12
12
|
};
|
|
@@ -42,8 +42,9 @@ interface ManagerCallbacks {
|
|
|
42
42
|
/**
|
|
43
43
|
* Optional callback will be triggered each time the RTC connection changes state
|
|
44
44
|
* @param state
|
|
45
|
+
* @param reason - a `StreamEndReason` when the server ended the stream, otherwise a diagnostic string
|
|
45
46
|
*/
|
|
46
|
-
onConnectionStateChange?(state: ConnectionState): void;
|
|
47
|
+
onConnectionStateChange?(state: ConnectionState, reason?: string): void;
|
|
47
48
|
/**
|
|
48
49
|
* Optional callback function that will be triggered each time video events happen
|
|
49
50
|
* @param state
|
|
@@ -250,6 +250,15 @@ export type ToolEventPayload = ToolCallStartedPayload | ToolCallDonePayload | To
|
|
|
250
250
|
export interface TurnEventPayload {
|
|
251
251
|
turn_id: number | null;
|
|
252
252
|
}
|
|
253
|
+
export declare enum StreamEndReason {
|
|
254
|
+
Ok = "ok",
|
|
255
|
+
UnknownError = "unknown_error",
|
|
256
|
+
NetworkIssue = "network_issue",
|
|
257
|
+
MessageLimit = "message_limit",
|
|
258
|
+
TimeLimit = "time_limit",
|
|
259
|
+
Inactivity = "inactivity",
|
|
260
|
+
EndedByAgent = "ended_by_agent"
|
|
261
|
+
}
|
|
253
262
|
export type ToolEventCallback = {
|
|
254
263
|
(event: StreamEvents.ToolCallStarted, data: ToolCallStartedPayload): void;
|
|
255
264
|
(event: StreamEvents.ToolCallDone, data: ToolCallDonePayload): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|