@d-id/client-sdk 3.0.0-staging.414 → 3.0.0-staging.415

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