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