@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
package/README.md CHANGED
@@ -1,6 +1,288 @@
1
- # agents-sdk
2
- SDK for Agents
1
+ # Agents SDK Overview 📙
3
2
 
4
- # Deploy
5
- In order to deploy, you need to merge your branch into main. After branch is merged, run ```yarn build && yarn publish```. <br>
6
- You will be prompted to enter the version.
3
+ <div style="display: flex; flex-direction: row; align-items: center; justify-content: space-evenly; min-height: 1px; font-size: 16px;">
4
+ <img style="width: auto; height: 200px; object-fit: contain;" src="https://create-images-results.d-id.com/api_docs/assets/agents_sdk_cover_v2.png" alt="Agents SDK Cover" />
5
+ <span style="width: 67%; text-align: justify;">
6
+ <br> Welcome to the Agents SDK documentation!<br> Here, you’ll find everything you need to know to get started with the SDK, understand its core concepts, utilize built-in methods, and access additional resources.<br> This guide is designed to help you integrate the Agents SDK into your projects effectively and efficiently.
7
+ </span>
8
+ </div>
9
+
10
+ ## ✴️ Introduction
11
+
12
+ The D-ID Agents SDK provides a seamless integration pathway for embedding your created Agents or real-time streaming avatars into web applications.
13
+
14
+ With a streamlined and user-friendly workflow, you can easily harness the capabilities of the D-ID Agents and Streams API right out of the box.
15
+
16
+ **Please note:** This SDK is designed for front-end development only. The creation of Agents and Knowledge bases should be handled through the [Agents API](https://docs.d-id.com/reference/agents-overview) or directly within the [D-ID Studio](https://studio.d-id.com/agents).
17
+
18
+ ## ✴️ Getting Started
19
+
20
+ ### ➤ ✴️ Prerequisites
21
+
22
+ Follow these steps:
23
+
24
+ 1. Log in to the [D-ID Studio](http://studio.d-id.com)
25
+ 2. Create a new Agent with the required options - Image, voice, etc.
26
+ 3. In the [Agents gallery](https://studio.d-id.com/agents), hover with your mouse over the created Agent, then click on the `[...]` button
27
+ 4. Click on `</> Embed` button
28
+ 5. Set the list of allowed domains for your Agent, for example: `http://localhost`
29
+ This is an additional security measurement: your Agent can be accessed only from the domains allowed by you.
30
+ 6. In the code snippet section, fetch the `data-client-key` and the `data-agent-id`, these will be used later to access your Agent.
31
+
32
+ ### ➤ ✴️ Installation
33
+
34
+ In your front-end application folder, install the Agents SDK library using `npm`.
35
+
36
+ ```shell
37
+ npm i @d-id/client-sdk
38
+ ```
39
+
40
+ Alternatively, you can clone the SDK from its [GitHub repository](https://github.com/de-id/agents-sdk).
41
+
42
+ ### ➤ ✴️ Initialization
43
+
44
+ In your front-end application,
45
+
46
+ 1. Import the Agents SDK library
47
+ 2. Paste the `data-agent-id` obtained in the prerequisites step in the `agentId` variable
48
+ 3. Paste the `data-client-key` obtained in the prerequisites step in the `auth.clientKey` variable
49
+ 4. Define an object called `callbacks`.
50
+ This will be explained in the [Usage section](#➤-%EF%B8%8F-callback-functions) in this guide.
51
+ 5. Define an object called `streamOptions` [optional]
52
+ This will be explained in the [Usage section](#➤-%EF%B8%8F-stream-options) in this guide.
53
+ 6. Create an instance of the `createAgentManger` object called `agentManager` with the values created above.
54
+ This will be explained later in the [Usage section](#➤-%EF%B8%8F-agent-manager) in this guide.
55
+
56
+ Example:
57
+
58
+ ```javascript
59
+ // 1. Import the Agents SDK library
60
+ import * as sdk from '@d-id/client-sdk';
61
+
62
+ // 2. Paste the `data-agent-id' in the 'agentId' variable
63
+ let agentId = 'agt_fumf1234';
64
+
65
+ // 3. Paste the 'data-client-key' in the 'auth.clientKey' variable
66
+ let auth = { type: 'key', clientKey: 'Z3123asdaczxSXSAasdcxzcashDY6MGSASFsafxSDdfASY2k0TUhPcEVsTnBR' };
67
+
68
+ // 4. Define the SDK callbacks functions in this object
69
+ const callbacks = {};
70
+
71
+ // 5. Define the Stream Options object (Optional)
72
+ let streamOptions = { compatibilityMode: 'auto', streamWarmup: true };
73
+
74
+ //....Rest of the APP's code here....//
75
+ //...................................//
76
+
77
+ // 6. Create the 'agentManager' instance with the values created above
78
+ let agentManager = await sdk.createAgentManager(agentId, { auth, callbacks, streamOptions });
79
+ ```
80
+
81
+ ## ✴️ Usage
82
+
83
+ ### ➤ ✴️ Agent Manager
84
+
85
+ #### **Built-in Properties**
86
+
87
+ The `agentManager` object created during initialization has several built-in parameters that might come in handy.
88
+
89
+ - **`agentManager.agent`**
90
+ Displaying all of the Agent's saved information (Same as the following [endpoint](/reference/getagent))
91
+ - **`agentManager.starterMessages`**
92
+ Displaying the Agent's defined Starter Messages.
93
+
94
+ #### **Built-in Methods**
95
+
96
+ The `agentManager` object created during initialization has several built-in methods that allow you to interact with your Agent.
97
+
98
+ - **`agentManager.connect()`**
99
+ Method to create a new connection with an Agent (new WebRTC connection, web-socket, new Agent chat ID)
100
+
101
+ - **`agentManager.speak({type, input})`**
102
+ Method to make your Agent stream back a video based on a text or audio file.
103
+ (Similar to [Talks Streams](https://docs.d-id.com/reference/talks-streams-overview) / [Clips Streams API](https://docs.d-id.com/reference/clips-streams-overview))
104
+
105
+ ```javascript Text - JavaScript
106
+ let speak = agentManager.speak({
107
+ type: 'text',
108
+ input: "Hi! I'm Alice!",
109
+ });
110
+ ```
111
+
112
+ ```javascript Audio File - JavaScript
113
+ let speak = agentManager.speak(
114
+ {
115
+ type: "audio",
116
+ audio_url: "http://www.yourwebsite.com/audio.mp3";
117
+ }
118
+ )
119
+ ```
120
+
121
+ - **`agentManager.chat(string)`**
122
+ Method to send a message to your Agent and get a streamed video based on its answer (LLM)
123
+
124
+ ```javascript JavaScript
125
+ let chat = agentManager.chat('What is the distance to the moon?');
126
+ ```
127
+
128
+ - **`agentManager.rate(messageID, score)`**
129
+ Method to rate the Agent's answer in the chat - for future analytics and insights.
130
+
131
+ - **`agentManager.reconnect()`**
132
+ Method to reconnect to the Agent when the session expires and continue the conversation on the same chat ID.
133
+
134
+ - **`agentManager.disconnect()`**
135
+ Method to close the existing connection and chat with the Agent.
136
+
137
+ ### ➤ ✴️ Callback Functions
138
+
139
+ Callback functions enable you to manage various events throughout the SDK lifecycle. Each function is linked to one or more methods within the built-in `agentManager` and triggers automatically to handle specific events efficiently
140
+
141
+ - **`onSrcObjectReady(value)`:**
142
+ [**MANDATORY for using the SDK**] - Linking the Streamed video and audio to the HTML element.
143
+ The `value` of this callback function is passed to the HTML video element in the following function.
144
+ Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
145
+
146
+ ```javascript
147
+ onSrcObjectReady(value) {
148
+ videoElement.srcObject = value
149
+ srcObject = value
150
+ return srcObject
151
+ }
152
+ ```
153
+
154
+ - **`onVideoStateChange(state)`:**
155
+ Displaying the state of the streamed video, used for switching the HTML element's source between the idle and streamed videos.
156
+ Triggered when `agentManager.chat() and agentManager.speak()` are called.
157
+
158
+ ```javascript
159
+ onVideoStateChange(state) {
160
+ console.log("onVideoStateChange(): ", state)
161
+ if (state == "STOP") {
162
+ videoElement.srcObject = undefined
163
+ videoElement.src = agentManager.agent.presenter.idle_video
164
+ }
165
+ else {
166
+ videoElement.src = ""
167
+ videoElement.srcObject = srcObject
168
+ connectionLabel.innerHTML = "Online"
169
+ }
170
+ }
171
+ ```
172
+
173
+ - **`onConnectionStateChange(state):`**
174
+ Displaying the different connection states with the Agent's WebRTC stream connection
175
+ Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
176
+
177
+ ```javascript
178
+ onConnectionStateChange(state) {
179
+ console.log("onConnectionStateChange(): ", state)
180
+ if (state == "connected") {
181
+ console.log("I'm ready to go!")
182
+ }
183
+ }
184
+ ```
185
+
186
+ ```javascript Example Values
187
+ state: ['new', 'fail', 'connecting', 'connected', 'disconnected', 'closed'];
188
+ ```
189
+
190
+ - **`onNewMessage(messages, type)`:**
191
+ Displaying the chat messages array when a new message is sent to the chat.
192
+ `type`: `answer` indicates the full answer replied in the streamed video.
193
+ `role`: `user`, `assistant`(Agent)
194
+
195
+ Triggered when `agentManager.chat()` is called:
196
+
197
+ ```javascript
198
+ onNewMessage(messages, type) {
199
+ console.log(messages, type)
200
+ }
201
+ ```
202
+
203
+ ```javascript Example Values
204
+ type: ['partial', 'answer'];
205
+
206
+ messages: [
207
+ {
208
+ role: 'assistant',
209
+ content: "Hi! I'm an Agent. How can I help you?",
210
+ created_at: '2024-07-08T08:35:54.503Z',
211
+ id: '35113960da531',
212
+ },
213
+ {
214
+ role: 'user',
215
+ content: 'What is the distance to the moon?',
216
+ created_at: '2024-07-08T08:36:48.036Z',
217
+ id: 'f82377af5a9c4',
218
+ },
219
+ {
220
+ role: 'assistant',
221
+ content:
222
+ "The average distance to the moon is about 238,855 miles (384,400 kilometers). That's about 30 times the diameter of the Earth!",
223
+ id: '49b86saf2aff8',
224
+ created_at: '2024-07-08T08:36:48.037Z',
225
+ matches: [],
226
+ },
227
+ ];
228
+ ```
229
+
230
+ - **`onError(error, errorData)`:**
231
+ Throwing an error and displaying the error message when things go badly.
232
+
233
+ ```javascript
234
+ onError(error, errorData) {
235
+ console.log("Error:", error, "Error Data", errorData)
236
+ }
237
+ ```
238
+
239
+ ### ➤ ✴️ Stream Options
240
+
241
+ - **`compatibilityMode`**:
242
+ Defines the video codec to be used in the stream.
243
+ When set to `"on"`: VP8 will be used.
244
+ When set to `"off"`: H264 will be used
245
+ When set to `"auto"` - the codec will be selected according to the browser [Default]
246
+ <br />
247
+ - **`streamWarmup`**:
248
+ Allowed values:
249
+ `true` - warmup video will be streamed when the connection is established.
250
+ `false` - no warmup video [Default]
251
+ <br />
252
+ - **`sessionTimeout`**:
253
+ **Can only be used with proper permissions**
254
+ Maximum duration (in seconds) between messages before the session times out.
255
+ Max value: `300`
256
+ <br />
257
+ - **`outputResolution`**:
258
+ **Supported only with Talk presenters (photo-based).**
259
+ The output resolution sets the maximum height or width pixels of the streamed video.
260
+ When resolution is not configured, it defaults to the agent output resolution.
261
+ Allowed values: `150 - 1080`
262
+
263
+ ## ✴️ See it in Action
264
+
265
+ Explore our demo repository on GitHub to see the Agents SDK in action!
266
+ This repository features a sample project crafted in Vanilla JavaScript and Vite, utilizing the Agents SDK to help you get started swiftly.
267
+
268
+ [GitHub Demo Repository](https://github.com/de-id/Agents-SDK-Demo)
269
+
270
+ ## ✴️ Support
271
+
272
+ <div style="display: flex; flex-direction: row; justify-content: space-evenly; min-height: 1px">
273
+ <img style="width: 37%; border-radius: 5px; object-fit: cover;" src="https://create-images-results.d-id.com/api_docs/assets/questions.png" alt="Support Image" />
274
+ <span style="width: 3%"><br/></span>
275
+ <span style="width: 60%; text-align: left;">
276
+ Have any questions? We are here to help! Please leave your question in the Discussions section and we will be happy to answer shortly.<br/><br/>
277
+ <a href="https://docs.d-id.com/discuss">
278
+ <span style="width: 30%; text-align: center; background: #ff882eff; color: #fff; display: inline-block; padding: 6px; border-radius: 5px;">
279
+ Ask a question
280
+ </span>
281
+ </a>
282
+ </span>
283
+ </div>
284
+
285
+ <div style="display: flex; flex-direction: row; justify-content: space-evenly; min-height: 1px">
286
+ <span style="width: 100%; text-align: center; background: linear-gradient(to right, #ff882eff , #fff); color: #fff; display: inline-block; padding: 6px; border-radius: 3px;">
287
+ </span>
288
+ </div>