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