@d-id/client-sdk 1.1.51 → 1.1.52-staging.234
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 +105 -57
- package/dist/index.js +880 -831
- package/dist/index.umd.cjs +5 -5
- package/dist/src/services/streaming-manager/common.d.ts +12 -0
- package/dist/src/types/auth.d.ts +5 -2
- package/dist/src/types/entities/agents/agent.d.ts +4 -0
- package/dist/src/types/entities/agents/manager.d.ts +12 -0
- package/dist/src/types/entities/agents/presenter.d.ts +1 -0
- package/dist/src/utils/agent.d.ts +3 -0
- package/dist/src/utils/analytics.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,12 @@ The D-ID Agents SDK provides a seamless integration pathway for embedding your c
|
|
|
13
13
|
|
|
14
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
15
|
|
|
16
|
+
The SDK supports three avatar types:
|
|
17
|
+
|
|
18
|
+
- **Talks (V2)** — Photo-based presenters using WebRTC streaming.
|
|
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.
|
|
21
|
+
|
|
16
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/reference/agents-overview) or directly within the [D-ID Studio](https://studio.d-id.com/agents).
|
|
17
23
|
|
|
18
24
|
## ✴️ Getting Started
|
|
@@ -25,7 +31,7 @@ Follow these steps:
|
|
|
25
31
|
2. Create a new Agent with the required options - Image, voice, etc.
|
|
26
32
|
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
33
|
4. Click on `</> Embed` button
|
|
28
|
-
5. Set the list of allowed domains for your Agent, for example: `http://localhost`
|
|
34
|
+
5. Set the list of allowed domains for your Agent, for example: `http://localhost`
|
|
29
35
|
This is an additional security measurement: your Agent can be accessed only from the domains allowed by you.
|
|
30
36
|
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
37
|
|
|
@@ -46,11 +52,11 @@ In your front-end application,
|
|
|
46
52
|
1. Import the Agents SDK library
|
|
47
53
|
2. Paste the `data-agent-id` obtained in the prerequisites step in the `agentId` variable
|
|
48
54
|
3. Paste the `data-client-key` obtained in the prerequisites step in the `auth.clientKey` variable
|
|
49
|
-
4. Define an object called `callbacks`.
|
|
55
|
+
4. Define an object called `callbacks`.
|
|
50
56
|
This will be explained in the [Usage section](#➤-%EF%B8%8F-callback-functions) in this guide.
|
|
51
|
-
5. Define an object called `streamOptions` [optional]
|
|
57
|
+
5. Define an object called `streamOptions` [optional — v2/v3 avatars only]
|
|
52
58
|
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.
|
|
59
|
+
6. Create an instance of the `createAgentManger` object called `agentManager` with the values created above.
|
|
54
60
|
This will be explained later in the [Usage section](#➤-%EF%B8%8F-agent-manager) in this guide.
|
|
55
61
|
|
|
56
62
|
Example:
|
|
@@ -68,7 +74,7 @@ let auth = { type: 'key', clientKey: 'Z3123asdaczxSXSAasdcxzcashDY6MGSASFsafxSDd
|
|
|
68
74
|
// 4. Define the SDK callbacks functions in this object
|
|
69
75
|
const callbacks = {};
|
|
70
76
|
|
|
71
|
-
// 5. Define the Stream Options object (Optional)
|
|
77
|
+
// 5. Define the Stream Options object (Optional — v2/v3 avatars only)
|
|
72
78
|
let streamOptions = { compatibilityMode: 'auto', streamWarmup: true };
|
|
73
79
|
|
|
74
80
|
//....Rest of the APP's code here....//
|
|
@@ -86,21 +92,21 @@ let agentManager = await sdk.createAgentManager(agentId, { auth, callbacks, stre
|
|
|
86
92
|
|
|
87
93
|
The `agentManager` object created during initialization has several built-in parameters that might come in handy.
|
|
88
94
|
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
-
|
|
92
|
-
|
|
95
|
+
- **`agentManager.agent`**
|
|
96
|
+
Displaying all of the Agent's saved information (Same as the following [endpoint](/reference/getagent))
|
|
97
|
+
- **`agentManager.starterMessages`**
|
|
98
|
+
Displaying the Agent's defined Starter Messages.
|
|
93
99
|
|
|
94
100
|
#### **Built-in Methods**
|
|
95
101
|
|
|
96
102
|
The `agentManager` object created during initialization has several built-in methods that allow you to interact with your Agent.
|
|
97
103
|
|
|
98
|
-
-
|
|
99
|
-
|
|
104
|
+
- **`agentManager.connect()`**
|
|
105
|
+
Method to create a new connection with an Agent (new WebRTC connection, web-socket, new Agent chat ID)
|
|
100
106
|
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
|
|
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))
|
|
104
110
|
|
|
105
111
|
```javascript Text - JavaScript
|
|
106
112
|
let speak = agentManager.speak({
|
|
@@ -118,30 +124,51 @@ The `agentManager` object created during initialization has several built-in met
|
|
|
118
124
|
)
|
|
119
125
|
```
|
|
120
126
|
|
|
121
|
-
-
|
|
122
|
-
|
|
127
|
+
- **`agentManager.chat(string)`**
|
|
128
|
+
Method to send a message to your Agent and get a streamed video based on its answer (LLM)
|
|
123
129
|
|
|
124
130
|
```javascript JavaScript
|
|
125
131
|
let chat = agentManager.chat('What is the distance to the moon?');
|
|
126
132
|
```
|
|
127
133
|
|
|
128
|
-
-
|
|
129
|
-
|
|
134
|
+
- **`agentManager.rate(messageID, score)`**
|
|
135
|
+
Method to rate the Agent's answer in the chat - for future analytics and insights.
|
|
136
|
+
|
|
137
|
+
- **`agentManager.reconnect()`**
|
|
138
|
+
Method to reconnect to the Agent when the session expires and continue the conversation on the same chat ID.
|
|
139
|
+
|
|
140
|
+
- **`agentManager.disconnect()`**
|
|
141
|
+
Method to close the existing connection and chat with the Agent.
|
|
142
|
+
|
|
143
|
+
- **`agentManager.interrupt(interrupt)`**
|
|
144
|
+
Method to interrupt the current video stream mid-playback.
|
|
145
|
+
Supported for Fluent streams (V3 Pro Avatars) and all Expressive (V4) agents.
|
|
130
146
|
|
|
131
|
-
-
|
|
132
|
-
|
|
147
|
+
- **`agentManager.publishMicrophoneStream(stream)`**
|
|
148
|
+
**Supported only with Expressive (V4) agents.**
|
|
149
|
+
Method to publish a microphone audio track to the session. Call after `connect()` to enable voice input.
|
|
133
150
|
|
|
134
|
-
|
|
135
|
-
|
|
151
|
+
```javascript
|
|
152
|
+
const micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
153
|
+
await agentManager.publishMicrophoneStream(micStream);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- **`agentManager.unpublishMicrophoneStream()`**
|
|
157
|
+
**Supported only with Expressive (V4) agents.**
|
|
158
|
+
Method to stop and remove the currently published microphone track from the session.
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
await agentManager.unpublishMicrophoneStream();
|
|
162
|
+
```
|
|
136
163
|
|
|
137
164
|
### ➤ ✴️ Callback Functions
|
|
138
165
|
|
|
139
166
|
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
167
|
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
168
|
+
- **`onSrcObjectReady(value)`:**
|
|
169
|
+
[**MANDATORY for using the SDK**] - Linking the Streamed video and audio to the HTML element.
|
|
170
|
+
The `value` of this callback function is passed to the HTML video element in the following function.
|
|
171
|
+
Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
|
|
145
172
|
|
|
146
173
|
```javascript
|
|
147
174
|
onSrcObjectReady(value) {
|
|
@@ -151,9 +178,9 @@ Callback functions enable you to manage various events throughout the SDK lifecy
|
|
|
151
178
|
}
|
|
152
179
|
```
|
|
153
180
|
|
|
154
|
-
-
|
|
155
|
-
|
|
156
|
-
|
|
181
|
+
- **`onVideoStateChange(state)`:**
|
|
182
|
+
Displaying the state of the streamed video, used for switching the HTML element's source between the idle and streamed videos.
|
|
183
|
+
Triggered when `agentManager.chat() and agentManager.speak()` are called.
|
|
157
184
|
|
|
158
185
|
```javascript
|
|
159
186
|
onVideoStateChange(state) {
|
|
@@ -170,9 +197,9 @@ Callback functions enable you to manage various events throughout the SDK lifecy
|
|
|
170
197
|
}
|
|
171
198
|
```
|
|
172
199
|
|
|
173
|
-
-
|
|
174
|
-
|
|
175
|
-
|
|
200
|
+
- **`onConnectionStateChange(state):`**
|
|
201
|
+
Displaying the different connection states with the Agent's WebRTC stream connection
|
|
202
|
+
Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
|
|
176
203
|
|
|
177
204
|
```javascript
|
|
178
205
|
onConnectionStateChange(state) {
|
|
@@ -187,10 +214,10 @@ Callback functions enable you to manage various events throughout the SDK lifecy
|
|
|
187
214
|
state: ['new', 'fail', 'connecting', 'connected', 'disconnected', 'closed'];
|
|
188
215
|
```
|
|
189
216
|
|
|
190
|
-
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
217
|
+
- **`onNewMessage(messages, type)`:**
|
|
218
|
+
Displaying the chat messages array when a new message is sent to the chat.
|
|
219
|
+
`type`: `answer` indicates the full answer replied in the streamed video.
|
|
220
|
+
`role`: `user`, `assistant`(Agent)
|
|
194
221
|
|
|
195
222
|
Triggered when `agentManager.chat()` is called:
|
|
196
223
|
|
|
@@ -227,8 +254,21 @@ Callback functions enable you to manage various events throughout the SDK lifecy
|
|
|
227
254
|
];
|
|
228
255
|
```
|
|
229
256
|
|
|
230
|
-
-
|
|
231
|
-
|
|
257
|
+
- **`onConnectivityStateChange(state)`:**
|
|
258
|
+
Triggered when the user's internet connectivity state changes, estimated by real-time bitrate.
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
onConnectivityStateChange(state) {
|
|
262
|
+
console.log("onConnectivityStateChange(): ", state)
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
```javascript Example Values
|
|
267
|
+
state: ['STRONG', 'WEAK', 'UNKNOWN'];
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
- **`onError(error, errorData)`:**
|
|
271
|
+
Throwing an error and displaying the error message when things go badly.
|
|
232
272
|
|
|
233
273
|
```javascript
|
|
234
274
|
onError(error, errorData) {
|
|
@@ -236,33 +276,41 @@ Callback functions enable you to manage various events throughout the SDK lifecy
|
|
|
236
276
|
}
|
|
237
277
|
```
|
|
238
278
|
|
|
239
|
-
### ➤ ✴️ Stream Options
|
|
279
|
+
### ➤ ✴️ Stream Options (v2/v3 avatars only)
|
|
240
280
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
When set to `"
|
|
281
|
+
> **Note:** `streamOptions` apply only to Talks (V2) and Clips (V3) agents. Expressive (V4) avatars manage transport settings automatically and do not use these options.
|
|
282
|
+
|
|
283
|
+
- **`compatibilityMode`**:
|
|
284
|
+
Defines the video codec to be used in the stream.
|
|
285
|
+
When set to `"on"`: VP8 will be used.
|
|
286
|
+
When set to `"off"`: H264 will be used
|
|
287
|
+
When set to `"auto"` - the codec will be selected according to the browser [Default]
|
|
246
288
|
<br />
|
|
247
|
-
- **`streamWarmup`**:
|
|
248
|
-
Allowed values:
|
|
249
|
-
`true` -
|
|
250
|
-
`false` - no warmup video [Default]
|
|
289
|
+
- **`streamWarmup`**:
|
|
290
|
+
Allowed values:
|
|
291
|
+
`true` - warmup video will be streamed when the connection is established.
|
|
292
|
+
`false` - no warmup video [Default]
|
|
251
293
|
<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`
|
|
294
|
+
- **`sessionTimeout`**:
|
|
295
|
+
**Can only be used with proper permissions**
|
|
296
|
+
Maximum duration (in seconds) between messages before the session times out.
|
|
297
|
+
Max value: `300`
|
|
256
298
|
<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.
|
|
299
|
+
- **`outputResolution`**:
|
|
300
|
+
**Supported only with Talk presenters (photo-based).**
|
|
301
|
+
The output resolution sets the maximum height or width pixels of the streamed video.
|
|
302
|
+
When resolution is not configured, it defaults to the agent output resolution.
|
|
261
303
|
Allowed values: `150 - 1080`
|
|
262
304
|
|
|
305
|
+
- **`fluent`**:
|
|
306
|
+
**Supported with Agents created with V3 Pro Avatars. Always enabled for V4 Avatars.**
|
|
307
|
+
Allowed values:
|
|
308
|
+
`true` - Fluent streaming (one video for Idle/Talking states)
|
|
309
|
+
`false` - Legacy streaming mode (2 video elements)
|
|
310
|
+
|
|
263
311
|
## ✴️ See it in Action
|
|
264
312
|
|
|
265
|
-
Explore our demo repository on GitHub to see the Agents SDK in action!
|
|
313
|
+
Explore our demo repository on GitHub to see the Agents SDK in action!
|
|
266
314
|
This repository features a sample project crafted in Vanilla JavaScript and Vite, utilizing the Agents SDK to help you get started swiftly.
|
|
267
315
|
|
|
268
316
|
[GitHub Demo Repository](https://github.com/de-id/Agents-SDK-Demo)
|