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

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-D0K-5SID.js +2037 -0
  4. package/dist/index.d.ts +3270 -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-CU_yynQK.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
@@ -1,856 +0,0 @@
1
- import { Analytics } from '../../services/analytics/mixpanel';
2
- import { VideoRTCStatsReport } from '../../services/streaming-manager/stats/report';
3
- import { Auth } from '../auth';
4
- import { ChatProgressCallback } from '../entities/agents/manager';
5
- import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
6
- import { ICreateStreamRequestResponse, IceCandidate, SpeakResponse, Status } from './rtc';
7
-
8
- /**
9
- * Which video codec the stream should negotiate.
10
- *
11
- * Passed as {@link StreamOptions.compatibilityMode}. `on` forces VP8 and `off` forces H264; with
12
- * `auto` the SDK forwards the flag and the codec is selected according to the browser. Talks (V2)
13
- * and Clips (V3) agents only — Expressive (V4) agents negotiate the codec themselves and ignore
14
- * the setting.
15
- *
16
- * @category Streaming Options
17
- */
18
- export type CompatibilityMode = 'on' | 'off' | 'auto';
19
- /**
20
- * Whether the agent's video is currently playing.
21
- *
22
- * The argument of {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange}: it tells
23
- * the application when to show the streamed video and when to fall back to the agent's idle video.
24
- *
25
- * @category Callbacks & Events
26
- */
27
- export declare enum StreamingState {
28
- /** The agent has started speaking; render the streamed media. */
29
- Start = "START",
30
- /** The agent has finished speaking; the application can switch back to the idle video. */
31
- Stop = "STOP"
32
- }
33
- /**
34
- * How well the streamed media is reaching the user.
35
- *
36
- * The argument of
37
- * {@link AgentManagerCallbacks.onConnectivityStateChange | onConnectivityStateChange}. It is
38
- * estimated from the session's own media statistics — jitter-buffer delay and freeze count for
39
- * Talks (V2) and Clips (V3), the transport's reported connection quality for Expressive (V4) — so
40
- * it reflects what this stream is actually getting rather than whether the browser is online.
41
- *
42
- * @category Callbacks & Events
43
- */
44
- export declare enum ConnectivityState {
45
- /** The stream is arriving smoothly. */
46
- Strong = "STRONG",
47
- /** The stream is degraded: video is stalling or arriving late. */
48
- Weak = "WEAK",
49
- /** There is not enough data to judge the connection yet, or the stream stopped arriving. */
50
- Unknown = "UNKNOWN"
51
- }
52
- /**
53
- * What the agent is doing right now, for driving the application's UI.
54
- *
55
- * The argument of
56
- * {@link AgentManagerCallbacks.onAgentActivityStateChange | onAgentActivityStateChange}. Expressive
57
- * (V4) agents move through all four states; Talks (V2) and Clips (V3) agents only alternate between
58
- * {@link AgentActivityState.Talking | TALKING} and {@link AgentActivityState.Idle | IDLE}, and only
59
- * on fluent streams.
60
- *
61
- * @category Callbacks & Events
62
- */
63
- export declare enum AgentActivityState {
64
- /** The agent is doing nothing and is waiting for the user — the conversational turn has ended. */
65
- Idle = "IDLE",
66
- /**
67
- * The agent is working on an answer that has not started streaming yet.
68
- *
69
- * Expressive (V4) only: set when a turn starts and when the user's speech has just been
70
- * transcribed. Use it for a typing or thinking indicator.
71
- */
72
- Loading = "LOADING",
73
- /** The agent's video has started; the agent is speaking. */
74
- Talking = "TALKING",
75
- /**
76
- * The agent is running one or more tool calls.
77
- *
78
- * Expressive (V4) only: set when a tool call starts, and returned to after the agent finishes
79
- * speaking while any call is still outstanding (for example a client tool waiting on the user).
80
- * The individual calls are reported by
81
- * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}.
82
- */
83
- ToolActive = "TOOL_ACTIVE"
84
- }
85
- /**
86
- * Every event the SDK receives on a stream's data channel or web socket.
87
- *
88
- * The three tool-call members are the only ones an application ever sees, and they reach it as
89
- * {@link ToolCallEvent} instead; the rest are consumed by the SDK and surfaced as callbacks.
90
- * @internal Implementation type; not part of the public SDK surface.
91
- */
92
- export declare enum StreamEvents {
93
- /**
94
- * The agent's complete answer for this turn; it becomes an `answer` message in the transcript.
95
- * @internal Consumed by the SDK; it surfaces as onNewMessage.
96
- */
97
- ChatAnswer = "chat/answer",
98
- /**
99
- * A fragment of the agent's answer as it is generated; it becomes a `partial` message.
100
- * @internal Consumed by the SDK; it surfaces as onNewMessage.
101
- */
102
- ChatPartial = "chat/partial",
103
- /**
104
- * The user's speech, transcribed by the server; it becomes a `user` message.
105
- * @internal Consumed by the SDK; it surfaces as onNewMessage.
106
- */
107
- ChatAudioTranscribed = "chat/audio-transcribed",
108
- /**
109
- * A video finished playing, or the session ended — which one depends on where it arrives.
110
- *
111
- * On the data channel of a Talks (V2) or Clips (V3) stream it closes the video
112
- * {@link StreamEvents.StreamStarted | 'stream/started'} opened, once per
113
- * {@link AgentManager.speak | speak()}, and drives
114
- * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange} with
115
- * {@link StreamingState.Stop | STOP} and
116
- * {@link AgentManagerCallbacks.onAgentActivityStateChange | onAgentActivityStateChange} with
117
- * {@link AgentActivityState.Idle | IDLE}.
118
- *
119
- * On the Talks (V2) and Clips (V3) web socket, and on an Expressive (V4) stream, it instead
120
- * ends the whole session: it carries the reason, which the SDK passes on as the `reason`
121
- * argument of {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange}
122
- * with {@link ConnectionState.Disconnected | 'disconnected'}. See {@link StreamEndReason}.
123
- * @internal Consumed by the SDK; it surfaces as onVideoStateChange or onConnectionStateChange.
124
- */
125
- StreamDone = "stream/done",
126
- /**
127
- * A video started playing on a Talks (V2) or Clips (V3) stream.
128
- * @internal Consumed by the SDK; it surfaces as onVideoStateChange.
129
- */
130
- StreamStarted = "stream/started",
131
- /**
132
- * The session ended because the stream failed.
133
- *
134
- * On the Talks (V2) and Clips (V3) web socket it is also reported through
135
- * {@link AgentManagerCallbacks.onError | onError}, as a {@link StreamError}.
136
- * @internal Consumed by the SDK; it surfaces as onError.
137
- */
138
- StreamFailed = "stream/error",
139
- /**
140
- * The warmup video has finished and the stream is ready for real content.
141
- *
142
- * Only sent when {@link StreamOptions.streamWarmup | streamWarmup} was requested.
143
- * @internal Consumed by the SDK; the application never sees it.
144
- */
145
- StreamReady = "stream/ready",
146
- /**
147
- * The video currently playing should stop.
148
- *
149
- * Sent by the SDK rather than received: it is the message
150
- * {@link AgentManager.interrupt | interrupt()} puts on the data channel of a fluent Talks (V2)
151
- * or Clips (V3) stream.
152
- * @internal Sent by the SDK; the application calls interrupt() instead.
153
- */
154
- StreamInterrupt = "stream/interrupt",
155
- /**
156
- * A video for one utterance started playing.
157
- * @internal Consumed by the SDK; it surfaces as onVideoStateChange.
158
- */
159
- StreamVideoCreated = "stream-video/started",
160
- /**
161
- * The video for one utterance finished playing.
162
- * @internal Consumed by the SDK; it surfaces as onVideoStateChange.
163
- */
164
- StreamVideoDone = "stream-video/done",
165
- /**
166
- * Generating or streaming the video for one utterance failed.
167
- * @internal Consumed by the SDK; it surfaces as onError.
168
- */
169
- StreamVideoError = "stream-video/error",
170
- /**
171
- * The server refused to generate the video for one utterance.
172
- * @internal Consumed by the SDK; it surfaces as onError.
173
- */
174
- StreamVideoRejected = "stream-video/rejected",
175
- /** The agent started a tool call; the payload is a {@link ToolCallStartedPayload}. */
176
- ToolCallStarted = "tool-call/started",
177
- /** A tool call finished successfully; the payload is a {@link ToolCallDonePayload}. */
178
- ToolCallDone = "tool-call/done",
179
- /** A tool call failed; the payload is a {@link ToolCallErrorPayload}. */
180
- ToolCallError = "tool-call/error",
181
- /**
182
- * A conversational turn started. Expressive (V4) only.
183
- * @internal Consumed by the SDK; it surfaces as onAgentActivityStateChange.
184
- */
185
- TurnStarted = "turn/started",
186
- /**
187
- * A conversational turn ended. Expressive (V4) only.
188
- * @internal Consumed by the SDK; it surfaces as onAgentActivityStateChange.
189
- */
190
- TurnEnded = "turn/ended"
191
- }
192
- /**
193
- * The tool-call events delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent}.
194
- *
195
- * Switch on the first argument of the handler to tell them apart: it narrows the second argument to
196
- * the payload that event carries — see {@link ToolEventCallback}. The members' values are the wire
197
- * strings the server sends, so compare against the enum rather than writing the string out.
198
- * Expressive (V4) agents only.
199
- *
200
- * @example
201
- * ```ts
202
- * import { ToolCallEvent } from '@d-id/client-sdk';
203
- *
204
- * const callbacks = {
205
- * onToolEvent(event, data) {
206
- * if (event === ToolCallEvent.Started) {
207
- * console.log('started', data.name, data.input);
208
- * }
209
- * },
210
- * };
211
- * ```
212
- * @category Callbacks & Events
213
- */
214
- export declare enum ToolCallEvent {
215
- /**
216
- * The agent has begun a tool call; the payload is a {@link ToolCallStartedPayload}, carrying the
217
- * call's id, the tool's name and the arguments the agent's LLM produced.
218
- */
219
- Started = "tool-call/started",
220
- /**
221
- * A tool call finished successfully; the payload is a {@link ToolCallDonePayload}, carrying the
222
- * result the tool returned and how long the call took.
223
- */
224
- Done = "tool-call/done",
225
- /**
226
- * A tool call failed; the payload is a {@link ToolCallErrorPayload}, carrying whatever the
227
- * server reported about the failure. The agent carries on with the conversation.
228
- */
229
- Error = "tool-call/error"
230
- }
231
- /**
232
- * The data-channel topics an application may send on with
233
- * {@link AgentManager.sendDataChannelMessage | sendDataChannelMessage()}.
234
- *
235
- * The remaining data-channel topics are driven by their own methods
236
- * ({@link AgentManager.chat | chat()}, {@link AgentManager.speak | speak()},
237
- * {@link AgentManager.interrupt | interrupt()},
238
- * {@link AgentManager.setSttLanguage | setSttLanguage()}), which own the payload shape and
239
- * bookkeeping those topics expect, so they stay internal.
240
- *
241
- * The members' values are the wire strings. Take the value from the enum rather than writing the
242
- * string out, so the wire string stays in one place. Expressive (V4) agents only.
243
- *
244
- * @example
245
- * ```ts
246
- * import { DataChannelTopic } from '@d-id/client-sdk';
247
- *
248
- * await agentManager.sendDataChannelMessage(DataChannelTopic.Presentation, {
249
- * type: 'navigate',
250
- * slide: 3,
251
- * });
252
- * ```
253
- * @category Agent Manager
254
- */
255
- export declare enum DataChannelTopic {
256
- /**
257
- * Messages that drive a presentation the agent is showing alongside its video, such as moving
258
- * to another slide. Sent on the wire as `did.presentation`; the payload shape is whatever the
259
- * presentation the agent is running expects.
260
- */
261
- Presentation = "did.presentation"
262
- }
263
- /**
264
- * The state of the connection between the browser and the agent's stream.
265
- *
266
- * The first argument of
267
- * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange}.
268
- * {@link ConnectionState.Connected | 'connected'} is the point at which
269
- * {@link AgentManager.chat | chat()} and {@link AgentManager.speak | speak()} can be called.
270
- *
271
- * Every agent type reports `'connecting'`, `'connected'`, `'fail'` and `'disconnected'`; `'new'`,
272
- * `'completed'` and `'closed'` are WebRTC ICE states that only Talks (V2) and Clips (V3) agents
273
- * reach, and `'disconnecting'` is Expressive (V4) only.
274
- *
275
- * @category Callbacks & Events
276
- */
277
- export declare enum ConnectionState {
278
- /** The connection object exists but nothing has been negotiated yet. */
279
- New = "new",
280
- /** The connection could not be established, or dropped irrecoverably. */
281
- Fail = "fail",
282
- /** The stream is live: the agent can be spoken to and its video rendered. */
283
- Connected = "connected",
284
- /** The connection is being established, or re-established after a drop. */
285
- Connecting = "connecting",
286
- /** The connection has been shut down and cannot be used again. */
287
- Closed = "closed",
288
- /**
289
- * Negotiation finished and the connection is fully established.
290
- *
291
- * It is reached after {@link ConnectionState.Connected | 'connected'}, so gate the application
292
- * on that one instead: it is the state every agent type reports.
293
- */
294
- Completed = "completed",
295
- /**
296
- * {@link AgentManager.disconnect | disconnect()} is in progress.
297
- *
298
- * Expressive (V4) agents only; Talks (V2) and Clips (V3) go straight from
299
- * {@link ConnectionState.Connected | 'connected'} to
300
- * {@link ConnectionState.Disconnected | 'disconnected'}.
301
- */
302
- Disconnecting = "disconnecting",
303
- /**
304
- * The stream has ended.
305
- *
306
- * The `reason` argument of
307
- * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} says why —
308
- * a {@link StreamEndReason} when the server ended the session deliberately. Reconnecting with
309
- * {@link AgentManager.reconnect | reconnect()} starts a new stream.
310
- */
311
- Disconnected = "disconnected"
312
- }
313
- /**
314
- * How the agent's idle and talking video are delivered.
315
- *
316
- * Returned by {@link AgentManager.getStreamType | getStreamType()}. Which one a session gets
317
- * follows from the agent and from {@link StreamOptions.fluent | fluent}.
318
- *
319
- * @category Streaming Options
320
- */
321
- export declare enum StreamType {
322
- /**
323
- * Two videos: the agent's idle video, which the application plays itself, and the streamed
324
- * talking video. Switch between them in
325
- * {@link AgentManagerCallbacks.onVideoStateChange | onVideoStateChange}.
326
- */
327
- Legacy = "legacy",
328
- /**
329
- * One continuous video for both the idle and the talking state, so there is nothing to swap.
330
- * Expressive (V4) agents always stream this way, and it is what makes
331
- * {@link AgentManager.interrupt | interrupt()} possible.
332
- */
333
- Fluent = "fluent"
334
- }
335
- /**
336
- * Handler for an RPC method registered on the LiveKit room before it connects.
337
- * @internal Implementation type; not part of the public SDK surface.
338
- */
339
- export type RpcMethodHandler = (data: {
340
- payload: string;
341
- }) => Promise<string>;
342
- /**
343
- * Identifiers of the stream the SDK has just opened for the session.
344
- *
345
- * Handed to {@link AgentManagerCallbacks.onStreamCreated | onStreamCreated} once the server has
346
- * accepted the stream, before the first video frame arrives. Log the three ids together: they are
347
- * what identifies the session in D-ID's own records.
348
- *
349
- * @category Callbacks & Events
350
- */
351
- export interface StreamCreatedInfo {
352
- /**
353
- * Id of the agent the stream was opened for.
354
- */
355
- agentId: string;
356
- /**
357
- * Id of the session; the SDK sends it back on every subsequent request for this stream.
358
- * On Expressive (V4) agents it is the same value as
359
- * {@link StreamCreatedInfo.streamId | streamId}.
360
- */
361
- sessionId: string;
362
- /**
363
- * Id of the stream itself.
364
- */
365
- streamId: string;
366
- }
367
- /**
368
- * Callback set consumed by the streaming managers (WebRTC and LiveKit).
369
- * The agent manager adapts these into the public {@link AgentManagerCallbacks}.
370
- * @internal Implementation type; not part of the public SDK surface.
371
- */
372
- export interface StreamingManagerCallbacks {
373
- onMessage?: ChatProgressCallback;
374
- onConnectionStateChange?: (state: ConnectionState, reason?: string) => void;
375
- onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
376
- onSrcObjectReady?: (value: MediaStream) => void;
377
- onError?: (error: Error, errorData: Record<string, unknown>) => void;
378
- onConnectivityStateChange?: (state: ConnectivityState) => void;
379
- onAgentActivityStateChange?: (state: AgentActivityState) => void;
380
- onVideoIdChange?: (videoId: string | null) => void;
381
- onStreamCreated?: (stream: StreamCreatedInfo) => void;
382
- onStreamReady?: () => void;
383
- onToolEvent?: ToolEventCallback;
384
- onInterruptibleChange?: (
385
- /** `true` while there is something to interrupt, `false` while there is not. */
386
- interruptible: boolean) => void;
387
- onRunningToolCallsChange?: (
388
- /** Every tool call running right now, empty when none is. */
389
- calls: readonly RunningToolCall[]) => void;
390
- onFirstAudioDetected?: (metrics: AudioDetectionMetrics) => void;
391
- }
392
- /**
393
- * Latency measurements captured when the first audio frame of a stream is detected.
394
- * @internal Implementation type; not part of the public SDK surface.
395
- */
396
- export interface AudioDetectionMetrics {
397
- latency?: number;
398
- networkLatency?: number;
399
- }
400
- /**
401
- * Union of callback names accepted by {@link StreamingManagerCallbacks}.
402
- * @internal Implementation type; not part of the public SDK surface.
403
- */
404
- export type ManagerCallbackKeys = keyof StreamingManagerCallbacks;
405
- /**
406
- * Custom end-user metadata attached to a stream creation request.
407
- * @internal Implementation type; not part of the public SDK surface.
408
- */
409
- export interface StreamEndUserData {
410
- plan?: string;
411
- }
412
- /**
413
- * Options for creating a legacy (talk) stream, combining the wire request with fluent-mode extras.
414
- * @internal Implementation type; not part of the public SDK surface.
415
- */
416
- export interface TalkStreamOptions extends CreateTalkStreamRequest {
417
- fluent?: boolean;
418
- end_user_data?: StreamEndUserData;
419
- }
420
- /**
421
- * Options for creating a clip stream, combining the wire request with fluent-mode extras.
422
- * @internal Implementation type; not part of the public SDK surface.
423
- */
424
- export interface ClipStreamOptions extends CreateClipStreamRequest {
425
- fluent?: boolean;
426
- end_user_data?: StreamEndUserData;
427
- }
428
- /**
429
- * Options accepted when creating a stream, discriminated by the underlying stream type (talk or clip).
430
- * @internal Implementation type; not part of the public SDK surface.
431
- */
432
- export type CreateStreamOptions = TalkStreamOptions | ClipStreamOptions;
433
- /**
434
- * Maps a {@link CreateStreamOptions} variant to the payload type sent to drive that stream.
435
- * @internal Implementation type; not part of the public SDK surface.
436
- */
437
- export type PayloadType<T> = T extends TalkStreamOptions ? SendTalkStreamPayload : T extends ClipStreamOptions ? SendClipStreamPayload : never;
438
- /**
439
- * HTTP client surface used by the streaming managers to create and drive a WebRTC stream.
440
- * @internal Implementation type; not part of the public SDK surface.
441
- */
442
- export interface RtcApi {
443
- createStream(options: CreateStreamOptions, signal?: AbortSignal): Promise<ICreateStreamRequestResponse>;
444
- startConnection(streamId: string, answer: RTCSessionDescriptionInit, sessionId?: string, signal?: AbortSignal): Promise<Status>;
445
- addIceCandidate(streamId: string, candidate: IceCandidate, sessionId: string, signal?: AbortSignal): Promise<Status>;
446
- sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload): Promise<SpeakResponse>;
447
- close(streamId: string, sessionId: string): Promise<Status>;
448
- }
449
- /**
450
- * Options used to construct a streaming manager (WebRTC or LiveKit) instance.
451
- * @internal Implementation type; not part of the public SDK surface.
452
- */
453
- export interface StreamingManagerOptions {
454
- callbacks: StreamingManagerCallbacks;
455
- baseURL?: string;
456
- debug?: boolean;
457
- verbose?: boolean;
458
- auth: Auth;
459
- analytics: Analytics;
460
- /**
461
- * RPC methods to register on the room before it connects, so the agent can
462
- * call them from the moment this participant joins.
463
- * @internal
464
- */
465
- rpcMethods?: ReadonlyMap<string, RpcMethodHandler>;
466
- }
467
- /**
468
- * Trimmed set of WebRTC inbound video stats sampled from `RTCStatsReport`, sampled for internal quality analytics.
469
- * @internal Implementation type; not part of the public SDK surface.
470
- */
471
- export interface SlimRTCStatsReport {
472
- index: number;
473
- codec: string;
474
- rtt: number;
475
- duration?: number;
476
- bitrate?: number;
477
- timestamp: any;
478
- bytesReceived: any;
479
- packetsReceived: any;
480
- packetsLost: any;
481
- framesDropped: any;
482
- framesDecoded: any;
483
- jitter: any;
484
- jitterBufferDelay: number;
485
- jitterBufferEmittedCount: number;
486
- avgJitterDelayInInterval: number;
487
- frameWidth: any;
488
- frameHeight: any;
489
- framesPerSecond: any;
490
- freezeCount: number;
491
- freezeDuration: number;
492
- av?: AvSyncSample;
493
- }
494
- /**
495
- * A single audio/video playout timestamp pair sampled during an utterance, used to compute lip-sync drift.
496
- * @internal Implementation type; not part of the public SDK surface.
497
- */
498
- export interface AvSyncSample {
499
- /** Audio estimatedPlayoutTimestamp (ms, NTP) — playout time of the audio sample currently being rendered. */
500
- audioPlayout: number;
501
- /** Video estimatedPlayoutTimestamp (ms, NTP) — playout time of the video frame currently being rendered. */
502
- videoPlayout: number;
503
- /** Local timestamp of this sample (ms) — the video inbound-rtp report timestamp; the utterance time axis. */
504
- localTs: number;
505
- }
506
- /**
507
- * Lip-sync (audio/video) drift analysis computed over an utterance's `AvSyncSample`s.
508
- * @internal Implementation type; not part of the public SDK surface.
509
- */
510
- export interface AvSyncReport {
511
- /** Measurable samples in this utterance (both audio and video playout present). Report is null if fewer than 2. */
512
- sampleCount: number;
513
- /** Measurement window in milliseconds (first to last sample). */
514
- durationMs: number;
515
- /** How long the A/V offset was perceptibly off (audio ahead > 45ms or behind > 100ms) — the "was there a lip-sync issue, and for how long" signal. */
516
- desyncDurationMs: number;
517
- /** The single worst offset (largest magnitude), signed. Positive = audio ahead of video, negative = video ahead. */
518
- maxOffsetMs: number;
519
- /** Settled offset after startup (signed median over the back half). ~0 = recovered; non-zero = persistent lip-sync error. */
520
- residualOffsetMs: number;
521
- }
522
- /**
523
- * WebRTC video stats reported to analytics (Mixpanel) at stream end.
524
- * @internal Implementation type; not part of the public SDK surface.
525
- */
526
- export interface AnalyticsRTCStatsReport {
527
- timestamp?: number;
528
- duration: number;
529
- bytesReceived: number;
530
- bitrate: number;
531
- packetsReceived: number;
532
- packetsLost: number;
533
- framesDropped: number;
534
- framesDecoded: number;
535
- jitter: number;
536
- jitterBufferDelay: number;
537
- jitterBufferEmittedCount: number;
538
- avgJitterDelayInInterval: number;
539
- framesPerSecond: number;
540
- freezeCount: number;
541
- freezeDuration: number;
542
- lowFpsCount?: number;
543
- causes?: string[];
544
- }
545
- /**
546
- * Data-channel payload notifying that the current stream utterance was interrupted.
547
- * @internal Implementation type; not part of the public SDK surface.
548
- */
549
- export interface StreamInterruptPayload {
550
- type: StreamEvents.StreamInterrupt;
551
- videoId: string;
552
- timestamp: number;
553
- }
554
- /**
555
- * A client tool's implementation: the function that runs in the browser when the agent calls it.
556
- *
557
- * Register it with {@link AgentManager.registerClientTool | registerClientTool()}, under the tool
558
- * name defined in the agent's configuration. The SDK parses the arguments the agent's LLM produced
559
- * and passes them in; whatever the handler resolves with is sent back to the agent as the tool's
560
- * result. Throwing rejects the call, and the error message is forwarded to the agent. Expressive
561
- * (V4) agents only.
562
- *
563
- * @param args - The arguments the LLM produced for this call, already parsed from JSON.
564
- * @returns A JSON string with the tool's result, at most 15 KiB — the LiveKit RPC response limit;
565
- * a larger result fails the call with an RPC error.
566
- * @example
567
- * ```ts
568
- * agentManager.registerClientTool('get_cart_total', async args => {
569
- * const total = await cart.total(args.currency as string);
570
- * return JSON.stringify({ total });
571
- * });
572
- * ```
573
- * @category Callbacks & Events
574
- */
575
- export type ClientToolHandler = (args: Record<string, unknown>) => Promise<string>;
576
- /**
577
- * Whether the agent waits for a tool call to finish before it carries on.
578
- *
579
- * Set on the agent's tool configuration, and reported on {@link RunningToolCall.executionMode} and
580
- * {@link ToolCallStartedPayload.executionMode}. Only a `blocking` call suspends the agent, which
581
- * is why one being outstanding is what makes the agent uninterruptible — see
582
- * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange}.
583
- *
584
- * @category Callbacks & Events
585
- */
586
- export type ToolExecutionMode = 'blocking' | 'async';
587
- /**
588
- * A tool call currently running in the session.
589
- *
590
- * The entries of the array given to
591
- * {@link AgentManagerCallbacks.onRunningToolCallsChange | onRunningToolCallsChange}. A call appears
592
- * when it starts and disappears when it finishes, fails, or — for a `blocking` call — when its turn
593
- * ends; an `async` call outlives its turn.
594
- *
595
- * @category Callbacks & Events
596
- */
597
- export interface RunningToolCall {
598
- /**
599
- * Id of this call, matching the {@link ToolCallStartedPayload.callId | callId} of the
600
- * {@link ToolCallStartedPayload} that announced it.
601
- */
602
- callId: string;
603
- /** Name of the tool being called, as configured on the agent. */
604
- name: string;
605
- /**
606
- * Whether the agent is suspended while this call runs.
607
- *
608
- * `blocking` means the agent waits for the result before it can continue; `async` means it
609
- * keeps talking while the call runs. See {@link ToolExecutionMode}.
610
- */
611
- executionMode: ToolExecutionMode;
612
- }
613
- /**
614
- * The payload of a {@link ToolCallEvent.Started} event: the agent has begun a tool call.
615
- *
616
- * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
617
- * {@link ToolEventCallback}.
618
- *
619
- * @category Callbacks & Events
620
- */
621
- export interface ToolCallStartedPayload {
622
- /** Id of this call. The matching done or error payload carries the same id. */
623
- callId: string;
624
- /** Name of the tool the agent is calling, as configured on the agent. */
625
- name: string;
626
- /** The arguments the agent's LLM produced for this call. */
627
- input: Record<string, unknown>;
628
- /** The tool's result. The started event is emitted before the tool has run, so it holds nothing useful yet. */
629
- output: Record<string, unknown>;
630
- /**
631
- * Whether the server considers the agent interruptible while this call is outstanding.
632
- *
633
- * Informational: the SDK does not forward it.
634
- * {@link AgentManagerCallbacks.onInterruptibleChange | onInterruptibleChange} is derived from
635
- * the {@link ToolCallStartedPayload.executionMode | executionMode} of the calls still
636
- * running, not from this field.
637
- */
638
- interruptible: boolean;
639
- /**
640
- * Whether the agent waits for this call. See {@link ToolExecutionMode}; anything other than
641
- * `async` is treated as `blocking`.
642
- */
643
- executionMode?: ToolExecutionMode;
644
- /** The conversational turn this call belongs to, or `null` when it belongs to no turn. */
645
- turnId?: number | null;
646
- /** When the call started, as reported by the server. */
647
- timestamp: string;
648
- }
649
- /**
650
- * The payload of a {@link ToolCallEvent.Done} event: a tool call finished successfully.
651
- *
652
- * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
653
- * {@link ToolEventCallback}.
654
- *
655
- * @category Callbacks & Events
656
- */
657
- export interface ToolCallDonePayload {
658
- /** Id of the call that finished, matching the {@link ToolCallStartedPayload} that announced it. */
659
- callId: string;
660
- /** Name of the tool that was called. */
661
- name: string;
662
- /** The arguments the call was made with. */
663
- input: Record<string, unknown>;
664
- /** The result the tool returned. */
665
- output: Record<string, unknown>;
666
- /** How long the call took, in milliseconds. */
667
- durationMs: number;
668
- /** Any additional metadata the tool reported alongside its result. */
669
- extra: Record<string, unknown>;
670
- /** When the call finished, as reported by the server. */
671
- timestamp: string;
672
- }
673
- /**
674
- * The payload of a {@link ToolCallEvent.Error} event: a tool call failed.
675
- *
676
- * Delivered to {@link AgentManagerCallbacks.onToolEvent | onToolEvent} — see
677
- * {@link ToolEventCallback}. The agent carries on with the conversation; the SDK does not retry.
678
- *
679
- * @category Callbacks & Events
680
- */
681
- export interface ToolCallErrorPayload {
682
- /** Id of the call that failed, matching the {@link ToolCallStartedPayload} that announced it. */
683
- callId: string;
684
- /** Name of the tool that was called. */
685
- name: string;
686
- /** The arguments the call was made with. */
687
- input: Record<string, unknown>;
688
- /** Whatever the failed call produced, if anything. */
689
- output: Record<string, unknown>;
690
- /** How long the call ran before failing, in milliseconds. */
691
- durationMs: number;
692
- /** Any additional metadata the server reported with the failure. */
693
- extra: Record<string, unknown>;
694
- /** When the call failed, as reported by the server. */
695
- timestamp: string;
696
- }
697
- /**
698
- * Union of the three tool-call payloads, narrowed away by the overloads on {@link ToolEventCallback}.
699
- * @internal Implementation type; not part of the public SDK surface.
700
- */
701
- export type ToolEventPayload = ToolCallStartedPayload | ToolCallDonePayload | ToolCallErrorPayload;
702
- /**
703
- * Data-channel wire shape of a `tool-call/started` event, converted to
704
- * {@link ToolCallStartedPayload} before it reaches the application.
705
- * @internal Wire type of the streaming transport; not part of the public SDK surface.
706
- */
707
- export interface ToolCallStartedWirePayload {
708
- call_id: string;
709
- name: string;
710
- input: Record<string, unknown>;
711
- output: Record<string, unknown>;
712
- interruptible?: boolean;
713
- execution_mode?: ToolExecutionMode;
714
- turn_id?: number | null;
715
- timestamp: string;
716
- }
717
- /**
718
- * Data-channel wire shape of a `tool-call/done` event, converted to {@link ToolCallDonePayload}
719
- * before it reaches the application.
720
- * @internal Wire type of the streaming transport; not part of the public SDK surface.
721
- */
722
- export interface ToolCallDoneWirePayload {
723
- call_id: string;
724
- name: string;
725
- input: Record<string, unknown>;
726
- output: Record<string, unknown>;
727
- duration_ms: number;
728
- extra: Record<string, unknown>;
729
- timestamp: string;
730
- }
731
- /**
732
- * Data-channel wire shape of a `tool-call/error` event, converted to {@link ToolCallErrorPayload}
733
- * before it reaches the application.
734
- * @internal Wire type of the streaming transport; not part of the public SDK surface.
735
- */
736
- export type ToolCallErrorWirePayload = ToolCallDoneWirePayload;
737
- /**
738
- * Data-channel payload identifying the conversational turn a `turn/started` or `turn/ended` event belongs to.
739
- * @internal Implementation type; not part of the public SDK surface.
740
- */
741
- export interface TurnEventPayload {
742
- turn_id: number | null;
743
- }
744
- /**
745
- * Why the server ended the session.
746
- *
747
- * Arrives as the `reason` argument of
748
- * {@link AgentManagerCallbacks.onConnectionStateChange | onConnectionStateChange} together with
749
- * {@link ConnectionState.Disconnected | 'disconnected'}, and is how you tell a session the server
750
- * closed on purpose from a connection that simply dropped — `reason` is an opaque transport
751
- * diagnostic in the latter case, so compare it against these values rather than parsing it. A
752
- * close reason the SDK does not recognise is forwarded as-is, which is the other reason to compare
753
- * against the enum. Which members can arrive depends on the agent type: Talks (V2) and Clips (V3)
754
- * agents report only {@link StreamEndReason.Ok | Ok},
755
- * {@link StreamEndReason.UnknownError | UnknownError},
756
- * {@link StreamEndReason.NetworkIssue | NetworkIssue} and
757
- * {@link StreamEndReason.Inactivity | Inactivity}.
758
- * {@link AgentManager.reconnect | reconnect()} still works afterwards; it starts a new stream
759
- * rather than resuming the ended one.
760
- *
761
- * @example Reacting to the limits an Expressive (V4) session reports
762
- * ```ts
763
- * import { ConnectionState, StreamEndReason } from '@d-id/client-sdk';
764
- *
765
- * const callbacks = {
766
- * onConnectionStateChange(state, reason) {
767
- * if (state !== ConnectionState.Disconnected) return;
768
- *
769
- * if (reason === StreamEndReason.TimeLimit || reason === StreamEndReason.MessageLimit) {
770
- * showMessage('This session has reached its limit.');
771
- * } else if (reason === StreamEndReason.Inactivity) {
772
- * showMessage('The session timed out.');
773
- * }
774
- * },
775
- * };
776
- * ```
777
- * @category Callbacks & Events
778
- */
779
- export declare enum StreamEndReason {
780
- /** The session ended normally, because it was closed deliberately. */
781
- Ok = "ok",
782
- /** The session ended because of a failure the server could not classify. */
783
- UnknownError = "unknown_error",
784
- /** The session ended because the connection to the browser broke down. */
785
- NetworkIssue = "network_issue",
786
- /**
787
- * The session ended because it reached the message limit configured for the agent.
788
- *
789
- * Expressive (V4) agents.
790
- */
791
- MessageLimit = "message_limit",
792
- /**
793
- * The session ended because it reached its maximum duration.
794
- *
795
- * Expressive (V4) agents.
796
- */
797
- TimeLimit = "time_limit",
798
- /**
799
- * The session ended because nothing happened for too long.
800
- *
801
- * The window is {@link StreamOptions.sessionTimeout | sessionTimeout} for Talks (V2) and
802
- * Clips (V3).
803
- */
804
- Inactivity = "inactivity",
805
- /**
806
- * The agent itself ended the call.
807
- *
808
- * Expressive (V4) agents.
809
- */
810
- EndedByAgent = "ended_by_agent"
811
- }
812
- /**
813
- * The overloaded handler type for
814
- * {@link AgentManagerCallbacks.onToolEvent | onToolEvent}: the event argument narrows the payload
815
- * argument.
816
- *
817
- * Three overloads, one per tool-call event, so the first argument narrows the second: a handler
818
- * written against this type sees exactly one of {@link ToolCallStartedPayload},
819
- * {@link ToolCallDonePayload} and {@link ToolCallErrorPayload}, never a union of the three.
820
- * Expressive (V4) agents only.
821
- *
822
- * @example
823
- * ```ts
824
- * import { ToolCallEvent } from '@d-id/client-sdk';
825
- *
826
- * const callbacks = {
827
- * onToolEvent(event, data) {
828
- * if (event === ToolCallEvent.Started) {
829
- * console.log('started', data.name, data.input);
830
- * } else if (event === ToolCallEvent.Done) {
831
- * console.log('done', data.name, data.output, data.durationMs);
832
- * } else {
833
- * console.log('failed', data.name, data.extra);
834
- * }
835
- * },
836
- * };
837
- * ```
838
- * @category Callbacks & Events
839
- */
840
- export type ToolEventCallback = {
841
- /**
842
- * @param event - Always {@link ToolCallEvent.Started} in this overload.
843
- * @param data - The call the agent has just begun, with the arguments its LLM produced.
844
- */
845
- (event: ToolCallEvent.Started, data: ToolCallStartedPayload): void;
846
- /**
847
- * @param event - Always {@link ToolCallEvent.Done} in this overload.
848
- * @param data - The call that has just finished, with the result the tool returned.
849
- */
850
- (event: ToolCallEvent.Done, data: ToolCallDonePayload): void;
851
- /**
852
- * @param event - Always {@link ToolCallEvent.Error} in this overload.
853
- * @param data - The call that has just failed, with whatever the server reported about it.
854
- */
855
- (event: ToolCallEvent.Error, data: ToolCallErrorPayload): void;
856
- };