@d-id/client-sdk 1.0.20 → 1.1.0-beta.1
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.
- package/README.md +288 -2
- package/dist/index.js +1061 -375
- package/dist/index.umd.cjs +1 -1
- package/dist/src/api/agents.d.ts +17 -0
- package/dist/src/api/apiClient.d.ts +10 -0
- package/dist/src/{lib/api → api}/knowledge.d.ts +3 -2
- package/dist/src/api/streams/clipStream.d.ts +2 -0
- package/dist/src/api/streams/index.d.ts +2 -0
- package/dist/src/api/streams/talkStream.d.ts +2 -0
- package/dist/src/auth/get-auth-header.d.ts +3 -0
- package/dist/src/config/consts.d.ts +2 -0
- package/dist/src/{lib → config}/environment.d.ts +0 -2
- package/dist/src/errors/base-error.d.ts +12 -0
- package/dist/src/errors/chat/chat-creation-failed.d.ts +5 -0
- package/dist/src/errors/chat/chat-mode-downgraded.d.ts +5 -0
- package/dist/src/errors/index.d.ts +4 -0
- package/dist/src/errors/validation-error.d.ts +5 -0
- package/dist/src/errors/ws-error.d.ts +4 -0
- package/dist/src/index.d.ts +3 -8
- package/dist/src/services/agent-manager/connect-to-manager.d.ts +7 -0
- package/dist/src/services/agent-manager/index.d.ts +24 -0
- package/dist/src/services/analytics/mixpanel.d.ts +21 -0
- package/dist/src/services/analytics/timestamp-tracker.d.ts +5 -0
- package/dist/src/services/chat/index.d.ts +7 -0
- package/dist/src/services/chat/intial-messages.d.ts +3 -0
- package/dist/src/services/socket-manager/index.d.ts +11 -0
- package/dist/src/services/socket-manager/message-queue.d.ts +11 -0
- package/dist/src/services/streaming-manager/index.d.ts +21 -0
- package/dist/src/services/streaming-manager/stats/poll.d.ts +4 -0
- package/dist/src/services/streaming-manager/stats/report.d.ts +11 -0
- package/dist/src/types/auth.d.ts +2 -4
- package/dist/src/types/entities/agents/agent.d.ts +37 -2
- package/dist/src/types/entities/agents/chat.d.ts +14 -6
- package/dist/src/types/entities/agents/knowledge.d.ts +2 -0
- package/dist/src/types/entities/agents/llm.d.ts +20 -17
- package/dist/src/types/entities/agents/manager.d.ts +99 -25
- package/dist/src/types/entities/agents/presenter.d.ts +8 -2
- package/dist/src/types/entities/video.d.ts +1 -0
- package/dist/src/types/face-rect.d.ts +6 -0
- package/dist/src/types/index.d.ts +4 -4
- package/dist/src/types/stream/api/clip.d.ts +20 -9
- package/dist/src/types/stream/api/talk.d.ts +31 -1
- package/dist/src/types/stream/rtc.d.ts +3 -3
- package/dist/src/types/stream/stream.d.ts +52 -4
- package/dist/src/types/{StreamScript.d.ts → stream-script.d.ts} +2 -2
- package/dist/src/types/voice/stt.d.ts +4 -0
- package/dist/src/utils/agent.d.ts +4 -0
- package/dist/src/utils/analytics.d.ts +13 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/retry-operation.d.ts +38 -0
- package/package.json +11 -11
- package/dist/src/lib/api/agents.d.ts +0 -10
- package/dist/src/lib/api/clipStream.d.ts +0 -2
- package/dist/src/lib/api/getClient.d.ts +0 -7
- package/dist/src/lib/api/ratings.d.ts +0 -7
- package/dist/src/lib/api/talkStream.d.ts +0 -2
- package/dist/src/lib/auth/getAuthHeader.d.ts +0 -2
- package/dist/src/lib/connectToSocket.d.ts +0 -9
- package/dist/src/lib/createAgentManager.d.ts +0 -15
- package/dist/src/lib/createStreamingManager.d.ts +0 -27
- package/dist/src/lib/utils/webrtc.d.ts +0 -2
- /package/dist/src/types/{tts.d.ts → voice/tts.d.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { STTTokenResponse } from '../..';
|
|
2
|
+
import { SupportedStreamScipt } from '../../stream-script';
|
|
2
3
|
import { Auth } from '../../auth';
|
|
3
|
-
import { SendStreamPayloadResponse,
|
|
4
|
+
import { CompatibilityMode, ConnectionState, SendStreamPayloadResponse, StreamEvents, StreamingState } from '../../stream';
|
|
4
5
|
import { Agent } from './agent';
|
|
5
|
-
import { ChatResponse, Message, RatingEntity
|
|
6
|
+
import { ChatMode, ChatResponse, Message, RatingEntity } from './chat';
|
|
6
7
|
/**
|
|
7
8
|
* Types of events provided in Chat Progress Callback
|
|
8
9
|
*/
|
|
@@ -28,15 +29,15 @@ export declare enum ChatProgress {
|
|
|
28
29
|
*/
|
|
29
30
|
Complete = "done"
|
|
30
31
|
}
|
|
31
|
-
export type ChatProgressCallback = (progress: ChatProgress, data:
|
|
32
|
-
export type ConnectionStateChangeCallback = (state:
|
|
33
|
-
export type VideoStateChangeCallback = (state: StreamingState,
|
|
32
|
+
export type ChatProgressCallback = (progress: ChatProgress | StreamEvents, data: any) => void;
|
|
33
|
+
export type ConnectionStateChangeCallback = (state: ConnectionState) => void;
|
|
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:
|
|
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
|
|
@@ -52,17 +53,76 @@ interface ManagerCallbacks {
|
|
|
52
53
|
*/
|
|
53
54
|
onSrcObjectReady(srcObject: MediaStream): void;
|
|
54
55
|
/**
|
|
55
|
-
* Optional callback function that will be triggered each time
|
|
56
|
-
* @param
|
|
56
|
+
* Optional callback function that will be triggered each time new message is received
|
|
57
|
+
* @param messages - array of messages
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
onNewMessage?(messages: Message[], type: 'answer' | 'partial' | 'user'): void;
|
|
60
|
+
/**
|
|
61
|
+
* Optional callback function that will be triggered each time new chat is created
|
|
62
|
+
* @param chatId - id of the new chat
|
|
63
|
+
*/
|
|
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;
|
|
59
109
|
}
|
|
60
110
|
export interface AgentManagerOptions {
|
|
111
|
+
auth: Auth;
|
|
61
112
|
callbacks: ManagerCallbacks;
|
|
113
|
+
mode: ChatMode;
|
|
62
114
|
baseURL?: string;
|
|
63
115
|
wsURL?: string;
|
|
64
116
|
debug?: boolean;
|
|
65
|
-
|
|
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;
|
|
66
126
|
}
|
|
67
127
|
export interface AgentManager {
|
|
68
128
|
/**
|
|
@@ -71,29 +131,38 @@ export interface AgentManager {
|
|
|
71
131
|
*/
|
|
72
132
|
agent: Agent;
|
|
73
133
|
/**
|
|
74
|
-
*
|
|
75
|
-
* Since chat uses an RTC connection to communicate with the agent, it could be dropped and to continue to chat you need to reconnect
|
|
134
|
+
* Array of starter messages that will be sent to the agent when the chat starts
|
|
76
135
|
*/
|
|
77
|
-
|
|
136
|
+
starterMessages: string[];
|
|
78
137
|
/**
|
|
79
|
-
*
|
|
138
|
+
* Get a token for the Speech to Text service
|
|
139
|
+
* Only available after a chat has started and the agent has been connected
|
|
80
140
|
*/
|
|
81
|
-
|
|
141
|
+
getSTTToken: () => Promise<STTTokenResponse | undefined>;
|
|
82
142
|
/**
|
|
83
|
-
*
|
|
143
|
+
* Method to connect to stream and chat
|
|
84
144
|
*/
|
|
85
|
-
|
|
145
|
+
connect: () => Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Method to reconnect to stream and continue chat
|
|
148
|
+
*/
|
|
149
|
+
reconnect: () => Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Method to close all connections with agent, stream and web socket
|
|
152
|
+
*/
|
|
153
|
+
disconnect: () => Promise<void>;
|
|
86
154
|
/**
|
|
87
155
|
* Method to send a chat message to existing chat with the agent
|
|
88
156
|
* @param messages
|
|
89
157
|
*/
|
|
90
|
-
chat: (
|
|
158
|
+
chat: (userMessage: string) => Promise<ChatResponse>;
|
|
91
159
|
/**
|
|
92
160
|
* Method to rate the answer in chat
|
|
93
|
-
* @param
|
|
161
|
+
* @param score: 1 | -1 - score of the answer. 1 for positive, -1 for negative
|
|
162
|
+
* @param matches - array of matches that were used to find the answer
|
|
94
163
|
* @param id - id of Rating entity. Leave it empty to create a new, one or pass it to work with the existing one
|
|
95
164
|
*/
|
|
96
|
-
rate: (
|
|
165
|
+
rate: (messageId: string, score: 1 | -1, rateId?: string) => Promise<RatingEntity>;
|
|
97
166
|
/**
|
|
98
167
|
* Method to delete rating from answer in chat
|
|
99
168
|
* @param id - id of Rating entity.
|
|
@@ -103,11 +172,16 @@ export interface AgentManager {
|
|
|
103
172
|
* Method to make your agent read the text you provide or reproduce sound
|
|
104
173
|
* @param payload
|
|
105
174
|
*/
|
|
106
|
-
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;
|
|
107
181
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param
|
|
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
|
|
110
184
|
*/
|
|
111
|
-
|
|
185
|
+
enrichAnalytics: (properties: Record<string, any>) => void;
|
|
112
186
|
}
|
|
113
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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
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
|
-
*
|
|
29
|
-
*
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
|
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
|
|
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';
|
|
@@ -11,20 +13,39 @@ export declare enum StreamEvents {
|
|
|
11
13
|
ChatAnswer = "chat/answer",
|
|
12
14
|
ChatPartial = "chat/partial",
|
|
13
15
|
StreamDone = "stream/done",
|
|
14
|
-
StreamStarted = "stream/started"
|
|
16
|
+
StreamStarted = "stream/started",
|
|
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"
|
|
15
33
|
}
|
|
16
34
|
export interface ManagerCallbacks {
|
|
17
35
|
onMessage?: (event: string, data: string) => void;
|
|
18
|
-
onConnectionStateChange?: (state:
|
|
19
|
-
onVideoStateChange?: (state: StreamingState,
|
|
36
|
+
onConnectionStateChange?: (state: ConnectionState) => void;
|
|
37
|
+
onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
|
|
20
38
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
39
|
+
onError?: (error: Error, errorData: object) => void;
|
|
21
40
|
}
|
|
22
41
|
export type ManagerCallbackKeys = keyof ManagerCallbacks;
|
|
23
42
|
export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
24
43
|
videoType: VideoType.Talk;
|
|
44
|
+
stream_greeting?: string;
|
|
25
45
|
}
|
|
26
46
|
export interface ClipStreamOptions extends CreateClipStreamRequest {
|
|
27
47
|
videoType: VideoType.Clip;
|
|
48
|
+
stream_greeting?: string;
|
|
28
49
|
}
|
|
29
50
|
export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
|
|
30
51
|
export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
|
|
@@ -39,16 +60,43 @@ export interface StreamingManagerOptions {
|
|
|
39
60
|
callbacks: ManagerCallbacks;
|
|
40
61
|
baseURL?: string;
|
|
41
62
|
debug?: boolean;
|
|
63
|
+
warmup?: boolean;
|
|
42
64
|
auth: Auth;
|
|
65
|
+
analytics: Analytics;
|
|
43
66
|
}
|
|
44
67
|
export interface SlimRTCStatsReport {
|
|
45
68
|
index: number;
|
|
69
|
+
codec: string;
|
|
70
|
+
duration?: number;
|
|
71
|
+
bitrate?: number;
|
|
46
72
|
timestamp: any;
|
|
47
73
|
bytesReceived: any;
|
|
48
74
|
packetsReceived: any;
|
|
49
75
|
packetsLost: any;
|
|
76
|
+
framesDropped: any;
|
|
77
|
+
framesDecoded: any;
|
|
50
78
|
jitter: any;
|
|
79
|
+
jitterBufferDelay: number;
|
|
51
80
|
frameWidth: any;
|
|
52
81
|
frameHeight: any;
|
|
53
|
-
|
|
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[];
|
|
54
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;
|
|
@@ -12,7 +12,7 @@ export interface Stream_Text_Script extends BaseStreamScript {
|
|
|
12
12
|
/**
|
|
13
13
|
* text-to-speech provider from list of supported providers. default is microsoft tts
|
|
14
14
|
*/
|
|
15
|
-
provider
|
|
15
|
+
provider?: StreamTextToSpeechProviders;
|
|
16
16
|
/**
|
|
17
17
|
* The input text that will be synthesized to an audio file.
|
|
18
18
|
* Note that each provider has its own limitations on the text length.
|
|
@@ -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,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.
|
|
4
|
+
"version": "1.1.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "d-id client sdk",
|
|
7
7
|
"repository": {
|
|
@@ -20,29 +20,29 @@
|
|
|
20
20
|
],
|
|
21
21
|
"main": "./dist/index.umd.cjs",
|
|
22
22
|
"module": "./dist/index.js",
|
|
23
|
-
"types": "./dist/src/
|
|
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
|
-
"
|
|
28
|
+
"dev:prod": "export NODE_ENV=production && vite --mode production",
|
|
29
|
+
"deploy:prod": "node ./infra/deploy.js --version beta",
|
|
29
30
|
"preview": "vite preview",
|
|
30
31
|
"test-build": "node .infra/build.js -m development",
|
|
31
32
|
"build:docs": "typedoc"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@preact/preset-vite": "^2.
|
|
35
|
+
"@preact/preset-vite": "^2.8.1",
|
|
35
36
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
|
37
|
+
"@types/node": "^20.11.24",
|
|
36
38
|
"commander": "^11.1.0",
|
|
37
39
|
"glob": "^10.3.10",
|
|
38
|
-
"preact": "^10.
|
|
39
|
-
"prettier": "^3.
|
|
40
|
+
"preact": "^10.19.6",
|
|
41
|
+
"prettier": "^3.2.5",
|
|
40
42
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
41
|
-
"serverless": "3.32.2",
|
|
42
43
|
"typedoc": "^0.25.7",
|
|
43
|
-
"typescript": "^5.3.
|
|
44
|
-
"vite": "^
|
|
45
|
-
"vite-plugin-dts": "^3.
|
|
46
|
-
"vite-plugin-html-env": "^1.2.8"
|
|
44
|
+
"typescript": "^5.3.3",
|
|
45
|
+
"vite": "^5.1.4",
|
|
46
|
+
"vite-plugin-dts": "^3.7.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../../types/index';
|
|
2
|
-
export declare function createAgentsApi(auth: Auth, host?: string): {
|
|
3
|
-
create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
4
|
-
getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
|
|
5
|
-
getById(id: string, options?: RequestInit): Promise<Agent>;
|
|
6
|
-
delete(id: string, options?: RequestInit): Promise<any>;
|
|
7
|
-
update(id: string, payload: AgentPayload, options?: RequestInit): Promise<Agent>;
|
|
8
|
-
newChat(agentId: string, options?: RequestInit): Promise<Chat>;
|
|
9
|
-
chat(agentId: string, chatId: string, payload: ChatPayload, options?: RequestInit): Promise<ChatResponse>;
|
|
10
|
-
};
|
|
@@ -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,9 +0,0 @@
|
|
|
1
|
-
import { Auth } from '../types/auth';
|
|
2
|
-
import { ChatProgressCallback } from '..';
|
|
3
|
-
interface SocketManager {
|
|
4
|
-
socket?: WebSocket;
|
|
5
|
-
terminate: () => void;
|
|
6
|
-
subscribeToEvents: (data: any) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function SocketManager(auth: Auth, host: string, onMessage?: ChatProgressCallback): Promise<SocketManager>;
|
|
9
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Agent, AgentManager, AgentManagerOptions, CreateStreamOptions } from '../types/index';
|
|
2
|
-
export declare function getAgentStreamArgs(agent: Agent): CreateStreamOptions;
|
|
3
|
-
/**
|
|
4
|
-
* Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} agentId - The ID of the agent to chat with.
|
|
7
|
-
* @param {AgentManagerOptions} options - Configurations for the Agent Manager API.
|
|
8
|
-
* * @returns {Promise<AgentManager>} - A promise that resolves to an instance of the AgentsAPI interface.
|
|
9
|
-
*
|
|
10
|
-
* @throws {Error} Throws an error if the agent is not initialized.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const agentManager = await createAgentManager('id-agent123', { auth: { type: 'key', clientKey: '123', externalId: '123' } });
|
|
14
|
-
*/
|
|
15
|
-
export declare function createAgentManager(agentId: string, options: AgentManagerOptions): Promise<AgentManager>;
|