@d-id/client-sdk 1.1.11-staging.40 → 1.1.11-staging.42

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,122 @@
1
+ import { c as x, a as N, S as O, C as g, b as U, d as P, e as V, A as w, f as q, T as J } from "./index-n99Xwccj.js";
2
+ function Q(u, T, h, i) {
3
+ const p = x(u, `${T}/v2/agents/${h}`, i);
4
+ return {
5
+ async createStream(d) {
6
+ return p.post("/streams", d);
7
+ }
8
+ };
9
+ }
10
+ async function W() {
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
+ async function H(u, T, h) {
20
+ var E, K, I;
21
+ const i = N(h.debug || !1, "LiveKitStreamingManager"), {
22
+ Room: p,
23
+ RoomEvent: d,
24
+ ConnectionState: C,
25
+ RemoteParticipant: z,
26
+ RemoteTrack: B
27
+ } = await W(), { callbacks: e, auth: j, baseURL: F, analytics: M } = h;
28
+ let a = null, v = !1, y = null, c = null;
29
+ const L = O.Fluent;
30
+ a = new p({
31
+ adaptiveStream: !0,
32
+ dynacast: !0
33
+ }), a.on(d.ConnectionStateChanged, (n) => {
34
+ var t, o, r, s, S;
35
+ switch (i("Connection state changed:", n), n) {
36
+ case C.Connecting:
37
+ (t = e.onConnectionStateChange) == null || t.call(e, g.Connecting);
38
+ break;
39
+ case C.Connected:
40
+ i("LiveKit room connected successfully"), v = !0, (o = e.onConnectionStateChange) == null || o.call(e, g.Connected);
41
+ break;
42
+ case C.Disconnected:
43
+ i("LiveKit room disconnected"), v = !1, (r = e.onConnectionStateChange) == null || r.call(e, g.Disconnected);
44
+ break;
45
+ case C.Reconnecting:
46
+ i("LiveKit room reconnecting..."), (s = e.onConnectionStateChange) == null || s.call(e, g.Connecting);
47
+ break;
48
+ case C.SignalReconnecting:
49
+ i("LiveKit room signal reconnecting..."), (S = e.onConnectionStateChange) == null || S.call(e, g.Connecting);
50
+ break;
51
+ }
52
+ }), a.on(d.ConnectionQualityChanged, (n, t) => {
53
+ var o;
54
+ t != null && t.isLocal && n === "poor" && (i("Connection quality is poor"), (o = e.onConnectivityStateChange) == null || o.call(e, U.Weak));
55
+ }), a.on(d.ParticipantConnected, (n) => {
56
+ i("Participant connected:", n.identity);
57
+ }), a.on(d.TrackSubscribed, (n, t, o) => {
58
+ var r, s;
59
+ i(`Track subscribed: ${n.kind} from ${o.identity}`), c ? c.addTrack(n.mediaStreamTrack) : c = new MediaStream([n.mediaStreamTrack]), (r = e.onSrcObjectReady) == null || r.call(e, c), n.kind === "video" && ((s = e.onVideoStateChange) == null || s.call(e, P.Start));
60
+ }), a.on(d.TrackUnsubscribed, (n, t, o) => {
61
+ var r;
62
+ i(`Track unsubscribed: ${n.kind} from ${o.identity}`), n.kind === "video" && ((r = e.onVideoStateChange) == null || r.call(e, P.Stop));
63
+ }), a.on(d.DataReceived, (n, t) => {
64
+ var r, s, S, D, $;
65
+ const o = new TextDecoder().decode(n);
66
+ i("Data received:", o);
67
+ try {
68
+ const m = JSON.parse(o);
69
+ m.subject === V.StreamStarted && ((r = m.metadata) != null && r.videoId) ? (y = m.metadata.videoId, (s = e.onVideoIdChange) == null || s.call(e, y), (S = e.onAgentActivityStateChange) == null || S.call(e, w.Talking)) : m.subject === V.StreamDone && (y = null, (D = e.onVideoIdChange) == null || D.call(e, y), ($ = e.onAgentActivityStateChange) == null || $.call(e, w.Idle));
70
+ } catch (m) {
71
+ i("Failed to parse data channel message:", m);
72
+ }
73
+ }), (E = e.onConnectionStateChange) == null || E.call(e, g.New);
74
+ const _ = Q(j, F || q, u, e.onError);
75
+ let f, A;
76
+ try {
77
+ const n = await _.createStream({
78
+ transport: J.Livekit
79
+ }), { agent_id: t, session_id: o, session_token: r, session_url: s } = n;
80
+ f = t, A = o, await a.connect(s, r), i("LiveKit room joined successfully");
81
+ } catch (n) {
82
+ throw i("Failed to connect to LiveKit room:", n), (K = e.onConnectionStateChange) == null || K.call(e, g.Fail), (I = e.onError) == null || I.call(e, n, { streamId: "" }), n;
83
+ }
84
+ M.enrich({
85
+ "stream-type": L
86
+ });
87
+ async function R(n) {
88
+ var t, o;
89
+ if (!v || !a) {
90
+ i("Room is not connected for sending messages"), (t = e.onError) == null || t.call(e, new Error("Room is not connected for sending messages"), {
91
+ streamId: f
92
+ });
93
+ return;
94
+ }
95
+ try {
96
+ await a.localParticipant.publishData(new TextEncoder().encode(n), { reliable: !0 });
97
+ } catch (r) {
98
+ i("Error sending data channel message", r), (o = e.onError) == null || o.call(e, r, { streamId: f });
99
+ }
100
+ }
101
+ return {
102
+ speak(n) {
103
+ const t = JSON.stringify({
104
+ type: "speak",
105
+ payload: n
106
+ });
107
+ return R(t);
108
+ },
109
+ async disconnect() {
110
+ var n, t;
111
+ a && (await a.disconnect(), a = null), c && (c.getTracks().forEach((o) => o.stop()), c = null), v = !1, (n = e.onConnectionStateChange) == null || n.call(e, g.Completed), (t = e.onAgentActivityStateChange) == null || t.call(e, w.Idle);
112
+ },
113
+ sendDataChannelMessage: R,
114
+ sessionId: A,
115
+ streamId: f,
116
+ streamType: L,
117
+ interruptAvailable: !0
118
+ };
119
+ }
120
+ export {
121
+ H as createLiveKitStreamingManager
122
+ };
@@ -0,0 +1,5 @@
1
+ import { Auth, CreateStreamV2Options, CreateStreamV2Response } from '../../types';
2
+
3
+ export declare function createStreamApiV2(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): {
4
+ createStream(options: CreateStreamV2Options): Promise<CreateStreamV2Response>;
5
+ };
@@ -3,6 +3,7 @@ export interface AnalyticsOptions {
3
3
  agentId: string;
4
4
  isEnabled?: boolean;
5
5
  distinctId?: string;
6
+ mixpanelAdditionalProperties?: Record<string, any>;
6
7
  }
7
8
  export interface Analytics {
8
9
  token: string;
@@ -0,0 +1,39 @@
1
+ import { CreateStreamOptions, PayloadType, StreamType } from '../../types';
2
+
3
+ export declare const createStreamingLogger: (debug: boolean, prefix: string) => (message: string, extra?: any) => false | void;
4
+ /**
5
+ * Shared type for all streaming managers (LiveKit, WebRTC, etc.)
6
+ * This type represents the return value of any streaming manager implementation
7
+ */
8
+ export type StreamingManager<T extends CreateStreamOptions> = {
9
+ /**
10
+ * Method to send request to server to get clip or talk depending on payload
11
+ * @param payload The payload to send to the streaming service
12
+ */
13
+ speak(payload: PayloadType<T>): Promise<any>;
14
+ /**
15
+ * Method to close the streaming connection
16
+ */
17
+ disconnect(): Promise<void>;
18
+ /**
19
+ * Method to send data channel messages to the server
20
+ * @param payload The message payload to send
21
+ */
22
+ sendDataChannelMessage(payload: string): void;
23
+ /**
24
+ * Session identifier information, should be returned in the body of all streaming requests
25
+ */
26
+ sessionId: string;
27
+ /**
28
+ * Id of current streaming session
29
+ */
30
+ streamId: string;
31
+ /**
32
+ * Type of streaming implementation being used
33
+ */
34
+ streamType: StreamType;
35
+ /**
36
+ * Whether interrupt functionality is available for this stream
37
+ */
38
+ interruptAvailable: boolean;
39
+ };
@@ -0,0 +1,3 @@
1
+ import { Agent, CreateStreamOptions, StreamingManagerOptions } from '../../types';
2
+
3
+ export declare function createStreamingManager<T extends CreateStreamOptions>(agent: Agent, streamOptions: T, options: StreamingManagerOptions): Promise<import('./common').StreamingManager<T>>;
@@ -1,35 +1,4 @@
1
- import { ConnectionState, CreateStreamOptions, PayloadType, StreamEvents, StreamType, StreamingManagerOptions } from '../../types/index';
2
-
3
- type DataChannelPayload = string | Record<string, unknown>;
4
- export declare function mapConnectionState(state: RTCIceConnectionState): ConnectionState;
5
- export declare function parseDataChannelMessage(message: string): {
6
- subject: StreamEvents;
7
- data: DataChannelPayload;
8
- };
9
- export declare function createStreamingManager<T extends CreateStreamOptions>(agentId: string, agent: T, { debug, callbacks, auth, baseURL, analytics }: StreamingManagerOptions): Promise<{
10
- /**
11
- * Method to send request to server to get clip or talk depend on you payload
12
- * @param payload
13
- */
14
- speak(payload: PayloadType<T>): Promise<import('../../types/index').SendStreamPayloadResponse>;
15
- /**
16
- * Method to close RTC connection
17
- */
18
- disconnect(): Promise<void>;
19
- /**
20
- * Method to send data channel messages to the server
21
- */
22
- sendDataChannelMessage(payload: string): void;
23
- /**
24
- * Session identifier information, should be returned in the body of all streaming requests
25
- */
26
- sessionId: string;
27
- /**
28
- * Id of current RTC stream
29
- */
30
- streamId: string;
31
- streamType: StreamType;
32
- interruptAvailable: boolean | undefined;
33
- }>;
34
- export type StreamingManager<T extends CreateStreamOptions> = Awaited<ReturnType<typeof createStreamingManager<T>>>;
35
- export {};
1
+ export { createStreamingManager } from './factory';
2
+ export type { StreamingManager } from './common';
3
+ export type { LiveKitStreamingManager } from './livekit-manager';
4
+ export * from './webrtc-manager';
@@ -0,0 +1,5 @@
1
+ import { CreateStreamOptions, StreamingManagerOptions } from '../../types';
2
+ import { StreamingManager } from './common';
3
+
4
+ export declare function createLiveKitStreamingManager<T extends CreateStreamOptions>(agentId: string, agent: T, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
5
+ export type LiveKitStreamingManager<T extends CreateStreamOptions> = StreamingManager<T>;
@@ -0,0 +1,12 @@
1
+ import { ConnectionState, CreateStreamOptions, StreamEvents, StreamingManagerOptions } from '../../types';
2
+ import { createStreamingLogger, StreamingManager } from './common';
3
+
4
+ type DataChannelPayload = string | Record<string, unknown>;
5
+ export declare function mapConnectionState(state: RTCIceConnectionState): ConnectionState;
6
+ export declare const createParseDataChannelMessage: (log: ReturnType<typeof createStreamingLogger>) => (message: string) => {
7
+ subject: StreamEvents;
8
+ data: DataChannelPayload;
9
+ };
10
+ export declare function createWebRTCStreamingManager<T extends CreateStreamOptions>(agentId: string, streamOptions: T, { debug, callbacks, auth, baseURL, analytics }: StreamingManagerOptions): Promise<StreamingManager<T>>;
11
+ export type WebRTCStreamingManager<T extends CreateStreamOptions> = StreamingManager<T>;
12
+ export {};
@@ -133,6 +133,7 @@ export interface AgentManagerOptions {
133
133
  debug?: boolean;
134
134
  enableAnalitics?: boolean;
135
135
  mixpanelKey?: string;
136
+ mixpanelAdditionalProperties?: Record<string, any>;
136
137
  /**
137
138
  * Unique ID of agent user used in analytics. Pass it to override the default way to get distinctId
138
139
  */
@@ -1,8 +1,8 @@
1
1
  import { ExtendedTextToSpeechProviders } from '../../voice/tts';
2
2
  import { Rect } from '../../face-rect';
3
3
 
4
- export type videoType = 'talk' | 'clip';
5
- export type Presenter = TalkPresenter | ClipPresenter;
4
+ export type videoType = 'talk' | 'clip' | 'expressive';
5
+ export type Presenter = TalkPresenter | ClipPresenter | ExpresivePresenter;
6
6
  export interface BasePresenter {
7
7
  type: videoType;
8
8
  voice?: ExtendedTextToSpeechProviders & {
@@ -25,3 +25,6 @@ export interface ClipPresenter extends BasePresenter {
25
25
  presenter_id: string;
26
26
  is_greenscreen?: boolean;
27
27
  }
28
+ export interface ExpresivePresenter extends BasePresenter {
29
+ type: 'expressive';
30
+ }
@@ -1,5 +1,6 @@
1
1
  export declare enum VideoType {
2
2
  Clip = "clip",
3
- Talk = "talk"
3
+ Talk = "talk",
4
+ Expressive = "expressive"
4
5
  }
5
6
  export declare const mapVideoType: (type: string) => VideoType;
@@ -1,3 +1,4 @@
1
1
  export * from './api';
2
2
  export * from './rtc';
3
3
  export * from './stream';
4
+ export * from './streams-v2';
@@ -0,0 +1,12 @@
1
+ export declare enum Transport {
2
+ Livekit = "livekit"
3
+ }
4
+ export interface CreateStreamV2Options {
5
+ transport: Transport.Livekit;
6
+ }
7
+ export interface CreateStreamV2Response {
8
+ agent_id: 'string';
9
+ session_id: 'string';
10
+ session_url: 'string';
11
+ session_token: 'string';
12
+ }
@@ -5,7 +5,7 @@ export declare function getAnalyticsInfo(agent: Agent): {
5
5
  isMobile: string;
6
6
  browser: string;
7
7
  origin: string;
8
- agentType: "talk" | "clip" | "clip_v2";
8
+ agentType: "talk" | "clip" | "expressive" | "clip_v2";
9
9
  agentVoice: {
10
10
  voiceId: string | undefined;
11
11
  provider: import('../types/index').Providers | undefined;
@@ -13,7 +13,7 @@ export declare function getAnalyticsInfo(agent: Agent): {
13
13
  };
14
14
  export declare function getAgentInfo(agent: Agent): {
15
15
  from?: string | undefined;
16
- agentType: "talk" | "clip" | "clip_v2";
16
+ agentType: "talk" | "clip" | "expressive" | "clip_v2";
17
17
  owner_id: string;
18
18
  promptVersion: "v1" | "v2" | null | undefined;
19
19
  behavior: {
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.11-staging.40",
4
+ "version": "1.1.11-staging.42",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -38,6 +38,9 @@
38
38
  "lint:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx}\"",
39
39
  "ci:test": "yarn type-check && yarn test:ci"
40
40
  },
41
+ "dependencies": {
42
+ "livekit-client": "^2.0.0"
43
+ },
41
44
  "devDependencies": {
42
45
  "@preact/preset-vite": "^2.8.1",
43
46
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",