@d-id/client-sdk 1.1.17-staging.76 → 1.1.17-staging.77

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.
@@ -0,0 +1,195 @@
1
+ import { c as H, a as X, S as Y, d as Z, T as k, C as u, b as p, A as K, e as F, f as b, g as ee } from "./index-DKb-cXkg.js";
2
+ function ne(c, f, s, i) {
3
+ const h = H(c, `${f}/v2/agents/${s}`, i);
4
+ return {
5
+ async createStream(a) {
6
+ return h.post("/streams", a);
7
+ }
8
+ };
9
+ }
10
+ async function te() {
11
+ try {
12
+ return await import("./livekit-client.esm-C1GRQdZY.js");
13
+ } catch {
14
+ throw new Error(
15
+ "LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
16
+ );
17
+ }
18
+ }
19
+ const ie = {
20
+ excellent: p.Strong,
21
+ good: p.Strong,
22
+ poor: p.Weak,
23
+ lost: p.Unknown,
24
+ unknown: p.Unknown
25
+ }, A = JSON.stringify({
26
+ kind: "InternalServerError",
27
+ description: "Stream Error"
28
+ });
29
+ function _(c, f, s, i) {
30
+ var h, a;
31
+ throw f("Failed to connect to LiveKit room:", c), i(), (h = s.onConnectionStateChange) == null || h.call(s, u.Fail), (a = s.onError) == null || a.call(s, c, { streamId: "" }), c;
32
+ }
33
+ async function se(c, f, s) {
34
+ var D, P;
35
+ const i = X(s.debug || !1, "LiveKitStreamingManager"), {
36
+ Room: h,
37
+ RoomEvent: a,
38
+ ConnectionState: v,
39
+ RemoteParticipant: oe,
40
+ RemoteTrack: re
41
+ } = await te(), { callbacks: e, auth: I, baseURL: N, analytics: U } = s;
42
+ let g = null, y = !1;
43
+ const R = Y.Fluent;
44
+ let w = !0, C = null;
45
+ g = new h({
46
+ adaptiveStream: !1,
47
+ // Must be false to use mediaStreamTrack directly
48
+ dynacast: !0
49
+ });
50
+ const x = ne(I, N || Z, c, e.onError);
51
+ let m, L, E, T;
52
+ try {
53
+ const n = await x.createStream({
54
+ transport_provider: k.Livekit,
55
+ chat_id: f.chat_id
56
+ }), { session_id: t, session_token: o, session_url: r } = n;
57
+ (D = e.onStreamCreated) == null || D.call(e, { stream_id: t, session_id: t, agent_id: c }), m = t, L = t, E = o, T = r, await g.prepareConnection(T, E);
58
+ } catch (n) {
59
+ _(n, i, e, () => {
60
+ w = !1;
61
+ });
62
+ }
63
+ if (!T || !E || !m || !L)
64
+ return Promise.reject(new Error("Failed to initialize LiveKit stream"));
65
+ g.on(a.ConnectionStateChanged, j).on(a.ConnectionQualityChanged, O).on(a.ActiveSpeakersChanged, J).on(a.ParticipantConnected, Q).on(a.TrackSubscribed, V).on(a.TrackUnsubscribed, q).on(a.DataReceived, z).on(a.MediaDevicesError, W).on(a.EncryptionError, l).on(a.TrackSubscriptionFailed, B), (P = e.onConnectionStateChange) == null || P.call(e, u.New);
66
+ try {
67
+ await g.connect(T, E), i("LiveKit room joined successfully"), w = !1;
68
+ } catch (n) {
69
+ _(n, i, e, () => {
70
+ w = !1;
71
+ });
72
+ }
73
+ U.enrich({
74
+ "stream-type": R
75
+ });
76
+ function j(n) {
77
+ var t, o, r, d, S;
78
+ switch (i("Connection state changed:", n), n) {
79
+ case v.Connecting:
80
+ (t = e.onConnectionStateChange) == null || t.call(e, u.Connecting);
81
+ break;
82
+ case v.Connected:
83
+ i("LiveKit room connected successfully"), y = !0, w ? queueMicrotask(() => {
84
+ var $;
85
+ ($ = e.onConnectionStateChange) == null || $.call(e, u.Connected);
86
+ }) : (o = e.onConnectionStateChange) == null || o.call(e, u.Connected);
87
+ break;
88
+ case v.Disconnected:
89
+ i("LiveKit room disconnected"), y = !1, (r = e.onConnectionStateChange) == null || r.call(e, u.Disconnected);
90
+ break;
91
+ case v.Reconnecting:
92
+ i("LiveKit room reconnecting..."), (d = e.onConnectionStateChange) == null || d.call(e, u.Connecting);
93
+ break;
94
+ case v.SignalReconnecting:
95
+ i("LiveKit room signal reconnecting..."), (S = e.onConnectionStateChange) == null || S.call(e, u.Connecting);
96
+ break;
97
+ }
98
+ }
99
+ function O(n, t) {
100
+ var o;
101
+ i("Connection quality:", n), t != null && t.isLocal && ((o = e.onConnectivityStateChange) == null || o.call(e, ie[n]));
102
+ }
103
+ function J(n) {
104
+ var o, r;
105
+ i("Active speakers changed:", n), n[0] ? (o = e.onAgentActivityStateChange) == null || o.call(e, K.Talking) : (r = e.onAgentActivityStateChange) == null || r.call(e, K.Idle);
106
+ }
107
+ function Q(n) {
108
+ i("Participant connected:", n.identity);
109
+ }
110
+ function V(n, t, o) {
111
+ var d, S;
112
+ i(`Track subscribed: ${n.kind} from ${o.identity}`);
113
+ const r = n.mediaStreamTrack;
114
+ if (!r) {
115
+ i(`No mediaStreamTrack available for ${n.kind}`);
116
+ return;
117
+ }
118
+ C ? (C.addTrack(r), i(`Added ${n.kind} track to shared MediaStream`)) : (C = new MediaStream([r]), i(`Created shared MediaStream with ${n.kind} track`)), n.kind === "video" && ((d = e.onSrcObjectReady) == null || d.call(e, C), (S = e.onVideoStateChange) == null || S.call(e, F.Start));
119
+ }
120
+ function q(n, t, o) {
121
+ var r;
122
+ i(`Track unsubscribed: ${n.kind} from ${o.identity}`), n.kind === "video" && ((r = e.onVideoStateChange) == null || r.call(e, F.Stop));
123
+ }
124
+ function z(n, t) {
125
+ var r;
126
+ const o = new TextDecoder().decode(n);
127
+ i("Data received:", o);
128
+ try {
129
+ const d = JSON.parse(o);
130
+ if (d.subject === b.ChatAnswer) {
131
+ const S = ee.Answer;
132
+ (r = e.onMessage) == null || r.call(e, S, {
133
+ event: S,
134
+ ...d
135
+ });
136
+ }
137
+ } catch (d) {
138
+ i("Failed to parse data channel message:", d);
139
+ }
140
+ }
141
+ function W(n) {
142
+ var t;
143
+ i("Media devices error:", n), (t = e.onError) == null || t.call(e, new Error(A), { streamId: m });
144
+ }
145
+ function l(n) {
146
+ var t;
147
+ i("Encryption error:", n), (t = e.onError) == null || t.call(e, new Error(A), { streamId: m });
148
+ }
149
+ function B(n, t, o) {
150
+ i("Track subscription failed:", { trackSid: n, participant: t, reason: o });
151
+ }
152
+ function G() {
153
+ C && (C.getTracks().forEach((n) => n.stop()), C = null);
154
+ }
155
+ async function M(n) {
156
+ var t, o;
157
+ if (!y || !g) {
158
+ i("Room is not connected for sending messages"), (t = e.onError) == null || t.call(e, new Error(A), {
159
+ streamId: m
160
+ });
161
+ return;
162
+ }
163
+ try {
164
+ await g.localParticipant.sendText(n, {
165
+ topic: "lk.chat"
166
+ }), i("Message sent successfully:", n);
167
+ } catch (r) {
168
+ i("Failed to send message:", r), (o = e.onError) == null || o.call(e, new Error(A), { streamId: m });
169
+ }
170
+ }
171
+ return {
172
+ speak(n) {
173
+ const t = JSON.stringify({
174
+ type: "speak",
175
+ payload: n
176
+ });
177
+ return M(t);
178
+ },
179
+ async disconnect() {
180
+ var n, t;
181
+ g && (await g.disconnect(), g = null), G(), y = !1, (n = e.onConnectionStateChange) == null || n.call(e, u.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, K.Idle);
182
+ },
183
+ sendDataChannelMessage: M,
184
+ sendTextMessage: M,
185
+ sessionId: L,
186
+ streamId: m,
187
+ streamType: R,
188
+ interruptAvailable: !0,
189
+ triggersAvailable: !1
190
+ };
191
+ }
192
+ export {
193
+ se as createLiveKitStreamingManager,
194
+ _ as handleInitError
195
+ };
@@ -1,10 +1,12 @@
1
1
  import { StreamingManager } from '../streaming-manager';
2
- import { Agent, AgentManagerOptions, AgentsAPI, Chat, CreateStreamOptions, CreateStreamV2Options } from '../../types';
2
+ import { Agent, AgentManagerOptions, AgentsAPI, Chat, ChatProgressCallback, CreateStreamOptions, CreateStreamV2Options } from '../../types';
3
3
  import { Analytics } from '../analytics/mixpanel';
4
4
 
5
5
  type ConnectToManagerOptions = AgentManagerOptions & {
6
6
  callbacks: AgentManagerOptions['callbacks'] & {
7
7
  onVideoIdChange?: (videoId: string | null) => void;
8
+ /** Internal callback for livekit-manager data channel events */
9
+ onMessage?: ChatProgressCallback;
8
10
  };
9
11
  chatId?: string;
10
12
  };
@@ -1,6 +1,7 @@
1
1
  import { Analytics } from '../../services/analytics/mixpanel';
2
2
  import { VideoRTCStatsReport } from '../../services/streaming-manager/stats/report';
3
3
  import { Auth } from '../auth';
4
+ import { ChatProgressCallback } from '../entities/agents/manager';
4
5
  import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
5
6
  import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
6
7
 
@@ -46,7 +47,7 @@ export declare enum StreamType {
46
47
  Fluent = "fluent"
47
48
  }
48
49
  export interface ManagerCallbacks {
49
- onMessage?: (event: string, data: string) => void;
50
+ onMessage?: ChatProgressCallback;
50
51
  onConnectionStateChange?: (state: ConnectionState) => void;
51
52
  onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
52
53
  onSrcObjectReady?: (value: MediaStream) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "1.1.17-staging.76",
4
+ "version": "1.1.17-staging.77",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -1,198 +0,0 @@
1
- import { c as b, a as k, S as ee, d as ne, T as te, C as h, b as v, A as E, e as P, f as _ } from "./index-BhpiSVbj.js";
2
- function oe(c, C, r, o) {
3
- const S = b(c, `${C}/v2/agents/${r}`, o);
4
- return {
5
- async createStream(s) {
6
- return S.post("/streams", s);
7
- }
8
- };
9
- }
10
- async function ie() {
11
- try {
12
- return await import("./livekit-client.esm-C1GRQdZY.js");
13
- } catch {
14
- throw new Error(
15
- "LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
16
- );
17
- }
18
- }
19
- function re(c, C) {
20
- const r = c.attach();
21
- return C.push(r), r.style.position = "absolute", r.style.width = "1px", r.style.height = "1px", r.style.opacity = "0.01", r.style.pointerEvents = "none", r.muted = !0, r;
22
- }
23
- const ae = {
24
- excellent: v.Strong,
25
- good: v.Strong,
26
- poor: v.Weak,
27
- lost: v.Unknown,
28
- unknown: v.Unknown
29
- }, K = JSON.stringify({
30
- kind: "InternalServerError",
31
- description: "Stream Error"
32
- });
33
- function x(c, C, r, o) {
34
- var S, s;
35
- throw C("Failed to connect to LiveKit room:", c), o(), (S = r.onConnectionStateChange) == null || S.call(r, h.Fail), (s = r.onError) == null || s.call(r, c, { streamId: "" }), c;
36
- }
37
- async function ge(c, C, r) {
38
- var j, F;
39
- const o = k(r.debug || !1, "LiveKitStreamingManager"), {
40
- Room: S,
41
- RoomEvent: s,
42
- ConnectionState: f,
43
- RemoteParticipant: de,
44
- RemoteTrack: se
45
- } = await ie(), { callbacks: e, auth: $, baseURL: N, analytics: U } = r;
46
- let g = null, w = !1, A = null;
47
- const M = ee.Fluent;
48
- let T = !0;
49
- const L = [];
50
- g = new S({
51
- adaptiveStream: !0,
52
- dynacast: !0
53
- });
54
- const V = oe($, N || ne, c, e.onError);
55
- let p, R, I, l;
56
- try {
57
- const n = await V.createStream({
58
- transport_provider: te.Livekit,
59
- chat_id: C.chat_id
60
- }), { session_id: t, session_token: i, session_url: a } = n;
61
- (j = e.onStreamCreated) == null || j.call(e, { stream_id: t, session_id: t, agent_id: c }), p = t, R = t, I = i, l = a, await g.prepareConnection(l, I);
62
- } catch (n) {
63
- x(n, o, e, () => {
64
- T = !1;
65
- });
66
- }
67
- if (!l || !I || !p || !R)
68
- return Promise.reject(new Error("Failed to initialize LiveKit stream"));
69
- g.on(s.ConnectionStateChanged, J).on(s.ConnectionQualityChanged, Q).on(s.ActiveSpeakersChanged, q).on(s.ParticipantConnected, H).on(s.TrackSubscribed, z).on(s.TrackUnsubscribed, W).on(s.DataReceived, B).on(s.MediaDevicesError, G).on(s.EncryptionError, X).on(s.TrackSubscriptionFailed, Y), (F = e.onConnectionStateChange) == null || F.call(e, h.New);
70
- try {
71
- await g.connect(l, I), o("LiveKit room joined successfully"), T = !1;
72
- } catch (n) {
73
- x(n, o, e, () => {
74
- T = !1;
75
- });
76
- }
77
- U.enrich({
78
- "stream-type": M
79
- });
80
- function J(n) {
81
- var t, i, a, m, d;
82
- switch (o("Connection state changed:", n), n) {
83
- case f.Connecting:
84
- (t = e.onConnectionStateChange) == null || t.call(e, h.Connecting);
85
- break;
86
- case f.Connected:
87
- o("LiveKit room connected successfully"), w = !0, T ? queueMicrotask(() => {
88
- var u;
89
- (u = e.onConnectionStateChange) == null || u.call(e, h.Connected);
90
- }) : (i = e.onConnectionStateChange) == null || i.call(e, h.Connected);
91
- break;
92
- case f.Disconnected:
93
- o("LiveKit room disconnected"), w = !1, (a = e.onConnectionStateChange) == null || a.call(e, h.Disconnected);
94
- break;
95
- case f.Reconnecting:
96
- o("LiveKit room reconnecting..."), (m = e.onConnectionStateChange) == null || m.call(e, h.Connecting);
97
- break;
98
- case f.SignalReconnecting:
99
- o("LiveKit room signal reconnecting..."), (d = e.onConnectionStateChange) == null || d.call(e, h.Connecting);
100
- break;
101
- }
102
- }
103
- function Q(n, t) {
104
- var i;
105
- o("Connection quality:", n), t != null && t.isLocal && ((i = e.onConnectivityStateChange) == null || i.call(e, ae[n]));
106
- }
107
- function q(n) {
108
- var i, a;
109
- o("Active speakers changed:", n), n[0] ? (i = e.onAgentActivityStateChange) == null || i.call(e, E.Talking) : (a = e.onAgentActivityStateChange) == null || a.call(e, E.Idle);
110
- }
111
- function H(n) {
112
- o("Participant connected:", n.identity);
113
- }
114
- function z(n, t, i) {
115
- var a, m;
116
- if (o(`Track subscribed: ${n.kind} from ${i.identity}`), n.kind === "video") {
117
- const d = re(n, L);
118
- document.body.appendChild(d), d.play().then(() => {
119
- o("Hidden video element playing");
120
- }).catch((u) => o("Error playing hidden element:", u)), o(`Video element created, srcObject: ${d.srcObject}`), d.srcObject && ((a = e.onSrcObjectReady) == null || a.call(e, d.srcObject), (m = e.onVideoStateChange) == null || m.call(e, P.Start));
121
- }
122
- if (n.kind === "audio") {
123
- const d = n.attach();
124
- L.push(d), d.style.display = "none", document.body.appendChild(d), d.play().catch((u) => o("Error playing audio element:", u));
125
- }
126
- }
127
- function W(n, t, i) {
128
- var a;
129
- o(`Track unsubscribed: ${n.kind} from ${i.identity}`), n.kind === "video" && ((a = e.onVideoStateChange) == null || a.call(e, P.Stop));
130
- }
131
- function B(n, t) {
132
- var a, m, d, u, O;
133
- const i = new TextDecoder().decode(n);
134
- o("Data received:", i);
135
- try {
136
- const y = JSON.parse(i);
137
- y.subject === _.StreamStarted && ((a = y.metadata) != null && a.videoId) ? (A = y.metadata.videoId, (m = e.onVideoIdChange) == null || m.call(e, A), (d = e.onAgentActivityStateChange) == null || d.call(e, E.Talking)) : y.subject === _.StreamDone && (A = null, (u = e.onVideoIdChange) == null || u.call(e, A), (O = e.onAgentActivityStateChange) == null || O.call(e, E.Idle));
138
- } catch (y) {
139
- o("Failed to parse data channel message:", y);
140
- }
141
- }
142
- function G(n) {
143
- var t;
144
- o("Media devices error:", n), (t = e.onError) == null || t.call(e, new Error(K), { streamId: p });
145
- }
146
- function X(n) {
147
- var t;
148
- o("Encryption error:", n), (t = e.onError) == null || t.call(e, new Error(K), { streamId: p });
149
- }
150
- function Y(n, t, i) {
151
- o("Track subscription failed:", { trackSid: n, participant: t, reason: i });
152
- }
153
- function Z() {
154
- L.forEach((n) => {
155
- n.parentNode && n.parentNode.removeChild(n);
156
- }), L.length = 0;
157
- }
158
- async function D(n) {
159
- var t, i;
160
- if (!w || !g) {
161
- o("Room is not connected for sending messages"), (t = e.onError) == null || t.call(e, new Error(K), {
162
- streamId: p
163
- });
164
- return;
165
- }
166
- try {
167
- await g.localParticipant.sendText(n, {
168
- topic: "lk.chat"
169
- }), o("Message sent successfully:", n);
170
- } catch (a) {
171
- o("Failed to send message:", a), (i = e.onError) == null || i.call(e, new Error(K), { streamId: p });
172
- }
173
- }
174
- return {
175
- speak(n) {
176
- const t = JSON.stringify({
177
- type: "speak",
178
- payload: n
179
- });
180
- return D(t);
181
- },
182
- async disconnect() {
183
- var n, t;
184
- g && (await g.disconnect(), g = null), Z(), w = !1, (n = e.onConnectionStateChange) == null || n.call(e, h.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, E.Idle);
185
- },
186
- sendDataChannelMessage: D,
187
- sendTextMessage: D,
188
- sessionId: R,
189
- streamId: p,
190
- streamType: M,
191
- interruptAvailable: !0,
192
- triggersAvailable: !1
193
- };
194
- }
195
- export {
196
- ge as createLiveKitStreamingManager,
197
- x as handleInitError
198
- };