@d-id/client-sdk 1.0.29-beta.55 → 1.1.0-beta.10

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 (58) hide show
  1. package/README.md +287 -5
  2. package/dist/index.js +1725 -414
  3. package/dist/index.umd.cjs +1851 -1
  4. package/dist/src/api/agents.d.ts +16 -9
  5. package/dist/src/api/apiClient.d.ts +10 -0
  6. package/dist/src/api/knowledge.d.ts +1 -1
  7. package/dist/src/api/streams/clipStream.d.ts +2 -0
  8. package/dist/src/api/streams/index.d.ts +2 -0
  9. package/dist/src/api/streams/talkStream.d.ts +2 -0
  10. package/dist/src/auth/{getAuthHeader.d.ts → get-auth-header.d.ts} +1 -0
  11. package/dist/src/config/consts.d.ts +2 -0
  12. package/dist/src/{environment.d.ts → config/environment.d.ts} +0 -1
  13. package/dist/src/errors/base-error.d.ts +12 -0
  14. package/dist/src/errors/chat/chat-creation-failed.d.ts +5 -0
  15. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +5 -0
  16. package/dist/src/errors/index.d.ts +4 -0
  17. package/dist/src/errors/validation-error.d.ts +5 -0
  18. package/dist/src/errors/ws-error.d.ts +4 -0
  19. package/dist/src/index.d.ts +3 -2
  20. package/dist/src/services/agent-manager/connect-to-manager.d.ts +7 -0
  21. package/dist/src/{createAgentManager.d.ts → services/agent-manager/index.d.ts} +12 -4
  22. package/dist/src/services/analytics/mixpanel.d.ts +21 -0
  23. package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
  24. package/dist/src/services/chat/index.d.ts +7 -0
  25. package/dist/src/services/chat/intial-messages.d.ts +2 -0
  26. package/dist/src/services/socket-manager/index.d.ts +11 -0
  27. package/dist/src/services/socket-manager/message-queue.d.ts +11 -0
  28. package/dist/src/{createStreamingManager.d.ts → services/streaming-manager/index.d.ts} +4 -3
  29. package/dist/src/services/streaming-manager/stats/poll.d.ts +4 -0
  30. package/dist/src/services/streaming-manager/stats/report.d.ts +17 -0
  31. package/dist/src/types/entities/agents/agent.d.ts +14 -2
  32. package/dist/src/types/entities/agents/chat.d.ts +12 -4
  33. package/dist/src/types/entities/agents/knowledge.d.ts +2 -0
  34. package/dist/src/types/entities/agents/llm.d.ts +20 -17
  35. package/dist/src/types/entities/agents/manager.d.ts +106 -23
  36. package/dist/src/types/entities/agents/presenter.d.ts +8 -2
  37. package/dist/src/types/entities/video.d.ts +1 -0
  38. package/dist/src/types/face-rect.d.ts +6 -0
  39. package/dist/src/types/index.d.ts +4 -4
  40. package/dist/src/types/stream/api/clip.d.ts +21 -9
  41. package/dist/src/types/stream/api/talk.d.ts +31 -1
  42. package/dist/src/types/stream/rtc.d.ts +4 -3
  43. package/dist/src/types/stream/stream.d.ts +70 -4
  44. package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +2 -2
  45. package/dist/src/types/voice/stt.d.ts +4 -0
  46. package/dist/src/utils/agent.d.ts +4 -0
  47. package/dist/src/utils/analytics.d.ts +15 -0
  48. package/dist/src/utils/chat.d.ts +2 -0
  49. package/dist/src/utils/index.d.ts +2 -0
  50. package/dist/src/utils/retry-operation.d.ts +38 -0
  51. package/package.json +3 -2
  52. package/dist/src/api/clipStream.d.ts +0 -2
  53. package/dist/src/api/getClient.d.ts +0 -7
  54. package/dist/src/api/ratings.d.ts +0 -7
  55. package/dist/src/api/talkStream.d.ts +0 -2
  56. package/dist/src/connectToSocket.d.ts +0 -9
  57. package/dist/src/utils/webrtc.d.ts +0 -2
  58. /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
@@ -1,9 +1,12 @@
1
- import { ExtendedTextToSpeechProviders } from '../../tts';
1
+ import { ExtendedTextToSpeechProviders } from '../../voice/tts';
2
+ import { Rect } from '../../face-rect';
2
3
  export type videoType = 'talk' | 'clip';
3
4
  export type Presenter = TalkPresenter | ClipPresenter;
4
5
  export interface BasePresenter {
5
6
  type: videoType;
6
- voice?: ExtendedTextToSpeechProviders;
7
+ voice?: ExtendedTextToSpeechProviders & {
8
+ language?: string;
9
+ };
7
10
  idle_video?: string;
8
11
  thumbnail?: string;
9
12
  }
@@ -11,10 +14,13 @@ export interface TalkPresenter extends BasePresenter {
11
14
  type: 'talk';
12
15
  source_url: string;
13
16
  driver_url?: string;
17
+ stitch?: boolean;
18
+ face?: Rect;
14
19
  }
15
20
  export interface ClipPresenter extends BasePresenter {
16
21
  type: 'clip';
17
22
  driver_id: string;
18
23
  background?: string;
19
24
  presenter_id: string;
25
+ is_greenscreen?: boolean;
20
26
  }
@@ -2,3 +2,4 @@ export declare enum VideoType {
2
2
  Clip = "clip",
3
3
  Talk = "talk"
4
4
  }
5
+ export declare const mapVideoType: (type: string) => VideoType;
@@ -0,0 +1,6 @@
1
+ export interface Rect {
2
+ top: number;
3
+ left: number;
4
+ bottom: number;
5
+ right: number;
6
+ }
@@ -1,6 +1,6 @@
1
- export * from './StreamScript';
2
- export * from './tts';
3
- export * from './stream';
1
+ export * from './stream-script';
4
2
  export * from './auth';
5
3
  export * from './entities';
6
- export * from '..';
4
+ export * from './stream';
5
+ export * from './voice/stt';
6
+ export * from './voice/tts';
@@ -25,16 +25,14 @@ interface ClipConfig {
25
25
  }
26
26
  export interface CreateClipStreamRequest {
27
27
  /**
28
- * ID of the selected presenter.
29
- * @example "rian-lZC6MmWfC1"
28
+ * The output resolution sets the maximum height or width of the streamed video.
29
+ * The aspect ratio is preserved from the source video.
30
+ * When resolution is not configured, it defaults to the agent output resolution.
31
+ * @minimum 150
32
+ * @maximum 1080
33
+ * @example 512
30
34
  */
31
- presenter_id: string;
32
- /**
33
- * ID of the selected driver.
34
- * If not provided a driver video will be selected for you from the predefined drivers bank.
35
- * @example "mXra4jY38i"
36
- */
37
- driver_id?: string;
35
+ output_resolution?: number;
38
36
  /**
39
37
  * Defines the video codec to be used in the stream.
40
38
  * When set to on: VP8 will be used.
@@ -43,6 +41,19 @@ export interface CreateClipStreamRequest {
43
41
  * @default auto
44
42
  */
45
43
  compatibility_mode?: CompatibilityMode;
44
+ /**
45
+ * Whether to stream wamrup video on the connection.
46
+ * If set to true, will stream a warmup video when connection is established.
47
+ * At the end of the warmup video, a message containing "stream/ready" will be sent on the data channel.
48
+ */
49
+ stream_warmup?: boolean;
50
+ /**
51
+ * Maximum duration (in seconds) between messages before session times out.
52
+ * Can only be used with proper permissions
53
+ * @maximum 300
54
+ * @example 180
55
+ */
56
+ session_timeout?: number;
46
57
  }
47
58
  export interface SendClipStreamPayload extends StickyRequest {
48
59
  script: StreamScript;
@@ -106,5 +117,6 @@ export interface SendClipStreamPayload extends StickyRequest {
106
117
  * @example "https://path.to.directory/"
107
118
  */
108
119
  raw_result_url?: string;
120
+ metadata: Record<string, any>;
109
121
  }
110
122
  export {};
@@ -1,6 +1,6 @@
1
1
  import { StreamScript } from '../..';
2
+ import { CompatibilityMode } from '../stream';
2
3
  export interface CreateTalkStreamRequest {
3
- source_url: string;
4
4
  driver_url?: string;
5
5
  face?: {
6
6
  size: number;
@@ -20,6 +20,36 @@ export interface CreateTalkStreamRequest {
20
20
  align_expand_factor?: number;
21
21
  stitch?: boolean;
22
22
  };
23
+ /**
24
+ * The output resolution sets the maximum height or width of the streamed video.
25
+ * The aspect ratio is preserved from the source image.
26
+ * When resolution is not configured, it defaults to the agent output resolution.
27
+ * @minimum 150
28
+ * @maximum 1080
29
+ * @example 512
30
+ */
31
+ output_resolution?: number;
32
+ /**
33
+ * Defines the video codec to be used in the stream.
34
+ * When set to on: VP8 will be used.
35
+ * When set to off: H264 will be used
36
+ * When set to auto the codec will be selected according to the browser.
37
+ * @default auto
38
+ */
39
+ compatibility_mode?: CompatibilityMode;
40
+ /**
41
+ * Whether to stream wamrup video on the connection.
42
+ * If set to true, will stream a warmup video when connection is established.
43
+ * At the end of the warmup video, a message containing "stream/ready" will be sent on the data channel.
44
+ */
45
+ stream_warmup?: boolean;
46
+ /**
47
+ * Maximum duration (in seconds) between messages before session times out.
48
+ * Can only be used with proper permissions
49
+ * @maximum 300
50
+ * @example 180
51
+ */
52
+ session_timeout?: number;
23
53
  }
24
54
  export interface SendTalkStreamPayload {
25
55
  script: StreamScript;
@@ -33,6 +33,7 @@ export interface ICreateStreamRequestResponse extends StickyRequest {
33
33
  jsep: Jsep;
34
34
  offer: any;
35
35
  ice_servers: IceServer[];
36
+ fluent?: boolean;
36
37
  }
37
38
  export interface IceCandidate {
38
39
  /**
@@ -40,17 +41,17 @@ export interface IceCandidate {
40
41
  * The format of this address is a candidate-attribute as defined in RFC 5245. This string is empty ("") if the
41
42
  * RTCIceCandidate is an "end of candidates" indicator.
42
43
  */
43
- candidate: string;
44
+ candidate: string | null;
44
45
  /**
45
46
  * A string specifying the candidate's media stream identification tag which uniquely identifies the media stream
46
47
  * within the component with which the candidate is associated, or null if no such association exists.
47
48
  */
48
- sdpMid: string;
49
+ sdpMid?: string;
49
50
  /**
50
51
  * If not null, sdpMLineIndex indicates the zero-based index number of the media description (as defined in RFC
51
52
  * 4566) in the SDP with which the candidate is associated.
52
53
  */
53
- sdpMLineIndex: number;
54
+ sdpMLineIndex?: number;
54
55
  }
55
56
  export interface Status {
56
57
  status: string;
@@ -1,3 +1,5 @@
1
+ import { Analytics } from '../../services/analytics/mixpanel';
2
+ import { VideoRTCStatsReport } from '../../services/streaming-manager/stats/report';
1
3
  import { Auth } from '../auth';
2
4
  import { VideoType } from '../entities';
3
5
  import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
@@ -7,26 +9,59 @@ export declare enum StreamingState {
7
9
  Start = "START",
8
10
  Stop = "STOP"
9
11
  }
12
+ export declare enum ConnectivityState {
13
+ Strong = "STRONG",
14
+ Weak = "WEAK",
15
+ Unknown = "UNKNOWN"
16
+ }
17
+ export declare enum AgentActivityState {
18
+ Idle = "IDLE",
19
+ Talking = "TALKING"
20
+ }
21
+ export declare const DataChannelSignalMap: Record<string, StreamingState>;
10
22
  export declare enum StreamEvents {
11
23
  ChatAnswer = "chat/answer",
12
24
  ChatPartial = "chat/partial",
13
25
  StreamDone = "stream/done",
14
26
  StreamStarted = "stream/started",
15
- StreamFailed = "stream/error"
27
+ StreamFailed = "stream/error",
28
+ StreamReady = "stream/ready",
29
+ StreamCreated = "stream/created",
30
+ StreamVideoCreated = "stream-video/started",
31
+ StreamVideoDone = "stream-video/done",
32
+ StreamVideoError = "stream-video/error",
33
+ StreamVideoRejected = "stream-video/rejected"
34
+ }
35
+ export declare enum ConnectionState {
36
+ New = "new",
37
+ Fail = "fail",
38
+ Connected = "connected",
39
+ Connecting = "connecting",
40
+ Closed = "closed",
41
+ Completed = "completed",
42
+ Disconnected = "disconnected"
43
+ }
44
+ export declare enum StreamType {
45
+ Legacy = "legacy",
46
+ Fluent = "fluent"
16
47
  }
17
48
  export interface ManagerCallbacks {
18
49
  onMessage?: (event: string, data: string) => void;
19
- onConnectionStateChange?: (state: RTCIceConnectionState) => void;
20
- onVideoStateChange?: (state: StreamingState, data?: any) => void;
50
+ onConnectionStateChange?: (state: ConnectionState) => void;
51
+ onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
21
52
  onSrcObjectReady?: (value: MediaStream) => void;
53
+ onError?: (error: Error, errorData: object) => void;
54
+ onConnectivityStateChange?: (state: ConnectivityState) => void;
55
+ onAgentActivityStateChange?: (state: AgentActivityState) => void;
22
56
  }
23
57
  export type ManagerCallbackKeys = keyof ManagerCallbacks;
24
58
  export interface TalkStreamOptions extends CreateTalkStreamRequest {
25
59
  videoType: VideoType.Talk;
60
+ fluent?: boolean;
26
61
  }
27
62
  export interface ClipStreamOptions extends CreateClipStreamRequest {
28
63
  videoType: VideoType.Clip;
29
- idle_video_url?: string;
64
+ fluent?: boolean;
30
65
  }
31
66
  export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
32
67
  export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
@@ -42,15 +77,46 @@ export interface StreamingManagerOptions {
42
77
  baseURL?: string;
43
78
  debug?: boolean;
44
79
  auth: Auth;
80
+ analytics: Analytics;
45
81
  }
46
82
  export interface SlimRTCStatsReport {
47
83
  index: number;
84
+ codec: string;
85
+ rtt: number;
86
+ duration?: number;
87
+ bitrate?: number;
48
88
  timestamp: any;
49
89
  bytesReceived: any;
50
90
  packetsReceived: any;
51
91
  packetsLost: any;
92
+ framesDropped: any;
93
+ framesDecoded: any;
52
94
  jitter: any;
95
+ jitterBufferDelay: number;
96
+ jitterBufferEmittedCount: number;
97
+ avgJitterDelayInInterval: number;
53
98
  frameWidth: any;
54
99
  frameHeight: any;
55
100
  framesPerSecond: any;
101
+ freezeCount: number;
102
+ freezeDuration: number;
103
+ }
104
+ export interface AnalyticsRTCStatsReport {
105
+ timestamp?: number;
106
+ duration: number;
107
+ bytesReceived: number;
108
+ bitrate: number;
109
+ packetsReceived: number;
110
+ packetsLost: number;
111
+ framesDropped: number;
112
+ framesDecoded: number;
113
+ jitter: number;
114
+ jitterBufferDelay: number;
115
+ jitterBufferEmittedCount: number;
116
+ avgJitterDelayInInterval: number;
117
+ framesPerSecond: number;
118
+ freezeCount: number;
119
+ freezeDuration: number;
120
+ lowFpsCount?: number;
121
+ causes?: string[];
56
122
  }
@@ -1,5 +1,5 @@
1
1
  import { Message } from './entities';
2
- import { StreamTextToSpeechProviders } from './tts';
2
+ import { StreamTextToSpeechProviders } from './voice/tts';
3
3
  export type StreamScriptType = 'text' | 'audio';
4
4
  export interface BaseStreamScript {
5
5
  type: StreamScriptType;
@@ -50,4 +50,4 @@ export interface Stream_LLM_Script {
50
50
  stream_audio?: boolean;
51
51
  }
52
52
  export type StreamScript = Stream_Text_Script | Stream_Audio_Script | Stream_LLM_Script;
53
- export type SupportedStreamScipt = Stream_Text_Script | Stream_Audio_Script;
53
+ export type SupportedStreamScript = Stream_Text_Script | Stream_Audio_Script;
@@ -0,0 +1,4 @@
1
+ export interface STTTokenResponse {
2
+ token: string;
3
+ region: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ import { Agent } from '../types';
2
+ type AgentType = 'clip_v2' | Agent['presenter']['type'];
3
+ export declare const getAgentType: (presenter: Agent['presenter']) => AgentType;
4
+ export {};
@@ -0,0 +1,15 @@
1
+ import { Agent } from '../types/index';
2
+ export declare function getAnalyticsInfo(agent: Agent): {
3
+ $os: string;
4
+ isMobile: string;
5
+ browser: string;
6
+ origin: string;
7
+ agentType: "talk" | "clip" | "clip_v2";
8
+ agentVoice: {
9
+ voiceId: string | undefined;
10
+ provider: import('../types/index').Providers | undefined;
11
+ };
12
+ };
13
+ export declare const sumFunc: (numbers: number[]) => number;
14
+ export declare const average: (numbers: number[]) => number;
15
+ export declare function getStreamAnalyticsProps(data: any, agent: Agent, additionalProps: Record<string, any>): any;
@@ -0,0 +1,2 @@
1
+ import { ChatMode } from '../types';
2
+ export declare const isTextualChat: (chatMode: ChatMode) => boolean;
@@ -0,0 +1,2 @@
1
+ export declare const sleep: (ms: number) => Promise<unknown>;
2
+ export declare const getRandom: (length?: number) => string;
@@ -0,0 +1,38 @@
1
+ interface RetryOptions {
2
+ limit?: number;
3
+ delayMs?: number;
4
+ timeout?: number;
5
+ timeoutErrorMessage?: string;
6
+ shouldRetryFn?: (error: any) => boolean;
7
+ onRetry?: (error: any) => void;
8
+ }
9
+ /**
10
+ * Utility function to retry a promise operation with configurable retry logic
11
+ *
12
+ * @param operation - A function that returns a Promise to be retried
13
+ * @param userOptions - Configuration options for retry behavior
14
+ * @param userOptions.limit - Maximum number of retry attempts (default: 3)
15
+ * @param userOptions.delayMs - Delay between retries in milliseconds (default: 0, no delay)
16
+ * @param userOptions.timeout - Timeout for each attempt in milliseconds (default: 30000, set 0 to disable)
17
+ * @param userOptions.timeoutErrorMessage - Custom timeout error message
18
+ * @param userOptions.shouldRetryFn - Function to determine if retry should occur based on error, that will force throw even if limit is not reached when returns "false"
19
+ *
20
+ * @returns Promise that resolves with the operation result or rejects with the last error
21
+ *
22
+ * @throws {Error} Last error encountered after all retries are exhausted
23
+ * @throws {Error} Timeout error if operation exceeds specified timeout
24
+ *
25
+ * @example
26
+ * // With custom options
27
+ * const result = await retryOperation(
28
+ * async () => await fetch(url),
29
+ * {
30
+ * limit: 5,
31
+ * delayMs: 1000,
32
+ * timeout: 5000,
33
+ * shouldRetryFn: (error) => error.status === 429
34
+ * }
35
+ * );
36
+ */
37
+ export declare function retryOperation<T>(operation: () => Promise<T>, userOptions?: RetryOptions): Promise<T>;
38
+ 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.0.29-beta.55",
4
+ "version": "1.1.0-beta.10",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -20,11 +20,12 @@
20
20
  ],
21
21
  "main": "./dist/index.umd.cjs",
22
22
  "module": "./dist/index.js",
23
- "types": "./dist/src/types/index.d.ts",
23
+ "types": "./dist/src/index.d.ts",
24
24
  "scripts": {
25
25
  "dev": "vite",
26
26
  "build": "node ./infra/build.js -m production",
27
27
  "build:dev": "node ./infra/build.js -m development",
28
+ "dev:prod": "export NODE_ENV=production && vite --mode production",
28
29
  "deploy:prod": "node ./infra/deploy.js --version beta",
29
30
  "preview": "vite preview",
30
31
  "test-build": "node .infra/build.js -m development",
@@ -1,2 +0,0 @@
1
- import { Auth, RtcApi } from '../types/index';
2
- export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,7 +0,0 @@
1
- import { Auth } from '../types/auth';
2
- export declare function createClient(auth: Auth, host?: string): {
3
- get<T = any>(url: string, options?: RequestInit): Promise<T>;
4
- post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
5
- delete<T_2 = any>(url: string, body?: any, options?: RequestInit): Promise<T_2>;
6
- patch<T_3 = any>(url: string, body?: any, options?: RequestInit): Promise<T_3>;
7
- };
@@ -1,7 +0,0 @@
1
- import { Auth, RatingEntity, RatingPayload } from '../index';
2
- export declare function createRatingsApi(auth: Auth, host?: string): {
3
- create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
4
- getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
5
- update(id: string, payload: Partial<RatingPayload>, options?: RequestInit): Promise<RatingEntity>;
6
- delete(id: string, options?: RequestInit): Promise<RatingEntity>;
7
- };
@@ -1,2 +0,0 @@
1
- import { Auth, RtcApi } from '../types/index';
2
- export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,9 +0,0 @@
1
- import { Auth } from './types/auth';
2
- import { ChatProgressCallback } from '.';
3
- interface SocketManager {
4
- socket?: WebSocket;
5
- disconnect: () => void;
6
- subscribeToEvents: (data: any) => void;
7
- }
8
- export declare function SocketManager(auth: Auth, host: string, onMessage?: ChatProgressCallback): Promise<SocketManager>;
9
- export {};
@@ -1,2 +0,0 @@
1
- import { SlimRTCStatsReport } from '../types';
2
- export declare function createVideoStatsReport(stats: SlimRTCStatsReport[], previousStats?: SlimRTCStatsReport): SlimRTCStatsReport[];
File without changes