@d-id/client-sdk 1.1.20 → 1.1.21-staging.95

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,188 @@
1
+ import { c as H, a as X, S as Y, d as Z, T as l, C as u, b as p, A as M, e as F, f as k, g as b } from "./index-DrtrGN5e.js";
2
+ function ee(c, f, d, i) {
3
+ const m = H(c, `${f}/v2/agents/${d}`, i);
4
+ return {
5
+ async createStream(a) {
6
+ return m.post("/sessions", a);
7
+ }
8
+ };
9
+ }
10
+ async function ne() {
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 te = {
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 P(c, f, d, i) {
30
+ var m, a;
31
+ throw f("Failed to connect to LiveKit room:", c), i(), (m = d.onConnectionStateChange) == null || m.call(d, u.Fail), (a = d.onError) == null || a.call(d, c, { sessionId: "" }), c;
32
+ }
33
+ async function oe(c, f, d) {
34
+ var R, D;
35
+ const i = X(d.debug || !1, "LiveKitStreamingManager"), { Room: m, RoomEvent: a, ConnectionState: v } = await ne(), { callbacks: e, auth: _, baseURL: I, analytics: N } = d;
36
+ let g = null, y = !1;
37
+ const K = Y.Fluent;
38
+ let w = !0, h = null;
39
+ g = new m({
40
+ adaptiveStream: !1,
41
+ // Must be false to use mediaStreamTrack directly
42
+ dynacast: !0
43
+ });
44
+ const U = ee(_, I || Z, c, e.onError);
45
+ let S, E, T;
46
+ try {
47
+ const n = await U.createStream({
48
+ transport_provider: l.Livekit,
49
+ chat_persist: f.chat_persist ?? !0
50
+ }), { id: t, session_token: o, session_url: r } = n;
51
+ (R = e.onStreamCreated) == null || R.call(e, { session_id: t, stream_id: t, agent_id: c }), S = t, E = o, T = r, await g.prepareConnection(T, E);
52
+ } catch (n) {
53
+ P(n, i, e, () => {
54
+ w = !1;
55
+ });
56
+ }
57
+ if (!T || !E || !S)
58
+ return Promise.reject(new Error("Failed to initialize LiveKit stream"));
59
+ g.on(a.ConnectionStateChanged, x).on(a.ConnectionQualityChanged, j).on(a.ActiveSpeakersChanged, O).on(a.ParticipantConnected, J).on(a.TrackSubscribed, Q).on(a.TrackUnsubscribed, V).on(a.DataReceived, q).on(a.MediaDevicesError, z).on(a.EncryptionError, W).on(a.TrackSubscriptionFailed, B), (D = e.onConnectionStateChange) == null || D.call(e, u.New);
60
+ try {
61
+ await g.connect(T, E), i("LiveKit room joined successfully"), w = !1;
62
+ } catch (n) {
63
+ P(n, i, e, () => {
64
+ w = !1;
65
+ });
66
+ }
67
+ N.enrich({
68
+ "stream-type": K
69
+ });
70
+ function x(n) {
71
+ var t, o, r, s, C;
72
+ switch (i("Connection state changed:", n), n) {
73
+ case v.Connecting:
74
+ (t = e.onConnectionStateChange) == null || t.call(e, u.Connecting);
75
+ break;
76
+ case v.Connected:
77
+ i("LiveKit room connected successfully"), y = !0, w ? queueMicrotask(() => {
78
+ var $;
79
+ ($ = e.onConnectionStateChange) == null || $.call(e, u.Connected);
80
+ }) : (o = e.onConnectionStateChange) == null || o.call(e, u.Connected);
81
+ break;
82
+ case v.Disconnected:
83
+ i("LiveKit room disconnected"), y = !1, (r = e.onConnectionStateChange) == null || r.call(e, u.Disconnected);
84
+ break;
85
+ case v.Reconnecting:
86
+ i("LiveKit room reconnecting..."), (s = e.onConnectionStateChange) == null || s.call(e, u.Connecting);
87
+ break;
88
+ case v.SignalReconnecting:
89
+ i("LiveKit room signal reconnecting..."), (C = e.onConnectionStateChange) == null || C.call(e, u.Connecting);
90
+ break;
91
+ }
92
+ }
93
+ function j(n, t) {
94
+ var o;
95
+ i("Connection quality:", n), t != null && t.isLocal && ((o = e.onConnectivityStateChange) == null || o.call(e, te[n]));
96
+ }
97
+ function O(n) {
98
+ var o, r;
99
+ i("Active speakers changed:", n), n[0] ? (o = e.onAgentActivityStateChange) == null || o.call(e, M.Talking) : (r = e.onAgentActivityStateChange) == null || r.call(e, M.Idle);
100
+ }
101
+ function J(n) {
102
+ i("Participant connected:", n.identity);
103
+ }
104
+ function Q(n, t, o) {
105
+ var s, C;
106
+ i(`Track subscribed: ${n.kind} from ${o.identity}`);
107
+ const r = n.mediaStreamTrack;
108
+ if (!r) {
109
+ i(`No mediaStreamTrack available for ${n.kind}`);
110
+ return;
111
+ }
112
+ h ? (h.addTrack(r), i(`Added ${n.kind} track to shared MediaStream`)) : (h = new MediaStream([r]), i(`Created shared MediaStream with ${n.kind} track`)), n.kind === "video" && ((s = e.onSrcObjectReady) == null || s.call(e, h), (C = e.onVideoStateChange) == null || C.call(e, F.Start));
113
+ }
114
+ function V(n, t, o) {
115
+ var r;
116
+ i(`Track unsubscribed: ${n.kind} from ${o.identity}`), n.kind === "video" && ((r = e.onVideoStateChange) == null || r.call(e, F.Stop));
117
+ }
118
+ function q(n, t) {
119
+ var r;
120
+ const o = new TextDecoder().decode(n);
121
+ i("Data received:", o);
122
+ try {
123
+ const s = JSON.parse(o);
124
+ if (s.subject === k.ChatAnswer) {
125
+ const C = b.Answer;
126
+ (r = e.onMessage) == null || r.call(e, C, {
127
+ event: C,
128
+ ...s
129
+ });
130
+ }
131
+ } catch (s) {
132
+ i("Failed to parse data channel message:", s);
133
+ }
134
+ }
135
+ function z(n) {
136
+ var t;
137
+ i("Media devices error:", n), (t = e.onError) == null || t.call(e, new Error(A), { sessionId: S });
138
+ }
139
+ function W(n) {
140
+ var t;
141
+ i("Encryption error:", n), (t = e.onError) == null || t.call(e, new Error(A), { sessionId: S });
142
+ }
143
+ function B(n, t, o) {
144
+ i("Track subscription failed:", { trackSid: n, participant: t, reason: o });
145
+ }
146
+ function G() {
147
+ h && (h.getTracks().forEach((n) => n.stop()), h = null);
148
+ }
149
+ async function L(n, t = "lk.chat") {
150
+ var o, r;
151
+ if (!y || !g) {
152
+ i("Room is not connected for sending messages"), (o = e.onError) == null || o.call(e, new Error(A), {
153
+ sessionId: S
154
+ });
155
+ return;
156
+ }
157
+ try {
158
+ await g.localParticipant.sendText(n, { topic: t }), i("Message sent successfully:", n);
159
+ } catch (s) {
160
+ i("Failed to send message:", s), (r = e.onError) == null || r.call(e, new Error(A), { sessionId: S });
161
+ }
162
+ }
163
+ return {
164
+ speak(n) {
165
+ const t = typeof n == "string" ? n : JSON.stringify(n);
166
+ return L(
167
+ t,
168
+ "did.speak"
169
+ /* Speak */
170
+ );
171
+ },
172
+ async disconnect() {
173
+ var n, t;
174
+ 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, M.Idle);
175
+ },
176
+ sendDataChannelMessage: L,
177
+ sendTextMessage: L,
178
+ sessionId: S,
179
+ streamId: S,
180
+ streamType: K,
181
+ interruptAvailable: !0,
182
+ triggersAvailable: !1
183
+ };
184
+ }
185
+ export {
186
+ oe as createLiveKitStreamingManager,
187
+ P as handleInitError
188
+ };
@@ -1,5 +1,5 @@
1
- import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '../../types';
1
+ import { Auth, CreateSessionV2Options, CreateSessionV2Response } from '../../types';
2
2
 
3
3
  export declare function createStreamApiV2(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): {
4
- createStream(options: CreateStreamV2Options): Promise<CreateStreamV2Response>;
4
+ createStream(options: CreateSessionV2Options): Promise<CreateSessionV2Response>;
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import { StreamingManager } from '../streaming-manager';
2
- import { Agent, AgentManagerOptions, AgentsAPI, Chat, ChatProgressCallback, CreateStreamOptions, CreateStreamV2Options } from '../../types';
2
+ import { Agent, AgentManagerOptions, AgentsAPI, Chat, ChatProgressCallback, CreateSessionV2Options, CreateStreamOptions } from '../../types';
3
3
  import { Analytics } from '../analytics/mixpanel';
4
4
 
5
5
  type ConnectToManagerOptions = AgentManagerOptions & {
@@ -12,6 +12,6 @@ type ConnectToManagerOptions = AgentManagerOptions & {
12
12
  };
13
13
  export declare function initializeStreamAndChat(agent: Agent, options: ConnectToManagerOptions, agentsApi: AgentsAPI, analytics: Analytics, chat?: Chat): Promise<{
14
14
  chat?: Chat;
15
- streamingManager?: StreamingManager<CreateStreamOptions | CreateStreamV2Options>;
15
+ streamingManager?: StreamingManager<CreateStreamOptions | CreateSessionV2Options>;
16
16
  }>;
17
17
  export {};
@@ -1,11 +1,11 @@
1
- import { CreateStreamOptions, CreateStreamV2Options, PayloadType, StreamType } from '../../types';
1
+ import { CreateSessionV2Options, CreateStreamOptions, PayloadType, StreamType } from '../../types';
2
2
 
3
3
  export declare const createStreamingLogger: (debug: boolean, prefix: string) => (message: string, extra?: any) => false | void;
4
4
  /**
5
5
  * Shared type for all streaming managers (LiveKit, WebRTC, etc.)
6
6
  * This type represents the return value of any streaming manager implementation
7
7
  */
8
- export type StreamingManager<T extends CreateStreamOptions | CreateStreamV2Options> = {
8
+ export type StreamingManager<T extends CreateStreamOptions | CreateSessionV2Options> = {
9
9
  /**
10
10
  * Method to send request to server to get clip or talk depending on payload
11
11
  * @param payload The payload to send to the streaming service
@@ -1,4 +1,4 @@
1
- import { Agent, CreateStreamOptions, CreateStreamV2Options, StreamingManagerOptions } from '../../types';
1
+ import { Agent, CreateSessionV2Options, CreateStreamOptions, StreamingManagerOptions } from '../../types';
2
2
  import { StreamingManager } from './common';
3
3
 
4
4
  export declare enum StreamApiVersion {
@@ -9,5 +9,5 @@ export type ExtendedStreamOptions = ({
9
9
  version: StreamApiVersion.V1;
10
10
  } & CreateStreamOptions) | ({
11
11
  version: StreamApiVersion.V2;
12
- } & CreateStreamV2Options);
13
- export declare function createStreamingManager(agent: Agent, streamOptions: ExtendedStreamOptions, options: StreamingManagerOptions): Promise<StreamingManager<CreateStreamOptions | CreateStreamV2Options>>;
12
+ } & CreateSessionV2Options);
13
+ export declare function createStreamingManager(agent: Agent, streamOptions: ExtendedStreamOptions, options: StreamingManagerOptions): Promise<StreamingManager<CreateStreamOptions | CreateSessionV2Options>>;
@@ -1,6 +1,6 @@
1
- import { CreateStreamOptions, CreateStreamV2Options, StreamingManagerOptions } from '../../types';
1
+ import { CreateSessionV2Options, CreateStreamOptions, StreamingManagerOptions } from '../../types';
2
2
  import { StreamingManager } from './common';
3
3
 
4
4
  export declare function handleInitError(error: unknown, log: (message?: any, ...optionalParams: any[]) => void, callbacks: StreamingManagerOptions['callbacks'], markInitialConnectionDone: () => void): void;
5
- export declare function createLiveKitStreamingManager<T extends CreateStreamV2Options>(agentId: string, agent: T, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
5
+ export declare function createLiveKitStreamingManager<T extends CreateSessionV2Options>(agentId: string, sessionOptions: CreateSessionV2Options, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
6
6
  export type LiveKitStreamingManager<T extends CreateStreamOptions> = StreamingManager<T>;
@@ -1,13 +1,12 @@
1
1
  export declare enum TransportProvider {
2
2
  Livekit = "livekit"
3
3
  }
4
- export interface CreateStreamV2Options {
4
+ export interface CreateSessionV2Options {
5
5
  transport_provider: TransportProvider.Livekit;
6
- chat_id?: string;
6
+ chat_persist?: boolean;
7
7
  }
8
- export interface CreateStreamV2Response {
9
- agent_id: 'string';
10
- session_id: 'string';
11
- session_url: 'string';
12
- session_token: 'string';
8
+ export interface CreateSessionV2Response {
9
+ id: string;
10
+ session_url: string;
11
+ session_token: string;
13
12
  }
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.20",
4
+ "version": "1.1.21-staging.95",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -1,195 +0,0 @@
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-DcoRNuxp.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
- };