@d-id/client-sdk 2.0.10-staging.411 → 3.0.0-staging.412

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 (49) hide show
  1. package/README.md +53 -264
  2. package/dist/{index-BgmEitAw.js → index-BLrKDuV_.js} +3002 -2825
  3. package/dist/index.js +23 -31
  4. package/dist/index.umd.cjs +5 -5
  5. package/dist/{livekit-manager-CgErNpNN.js → livekit-manager-Cfb9x2ei.js} +53 -50
  6. package/dist/src/api/agents.d.ts +1 -1
  7. package/dist/src/api/apiClient.d.ts +1 -1
  8. package/dist/src/api/knowledge.d.ts +1 -1
  9. package/dist/src/api/streams/streamApi.d.ts +1 -1
  10. package/dist/src/api/streams/streamsApiV2.d.ts +1 -1
  11. package/dist/src/errors/base-error.d.ts +170 -1
  12. package/dist/src/errors/chat/chat-creation-failed.d.ts +24 -0
  13. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +29 -0
  14. package/dist/src/errors/http-error.d.ts +67 -5
  15. package/dist/src/errors/index.d.ts +1 -0
  16. package/dist/src/errors/network-error.d.ts +62 -8
  17. package/dist/src/errors/request-meta.d.ts +12 -0
  18. package/dist/src/errors/stream-error.d.ts +32 -0
  19. package/dist/src/errors/validation-error.d.ts +62 -1
  20. package/dist/src/errors/ws-error.d.ts +29 -0
  21. package/dist/src/index.d.ts +18 -4
  22. package/dist/src/public-api.test.d.ts +1 -0
  23. package/dist/src/services/agent-manager/index.d.ts +46 -6
  24. package/dist/src/services/chat/intial-messages.test.d.ts +1 -0
  25. package/dist/src/services/streaming-manager/common.d.ts +8 -3
  26. package/dist/src/types/auth.d.ts +78 -6
  27. package/dist/src/types/entities/agents/agent.d.ts +152 -6
  28. package/dist/src/types/entities/agents/chat.d.ts +384 -12
  29. package/dist/src/types/entities/agents/manager.d.ts +795 -215
  30. package/dist/src/types/entities/avatar.d.ts +21 -0
  31. package/dist/src/types/entities/index.d.ts +1 -1
  32. package/dist/src/types/entities/knowledge/document.d.ts +7 -8
  33. package/dist/src/types/entities/knowledge/knowledge.d.ts +20 -0
  34. package/dist/src/types/entities/knowledge/record.d.ts +8 -0
  35. package/dist/src/types/entities/knowledge/retrival.d.ts +4 -0
  36. package/dist/src/types/stream/api/clip.d.ts +8 -9
  37. package/dist/src/types/stream/api/talk.d.ts +8 -9
  38. package/dist/src/types/stream/rtc.d.ts +54 -4
  39. package/dist/src/types/stream/stream.d.ts +553 -34
  40. package/dist/src/types/stream/streams-v2.d.ts +12 -0
  41. package/dist/src/types/stream-script.d.ts +92 -19
  42. package/dist/src/types/voice/stt.d.ts +12 -0
  43. package/dist/src/types/voice/tts.d.ts +149 -64
  44. package/dist/src/utils/analytics.d.ts +2 -2
  45. package/dist/src/utils/content-parser.d.ts +31 -0
  46. package/dist/src/utils/tool-calls.d.ts +21 -2
  47. package/dist/src/version.d.ts +6 -0
  48. package/package.json +7 -3
  49. package/dist/src/types/entities/video.d.ts +0 -6
package/README.md CHANGED
@@ -1,33 +1,35 @@
1
- # Agents SDK Overview 📙
1
+ # D-ID Client SDK
2
2
 
3
3
  <div style="display: flex; flex-direction: row; align-items: center; justify-content: space-evenly; min-height: 1px; font-size: 16px;">
4
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
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.
6
+ <br> This guide covers installing the SDK, connecting to an agent and where to find the full API reference.
7
7
  </span>
8
8
  </div>
9
9
 
10
- ## ✴️ Introduction
10
+ ## Introduction
11
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.
12
+ The D-ID Agents SDK embeds your created Agents or real-time streaming avatars into web applications.
13
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.
14
+ It wraps the D-ID Agents and Streams APIs.
15
15
 
16
16
  The SDK supports three avatar types:
17
17
 
18
18
  - **Talks (V2)** — Photo-based presenters using WebRTC streaming.
19
19
  - **Clips (V3)** — Pre-built presenter avatars using WebRTC streaming.
20
- - **Expressives (V4)** — Next-generation avatars using LiveKit-based streaming, supporting microphone input and always-on fluent mode.
20
+ - **Expressive (V4)** — Next-generation avatars using LiveKit-based streaming, supporting microphone input and always-on fluent mode.
21
21
 
22
22
  **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/docs/agent-quickstart) or directly within the [D-ID Studio](https://studio.d-id.com/agents).
23
23
 
24
- ## ✴️ Getting Started
24
+ > 📚 **Full API reference:** [sdk.d-id.com](https://sdk.d-id.com/) — every method, callback, option and type, generated from the source on each release. ![Docs coverage](https://sdk.d-id.com/coverage.svg)
25
25
 
26
- ### ➤ ✴️ Prerequisites
26
+ ## Getting Started
27
+
28
+ ### Prerequisites
27
29
 
28
30
  Follow these steps:
29
31
 
30
- 1. Log in to the [D-ID Studio](http://studio.d-id.com)
32
+ 1. Log in to the [D-ID Studio](https://studio.d-id.com)
31
33
  2. Create a new Agent with the required options - Image, voice, etc.
32
34
  3. In the [Agents gallery](https://studio.d-id.com/agents), hover with your mouse over the created Agent, then click on the `[...]` button
33
35
  4. Click on `</> Embed` button
@@ -35,7 +37,7 @@ Follow these steps:
35
37
  This is an additional security measurement: your Agent can be accessed only from the domains allowed by you.
36
38
  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.
37
39
 
38
- ### ➤ ✴️ Installation
40
+ ### Installation
39
41
 
40
42
  In your front-end application folder, install the Agents SDK library using `npm`.
41
43
 
@@ -45,19 +47,21 @@ npm i @d-id/client-sdk
45
47
 
46
48
  Alternatively, you can clone the SDK from its [GitHub repository](https://github.com/de-id/agents-sdk).
47
49
 
48
- ### ➤ ✴️ Initialization
50
+ ### Initialization
49
51
 
50
52
  In your front-end application,
51
53
 
52
54
  1. Import the Agents SDK library
53
55
  2. Paste the `data-agent-id` obtained in the prerequisites step in the `agentId` variable
54
56
  3. Paste the `data-client-key` obtained in the prerequisites step in the `auth.clientKey` variable
55
- 4. Define an object called `callbacks`.
56
- This will be explained in the [Usage section](#➤-%EF%B8%8F-callback-functions) in this guide.
57
- 5. Define an object called `streamOptions` [optional — v2/v3 avatars only]
58
- This will be explained in the [Usage section](#➤-%EF%B8%8F-stream-options) in this guide.
59
- 6. Create an instance of the `createAgentManger` object called `agentManager` with the values created above.
60
- This will be explained later in the [Usage section](#➤-%EF%B8%8F-agent-manager) in this guide.
57
+ 4. Define an object called `callbacks`. `onSrcObjectReady` is mandatory: it hands you the media stream to render, so without it the agent has nowhere to play.
58
+ See [`AgentManagerCallbacks`](https://sdk.d-id.com/interfaces/AgentManagerCallbacks.html) in the API reference.
59
+ 5. Define an object called `streamOptions` [optional — Talks (V2) and Clips (V3) agents only]
60
+ See [`StreamOptions`](https://sdk.d-id.com/interfaces/StreamOptions.html) in the API reference.
61
+ 6. Create an instance of the `createAgentManager` object called `agentManager` with the values created above.
62
+ See [`AgentManager`](https://sdk.d-id.com/interfaces/AgentManager.html) in the API reference.
63
+ 7. Open the session with `connect()`, and wait for it to resolve before speaking to the agent.
64
+ 8. Make the agent talk: `speak()` says exactly what you give it, `chat()` has the agent answer with its own LLM.
61
65
 
62
66
  Example:
63
67
 
@@ -72,9 +76,23 @@ let agentId = 'agt_fumf1234';
72
76
  let auth = { type: 'key', clientKey: 'Z3123asdaczxSXSAasdcxzcashDY6MGSASFsafxSDdfASY2k0TUhPcEVsTnBR' };
73
77
 
74
78
  // 4. Define the SDK callbacks functions in this object
75
- const callbacks = {};
79
+ const videoElement = document.getElementById('agent-video');
80
+
81
+ const callbacks = {
82
+ onSrcObjectReady(value) {
83
+ videoElement.srcObject = value;
84
+ },
85
+ onConnectionStateChange(state) {
86
+ console.log('connection:', state);
87
+ },
88
+ onNewMessage(messages, type) {
89
+ if (type === 'answer') {
90
+ console.log(messages[messages.length - 1].content);
91
+ }
92
+ },
93
+ };
76
94
 
77
- // 5. Define the Stream Options object (Optional — v2/v3 avatars only)
95
+ // 5. Define the Stream Options object (Optional — Talks (V2) and Clips (V3) agents only)
78
96
  let streamOptions = { compatibilityMode: 'auto', streamWarmup: true };
79
97
 
80
98
  //....Rest of the APP's code here....//
@@ -82,268 +100,39 @@ let streamOptions = { compatibilityMode: 'auto', streamWarmup: true };
82
100
 
83
101
  // 6. Create the 'agentManager' instance with the values created above
84
102
  let agentManager = await sdk.createAgentManager(agentId, { auth, callbacks, streamOptions });
85
- ```
86
-
87
- ## ✴️ Usage
88
-
89
- ### ➤ ✴️ Agent Manager
90
-
91
- #### **Built-in Properties**
92
-
93
- The `agentManager` object created during initialization has several built-in parameters that might come in handy.
94
-
95
- - **`agentManager.agent`**
96
- Displaying all of the Agent's saved information (Same as the following [endpoint](https://docs.d-id.com/reference/agent-get))
97
- - **`agentManager.starterMessages`**
98
- Displaying the Agent's defined Starter Messages.
99
-
100
- #### **Built-in Methods**
101
-
102
- The `agentManager` object created during initialization has several built-in methods that allow you to interact with your Agent.
103
-
104
- - **`agentManager.connect()`**
105
- Method to create a new connection with an Agent (new WebRTC connection, web-socket, new Agent chat ID)
106
-
107
- - **`agentManager.speak({type, input})`**
108
- Method to make your Agent stream back a video based on a text or audio file.
109
- (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))
110
-
111
- ```javascript Text - JavaScript
112
- let speak = agentManager.speak({
113
- type: 'text',
114
- input: "Hi! I'm Alice!",
115
- });
116
- ```
117
-
118
- Text scripts also accept an optional `sentiment` (expressive avatars only). If the requested sentiment is not supported by the agent, the default sentiment is used.
119
-
120
- ```javascript Text with sentiment - JavaScript
121
- let speak = agentManager.speak({
122
- type: 'text',
123
- input: "Hi! I'm Alice!",
124
- sentiment: 'friendly',
125
- });
126
- ```
127
-
128
- ```javascript Audio File - JavaScript
129
- let speak = agentManager.speak({
130
- type: 'audio',
131
- audio_url: 'http://www.yourwebsite.com/audio.mp3',
132
- });
133
- ```
134
-
135
- - **`agentManager.chat(string)`**
136
- Method to send a message to your Agent and get a streamed video based on its answer (LLM)
137
-
138
- ```javascript JavaScript
139
- let chat = agentManager.chat('What is the distance to the moon?');
140
- ```
141
-
142
- - **`agentManager.rate(messageID, score)`**
143
- Method to rate the Agent's answer in the chat - for future analytics and insights.
144
103
 
145
- - **`agentManager.reconnect()`**
146
- Method to reconnect to the Agent when the session expires and continue the conversation on the same chat ID.
104
+ // 7. Open the session
105
+ await agentManager.connect();
147
106
 
148
- - **`agentManager.disconnect()`**
149
- Method to close the existing connection and chat with the Agent.
150
-
151
- - **`agentManager.interrupt(interrupt)`**
152
- Method to interrupt the current video stream mid-playback.
153
- Supported for Fluent streams (V3 Pro Avatars) and all Expressive (V4) agents.
154
-
155
- - **`agentManager.publishMicrophoneStream(stream)`**
156
- **Supported only with Expressive (V4) agents.**
157
- Method to publish a microphone audio track to the session. Call after `connect()` to enable voice input.
158
-
159
- ```javascript
160
- const micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
161
- await agentManager.publishMicrophoneStream(micStream);
162
- ```
163
-
164
- - **`agentManager.unpublishMicrophoneStream()`**
165
- **Supported only with Expressive (V4) agents.**
166
- Method to stop and remove the currently published microphone track from the session.
167
-
168
- ```javascript
169
- await agentManager.unpublishMicrophoneStream();
170
- ```
171
-
172
- - **`agentManager.sendDataChannelMessage(topic, payload)`**
173
- **Supported only with Expressive (V4) agents.**
174
- Method to send a JSON payload to the agent over a data-channel topic. `PublicDataChannelTopic` is exported from the package root and lists every topic this method accepts.
175
-
176
- ```javascript
177
- import { PublicDataChannelTopic } from '@d-id/client-sdk';
178
-
179
- await agentManager.sendDataChannelMessage(PublicDataChannelTopic.Presentation, { type: 'navigate', slide: 3 });
180
- ```
181
-
182
- ### ➤ ✴️ Callback Functions
183
-
184
- 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
185
-
186
- - **`onSrcObjectReady(value)`:**
187
- [**MANDATORY for using the SDK**] - Linking the Streamed video and audio to the HTML element.
188
- The `value` of this callback function is passed to the HTML video element in the following function.
189
- Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
190
-
191
- ```javascript
192
- onSrcObjectReady(value) {
193
- videoElement.srcObject = value
194
- srcObject = value
195
- return srcObject
196
- }
197
- ```
198
-
199
- - **`onVideoStateChange(state)`:**
200
- Displaying the state of the streamed video, used for switching the HTML element's source between the idle and streamed videos.
201
- Triggered when `agentManager.chat() and agentManager.speak()` are called.
202
-
203
- ```javascript
204
- onVideoStateChange(state) {
205
- console.log("onVideoStateChange(): ", state)
206
- if (state == "STOP") {
207
- videoElement.srcObject = undefined
208
- videoElement.src = agentManager.agent.presenter.idle_video
209
- }
210
- else {
211
- videoElement.src = ""
212
- videoElement.srcObject = srcObject
213
- connectionLabel.innerHTML = "Online"
214
- }
215
- }
216
- ```
217
-
218
- - **`onConnectionStateChange(state, reason):`**
219
- Displaying the different connection states with the Agent's WebRTC stream connection
220
- Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
221
-
222
- ```javascript
223
- onConnectionStateChange(state, reason) {
224
- console.log("onConnectionStateChange(): ", state, reason)
225
- if (state == "connected") {
226
- console.log("I'm ready to go!")
227
- }
228
- }
229
- ```
230
-
231
- The second `reason` argument says why the connection reached that state. On `disconnected` it is a `StreamEndReason` when the server ended the stream on purpose, which lets you tell a deliberate end from a dropped connection. Any other value is an opaque transport diagnostic. `agentManager.reconnect()` still works after a deliberate end; it starts a new stream rather than resuming the old one.
107
+ // 8. Make the agent talk
108
+ await agentManager.speak({ type: 'text', input: "Hi! I'm Alice!" });
109
+ await agentManager.chat('What is the distance to the moon?');
110
+ ```
232
111
 
233
- ```javascript Example Values
234
- state: ['new', 'fail', 'connecting', 'connected', 'disconnected', 'closed'];
235
- reason: ['ok', 'unknown_error', 'network_issue', 'message_limit', 'time_limit', 'inactivity', 'ended_by_agent'];
236
- ```
112
+ ## Usage
237
113
 
238
- - **`onNewMessage(messages, type)`:**
239
- Displaying the chat messages array when a new message is sent to the chat.
240
- `type`: `answer` indicates the full answer replied in the streamed video.
241
- `role`: `user`, `assistant`(Agent)
114
+ Everything the `agentManager` exposes — methods, callbacks, stream options and every type — is documented in the **[API reference](https://sdk.d-id.com/)**, generated from the source on each release. Start with:
242
115
 
243
- Triggered when `agentManager.chat()` is called:
116
+ - [`createAgentManager()`](https://sdk.d-id.com/functions/createAgentManager.html) — initialization and options
117
+ - [`AgentManager`](https://sdk.d-id.com/interfaces/AgentManager.html) — `connect()`, `speak()`, `chat()`, `interrupt()`, microphone and camera publishing, client tools
118
+ - [`AgentManagerCallbacks`](https://sdk.d-id.com/interfaces/AgentManagerCallbacks.html) — `onSrcObjectReady` (mandatory), `onVideoStateChange`, `onConnectionStateChange`, `onNewMessage`, …
119
+ - [`StreamOptions`](https://sdk.d-id.com/interfaces/StreamOptions.html) — Talks (V2) and Clips (V3) transport options
244
120
 
245
- ```javascript
246
- onNewMessage(messages, type) {
247
- console.log(messages, type)
248
- }
249
- ```
250
-
251
- ```javascript Example Values
252
- type: ['partial', 'answer'];
253
-
254
- messages: [
255
- {
256
- role: 'assistant',
257
- content: "Hi! I'm an Agent. How can I help you?",
258
- created_at: '2024-07-08T08:35:54.503Z',
259
- id: '35113960da531',
260
- },
261
- {
262
- role: 'user',
263
- content: 'What is the distance to the moon?',
264
- created_at: '2024-07-08T08:36:48.036Z',
265
- id: 'f82377af5a9c4',
266
- },
267
- {
268
- role: 'assistant',
269
- content:
270
- "The average distance to the moon is about 238,855 miles (384,400 kilometers). That's about 30 times the diameter of the Earth!",
271
- id: '49b86saf2aff8',
272
- created_at: '2024-07-08T08:36:48.037Z',
273
- matches: [],
274
- },
275
- ];
276
- ```
277
-
278
- - **`onConnectivityStateChange(state)`:**
279
- Triggered when the user's internet connectivity state changes, estimated by real-time bitrate.
280
-
281
- ```javascript
282
- onConnectivityStateChange(state) {
283
- console.log("onConnectivityStateChange(): ", state)
284
- }
285
- ```
286
-
287
- ```javascript Example Values
288
- state: ['STRONG', 'WEAK', 'UNKNOWN'];
289
- ```
290
-
291
- - **`onError(error, errorData)`:**
292
- Throwing an error and displaying the error message when things go badly.
293
-
294
- ```javascript
295
- onError(error, errorData) {
296
- console.log("Error:", error, "Error Data", errorData)
297
- }
298
- ```
299
-
300
- ### ➤ ✴️ Stream Options (v2/v3 avatars only)
301
-
302
- > **Note:** `streamOptions` apply only to Talks (V2) and Clips (V3) agents. Expressive (V4) avatars manage transport settings automatically and do not use these options.
303
-
304
- - **`compatibilityMode`**:
305
- Defines the video codec to be used in the stream.
306
- When set to `"on"`: VP8 will be used.
307
- When set to `"off"`: H264 will be used
308
- When set to `"auto"` - the codec will be selected according to the browser [Default]
309
- <br />
310
- - **`streamWarmup`**:
311
- Allowed values:
312
- `true` - warmup video will be streamed when the connection is established.
313
- `false` - no warmup video [Default]
314
- <br />
315
- - **`sessionTimeout`**:
316
- **Can only be used with proper permissions**
317
- Maximum duration (in seconds) between messages before the session times out.
318
- Max value: `300`
319
- <br />
320
- - **`outputResolution`**:
321
- **Supported only with Talk presenters (photo-based).**
322
- The output resolution sets the maximum height or width pixels of the streamed video.
323
- When resolution is not configured, it defaults to the agent output resolution.
324
- Allowed values: `150 - 1080`
325
-
326
- - **`fluent`**:
327
- **Supported with Agents created with V3 Pro Avatars. Always enabled for V4 Avatars.**
328
- Allowed values:
329
- `true` - Fluent streaming (one video for Idle/Talking states)
330
- `false` - Legacy streaming mode (2 video elements)
331
-
332
- ## ✴️ See it in Action
121
+ ## See it in Action
333
122
 
334
123
  Explore our demo repository on GitHub to see the Agents SDK in action!
335
124
  This repository features a sample project crafted in Vanilla JavaScript and Vite, utilizing the Agents SDK to help you get started swiftly.
336
125
 
337
126
  [GitHub Demo Repository](https://github.com/de-id/Agents-SDK-Demo)
338
127
 
339
- ## ✴️ Support
128
+ ## Support
340
129
 
341
130
  <div style="display: flex; flex-direction: row; justify-content: space-evenly; min-height: 1px">
342
131
  <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" />
343
132
  <span style="width: 3%"><br/></span>
344
133
  <span style="width: 60%; text-align: left;">
345
- 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/>
346
- <a href="https://docs.d-id.com/discuss">
134
+ Have any questions? We are here to help! Please open an issue on GitHub and we will be happy to answer shortly.<br/><br/>
135
+ <a href="https://github.com/de-id/agents-sdk/issues">
347
136
  <span style="width: 30%; text-align: center; background: #ff882eff; color: #fff; display: inline-block; padding: 6px; border-radius: 5px;">
348
137
  Ask a question
349
138
  </span>