@d-id/client-sdk 1.1.14 → 1.1.15-staging.63

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,124 @@
1
+ import { c as x, a as N, S as O, C as g, b as U, d as P, e as $, A as T, f as q, T as J } from "./index-DC-HTOF-.js";
2
+ function Q(u, p, h, i) {
3
+ const w = x(u, `${p}/v2/agents/${h}`, i);
4
+ return {
5
+ async createStream(d) {
6
+ return w.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, p, h) {
20
+ var E, K, I;
21
+ const i = N(h.debug || !1, "LiveKitStreamingManager"), {
22
+ Room: w,
23
+ RoomEvent: d,
24
+ ConnectionState: C,
25
+ RemoteParticipant: z,
26
+ RemoteTrack: B
27
+ } = await W(), { callbacks: e, auth: V, baseURL: j, analytics: F } = h;
28
+ let a = null, v = !1, y = null, c = null;
29
+ const L = O.Fluent;
30
+ a = new w({
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 === $.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, T.Talking)) : m.subject === $.StreamDone && (y = null, (D = e.onVideoIdChange) == null || D.call(e, y), (_ = e.onAgentActivityStateChange) == null || _.call(e, T.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 M = Q(V, j || q, u, e.onError);
75
+ let f, A;
76
+ try {
77
+ const n = await M.createStream({
78
+ transport_provider: J.Livekit,
79
+ chat_id: p.chat_id
80
+ }), { agent_id: t, session_id: o, session_token: r, session_url: s } = n;
81
+ f = t, A = o, await a.connect(s, r), i("LiveKit room joined successfully");
82
+ } catch (n) {
83
+ 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;
84
+ }
85
+ F.enrich({
86
+ "stream-type": L
87
+ });
88
+ async function R(n) {
89
+ var t, o;
90
+ if (!v || !a) {
91
+ i("Room is not connected for sending messages"), (t = e.onError) == null || t.call(e, new Error("Room is not connected for sending messages"), {
92
+ streamId: f
93
+ });
94
+ return;
95
+ }
96
+ try {
97
+ await a.localParticipant.publishData(new TextEncoder().encode(n), { reliable: !0 });
98
+ } catch (r) {
99
+ i("Error sending data channel message", r), (o = e.onError) == null || o.call(e, r, { streamId: f });
100
+ }
101
+ }
102
+ return {
103
+ speak(n) {
104
+ const t = JSON.stringify({
105
+ type: "speak",
106
+ payload: n
107
+ });
108
+ return R(t);
109
+ },
110
+ async disconnect() {
111
+ var n, t;
112
+ 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, T.Idle);
113
+ },
114
+ sendDataChannelMessage: R,
115
+ sessionId: A,
116
+ streamId: f,
117
+ streamType: L,
118
+ interruptAvailable: !0,
119
+ triggersAvailable: !1
120
+ };
121
+ }
122
+ export {
123
+ H as createLiveKitStreamingManager
124
+ };
@@ -1,14 +1,15 @@
1
1
  import { StreamingManager } from '../streaming-manager';
2
- import { Agent, AgentManagerOptions, AgentsAPI, Chat, CreateStreamOptions } from '../../types';
2
+ import { Agent, AgentManagerOptions, AgentsAPI, Chat, 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
8
  };
9
+ chatId?: string;
9
10
  };
10
11
  export declare function initializeStreamAndChat(agent: Agent, options: ConnectToManagerOptions, agentsApi: AgentsAPI, analytics: Analytics, chat?: Chat): Promise<{
11
12
  chat?: Chat;
12
- streamingManager?: StreamingManager<CreateStreamOptions>;
13
+ streamingManager?: StreamingManager<CreateStreamOptions | CreateStreamV2Options>;
13
14
  }>;
14
15
  export {};
@@ -1,11 +1,11 @@
1
- import { CreateStreamOptions, PayloadType, StreamType } from '../../types';
1
+ import { CreateStreamOptions, CreateStreamV2Options, 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> = {
8
+ export type StreamingManager<T extends CreateStreamOptions | CreateStreamV2Options> = {
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,3 +1,13 @@
1
- import { Agent, CreateStreamOptions, StreamingManagerOptions } from '../../types';
1
+ import { Agent, CreateStreamOptions, CreateStreamV2Options, StreamingManagerOptions } from '../../types';
2
+ import { StreamingManager } from './common';
2
3
 
3
- export declare function createStreamingManager<T extends CreateStreamOptions>(agent: Agent, streamOptions: T, options: StreamingManagerOptions): Promise<any>;
4
+ export declare enum StreamApiVersion {
5
+ V1 = "v1",
6
+ V2 = "v2"
7
+ }
8
+ export type ExtendedStreamOptions = ({
9
+ version: StreamApiVersion.V1;
10
+ } & CreateStreamOptions) | ({
11
+ version: StreamApiVersion.V2;
12
+ } & CreateStreamV2Options);
13
+ export declare function createStreamingManager(agent: Agent, streamOptions: ExtendedStreamOptions, options: StreamingManagerOptions): Promise<StreamingManager<CreateStreamOptions | CreateStreamV2Options>>;
@@ -1,3 +1,5 @@
1
- export { createStreamingManager } from './factory';
1
+ export { StreamApiVersion as StreamApiVersion, createStreamingManager } from './factory';
2
+ export type { ExtendedStreamOptions } from './factory';
2
3
  export type { StreamingManager } from './common';
4
+ export type { LiveKitStreamingManager } from './livekit-manager';
3
5
  export * from './webrtc-manager';
@@ -1,5 +1,5 @@
1
- import { CreateStreamOptions, StreamingManagerOptions } from '../../types';
1
+ import { CreateStreamOptions, CreateStreamV2Options, StreamingManagerOptions } from '../../types';
2
2
  import { StreamingManager } from './common';
3
3
 
4
- export declare function createLiveKitStreamingManager<T extends CreateStreamOptions>(agentId: string, agent: T, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
4
+ export declare function createLiveKitStreamingManager<T extends CreateStreamV2Options>(agentId: string, agent: T, options: StreamingManagerOptions): Promise<StreamingManager<T>>;
5
5
  export type LiveKitStreamingManager<T extends CreateStreamOptions> = StreamingManager<T>;
@@ -61,11 +61,17 @@ export interface ManagerCallbacks {
61
61
  }) => void;
62
62
  }
63
63
  export type ManagerCallbackKeys = keyof ManagerCallbacks;
64
+ export interface StreamEndUserData {
65
+ distinct_id?: string;
66
+ plan?: string;
67
+ }
64
68
  export interface TalkStreamOptions extends CreateTalkStreamRequest {
65
69
  fluent?: boolean;
70
+ end_user_data?: StreamEndUserData;
66
71
  }
67
72
  export interface ClipStreamOptions extends CreateClipStreamRequest {
68
73
  fluent?: boolean;
74
+ end_user_data?: StreamEndUserData;
69
75
  }
70
76
  export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
71
77
  export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
@@ -1,8 +1,9 @@
1
- export declare enum Transport {
1
+ export declare enum TransportProvider {
2
2
  Livekit = "livekit"
3
3
  }
4
4
  export interface CreateStreamV2Options {
5
- transport: Transport.Livekit;
5
+ transport_provider: TransportProvider.Livekit;
6
+ chat_id?: string;
6
7
  }
7
8
  export interface CreateStreamV2Response {
8
9
  agent_id: 'string';
@@ -2,4 +2,5 @@ import { Agent } from '../types';
2
2
 
3
3
  type AgentType = 'clip_v2' | Agent['presenter']['type'];
4
4
  export declare const getAgentType: (presenter: Agent["presenter"]) => AgentType;
5
+ export declare const isStreamsV2Agent: (type: AgentType) => boolean;
5
6
  export {};
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.14",
4
+ "version": "1.1.15-staging.63",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Advanced functionality tests for streaming manager
3
- * Tests complex scenarios, edge cases, and advanced features
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Business flow tests for streaming manager
3
- * Tests critical end-to-end workflows and configurations
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Disconnect and cleanup tests for streaming manager
3
- * Tests disconnection workflows, cleanup, and error handling
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Edge cases and branch coverage tests for streaming manager
3
- * Tests detailed edge cases, error conditions, and branch coverage scenarios
4
- */
5
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Core functionality tests for streaming manager
3
- * Tests basic streaming manager creation, connection, and operations
4
- */
5
- export {};
@@ -1,5 +0,0 @@
1
- /**
2
- * Utility function tests for streaming manager
3
- * Tests helper functions like mapConnectionState and parseDataChannelMessage
4
- */
5
- export {};