@d-id/client-sdk 3.0.0-staging.414 → 3.0.0-staging.416

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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/index-DCAt0P7O.js +2062 -0
  4. package/dist/index.d.ts +3525 -0
  5. package/dist/index.js +1 -1
  6. package/dist/index.umd.cjs +13 -13
  7. package/dist/{index-DBWnR72S.js → livekit-client.esm-QkbCKsng.js} +6234 -8269
  8. package/dist/livekit-manager-Cj0YXe2U.js +557 -0
  9. package/package.json +33 -9
  10. package/dist/livekit-manager-BM3JMzT5.js +0 -531
  11. package/dist/src/api/agents.d.ts +0 -18
  12. package/dist/src/api/apiClient.d.ts +0 -11
  13. package/dist/src/api/apiClient.test.d.ts +0 -1
  14. package/dist/src/api/knowledge.d.ts +0 -15
  15. package/dist/src/api/streams/index.d.ts +0 -1
  16. package/dist/src/api/streams/streamApi.d.ts +0 -3
  17. package/dist/src/api/streams/streamApi.test.d.ts +0 -1
  18. package/dist/src/api/streams/streamsApiV2.d.ts +0 -5
  19. package/dist/src/auth/get-auth-header.d.ts +0 -5
  20. package/dist/src/auth/get-auth-header.test.d.ts +0 -1
  21. package/dist/src/config/consts.d.ts +0 -3
  22. package/dist/src/config/environment.d.ts +0 -5
  23. package/dist/src/errors/base-error.d.ts +0 -182
  24. package/dist/src/errors/chat/chat-creation-failed.d.ts +0 -30
  25. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +0 -35
  26. package/dist/src/errors/errors.test.d.ts +0 -1
  27. package/dist/src/errors/http-error.d.ts +0 -74
  28. package/dist/src/errors/index.d.ts +0 -9
  29. package/dist/src/errors/network-error.d.ts +0 -72
  30. package/dist/src/errors/request-meta.d.ts +0 -12
  31. package/dist/src/errors/stream-error.d.ts +0 -37
  32. package/dist/src/errors/validation-error.d.ts +0 -67
  33. package/dist/src/errors/ws-error.d.ts +0 -34
  34. package/dist/src/index.d.ts +0 -20
  35. package/dist/src/public-api.test.d.ts +0 -1
  36. package/dist/src/services/agent-manager/connect-to-manager.d.ts +0 -19
  37. package/dist/src/services/agent-manager/connect-to-manager.test.d.ts +0 -1
  38. package/dist/src/services/agent-manager/index.d.ts +0 -64
  39. package/dist/src/services/agent-manager/index.test.d.ts +0 -1
  40. package/dist/src/services/analytics/mixpanel.d.ts +0 -22
  41. package/dist/src/services/analytics/mixpanel.test.d.ts +0 -1
  42. package/dist/src/services/analytics/timestamp-tracker.d.ts +0 -15
  43. package/dist/src/services/chat/index.d.ts +0 -10
  44. package/dist/src/services/chat/index.test.d.ts +0 -1
  45. package/dist/src/services/chat/intial-messages.d.ts +0 -3
  46. package/dist/src/services/chat/intial-messages.test.d.ts +0 -1
  47. package/dist/src/services/socket-manager/index.d.ts +0 -12
  48. package/dist/src/services/socket-manager/message-queue.d.ts +0 -12
  49. package/dist/src/services/socket-manager/message-queue.test.d.ts +0 -1
  50. package/dist/src/services/streaming-manager/advanced.test.d.ts +0 -1
  51. package/dist/src/services/streaming-manager/business-flows.test.d.ts +0 -5
  52. package/dist/src/services/streaming-manager/common.d.ts +0 -101
  53. package/dist/src/services/streaming-manager/data-channel-handlers.d.ts +0 -3
  54. package/dist/src/services/streaming-manager/disconnect.test.d.ts +0 -5
  55. package/dist/src/services/streaming-manager/edge-cases.test.d.ts +0 -1
  56. package/dist/src/services/streaming-manager/factory.d.ts +0 -13
  57. package/dist/src/services/streaming-manager/factory.test.d.ts +0 -1
  58. package/dist/src/services/streaming-manager/index.d.ts +0 -5
  59. package/dist/src/services/streaming-manager/livekit-manager.d.ts +0 -10
  60. package/dist/src/services/streaming-manager/livekit-manager.test.d.ts +0 -1
  61. package/dist/src/services/streaming-manager/stats/av-sync.d.ts +0 -3
  62. package/dist/src/services/streaming-manager/stats/av-sync.test.d.ts +0 -1
  63. package/dist/src/services/streaming-manager/stats/poll.d.ts +0 -16
  64. package/dist/src/services/streaming-manager/stats/report.d.ts +0 -19
  65. package/dist/src/services/streaming-manager/stats/report.test.d.ts +0 -1
  66. package/dist/src/services/streaming-manager/webrtc-core.test.d.ts +0 -1
  67. package/dist/src/services/streaming-manager/webrtc-manager.d.ts +0 -12
  68. package/dist/src/services/streaming-manager/webrtc-utils.test.d.ts +0 -5
  69. package/dist/src/test-utils/factories/agent-manager.factory.d.ts +0 -3
  70. package/dist/src/test-utils/factories/agent.factory.d.ts +0 -4
  71. package/dist/src/test-utils/factories/agents-api.factory.d.ts +0 -1
  72. package/dist/src/test-utils/factories/analytics.factory.d.ts +0 -1
  73. package/dist/src/test-utils/factories/chat.factory.d.ts +0 -1
  74. package/dist/src/test-utils/factories/index.d.ts +0 -8
  75. package/dist/src/test-utils/factories/socket-manager.factory.d.ts +0 -1
  76. package/dist/src/test-utils/factories/stream-api.factory.d.ts +0 -1
  77. package/dist/src/test-utils/factories/streaming-manager.factory.d.ts +0 -4
  78. package/dist/src/types/auth.d.ts +0 -95
  79. package/dist/src/types/entities/agents/agent.d.ts +0 -202
  80. package/dist/src/types/entities/agents/chat.d.ts +0 -476
  81. package/dist/src/types/entities/agents/index.d.ts +0 -3
  82. package/dist/src/types/entities/agents/manager.d.ts +0 -897
  83. package/dist/src/types/entities/avatar.d.ts +0 -21
  84. package/dist/src/types/entities/index.d.ts +0 -3
  85. package/dist/src/types/entities/knowledge/document.d.ts +0 -31
  86. package/dist/src/types/entities/knowledge/index.d.ts +0 -4
  87. package/dist/src/types/entities/knowledge/knowledge.d.ts +0 -56
  88. package/dist/src/types/entities/knowledge/record.d.ts +0 -24
  89. package/dist/src/types/entities/knowledge/retrival.d.ts +0 -9
  90. package/dist/src/types/face-rect.d.ts +0 -6
  91. package/dist/src/types/index.d.ts +0 -6
  92. package/dist/src/types/stream/api/clip.d.ts +0 -122
  93. package/dist/src/types/stream/api/index.d.ts +0 -2
  94. package/dist/src/types/stream/api/talk.d.ts +0 -77
  95. package/dist/src/types/stream/data-channel.d.ts +0 -16
  96. package/dist/src/types/stream/index.d.ts +0 -4
  97. package/dist/src/types/stream/rtc.d.ts +0 -125
  98. package/dist/src/types/stream/stream.d.ts +0 -856
  99. package/dist/src/types/stream/streams-v2.d.ts +0 -28
  100. package/dist/src/types/stream-script.d.ts +0 -138
  101. package/dist/src/types/voice/stt.d.ts +0 -16
  102. package/dist/src/types/voice/tts.d.ts +0 -238
  103. package/dist/src/utils/agent.d.ts +0 -8
  104. package/dist/src/utils/analytics.d.ts +0 -31
  105. package/dist/src/utils/analytics.test.d.ts +0 -1
  106. package/dist/src/utils/chat.d.ts +0 -4
  107. package/dist/src/utils/content-parser.d.ts +0 -35
  108. package/dist/src/utils/content-parser.test.d.ts +0 -1
  109. package/dist/src/utils/defer.d.ts +0 -7
  110. package/dist/src/utils/error-analytics.d.ts +0 -4
  111. package/dist/src/utils/error-analytics.test.d.ts +0 -1
  112. package/dist/src/utils/index.d.ts +0 -3
  113. package/dist/src/utils/retry-operation.d.ts +0 -38
  114. package/dist/src/utils/stream-end.d.ts +0 -5
  115. package/dist/src/utils/stream-end.test.d.ts +0 -1
  116. package/dist/src/utils/tool-calls.d.ts +0 -27
  117. package/dist/src/utils/tool-calls.test.d.ts +0 -1
  118. package/dist/src/utils/user-context.d.ts +0 -15
  119. package/dist/src/utils/user-context.test.d.ts +0 -1
  120. package/dist/src/version.d.ts +0 -7
@@ -0,0 +1,3525 @@
1
+ /**
2
+ * An agent's profile, as the Agents API returns it.
3
+ *
4
+ * The SDK fetches it once while {@link createAgentManager} runs and exposes it as
5
+ * {@link AgentManager.agent}, so everything here is available before
6
+ * {@link AgentManager.connect | connect()} — which is what makes it useful for rendering the agent
7
+ * before the video exists. The fields are the agent's configuration, whether it was set in D-ID Studio
8
+ * or through the Agents API; most of them are for the application to use, and each one below says
9
+ * where the SDK itself reads it.
10
+ *
11
+ * @see [Get an agent](https://docs.d-id.com/reference/agent-get)
12
+ * @category Agent Manager
13
+ */
14
+ export declare interface Agent {
15
+ /** Id of the agent: the same value passed to {@link createAgentManager}. */
16
+ id: string;
17
+ /** Id of the D-ID account that owns the agent. Set by the Agents API. */
18
+ owner_id?: string;
19
+ /** The agent's display name. */
20
+ name?: string;
21
+ /** `'public'` when the agent is configured for public access; omitted otherwise. */
22
+ access?: 'public';
23
+ /** URL of the agent's still image. Use it as the poster of your video element before
24
+ * {@link AgentManager.connect | connect()} has a stream to show. */
25
+ thumbnail?: string;
26
+ /**
27
+ * The greeting lines configured for the agent.
28
+ *
29
+ * The SDK never speaks them by itself: pass one to {@link AgentManager.speak | speak()} once
30
+ * the agent is connected if you want the agent to open the conversation. Check what your own
31
+ * agent does first — an Expressive (V4) session's server side may greet on its own, in which
32
+ * case speaking a greeting as well says it twice.
33
+ */
34
+ greetings?: string[];
35
+ /**
36
+ * Suggested opening questions to offer the user.
37
+ *
38
+ * The SDK surfaces the same array as {@link AgentManager.starterMessages | starterMessages}.
39
+ */
40
+ starter_message?: string[];
41
+ /**
42
+ * URL of the agent's looping idle video.
43
+ *
44
+ * Show it while the agent is not speaking: put it on your video element's `src` when
45
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} reports `STOP`.
46
+ */
47
+ idle_video?: string;
48
+ /**
49
+ * The knowledge base attached to the agent, when it has one.
50
+ *
51
+ * Its presence is what tells you the agent can cite sources; the citations themselves arrive on
52
+ * each answer as {@link Message.matches | matches}.
53
+ */
54
+ knowledge?: {
55
+ /**
56
+ * Id of the knowledge base.
57
+ *
58
+ * The SDK sends it with every rating made by {@link AgentManager.rate | rate()}, and it is
59
+ * the {@link RetrievalMetadata.knowledge_id | knowledge_id} of the citations on an answer.
60
+ */
61
+ id: string;
62
+ /** The embedding model the knowledge base was indexed with. The SDK does not act on it. */
63
+ embedder?: {
64
+ /** Whether that embedding model covers only a limited set of languages, so knowledge
65
+ * written in another language may not be retrieved well. */
66
+ is_limited_language?: boolean;
67
+ };
68
+ };
69
+ /**
70
+ * The avatar the agent is built on.
71
+ *
72
+ * Its `type` is the single most important field on an agent: it decides which transport the
73
+ * session uses and therefore which SDK features work. See {@link AgentAvatar}.
74
+ */
75
+ avatar: AgentAvatar;
76
+ /**
77
+ * Whether vision is enabled for the agent.
78
+ *
79
+ * Exposed so an application can decide whether to offer the camera; the SDK does not read it,
80
+ * and publishing a camera stream is an Expressive (V4) feature — see
81
+ * {@link AgentManager.publishCameraStream | publishCameraStream()}.
82
+ */
83
+ vision?: {
84
+ /** `true` when the agent is configured to use the user's camera. */
85
+ enabled: boolean;
86
+ };
87
+ /**
88
+ * The end-of-call feedback form configured for the agent.
89
+ *
90
+ * The SDK does not read it: render your own form from it and submit the result with
91
+ * {@link AgentManager.submitFeedback | submitFeedback()}. See
92
+ * {@link EndOfCallFeedbackConfig}.
93
+ */
94
+ end_of_call_feedback?: EndOfCallFeedbackConfig;
95
+ /** Whether the agent has triggers configured. The SDK does not act on them. */
96
+ triggers_available?: boolean;
97
+ /** Settings that change how D-ID's own surfaces present the agent. */
98
+ advanced_settings?: {
99
+ /**
100
+ * Whether the SDK logs its streaming lifecycle to the browser console.
101
+ *
102
+ * When it is enabled the SDK turns debug logging on for every visitor, whatever
103
+ * {@link AgentManagerOptions.debug | debug} was passed to {@link createAgentManager}.
104
+ */
105
+ ui_debug_mode?: boolean;
106
+ /**
107
+ * Account the agent's rendering VM is billed to. D-ID internal; kept in the declarations
108
+ * for D-ID's own applications, hidden from the reference.
109
+ *
110
+ * @hidden
111
+ */
112
+ vm_account_id?: string;
113
+ /** Whether the embedding UI should show closed captions. The SDK does not act on it. */
114
+ closed_captions_enabled?: boolean;
115
+ };
116
+ /**
117
+ * Feature-flag targeting context for the account this agent belongs to.
118
+ *
119
+ * Used by D-ID's own applications; not part of the SDK contract and may change without notice.
120
+ */
121
+ ld_context?: {
122
+ /** Key identifying the context. */
123
+ key: string;
124
+ /** Hashed form of the key. */
125
+ hash_key: string;
126
+ /** The plan group the account falls into. */
127
+ plan_group: string;
128
+ };
129
+ }
130
+
131
+ /**
132
+ * What the agent is doing right now, for driving the application's UI.
133
+ *
134
+ * The argument of
135
+ * {@link AgentManagerCallbacks.onAgentActivityStateChange | onAgentActivityStateChange}. Expressive
136
+ * (V4) agents move through all four states; Talks (V2) and Clips (V3) agents only alternate between
137
+ * {@link AgentActivityState.Talking | TALKING} and {@link AgentActivityState.Idle | IDLE}, and only
138
+ * on fluent streams.
139
+ *
140
+ * @category Callbacks & Events
141
+ */
142
+ export declare enum AgentActivityState {
143
+ /** The agent is doing nothing and is waiting for the user — the conversational turn has ended. */
144
+ Idle = "IDLE",
145
+ /**
146
+ * The agent is working on an answer that has not started streaming yet.
147
+ *
148
+ * Expressive (V4) only: set when a turn starts and when the user's speech has just been
149
+ * transcribed. Use it for a typing or thinking indicator.
150
+ */
151
+ Loading = "LOADING",
152
+ /** The agent's video has started; the agent is speaking. */
153
+ Talking = "TALKING",
154
+ /**
155
+ * The agent is running one or more tool calls.
156
+ *
157
+ * Expressive (V4) only: set when a tool call starts, and returned to after the agent finishes
158
+ * speaking while any call is still outstanding (for example a client tool waiting on the user).
159
+ * The individual calls are reported by
160
+ * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}.
161
+ */
162
+ ToolActive = "TOOL_ACTIVE"
163
+ }
164
+
165
+ /**
166
+ * The avatar an agent speaks through: its rendering tier and the language of its voice.
167
+ *
168
+ * The value of {@link Agent.avatar}. Its `type` is the single most important field on an agent: it
169
+ * decides which transport the session uses and therefore which SDK features work.
170
+ *
171
+ * @category Agent Manager
172
+ */
173
+ export declare interface AgentAvatar {
174
+ /**
175
+ * The kind of avatar: {@link AvatarType.Talk | talk} for Talks (V2), {@link AvatarType.Clip | clip}
176
+ * for Clips (V3), {@link AvatarType.Expressive | expressive} for Expressive (V4).
177
+ *
178
+ * Talks (V2) and Clips (V3) agents stream over WebRTC and receive their events on the
179
+ * notifications web socket; Expressive (V4) agents connect to a real-time session instead, which
180
+ * is what makes the microphone, camera, client tool and data-channel methods of
181
+ * {@link AgentManager} available.
182
+ *
183
+ * Either an {@link AvatarType} member or its string value — `AvatarType.Talk` and `'talk'` are
184
+ * both accepted, so an {@link Agent} restored from your own storage does not have to import the
185
+ * enum.
186
+ */
187
+ type: `${AvatarType}`;
188
+ /** The voice the agent speaks with. */
189
+ voice?: {
190
+ /**
191
+ * Language of the configured voice. The SDK reports it in analytics; it does not change how
192
+ * the session behaves.
193
+ */
194
+ language?: string;
195
+ };
196
+ }
197
+
198
+ /**
199
+ * A live connection to one agent: its profile, its chat, and the video stream it answers on.
200
+ *
201
+ * Created by {@link createAgentManager}. Nothing happens on the wire until
202
+ * {@link AgentManager.connect | connect()} resolves; after that
203
+ * {@link AgentManager.chat | chat()} makes the agent answer with its own LLM and
204
+ * {@link AgentManager.speak | speak()} makes it say exactly what you give it. Call
205
+ * {@link AgentManager.disconnect | disconnect()} when the user leaves.
206
+ *
207
+ * Two properties, {@link AgentManager.agent | agent} and
208
+ * {@link AgentManager.starterMessages | starterMessages}, are readable as soon as the manager
209
+ * exists; everything else is a method. Some methods work only with some avatar types: each one
210
+ * says so, and {@link AgentAvatar} is where the session's tier is read from.
211
+ *
212
+ * The manager's own state is readable at any time:
213
+ * {@link AgentManager.getChatMode | getChatMode()},
214
+ * {@link AgentManager.getConnectionState | getConnectionState()} and
215
+ * {@link AgentManager.getSessionInfo | getSessionInfo()} answer with what the matching callback
216
+ * last reported, so nothing has to be mirrored in application state.
217
+ *
218
+ * Every method that reaches the Agents API can reject with an {@link HttpError} when the request
219
+ * comes back non-2xx, or a {@link NetworkError} when it never reaches the server; the individual
220
+ * `@throws` entries below name the errors that are specific to each method.
221
+ *
222
+ * @category Agent Manager
223
+ */
224
+ export declare interface AgentManager {
225
+ /**
226
+ * The agent this manager is connected to, as the Agents API returned it.
227
+ *
228
+ * Fetched once while the manager is created, so it is available before
229
+ * {@link AgentManager.connect | connect()}. Useful for rendering the agent's name, thumbnail
230
+ * and {@link Agent.idle_video | idle_video}. See {@link Agent}.
231
+ *
232
+ * Read-only: the property cannot be reassigned, and the SDK never replaces it — the manager
233
+ * talks to the agent it was created for, for its whole life.
234
+ */
235
+ readonly agent: Agent;
236
+ /**
237
+ * Returns the kind of stream the current session negotiated.
238
+ *
239
+ * @returns {@link StreamType.Fluent} for a fluent stream (one video for the idle and talking
240
+ * states), {@link StreamType.Legacy} for the two-element legacy mode, or `undefined` before
241
+ * {@link AgentManager.connect | connect()} has established a session.
242
+ */
243
+ getStreamType(): StreamType | undefined;
244
+ /**
245
+ * Returns whether the current stream supports interrupting the agent mid-answer.
246
+ *
247
+ * True on a fluent stream — a Clips (V3) agent built on a Pro avatar, or any Expressive (V4)
248
+ * agent — once connected. This says the stream supports interrupting at all;
249
+ * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange} says whether
250
+ * interrupting is allowed right now.
251
+ *
252
+ * @returns `true` when {@link AgentManager.interrupt | interrupt()} can do anything.
253
+ */
254
+ isInterruptAvailable(): boolean;
255
+ /**
256
+ * The agent's starter messages.
257
+ *
258
+ * Suggested openers to offer the user as buttons; empty when the agent defines none. Available
259
+ * before {@link AgentManager.connect | connect()}.
260
+ *
261
+ * Read-only, and a copy of {@link Agent.starter_message} rather than the same array, so
262
+ * sorting or filtering a local copy of it cannot change what
263
+ * {@link AgentManager.agent | agent} reports.
264
+ */
265
+ readonly starterMessages: readonly string[];
266
+ /**
267
+ * Fetches a short-lived token for the D-ID speech-to-text service.
268
+ *
269
+ * The SDK sends the request whenever it is called, connected or not; the service decides
270
+ * whether to issue a token for the agent.
271
+ *
272
+ * @returns The {@link SttTokenResponse} for this agent.
273
+ * @throws {@link HttpError} When the service does not answer with a token, or the request comes
274
+ * back non-2xx for any other reason.
275
+ * @throws {@link NetworkError} When the request never reaches the server.
276
+ */
277
+ getSttToken(): Promise<SttTokenResponse>;
278
+ /**
279
+ * Returns the chat mode in effect right now.
280
+ *
281
+ * The same value {@link AgentManagerCallbacks.onModeChange | onModeChange} last reported, and
282
+ * the one every mode guard in the SDK reads. It is not always the mode that was asked for: the
283
+ * server can answer {@link AgentManager.connect | connect()} with a different mode, which the
284
+ * manager adopts, and a failed connection leaves the session in
285
+ * {@link ChatMode.Maintenance | Maintenance}. Use it instead of mirroring `onModeChange` in
286
+ * your own state.
287
+ *
288
+ * @returns The current {@link ChatMode}; before {@link AgentManager.connect | connect()}, the
289
+ * mode the manager was created with ({@link ChatMode.Functional} by default).
290
+ * @example
291
+ * ```ts
292
+ * if (agentManager.getChatMode() === 'maintenance') {
293
+ * showBanner('The agent is temporarily unavailable.');
294
+ * }
295
+ * ```
296
+ */
297
+ getChatMode(): ChatMode;
298
+ /**
299
+ * Returns the connection state the manager last reported.
300
+ *
301
+ * The same value
302
+ * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} was last
303
+ * called with, so a component that mounts after the session is up can read the state instead of
304
+ * waiting for the next change.
305
+ *
306
+ * @returns The current {@link ConnectionState}; {@link ConnectionState.New | 'new'} before the
307
+ * first {@link AgentManager.connect | connect()}.
308
+ * @example
309
+ * ```ts
310
+ * const canChat = agentManager.getConnectionState() === 'connected';
311
+ * ```
312
+ */
313
+ getConnectionState(): ConnectionState;
314
+ /**
315
+ * Returns the ids of the session that is open, for support and for your own logs.
316
+ *
317
+ * The same {@link StreamCreatedInfo} that
318
+ * {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated} delivered for this session.
319
+ *
320
+ * @returns The open session's `streamId`, `sessionId` and `agentId`, or `undefined` before
321
+ * {@link AgentManager.connect | connect()} and after
322
+ * {@link AgentManager.disconnect | disconnect()}.
323
+ * @example
324
+ * ```ts
325
+ * const session = agentManager.getSessionInfo();
326
+ * console.log('session', session?.sessionId, 'stream', session?.streamId);
327
+ * ```
328
+ */
329
+ getSessionInfo(): StreamCreatedInfo | undefined;
330
+ /**
331
+ * Opens a new session with the agent: a new WebRTC connection, a new web socket and a new chat.
332
+ *
333
+ * Resolves once the connection reaches {@link ConnectionState.Connected | 'connected'}, by
334
+ * which point {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} has been called
335
+ * with the media stream to render.
336
+ *
337
+ * One session at a time: while a call is still in flight a second call returns that same
338
+ * promise rather than opening a second session, which is what makes it safe in a React
339
+ * StrictMode effect. Once a session exists it rejects instead — call
340
+ * {@link AgentManager.disconnect | disconnect()} first to start a fresh conversation, or
341
+ * {@link AgentManager.reconnect | reconnect()} to keep the current one. A call that joins an
342
+ * operation a {@link AgentManager.disconnect | disconnect()} later cancels resolves without a
343
+ * session open; read {@link AgentManager.getConnectionState | getConnectionState()} for what
344
+ * happened.
345
+ *
346
+ * @returns Resolves when the agent is connected and ready.
347
+ * @throws {@link ValidationError} When a session is already open, or when
348
+ * {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} was not supplied and the
349
+ * current {@link ChatMode} streams video — which a
350
+ * {@link AgentManager.changeMode | changeMode()} out of a text-only mode can bring about.
351
+ * @throws {@link HttpError} When creating the stream or the chat comes back non-2xx — a client
352
+ * key that is not authorized for the agent or the calling domain, or an account out of
353
+ * credits. The SDK tries the initialization up to three times first, except on `429` and on an
354
+ * out-of-credits response.
355
+ * @throws {@link NetworkError} When those requests never reach the server.
356
+ * @example
357
+ * ```ts
358
+ * await agentManager.connect();
359
+ * ```
360
+ */
361
+ connect(): Promise<void>;
362
+ /**
363
+ * Reopens the stream when the session expires, and continues the conversation on the same chat.
364
+ *
365
+ * The chat id normally does not change, so the agent keeps its context. It starts a new stream
366
+ * — including after the server ended the previous one deliberately — rather than resuming the
367
+ * old one. On Expressive (V4) agents the transport is asked to reconnect first; if that fails
368
+ * the SDK falls back to a disconnect and a fresh connect, which starts a new chat id.
369
+ *
370
+ * One session-opening operation runs at a time, teardown included, so this and
371
+ * {@link AgentManager.connect | connect()} cannot interleave — call one or the other rather
372
+ * than racing them. A `connect()` that joins this one continues the existing chat, so
373
+ * {@link AgentManagerCallbacks.onNewChat | onNewChat} does not fire for it.
374
+ *
375
+ * @returns Resolves when the new stream is connected.
376
+ * @throws {@link ValidationError} When a {@link AgentManager.connect | connect()} is still in
377
+ * flight; wait for it to settle first.
378
+ * @throws {@link HttpError} When creating the new stream comes back non-2xx.
379
+ * @throws {@link NetworkError} When that request never reaches the server.
380
+ */
381
+ reconnect(): Promise<void>;
382
+ /**
383
+ * Closes the existing connection and chat with the agent: the stream and the web socket.
384
+ *
385
+ * Call it when the user leaves the page or the conversation, so the session does not keep
386
+ * running. After it resolves, {@link AgentManager.connect | connect()} is needed before the
387
+ * agent can be used again.
388
+ *
389
+ * @returns Resolves once everything is closed.
390
+ */
391
+ disconnect(): Promise<void>;
392
+ /**
393
+ * Publishes a microphone audio track to the session so the agent can hear the user.
394
+ *
395
+ * Call it after {@link AgentManager.connect | connect()} to enable voice input. Expressive (V4)
396
+ * agents only; on Talks (V2) and Clips (V3) agents, and before `connect()`, the returned
397
+ * promise rejects with a {@link ValidationError}.
398
+ *
399
+ * @param stream - A `MediaStream` whose audio track is published to the session.
400
+ * @returns Resolves once the track is published.
401
+ * @throws {@link ValidationError} When the session is not an Expressive (V4) one, or
402
+ * {@link AgentManager.connect | connect()} has not run yet.
403
+ * @example
404
+ * ```ts
405
+ * const micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
406
+ * await agentManager.publishMicrophoneStream(micStream);
407
+ * ```
408
+ */
409
+ publishMicrophoneStream(stream: MediaStream): Promise<void>;
410
+ /**
411
+ * Stops and removes the currently published microphone track from the session.
412
+ *
413
+ * The counterpart of {@link AgentManager.publishMicrophoneStream | publishMicrophoneStream()} —
414
+ * use it to mute the user for the rest of the session. Expressive (V4) agents only; on Talks
415
+ * (V2) and Clips (V3) agents, and when nothing is published, it resolves without doing
416
+ * anything.
417
+ *
418
+ * @returns Resolves once the track is removed.
419
+ * @example
420
+ * ```ts
421
+ * await agentManager.unpublishMicrophoneStream();
422
+ * ```
423
+ */
424
+ unpublishMicrophoneStream(): Promise<void>;
425
+ /**
426
+ * Swaps the live microphone track without unpublishing it.
427
+ *
428
+ * Use it when the user picks a different input device: the publication is preserved — its
429
+ * LiveKit publication id (SID) and SSRC stay the same, though the `MediaStreamTrack` id
430
+ * changes — so the server sees continuous audio across the swap rather than a stop and a
431
+ * restart. Rejects with a plain `Error` from the transport when there is no active publication
432
+ * — fall back to {@link AgentManager.publishMicrophoneStream | publishMicrophoneStream()} in
433
+ * that case. Expressive (V4) agents only; on Talks (V2) and Clips (V3) agents, and before
434
+ * {@link AgentManager.connect | connect()}, the returned promise rejects with a
435
+ * {@link ValidationError}.
436
+ *
437
+ * @param track - The audio track to send from now on.
438
+ * @returns Resolves once the transport has switched to the new track.
439
+ * @throws {@link ValidationError} When the session is not an Expressive (V4) one, or
440
+ * {@link AgentManager.connect | connect()} has not run yet.
441
+ */
442
+ replaceMicrophoneTrack(track: MediaStreamTrack): Promise<void>;
443
+ /**
444
+ * Publishes a camera video track to the session so the agent can see the user.
445
+ *
446
+ * Call it after {@link AgentManager.connect | connect()} to enable vision. Expressive (V4)
447
+ * agents only; on Talks (V2) and Clips (V3) agents, and before `connect()`, the returned
448
+ * promise rejects with a {@link ValidationError}.
449
+ *
450
+ * @param stream - A `MediaStream` whose video track is published to the session.
451
+ * @returns Resolves once the track is published.
452
+ * @throws {@link ValidationError} When the session is not an Expressive (V4) one, or
453
+ * {@link AgentManager.connect | connect()} has not run yet.
454
+ */
455
+ publishCameraStream(stream: MediaStream): Promise<void>;
456
+ /**
457
+ * Stops and removes the currently published camera track from the session.
458
+ *
459
+ * Call it to disable vision. Expressive (V4) agents only; on Talks (V2) and Clips (V3) agents,
460
+ * and when nothing is published, it resolves without doing anything.
461
+ *
462
+ * @returns Resolves once the track is removed.
463
+ */
464
+ unpublishCameraStream(): Promise<void>;
465
+ /**
466
+ * Sends a message to the agent and gets a streamed video based on its answer (LLM).
467
+ *
468
+ * The answer arrives through {@link AgentManagerCallbacks.onNewMessage | onNewMessage} — first
469
+ * as `partial` chunks, then as the full `answer` — while the video plays it. The chat is
470
+ * created on the first call if the session does not have one yet.
471
+ *
472
+ * @param userMessage - The user's message text to send to the agent.
473
+ * @returns The {@link ChatResponse} for this turn.
474
+ * @throws {@link ValidationError} When the message is empty or too long, when the chat mode has
475
+ * chat disabled or is in maintenance, or when the manager is not connected yet.
476
+ * @throws {@link ChatCreationFailed} On Talks (V2) and Clips (V3) agents, when the session has
477
+ * no chat yet and the Agents API answers the creation request without one.
478
+ * @throws {@link HttpError} On Talks (V2) and Clips (V3) agents, and in
479
+ * {@link ChatMode.Playground}, when the message request comes back non-2xx. Expressive (V4)
480
+ * agents send the message over the data channel instead, so no HTTP request is made.
481
+ * @throws {@link NetworkError} On Talks (V2) and Clips (V3) agents, and in
482
+ * {@link ChatMode.Playground}, when that request never reaches the server.
483
+ * @example
484
+ * ```ts
485
+ * const chat = await agentManager.chat('What is the distance to the moon?');
486
+ * ```
487
+ */
488
+ chat(userMessage: string): Promise<ChatResponse>;
489
+ /**
490
+ * Rates one of the agent's answers in the chat, for future analytics and insights.
491
+ *
492
+ * Pass `rateId` to change a rating the user already gave instead of adding another.
493
+ *
494
+ * Works on every avatar type. On an Expressive (V4) session an answer that arrived over the
495
+ * data channel without a server id is given a locally generated one, which D-ID's records
496
+ * cannot be matched against — rate the answers whose ids came from the server.
497
+ *
498
+ * @param messageId - Id of the message being rated.
499
+ * @param score - 1 for a positive rating, -1 for a negative one.
500
+ * @param rateId - Id of an existing rating to update; omit to create a new one.
501
+ * @returns The created or updated {@link Rating}.
502
+ * @throws {@link ValidationError} When no chat has started, or when no message with that id is
503
+ * in the transcript.
504
+ * @throws {@link HttpError} When the rating request comes back non-2xx.
505
+ * @throws {@link NetworkError} When the rating request never reaches the server.
506
+ */
507
+ rate(messageId: string, score: 1 | -1, rateId?: string): Promise<Rating>;
508
+ /**
509
+ * Removes a rating the user gave to an answer in the chat.
510
+ *
511
+ * @param id - Id of the rating to remove, as returned by
512
+ * {@link AgentManager.rate | rate()}.
513
+ * @returns The {@link Rating} that was deleted.
514
+ * @throws {@link ValidationError} When no chat has started.
515
+ * @throws {@link HttpError} When the delete request comes back non-2xx.
516
+ * @throws {@link NetworkError} When the delete request never reaches the server.
517
+ */
518
+ deleteRate(id: string): Promise<Rating>;
519
+ /**
520
+ * Submits end-of-call feedback for the whole conversation.
521
+ *
522
+ * Separate from {@link AgentManager.rate | rate()}, which scores a single answer. Collect it
523
+ * when the user ends the call, using the agent's end-of-call feedback configuration.
524
+ *
525
+ * Every avatar type. The agent must have end-of-call feedback switched on
526
+ * ({@link Agent.end_of_call_feedback}, {@link EndOfCallFeedbackConfig.enabled | enabled}) —
527
+ * the Agents API rejects the request otherwise, so read the configuration before offering the
528
+ * form. A second submission for the same conversation replaces the first.
529
+ *
530
+ * @param rating - The user's score for the conversation: 1, 2, 3, 4 or 5. The Agents API
531
+ * rejects anything else, whole numbers outside the range and fractions alike.
532
+ * @param answer - The user's free-text answer to the follow-up question, when one was asked.
533
+ * @returns The stored {@link SubmitFeedbackResponse}.
534
+ * @throws {@link ValidationError} When no chat has started.
535
+ * @throws {@link HttpError} When the feedback request comes back non-2xx — including a `400`
536
+ * when the agent does not have end-of-call feedback enabled.
537
+ * @throws {@link NetworkError} When the feedback request never reaches the server.
538
+ */
539
+ submitFeedback(rating: 1 | 2 | 3 | 4 | 5, answer?: string): Promise<SubmitFeedbackResponse>;
540
+ /**
541
+ * Makes the agent stream back a video based on the text or audio file you provide.
542
+ *
543
+ * Unlike {@link AgentManager.chat | chat()} the agent's LLM is not involved, so this is how you
544
+ * script greetings and canned lines. Pass a plain string as a shorthand for a text script. See
545
+ * {@link SpeakScript}, {@link TextStreamScript} and {@link AudioStreamScript}. Text
546
+ * scripts also accept an optional `sentiment`, for Expressive (V4) agents only; if the
547
+ * requested sentiment is not supported by the agent, the default sentiment is used.
548
+ *
549
+ * @see [Create a video stream](https://docs.d-id.com/reference/createvideoagentstream) — the request
550
+ * sent for Talks (V2) and Clips (V3) agents.
551
+ * @see [Control the Agent](https://docs.d-id.com/docs/livekit-commands) — the `did.speak` command
552
+ * sent over the data channel for Expressive (V4) agents.
553
+ * @param payload - A text or audio script, or a string treated as the text to speak.
554
+ * @returns The {@link SpeakResponse} for the video that was produced, or the same
555
+ * response with `duration` `0` and an empty `videoId` when the call produced no discrete video
556
+ * — on Expressive (V4) agents, and in a text-only chat mode.
557
+ * @throws {@link ValidationError} When the manager is not connected to a stream yet.
558
+ * @throws {@link HttpError} On Talks (V2) and Clips (V3) agents, when the Agents API answers
559
+ * the request non-2xx. Expressive (V4) agents send the script over the data channel instead,
560
+ * so no HTTP request is made.
561
+ * @throws {@link NetworkError} On Talks (V2) and Clips (V3) agents, when that request never
562
+ * reaches the server.
563
+ * @example Text
564
+ * ```ts
565
+ * const speak = await agentManager.speak({
566
+ * type: 'text',
567
+ * input: "Hi! I'm Alice!",
568
+ * });
569
+ * ```
570
+ * @example Text with sentiment (Expressive (V4) agents)
571
+ * ```ts
572
+ * const speak = await agentManager.speak({
573
+ * type: 'text',
574
+ * input: "Hi! I'm Alice!",
575
+ * sentiment: 'friendly',
576
+ * });
577
+ * ```
578
+ * @example Audio file
579
+ * ```ts
580
+ * const speak = await agentManager.speak({
581
+ * type: 'audio',
582
+ * audio_url: 'https://www.yourwebsite.com/audio.mp3',
583
+ * });
584
+ * ```
585
+ */
586
+ speak(payload: SpeakScript | string): Promise<SpeakResponse>;
587
+ /**
588
+ * Switches the chat to another mode.
589
+ *
590
+ * Anything other than {@link ChatMode.Functional} disconnects the stream, since those modes do
591
+ * not produce video, which is why this is asynchronous: the returned promise resolves once that
592
+ * disconnect has finished. Switching *into* {@link ChatMode.Functional} disconnects it as well
593
+ * when the open session was built for a mode that skipped what a conversation needs — a
594
+ * {@link ChatMode.DirectPlayback} session has neither the notifications web socket the answer
595
+ * arrives on nor a chat to send to. Call {@link AgentManager.connect | connect()} again after
596
+ * a change that tore the session down. {@link AgentManagerCallbacks.onModeChange | onModeChange}
597
+ * fires once the change has been applied; passing the mode already in effect does nothing.
598
+ *
599
+ * @param mode - The {@link ChatMode} to switch to.
600
+ * @returns A promise resolved when the mode is in effect and any disconnect it caused has
601
+ * completed.
602
+ * @throws {@link ValidationError} Rejects on Expressive (V4) agents for {@link ChatMode.Off} and
603
+ * {@link ChatMode.DirectPlayback}, which those agents do not support.
604
+ */
605
+ changeMode(mode: ChatMode): Promise<void>;
606
+ /**
607
+ * Adds properties to every analytics event the SDK sends from now on.
608
+ *
609
+ * The same thing
610
+ * {@link AnalyticsOptions.additionalProperties | analytics.additionalProperties} does at
611
+ * creation time, for values you only learn later.
612
+ *
613
+ * Advanced. Calls merge, so a property sent twice takes the later value, and events already
614
+ * sent are not changed. It has no visible effect when analytics is switched off with
615
+ * {@link AnalyticsOptions.enabled | analytics.enabled} set to `false`, because nothing is sent
616
+ * at all.
617
+ *
618
+ * @param properties - A flat JSON object whose properties are added to every analytics event
619
+ * the SDK sends from now on.
620
+ */
621
+ enrichAnalytics(properties: Record<string, unknown>): void;
622
+ /**
623
+ * Interrupts the current video stream mid-playback, so the user can talk over the agent.
624
+ *
625
+ * Supported on a fluent stream — a Clips (V3) agent built on a Pro avatar, or any Expressive
626
+ * (V4) agent. It never throws: on every agent type it returns without doing anything when
627
+ * interrupting is not available for the session, when it is not allowed right now, and — on
628
+ * Talks (V2) and Clips (V3) agents — when the stream is not a fluent stream or no video is
629
+ * playing. Check {@link AgentManager.isInterruptAvailable | isInterruptAvailable()}
630
+ * before offering the control at all; on Expressive (V4) agents
631
+ * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange} tracks whether it
632
+ * is allowed right now.
633
+ *
634
+ * The interrupted message is marked as such in the next
635
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} — but only when an interrupt was
636
+ * actually sent. A call that finds nothing to interrupt leaves the message untouched and fires
637
+ * no callback.
638
+ *
639
+ * @param options - What caused the interruption, as an {@link InterruptOptions}: `text`,
640
+ * `audio`, `click` or `manual`. Optional — a stop button is the common case, so leaving it out
641
+ * means `{ type: 'click' }`. Expressive (V4) agents drop `text` interrupts, because the
642
+ * orchestrator does not cancel the in-flight answer for them.
643
+ * @example
644
+ * ```ts
645
+ * stopButton.onclick = () => agentManager.interrupt();
646
+ *
647
+ * // The user typed over the answer instead of pressing the button.
648
+ * agentManager.interrupt({ type: 'text' });
649
+ * ```
650
+ */
651
+ interrupt(options?: InterruptOptions): void;
652
+ /**
653
+ * Switches the speech-to-text language in the middle of a session.
654
+ *
655
+ * Expressive (V4) agents only, after {@link AgentManager.connect | connect()}; otherwise the
656
+ * returned promise rejects with a {@link ValidationError}.
657
+ *
658
+ * @param language - The language to transcribe in, as a name or a BCP-47 code — `"English"` or
659
+ * `"en-US"`.
660
+ * @returns Resolves once the new language has been sent to the agent. A room that has dropped
661
+ * since {@link AgentManager.connect | connect()} reports a {@link StreamError} through
662
+ * {@link AgentManagerCallbacks.onError | onError} and the promise still resolves.
663
+ * @throws {@link ValidationError} When the session is not an Expressive (V4) one, or
664
+ * {@link AgentManager.connect | connect()} has not run yet.
665
+ */
666
+ setSttLanguage(language: string): Promise<void>;
667
+ /**
668
+ * Sends a JSON payload to the agent over a data-channel topic.
669
+ *
670
+ * Use it for application-specific messages that are not speech, such as telling a presentation
671
+ * to change slide. Expressive (V4) agents only, after {@link AgentManager.connect | connect()};
672
+ * otherwise the returned promise rejects with a {@link ValidationError}.
673
+ *
674
+ * @param topic - Data-channel topic to send on. Either a {@link DataChannelTopic} member or
675
+ * its string value — `DataChannelTopic.Presentation` and `'did.presentation'` are both
676
+ * accepted. {@link DataChannelTopic} is exported from the package root and lists every topic
677
+ * this method accepts.
678
+ * @param payload - A plain object, sent as JSON.
679
+ * @returns Resolves once the payload has been sent. A room that has dropped since
680
+ * {@link AgentManager.connect | connect()} reports a {@link StreamError} through
681
+ * {@link AgentManagerCallbacks.onError | onError} and the promise still resolves.
682
+ * @throws {@link ValidationError} When the session is not an Expressive (V4) one, or
683
+ * {@link AgentManager.connect | connect()} has not run yet.
684
+ * @example
685
+ * ```ts
686
+ * import { DataChannelTopic } from '@d-id/client-sdk';
687
+ *
688
+ * await agentManager.sendDataChannelMessage(DataChannelTopic.Presentation, {
689
+ * type: 'navigate',
690
+ * slide: 3,
691
+ * });
692
+ * ```
693
+ */
694
+ sendDataChannelMessage(topic: `${DataChannelTopic}`, payload: Record<string, unknown>): Promise<void>;
695
+ /**
696
+ * Registers a handler for a client tool, run in the browser when the agent's LLM calls it.
697
+ *
698
+ * Expressive (V4) agents only: client tools travel on the real-time session's RPC channel,
699
+ * which Talks (V2) and Clips (V3) agents do not have. It throws a {@link ValidationError} on
700
+ * those rather than registering a handler the agent could never call. The check is on the
701
+ * agent, not on the connection, so it applies before
702
+ * {@link AgentManager.connect | connect()} too.
703
+ *
704
+ * The handler executes on the client and its result is returned to the LLM. Register the
705
+ * handlers before {@link AgentManager.connect | connect()} so the agent can call
706
+ * them from the moment the session starts; registering the same name again replaces the
707
+ * handler. Progress is reported through
708
+ * {@link AgentManagerCallbacks.onToolEvent | onToolEvent}.
709
+ *
710
+ * @param name - Name of the tool, which must match the one defined in the agent's
711
+ * configuration.
712
+ * @param handler - The function that runs when the agent calls the tool. It receives the
713
+ * arguments the LLM produced and returns a JSON string of at most 15 KiB — the limit is the
714
+ * transport's, not the SDK's, and a larger result fails the call. See
715
+ * {@link ClientToolHandler}.
716
+ * @throws {@link ValidationError} When the agent is a Talks (V2) or Clips (V3) one.
717
+ */
718
+ registerClientTool(name: string, handler: ClientToolHandler): void;
719
+ /**
720
+ * Removes a previously registered client tool handler.
721
+ *
722
+ * After this the agent's calls to that tool fail rather than reaching your code. Unlike
723
+ * {@link AgentManager.registerClientTool | registerClientTool()} it never throws — a name that
724
+ * was never registered, and any agent type, is a no-op — so it is safe in a cleanup path.
725
+ *
726
+ * @param name - Name of the tool whose handler should be removed.
727
+ */
728
+ unregisterClientTool(name: string): void;
729
+ }
730
+
731
+ /**
732
+ * Handlers the SDK calls as the connection, the video stream and the chat change state.
733
+ *
734
+ * Pass the object as {@link AgentManagerOptions.callbacks}. Every handler is optional in the type,
735
+ * but {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} is required in practice
736
+ * for any chat mode that streams video — without it there is nothing to render the agent into, and
737
+ * {@link createAgentManager} rejects. Every handler is called from the SDK's own event handling,
738
+ * so keep the work inside short.
739
+ *
740
+ * The handlers fall into four groups: the connection
741
+ * ({@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange},
742
+ * {@link AgentManagerCallbacks.onConnectivityStateChange | onConnectivityStateChange},
743
+ * {@link AgentManagerCallbacks.onError | onError}), the video stream
744
+ * ({@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady},
745
+ * {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated},
746
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange},
747
+ * {@link AgentManagerCallbacks.onAgentActivityStateChange | onAgentActivityStateChange},
748
+ * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange}), the chat
749
+ * ({@link AgentManagerCallbacks.onNewChat | onNewChat}, {@link AgentManagerCallbacks.onNewMessage | onNewMessage},
750
+ * {@link AgentManagerCallbacks.onModeChange | onModeChange}) and client tools
751
+ * ({@link AgentManagerCallbacks.onToolEvent | onToolEvent},
752
+ * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}). A handler that
753
+ * lives outside the object can be typed with an indexed access such as
754
+ * `AgentManagerCallbacks['onNewMessage']`.
755
+ *
756
+ * The whole object is captured once, by {@link createAgentManager}, and the manager works from its
757
+ * own copy — assigning a handler to the object you passed afterwards has no effect, and neither
758
+ * does replacing {@link AgentManagerOptions.callbacks | options.callbacks}. Give each handler a
759
+ * stable identity that reads the current state rather than closing over it: in React, keep the
760
+ * state in a ref and read `ref.current` inside the handler.
761
+ *
762
+ * @category Callbacks & Events
763
+ */
764
+ export declare interface AgentManagerCallbacks {
765
+ /**
766
+ * Called every time the connection to the agent's stream changes state.
767
+ *
768
+ * Triggered by {@link AgentManager.connect | connect()},
769
+ * {@link AgentManager.reconnect | reconnect()} and
770
+ * {@link AgentManager.disconnect | disconnect()}.
771
+ * {@link ConnectionState.Connected | 'connected'} is the point at which
772
+ * {@link AgentManager.chat | chat()} and {@link AgentManager.speak | speak()} can be called.
773
+ *
774
+ * @param state - The state just reached: one of `new`, `connecting`, `connected`, `completed`,
775
+ * `disconnecting`, `disconnected`, `closed` or `fail`. See {@link ConnectionState}.
776
+ * @param reason - Why that state was reached. On `disconnected` it is a
777
+ * {@link StreamEndReason} value when the server ended the stream on purpose, which is how you
778
+ * tell a deliberate end from a dropped connection. Talks (V2) and Clips (V3) agents report
779
+ * only `ok`, `unknown_error`, `network_issue` and `inactivity`; `message_limit`, `time_limit`
780
+ * and `ended_by_agent` come from Expressive (V4) agents. A close reason the SDK does not
781
+ * recognise is forwarded as-is, so compare `reason` against the enum rather than parsing it;
782
+ * any other value is an opaque transport diagnostic.
783
+ * {@link AgentManager.reconnect | reconnect()} still works after a deliberate end; it starts a
784
+ * new stream rather than resuming the old one.
785
+ * @example
786
+ * ```ts
787
+ * onConnectionStateChange(state, reason) {
788
+ * console.log('onConnectionStateChange(): ', state, reason);
789
+ *
790
+ * if (state === 'connected') {
791
+ * console.log("I'm ready to go!");
792
+ * }
793
+ * }
794
+ * ```
795
+ */
796
+ onConnectionStateChange?: (state: ConnectionState, reason?: string) => void;
797
+ /**
798
+ * Called when the streamed video starts and stops, so the video element can switch source.
799
+ *
800
+ * Triggered by {@link AgentManager.chat | chat()} and {@link AgentManager.speak | speak()}. On
801
+ * `STOP` point the element at the agent's idle video ({@link Agent.idle_video}); on `START` put
802
+ * the stream handed to {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} back
803
+ * on it.
804
+ *
805
+ * On a **legacy** stream this is the only "is the agent speaking" signal — see
806
+ * {@link AgentManagerCallbacks.onAgentActivityStateChange | onAgentActivityStateChange} for
807
+ * which stream types report which.
808
+ *
809
+ * @param state - {@link StreamingState.Start | START} while the agent is speaking,
810
+ * {@link StreamingState.Stop | STOP} once it has finished.
811
+ * @example
812
+ * ```ts
813
+ * onVideoStateChange(state) {
814
+ * console.log('onVideoStateChange(): ', state);
815
+ *
816
+ * if (state === 'STOP') {
817
+ * videoElement.srcObject = undefined;
818
+ * videoElement.src = agentManager.agent.idle_video ?? '';
819
+ * } else {
820
+ * videoElement.src = '';
821
+ * videoElement.srcObject = srcObject;
822
+ * }
823
+ * }
824
+ * ```
825
+ */
826
+ onVideoStateChange?: (state: StreamingState) => void;
827
+ /**
828
+ * Called with the media stream carrying the agent's video and audio.
829
+ *
830
+ * This is the one callback a video session cannot work without: assign the value to the
831
+ * `srcObject` of your `<video>` element, and keep a reference to it, because
832
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} has to put it back
833
+ * after the idle video has been shown. Triggered by
834
+ * {@link AgentManager.connect | connect()}, {@link AgentManager.reconnect | reconnect()} and
835
+ * {@link AgentManager.disconnect | disconnect()}.
836
+ *
837
+ * Optional only for the chat modes that never stream video — {@link ChatMode.TextOnly},
838
+ * {@link ChatMode.Playground} and {@link ChatMode.Maintenance} — so a text-only application
839
+ * does not have to supply a stub. {@link createAgentManager} rejects with a
840
+ * {@link ValidationError} when it is missing in any other mode — {@link ChatMode.Off} and
841
+ * {@link ChatMode.DirectPlayback} included, since those create no chat but still stream video.
842
+ * {@link AgentManager.connect | connect()} checks it again against the mode in
843
+ * effect then, so a manager created in a text-only mode and later moved into a video mode with
844
+ * {@link AgentManager.changeMode | changeMode()} rejects rather than opening a stream with
845
+ * nothing to render it into.
846
+ *
847
+ * @param srcObject - The live media stream to render.
848
+ * @example
849
+ * ```ts
850
+ * let srcObject;
851
+ *
852
+ * const callbacks = {
853
+ * onSrcObjectReady(value) {
854
+ * videoElement.srcObject = value;
855
+ * srcObject = value;
856
+ * },
857
+ * };
858
+ * ```
859
+ */
860
+ onSrcObjectReady?: (srcObject: MediaStream) => void;
861
+ /**
862
+ * Called with the whole chat transcript every time a message is added or updated.
863
+ *
864
+ * Triggered by {@link AgentManager.chat | chat()}, by {@link AgentManager.speak | speak()} for
865
+ * text scripts, and as the agent's answer streams in. It also fires once while the manager is
866
+ * created, with whatever {@link AgentManagerOptions.initialMessages | initialMessages} were
867
+ * given, and again on every {@link AgentManager.connect | connect()} after the first — both
868
+ * with type `answer`. The array is a fresh copy on each call, oldest message first; every
869
+ * {@link Message} carries an `id`, a `role` of `user` or `assistant` (the agent), its `content`
870
+ * and a `createdAt` timestamp.
871
+ *
872
+ * @param messages - The chat so far.
873
+ * @param type - `partial` while the agent's answer is still streaming in, `answer` for the full
874
+ * answer spoken in the streamed video, `user` when the message just added is the user's own
875
+ * (a message passed to {@link AgentManager.chat | chat()}, or a transcribed utterance).
876
+ * @example
877
+ * ```ts
878
+ * onNewMessage(messages, type) {
879
+ * console.log(messages, type);
880
+ *
881
+ * if (type === 'answer') {
882
+ * console.log(messages[messages.length - 1].content);
883
+ * }
884
+ * }
885
+ * ```
886
+ */
887
+ onNewMessage?: (messages: Message[], type: 'answer' | 'partial' | 'user') => void;
888
+ /**
889
+ * Called when a chat is created for this session.
890
+ *
891
+ * A chat is created while {@link AgentManager.connect | connect()} runs, and lazily on the
892
+ * first {@link AgentManager.chat | chat()} when none exists yet. Store the id if you want to
893
+ * correlate the conversation with your own records.
894
+ *
895
+ * On Talks (V2) and Clips (V3) agents the id comes from the Agents API. On Expressive (V4)
896
+ * agents the SDK derives it from the session id as `cht_<sessionId>`, which is the same id the
897
+ * Agents API stores the conversation under — so it correlates with D-ID's own records either
898
+ * way.
899
+ *
900
+ * @param chatId - Id of the chat that was just created.
901
+ */
902
+ onNewChat?: (chatId: string) => void;
903
+ /**
904
+ * Called when the chat mode changes.
905
+ *
906
+ * Fires after {@link AgentManager.changeMode | changeMode()}, and when the server answers with
907
+ * a different mode than the one requested (for example {@link ChatMode.Maintenance}).
908
+ *
909
+ * @param mode - The {@link ChatMode} now in effect.
910
+ */
911
+ onModeChange?: (mode: ChatMode) => void;
912
+ /**
913
+ * Called when the quality of the user's internet connection changes.
914
+ *
915
+ * The state is derived from jitter-buffer delay and freeze count on the video stream for
916
+ * Talks (V2) and Clips (V3) agents, and from LiveKit's reported connection quality for
917
+ * Expressive (V4) agents, so it reflects what the session is actually getting rather than the
918
+ * browser's online flag.
919
+ *
920
+ * @param state - {@link ConnectivityState.Strong | STRONG},
921
+ * {@link ConnectivityState.Weak | WEAK} or {@link ConnectivityState.Unknown | UNKNOWN}.
922
+ * @example
923
+ * ```ts
924
+ * onConnectivityStateChange(state) {
925
+ * console.log('onConnectivityStateChange(): ', state);
926
+ * }
927
+ * ```
928
+ */
929
+ onConnectivityStateChange?: (state: ConnectivityState) => void;
930
+ /**
931
+ * Called when the SDK fails, so the application can surface the problem.
932
+ *
933
+ * Receives failures from the Agents API requests, the stream and the web socket — an
934
+ * {@link HttpError} when a request comes back non-2xx, a {@link NetworkError} when it never
935
+ * reaches the server, a {@link WsError} when the web socket itself fails, and also
936
+ * {@link ChatModeDowngraded} and {@link StreamError}. Two errors do not arrive here:
937
+ * {@link ValidationError} and {@link ChatCreationFailed} are thrown to whoever called the
938
+ * method ({@link AgentManager.chat | chat()}, {@link AgentManager.speak | speak()} and the
939
+ * rating methods), so they surface as a rejected promise rather than through this callback.
940
+ *
941
+ * @param error - The error that occurred. Narrow it with {@link isDIDError} and branch on
942
+ * {@link BaseError.kind | kind}; {@link BaseError.toJson | toJson()} is what to log.
943
+ * @param errorData - Where the failure happened, as an {@link ErrorContext}: the endpoint and
944
+ * method for a failed request, the session or stream id for a failure on the stream. Every
945
+ * field is optional and nothing else is passed — in particular not the request body, which
946
+ * carries the end user's own message.
947
+ * @example
948
+ * ```ts
949
+ * onError(error, errorData) {
950
+ * reportToYourErrorService({
951
+ * ...(isDIDError(error) ? error.toJson() : { message: error.message }),
952
+ * ...errorData,
953
+ * });
954
+ * }
955
+ * ```
956
+ */
957
+ onError?: (error: Error, errorData?: ErrorContext) => void;
958
+ /**
959
+ * Called when the agent moves between idle, loading, talking and running a tool.
960
+ *
961
+ * Use it to drive a typing indicator or to disable input while the agent is busy. The full set
962
+ * of states is reported for Expressive (V4) agents only. Talks (V2) and Clips (V3) agents
963
+ * report just {@link AgentActivityState.Talking | Talking} and
964
+ * {@link AgentActivityState.Idle | Idle}, and only on fluent streams, plus a final
965
+ * {@link AgentActivityState.Idle | Idle} when the connection closes.
966
+ *
967
+ * It is the authoritative "is the agent speaking" signal wherever it reports at all — an
968
+ * Expressive (V4) session or a fluent stream — because it comes from the agent rather than from
969
+ * the video track, so it also covers thinking and tool calls, which produce no video.
970
+ * On a **legacy** stream it reports nothing, so use
971
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} there; that is the
972
+ * branch every consumer otherwise writes for itself, keyed on
973
+ * {@link AgentManager.getStreamType | getStreamType()}.
974
+ *
975
+ * @param state - The {@link AgentActivityState} the agent has moved to.
976
+ */
977
+ onAgentActivityStateChange?: (state: AgentActivityState) => void;
978
+ /**
979
+ * Called once per session when the stream has been created on the server.
980
+ *
981
+ * Fires before the connection reaches {@link ConnectionState.Connected | 'connected'}. The ids
982
+ * are useful when correlating a session with D-ID support or with your own logs.
983
+ *
984
+ * @param stream - The new stream's `streamId`, `sessionId` and `agentId`.
985
+ */
986
+ onStreamCreated?: (stream: StreamCreatedInfo) => void;
987
+ /**
988
+ * Called when the agent starts, finishes or fails a tool call.
989
+ *
990
+ * Expressive (V4) agents only. The handler takes two arguments and returns nothing: `event`,
991
+ * one of {@link ToolCallEvent.Started}, {@link ToolCallEvent.Done} or
992
+ * {@link ToolCallEvent.Error}; and `data`, the payload that event narrows to —
993
+ * {@link ToolCallStartedPayload}, {@link ToolCallDonePayload} or
994
+ * {@link ToolCallErrorPayload} respectively. The signature that does the narrowing is on
995
+ * {@link ToolEventCallback}, with an example handler.
996
+ */
997
+ onToolEvent?: ToolEventCallback;
998
+ /**
999
+ * Called when the agent becomes interruptible, or stops being interruptible.
1000
+ *
1001
+ * Expressive (V4) agents only, and about whether interrupting is allowed *right now*: it goes
1002
+ * `false` while a `blocking` client tool call is outstanding, because the agent is suspended
1003
+ * waiting for it, and back to `true` when the call finishes. That is a different question from
1004
+ * {@link AgentManager.isInterruptAvailable | isInterruptAvailable()}, which says whether
1005
+ * the session supports interrupting at all. Use this one to enable or disable an interrupt
1006
+ * button. Talks (V2) and Clips (V3) agents never report a change.
1007
+ */
1008
+ onInterruptibleChange?: (
1009
+ /** `true` while there is something to interrupt, `false` while there is not. */
1010
+ interruptible: boolean) => void;
1011
+ /**
1012
+ * Called whenever the set of tool calls running in the session changes.
1013
+ *
1014
+ * Expressive (V4) agents only. Fires with an empty array on disconnect, so a spinner driven by
1015
+ * this callback always clears. Each entry is a {@link RunningToolCall}.
1016
+ */
1017
+ onRunningToolCallsChange?: (
1018
+ /** Every tool call running right now, empty when none is. */
1019
+ calls: readonly RunningToolCall[]) => void;
1020
+ }
1021
+
1022
+ /**
1023
+ * Everything {@link createAgentManager} needs to reach an agent and report back to the application.
1024
+ *
1025
+ * {@link AgentManagerOptions.auth | auth} and {@link AgentManagerOptions.callbacks | callbacks} are
1026
+ * required; the rest have defaults that suit a browser application talking to D-ID production.
1027
+ *
1028
+ * {@link createAgentManager} reads the object once, at creation, and never writes to it: the
1029
+ * manager works from its own copy, so one options object can create two managers, and a property
1030
+ * you read back afterwards is still the one you set. The same means a handler assigned to
1031
+ * {@link AgentManagerOptions.callbacks | callbacks} after the manager exists is not picked up —
1032
+ * give the callback a stable identity and dispatch inside it instead.
1033
+ *
1034
+ * @category Agent Manager
1035
+ */
1036
+ export declare interface AgentManagerOptions {
1037
+ /**
1038
+ * Credentials used for every request the SDK makes on the application's behalf.
1039
+ *
1040
+ * Use `{ type: 'key', clientKey }` in a browser: a client key is scoped to one agent and to
1041
+ * the domains you allowed, so it is the only shape that is safe to ship in a page. See
1042
+ * {@link Auth}.
1043
+ */
1044
+ auth: Auth;
1045
+ /**
1046
+ * Handlers the SDK calls as the connection, the video stream and the chat change state.
1047
+ *
1048
+ * See {@link AgentManagerCallbacks}.
1049
+ * {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} is what connects the
1050
+ * streamed media to your video element, so every chat mode that streams video needs it. The
1051
+ * handlers are captured at creation, so replacing one on this object later has no effect.
1052
+ */
1053
+ callbacks: AgentManagerCallbacks;
1054
+ /**
1055
+ * How the agent answers: with a streamed video, as text only, or not at all.
1056
+ *
1057
+ * See {@link ChatMode}. It can be changed later with
1058
+ * {@link AgentManager.changeMode | changeMode()}. {@link ChatMode.Off} and
1059
+ * {@link ChatMode.DirectPlayback} are supported on Talks (V2) and Clips (V3) agents only.
1060
+ *
1061
+ * @default ChatMode.Functional
1062
+ * @throws {@link ValidationError} From {@link createAgentManager}, when the agent is Expressive
1063
+ * (V4) and the mode is {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}.
1064
+ */
1065
+ mode?: ChatMode;
1066
+ /**
1067
+ * Base URL of the D-ID Agents API.
1068
+ *
1069
+ * Advanced. Points the SDK at another D-ID environment. Production applications do not set
1070
+ * this. Every REST call the manager makes — agent lookup, chat, ratings, stream creation — is
1071
+ * addressed against it.
1072
+ *
1073
+ * @defaultValue D-ID's production Agents API.
1074
+ */
1075
+ baseURL?: string;
1076
+ /**
1077
+ * URL of the D-ID notifications web socket.
1078
+ *
1079
+ * Advanced. Points the SDK at another D-ID environment. Production applications do not set
1080
+ * this. Only opened in the chat modes that stream the agent's answer, so it has no effect in
1081
+ * {@link ChatMode.DirectPlayback | DirectPlayback} or {@link ChatMode.Off | Off}.
1082
+ *
1083
+ * @defaultValue D-ID's production notifications web socket.
1084
+ */
1085
+ wsURL?: string;
1086
+ /**
1087
+ * Whether the SDK logs its streaming lifecycle to the browser console.
1088
+ *
1089
+ * It is also switched on for everyone when the agent's `ui_debug_mode` advanced setting is
1090
+ * enabled, regardless of the value passed here.
1091
+ *
1092
+ * @default false
1093
+ */
1094
+ debug?: boolean;
1095
+ /**
1096
+ * Whether the stream is created in verbose mode, which logs more server-side detail.
1097
+ *
1098
+ * Independent of {@link AgentManagerOptions.debug | debug}: this one is sent to the streaming
1099
+ * service rather than controlling console output. Expressive (V4) agents only.
1100
+ *
1101
+ * @default false
1102
+ */
1103
+ verbose?: boolean;
1104
+ /**
1105
+ * What the SDK reports about the session, and where it goes.
1106
+ *
1107
+ * See {@link AnalyticsOptions}. Reporting is on unless you turn it off with
1108
+ * `analytics: { enabled: false }`.
1109
+ */
1110
+ analytics?: AnalyticsOptions;
1111
+ /**
1112
+ * Your own identifier for the end user.
1113
+ *
1114
+ * It is stored in `localStorage`, sent as part of the `type: 'key'` authorization header and
1115
+ * attached to analytics, so the same visitor is recognised across page loads. When it is
1116
+ * omitted the SDK generates an id and reuses it.
1117
+ */
1118
+ externalId?: string;
1119
+ /**
1120
+ * Transport settings applied when the stream is created.
1121
+ *
1122
+ * See {@link StreamOptions}. Talks (V2) and Clips (V3) agents only. Expressive (V4) agents
1123
+ * manage transport settings automatically.
1124
+ */
1125
+ streamOptions?: StreamOptions;
1126
+ /**
1127
+ * Messages the chat starts with, for example a transcript restored from your own storage.
1128
+ *
1129
+ * They are delivered to {@link AgentManagerCallbacks.onNewMessage | onNewMessage} so the UI can
1130
+ * render them. On Talks (V2) and Clips (V3) agents they are also sent as context with the next
1131
+ * {@link AgentManager.chat | chat()} request. See {@link Message}.
1132
+ *
1133
+ * A row from your own storage is enough: {@link Message.parts | parts} and
1134
+ * {@link Message.createdAt | createdAt} are optional, and the SDK builds the parts from
1135
+ * `content` with {@link parseMessageParts} for every message that arrives without them, so a
1136
+ * transcript restored from the text alone still renders. A non-empty `parts` array is kept as
1137
+ * given.
1138
+ *
1139
+ * @example Restoring rows that carry only the message text
1140
+ * ```ts
1141
+ * const initialMessages = stored.map(({ id, role, content }) => ({ id, role, content }));
1142
+ * ```
1143
+ */
1144
+ initialMessages?: Message[];
1145
+ /**
1146
+ * Whether the server keeps the chat so it can be resumed in a later session.
1147
+ *
1148
+ * Without persistence a chat lives only as long as the connection.
1149
+ * {@link AgentManager.reconnect | reconnect()} normally continues the same chat either way —
1150
+ * see the caveat there for Expressive (V4) agents.
1151
+ *
1152
+ * Off unless you set it, on every agent type.
1153
+ *
1154
+ * @default false
1155
+ */
1156
+ persistentChat?: boolean;
1157
+ }
1158
+
1159
+ /**
1160
+ * Amazon provider details: the provider type and the requested voice id.
1161
+ *
1162
+ * Pass it as {@link TextStreamScript.provider} to have Amazon synthesise the text. It is the one
1163
+ * provider with no `voice_config`: the voice is selected by `voice_id` alone.
1164
+ *
1165
+ * @category Voice
1166
+ */
1167
+ export declare interface AmazonTtsProvider {
1168
+ /**
1169
+ * Selects Amazon. Either {@link Providers.Amazon} or its string value `'amazon'` — both are
1170
+ * accepted, so the provider object can be written inline without importing the enum.
1171
+ */
1172
+ type: `${Providers.Amazon}`;
1173
+ /**
1174
+ * Id of the voice to speak with, from D-ID's list of Amazon voices.
1175
+ *
1176
+ * @example "Joanna"
1177
+ * @see [Amazon voices](https://docs.d-id.com/docs/tts-amazon)
1178
+ */
1179
+ voice_id: string;
1180
+ }
1181
+
1182
+ /**
1183
+ * What the SDK reports about the session, and where it goes.
1184
+ *
1185
+ * Pass it as {@link AgentManagerOptions.analytics}; every field is optional, and leaving the whole
1186
+ * object out reports to D-ID's own project.
1187
+ *
1188
+ * The SDK posts an event to Mixpanel for each step of a session — connect, reconnect and
1189
+ * disconnect, every message sent and answered, every {@link AgentManager.speak | speak()}, mode
1190
+ * change, rating, feedback, tool call, video start and stop, interrupt and error. Each event
1191
+ * carries the agent id, the visitor id derived from
1192
+ * {@link AgentManagerOptions.externalId | externalId}, the page URL, the screen size, the user
1193
+ * agent, the SDK version and whatever
1194
+ * {@link AnalyticsOptions.additionalProperties | additionalProperties} added. **Conversation text
1195
+ * is included too:** the agent's answer on `agent-message-received`, and the script on
1196
+ * `agent-speak`. Set {@link AnalyticsOptions.enabled | enabled: false} to send nothing at all.
1197
+ *
1198
+ * Events that fail to post are buffered in memory (at most 50) and retried when the tab comes back
1199
+ * online or becomes visible.
1200
+ *
1201
+ * @example Send the SDK's events to your own project, tagged with your plan
1202
+ * ```ts
1203
+ * const agentManager = await sdk.createAgentManager('agt_fumf1234', {
1204
+ * auth: { type: 'key', clientKey: 'YOUR_CLIENT_KEY' },
1205
+ * callbacks,
1206
+ * analytics: { mixpanelKey: 'YOUR_MIXPANEL_TOKEN', additionalProperties: { plan: 'pro' } },
1207
+ * });
1208
+ * ```
1209
+ * @category Agent Manager
1210
+ */
1211
+ export declare interface AnalyticsOptions {
1212
+ /**
1213
+ * Whether the SDK reports usage analytics at all. Set it to `false` to send nothing.
1214
+ *
1215
+ * @default true
1216
+ */
1217
+ enabled?: boolean;
1218
+ /**
1219
+ * Mixpanel project token the SDK's analytics events are sent to.
1220
+ *
1221
+ * Defaults to D-ID's own project. Set it to send the SDK's events to your Mixpanel project
1222
+ * instead.
1223
+ */
1224
+ mixpanelKey?: string;
1225
+ /**
1226
+ * Extra properties merged into every analytics event the SDK sends.
1227
+ *
1228
+ * A flat object — use it to tag events with your own identifiers. More properties can be added
1229
+ * later with {@link AgentManager.enrichAnalytics | enrichAnalytics()}. A `plan` property here
1230
+ * is also forwarded to the Agents API as end-user data when a Talks (V2) or Clips (V3) stream
1231
+ * is created.
1232
+ */
1233
+ additionalProperties?: Record<string, unknown>;
1234
+ }
1235
+
1236
+ /**
1237
+ * A script that makes the agent lip-sync an audio file you host, with no text-to-speech involved.
1238
+ *
1239
+ * The other payload {@link AgentManager.speak | speak()} accepts. Use it when the audio already
1240
+ * exists — a recording, or speech you synthesised yourself — instead of having a provider generate
1241
+ * it from text.
1242
+ *
1243
+ * @example Audio file
1244
+ * ```ts
1245
+ * const speak = await agentManager.speak({
1246
+ * type: 'audio',
1247
+ * audio_url: 'https://www.yourwebsite.com/audio.mp3',
1248
+ * });
1249
+ * ```
1250
+ * @category Speak & Scripts
1251
+ */
1252
+ export declare interface AudioStreamScript {
1253
+ /**
1254
+ * Which kind of script this is. Always `audio` for this variant; a
1255
+ * {@link TextStreamScript} carries `text` instead.
1256
+ */
1257
+ type: 'audio';
1258
+ /**
1259
+ * URL of the audio file the agent lip-syncs to.
1260
+ *
1261
+ * The URL has to be publicly reachable, since the file is fetched server-side rather than
1262
+ * uploaded from the browser. The file may be at most 15 MB.
1263
+ * @example "https://www.yourwebsite.com/audio.mp3"
1264
+ */
1265
+ audio_url: string;
1266
+ }
1267
+
1268
+ /**
1269
+ * The credentials {@link createAgentManager} accepts, as
1270
+ * {@link AgentManagerOptions.auth | options.auth}.
1271
+ *
1272
+ * Pick {@link ClientKeyAuth} (`{ type: 'key', clientKey }`) for anything that runs in a browser: it
1273
+ * is the only variant scoped to one agent and to the domains you allowed. {@link BearerToken} and
1274
+ * {@link BasicAuth} carry account-wide credentials and belong in a trusted environment. Whichever
1275
+ * you pass is used for every request the SDK makes — the REST calls, the video stream and the
1276
+ * notifications web socket.
1277
+ *
1278
+ * @category Authentication
1279
+ */
1280
+ export declare type Auth = BearerToken | BasicAuth | ClientKeyAuth;
1281
+
1282
+ /**
1283
+ * The kind of avatar an agent is built on, which is what decides how its video is produced.
1284
+ *
1285
+ * It is the `type` of the agent's avatar ({@link Agent.avatar}) and so determines which SDK
1286
+ * features a session has: {@link AvatarType.Talk | talk} is Talks (V2),
1287
+ * {@link AvatarType.Clip | clip} is Clips (V3), and {@link AvatarType.Expressive | expressive} is
1288
+ * Expressive (V4).
1289
+ *
1290
+ * @category Agent Manager
1291
+ */
1292
+ export declare enum AvatarType {
1293
+ /** A Clips (V3) agent: a pre-recorded presenter, driven by the D-ID Clips pipeline. */
1294
+ Clip = "clip",
1295
+ /** A Talks (V2) agent: a still photo animated to speak. */
1296
+ Talk = "talk",
1297
+ /**
1298
+ * An Expressive (V4) avatar: a real-time avatar that also supports microphone and camera
1299
+ * publishing, client tools and interruption.
1300
+ */
1301
+ Expressive = "expressive"
1302
+ }
1303
+
1304
+ /**
1305
+ * Azure OpenAI provider details: the provider type, the requested voice id and an optional
1306
+ * `voice_config` for style, rate and pitch.
1307
+ *
1308
+ * The same shape as {@link MicrosoftTtsProvider} — a `voice_id` and an optional
1309
+ * {@link VoiceConfigMicrosoft} as `voice_config` — with the `type` naming Azure OpenAI instead.
1310
+ *
1311
+ * @category Voice
1312
+ */
1313
+ export declare interface AzureOpenAiTtsProvider extends Omit<MicrosoftTtsProvider, 'type'> {
1314
+ /**
1315
+ * Selects Azure OpenAI. Either {@link Providers.AzureOpenAi} or its string value
1316
+ * `'azure-openai'` — both are accepted, so the provider object can be written inline without
1317
+ * importing the enum.
1318
+ */
1319
+ type: `${Providers.AzureOpenAi}`;
1320
+ }
1321
+
1322
+ /**
1323
+ * Base class of every error the SDK itself raises.
1324
+ *
1325
+ * Catching `BaseError` catches everything the SDK classified; branch on
1326
+ * {@link BaseError.kind | kind}, which is stable, rather than on the message, which is not.
1327
+ * Errors reach the application two ways, and each subclass says which applies: some are thrown to
1328
+ * the caller of the method, so they reject the promise it returned; others are handed to
1329
+ * {@link AgentManagerCallbacks.onError | onError} because no call of yours was in flight when they
1330
+ * happened. {@link HttpError} and {@link NetworkError} do both — the request that failed rejects,
1331
+ * and the callback is notified as well.
1332
+ *
1333
+ * Not everything that reaches the application is one of these. The streaming transport is the main
1334
+ * exception: a failure LiveKit raises inside a media call on an Expressive (V4) agent — no
1335
+ * microphone publication to replace, a room that is not connected — rejects with a plain `Error`,
1336
+ * and so do a few low-level guards inside {@link AgentManager.connect | connect()}, such as a
1337
+ * `livekit-client` package that is not installed, a transport the SDK does not recognise, or a
1338
+ * stream the server created without a session id. An unknown
1339
+ * {@link AgentManagerOptions.auth | auth} type is a plain `Error` too. So keep the
1340
+ * `else throw error` branch in a handler built on {@link isDIDError}.
1341
+ *
1342
+ * Subclasses: {@link HttpError}, {@link NetworkError}, {@link WsError}, {@link StreamError},
1343
+ * {@link ValidationError}, {@link ChatCreationFailed} and {@link ChatModeDowngraded}. When the
1344
+ * caught value is typed `unknown`, {@link isDIDError} narrows it to {@link DIDError}, the union of
1345
+ * those seven, so a `switch` on {@link BaseError.kind | kind} then narrows it to one class.
1346
+ *
1347
+ * @category Errors
1348
+ */
1349
+ export declare class BaseError extends Error {
1350
+ /**
1351
+ * Stable machine-readable code for this failure, and the value to branch on.
1352
+ *
1353
+ * Every subclass redeclares it as the literal it always carries, so a `switch` on `kind`
1354
+ * narrows a value {@link isDIDError} has recognized to that class: `'HttpError'` on
1355
+ * {@link HttpError}, `'NetworkError'` on {@link NetworkError}, `'WSError'` on
1356
+ * {@link WsError}, `'StreamError'` on {@link StreamError}, `'ValidationError'` on
1357
+ * {@link ValidationError}, `'ChatCreationFailed'` on {@link ChatCreationFailed} and
1358
+ * `'ChatModeDowngraded'` on {@link ChatModeDowngraded}. It stays a plain `string` here on
1359
+ * the base class: on a `BaseError` built directly it is whatever the caller passed, and
1360
+ * `'Error'` when nothing was. The Agents API's own classification of a failed request is
1361
+ * {@link HttpError.code | HttpError.code}, not this.
1362
+ */
1363
+ readonly kind: string;
1364
+ /**
1365
+ * The error or value that caused this one, when the SDK was wrapping something else.
1366
+ *
1367
+ * For a {@link NetworkError} this is the browser's own `fetch` rejection. It is not
1368
+ * serialized as-is: {@link BaseError.toJson | toJson()} takes only an `Error` cause's
1369
+ * message.
1370
+ */
1371
+ readonly originalError?: unknown | undefined;
1372
+ /**
1373
+ * Creates an SDK error. The SDK builds these itself; applications normally only catch them.
1374
+ *
1375
+ * @param message - Human-readable description of the failure, used as the `Error` message.
1376
+ * @param kind - Stable machine-readable code for the failure.
1377
+ * @param originalError - The underlying error or value this one wraps, when there is one.
1378
+ */
1379
+ constructor(message: string,
1380
+ /**
1381
+ * Stable machine-readable code for this failure, and the value to branch on.
1382
+ *
1383
+ * Every subclass redeclares it as the literal it always carries, so a `switch` on `kind`
1384
+ * narrows a value {@link isDIDError} has recognized to that class: `'HttpError'` on
1385
+ * {@link HttpError}, `'NetworkError'` on {@link NetworkError}, `'WSError'` on
1386
+ * {@link WsError}, `'StreamError'` on {@link StreamError}, `'ValidationError'` on
1387
+ * {@link ValidationError}, `'ChatCreationFailed'` on {@link ChatCreationFailed} and
1388
+ * `'ChatModeDowngraded'` on {@link ChatModeDowngraded}. It stays a plain `string` here on
1389
+ * the base class: on a `BaseError` built directly it is whatever the caller passed, and
1390
+ * `'Error'` when nothing was. The Agents API's own classification of a failed request is
1391
+ * {@link HttpError.code | HttpError.code}, not this.
1392
+ */
1393
+ kind?: string,
1394
+ /**
1395
+ * The error or value that caused this one, when the SDK was wrapping something else.
1396
+ *
1397
+ * For a {@link NetworkError} this is the browser's own `fetch` rejection. It is not
1398
+ * serialized as-is: {@link BaseError.toJson | toJson()} takes only an `Error` cause's
1399
+ * message.
1400
+ */
1401
+ originalError?: unknown | undefined);
1402
+ /**
1403
+ * Serializes the error into the JSON-safe {@link ErrorJson} payload for logging or reporting.
1404
+ *
1405
+ * The payload always carries {@link BaseError.kind | kind} and the message. The cause's message
1406
+ * is added only when {@link BaseError.originalError | originalError} is an `Error` and says
1407
+ * something the message does not, truncated to 256 characters; any other cause is dropped.
1408
+ * Subclasses extend the payload with the fields listed on their own pages.
1409
+ *
1410
+ * @returns The error as plain, JSON-serializable data.
1411
+ * @example An HttpError from a request that was refused
1412
+ * ```json
1413
+ * {
1414
+ * "kind": "InsufficientCreditsError",
1415
+ * "message": "Account has insufficient credits",
1416
+ * "httpStatus": 402,
1417
+ * "endpoint": "/agt_x/chat/cht_y",
1418
+ * "method": "POST"
1419
+ * }
1420
+ * ```
1421
+ * @example A NetworkError from a request that never left the browser
1422
+ * ```json
1423
+ * {
1424
+ * "kind": "NetworkError",
1425
+ * "message": "Network request failed",
1426
+ * "cause": "Failed to fetch",
1427
+ * "endpoint": "/agt_x/chat/cht_y",
1428
+ * "method": "POST",
1429
+ * "durationMs": 12,
1430
+ * "online": false,
1431
+ * "visibility": "visible"
1432
+ * }
1433
+ * ```
1434
+ */
1435
+ toJson(): ErrorJson;
1436
+ }
1437
+
1438
+ /**
1439
+ * HTTP basic credentials for the Agents API, given either pre-encoded or as a username and
1440
+ * password.
1441
+ *
1442
+ * Like {@link BearerToken} these are account-wide and belong in a trusted environment, never in a
1443
+ * client bundle. The SDK sends them as `Authorization: Basic <credentials>~<connectionId>`, where
1444
+ * the `token` form is used as the credentials as-is and the `username`/`password` form is
1445
+ * base64-encoded as `username:password` first; the trailing per-connection id is stripped by the
1446
+ * D-ID authorizer before the credentials are validated.
1447
+ *
1448
+ * @category Authentication
1449
+ */
1450
+ export declare type BasicAuth = {
1451
+ /**
1452
+ * Discriminator selecting this variant of {@link Auth}.
1453
+ */
1454
+ type: 'basic';
1455
+ /**
1456
+ * Credentials that are already base64-encoded, as `username:password`. Used as they
1457
+ * are, so they are not encoded a second time.
1458
+ */
1459
+ token: string;
1460
+ } | {
1461
+ /**
1462
+ * Discriminator selecting this variant of {@link Auth}.
1463
+ */
1464
+ type: 'basic';
1465
+ /**
1466
+ * The account's user name; base64-encoded with the password before it is sent.
1467
+ */
1468
+ username: string;
1469
+ /**
1470
+ * The account's password; base64-encoded with the user name before it is sent.
1471
+ */
1472
+ password: string;
1473
+ };
1474
+
1475
+ /**
1476
+ * A bearer token for the Agents API.
1477
+ *
1478
+ * Account-wide, so it is meant for a trusted environment — a server, a build step, an internal
1479
+ * tool. Anyone who reads the token can spend the account's credits, so do not ship one in a page
1480
+ * you serve to users; use {@link ClientKeyAuth} there. The SDK sends it as
1481
+ * `Authorization: Bearer <token>~<connectionId>`, appending a per-connection id the D-ID
1482
+ * authorizer strips before it validates the token.
1483
+ *
1484
+ * @category Authentication
1485
+ */
1486
+ export declare interface BearerToken {
1487
+ /**
1488
+ * Discriminator selecting this variant of {@link Auth}.
1489
+ */
1490
+ type: 'bearer';
1491
+ /**
1492
+ * The bearer token itself, sent in the `Authorization` header.
1493
+ */
1494
+ token: string;
1495
+ }
1496
+
1497
+ /**
1498
+ * A chat could not be created for the session.
1499
+ *
1500
+ * {@link AgentManager.chat | chat()} creates a chat on the first message when the session does not
1501
+ * have one yet; this error is thrown when that call comes back without one, so it rejects the
1502
+ * promise `chat()` returned and the user's message is not sent. It is not delivered to
1503
+ * {@link AgentManagerCallbacks.onError | onError} — catch it around `chat()`. A failing request
1504
+ * surfaces as {@link HttpError} or {@link NetworkError} instead; this error is the case where the
1505
+ * request succeeded but produced no chat.
1506
+ *
1507
+ * The message names the {@link ChatMode} in effect and whether a persistent chat was asked for, for
1508
+ * example `Failed to create persistent chat, mode: Functional`.
1509
+ * {@link BaseError.kind | kind} is `'ChatCreationFailed'`.
1510
+ *
1511
+ * @category Errors
1512
+ */
1513
+ export declare class ChatCreationFailed extends BaseError {
1514
+ /**
1515
+ * Always `'ChatCreationFailed'`. Branch on it to tell this failure from the other SDK errors.
1516
+ */
1517
+ readonly kind: 'ChatCreationFailed';
1518
+ }
1519
+
1520
+ /**
1521
+ * How the agent answers: with a streamed video, as text only, or not at all.
1522
+ *
1523
+ * Chosen with {@link AgentManagerOptions.mode | mode} and changed later with
1524
+ * {@link AgentManager.changeMode | changeMode()}, which reports the new value through
1525
+ * {@link AgentManagerCallbacks.onModeChange | onModeChange}. Switching to anything other than
1526
+ * {@link ChatMode.Functional} disconnects the stream, and switching *into*
1527
+ * {@link ChatMode.Functional} disconnects it too when the open session cannot carry a conversation
1528
+ * — call {@link AgentManager.connect | connect()} again after either.
1529
+ *
1530
+ * What the mode decides is narrower than it looks: whether a chat is created for the session, and
1531
+ * whether {@link AgentManager.connect | connect()} opens the notifications web socket — which is
1532
+ * exactly why a session built for one mode may not serve another. The video stream is established
1533
+ * in every mode, and every guard reads the mode the session is in at the time of the call, not the
1534
+ * one {@link createAgentManager} was given.
1535
+ *
1536
+ * The server can also answer with a different mode than the one asked for when the chat is created;
1537
+ * the SDK then adopts it and reports a {@link ChatModeDowngraded} error through
1538
+ * {@link AgentManagerCallbacks.onError | onError}.
1539
+ *
1540
+ * @category Chat
1541
+ */
1542
+ export declare enum ChatMode {
1543
+ /**
1544
+ * Chat and video: the agent answers questions with its own LLM, in a streamed video.
1545
+ *
1546
+ * The default when {@link AgentManagerOptions.mode | mode} is omitted, and the only mode a
1547
+ * session can be in while a stream is connected and chat is available at the same time:
1548
+ * {@link AgentManager.changeMode | changeMode()} to any other value disconnects the stream.
1549
+ */
1550
+ Functional = "Functional",
1551
+ /**
1552
+ * Text answers only: the chat works, but no video is produced.
1553
+ *
1554
+ * {@link AgentManager.chat | chat()} still returns answers through
1555
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}, and
1556
+ * {@link AgentManager.speak | speak()} adds a text script to the transcript but streams no
1557
+ * video: it resolves with a `duration` of `0` and an empty `videoId`.
1558
+ */
1559
+ TextOnly = "TextOnly",
1560
+ /**
1561
+ * The agent is unavailable: {@link AgentManager.chat | chat()} throws a
1562
+ * {@link ValidationError}.
1563
+ *
1564
+ * The SDK switches to it by itself when connecting fails after its retries, so a UI can show
1565
+ * that the agent is temporarily out of service; the server can also return it when a chat is
1566
+ * created. Like {@link ChatMode.TextOnly} it produces no video.
1567
+ */
1568
+ Maintenance = "Maintenance",
1569
+ /**
1570
+ * A text-only test conversation, used by the agent playground in D-ID Studio.
1571
+ *
1572
+ * Produces no video, and marks each chat request with a playground header so the Agents API
1573
+ * can treat it as a test. Chats in this mode always go over the Agents API, even for
1574
+ * Expressive (V4) agents, which otherwise chat over the data channel. Applications normally
1575
+ * use {@link ChatMode.Functional} or {@link ChatMode.TextOnly} instead.
1576
+ */
1577
+ Playground = "Playground",
1578
+ /**
1579
+ * Speak-only: no chat is created for the session, while video still streams.
1580
+ *
1581
+ * Talks (V2) and Clips (V3) agents only; {@link createAgentManager} and
1582
+ * {@link AgentManager.changeMode | changeMode()} reject it with a {@link ValidationError} for
1583
+ * Expressive (V4) agents.
1584
+ *
1585
+ * {@link AgentManager.chat | chat()} rejects with a {@link ValidationError} while this is the
1586
+ * mode, however the session arrived at it. {@link AgentManager.connect | connect()} also skips
1587
+ * the notifications web socket while it is in force. Use it when the application drives the
1588
+ * agent entirely through {@link AgentManager.speak | speak()} and never asks its LLM anything.
1589
+ * The stream keeps running only when this is the mode {@link createAgentManager} was given;
1590
+ * switching into it later with {@link AgentManager.changeMode | changeMode()} disconnects the
1591
+ * stream like any other non-{@link ChatMode.Functional} mode.
1592
+ */
1593
+ DirectPlayback = "DirectPlayback",
1594
+ /**
1595
+ * Chat is switched off: no chat is created for the session, while video still streams.
1596
+ *
1597
+ * Talks (V2) and Clips (V3) agents only; {@link createAgentManager} and
1598
+ * {@link AgentManager.changeMode | changeMode()} reject it with a {@link ValidationError} for
1599
+ * Expressive (V4) agents.
1600
+ *
1601
+ * {@link AgentManager.chat | chat()} rejects with a {@link ValidationError} while this is the
1602
+ * mode, exactly as in {@link ChatMode.DirectPlayback}. The one difference between the two is
1603
+ * the notifications web socket: this mode still opens it on a Talks (V2) or Clips (V3) agent,
1604
+ * where {@link ChatMode.DirectPlayback} skips it. As with {@link ChatMode.DirectPlayback}, the
1605
+ * stream keeps running only when this is the mode set at creation; switching into it later with
1606
+ * {@link AgentManager.changeMode | changeMode()} disconnects the stream.
1607
+ */
1608
+ Off = "Off"
1609
+ }
1610
+
1611
+ /**
1612
+ * The server put the session into a different chat mode from the one that was requested, and the
1613
+ * new mode cannot stream video.
1614
+ *
1615
+ * Raised while {@link AgentManager.connect | connect()} runs, when the chat the server created came
1616
+ * back in a mode other than the requested {@link AgentManagerOptions.mode | mode} and that mode is
1617
+ * not {@link ChatMode.Functional | Functional} — {@link ChatMode.TextOnly | TextOnly} or
1618
+ * {@link ChatMode.Maintenance | Maintenance}, for instance. The comparison only runs when `mode` was
1619
+ * set in the options, so a session that never asked for a mode never sees this error. The SDK
1620
+ * disconnects the stream it had just opened and `connect()` resolves anyway, so no video will play
1621
+ * and {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} will not fire again: the
1622
+ * session continues as a text chat.
1623
+ *
1624
+ * It is delivered to {@link AgentManagerCallbacks.onError | onError} and never thrown, so
1625
+ * `connect()` does not reject on it.
1626
+ * {@link AgentManagerCallbacks.onModeChange | onModeChange} fires with the new mode just before it.
1627
+ * Treat it as a signal to switch the interface to text, not as a connection failure.
1628
+ * {@link BaseError.kind | kind} is `'ChatModeDowngraded'`.
1629
+ *
1630
+ * @category Errors
1631
+ */
1632
+ export declare class ChatModeDowngraded extends BaseError {
1633
+ /**
1634
+ * Always `'ChatModeDowngraded'`. Branch on it to tell this failure from the other SDK errors.
1635
+ */
1636
+ readonly kind: 'ChatModeDowngraded';
1637
+ }
1638
+
1639
+ /**
1640
+ * What the Agents API answers a chat request with.
1641
+ *
1642
+ * Returned by {@link AgentManager.chat | chat()}. The SDK has already added the answer to the
1643
+ * transcript by the time you get it, so most applications render
1644
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} instead and use this only for the
1645
+ * fields that never reach a {@link Message}. Expressive (V4) agents chat over the data channel
1646
+ * rather than over the Agents API — except in {@link ChatMode.Playground} — so for them the
1647
+ * object is empty and the answer arrives through the callback.
1648
+ *
1649
+ * @category Chat
1650
+ */
1651
+ export declare interface ChatResponse {
1652
+ /**
1653
+ * The agent's answer.
1654
+ *
1655
+ * Empty or absent when the answer is delivered as it is generated instead, which is what
1656
+ * streaming modes do; the SDK then adds no message for it and the text arrives through
1657
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}.
1658
+ */
1659
+ result?: string;
1660
+ /**
1661
+ * The Agents API's own list of ids for the documents behind the answer. The SDK never reads it;
1662
+ * {@link ChatResponse.matches | matches} is what it keeps on the message.
1663
+ */
1664
+ documentIds?: string[];
1665
+ /**
1666
+ * The knowledge citations behind the answer.
1667
+ *
1668
+ * Copied onto the answer as {@link Message.matches | matches}.
1669
+ */
1670
+ matches?: RetrievalMetadata[];
1671
+ /**
1672
+ * The {@link ChatMode} the server handled the request in.
1673
+ *
1674
+ * It can differ from the mode that was asked for — see {@link ChatMode}.
1675
+ */
1676
+ chatMode?: ChatMode;
1677
+ /**
1678
+ * The retrieved context the answer was generated from.
1679
+ *
1680
+ * Copied onto the answer as {@link Message.context | context}.
1681
+ */
1682
+ context?: string;
1683
+ /** Id of the video generated for the answer, when the server reported one. */
1684
+ videoId?: string;
1685
+ }
1686
+
1687
+ /**
1688
+ * A client key for the Agents API — the credential to use in a browser.
1689
+ *
1690
+ * This is the one shape that is safe to ship in a page: a client key is scoped to a single agent
1691
+ * and only works from the domains allowed for it, so it cannot be reused elsewhere. Copy it from the
1692
+ * agent's Embed snippet, where it appears as `data-client-key`, or create one with the Agents API
1693
+ * (see the link below). The SDK sends it
1694
+ * as `Authorization: Client-Key <clientKey>.<externalId>_<connectionId>`, where the external id is
1695
+ * either {@link AgentManagerOptions.externalId | externalId} or a per-browser id the SDK keeps in
1696
+ * `localStorage`.
1697
+ *
1698
+ * @see [Create a client key](https://docs.d-id.com/reference/createclientkey)
1699
+ * @category Authentication
1700
+ */
1701
+ export declare interface ClientKeyAuth {
1702
+ /**
1703
+ * Discriminator selecting this variant of {@link Auth}.
1704
+ */
1705
+ type: 'key';
1706
+ /**
1707
+ * The client key: the `data-client-key` value from the agent's Embed snippet, or a key created with
1708
+ * the Agents API.
1709
+ */
1710
+ clientKey: string;
1711
+ }
1712
+
1713
+ /**
1714
+ * A client tool's implementation: the function that runs in the browser when the agent calls it.
1715
+ *
1716
+ * Register it with {@link AgentManager.registerClientTool | registerClientTool()}, under the tool
1717
+ * name defined in the agent's configuration. The SDK parses the arguments the agent's LLM produced
1718
+ * and passes them in; whatever the handler resolves with is sent back to the agent as the tool's
1719
+ * result. Throwing rejects the call, and the error message is forwarded to the agent. Expressive
1720
+ * (V4) agents only — {@link AgentManager.registerClientTool | registerClientTool()} throws a
1721
+ * {@link ValidationError} on a Talks (V2) or Clips (V3) agent.
1722
+ *
1723
+ * @param args - The arguments the LLM produced for this call, already parsed from JSON.
1724
+ * @returns A JSON string with the tool's result, at most 15 KiB — the LiveKit RPC response limit;
1725
+ * a larger result fails the call with an RPC error. A synchronous handler may return the string
1726
+ * directly; the SDK awaits the result either way.
1727
+ * @example
1728
+ * ```ts
1729
+ * agentManager.registerClientTool('get_cart_total', async args => {
1730
+ * const total = await cart.total(args.currency as string);
1731
+ * return JSON.stringify({ total });
1732
+ * });
1733
+ *
1734
+ * // Nothing to await: the string is enough.
1735
+ * agentManager.registerClientTool('get_locale', () => JSON.stringify({ locale: navigator.language }));
1736
+ * ```
1737
+ * @category Callbacks & Events
1738
+ */
1739
+ export declare type ClientToolHandler = (args: Record<string, unknown>) => string | Promise<string>;
1740
+
1741
+ /**
1742
+ * Which video codec the stream should negotiate.
1743
+ *
1744
+ * Passed as {@link StreamOptions.compatibilityMode}. `on` forces VP8 and `off` forces H264; with
1745
+ * `auto` the SDK forwards the flag and the codec is selected according to the browser. Talks (V2)
1746
+ * and Clips (V3) agents only — Expressive (V4) agents negotiate the codec themselves and ignore
1747
+ * the setting.
1748
+ *
1749
+ * @category Streaming Options
1750
+ */
1751
+ export declare type CompatibilityMode = 'on' | 'off' | 'auto';
1752
+
1753
+ /**
1754
+ * The state of the connection between the browser and the agent's stream.
1755
+ *
1756
+ * The first argument of
1757
+ * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange}.
1758
+ * {@link ConnectionState.Connected | 'connected'} is the point at which
1759
+ * {@link AgentManager.chat | chat()} and {@link AgentManager.speak | speak()} can be called.
1760
+ *
1761
+ * Every agent type reports `'connecting'`, `'connected'`, `'fail'` and `'disconnected'`; `'new'`,
1762
+ * `'completed'` and `'closed'` are WebRTC ICE states that only Talks (V2) and Clips (V3) agents
1763
+ * reach, and `'disconnecting'` is Expressive (V4) only.
1764
+ *
1765
+ * @category Callbacks & Events
1766
+ */
1767
+ export declare enum ConnectionState {
1768
+ /** The connection object exists but nothing has been negotiated yet. */
1769
+ New = "new",
1770
+ /** The connection could not be established, or dropped irrecoverably. */
1771
+ Fail = "fail",
1772
+ /** The stream is live: the agent can be spoken to and its video rendered. */
1773
+ Connected = "connected",
1774
+ /** The connection is being established, or re-established after a drop. */
1775
+ Connecting = "connecting",
1776
+ /** The connection has been shut down and cannot be used again. */
1777
+ Closed = "closed",
1778
+ /**
1779
+ * Negotiation finished and the connection is fully established.
1780
+ *
1781
+ * It is reached after {@link ConnectionState.Connected | 'connected'}, so gate the application
1782
+ * on that one instead: it is the state every agent type reports.
1783
+ */
1784
+ Completed = "completed",
1785
+ /**
1786
+ * {@link AgentManager.disconnect | disconnect()} is in progress.
1787
+ *
1788
+ * Expressive (V4) agents only; Talks (V2) and Clips (V3) go straight from
1789
+ * {@link ConnectionState.Connected | 'connected'} to
1790
+ * {@link ConnectionState.Disconnected | 'disconnected'}.
1791
+ */
1792
+ Disconnecting = "disconnecting",
1793
+ /**
1794
+ * The stream has ended.
1795
+ *
1796
+ * The `reason` argument of
1797
+ * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} says why —
1798
+ * a {@link StreamEndReason} when the server ended the session deliberately. Reconnecting with
1799
+ * {@link AgentManager.reconnect | reconnect()} starts a new stream.
1800
+ */
1801
+ Disconnected = "disconnected"
1802
+ }
1803
+
1804
+ /**
1805
+ * How well the streamed media is reaching the user.
1806
+ *
1807
+ * The argument of
1808
+ * {@link AgentManagerCallbacks.onConnectivityStateChange | onConnectivityStateChange}. It is
1809
+ * estimated from the session's own media statistics — jitter-buffer delay and freeze count for
1810
+ * Talks (V2) and Clips (V3), the transport's reported connection quality for Expressive (V4) — so
1811
+ * it reflects what this stream is actually getting rather than whether the browser is online.
1812
+ *
1813
+ * @category Callbacks & Events
1814
+ */
1815
+ export declare enum ConnectivityState {
1816
+ /** The stream is arriving smoothly. */
1817
+ Strong = "STRONG",
1818
+ /** The stream is degraded: video is stalling or arriving late. */
1819
+ Weak = "WEAK",
1820
+ /** There is not enough data to judge the connection yet, or the stream stopped arriving. */
1821
+ Unknown = "UNKNOWN"
1822
+ }
1823
+
1824
+ /**
1825
+ * Creates an {@link AgentManager} for one agent: its chat, its video stream and its connections.
1826
+ *
1827
+ * Fetches the agent from the Agents API before it resolves, so the returned manager already has
1828
+ * {@link AgentManager.agent | agent} and {@link AgentManager.starterMessages | starterMessages}
1829
+ * filled in. No stream is opened until {@link AgentManager.connect | connect()} is called.
1830
+ * Two options are checked here, and both reject with a {@link ValidationError}: an Expressive (V4)
1831
+ * agent asked for {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}, which only Talks (V2)
1832
+ * and Clips (V3) agents support; and
1833
+ * {@link AgentManagerOptions.callbacks | callbacks} without
1834
+ * {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} in a mode that streams video —
1835
+ * that callback is what attaches the streamed media to a video element, and only
1836
+ * {@link ChatMode.TextOnly}, {@link ChatMode.Playground} and {@link ChatMode.Maintenance} can do
1837
+ * without it. Every other bad argument surfaces later, as a {@link ValidationError} rejected by the
1838
+ * method that was called on the returned manager, such as
1839
+ * {@link AgentManager.chat | chat()} or {@link AgentManager.speak | speak()}.
1840
+ *
1841
+ * @param agent - Id of the agent to talk to: the `data-agent-id` from its Embed snippet, or the `id`
1842
+ * returned by the Agents API.
1843
+ * @param options - Credentials, callbacks and everything else the manager needs. See
1844
+ * {@link AgentManagerOptions}.
1845
+ * @returns A manager for that agent, ready to {@link AgentManager.connect | connect()}.
1846
+ * @throws {@link ValidationError} When an Expressive (V4) agent is created with
1847
+ * {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}, or when
1848
+ * {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} is missing in a mode that
1849
+ * streams video.
1850
+ * @throws {@link HttpError} When the agent cannot be fetched — an unknown id, or a client key that
1851
+ * is not authorized for the agent or the calling domain.
1852
+ * @throws {@link NetworkError} When the request for the agent never reaches the server: the browser
1853
+ * is offline, DNS or TLS fails, or the request is blocked.
1854
+ *
1855
+ * @example
1856
+ * ```ts
1857
+ * import * as sdk from '@d-id/client-sdk';
1858
+ *
1859
+ * const agentManager = await sdk.createAgentManager('agt_fumf1234', {
1860
+ * auth: { type: 'key', clientKey: 'YOUR_CLIENT_KEY' },
1861
+ * callbacks: {
1862
+ * // Hand the streamed media to your video element. Required in every mode that
1863
+ * // streams video, which is every mode but TextOnly, Playground and Maintenance.
1864
+ * onSrcObjectReady(value) {
1865
+ * videoElement.srcObject = value;
1866
+ * },
1867
+ * },
1868
+ * });
1869
+ *
1870
+ * await agentManager.connect();
1871
+ * await agentManager.chat('What is the distance to the moon?');
1872
+ * ```
1873
+ *
1874
+ * @category Agent Manager
1875
+ */
1876
+ export declare function createAgentManager(agent: string, options: AgentManagerOptions): Promise<AgentManager>;
1877
+
1878
+ /**
1879
+ * The data-channel topics an application may send on with
1880
+ * {@link AgentManager.sendDataChannelMessage | sendDataChannelMessage()}.
1881
+ *
1882
+ * The remaining data-channel topics are driven by their own methods
1883
+ * ({@link AgentManager.chat | chat()}, {@link AgentManager.speak | speak()},
1884
+ * {@link AgentManager.interrupt | interrupt()},
1885
+ * {@link AgentManager.setSttLanguage | setSttLanguage()}), which own the payload shape and
1886
+ * bookkeeping those topics expect, so they stay internal.
1887
+ *
1888
+ * The members' values are the wire strings. Take the value from the enum rather than writing the
1889
+ * string out, so the wire string stays in one place. Expressive (V4) agents only.
1890
+ *
1891
+ * @example
1892
+ * ```ts
1893
+ * import { DataChannelTopic } from '@d-id/client-sdk';
1894
+ *
1895
+ * await agentManager.sendDataChannelMessage(DataChannelTopic.Presentation, {
1896
+ * type: 'navigate',
1897
+ * slide: 3,
1898
+ * });
1899
+ * ```
1900
+ * @category Agent Manager
1901
+ */
1902
+ export declare enum DataChannelTopic {
1903
+ /**
1904
+ * Messages that drive a presentation the agent is showing alongside its video, such as moving
1905
+ * to another slide. Sent on the wire as `did.presentation`; the payload shape is whatever the
1906
+ * presentation the agent is running expects.
1907
+ */
1908
+ Presentation = "did.presentation"
1909
+ }
1910
+
1911
+ /**
1912
+ * Every error the SDK raises, as a union — what {@link isDIDError} narrows a caught value to.
1913
+ *
1914
+ * Each member declares {@link BaseError.kind | kind} as a different literal, so a `switch` on
1915
+ * `kind` inside an `isDIDError` branch narrows the value to one class and gives typed access to
1916
+ * that class's own fields — {@link HttpError.status | status} and {@link HttpError.code | code} on
1917
+ * an {@link HttpError}, {@link ValidationError.key | key} on a {@link ValidationError}, and so on.
1918
+ * The `default` branch of an exhaustive `switch` is `never` to the type checker.
1919
+ *
1920
+ * Keep that branch total anyway. {@link isDIDError} recognizes any `Error` carrying a string
1921
+ * `kind`, which is what lets it see across a bundle boundary, so a value built by a different copy
1922
+ * of the SDK — a 2.x `HttpError`, whose `kind` was the server's classification — can reach the
1923
+ * `default` branch at runtime with a `kind` outside this union.
1924
+ *
1925
+ * {@link BaseError} itself is deliberately not a member: its `kind` is a plain `string`, which
1926
+ * matches every literal and would stop the narrowing from working.
1927
+ *
1928
+ * @example Branching on a caught error
1929
+ * ```ts
1930
+ * import { isDIDError, type DIDError } from '@d-id/client-sdk';
1931
+ *
1932
+ * try {
1933
+ * await agentManager.connect();
1934
+ * } catch (error) {
1935
+ * if (!isDIDError(error)) {
1936
+ * throw error;
1937
+ * }
1938
+ *
1939
+ * switch (error.kind) {
1940
+ * case 'HttpError':
1941
+ * console.error(error.status, error.code);
1942
+ * break;
1943
+ * case 'NetworkError':
1944
+ * console.error('offline?', error.endpoint);
1945
+ * break;
1946
+ * default:
1947
+ * // Total on purpose: `kind` is `never` here to the type checker, but a value from
1948
+ * // another copy of the SDK can still land in this branch.
1949
+ * console.error(error.kind, error.message);
1950
+ * }
1951
+ * }
1952
+ * ```
1953
+ * @category Errors
1954
+ */
1955
+ export declare type DIDError = HttpError | NetworkError | StreamError | WsError | ValidationError | ChatCreationFailed | ChatModeDowngraded;
1956
+
1957
+ /**
1958
+ * ElevenLabs provider details: the provider type and the requested voice id. Available to premium users.
1959
+ *
1960
+ * Pass it as {@link TextStreamScript.provider} to have ElevenLabs synthesise the text, optionally
1961
+ * with {@link VoiceConfigElevenlabs} to control how closely the voice is reproduced.
1962
+ *
1963
+ * @category Voice
1964
+ */
1965
+ export declare interface ElevenlabsTtsProvider {
1966
+ /**
1967
+ * Selects ElevenLabs. Either {@link Providers.Elevenlabs} or its string value `'elevenlabs'` —
1968
+ * both are accepted, so the provider object can be written inline without importing the enum.
1969
+ */
1970
+ type: `${Providers.Elevenlabs}`;
1971
+ /**
1972
+ * Id of the voice to speak with, from D-ID's list of ElevenLabs voices.
1973
+ *
1974
+ * @example "21m00Tcm4TlvDq8ikWAM"
1975
+ * @see [ElevenLabs voices](https://docs.d-id.com/docs/tts-elevenlabs)
1976
+ */
1977
+ voice_id: string;
1978
+ /**
1979
+ * How closely the voice should follow the original it was cloned from. See
1980
+ * {@link VoiceConfigElevenlabs}.
1981
+ *
1982
+ * @see [ElevenLabs voice settings](https://elevenlabs.io/docs/best-practices/prompting/controls)
1983
+ */
1984
+ voice_config?: VoiceConfigElevenlabs;
1985
+ }
1986
+
1987
+ /**
1988
+ * The end-of-call feedback form configured on an agent.
1989
+ *
1990
+ * It describes what to ask the user when the conversation ends; the SDK does not render anything
1991
+ * itself. Read it from {@link Agent.end_of_call_feedback}, show your own form when
1992
+ * {@link EndOfCallFeedbackConfig.enabled | enabled} is set, and send the result with
1993
+ * {@link AgentManager.submitFeedback | submitFeedback()}.
1994
+ *
1995
+ * @category Agent Manager
1996
+ */
1997
+ export declare interface EndOfCallFeedbackConfig {
1998
+ /** Whether the agent is configured to ask for feedback when a call ends. */
1999
+ enabled: boolean;
2000
+ /** The line to show the user as the call ends, before the rating is asked for. */
2001
+ closing_message?: string;
2002
+ /** Whether a free-text follow-up question should be asked after the rating. */
2003
+ follow_up_enabled?: boolean;
2004
+ /**
2005
+ * The follow-up question to ask, chosen by the score the user gave.
2006
+ *
2007
+ * Whichever one you show is what {@link AgentManager.submitFeedback | submitFeedback()} records
2008
+ * as {@link SubmitFeedbackResponse.question_shown | question_shown}.
2009
+ */
2010
+ follow_up_messages?: {
2011
+ /** Question for a score at the low end of the scale. */
2012
+ low?: string;
2013
+ /** Question for a score of 4. */
2014
+ four?: string;
2015
+ /** Question for a score of 5. */
2016
+ five?: string;
2017
+ };
2018
+ }
2019
+
2020
+ /**
2021
+ * What the SDK knows about where a failure happened, beyond the error itself.
2022
+ *
2023
+ * The second argument of {@link AgentManagerCallbacks.onError | onError}. Which fields are set
2024
+ * follows from the call that failed, not from the class of the error:
2025
+ *
2026
+ * - a failed Agents API request — an {@link HttpError} or a {@link NetworkError} — sets
2027
+ * {@link ErrorContext.endpoint | endpoint} and {@link ErrorContext.method | method};
2028
+ * - a failure on an Expressive (V4) session sets {@link ErrorContext.sessionId | sessionId};
2029
+ * - a failure on a Talks (V2) or Clips (V3) stream sets {@link ErrorContext.streamId | streamId}.
2030
+ *
2031
+ * Nothing else is passed. In particular the request body and headers are not: the body is the end
2032
+ * user's own message, and applications routinely forward this argument straight to an error
2033
+ * reporter. The error is the thing to log — {@link BaseError.toJson | toJson()} renders it with
2034
+ * the same request fields already redacted — and this is context to attach alongside it.
2035
+ *
2036
+ * Every field is optional, so read them with a guard — and the whole argument is optional too: a
2037
+ * failure the SDK has no context for is reported with an empty object, or with no second argument
2038
+ * at all.
2039
+ *
2040
+ * @category Callbacks & Events
2041
+ */
2042
+ export declare interface ErrorContext {
2043
+ /**
2044
+ * Path of the Agents API request that failed, relative to the API host.
2045
+ *
2046
+ * The same value as {@link HttpError.endpoint} and {@link NetworkError.endpoint} on the error
2047
+ * itself.
2048
+ */
2049
+ endpoint?: string;
2050
+ /** HTTP method of the request that failed, such as `GET` or `POST`. */
2051
+ method?: string;
2052
+ /**
2053
+ * Id of the Expressive (V4) session the failure happened on.
2054
+ *
2055
+ * The same value {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated} reported as
2056
+ * {@link StreamCreatedInfo.sessionId}, and {@link AgentManager.getSessionInfo | getSessionInfo()}
2057
+ * returns.
2058
+ */
2059
+ sessionId?: string;
2060
+ /**
2061
+ * Id of the Talks (V2) or Clips (V3) stream the failure happened on.
2062
+ *
2063
+ * The same value {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated} reported as
2064
+ * {@link StreamCreatedInfo.streamId}.
2065
+ */
2066
+ streamId?: string;
2067
+ }
2068
+
2069
+ /**
2070
+ * The JSON-safe payload {@link BaseError.toJson | toJson()} produces, for logs and error reports.
2071
+ *
2072
+ * Only the fields the SDK deliberately exposes are present, so the payload can be forwarded to a
2073
+ * logging service as it is. Subclasses add their own keys: {@link HttpError} adds `code` and
2074
+ * `httpStatus` and, when the failing call is known, `endpoint` and `method`; {@link NetworkError}
2075
+ * adds `endpoint`, `method`, `durationMs`, `online` and `visibility`.
2076
+ *
2077
+ * @example An HttpError from a request that was refused
2078
+ * ```json
2079
+ * {
2080
+ * "kind": "HttpError",
2081
+ * "code": "InsufficientCreditsError",
2082
+ * "message": "Account has insufficient credits",
2083
+ * "httpStatus": 402,
2084
+ * "endpoint": "/agt_x/chat/cht_y",
2085
+ * "method": "POST"
2086
+ * }
2087
+ * ```
2088
+ * @category Errors
2089
+ */
2090
+ export declare interface ErrorJson {
2091
+ /**
2092
+ * Stable machine-readable code for the failure — the error's {@link BaseError.kind | kind}.
2093
+ */
2094
+ kind: string;
2095
+ /**
2096
+ * Human-readable description of the failure — the error's `message`.
2097
+ */
2098
+ message: string;
2099
+ /**
2100
+ * Message of the error that caused this one, truncated to 256 characters.
2101
+ *
2102
+ * Present only when {@link BaseError.originalError | originalError} is an `Error` and its
2103
+ * message differs from {@link ErrorJson.message | message}. A cause that is not an `Error` is
2104
+ * never serialized, so an arbitrary object carrying credentials cannot end up in the payload.
2105
+ */
2106
+ cause?: string;
2107
+ /**
2108
+ * The Agents API's own classification of the failure, from {@link HttpError.code | code}.
2109
+ *
2110
+ * Present on an {@link HttpError} only.
2111
+ */
2112
+ code?: string;
2113
+ /**
2114
+ * Additional fields contributed by a subclass, such as `httpStatus` on {@link HttpError}.
2115
+ *
2116
+ * Typed `unknown`, so a key that is not declared above has to be narrowed before it is used.
2117
+ */
2118
+ [key: string]: unknown;
2119
+ }
2120
+
2121
+ /**
2122
+ * A request to the Agents API came back with a non-2xx status.
2123
+ *
2124
+ * Raised for every REST call the SDK makes on the application's behalf: fetching the agent in
2125
+ * {@link createAgentManager}, creating the stream and the chat during
2126
+ * {@link AgentManager.connect | connect()}, sending a message with
2127
+ * {@link AgentManager.chat | chat()}, and the rating and feedback calls. The same error is both
2128
+ * handed to {@link AgentManagerCallbacks.onError | onError} and thrown, so it also rejects the
2129
+ * promise of whichever method made the request — catch it around that call, or handle it centrally
2130
+ * in the callback. For the message-send request behind {@link AgentManager.chat | chat()} the
2131
+ * callback may not fire; the error is still thrown. Typical cases are `401` or `403` for a client
2132
+ * key that is not authorized for the agent or the calling domain, and `404` for an unknown agent
2133
+ * id; an account that is out of credits comes back with {@link HttpError.code | code}
2134
+ * `'InsufficientCreditsError'`. A `429` is retried twice, one second apart (three attempts in
2135
+ * total), before it surfaces.
2136
+ *
2137
+ * {@link BaseError.kind | kind} is always `'HttpError'`, so a `switch` on it narrows a caught value
2138
+ * to this class. The server's own classification lives on {@link HttpError.code | code} — the
2139
+ * `'InsufficientCreditsError'` above is one — so a message-independent branch on a specific API
2140
+ * failure is possible.
2141
+ *
2142
+ * The message is the envelope's `description` when the body is that JSON, and the raw body
2143
+ * otherwise — truncated to 256 characters either way, because a gateway can answer a 5xx with a
2144
+ * whole HTML page.
2145
+ *
2146
+ * @category Errors
2147
+ */
2148
+ export declare class HttpError extends BaseError {
2149
+ /**
2150
+ * Always `'HttpError'`. Branch on it to tell this failure from the other SDK errors.
2151
+ */
2152
+ readonly kind: 'HttpError';
2153
+ /**
2154
+ * The Agents API's own classification of the failure — the `kind` from D-ID's
2155
+ * `{ kind, description }` error body — and `'HttpError'` when the response was not that
2156
+ * envelope.
2157
+ *
2158
+ * An account out of credits comes back as `'InsufficientCreditsError'`, for instance. It is a
2159
+ * plain `string` because the set is the API's, not the SDK's, and grows without an SDK release.
2160
+ * Use {@link HttpError.status | status} for the transport-level branch, this for the API-level
2161
+ * one, and {@link BaseError.kind | kind} to tell an `HttpError` from the SDK's other errors.
2162
+ */
2163
+ readonly code: string;
2164
+ /**
2165
+ * HTTP status code of the response, such as `401`, `404` or `500`.
2166
+ */
2167
+ readonly status: number;
2168
+ /**
2169
+ * Path of the request that failed, relative to the API client's base path — for example
2170
+ * `/agt_x/chat/cht_y` for a message sent to a chat.
2171
+ *
2172
+ * Absent when the error was constructed without call context. {@link NetworkError.endpoint}
2173
+ * is the same value on a transport failure.
2174
+ */
2175
+ readonly endpoint?: string;
2176
+ /**
2177
+ * HTTP method of the request that failed, such as `GET` or `POST`.
2178
+ *
2179
+ * Absent when the error was constructed without call context.
2180
+ */
2181
+ readonly method?: string;
2182
+ /**
2183
+ * Serializes the error, adding the failing call to what
2184
+ * {@link BaseError.toJson | BaseError.toJson()} already returns.
2185
+ *
2186
+ * Adds {@link HttpError.code | code}, `httpStatus` from {@link HttpError.status | status}, and
2187
+ * `endpoint` and `method` when the call context is known. The raw `status` property is
2188
+ * serialized as `httpStatus`.
2189
+ *
2190
+ * @returns The error as plain, JSON-serializable data.
2191
+ */
2192
+ toJson(): ErrorJson;
2193
+ }
2194
+
2195
+ /**
2196
+ * What caused the user to interrupt the agent, passed to
2197
+ * {@link AgentManager.interrupt | interrupt()}.
2198
+ *
2199
+ * @category Chat
2200
+ */
2201
+ export declare interface InterruptOptions {
2202
+ /**
2203
+ * The cause: `text` when the user typed over the answer, `audio` when they started speaking,
2204
+ * `click` when they pressed a stop control, and `manual` for an interruption the application
2205
+ * decided on itself.
2206
+ *
2207
+ * The SDK records it with the interruption for analytics. It changes behaviour in one case
2208
+ * only: Expressive (V4) agents ignore a `text` interrupt, because their orchestrator does not
2209
+ * cancel the answer already in flight. Talks (V2) and Clips (V3) agents interrupt the current
2210
+ * video whatever the value.
2211
+ */
2212
+ type: 'text' | 'audio' | 'click' | 'manual';
2213
+ }
2214
+
2215
+ /**
2216
+ * Whether the agent is waiting on a tool call before it can continue.
2217
+ *
2218
+ * True while any of the running calls is `blocking`; false when nothing is running, or when
2219
+ * everything running is `async` and the agent can keep talking. Pass it the array
2220
+ * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange} hands you, to
2221
+ * decide whether to show the user that the agent is busy.
2222
+ *
2223
+ * @param calls - The tool calls running right now, as reported by
2224
+ * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}. See
2225
+ * {@link RunningToolCall}.
2226
+ * @returns `true` while the agent is suspended on a blocking tool call.
2227
+ * @example
2228
+ * ```ts
2229
+ * import { isAwaitingTool } from '@d-id/client-sdk';
2230
+ *
2231
+ * const callbacks = {
2232
+ * onRunningToolCallsChange(calls) {
2233
+ * setSpinnerVisible(isAwaitingTool(calls));
2234
+ * },
2235
+ * };
2236
+ * ```
2237
+ * @category Callbacks & Events
2238
+ */
2239
+ export declare function isAwaitingTool(calls: readonly RunningToolCall[]): boolean;
2240
+
2241
+ /**
2242
+ * Type guard that reports whether a caught value is an error raised by the SDK.
2243
+ *
2244
+ * It accepts any `Error` carrying a string `kind`, which every {@link BaseError} has, so it also
2245
+ * recognizes SDK errors that crossed a bundle boundary, where `instanceof BaseError` can fail
2246
+ * because two copies of the class are loaded. It narrows to {@link DIDError}, the union of the
2247
+ * seven subclasses, so a `switch` on {@link BaseError.kind | kind} inside the branch narrows
2248
+ * further to one class and its own fields — `error.status` on an {@link HttpError},
2249
+ * `error.key` on a {@link ValidationError}.
2250
+ *
2251
+ * The duck-typing is wider than the union it promises, so keep the `default` branch of a `switch`
2252
+ * total — {@link DIDError} says why.
2253
+ *
2254
+ * @param error - The caught value to test.
2255
+ * @returns `true` when `error` is an error the SDK raised.
2256
+ * @example
2257
+ * ```ts
2258
+ * try {
2259
+ * await agentManager.chat('What is the distance to the moon?');
2260
+ * } catch (error) {
2261
+ * if (isDIDError(error)) {
2262
+ * console.error(error.kind, error.toJson());
2263
+ *
2264
+ * if (error.kind === 'HttpError' && error.status === 401) {
2265
+ * refreshCredentials();
2266
+ * }
2267
+ * } else {
2268
+ * throw error;
2269
+ * }
2270
+ * }
2271
+ * ```
2272
+ * @category Errors
2273
+ */
2274
+ export declare function isDIDError(error: unknown): error is DIDError;
2275
+
2276
+ /**
2277
+ * One message of a chat: what the user asked, or what the agent answered.
2278
+ *
2279
+ * The SDK keeps the whole transcript and hands a fresh copy of it to
2280
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage} every time a message is added or
2281
+ * changed, oldest first. While an answer streams in, the last message's
2282
+ * {@link Message.content | content} and {@link Message.parts | parts} are replaced with the latest
2283
+ * text on each `partial` callback — not appended to — and are final on `answer`. The same shape is
2284
+ * accepted by {@link AgentManagerOptions.initialMessages | initialMessages} to seed a transcript.
2285
+ *
2286
+ * @category Chat
2287
+ */
2288
+ export declare interface Message {
2289
+ /**
2290
+ * Id of this message.
2291
+ *
2292
+ * Pass it to {@link AgentManager.rate | rate()} to rate the answer. The SDK generates a random
2293
+ * id for the messages it creates locally, and uses the id sent with the message for those that
2294
+ * arrive from the agent.
2295
+ */
2296
+ id: string;
2297
+ /**
2298
+ * Who the message is from.
2299
+ *
2300
+ * The SDK itself only creates `user` (the end user) and `assistant` (the agent) messages; the
2301
+ * value on a transcribed or streamed message is whatever the server payload carried. `system`,
2302
+ * `function` and `tool` exist because the underlying chat protocol allows them.
2303
+ */
2304
+ role?: 'system' | 'assistant' | 'user' | 'function' | 'tool';
2305
+ /**
2306
+ * The message text.
2307
+ *
2308
+ * Plain text, which for agent answers may contain markdown. It is replaced by the latest text
2309
+ * on every `partial` callback while the answer streams in — and the final `answer` may be
2310
+ * shorter than the partials before it, which is exactly how the SDK spots an interruption — so
2311
+ * render it as it is rather than appending to what you rendered before.
2312
+ */
2313
+ content: string;
2314
+ /**
2315
+ * {@link Message.content | content} split into renderable pieces by {@link parseMessageParts}.
2316
+ *
2317
+ * Kept in step with `content` on every message the SDK creates, including while an answer
2318
+ * streams in. Render these instead of the raw string when the agent may answer with images,
2319
+ * videos or links; a message with no markup is a single `text` part, and an empty message is
2320
+ * an empty array.
2321
+ *
2322
+ * Optional because {@link AgentManagerOptions.initialMessages | initialMessages} take the same
2323
+ * shape, and a transcript restored from your own storage carries only the text: leave `parts`
2324
+ * out and the SDK runs the parser over `content` before the message reaches the transcript. A
2325
+ * non-empty array you built yourself is kept exactly as given. Every message the SDK delivers
2326
+ * through {@link AgentManagerCallbacks.onNewMessage | onNewMessage} has it set, seeded
2327
+ * `initialMessages` included, so a handler can read it without a guard.
2328
+ */
2329
+ parts?: MessagePart[];
2330
+ /**
2331
+ * When the message was added, as an ISO 8601 timestamp.
2332
+ *
2333
+ * Optional for the same reason as {@link Message.parts | parts} — a restored transcript need
2334
+ * not carry one — but set on every message the SDK builds itself, which is every message that
2335
+ * reaches {@link AgentManagerCallbacks.onNewMessage | onNewMessage} other than a seeded
2336
+ * {@link AgentManagerOptions.initialMessages | initialMessage} that arrived without one.
2337
+ */
2338
+ createdAt?: string;
2339
+ /**
2340
+ * The knowledge citations the answer was drawn from, as {@link RetrievalMetadata} entries.
2341
+ *
2342
+ * Present on an agent answer when the chat response carried them, so a UI can show its sources;
2343
+ * {@link AgentManager.rate | rate()} also sends them with a rating. The SDK strips this field
2344
+ * from the transcript it sends back to the Agents API with the next
2345
+ * {@link AgentManager.chat | chat()}.
2346
+ */
2347
+ matches?: ChatResponse['matches'];
2348
+ /**
2349
+ * The retrieved context the answer was generated from, as
2350
+ * {@link ChatResponse.context | the chat response} supplied it.
2351
+ *
2352
+ * Only ever set on an agent answer, and only when the answer came back from the Agents API.
2353
+ * Expressive (V4) agents chat over the data channel instead, so their answers carry no context
2354
+ * — except in {@link ChatMode.Playground}, which always takes the Agents API path.
2355
+ */
2356
+ context?: string;
2357
+ /**
2358
+ * `true` when the answer was cut short instead of being spoken to the end.
2359
+ *
2360
+ * Set on the last message by {@link AgentManager.interrupt | interrupt()}, and by the SDK when
2361
+ * the final answer turns out to be shorter than the partial text already received — which is
2362
+ * how it detects that the agent was interrupted mid-utterance.
2363
+ */
2364
+ interrupted?: boolean;
2365
+ /**
2366
+ * `true` when this user message came from speech-to-text rather than from
2367
+ * {@link AgentManager.chat | chat()}.
2368
+ *
2369
+ * It is what distinguishes an utterance the user spoke from one they typed.
2370
+ */
2371
+ transcribed?: boolean;
2372
+ /**
2373
+ * The sentiment the agent delivered this answer with, when the stream reported one.
2374
+ *
2375
+ * Taken from the metadata the server sends with the video it created, and attached to the most
2376
+ * recent agent answer. The SDK only ever fills it in from an Expressive (V4) session, and only
2377
+ * while {@link AgentManagerOptions.debug | debug} is enabled.
2378
+ */
2379
+ sentiment?: MessageSentiment;
2380
+ }
2381
+
2382
+ /**
2383
+ * One renderable piece of a message: a run of text, an image, a video or a link.
2384
+ *
2385
+ * {@link parseMessageParts} splits a message's {@link Message.content | content} into these, and
2386
+ * the SDK keeps the result on {@link Message.parts}. Switch on `type` when rendering. Anything the
2387
+ * parser did not recognise is preserved verbatim as a `text` part, in its original order, and
2388
+ * nothing is dropped or reordered; a recognised image, video or link replaces the markup it was
2389
+ * written as, so the parts are not a concatenation of the original string.
2390
+ *
2391
+ * @category Chat
2392
+ */
2393
+ export declare type MessagePart = {
2394
+ /** Discriminant: plain text that the parser found no markup in. */
2395
+ type: 'text';
2396
+ /** The text itself, exactly as it appeared in {@link Message.content}. */
2397
+ text: string;
2398
+ } | {
2399
+ /** Discriminant: an image, from markdown image syntax such as `![alt](url)`. */
2400
+ type: 'image';
2401
+ /** URL of the image. */
2402
+ src: string;
2403
+ /** The alt text from the markdown, or an empty string when it had none. */
2404
+ alt: string;
2405
+ /**
2406
+ * `image/gif` when the URL itself ends in `.gif`, ignoring case; absent otherwise.
2407
+ *
2408
+ * The check looks at the whole URL, so a query string or fragment suppresses it —
2409
+ * `cat.gif?v=2` carries no `mimeType`. Video detection differs: it strips both before
2410
+ * looking at the extension.
2411
+ */
2412
+ mimeType?: string;
2413
+ } | {
2414
+ /**
2415
+ * Discriminant: a video, either from thumbnail syntax (`[![alt](thumb)](video)`) or from
2416
+ * an image whose URL ends in `.mp4`, `.webm`, `.mkv`, `.mov`, `.m4v` or `.ogv` once any
2417
+ * query string and fragment have been stripped.
2418
+ */
2419
+ type: 'video';
2420
+ /** URL of the video file. */
2421
+ src: string;
2422
+ /** The alt text from the markdown, or an empty string when it had none. */
2423
+ alt: string;
2424
+ /** URL of the poster image, when the thumbnail syntax supplied one. */
2425
+ thumbnail?: string;
2426
+ } | {
2427
+ /** Discriminant: a link, from markdown `[label](url)` or from an HTML `<a href>`. */
2428
+ type: 'link';
2429
+ /** Target of the link. */
2430
+ href: string;
2431
+ /** The text shown for the link. */
2432
+ label: string;
2433
+ };
2434
+
2435
+ /**
2436
+ * The sentiment an agent answer was delivered with, as the server reported it.
2437
+ *
2438
+ * The shape of {@link Message.sentiment}. It is an object rather than a string because the server
2439
+ * reports both the id of the sentiment it used and its name, where
2440
+ * {@link TextStreamScript.sentiment} — the sentiment the application *asks* for — is just the
2441
+ * name.
2442
+ *
2443
+ * @category Chat
2444
+ */
2445
+ export declare interface MessageSentiment {
2446
+ /** Id of the sentiment, as the server sent it. */
2447
+ id: string;
2448
+ /** Name of the sentiment, as the server sent it. */
2449
+ name: string;
2450
+ }
2451
+
2452
+ /**
2453
+ * Microsoft Azure provider details: the provider type, the requested voice id and an optional
2454
+ * `voice_config` for style, rate and pitch.
2455
+ *
2456
+ * Pass it as {@link TextStreamScript.provider} to pick a Microsoft Azure voice explicitly,
2457
+ * optionally with {@link VoiceConfigMicrosoft} to set style, rate and pitch. The Agents API
2458
+ * documents Microsoft TTS as its default when a script names no provider, so this is also the
2459
+ * provider a script without one ends up using.
2460
+ *
2461
+ * @category Voice
2462
+ */
2463
+ export declare interface MicrosoftTtsProvider {
2464
+ /**
2465
+ * Selects Microsoft Azure. Either {@link Providers.Microsoft} or its string value
2466
+ * `'microsoft'` — both are accepted, so the provider object can be written inline without
2467
+ * importing the enum.
2468
+ */
2469
+ type: `${Providers.Microsoft}`;
2470
+ /**
2471
+ * Id of the voice to speak with, from D-ID's list of Microsoft Azure voices.
2472
+ *
2473
+ * @example "en-US-JennyNeural"
2474
+ * @see [Microsoft Azure voices](https://docs.d-id.com/docs/tts-microsoft)
2475
+ */
2476
+ voice_id: string;
2477
+ /**
2478
+ * How the voice should deliver the text: style, rate and pitch. See
2479
+ * {@link VoiceConfigMicrosoft}.
2480
+ */
2481
+ voice_config?: VoiceConfigMicrosoft;
2482
+ }
2483
+
2484
+ /**
2485
+ * A request to the Agents API never reached the server, so no response came back.
2486
+ *
2487
+ * This is the transport failure counterpart of {@link HttpError}, where the server did answer: the
2488
+ * browser's `fetch` rejected outright because the device is offline, DNS or TLS failed, the
2489
+ * connection was refused or the request was blocked, for instance by CORS or an extension. Like
2490
+ * {@link HttpError} it is both handed to {@link AgentManagerCallbacks.onError | onError} and
2491
+ * thrown, so it also rejects the promise of the method that made the request; for the message-send
2492
+ * request behind {@link AgentManager.chat | chat()} the callback may not fire, but the error is
2493
+ * still thrown. A request the SDK cancelled itself is not reported this way — the browser's own
2494
+ * `AbortError` is rethrown unchanged.
2495
+ *
2496
+ * The message is always `'Network request failed'`; the browser's own wording, such as
2497
+ * `'Failed to fetch'`, is kept in {@link BaseError.originalError | originalError} and appears as
2498
+ * `cause` in {@link NetworkError.toJson | toJson()}. The remaining properties record what was
2499
+ * happening at the time, which is usually what distinguishes a dropped connection from a tab that
2500
+ * was backgrounded.
2501
+ *
2502
+ * @category Errors
2503
+ */
2504
+ export declare class NetworkError extends BaseError {
2505
+ /**
2506
+ * Always `'NetworkError'`. Branch on it to tell this failure from the other SDK errors.
2507
+ */
2508
+ readonly kind: 'NetworkError';
2509
+ /**
2510
+ * Path of the request that failed, relative to the API client's base path — for example
2511
+ * `/agt_x/chat/cht_y`.
2512
+ */
2513
+ readonly endpoint?: string;
2514
+ /**
2515
+ * HTTP method of the request that failed, such as `GET` or `POST`.
2516
+ */
2517
+ readonly method?: string;
2518
+ /**
2519
+ * How long the request ran before it failed, in milliseconds.
2520
+ *
2521
+ * A value close to zero usually means the request never left the browser; a large one points
2522
+ * at a connection that was established and then lost.
2523
+ */
2524
+ readonly durationMs?: number;
2525
+ /**
2526
+ * The browser's `navigator.onLine` at the moment of the failure — `false` when the device
2527
+ * reported itself offline.
2528
+ */
2529
+ readonly online?: boolean;
2530
+ /**
2531
+ * The page's `document.visibilityState` at the moment of the failure.
2532
+ *
2533
+ * `'hidden'` means the tab was in the background, where browsers throttle or suspend network
2534
+ * activity.
2535
+ */
2536
+ readonly visibility?: DocumentVisibilityState;
2537
+ /**
2538
+ * Serializes the error, adding the captured context to what
2539
+ * {@link BaseError.toJson | BaseError.toJson()} already returns.
2540
+ *
2541
+ * Each of `endpoint`, `method`, `durationMs`, `online` and `visibility` is included only when it
2542
+ * was captured.
2543
+ *
2544
+ * @returns The error as plain, JSON-serializable data.
2545
+ */
2546
+ toJson(): ErrorJson;
2547
+ }
2548
+
2549
+ /**
2550
+ * Splits a message's text into the typed {@link MessagePart | parts} a UI can render.
2551
+ *
2552
+ * The SDK already runs it over every message it builds and keeps the result on
2553
+ * {@link Message.parts}, so this is for content that comes from somewhere else — a transcript you
2554
+ * render outside the SDK, or text you assembled before handing it to a renderer.
2555
+ * {@link AgentManagerOptions.initialMessages | initialMessages} no longer need it: pass `parts: []`
2556
+ * and the SDK runs this for you. It recognises markdown
2557
+ * images (`![alt](url)`), the video thumbnail form (`[![alt](thumb)](video)`), markdown links
2558
+ * (`[label](url)`) and HTML anchors (`<a href="url">label</a>`); an image whose URL looks like a
2559
+ * video becomes a `video` part instead, and a GIF is tagged with a `mimeType`, both under the rules
2560
+ * {@link MessagePart} sets out. Everything the parser does not recognise is preserved verbatim as a
2561
+ * `text` part, in its original order, and nothing is dropped or reordered; each recognised part
2562
+ * replaces the markup it was written as, so the parts are not a concatenation of the input.
2563
+ *
2564
+ * @param content - The message text to split, as it appears in {@link Message.content}.
2565
+ * @returns The parts in the order they appear in `content`: a single `text` part when there is no
2566
+ * markup to find, and an empty array for an empty string.
2567
+ * @example
2568
+ * ```ts
2569
+ * import { parseMessageParts } from '@d-id/client-sdk';
2570
+ *
2571
+ * parseMessageParts('Here it is: ![a cat](https://example.com/cat.png) — enjoy!');
2572
+ * // [
2573
+ * // { type: 'text', text: 'Here it is: ' },
2574
+ * // { type: 'image', src: 'https://example.com/cat.png', alt: 'a cat' },
2575
+ * // { type: 'text', text: ' — enjoy!' },
2576
+ * // ]
2577
+ * ```
2578
+ * @category Chat
2579
+ */
2580
+ export declare function parseMessageParts(content: string): MessagePart[];
2581
+
2582
+ /**
2583
+ * The text-to-speech engines a voice can be served by.
2584
+ *
2585
+ * The value of the `type` field that discriminates the provider objects — {@link Providers.Microsoft}
2586
+ * selects a {@link MicrosoftTtsProvider}, {@link Providers.Elevenlabs} an
2587
+ * {@link ElevenlabsTtsProvider}, and so on — and of {@link Voice.provider} when you look a voice up
2588
+ * in D-ID's catalogue. Which providers an account may use depends on its plan.
2589
+ *
2590
+ * @category Voice
2591
+ */
2592
+ export declare enum Providers {
2593
+ /** Amazon's text-to-speech service; see {@link AmazonTtsProvider}. */
2594
+ Amazon = "amazon",
2595
+ /** Azure OpenAI text-to-speech; see {@link AzureOpenAiTtsProvider}. */
2596
+ AzureOpenAi = "azure-openai",
2597
+ /** Microsoft Azure text-to-speech, which the Agents API documents as its default when a
2598
+ * script names no provider; see {@link MicrosoftTtsProvider}. */
2599
+ Microsoft = "microsoft",
2600
+ /** ElevenLabs text-to-speech; see {@link ElevenlabsTtsProvider}. */
2601
+ Elevenlabs = "elevenlabs"
2602
+ }
2603
+
2604
+ /**
2605
+ * A rating stored against one message of a chat, as the Agents API returns it.
2606
+ *
2607
+ * Produced by {@link AgentManager.rate | rate()} and returned again by
2608
+ * {@link AgentManager.deleteRate | deleteRate()}. Keep {@link Rating.id | id} if the user may
2609
+ * change their mind: pass it back to {@link AgentManager.rate | rate()} as `rateId` to update the
2610
+ * rating, or to {@link AgentManager.deleteRate | deleteRate()} to remove it.
2611
+ *
2612
+ * @category Chat
2613
+ */
2614
+ export declare interface Rating {
2615
+ /**
2616
+ * Id of this rating.
2617
+ *
2618
+ * Pass it as the `rateId` argument of {@link AgentManager.rate | rate()} to update the rating,
2619
+ * or to {@link AgentManager.deleteRate | deleteRate()} to remove it.
2620
+ */
2621
+ id: string;
2622
+ /** Id of the D-ID account that owns the agent the rating was left on. Set by the Agents API. */
2623
+ owner_id: string;
2624
+ /** Id of the agent whose answer was rated. */
2625
+ agent_id: string;
2626
+ /**
2627
+ * The knowledge citations that were attached to the rated answer, as `[document_id, id]` pairs.
2628
+ *
2629
+ * The SDK builds them from the {@link Message.matches | matches} of the rated message, so a
2630
+ * negative rating can be traced back to the documents the answer was drawn from. Empty when the
2631
+ * answer cited nothing.
2632
+ */
2633
+ matches: [string, string][];
2634
+ /**
2635
+ * Id of the agent's knowledge base ({@link Agent.knowledge}) at the time of the rating.
2636
+ *
2637
+ * An empty string when the agent has no knowledge base.
2638
+ */
2639
+ knowledge_id: string;
2640
+ /**
2641
+ * The end-user identifier the Agents API recorded for the request.
2642
+ *
2643
+ * Derived from the credentials the SDK sends, which carry
2644
+ * {@link AgentManagerOptions.externalId | externalId} for `type: 'key'` authorization.
2645
+ */
2646
+ external_id: string;
2647
+ /** Identity the Agents API attributed the rating to. Set by the Agents API. */
2648
+ created_by: string;
2649
+ /** Id of the chat the rated message belongs to — the value
2650
+ * {@link AgentManagerCallbacks.onNewChat | onNewChat} reported. */
2651
+ chat_id: string;
2652
+ /** The score itself: `1` for a positive rating, `-1` for a negative one. */
2653
+ score: 1 | -1;
2654
+ /** When the rating was created, as an ISO 8601 timestamp. */
2655
+ created_at: string;
2656
+ /** When the rating was last changed, as an ISO 8601 timestamp. */
2657
+ modified_at: string;
2658
+ /** {@link Message.id | Id of the message} that was rated. */
2659
+ message_id: string;
2660
+ }
2661
+
2662
+ /**
2663
+ * One knowledge citation: the passage of the agent's knowledge base an answer was drawn from.
2664
+ *
2665
+ * The Agents API returns these with an answer and the SDK keeps them on
2666
+ * {@link Message.matches | matches}, so a UI can show the sources behind a reply.
2667
+ *
2668
+ * @category Chat
2669
+ */
2670
+ export declare interface RetrievalMetadata {
2671
+ /** Id of this match. Sent back with a rating as the second half of a
2672
+ * {@link Rating.matches} pair. */
2673
+ id: string;
2674
+ /** The matched passage itself, as stored in the knowledge base. */
2675
+ data: string;
2676
+ /** Title of the document the passage comes from. */
2677
+ title: string;
2678
+ /** Id of the source document. Sent back with a rating as the first half of a
2679
+ * {@link Rating.matches} pair. */
2680
+ document_id: string;
2681
+ /** Id of the knowledge base the document belongs to — the agent's {@link Agent.knowledge}. */
2682
+ knowledge_id: string;
2683
+ /** URL of the original source, for linking the citation out of the chat. */
2684
+ source_url: string;
2685
+ }
2686
+
2687
+ /**
2688
+ * A tool call currently running in the session.
2689
+ *
2690
+ * The entries of the array given to
2691
+ * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}. A call appears
2692
+ * when it starts and disappears when it finishes, fails, or — for a `blocking` call — when its turn
2693
+ * ends; an `async` call outlives its turn.
2694
+ *
2695
+ * @category Callbacks & Events
2696
+ */
2697
+ export declare interface RunningToolCall {
2698
+ /**
2699
+ * Id of this call, matching the {@link ToolCallStartedPayload.callId | callId} of the
2700
+ * {@link ToolCallStartedPayload} that announced it.
2701
+ */
2702
+ callId: string;
2703
+ /** Name of the tool being called, as configured on the agent. */
2704
+ name: string;
2705
+ /**
2706
+ * Whether the agent is suspended while this call runs.
2707
+ *
2708
+ * `blocking` means the agent waits for the result before it can continue; `async` means it
2709
+ * keeps talking while the call runs. See {@link ToolExecutionMode}.
2710
+ */
2711
+ executionMode: ToolExecutionMode;
2712
+ }
2713
+
2714
+ /**
2715
+ * What {@link AgentManager.speak | speak()} resolves with: the video the agent is about to stream.
2716
+ *
2717
+ * The fields come from the Talks (V2) and Clips (V3) API, which generates a discrete video while
2718
+ * answering the request. Where no such video exists the call still resolves, with the same stub —
2719
+ * `status` `'success'`, `duration` `0` and an empty `videoId`: on Expressive (V4) agents, whose
2720
+ * speech is streamed over the data channel rather than rendered as a separate video, and in a
2721
+ * text-only chat mode ({@link ChatMode.TextOnly}, {@link ChatMode.Playground} or
2722
+ * {@link ChatMode.Maintenance}), which produces no video at all.
2723
+ *
2724
+ * @category Speak & Scripts
2725
+ */
2726
+ export declare interface SpeakResponse {
2727
+ /**
2728
+ * What the server said about the request. Not a fixed set — the Agents API declares it as an
2729
+ * open string — so treat an unrecognized value as accepted; a rejected request comes back as
2730
+ * an {@link HttpError}. `'success'` on the stub the SDK returns where no video is produced.
2731
+ */
2732
+ status: string;
2733
+ /**
2734
+ * Id of the session this call was made on; the SDK sends it back on later streaming requests.
2735
+ */
2736
+ sessionId?: string;
2737
+ /**
2738
+ * Duration of the generated video as reported by the Agents API for Talks (V2) and Clips (V3)
2739
+ * agents. `0` when the call produced no discrete video — on Expressive (V4) agents, and in a
2740
+ * text-only chat mode.
2741
+ */
2742
+ duration: number;
2743
+ /**
2744
+ * Id of the generated video.
2745
+ *
2746
+ * Use it to correlate this call with the video the agent then plays, which
2747
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} reports the start and
2748
+ * end of, and which {@link AgentManager.interrupt | interrupt()} cancels. Empty when the call
2749
+ * produced no discrete video — on Expressive (V4) agents, and in a text-only chat mode.
2750
+ */
2751
+ videoId: string;
2752
+ }
2753
+
2754
+ /**
2755
+ * The script payload {@link AgentManager.speak | speak()} accepts: text or audio.
2756
+ *
2757
+ * Discriminated by its `type` field, so `'text'` narrows the object to {@link TextStreamScript}
2758
+ * and `'audio'` to {@link AudioStreamScript}.
2759
+ * {@link AgentManager.speak | speak()} additionally takes a plain string, as shorthand for a
2760
+ * {@link TextStreamScript} with that string as its `input`.
2761
+ *
2762
+ * @category Speak & Scripts
2763
+ */
2764
+ export declare type SpeakScript = TextStreamScript | AudioStreamScript;
2765
+
2766
+ /**
2767
+ * Identifiers of the stream the SDK has just opened for the session.
2768
+ *
2769
+ * Handed to {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated} once the server has
2770
+ * accepted the stream, before the first video frame arrives. Log the three ids together: they are
2771
+ * what identifies the session in D-ID's own records.
2772
+ *
2773
+ * @category Callbacks & Events
2774
+ */
2775
+ export declare interface StreamCreatedInfo {
2776
+ /**
2777
+ * Id of the agent the stream was opened for.
2778
+ */
2779
+ agentId: string;
2780
+ /**
2781
+ * Id of the session; the SDK sends it back on every subsequent request for this stream.
2782
+ * On Expressive (V4) agents it is the same value as
2783
+ * {@link StreamCreatedInfo.streamId | streamId}.
2784
+ */
2785
+ sessionId: string;
2786
+ /**
2787
+ * Id of the stream itself.
2788
+ */
2789
+ streamId: string;
2790
+ }
2791
+
2792
+ /**
2793
+ * Why the server ended the session.
2794
+ *
2795
+ * Arrives as the `reason` argument of
2796
+ * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} together with
2797
+ * {@link ConnectionState.Disconnected | 'disconnected'}, and is how you tell a session the server
2798
+ * closed on purpose from a connection that simply dropped — `reason` is an opaque transport
2799
+ * diagnostic in the latter case, so compare it against these values rather than parsing it. A
2800
+ * close reason the SDK does not recognise is forwarded as-is, which is the other reason to compare
2801
+ * against the enum. Which members can arrive depends on the agent type: Talks (V2) and Clips (V3)
2802
+ * agents report only {@link StreamEndReason.Ok | Ok},
2803
+ * {@link StreamEndReason.UnknownError | UnknownError},
2804
+ * {@link StreamEndReason.NetworkIssue | NetworkIssue} and
2805
+ * {@link StreamEndReason.Inactivity | Inactivity}.
2806
+ * {@link AgentManager.reconnect | reconnect()} still works afterwards; it starts a new stream
2807
+ * rather than resuming the ended one.
2808
+ *
2809
+ * @example Reacting to the limits an Expressive (V4) session reports
2810
+ * ```ts
2811
+ * import { ConnectionState, StreamEndReason } from '@d-id/client-sdk';
2812
+ *
2813
+ * const callbacks = {
2814
+ * onConnectionStateChange(state, reason) {
2815
+ * if (state !== ConnectionState.Disconnected) return;
2816
+ *
2817
+ * if (reason === StreamEndReason.TimeLimit || reason === StreamEndReason.MessageLimit) {
2818
+ * showMessage('This session has reached its limit.');
2819
+ * } else if (reason === StreamEndReason.Inactivity) {
2820
+ * showMessage('The session timed out.');
2821
+ * }
2822
+ * },
2823
+ * };
2824
+ * ```
2825
+ * @category Callbacks & Events
2826
+ */
2827
+ export declare enum StreamEndReason {
2828
+ /** The session ended normally, because it was closed deliberately. */
2829
+ Ok = "ok",
2830
+ /** The session ended because of a failure the server could not classify. */
2831
+ UnknownError = "unknown_error",
2832
+ /** The session ended because the connection to the browser broke down. */
2833
+ NetworkIssue = "network_issue",
2834
+ /**
2835
+ * The session ended because it reached the message limit configured for the agent.
2836
+ *
2837
+ * Expressive (V4) agents.
2838
+ */
2839
+ MessageLimit = "message_limit",
2840
+ /**
2841
+ * The session ended because it reached its maximum duration.
2842
+ *
2843
+ * Expressive (V4) agents.
2844
+ */
2845
+ TimeLimit = "time_limit",
2846
+ /**
2847
+ * The session ended because nothing happened for too long.
2848
+ *
2849
+ * The window is {@link StreamOptions.sessionTimeout | sessionTimeout} for Talks (V2) and
2850
+ * Clips (V3).
2851
+ */
2852
+ Inactivity = "inactivity",
2853
+ /**
2854
+ * The agent itself ended the call.
2855
+ *
2856
+ * Expressive (V4) agents.
2857
+ */
2858
+ EndedByAgent = "ended_by_agent"
2859
+ }
2860
+
2861
+ /**
2862
+ * Something went wrong inside the live audio and video stream.
2863
+ *
2864
+ * Unlike {@link HttpError} and {@link NetworkError}, which come from REST calls, this one comes
2865
+ * from the transport carrying the agent's video, so it is only ever delivered to
2866
+ * {@link AgentManagerCallbacks.onError | onError} — no call of yours is necessarily in flight when
2867
+ * it happens, and nothing throws it. The SDK raises it when:
2868
+ *
2869
+ * - no media track is subscribed within the timeout after the LiveKit room used by Expressive (V4)
2870
+ * agents connects, after which the SDK disconnects the stream;
2871
+ * - the LiveKit room reports a media-device or encryption failure;
2872
+ * - a message cannot be put on the data channel — the WebRTC channel used by Talks (V2) and Clips
2873
+ * (V3) is not open, or the LiveKit room is not connected or rejects the send;
2874
+ * - the server reports that the stream itself failed, with the message
2875
+ * `Stream failed with event <event>`.
2876
+ *
2877
+ * Most of these leave the session unusable, so the useful response is to tell the user and call
2878
+ * {@link AgentManager.reconnect | reconnect()}. {@link BaseError.kind | kind} is `'StreamError'`.
2879
+ * The message describes the failure, and is the plain `'Stream Error'` when the transport gave no
2880
+ * detail; the underlying error, where there was one, is kept as
2881
+ * {@link BaseError.originalError | originalError}.
2882
+ *
2883
+ * @category Errors
2884
+ */
2885
+ export declare class StreamError extends BaseError {
2886
+ /**
2887
+ * Always `'StreamError'`. Branch on it to tell this failure from the other SDK errors.
2888
+ */
2889
+ readonly kind: 'StreamError';
2890
+ }
2891
+
2892
+ /**
2893
+ * Whether the agent's video is currently playing.
2894
+ *
2895
+ * The argument of {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange}: it tells
2896
+ * the application when to show the streamed video and when to fall back to the agent's idle video.
2897
+ *
2898
+ * @category Callbacks & Events
2899
+ */
2900
+ export declare enum StreamingState {
2901
+ /** The agent has started speaking; render the streamed media. */
2902
+ Start = "START",
2903
+ /** The agent has finished speaking; the application can switch back to the idle video. */
2904
+ Stop = "STOP"
2905
+ }
2906
+
2907
+ /**
2908
+ * Transport settings applied when the stream is created.
2909
+ *
2910
+ * Talks (V2) and Clips (V3) agents only. Expressive (V4) agents manage transport settings
2911
+ * automatically and ignore these options. Pass the object as
2912
+ * {@link AgentManagerOptions.streamOptions}; every field is optional.
2913
+ *
2914
+ * @category Streaming Options
2915
+ */
2916
+ export declare interface StreamOptions {
2917
+ /**
2918
+ * Which video codec the stream negotiates.
2919
+ *
2920
+ * See {@link CompatibilityMode}.
2921
+ *
2922
+ * @default auto
2923
+ */
2924
+ compatibilityMode?: CompatibilityMode;
2925
+ /**
2926
+ * Whether the stream plays a warmup video while the connection settles.
2927
+ *
2928
+ * With it on the server plays a short warmup video as soon as the connection is up, and the
2929
+ * SDK holds back {@link ConnectionState.Connected | 'connected'} — and so the resolution of
2930
+ * {@link AgentManager.connect | connect()} — until that video has played out. Without it,
2931
+ * `'connected'` is reported as soon as the data channel opens. The application sees nothing of
2932
+ * the warmup video itself beyond the delay; it is not distinguishable from any other. A fluent
2933
+ * stream ignores the option — the warmup only runs on legacy streams (see
2934
+ * {@link StreamOptions.fluent | fluent}).
2935
+ *
2936
+ * @default false
2937
+ */
2938
+ streamWarmup?: boolean;
2939
+ /**
2940
+ * How long the session may sit idle between messages before the server ends it, in seconds.
2941
+ *
2942
+ * Up to 300, and only for accounts whose plan allows it. When the session does time out,
2943
+ * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} reports
2944
+ * {@link ConnectionState.Disconnected | 'disconnected'} with the reason
2945
+ * {@link StreamEndReason.Inactivity | 'inactivity'}. Leave it out and the server decides.
2946
+ */
2947
+ sessionTimeout?: number;
2948
+ /**
2949
+ * Whether to request a fluent stream.
2950
+ *
2951
+ * `true` streams one video for both the idle and talking states; `false` uses the legacy mode,
2952
+ * where the application swaps between two video elements. Clips (V3) agents built on a Pro
2953
+ * avatar; always on for Expressive (V4). A fluent stream is also what makes
2954
+ * {@link AgentManager.interrupt | interrupt()} available.
2955
+ *
2956
+ * @default false
2957
+ */
2958
+ fluent?: boolean;
2959
+ }
2960
+
2961
+ /**
2962
+ * How the agent's idle and talking video are delivered.
2963
+ *
2964
+ * Returned by {@link AgentManager.getStreamType | getStreamType()}. Which one a session gets
2965
+ * follows from the agent and from {@link StreamOptions.fluent | fluent}.
2966
+ *
2967
+ * @category Streaming Options
2968
+ */
2969
+ export declare enum StreamType {
2970
+ /**
2971
+ * Two videos: the agent's idle video, which the application plays itself, and the streamed
2972
+ * talking video. Switch between them in
2973
+ * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange}.
2974
+ */
2975
+ Legacy = "legacy",
2976
+ /**
2977
+ * One continuous video for both the idle and the talking state, so there is nothing to swap.
2978
+ * Expressive (V4) agents always stream this way, and it is what makes
2979
+ * {@link AgentManager.interrupt | interrupt()} possible.
2980
+ */
2981
+ Fluent = "fluent"
2982
+ }
2983
+
2984
+ /**
2985
+ * A short-lived credential for the D-ID speech-to-text service.
2986
+ *
2987
+ * What {@link AgentManager.getSttToken | getSttToken()} resolves with, fetched fresh from the
2988
+ * Agents API each time. It lets an application drive its own speech recognition against the
2989
+ * service the agent uses without putting D-ID credentials in the browser. The token expires, so request one per recognition session
2990
+ * rather than holding on to it.
2991
+ *
2992
+ * @category Agent Manager
2993
+ */
2994
+ export declare interface SttTokenResponse {
2995
+ /** The authorization token to present to the speech service. */
2996
+ token: string;
2997
+ /** The speech service region the token is valid in. */
2998
+ region: string;
2999
+ }
3000
+
3001
+ /**
3002
+ * What the Agents API stored when end-of-call feedback was submitted.
3003
+ *
3004
+ * Returned by {@link AgentManager.submitFeedback | submitFeedback()}, which rates the conversation
3005
+ * as a whole rather than a single answer.
3006
+ *
3007
+ * @category Chat
3008
+ */
3009
+ export declare interface SubmitFeedbackResponse {
3010
+ /** Id of the chat the feedback belongs to — the value
3011
+ * {@link AgentManagerCallbacks.onNewChat | onNewChat} reported. */
3012
+ chat_id: string;
3013
+ /** The score that was submitted, on the agent's end-of-call scale of 1 to 5. */
3014
+ rating: number;
3015
+ /**
3016
+ * The follow-up question the user was asked, when one was recorded.
3017
+ *
3018
+ * Applications pick it from {@link EndOfCallFeedbackConfig.follow_up_messages}.
3019
+ */
3020
+ question_shown?: string;
3021
+ /** When the feedback was stored, as an ISO 8601 timestamp. */
3022
+ submitted_at: string;
3023
+ }
3024
+
3025
+ /**
3026
+ * A script that makes the agent say text you supply, synthesised by a text-to-speech provider.
3027
+ *
3028
+ * The usual payload for {@link AgentManager.speak | speak()}. The agent's LLM is not involved, so
3029
+ * the agent says exactly what {@link TextStreamScript.input | input} contains — which is what makes
3030
+ * it the right script for greetings and other canned lines. Passing a plain string to
3031
+ * {@link AgentManager.speak | speak()} is shorthand for this script with `ssml` set to `false`.
3032
+ *
3033
+ * @example Text
3034
+ * ```ts
3035
+ * const speak = await agentManager.speak({
3036
+ * type: 'text',
3037
+ * input: "Hi! I'm Alice!",
3038
+ * });
3039
+ * ```
3040
+ * @example Text with sentiment
3041
+ * `sentiment` is for Expressive (V4) agents only. If the requested sentiment is not supported by
3042
+ * the agent, the default sentiment is used.
3043
+ * ```ts
3044
+ * const speak = await agentManager.speak({
3045
+ * type: 'text',
3046
+ * input: "Hi! I'm Alice!",
3047
+ * sentiment: 'friendly',
3048
+ * });
3049
+ * ```
3050
+ * @category Speak & Scripts
3051
+ */
3052
+ export declare interface TextStreamScript {
3053
+ /**
3054
+ * Which kind of script this is. Always `text` for this variant; an
3055
+ * {@link AudioStreamScript} carries `audio` instead.
3056
+ */
3057
+ type: 'text';
3058
+ /**
3059
+ * The text-to-speech provider and voice that synthesise
3060
+ * {@link TextStreamScript.input | input}, from the list of supported providers.
3061
+ *
3062
+ * One of the objects in {@link TtsProvider}: a `type` naming the provider, the
3063
+ * `voice_id` to speak with, and optional provider-specific `voice_config`. Leave it out and the
3064
+ * SDK sends the script without a provider, so the voice is chosen server-side; the Agents API
3065
+ * documents Microsoft TTS as its default when no provider is given.
3066
+ */
3067
+ provider?: TtsProvider;
3068
+ /**
3069
+ * The text to be synthesised into speech.
3070
+ *
3071
+ * Each provider has its own limit on the text length.
3072
+ * @example "This is an example text"
3073
+ * @maxLength 40000
3074
+ * @minLength 3
3075
+ */
3076
+ input: string;
3077
+ /**
3078
+ * Is the text provided in ssml form.
3079
+ *
3080
+ * Set it to `true` when {@link TextStreamScript.input | input} is SSML markup rather than plain
3081
+ * text, so the provider reads the tags instead of speaking them.
3082
+ * @default false
3083
+ */
3084
+ ssml?: boolean;
3085
+ /**
3086
+ * Queue this speak behind the current speech instead of interrupting it. Expressive (V4)
3087
+ * agents only.
3088
+ * @default false
3089
+ */
3090
+ should_queue_speaks?: boolean;
3091
+ /**
3092
+ * Sentiment name to speak with. Expressive (V4) agents only; if the agent does not support the
3093
+ * requested sentiment, its default sentiment is used.
3094
+ * @example "friendly"
3095
+ */
3096
+ sentiment?: string;
3097
+ }
3098
+
3099
+ /**
3100
+ * The payload of a {@link ToolCallEvent.Done} event: a tool call finished successfully.
3101
+ *
3102
+ * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
3103
+ * {@link ToolEventCallback}.
3104
+ *
3105
+ * @category Callbacks & Events
3106
+ */
3107
+ export declare interface ToolCallDonePayload {
3108
+ /** Id of the call that finished, matching the {@link ToolCallStartedPayload} that announced it. */
3109
+ callId: string;
3110
+ /** Name of the tool that was called. */
3111
+ name: string;
3112
+ /** The arguments the call was made with. */
3113
+ input: Record<string, unknown>;
3114
+ /** The result the tool returned. */
3115
+ output: Record<string, unknown>;
3116
+ /** How long the call took, in milliseconds. */
3117
+ durationMs: number;
3118
+ /** Any additional metadata the tool reported alongside its result. */
3119
+ extra: Record<string, unknown>;
3120
+ /** When the call finished, as reported by the server. */
3121
+ timestamp: string;
3122
+ }
3123
+
3124
+ /**
3125
+ * The payload of a {@link ToolCallEvent.Error} event: a tool call failed.
3126
+ *
3127
+ * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
3128
+ * {@link ToolEventCallback}. Read {@link ToolCallErrorPayload.error | error} for what went wrong.
3129
+ * The agent carries on with the conversation; the SDK does not retry.
3130
+ *
3131
+ * @category Callbacks & Events
3132
+ */
3133
+ export declare interface ToolCallErrorPayload {
3134
+ /** Id of the call that failed, matching the {@link ToolCallStartedPayload} that announced it. */
3135
+ callId: string;
3136
+ /** Name of the tool that was called. */
3137
+ name: string;
3138
+ /** The arguments the call was made with. */
3139
+ input: Record<string, unknown>;
3140
+ /**
3141
+ * Whatever the failed call produced, if anything.
3142
+ *
3143
+ * Any JSON value — the server's own type for a tool result is unconstrained, and on a failure
3144
+ * it is commonly the reason as a plain string rather than a structured result. Narrow it
3145
+ * before use. The string case is also given to you as
3146
+ * {@link ToolCallErrorPayload.error | error}, which is what to show.
3147
+ */
3148
+ output: unknown;
3149
+ /** How long the call ran before failing, in milliseconds. */
3150
+ durationMs: number;
3151
+ /** Any additional metadata the server reported with the failure. */
3152
+ extra: Record<string, unknown>;
3153
+ /**
3154
+ * What went wrong, in one line, when the server said.
3155
+ *
3156
+ * Taken from the failure the server reports in {@link ToolCallErrorPayload.extra | extra}
3157
+ * (`extra.error.message`), and from {@link ToolCallErrorPayload.output | output} when that is
3158
+ * a plain string instead. Absent when the server sent neither, which is why an application
3159
+ * that shows the reason needs a fallback of its own; the full structured failure — its kind,
3160
+ * code and any data — is in `extra.error`.
3161
+ */
3162
+ error?: string;
3163
+ /** When the call failed, as reported by the server. */
3164
+ timestamp: string;
3165
+ }
3166
+
3167
+ /**
3168
+ * The tool-call events delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent}.
3169
+ *
3170
+ * Switch on the first argument of the handler to tell them apart: it narrows the second argument to
3171
+ * the payload that event carries — see {@link ToolEventCallback}. The members' values are the wire
3172
+ * strings the server sends, so compare against the enum rather than writing the string out.
3173
+ * Expressive (V4) agents only.
3174
+ *
3175
+ * @example
3176
+ * ```ts
3177
+ * import { AgentManagerCallbacks, ToolCallEvent } from '@d-id/client-sdk';
3178
+ *
3179
+ * const callbacks: AgentManagerCallbacks = {
3180
+ * onToolEvent(event, data) {
3181
+ * if (event === ToolCallEvent.Started) {
3182
+ * console.log('started', data.name, data.input);
3183
+ * }
3184
+ * },
3185
+ * };
3186
+ * ```
3187
+ * @category Callbacks & Events
3188
+ */
3189
+ export declare enum ToolCallEvent {
3190
+ /**
3191
+ * The agent has begun a tool call; the payload is a {@link ToolCallStartedPayload}, carrying the
3192
+ * call's id, the tool's name and the arguments the agent's LLM produced.
3193
+ */
3194
+ Started = "tool-call/started",
3195
+ /**
3196
+ * A tool call finished successfully; the payload is a {@link ToolCallDonePayload}, carrying the
3197
+ * result the tool returned and how long the call took.
3198
+ */
3199
+ Done = "tool-call/done",
3200
+ /**
3201
+ * A tool call failed; the payload is a {@link ToolCallErrorPayload}, carrying the reason in
3202
+ * {@link ToolCallErrorPayload.error | error} when the server gave one. The agent carries on
3203
+ * with the conversation.
3204
+ */
3205
+ Error = "tool-call/error"
3206
+ }
3207
+
3208
+ /**
3209
+ * The payload of a {@link ToolCallEvent.Started} event: the agent has begun a tool call.
3210
+ *
3211
+ * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
3212
+ * {@link ToolEventCallback}.
3213
+ *
3214
+ * @category Callbacks & Events
3215
+ */
3216
+ export declare interface ToolCallStartedPayload {
3217
+ /** Id of this call. The matching done or error payload carries the same id. */
3218
+ callId: string;
3219
+ /** Name of the tool the agent is calling, as configured on the agent. */
3220
+ name: string;
3221
+ /** The arguments the agent's LLM produced for this call. */
3222
+ input: Record<string, unknown>;
3223
+ /**
3224
+ * The tool's result, when the server sent one.
3225
+ *
3226
+ * The event is emitted before the tool has run, so it is normally absent; read the
3227
+ * {@link ToolCallDonePayload.output | output} of the matching done event instead.
3228
+ */
3229
+ output?: Record<string, unknown>;
3230
+ /**
3231
+ * Whether the server considers the agent interruptible while this call is outstanding.
3232
+ *
3233
+ * Informational: the SDK does not forward it.
3234
+ * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange} is derived from
3235
+ * the {@link ToolCallStartedPayload.executionMode | executionMode} of the calls still
3236
+ * running, not from this field.
3237
+ */
3238
+ interruptible: boolean;
3239
+ /**
3240
+ * Whether the agent waits for this call. See {@link ToolExecutionMode}.
3241
+ *
3242
+ * Always present: a server event that omits it, or carries anything other than `async`, is
3243
+ * reported as `'blocking'` — the same normalization
3244
+ * {@link RunningToolCall.executionMode | RunningToolCall.executionMode} applies, so the two
3245
+ * agree about the same call.
3246
+ */
3247
+ executionMode: ToolExecutionMode;
3248
+ /** The conversational turn this call belongs to, or `null` when it belongs to no turn. */
3249
+ turnId?: number | null;
3250
+ /** When the call started, as reported by the server. */
3251
+ timestamp: string;
3252
+ }
3253
+
3254
+ /**
3255
+ * The handler type for {@link AgentManagerCallbacks.onToolEvent | onToolEvent}: the event argument
3256
+ * narrows the payload argument.
3257
+ *
3258
+ * One signature over three argument pairs, one pair per tool-call event, so the first argument
3259
+ * narrows the second: a handler written against this type sees exactly one of
3260
+ * {@link ToolCallStartedPayload}, {@link ToolCallDonePayload} and {@link ToolCallErrorPayload},
3261
+ * never a union of the three — in an inline `onToolEvent(event, data) { … }` handler as much as in
3262
+ * a standalone function annotated with this type. A payload that does not belong to its event is
3263
+ * rejected. Expressive (V4) agents only.
3264
+ *
3265
+ * @param args - The event and the payload it carries, as one pair:
3266
+ * {@link ToolCallEvent.Started} with a {@link ToolCallStartedPayload} — the call the agent has just
3267
+ * begun, with the arguments its LLM produced; {@link ToolCallEvent.Done} with a
3268
+ * {@link ToolCallDonePayload} — the call that has just finished, with the result the tool returned;
3269
+ * or {@link ToolCallEvent.Error} with a {@link ToolCallErrorPayload} — the call that has just
3270
+ * failed, with the reason in {@link ToolCallErrorPayload.error | error} when the server gave one.
3271
+ *
3272
+ * @example
3273
+ * ```ts
3274
+ * import { AgentManagerCallbacks, ToolCallEvent } from '@d-id/client-sdk';
3275
+ *
3276
+ * const callbacks: AgentManagerCallbacks = {
3277
+ * onToolEvent(event, data) {
3278
+ * if (event === ToolCallEvent.Started) {
3279
+ * console.log('started', data.name, data.input);
3280
+ * } else if (event === ToolCallEvent.Done) {
3281
+ * console.log('done', data.name, data.output, data.durationMs);
3282
+ * } else {
3283
+ * console.log('failed', data.name, data.error ?? 'no reason given');
3284
+ * }
3285
+ * },
3286
+ * };
3287
+ * ```
3288
+ * @category Callbacks & Events
3289
+ */
3290
+ export declare type ToolEventCallback = (...args: [event: ToolCallEvent.Started, data: ToolCallStartedPayload] | [event: ToolCallEvent.Done, data: ToolCallDonePayload] | [event: ToolCallEvent.Error, data: ToolCallErrorPayload]) => void;
3291
+
3292
+ /**
3293
+ * Whether the agent waits for a tool call to finish before it carries on.
3294
+ *
3295
+ * Set on the agent's tool configuration, and reported on {@link RunningToolCall.executionMode} and
3296
+ * {@link ToolCallStartedPayload.executionMode}. Only a `blocking` call suspends the agent, which
3297
+ * is why one being outstanding is what makes the agent uninterruptible — see
3298
+ * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange}.
3299
+ *
3300
+ * @category Callbacks & Events
3301
+ */
3302
+ export declare type ToolExecutionMode = 'blocking' | 'async';
3303
+
3304
+ /**
3305
+ * The provider object a speak script accepts: any of the four text-to-speech providers.
3306
+ *
3307
+ * This is the type of {@link TextStreamScript.provider}. Pick the variant for the provider you
3308
+ * want, give it the `voice_id` to speak with and, except for {@link AmazonTtsProvider}, an optional
3309
+ * `voice_config`; `type` discriminates the union.
3310
+ *
3311
+ * @example
3312
+ * ```ts
3313
+ * import { Providers } from '@d-id/client-sdk';
3314
+ *
3315
+ * const speak = await agentManager.speak({
3316
+ * type: 'text',
3317
+ * input: "Hi! I'm Alice!",
3318
+ * provider: { type: Providers.Microsoft, voice_id: 'en-US-JennyNeural' },
3319
+ * });
3320
+ * ```
3321
+ * @category Voice
3322
+ */
3323
+ export declare type TtsProvider = MicrosoftTtsProvider | AzureOpenAiTtsProvider | ElevenlabsTtsProvider | AmazonTtsProvider;
3324
+
3325
+ /**
3326
+ * A method was called with arguments, or in a state, that the SDK will not send to the Agents
3327
+ * API.
3328
+ *
3329
+ * This is one of the two SDK errors that only ever reach the caller and are never delivered to
3330
+ * {@link AgentManagerCallbacks.onError | onError} (the other is {@link ChatCreationFailed}): it is
3331
+ * the direct answer to the call you just made, and every method that raises it rejects the promise
3332
+ * it returned, so `await` the call inside a `try`/`catch` or attach a `.catch()`. The SDK raises it
3333
+ * from
3334
+ * {@link AgentManager.chat | chat()} when the message is empty or 2000 characters or longer, when
3335
+ * the session's {@link ChatMode} has chat disabled or is in maintenance, and when the chat or the
3336
+ * stream has not been initialized yet; from {@link AgentManager.speak | speak()} when it is called
3337
+ * before {@link AgentManager.connect | connect()}; and from
3338
+ * {@link AgentManager.rate | rate()}, {@link AgentManager.deleteRate | deleteRate()} and
3339
+ * {@link AgentManager.submitFeedback | submitFeedback()} when no chat has started, plus, for
3340
+ * `rate()` alone, when no message with the given id is in the transcript. It is also raised from
3341
+ * {@link createAgentManager} and {@link AgentManager.changeMode | changeMode()} when an Expressive
3342
+ * (V4) agent is asked for {@link ChatMode.Off} or {@link ChatMode.DirectPlayback}, which only Talks
3343
+ * (V2) and Clips (V3) agents support. The five Expressive-only media methods —
3344
+ * {@link AgentManager.publishMicrophoneStream | publishMicrophoneStream()},
3345
+ * {@link AgentManager.replaceMicrophoneTrack | replaceMicrophoneTrack()},
3346
+ * {@link AgentManager.publishCameraStream | publishCameraStream()},
3347
+ * {@link AgentManager.setSttLanguage | setSttLanguage()} and
3348
+ * {@link AgentManager.sendDataChannelMessage | sendDataChannelMessage()} — raise it the other way
3349
+ * round: when the session is a Talks (V2) or Clips (V3) one, or
3350
+ * {@link AgentManager.connect | connect()} has not run yet.
3351
+ *
3352
+ * Nothing was sent to the Agents API when this is raised, so the session stays usable: fix the
3353
+ * argument or wait for {@link ConnectionState.Connected | 'connected'} and call again.
3354
+ * {@link BaseError.kind | kind} is `'ValidationError'`.
3355
+ *
3356
+ * @category Errors
3357
+ */
3358
+ export declare class ValidationError extends BaseError {
3359
+ /**
3360
+ * Name of the field the failure is about.
3361
+ *
3362
+ * The SDK does not populate it — every validation it raises passes the message alone — so it
3363
+ * is only set on a `ValidationError` an application constructed itself. It is also left out
3364
+ * of {@link BaseError.toJson | toJson()}, so a serialized validation error carries only its
3365
+ * kind and message.
3366
+ */
3367
+ readonly key?: string | undefined;
3368
+ /**
3369
+ * Always `'ValidationError'`. Branch on it to tell this failure from the other SDK errors.
3370
+ */
3371
+ readonly kind: 'ValidationError';
3372
+ /**
3373
+ * Builds a validation failure. The SDK does this itself before it performs a request.
3374
+ *
3375
+ * @param message - What was wrong with the call, such as `'Message cannot be empty'`.
3376
+ * @param key - Name of the field the failure is about. The SDK's own validations leave it
3377
+ * unset.
3378
+ */
3379
+ constructor(message: string,
3380
+ /**
3381
+ * Name of the field the failure is about.
3382
+ *
3383
+ * The SDK does not populate it — every validation it raises passes the message alone — so it
3384
+ * is only set on a `ValidationError` an application constructed itself. It is also left out
3385
+ * of {@link BaseError.toJson | toJson()}, so a serialized validation error carries only its
3386
+ * kind and message.
3387
+ */
3388
+ key?: string | undefined);
3389
+ }
3390
+
3391
+ /**
3392
+ * One voice in D-ID's catalogue of text-to-speech voices.
3393
+ *
3394
+ * The SDK does not fetch voices itself; the type is exported so an application that lists them —
3395
+ * to build a voice picker, say — can type the result and then feed {@link Voice.id | id} and
3396
+ * {@link Voice.provider | provider} into the provider object it passes as
3397
+ * {@link TextStreamScript.provider}. {@link Voice.provider | provider} is the wide
3398
+ * {@link Providers} enum, while each provider variant requires its own literal `type` — so switch
3399
+ * on it to build the matching variant, for example {@link Providers.Elevenlabs} to an
3400
+ * {@link ElevenlabsTtsProvider}.
3401
+ *
3402
+ * @category Voice
3403
+ */
3404
+ export declare interface Voice {
3405
+ /** Identifier of the voice: the value to pass as a provider object's `voice_id`. */
3406
+ id: string;
3407
+ /** Human-readable name of the voice. */
3408
+ name: string;
3409
+ /** The gender the voice is labelled with. */
3410
+ gender: string;
3411
+ /** The locale the voice speaks, such as `en-US`. */
3412
+ locale: string;
3413
+ /** Which accounts may use the voice. See {@link VoiceAccess}. */
3414
+ access: VoiceAccess;
3415
+ /** The provider that serves the voice. See {@link Providers}. */
3416
+ provider: Providers;
3417
+ /** The speaking styles this particular voice offers, for example as a
3418
+ * {@link VoiceConfigMicrosoft.style | style}. Styles differ from voice to voice. */
3419
+ styles: string[];
3420
+ /** The language of the voice, as a name rather than a locale code. */
3421
+ language: string;
3422
+ }
3423
+
3424
+ /**
3425
+ * Who may use a voice.
3426
+ *
3427
+ * The value of {@link Voice.access}, so an application listing voices can show or hide the ones the
3428
+ * account cannot select.
3429
+ *
3430
+ * @category Voice
3431
+ */
3432
+ export declare enum VoiceAccess {
3433
+ /** As exposed by the voices API: available to every account. */
3434
+ Public = "public",
3435
+ /** As exposed by the voices API: available to accounts whose plan includes premium voices. */
3436
+ Premium = "premium",
3437
+ /** As exposed by the voices API: available only to the account the voice belongs to. */
3438
+ Private = "private"
3439
+ }
3440
+
3441
+ /**
3442
+ * How closely an ElevenLabs voice should follow the original it was built from.
3443
+ *
3444
+ * The `voice_config` of {@link ElevenlabsTtsProvider}, mirroring ElevenLabs' own voice settings.
3445
+ * Both fields are optional; when one is omitted the Agents API applies its own default.
3446
+ *
3447
+ * @category Voice
3448
+ */
3449
+ export declare interface VoiceConfigElevenlabs {
3450
+ /**
3451
+ * How stable the voice is, and how much each generation varies.
3452
+ *
3453
+ * A number from 0 to 1: lower is more expressive and more variable between generations, higher
3454
+ * is flatter and more repeatable.
3455
+ * @example 0.5
3456
+ */
3457
+ stability?: number;
3458
+ /**
3459
+ * How closely the synthesised speech should adhere to the original voice it was cloned from.
3460
+ *
3461
+ * A number from 0 to 1: higher follows the original more strictly.
3462
+ * @example 0.5
3463
+ */
3464
+ similarity_boost?: number;
3465
+ }
3466
+
3467
+ /**
3468
+ * How a Microsoft Azure or Azure OpenAI voice should deliver the text.
3469
+ *
3470
+ * The `voice_config` of {@link MicrosoftTtsProvider} and {@link AzureOpenAiTtsProvider}. Every
3471
+ * field is optional; when one is omitted the Agents API applies its own default.
3472
+ *
3473
+ * @category Voice
3474
+ */
3475
+ export declare interface VoiceConfigMicrosoft {
3476
+ /**
3477
+ * The style of the voice.
3478
+ * Available styles change between voices.
3479
+ */
3480
+ style?: string;
3481
+ /**
3482
+ * The speed of the voice.
3483
+ * The value is relative to 1, 0.5 being half speed, 2 being twice as fast, etc.
3484
+ * Another option is a constant value from x-slow/slow/medium/fast/x-fast.
3485
+ * @example "0.5"
3486
+ */
3487
+ rate?: string;
3488
+ /**
3489
+ * The pitch of the voice.
3490
+ * Value could be an absolute value in Hz (including units), a relative value in Hz or st(semitones)
3491
+ * or a constant value from x-low/low/medium/high/x-high.
3492
+ * @example "+2st"
3493
+ */
3494
+ pitch?: string;
3495
+ }
3496
+
3497
+ /**
3498
+ * The web socket the SDK uses for chat notifications failed to connect.
3499
+ *
3500
+ * Talks (V2) and Clips (V3) sessions open a web socket alongside the video stream; the agent's
3501
+ * answer arrives over it as `partial` and `answer` events, which is what drives
3502
+ * {@link AgentManagerCallbacks.onNewMessage | onNewMessage}. This error is raised when that socket
3503
+ * emits an `error` event, once per failed attempt while
3504
+ * {@link AgentManager.connect | connect()} is retrying. It is only delivered to
3505
+ * {@link AgentManagerCallbacks.onError | onError} and never thrown, so there is nothing to catch
3506
+ * around `connect()` for it; if every attempt fails, `connect()` rejects with the browser's own
3507
+ * socket event instead.
3508
+ *
3509
+ * The socket is not opened at all for Expressive (V4) agents, which receive the same events over
3510
+ * the LiveKit data channel, nor in {@link ChatMode.DirectPlayback | DirectPlayback} mode, so the
3511
+ * error cannot occur in either case.
3512
+ *
3513
+ * {@link BaseError.kind | kind} is `'WSError'`, and the message is
3514
+ * `'Websocket failed to connect'`.
3515
+ *
3516
+ * @category Errors
3517
+ */
3518
+ export declare class WsError extends BaseError {
3519
+ /**
3520
+ * Always `'WSError'` — note the capitalization, which does not match the class name.
3521
+ */
3522
+ readonly kind: 'WSError';
3523
+ }
3524
+
3525
+ export { }