@d-id/client-sdk 2.0.10 → 3.0.0-staging.412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -265
- package/dist/{index-K6rHpqny.js → index-BLrKDuV_.js} +3002 -2825
- package/dist/index.js +23 -31
- package/dist/index.umd.cjs +5 -5
- package/dist/{livekit-manager-25aUaO_G.js → livekit-manager-Cfb9x2ei.js} +53 -50
- package/dist/src/api/agents.d.ts +1 -1
- package/dist/src/api/apiClient.d.ts +1 -1
- package/dist/src/api/knowledge.d.ts +1 -1
- package/dist/src/api/streams/streamApi.d.ts +1 -1
- package/dist/src/api/streams/streamsApiV2.d.ts +1 -1
- package/dist/src/errors/base-error.d.ts +170 -1
- package/dist/src/errors/chat/chat-creation-failed.d.ts +24 -0
- package/dist/src/errors/chat/chat-mode-downgraded.d.ts +29 -0
- package/dist/src/errors/http-error.d.ts +67 -5
- package/dist/src/errors/index.d.ts +1 -0
- package/dist/src/errors/network-error.d.ts +62 -8
- package/dist/src/errors/request-meta.d.ts +12 -0
- package/dist/src/errors/stream-error.d.ts +32 -0
- package/dist/src/errors/validation-error.d.ts +62 -1
- package/dist/src/errors/ws-error.d.ts +29 -0
- package/dist/src/index.d.ts +18 -4
- package/dist/src/public-api.test.d.ts +1 -0
- package/dist/src/services/agent-manager/index.d.ts +46 -6
- package/dist/src/services/chat/intial-messages.test.d.ts +1 -0
- package/dist/src/services/streaming-manager/common.d.ts +8 -3
- package/dist/src/types/auth.d.ts +78 -6
- package/dist/src/types/entities/agents/agent.d.ts +152 -6
- package/dist/src/types/entities/agents/chat.d.ts +384 -12
- package/dist/src/types/entities/agents/manager.d.ts +795 -215
- package/dist/src/types/entities/avatar.d.ts +21 -0
- package/dist/src/types/entities/index.d.ts +1 -1
- package/dist/src/types/entities/knowledge/document.d.ts +7 -8
- package/dist/src/types/entities/knowledge/knowledge.d.ts +20 -0
- package/dist/src/types/entities/knowledge/record.d.ts +8 -0
- package/dist/src/types/entities/knowledge/retrival.d.ts +4 -0
- package/dist/src/types/stream/api/clip.d.ts +8 -9
- package/dist/src/types/stream/api/talk.d.ts +8 -9
- package/dist/src/types/stream/rtc.d.ts +54 -4
- package/dist/src/types/stream/stream.d.ts +553 -34
- package/dist/src/types/stream/streams-v2.d.ts +12 -0
- package/dist/src/types/stream-script.d.ts +92 -19
- package/dist/src/types/voice/stt.d.ts +12 -0
- package/dist/src/types/voice/tts.d.ts +149 -64
- package/dist/src/utils/analytics.d.ts +2 -2
- package/dist/src/utils/content-parser.d.ts +31 -0
- package/dist/src/utils/tool-calls.d.ts +21 -2
- package/dist/src/version.d.ts +6 -0
- package/package.json +7 -3
- package/dist/src/types/entities/video.d.ts +0 -6
|
@@ -3,115 +3,405 @@ import { VideoRTCStatsReport } from '../../services/streaming-manager/stats/repo
|
|
|
3
3
|
import { Auth } from '../auth';
|
|
4
4
|
import { ChatProgressCallback } from '../entities/agents/manager';
|
|
5
5
|
import { CreateClipStreamRequest, CreateTalkStreamRequest, SendClipStreamPayload, SendTalkStreamPayload } from './api';
|
|
6
|
-
import { DataChannelTopic } from './data-channel';
|
|
7
6
|
import { ICreateStreamRequestResponse, IceCandidate, SendStreamPayloadResponse, Status } from './rtc';
|
|
8
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
|
+
*/
|
|
9
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
|
+
*/
|
|
10
27
|
export declare enum StreamingState {
|
|
28
|
+
/** The agent has started speaking; render the streamed media. */
|
|
11
29
|
Start = "START",
|
|
30
|
+
/** The agent has finished speaking; the application can switch back to the idle video. */
|
|
12
31
|
Stop = "STOP"
|
|
13
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
|
+
*/
|
|
14
44
|
export declare enum ConnectivityState {
|
|
45
|
+
/** The stream is arriving smoothly. */
|
|
15
46
|
Strong = "STRONG",
|
|
47
|
+
/** The stream is degraded: video is stalling or arriving late. */
|
|
16
48
|
Weak = "WEAK",
|
|
49
|
+
/** There is not enough data to judge the connection yet, or the stream stopped arriving. */
|
|
17
50
|
Unknown = "UNKNOWN"
|
|
18
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
|
+
*/
|
|
19
63
|
export declare enum AgentActivityState {
|
|
64
|
+
/** The agent is doing nothing and is waiting for the user — the conversational turn has ended. */
|
|
20
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
|
+
*/
|
|
21
72
|
Loading = "LOADING",
|
|
73
|
+
/** The agent's video has started; the agent is speaking. */
|
|
22
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
|
+
*/
|
|
23
83
|
ToolActive = "TOOL_ACTIVE"
|
|
24
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
|
+
*/
|
|
25
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
|
+
*/
|
|
26
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
|
+
*/
|
|
27
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
|
+
*/
|
|
28
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
|
+
*/
|
|
29
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
|
+
*/
|
|
30
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
|
+
*/
|
|
31
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
|
+
*/
|
|
32
148
|
StreamReady = "stream/ready",
|
|
33
|
-
|
|
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
|
+
*/
|
|
34
157
|
StreamInterrupt = "stream/interrupt",
|
|
158
|
+
/**
|
|
159
|
+
* A video for one utterance started playing.
|
|
160
|
+
* @internal Consumed by the SDK; it surfaces as onVideoStateChange.
|
|
161
|
+
*/
|
|
35
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
|
+
*/
|
|
36
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
|
+
*/
|
|
37
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
|
+
*/
|
|
38
177
|
StreamVideoRejected = "stream-video/rejected",
|
|
178
|
+
/** The agent started a tool call; the payload is a {@link ToolCallStartedPayload}. */
|
|
39
179
|
ToolCallStarted = "tool-call/started",
|
|
180
|
+
/** A tool call finished successfully; the payload is a {@link ToolCallDonePayload}. */
|
|
40
181
|
ToolCallDone = "tool-call/done",
|
|
182
|
+
/** A tool call failed; the payload is a {@link ToolCallErrorPayload}. */
|
|
41
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
|
+
*/
|
|
42
188
|
TurnStarted = "turn/started",
|
|
189
|
+
/**
|
|
190
|
+
* A conversational turn ended. Expressive (V4) only.
|
|
191
|
+
* @internal Consumed by the SDK; it surfaces as onAgentActivityStateChange.
|
|
192
|
+
*/
|
|
43
193
|
TurnEnded = "turn/ended"
|
|
44
194
|
}
|
|
45
195
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* (`chat`, `speak`, `interrupt`, `setSttLanguage`), which own the payload shape
|
|
49
|
-
* and bookkeeping those topics expect, so they stay internal.
|
|
196
|
+
* The data-channel topics an application may send on with
|
|
197
|
+
* {@link AgentManager.sendDataChannelMessage | sendDataChannelMessage()}.
|
|
50
198
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
|
54
240
|
*/
|
|
55
|
-
export declare const PublicDataChannelTopic: {
|
|
56
|
-
readonly Presentation: DataChannelTopic.Presentation;
|
|
57
|
-
};
|
|
58
|
-
export type PublicDataChannelTopic = (typeof PublicDataChannelTopic)[keyof typeof PublicDataChannelTopic];
|
|
59
241
|
export declare enum ConnectionState {
|
|
242
|
+
/** The connection object exists but nothing has been negotiated yet. */
|
|
60
243
|
New = "new",
|
|
244
|
+
/** The connection could not be established, or dropped irrecoverably. */
|
|
61
245
|
Fail = "fail",
|
|
246
|
+
/** The stream is live: the agent can be spoken to and its video rendered. */
|
|
62
247
|
Connected = "connected",
|
|
248
|
+
/** The connection is being established, or re-established after a drop. */
|
|
63
249
|
Connecting = "connecting",
|
|
250
|
+
/** The connection has been shut down and cannot be used again. */
|
|
64
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
|
+
*/
|
|
65
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
|
+
*/
|
|
66
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
|
+
*/
|
|
67
275
|
Disconnected = "disconnected"
|
|
68
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
|
+
*/
|
|
69
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
|
+
*/
|
|
70
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
|
+
*/
|
|
71
297
|
Fluent = "fluent"
|
|
72
298
|
}
|
|
73
|
-
/**
|
|
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
|
+
*/
|
|
74
303
|
export type RpcMethodHandler = (data: {
|
|
75
304
|
payload: string;
|
|
76
305
|
}) => Promise<string>;
|
|
77
|
-
|
|
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 {
|
|
78
336
|
onMessage?: ChatProgressCallback;
|
|
79
337
|
onConnectionStateChange?: (state: ConnectionState, reason?: string) => void;
|
|
80
338
|
onVideoStateChange?: (state: StreamingState, report?: VideoRTCStatsReport) => void;
|
|
81
339
|
onSrcObjectReady?: (value: MediaStream) => void;
|
|
82
|
-
onError?: (error: Error, errorData:
|
|
340
|
+
onError?: (error: Error, errorData: Record<string, unknown>) => void;
|
|
83
341
|
onConnectivityStateChange?: (state: ConnectivityState) => void;
|
|
84
342
|
onAgentActivityStateChange?: (state: AgentActivityState) => void;
|
|
85
343
|
onVideoIdChange?: (videoId: string | null) => void;
|
|
86
|
-
onStreamCreated?: (stream:
|
|
87
|
-
stream_id: string;
|
|
88
|
-
session_id: string;
|
|
89
|
-
agent_id: string;
|
|
90
|
-
}) => void;
|
|
344
|
+
onStreamCreated?: (stream: StreamCreatedInfo) => void;
|
|
91
345
|
onStreamReady?: () => void;
|
|
92
346
|
onToolEvent?: ToolEventCallback;
|
|
93
|
-
onInterruptibleChange?: (
|
|
94
|
-
|
|
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;
|
|
95
353
|
onFirstAudioDetected?: (metrics: AudioDetectionMetrics) => void;
|
|
96
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
|
+
*/
|
|
97
359
|
export interface AudioDetectionMetrics {
|
|
98
360
|
latency?: number;
|
|
99
361
|
networkLatency?: number;
|
|
100
362
|
}
|
|
101
|
-
|
|
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
|
+
*/
|
|
102
372
|
export interface StreamEndUserData {
|
|
103
373
|
plan?: string;
|
|
104
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
|
+
*/
|
|
105
379
|
export interface TalkStreamOptions extends CreateTalkStreamRequest {
|
|
106
380
|
fluent?: boolean;
|
|
107
381
|
end_user_data?: StreamEndUserData;
|
|
108
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
|
+
*/
|
|
109
387
|
export interface ClipStreamOptions extends CreateClipStreamRequest {
|
|
110
388
|
fluent?: boolean;
|
|
111
389
|
end_user_data?: StreamEndUserData;
|
|
112
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
|
+
*/
|
|
113
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
|
+
*/
|
|
114
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
|
+
*/
|
|
115
405
|
export interface RtcApi {
|
|
116
406
|
createStream(options: CreateStreamOptions, signal?: AbortSignal): Promise<ICreateStreamRequestResponse>;
|
|
117
407
|
startConnection(streamId: string, answer: RTCSessionDescriptionInit, sessionId?: string, signal?: AbortSignal): Promise<Status>;
|
|
@@ -119,19 +409,17 @@ export interface RtcApi {
|
|
|
119
409
|
sendStreamRequest(streamId: string, sessionId: string, payload: SendClipStreamPayload | SendTalkStreamPayload): Promise<SendStreamPayloadResponse>;
|
|
120
410
|
close(streamId: string, sessionId: string): Promise<Status>;
|
|
121
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
|
+
*/
|
|
122
416
|
export interface StreamingManagerOptions {
|
|
123
|
-
callbacks:
|
|
417
|
+
callbacks: StreamingManagerCallbacks;
|
|
124
418
|
baseURL?: string;
|
|
125
419
|
debug?: boolean;
|
|
126
420
|
verbose?: boolean;
|
|
127
421
|
auth: Auth;
|
|
128
422
|
analytics: Analytics;
|
|
129
|
-
/**
|
|
130
|
-
* Optional MediaStream to use for microphone input.
|
|
131
|
-
* If provided, the audio track from this stream will be published to the data channel.
|
|
132
|
-
* Supported by LiveKit streaming managers.
|
|
133
|
-
*/
|
|
134
|
-
microphoneStream?: MediaStream;
|
|
135
423
|
/**
|
|
136
424
|
* RPC methods to register on the room before it connects, so the agent can
|
|
137
425
|
* call them from the moment this participant joins.
|
|
@@ -139,6 +427,10 @@ export interface StreamingManagerOptions {
|
|
|
139
427
|
*/
|
|
140
428
|
rpcMethods?: ReadonlyMap<string, RpcMethodHandler>;
|
|
141
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
|
+
*/
|
|
142
434
|
export interface SlimRTCStatsReport {
|
|
143
435
|
index: number;
|
|
144
436
|
codec: string;
|
|
@@ -162,6 +454,10 @@ export interface SlimRTCStatsReport {
|
|
|
162
454
|
freezeDuration: number;
|
|
163
455
|
av?: AvSyncSample;
|
|
164
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
|
+
*/
|
|
165
461
|
export interface AvSyncSample {
|
|
166
462
|
/** Audio estimatedPlayoutTimestamp (ms, NTP) — playout time of the audio sample currently being rendered. */
|
|
167
463
|
audioPlayout: number;
|
|
@@ -170,6 +466,10 @@ export interface AvSyncSample {
|
|
|
170
466
|
/** Local timestamp of this sample (ms) — the video inbound-rtp report timestamp; the utterance time axis. */
|
|
171
467
|
localTs: number;
|
|
172
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
|
+
*/
|
|
173
473
|
export interface AvSyncReport {
|
|
174
474
|
/** Measurable samples in this utterance (both audio and video playout present). Report is null if fewer than 2. */
|
|
175
475
|
sampleCount: number;
|
|
@@ -182,6 +482,10 @@ export interface AvSyncReport {
|
|
|
182
482
|
/** Settled offset after startup (signed median over the back half). ~0 = recovered; non-zero = persistent lip-sync error. */
|
|
183
483
|
residualOffsetMs: number;
|
|
184
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
|
+
*/
|
|
185
489
|
export interface AnalyticsRTCStatsReport {
|
|
186
490
|
timestamp?: number;
|
|
187
491
|
duration: number;
|
|
@@ -201,66 +505,281 @@ export interface AnalyticsRTCStatsReport {
|
|
|
201
505
|
lowFpsCount?: number;
|
|
202
506
|
causes?: string[];
|
|
203
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
|
+
*/
|
|
204
512
|
export interface StreamInterruptPayload {
|
|
205
513
|
type: StreamEvents.StreamInterrupt;
|
|
206
514
|
videoId: string;
|
|
207
515
|
timestamp: number;
|
|
208
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
|
+
*/
|
|
209
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
|
+
*/
|
|
210
549
|
export type ToolExecutionMode = 'blocking' | 'async';
|
|
211
|
-
/**
|
|
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
|
+
*/
|
|
212
564
|
export interface RunningToolCall {
|
|
565
|
+
/** Id of this call, matching the `call_id` of the {@link ToolCallStartedPayload} that announced it. */
|
|
213
566
|
callId: string;
|
|
567
|
+
/** Name of the tool being called, as configured on the agent. */
|
|
214
568
|
name: string;
|
|
215
569
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
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}.
|
|
218
574
|
*/
|
|
219
575
|
executionMode: ToolExecutionMode;
|
|
220
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
|
+
*/
|
|
221
585
|
export interface ToolCallStartedPayload {
|
|
586
|
+
/** Id of this call. The matching done or error payload carries the same id. */
|
|
222
587
|
call_id: string;
|
|
588
|
+
/** Name of the tool the agent is calling, as configured on the agent. */
|
|
223
589
|
name: string;
|
|
590
|
+
/** The arguments the agent's LLM produced for this call. */
|
|
224
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. */
|
|
225
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
|
+
*/
|
|
226
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
|
+
*/
|
|
227
607
|
execution_mode?: ToolExecutionMode;
|
|
608
|
+
/** The conversational turn this call belongs to, or `null` when it belongs to no turn. */
|
|
228
609
|
turn_id?: number | null;
|
|
610
|
+
/** When the call started, as reported by the server. */
|
|
229
611
|
timestamp: string;
|
|
230
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
|
+
*/
|
|
231
621
|
export interface ToolCallDonePayload {
|
|
622
|
+
/** Id of the call that finished, matching the {@link ToolCallStartedPayload} that announced it. */
|
|
232
623
|
call_id: string;
|
|
624
|
+
/** Name of the tool that was called. */
|
|
233
625
|
name: string;
|
|
626
|
+
/** The arguments the call was made with. */
|
|
234
627
|
input: Record<string, unknown>;
|
|
628
|
+
/** The result the tool returned. */
|
|
235
629
|
output: Record<string, unknown>;
|
|
630
|
+
/** How long the call took, in milliseconds. */
|
|
236
631
|
duration_ms: number;
|
|
632
|
+
/** Any additional metadata the tool reported alongside its result. */
|
|
237
633
|
extra: Record<string, unknown>;
|
|
634
|
+
/** When the call finished, as reported by the server. */
|
|
238
635
|
timestamp: string;
|
|
239
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
|
+
*/
|
|
240
645
|
export interface ToolCallErrorPayload {
|
|
646
|
+
/** Id of the call that failed, matching the {@link ToolCallStartedPayload} that announced it. */
|
|
241
647
|
call_id: string;
|
|
648
|
+
/** Name of the tool that was called. */
|
|
242
649
|
name: string;
|
|
650
|
+
/** The arguments the call was made with. */
|
|
243
651
|
input: Record<string, unknown>;
|
|
652
|
+
/** Whatever the failed call produced, if anything. */
|
|
244
653
|
output: Record<string, unknown>;
|
|
654
|
+
/** How long the call ran before failing, in milliseconds. */
|
|
245
655
|
duration_ms: number;
|
|
656
|
+
/** Any additional metadata the server reported with the failure. */
|
|
246
657
|
extra: Record<string, unknown>;
|
|
658
|
+
/** When the call failed, as reported by the server. */
|
|
247
659
|
timestamp: string;
|
|
248
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
|
+
*/
|
|
249
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
|
+
*/
|
|
250
670
|
export interface TurnEventPayload {
|
|
251
671
|
turn_id: number | null;
|
|
252
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
|
+
*/
|
|
253
708
|
export declare enum StreamEndReason {
|
|
709
|
+
/** The session ended normally, because it was closed deliberately. */
|
|
254
710
|
Ok = "ok",
|
|
711
|
+
/** The session ended because of a failure the server could not classify. */
|
|
255
712
|
UnknownError = "unknown_error",
|
|
713
|
+
/** The session ended because the connection to the browser broke down. */
|
|
256
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
|
+
*/
|
|
257
720
|
MessageLimit = "message_limit",
|
|
721
|
+
/**
|
|
722
|
+
* The session ended because it reached its maximum duration.
|
|
723
|
+
*
|
|
724
|
+
* Expressive (V4) agents.
|
|
725
|
+
*/
|
|
258
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
|
+
*/
|
|
259
733
|
Inactivity = "inactivity",
|
|
734
|
+
/**
|
|
735
|
+
* The agent itself ended the call.
|
|
736
|
+
*
|
|
737
|
+
* Expressive (V4) agents.
|
|
738
|
+
*/
|
|
260
739
|
EndedByAgent = "ended_by_agent"
|
|
261
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
|
+
*/
|
|
262
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
|
+
*/
|
|
263
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
|
+
*/
|
|
264
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
|
+
*/
|
|
265
784
|
(event: StreamEvents.ToolCallError, data: ToolCallErrorPayload): void;
|
|
266
785
|
};
|