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

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 (57) hide show
  1. package/README.md +287 -5
  2. package/dist/index.js +1038 -383
  3. package/dist/index.umd.cjs +1 -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 +3 -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} +3 -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 +11 -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 +92 -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 +3 -3
  43. package/dist/src/types/stream/stream.d.ts +50 -4
  44. package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +1 -1
  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 +13 -0
  48. package/dist/src/utils/index.d.ts +2 -0
  49. package/dist/src/utils/retry-operation.d.ts +38 -0
  50. package/package.json +4 -3
  51. package/dist/src/api/clipStream.d.ts +0 -2
  52. package/dist/src/api/getClient.d.ts +0 -7
  53. package/dist/src/api/ratings.d.ts +0 -7
  54. package/dist/src/api/talkStream.d.ts +0 -2
  55. package/dist/src/connectToSocket.d.ts +0 -9
  56. package/dist/src/utils/webrtc.d.ts +0 -2
  57. /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
@@ -1,8 +1,9 @@
1
- import { SupportedStreamScipt } from '../../StreamScript';
1
+ import { STTTokenResponse } from '../..';
2
+ import { SupportedStreamScipt } from '../../stream-script';
2
3
  import { Auth } from '../../auth';
3
- import { SendStreamPayloadResponse, StreamingState } from '../../stream';
4
+ import { CompatibilityMode, ConnectionState, SendStreamPayloadResponse, StreamEvents, StreamingState } from '../../stream';
4
5
  import { Agent } from './agent';
5
- import { ChatResponse, Message, RatingEntity } from './chat';
6
+ import { ChatMode, ChatResponse, Message, RatingEntity } from './chat';
6
7
  /**
7
8
  * Types of events provided in Chat Progress Callback
8
9
  */
@@ -28,20 +29,20 @@ export declare enum ChatProgress {
28
29
  */
29
30
  Complete = "done"
30
31
  }
31
- export type ChatProgressCallback = (progress: ChatProgress, data: string) => void;
32
- export type ConnectionStateChangeCallback = (state: RTCIceConnectionState) => void;
32
+ export type ChatProgressCallback = (progress: ChatProgress | StreamEvents, data: any) => void;
33
+ export type ConnectionStateChangeCallback = (state: ConnectionState) => void;
33
34
  export type VideoStateChangeCallback = (state: StreamingState, data: any) => void;
34
35
  interface ManagerCallbacks {
35
36
  /**
36
37
  * Optional callback will be triggered each time the RTC connection changes state
37
38
  * @param state
38
39
  */
39
- onConnectionStateChange?(state: RTCIceConnectionState): void;
40
+ onConnectionStateChange?(state: ConnectionState): void;
40
41
  /**
41
42
  * Optional callback function that will be triggered each time video events happen
42
43
  * @param state
43
44
  */
44
- onVideoStateChange?(state: StreamingState, data?: any): void;
45
+ onVideoStateChange?(state: StreamingState): void;
45
46
  /**
46
47
  * Callback function that will be triggered each time the video stream starts or stops to update html element on webpage
47
48
  * Required callback for SDK
@@ -52,22 +53,76 @@ interface ManagerCallbacks {
52
53
  */
53
54
  onSrcObjectReady(srcObject: MediaStream): void;
54
55
  /**
55
- * Optional callback function that will be triggered each time any changes happen in the chat
56
- * @param progress
56
+ * Optional callback function that will be triggered each time new message is received
57
+ * @param messages - array of messages
57
58
  */
58
- onChatEvents?(progress: ChatProgress, data: any): void;
59
+ onNewMessage?(messages: Message[], type: 'answer' | 'partial' | 'user'): void;
59
60
  /**
60
- * Optional callback function that will be triggered when the agent is ready
61
- * @param agent - Agent instance you are working with
61
+ * Optional callback function that will be triggered each time new chat is created
62
+ * @param chatId - id of the new chat
62
63
  */
63
- onAgentReady?(agent: Agent): void;
64
+ onNewChat?(chatId: string): void;
65
+ /**
66
+ * Optional callback function that will be triggered each time the chat mode changes
67
+ * @param mode - ChatMode
68
+ */
69
+ onModeChange?(mode: ChatMode): void;
70
+ /**
71
+ * Optional callback function that will be triggered on fetch request errors
72
+ */
73
+ onError?: (error: Error, errorData?: object) => void;
74
+ }
75
+ interface StreamOptions {
76
+ /**
77
+ * Defines the video codec to be used in the stream.
78
+ * When set to on: VP8 will be used.
79
+ * When set to off: H264 will be used
80
+ * When set to auto the codec will be selected according to the browser.
81
+ * @default auto
82
+ */
83
+ compatibilityMode?: CompatibilityMode;
84
+ /**
85
+ * Whether to stream wamrup video on the connection.
86
+ * If set to true, will stream a warmup video when connection is established.
87
+ * At the end of the warmup video, a message containing "stream/ready" will be sent on the data channel.
88
+ * @default false
89
+ */
90
+ streamWarmup?: boolean;
91
+ /**
92
+ * Maximum duration (in seconds) between messages before session times out.
93
+ * Can only be used with proper permissions
94
+ * @maximum 300
95
+ * @example 180
96
+ */
97
+ sessionTimeout?: number;
98
+ /**
99
+ * Desired stream resolution for the session
100
+ * @minimum 150
101
+ * @maximum 1080
102
+ */
103
+ outputResolution?: number;
104
+ /**
105
+ * Whether to stream greeting video on the connection.
106
+ * Not supported for premium presenters.
107
+ */
108
+ streamGreeting?: boolean;
64
109
  }
65
110
  export interface AgentManagerOptions {
111
+ auth: Auth;
66
112
  callbacks: ManagerCallbacks;
113
+ mode: ChatMode;
67
114
  baseURL?: string;
68
115
  wsURL?: string;
69
116
  debug?: boolean;
70
- auth: Auth;
117
+ enableAnalitics?: boolean;
118
+ mixpanelKey?: string;
119
+ /**
120
+ * Unique ID of agent user used in analytics. Pass it to override the default way to get distinctId
121
+ */
122
+ distinctId?: string;
123
+ streamOptions?: StreamOptions;
124
+ initialMessages?: Message[];
125
+ persistentChat?: boolean;
71
126
  }
72
127
  export interface AgentManager {
73
128
  /**
@@ -80,30 +135,34 @@ export interface AgentManager {
80
135
  */
81
136
  starterMessages: string[];
82
137
  /**
83
- * Method to be reconnected to chat
84
- * Since chat uses an RTC connection to communicate with the agent, it could be dropped and to continue to chat you need to reconnect
138
+ * Get a token for the Speech to Text service
139
+ * Only available after a chat has started and the agent has been connected
140
+ */
141
+ getSTTToken: () => Promise<STTTokenResponse | undefined>;
142
+ /**
143
+ * Method to connect to stream and chat
144
+ */
145
+ connect: () => Promise<void>;
146
+ /**
147
+ * Method to reconnect to stream and continue chat
85
148
  */
86
149
  reconnect: () => Promise<void>;
87
150
  /**
88
151
  * Method to close all connections with agent, stream and web socket
89
152
  */
90
153
  disconnect: () => Promise<void>;
91
- /**
92
- * ID of chat you are working on now
93
- */
94
- chatId: string;
95
154
  /**
96
155
  * Method to send a chat message to existing chat with the agent
97
156
  * @param messages
98
157
  */
99
- chat: (messages: Message[]) => Promise<ChatResponse>;
158
+ chat: (userMessage: string) => Promise<ChatResponse>;
100
159
  /**
101
160
  * Method to rate the answer in chat
102
161
  * @param score: 1 | -1 - score of the answer. 1 for positive, -1 for negative
103
162
  * @param matches - array of matches that were used to find the answer
104
163
  * @param id - id of Rating entity. Leave it empty to create a new, one or pass it to work with the existing one
105
164
  */
106
- rate: (score: 1 | -1, Message: Message, id?: string) => Promise<RatingEntity>;
165
+ rate: (messageId: string, score: 1 | -1, rateId?: string) => Promise<RatingEntity>;
107
166
  /**
108
167
  * Method to delete rating from answer in chat
109
168
  * @param id - id of Rating entity.
@@ -113,6 +172,16 @@ export interface AgentManager {
113
172
  * Method to make your agent read the text you provide or reproduce sound
114
173
  * @param payload
115
174
  */
116
- speak: (payload: SupportedStreamScipt) => Promise<SendStreamPayloadResponse>;
175
+ speak: (payload: SupportedStreamScipt | string) => Promise<SendStreamPayloadResponse>;
176
+ /**
177
+ * Method to change the mode of the chat
178
+ * @param mode - ChatMode
179
+ */
180
+ changeMode(mode: ChatMode): void;
181
+ /**
182
+ * Method to enrich analytics properties
183
+ * @param properties flat json object with properties that will be added to analytics events fired from the sdk
184
+ */
185
+ enrichAnalytics: (properties: Record<string, any>) => void;
117
186
  }
118
187
  export {};
@@ -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;
@@ -40,17 +40,17 @@ export interface IceCandidate {
40
40
  * The format of this address is a candidate-attribute as defined in RFC 5245. This string is empty ("") if the
41
41
  * RTCIceCandidate is an "end of candidates" indicator.
42
42
  */
43
- candidate: string;
43
+ candidate: string | null;
44
44
  /**
45
45
  * A string specifying the candidate's media stream identification tag which uniquely identifies the media stream
46
46
  * within the component with which the candidate is associated, or null if no such association exists.
47
47
  */
48
- sdpMid: string;
48
+ sdpMid?: string;
49
49
  /**
50
50
  * If not null, sdpMLineIndex indicates the zero-based index number of the media description (as defined in RFC
51
51
  * 4566) in the SDP with which the candidate is associated.
52
52
  */
53
- sdpMLineIndex: number;
53
+ sdpMLineIndex?: number;
54
54
  }
55
55
  export interface Status {
56
56
  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';
@@ -12,21 +14,38 @@ export declare enum StreamEvents {
12
14
  ChatPartial = "chat/partial",
13
15
  StreamDone = "stream/done",
14
16
  StreamStarted = "stream/started",
15
- StreamFailed = "stream/error"
17
+ StreamFailed = "stream/error",
18
+ StreamReady = "stream/ready",
19
+ StreamCreated = "stream/created",
20
+ StreamVideoCreated = "stream-video/started",
21
+ StreamVideoDone = "stream-video/done",
22
+ StreamVideoError = "stream-video/error",
23
+ StreamVideoRejected = "stream-video/rejected"
24
+ }
25
+ export declare enum ConnectionState {
26
+ New = "new",
27
+ Fail = "fail",
28
+ Connected = "connected",
29
+ Connecting = "connecting",
30
+ Closed = "closed",
31
+ Completed = "completed",
32
+ Disconnected = "disconnected"
16
33
  }
17
34
  export interface ManagerCallbacks {
18
35
  onMessage?: (event: string, data: string) => void;
19
- onConnectionStateChange?: (state: RTCIceConnectionState) => void;
20
- onVideoStateChange?: (state: StreamingState, data?: any) => void;
36
+ onConnectionStateChange?: (state: ConnectionState) => void;
37
+ onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
21
38
  onSrcObjectReady?: (value: MediaStream) => void;
39
+ onError?: (error: Error, errorData: object) => void;
22
40
  }
23
41
  export type ManagerCallbackKeys = keyof ManagerCallbacks;
24
42
  export interface TalkStreamOptions extends CreateTalkStreamRequest {
25
43
  videoType: VideoType.Talk;
44
+ stream_greeting?: string;
26
45
  }
27
46
  export interface ClipStreamOptions extends CreateClipStreamRequest {
28
47
  videoType: VideoType.Clip;
29
- idle_video_url?: string;
48
+ stream_greeting?: string;
30
49
  }
31
50
  export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
32
51
  export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
@@ -41,16 +60,43 @@ export interface StreamingManagerOptions {
41
60
  callbacks: ManagerCallbacks;
42
61
  baseURL?: string;
43
62
  debug?: boolean;
63
+ warmup?: boolean;
44
64
  auth: Auth;
65
+ analytics: Analytics;
45
66
  }
46
67
  export interface SlimRTCStatsReport {
47
68
  index: number;
69
+ codec: string;
70
+ duration?: number;
71
+ bitrate?: number;
48
72
  timestamp: any;
49
73
  bytesReceived: any;
50
74
  packetsReceived: any;
51
75
  packetsLost: any;
76
+ framesDropped: any;
77
+ framesDecoded: any;
52
78
  jitter: any;
79
+ jitterBufferDelay: number;
53
80
  frameWidth: any;
54
81
  frameHeight: any;
55
82
  framesPerSecond: any;
83
+ freezeCount: number;
84
+ freezeDuration: number;
85
+ }
86
+ export interface AnalyticsRTCStatsReport {
87
+ timestamp?: number;
88
+ duration: number;
89
+ bytesReceived: number;
90
+ bitrate: number;
91
+ packetsReceived: number;
92
+ packetsLost: number;
93
+ framesDropped: number;
94
+ framesDecoded: number;
95
+ jitter: number;
96
+ jitterBufferDelay: number;
97
+ framesPerSecond: number;
98
+ freezeCount: number;
99
+ freezeDuration: number;
100
+ lowFpsCount?: number;
101
+ causes?: string[];
56
102
  }
@@ -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;
@@ -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,13 @@
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 function getStreamAnalyticsProps(data: any, agent: Agent, additionalProps: Record<string, any>): any;
@@ -0,0 +1,2 @@
1
+ export declare const sleep: (ms: number) => Promise<unknown>;
2
+ export declare const getRandom: () => 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.2",
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",
@@ -44,4 +45,4 @@
44
45
  "vite": "^5.1.4",
45
46
  "vite-plugin-dts": "^3.7.3"
46
47
  }
47
- }
48
+ }
@@ -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