@d-id/client-sdk 2.0.10 → 3.0.0-staging.413

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 (49) hide show
  1. package/README.md +54 -265
  2. package/dist/{index-K6rHpqny.js → index-BOeL7MEm.js} +3002 -2825
  3. package/dist/index.js +23 -31
  4. package/dist/index.umd.cjs +5 -5
  5. package/dist/{livekit-manager-25aUaO_G.js → livekit-manager-D-B3qdMq.js} +53 -50
  6. package/dist/src/api/agents.d.ts +1 -1
  7. package/dist/src/api/apiClient.d.ts +1 -1
  8. package/dist/src/api/knowledge.d.ts +1 -1
  9. package/dist/src/api/streams/streamApi.d.ts +1 -1
  10. package/dist/src/api/streams/streamsApiV2.d.ts +1 -1
  11. package/dist/src/errors/base-error.d.ts +170 -1
  12. package/dist/src/errors/chat/chat-creation-failed.d.ts +24 -0
  13. package/dist/src/errors/chat/chat-mode-downgraded.d.ts +29 -0
  14. package/dist/src/errors/http-error.d.ts +67 -5
  15. package/dist/src/errors/index.d.ts +1 -0
  16. package/dist/src/errors/network-error.d.ts +62 -8
  17. package/dist/src/errors/request-meta.d.ts +12 -0
  18. package/dist/src/errors/stream-error.d.ts +32 -0
  19. package/dist/src/errors/validation-error.d.ts +62 -1
  20. package/dist/src/errors/ws-error.d.ts +29 -0
  21. package/dist/src/index.d.ts +18 -4
  22. package/dist/src/public-api.test.d.ts +1 -0
  23. package/dist/src/services/agent-manager/index.d.ts +46 -6
  24. package/dist/src/services/chat/intial-messages.test.d.ts +1 -0
  25. package/dist/src/services/streaming-manager/common.d.ts +8 -3
  26. package/dist/src/types/auth.d.ts +78 -6
  27. package/dist/src/types/entities/agents/agent.d.ts +152 -6
  28. package/dist/src/types/entities/agents/chat.d.ts +384 -12
  29. package/dist/src/types/entities/agents/manager.d.ts +795 -215
  30. package/dist/src/types/entities/avatar.d.ts +21 -0
  31. package/dist/src/types/entities/index.d.ts +1 -1
  32. package/dist/src/types/entities/knowledge/document.d.ts +7 -8
  33. package/dist/src/types/entities/knowledge/knowledge.d.ts +20 -0
  34. package/dist/src/types/entities/knowledge/record.d.ts +8 -0
  35. package/dist/src/types/entities/knowledge/retrival.d.ts +4 -0
  36. package/dist/src/types/stream/api/clip.d.ts +8 -9
  37. package/dist/src/types/stream/api/talk.d.ts +8 -9
  38. package/dist/src/types/stream/rtc.d.ts +54 -4
  39. package/dist/src/types/stream/stream.d.ts +553 -34
  40. package/dist/src/types/stream/streams-v2.d.ts +12 -0
  41. package/dist/src/types/stream-script.d.ts +92 -19
  42. package/dist/src/types/voice/stt.d.ts +12 -0
  43. package/dist/src/types/voice/tts.d.ts +149 -64
  44. package/dist/src/utils/analytics.d.ts +2 -2
  45. package/dist/src/utils/content-parser.d.ts +31 -0
  46. package/dist/src/utils/tool-calls.d.ts +21 -2
  47. package/dist/src/version.d.ts +6 -0
  48. package/package.json +7 -3
  49. package/dist/src/types/entities/video.d.ts +0 -6
@@ -1,4 +1,4 @@
1
- import { c as Qe, C as J, S as l, a as We, b as qe, A as C, d as Ge, l as pe, e as He, t as Xe, f as A, g as U, h as Ze, D as me, i as Ye, j as b, n as en } from "./index-K6rHpqny.js";
1
+ import { c as Qe, C as J, S as l, a as We, b as qe, A as C, d as Ge, l as pe, e as He, t as Xe, f as E, g as U, h as Ze, D as me, i as Ye, j as b, n as en } from "./index-BOeL7MEm.js";
2
2
  function nn() {
3
3
  try {
4
4
  return Intl.DateTimeFormat().resolvedOptions().timeZone ?? "";
@@ -35,7 +35,7 @@ const an = {
35
35
  }, Ce = 2e4, cn = [];
36
36
  async function sn() {
37
37
  try {
38
- return await import("./index-K6rHpqny.js").then((f) => f.G);
38
+ return await import("./index-BOeL7MEm.js").then((f) => f.y);
39
39
  } catch {
40
40
  throw new Error(
41
41
  "LiveKit client is required for this streaming manager. Please install it using: npm install livekit-client"
@@ -51,12 +51,12 @@ const un = {
51
51
  }, j = (f = "Stream Error") => new He(f);
52
52
  function Se(f, S, u) {
53
53
  var i, k;
54
- throw S("Failed to connect to LiveKit room:", f), (i = u.onConnectionStateChange) == null || i.call(u, A.Fail, "internal:init-error"), (k = u.onError) == null || k.call(u, f, { sessionId: "" }), f;
54
+ throw S("Failed to connect to LiveKit room:", f), (i = u.onConnectionStateChange) == null || i.call(u, E.Fail, "internal:init-error"), (k = u.onError) == null || k.call(u, f, { sessionId: "" }), f;
55
55
  }
56
56
  async function ln(f, S, u) {
57
57
  var de;
58
- const i = We(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: g, ConnectionState: I, Track: ee } = await sn(), { callbacks: n, auth: Te, baseURL: ve, analytics: ne } = u;
59
- let a = null, E = !1;
58
+ const i = We(u.debug || !1, "LiveKitStreamingManager"), { Room: k, RoomEvent: g, ConnectionState: I, Track: ee } = await sn(), { callbacks: n, auth: Te, baseURL: ye, analytics: ne } = u;
59
+ let a = null, w = !1;
60
60
  const te = qe.Fluent;
61
61
  let L = null;
62
62
  const P = { isPublishing: !1, publication: null }, Q = { isPublishing: !1, publication: null };
@@ -69,21 +69,21 @@ async function ln(f, S, u) {
69
69
  for (const [e, t] of u.rpcMethods ?? [])
70
70
  a.registerRpcMethod(e, t);
71
71
  let R = null, M = C.Idle, W = !0;
72
- const v = /* @__PURE__ */ new Map();
72
+ const y = /* @__PURE__ */ new Map();
73
73
  let x = null, q = null;
74
- const ye = rn(Te, ve || Ge, f, n.onError);
75
- let y, _, $, ie = !0;
74
+ const ve = rn(Te, ye || Ge, f, n.onError);
75
+ let v, _, $, ie = !0;
76
76
  try {
77
- const e = await ye.createStream({
77
+ const e = await ve.createStream({
78
78
  transport: S.transport,
79
- chat_persist: S.chat_persist ?? !0,
79
+ chat_persist: S.chat_persist ?? !1,
80
80
  verbose: u.verbose ?? !1
81
81
  }), { id: t, session_token: o, session_url: r, interrupt_enabled: c } = e;
82
- (de = n.onStreamCreated) == null || de.call(n, { session_id: t, stream_id: t, agent_id: f }), y = t, _ = o, $ = r, ie = c ?? !0, await a.prepareConnection($, _);
82
+ (de = n.onStreamCreated) == null || de.call(n, { session_id: t, stream_id: t, agent_id: f }), v = t, _ = o, $ = r, ie = c ?? !0, await a.prepareConnection($, _);
83
83
  } catch (e) {
84
84
  Se(e, i, n);
85
85
  }
86
- if (!$ || !_ || !y)
86
+ if (!$ || !_ || !v)
87
87
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
88
88
  a.on(g.ConnectionStateChanged, Ee).on(g.ConnectionQualityChanged, Re).on(g.ParticipantConnected, be).on(g.ParticipantDisconnected, Le).on(g.TrackSubscribed, Me).on(g.TrackUnsubscribed, ke).on(g.DataReceived, Ve).on(g.MediaDevicesError, Fe).on(g.TranscriptionReceived, we).on(g.EncryptionError, Ue).on(g.TrackSubscriptionFailed, je);
89
89
  function we(e, t) {
@@ -107,8 +107,8 @@ async function ln(f, S, u) {
107
107
  const e = j("Track subscription timeout");
108
108
  ne.track("connectivity-error", {
109
109
  error: Xe(e),
110
- sessionId: y
111
- }), (t = n.onError) == null || t.call(n, e, { sessionId: y }), Y("internal:track-subscription-timeout");
110
+ sessionId: v
111
+ }), (t = n.onError) == null || t.call(n, e, { sessionId: v }), Y("internal:track-subscription-timeout");
112
112
  }, Ce);
113
113
  } catch (e) {
114
114
  Se(e, i, n);
@@ -120,23 +120,23 @@ async function ln(f, S, u) {
120
120
  var t, o, r, c;
121
121
  switch (i("Connection state changed:", e), e) {
122
122
  case I.Connecting:
123
- i("CALLBACK: onConnectionStateChange(Connecting)"), (t = n.onConnectionStateChange) == null || t.call(n, A.Connecting, "livekit:connecting");
123
+ i("CALLBACK: onConnectionStateChange(Connecting)"), (t = n.onConnectionStateChange) == null || t.call(n, E.Connecting, "livekit:connecting");
124
124
  break;
125
125
  case I.Connected:
126
- i("LiveKit room connected successfully"), E = !0;
126
+ i("LiveKit room connected successfully"), w = !0;
127
127
  break;
128
128
  case I.Disconnected:
129
- i("LiveKit room disconnected"), E = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(
129
+ i("LiveKit room disconnected"), w = !1, K = !1, P.publication = null, Q.publication = null, (o = n.onConnectionStateChange) == null || o.call(
130
130
  n,
131
- A.Disconnected,
131
+ E.Disconnected,
132
132
  q ?? "livekit:disconnected"
133
133
  );
134
134
  break;
135
135
  case I.Reconnecting:
136
- i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, A.Connecting, "livekit:reconnecting");
136
+ i("LiveKit room reconnecting..."), (r = n.onConnectionStateChange) == null || r.call(n, E.Connecting, "livekit:reconnecting");
137
137
  break;
138
138
  case I.SignalReconnecting:
139
- i("LiveKit room signal reconnecting..."), (c = n.onConnectionStateChange) == null || c.call(n, A.Connecting, "livekit:signal-reconnecting");
139
+ i("LiveKit room signal reconnecting..."), (c = n.onConnectionStateChange) == null || c.call(n, E.Connecting, "livekit:signal-reconnecting");
140
140
  break;
141
141
  }
142
142
  }
@@ -176,12 +176,12 @@ async function ln(f, S, u) {
176
176
  const ge = ((fe = (le = p == null ? void 0 : p.getReport()) == null ? void 0 : le.webRTCStats) == null ? void 0 : fe.avgRtt) ?? 0;
177
177
  F = ge > 0 ? Math.round(ge * 1e3) : 0;
178
178
  }
179
- const D = V > 0 ? V + (h ?? 0) + F : void 0, w = D !== void 0 && m !== void 0 ? D - m : void 0;
180
- (he = n.onFirstAudioDetected) == null || he.call(n, { latency: D, networkLatency: w });
179
+ const D = V > 0 ? V + (h ?? 0) + F : void 0, A = D !== void 0 && m !== void 0 ? D - m : void 0;
180
+ (he = n.onFirstAudioDetected) == null || he.call(n, { latency: D, networkLatency: A });
181
181
  }
182
- )), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, A.Connected, "livekit:track-subscribed")), p = Ze(
182
+ )), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (d = n.onSrcObjectReady) == null || d.call(n, L), K || (K = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (s = n.onConnectionStateChange) == null || s.call(n, E.Connected, "livekit:track-subscribed")), p = Ze(
183
183
  () => e.getRTCStatsReport(),
184
- () => E,
184
+ () => w,
185
185
  en,
186
186
  (h, m) => {
187
187
  i(`Video state change: ${h}`), h === b.Start ? (R && (clearTimeout(R), R = null, i("Track subscription timeout cleared")), Pe()) : h === b.Stop && oe(m);
@@ -200,7 +200,7 @@ async function ln(f, S, u) {
200
200
  var o, r, c, d;
201
201
  if (e === l.ToolCallStarted) {
202
202
  const s = t;
203
- v.set(s.call_id, {
203
+ y.set(s.call_id, {
204
204
  call: {
205
205
  callId: s.call_id,
206
206
  name: s.name,
@@ -222,24 +222,24 @@ async function ln(f, S, u) {
222
222
  }
223
223
  }
224
224
  function ae(e) {
225
- v.delete(e) && (N(), z());
225
+ y.delete(e) && (N(), z());
226
226
  }
227
227
  function Ie(e) {
228
228
  let t = !1;
229
- for (const [o, r] of v)
230
- r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (v.delete(o), t = !0));
229
+ for (const [o, r] of y)
230
+ r.call.executionMode === "blocking" && (e !== null && r.turnId !== null && r.turnId !== e || (y.delete(o), t = !0));
231
231
  t && (N(), z());
232
232
  }
233
233
  function N() {
234
234
  var t;
235
- const e = ![...v.values()].some(({ call: o }) => o.executionMode === "blocking");
235
+ const e = ![...y.values()].some(({ call: o }) => o.executionMode === "blocking");
236
236
  e !== W && (W = e, (t = n.onInterruptibleChange) == null || t.call(n, e));
237
237
  }
238
238
  function z() {
239
239
  var e;
240
240
  (e = n.onRunningToolCallsChange) == null || e.call(
241
241
  n,
242
- v.size === 0 ? cn : [...v.values()].map(({ call: t }) => t)
242
+ y.size === 0 ? cn : [...y.values()].map(({ call: t }) => t)
243
243
  );
244
244
  }
245
245
  function _e(e, t) {
@@ -251,7 +251,7 @@ async function ln(f, S, u) {
251
251
  });
252
252
  return;
253
253
  }
254
- if (v.size > 0) {
254
+ if (y.size > 0) {
255
255
  M !== C.ToolActive && (M = C.ToolActive, (c = n.onAgentActivityStateChange) == null || c.call(n, C.ToolActive));
256
256
  return;
257
257
  }
@@ -320,11 +320,11 @@ async function ln(f, S, u) {
320
320
  }
321
321
  function Fe(e) {
322
322
  var t;
323
- i("Media devices error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: y });
323
+ i("Media devices error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
324
324
  }
325
325
  function Ue(e) {
326
326
  var t;
327
- i("Encryption error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: y });
327
+ i("Encryption error:", e), (t = n.onError) == null || t.call(n, j(), { sessionId: v });
328
328
  }
329
329
  function je(e, t, o) {
330
330
  i("Track subscription failed:", { trackSid: e, participant: t, reason: o });
@@ -340,7 +340,7 @@ async function ln(f, S, u) {
340
340
  }
341
341
  async function se(e, t, o, r, c, d) {
342
342
  var V, F, D;
343
- if (!E || !a)
343
+ if (!w || !a)
344
344
  throw i(`Room is not connected, cannot publish ${r} stream`), new Error("Room is not connected");
345
345
  if (e.isPublishing) {
346
346
  i(`${r} publish already in progress, skipping`);
@@ -358,14 +358,14 @@ async function ln(f, S, u) {
358
358
  return;
359
359
  }
360
360
  if ((D = e.publication) != null && D.track) {
361
- const w = e.publication.track.mediaStreamTrack;
362
- w !== h && (w == null ? void 0 : w.id) !== h.id && (i(`Unpublishing existing ${r} track before publishing new one`), await d());
361
+ const A = e.publication.track.mediaStreamTrack;
362
+ A !== h && (A == null ? void 0 : A.id) !== h.id && (i(`Unpublishing existing ${r} track before publishing new one`), await d());
363
363
  }
364
364
  i(`Publishing ${r} track from provided MediaStream`, { trackId: h.id }), e.isPublishing = !0;
365
365
  try {
366
366
  e.publication = await a.localParticipant.publishTrack(h, { source: r }), i(`${r} track published successfully`, { trackSid: e.publication.trackSid });
367
- } catch (w) {
368
- throw i(`Failed to publish ${r} track:`, w), w;
367
+ } catch (A) {
368
+ throw i(`Failed to publish ${r} track:`, A), A;
369
369
  } finally {
370
370
  e.isPublishing = !1;
371
371
  }
@@ -394,7 +394,7 @@ async function ln(f, S, u) {
394
394
  return ue(P, "Microphone");
395
395
  }
396
396
  async function ze(e) {
397
- if (!E || !a)
397
+ if (!w || !a)
398
398
  throw i("Cannot replace microphone track: room is not connected"), new Error("Room is not connected");
399
399
  if (e.kind !== "audio")
400
400
  throw i("Cannot replace microphone track: not an audio track", { kind: e.kind }), new Error("Microphone track must be an audio track");
@@ -427,21 +427,21 @@ async function ln(f, S, u) {
427
427
  }
428
428
  async function Z(e, t) {
429
429
  var o, r;
430
- if (!E || !a) {
430
+ if (!w || !a) {
431
431
  i("Room is not connected for sending messages"), (o = n.onError) == null || o.call(n, j(), {
432
- sessionId: y
432
+ sessionId: v
433
433
  });
434
434
  return;
435
435
  }
436
436
  try {
437
437
  await a.localParticipant.sendText(t, { topic: e }), i("Message sent successfully:", t);
438
438
  } catch (c) {
439
- i("Failed to send message:", c), (r = n.onError) == null || r.call(n, j(), { sessionId: y });
439
+ i("Failed to send message:", c), (r = n.onError) == null || r.call(n, j(), { sessionId: v });
440
440
  }
441
441
  }
442
442
  async function Y(e) {
443
443
  var t, o;
444
- R && (clearTimeout(R), R = null), T == null || T.destroy(), T = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, A.Disconnecting, e), await Promise.all([H(), X()]), await a.disconnect()), Je(), E = !1, K = !1, v.size > 0 && (v.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Idle), M = C.Idle;
444
+ R && (clearTimeout(R), R = null), T == null || T.destroy(), T = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, E.Disconnecting, e), await Promise.all([H(), X()]), await a.disconnect()), Je(), w = !1, K = !1, y.size > 0 && (y.clear(), N(), z()), x = null, (o = n.onAgentActivityStateChange) == null || o.call(n, C.Idle), M = C.Idle;
445
445
  }
446
446
  return {
447
447
  speak(e) {
@@ -457,9 +457,9 @@ async function ln(f, S, u) {
457
457
  }
458
458
  if (!a || !$ || !_)
459
459
  throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
460
- i("Reconnecting to LiveKit room, state:", a.state), K = !1, q = null, (e = n.onConnectionStateChange) == null || e.call(n, A.Connecting, "user:reconnect");
460
+ i("Reconnecting to LiveKit room, state:", a.state), K = !1, q = null, (e = n.onConnectionStateChange) == null || e.call(n, E.Connecting, "user:reconnect");
461
461
  try {
462
- if (await a.connect($, _), i("Room reconnected"), E = !0, a.remoteParticipants.size === 0) {
462
+ if (await a.connect($, _), i("Room reconnected"), w = !0, a.remoteParticipants.size === 0) {
463
463
  if (i("Waiting for agent to join..."), !await new Promise((r) => {
464
464
  const c = setTimeout(() => {
465
465
  a == null || a.off(g.ParticipantConnected, d), r(!1);
@@ -472,7 +472,7 @@ async function ln(f, S, u) {
472
472
  i("Agent joined, reconnection successful");
473
473
  }
474
474
  } catch (o) {
475
- throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, A.Fail, "user:reconnect-failed"), o;
475
+ throw i("Failed to reconnect:", o), (t = n.onConnectionStateChange) == null || t.call(n, E.Fail, "user:reconnect-failed"), o;
476
476
  }
477
477
  },
478
478
  sendDataChannelMessage: Z,
@@ -482,7 +482,7 @@ async function ln(f, S, u) {
482
482
  publishCameraStream: Be,
483
483
  unpublishCameraStream: X,
484
484
  interrupt(e) {
485
- e !== "text" && Z(me.Interrupt, "");
485
+ return e === "text" || !w || !a ? !1 : (Z(me.Interrupt, ""), !0);
486
486
  },
487
487
  registerRpcMethod(e, t) {
488
488
  a == null || a.registerRpcMethod(e, t);
@@ -490,11 +490,14 @@ async function ln(f, S, u) {
490
490
  unregisterRpcMethod(e) {
491
491
  a == null || a.unregisterRpcMethod(e);
492
492
  },
493
- sessionId: y,
494
- streamId: y,
493
+ sessionId: v,
494
+ streamId: v,
495
495
  streamType: te,
496
496
  interruptAvailable: ie,
497
- isInterruptible: W
497
+ // A getter, not a snapshot: currentInterruptible changes as blocking tool calls come and go.
498
+ get isInterruptible() {
499
+ return W;
500
+ }
498
501
  };
499
502
  }
500
503
  export {
@@ -1,7 +1,7 @@
1
1
  import { Agent, Auth, Chat, ChatPayload, ChatResponse, RatingEntity, RatingPayload, STTTokenResponse, SubmitFeedbackResponse } from '../types/index';
2
2
  import { RequestOptions } from './apiClient';
3
3
 
4
- export declare function createAgentsApi(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void, externalId?: string): {
4
+ export declare function createAgentsApi(auth: Auth, host?: string, onError?: (error: Error, errorData: Record<string, unknown>) => void, externalId?: string): {
5
5
  getRuntimeById(id: string, options?: RequestOptions): Promise<Agent>;
6
6
  newChat(agentId: string, payload: {
7
7
  persist: boolean;
@@ -3,7 +3,7 @@ import { Auth } from '../types/auth';
3
3
  export type RequestOptions = RequestInit & {
4
4
  skipErrorHandler?: boolean;
5
5
  };
6
- export declare function createClient(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void, externalId?: string): {
6
+ export declare function createClient(auth: Auth, host?: string, onError?: (error: Error, errorData: Record<string, unknown>) => void, externalId?: string): {
7
7
  get<T = any>(url: string, options?: RequestOptions): Promise<T>;
8
8
  post<T = any>(url: string, body?: any, options?: RequestOptions): Promise<T>;
9
9
  delete<T = any>(url: string, body?: any, options?: RequestOptions): Promise<T>;
@@ -1,6 +1,6 @@
1
1
  import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../types/index';
2
2
 
3
- export declare function createKnowledgeApi(auth: Auth, host?: string, onError?: (error: Error, errorData: object) => void): {
3
+ export declare function createKnowledgeApi(auth: Auth, host?: string, onError?: (error: Error, errorData: Record<string, unknown>) => void): {
4
4
  createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
5
5
  getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
6
6
  getKnowledge(knowledgeId: string, options?: RequestInit): Promise<KnowledgeData>;
@@ -1,3 +1,3 @@
1
1
  import { Auth, RtcApi } from '../../types/index';
2
2
 
3
- export declare function createStreamApi(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): RtcApi;
3
+ export declare function createStreamApi(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: Record<string, unknown>) => void): RtcApi;
@@ -1,5 +1,5 @@
1
1
  import { Auth, CreateSessionV2Options, CreateSessionV2Response } from '../../types';
2
2
 
3
- export declare function createStreamApiV2(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: object) => void): {
3
+ export declare function createStreamApiV2(auth: Auth, host: string, agentId: string, onError?: (error: Error, errorData: Record<string, unknown>) => void): {
4
4
  createStream(options: CreateSessionV2Options): Promise<CreateSessionV2Response>;
5
5
  };
@@ -1,13 +1,182 @@
1
+ /**
2
+ * The JSON-safe payload {@link BaseError.toJson | toJson()} produces, for logs and error reports.
3
+ *
4
+ * Only the fields the SDK deliberately exposes are present, so the payload can be forwarded to a
5
+ * logging service as it is. Subclasses add their own keys: {@link HttpError} adds `httpStatus` and,
6
+ * when the failing call is known, `endpoint` and `method`; {@link NetworkError} adds `endpoint`,
7
+ * `method`, `durationMs`, `online` and `visibility`.
8
+ *
9
+ * @example An HttpError from a request that was refused
10
+ * ```json
11
+ * {
12
+ * "kind": "InsufficientCreditsError",
13
+ * "message": "Account has insufficient credits",
14
+ * "httpStatus": 402,
15
+ * "endpoint": "/agt_x/chat/cht_y",
16
+ * "method": "POST"
17
+ * }
18
+ * ```
19
+ * @category Errors
20
+ */
1
21
  export interface ErrorJson {
22
+ /**
23
+ * Stable machine-readable code for the failure — the error's {@link BaseError.kind | kind}.
24
+ */
2
25
  kind: string;
26
+ /**
27
+ * Human-readable description of the failure — the error's `message`.
28
+ */
3
29
  message: string;
30
+ /**
31
+ * Message of the error that caused this one, truncated to 256 characters.
32
+ *
33
+ * Present only when {@link BaseError.originalError | originalError} is an `Error` and its
34
+ * message differs from {@link ErrorJson.message | message}. A cause that is not an `Error` is
35
+ * never serialized, so an arbitrary object carrying credentials cannot end up in the payload.
36
+ */
4
37
  cause?: string;
38
+ /**
39
+ * Additional fields contributed by a subclass, such as `httpStatus` on {@link HttpError}.
40
+ */
5
41
  [key: string]: any;
6
42
  }
43
+ /**
44
+ * Base class of every error the SDK itself raises.
45
+ *
46
+ * Catching `BaseError` catches everything the SDK classified; branch on
47
+ * {@link BaseError.kind | kind}, which is stable, rather than on the message, which is not.
48
+ * Errors reach the application two ways, and each subclass says which applies: some are thrown to
49
+ * the caller of the method, so they reject the promise it returned; others are handed to
50
+ * {@link AgentManagerCallbacks.onError | onError} because no call of yours was in flight when they
51
+ * happened. {@link HttpError} and {@link NetworkError} do both — the request that failed rejects,
52
+ * and the callback is notified as well.
53
+ *
54
+ * Not everything that reaches the application is one of these. The streaming transport is the main
55
+ * exception: a failure LiveKit raises inside a media call on an Expressive (V4) agent — no
56
+ * microphone publication to replace, a room that is not connected — rejects with a plain `Error`,
57
+ * and so do a few low-level guards inside {@link AgentManager.connect | connect()}, such as a
58
+ * `livekit-client` package that is not installed, a transport the SDK does not recognise, or a
59
+ * stream the server created without a session id. An unknown
60
+ * {@link AgentManagerOptions.auth | auth} type is a plain `Error` too. So keep the
61
+ * `else throw error` branch in a handler built on {@link isDIDError}.
62
+ *
63
+ * Subclasses: {@link HttpError}, {@link NetworkError}, {@link WsError}, {@link StreamError},
64
+ * {@link ValidationError}, {@link ChatCreationFailed} and {@link ChatModeDowngraded}. When the
65
+ * caught value is typed `unknown`, {@link isDIDError} narrows it to this class.
66
+ *
67
+ * @category Errors
68
+ */
7
69
  export declare class BaseError extends Error {
70
+ /**
71
+ * Stable machine-readable code for this failure, and the value to branch on.
72
+ *
73
+ * Every subclass redeclares it as the literal it always carries, so a `switch` on `kind`
74
+ * narrows the caught error to that class: `'NetworkError'` on {@link NetworkError},
75
+ * `'WSError'` on {@link WsError}, `'StreamError'` on {@link StreamError},
76
+ * `'ValidationError'` on {@link ValidationError}, `'ChatCreationFailed'` on
77
+ * {@link ChatCreationFailed} and `'ChatModeDowngraded'` on {@link ChatModeDowngraded}.
78
+ * {@link HttpError} is the one that stays a plain `string`, because it reuses the server's
79
+ * own classification when the response carries one and is `'HttpError'` otherwise. On a
80
+ * `BaseError` built directly it is whatever the caller passed, and `'Error'` when nothing
81
+ * was.
82
+ */
8
83
  readonly kind: string;
84
+ /**
85
+ * The error or value that caused this one, when the SDK was wrapping something else.
86
+ *
87
+ * For a {@link NetworkError} this is the browser's own `fetch` rejection. It is not
88
+ * serialized as-is: {@link BaseError.toJson | toJson()} takes only an `Error` cause's
89
+ * message.
90
+ */
9
91
  readonly originalError?: unknown | undefined;
10
- constructor(message: string, kind?: string, originalError?: unknown | undefined);
92
+ /**
93
+ * Creates an SDK error. The SDK builds these itself; applications normally only catch them.
94
+ *
95
+ * @param message - Human-readable description of the failure, used as the `Error` message.
96
+ * @param kind - Stable machine-readable code for the failure.
97
+ * @param originalError - The underlying error or value this one wraps, when there is one.
98
+ */
99
+ constructor(message: string,
100
+ /**
101
+ * Stable machine-readable code for this failure, and the value to branch on.
102
+ *
103
+ * Every subclass redeclares it as the literal it always carries, so a `switch` on `kind`
104
+ * narrows the caught error to that class: `'NetworkError'` on {@link NetworkError},
105
+ * `'WSError'` on {@link WsError}, `'StreamError'` on {@link StreamError},
106
+ * `'ValidationError'` on {@link ValidationError}, `'ChatCreationFailed'` on
107
+ * {@link ChatCreationFailed} and `'ChatModeDowngraded'` on {@link ChatModeDowngraded}.
108
+ * {@link HttpError} is the one that stays a plain `string`, because it reuses the server's
109
+ * own classification when the response carries one and is `'HttpError'` otherwise. On a
110
+ * `BaseError` built directly it is whatever the caller passed, and `'Error'` when nothing
111
+ * was.
112
+ */
113
+ kind?: string,
114
+ /**
115
+ * The error or value that caused this one, when the SDK was wrapping something else.
116
+ *
117
+ * For a {@link NetworkError} this is the browser's own `fetch` rejection. It is not
118
+ * serialized as-is: {@link BaseError.toJson | toJson()} takes only an `Error` cause's
119
+ * message.
120
+ */
121
+ originalError?: unknown | undefined);
122
+ /**
123
+ * Serializes the error into the JSON-safe {@link ErrorJson} payload for logging or reporting.
124
+ *
125
+ * The payload always carries {@link BaseError.kind | kind} and the message. The cause's message
126
+ * is added only when {@link BaseError.originalError | originalError} is an `Error` and says
127
+ * something the message does not, truncated to 256 characters; any other cause is dropped.
128
+ * Subclasses extend the payload with the fields listed on their own pages.
129
+ *
130
+ * @returns The error as plain, JSON-serializable data.
131
+ * @example An HttpError from a request that was refused
132
+ * ```json
133
+ * {
134
+ * "kind": "InsufficientCreditsError",
135
+ * "message": "Account has insufficient credits",
136
+ * "httpStatus": 402,
137
+ * "endpoint": "/agt_x/chat/cht_y",
138
+ * "method": "POST"
139
+ * }
140
+ * ```
141
+ * @example A NetworkError from a request that never left the browser
142
+ * ```json
143
+ * {
144
+ * "kind": "NetworkError",
145
+ * "message": "Network request failed",
146
+ * "cause": "Failed to fetch",
147
+ * "endpoint": "/agt_x/chat/cht_y",
148
+ * "method": "POST",
149
+ * "durationMs": 12,
150
+ * "online": false,
151
+ * "visibility": "visible"
152
+ * }
153
+ * ```
154
+ */
11
155
  toJson(): ErrorJson;
12
156
  }
157
+ /**
158
+ * Type guard that reports whether a caught value is an error raised by the SDK.
159
+ *
160
+ * It accepts any `Error` carrying a string `kind`, which every {@link BaseError} has, so it also
161
+ * recognizes SDK errors that crossed a bundle boundary, where `instanceof BaseError` can fail
162
+ * because two copies of the class are loaded. Narrowing with it gives typed access to
163
+ * {@link BaseError.kind | kind}, {@link BaseError.originalError | originalError} and
164
+ * {@link BaseError.toJson | toJson()}.
165
+ *
166
+ * @param error - The caught value to test.
167
+ * @returns `true` when `error` is a {@link BaseError}.
168
+ * @example
169
+ * ```ts
170
+ * try {
171
+ * await agentManager.chat('What is the distance to the moon?');
172
+ * } catch (error) {
173
+ * if (isDIDError(error)) {
174
+ * console.error(error.kind, error.toJson());
175
+ * } else {
176
+ * throw error;
177
+ * }
178
+ * }
179
+ * ```
180
+ * @category Errors
181
+ */
13
182
  export declare function isDIDError(error: unknown): error is BaseError;
@@ -1,6 +1,30 @@
1
1
  import { ChatMode } from '../../types';
2
2
  import { BaseError } from '../base-error';
3
3
 
4
+ /**
5
+ * A chat could not be created for the session.
6
+ *
7
+ * {@link AgentManager.chat | chat()} creates a chat on the first message when the session does not
8
+ * have one yet; this error is thrown when that call comes back without one, so it rejects the
9
+ * promise `chat()` returned and the user's message is not sent. It is not delivered to
10
+ * {@link AgentManagerCallbacks.onError | onError} — catch it around `chat()`. A failing request
11
+ * surfaces as {@link HttpError} or {@link NetworkError} instead; this error is the case where the
12
+ * request succeeded but produced no chat.
13
+ *
14
+ * The message names the {@link ChatMode} in effect and whether a persistent chat was asked for, for
15
+ * example `Failed to create persistent chat, mode: Functional`.
16
+ * {@link BaseError.kind | kind} is `'ChatCreationFailed'`.
17
+ *
18
+ * @category Errors
19
+ */
4
20
  export declare class ChatCreationFailed extends BaseError {
21
+ /**
22
+ * Always `'ChatCreationFailed'`. Branch on it to tell this failure from the other SDK errors.
23
+ */
24
+ readonly kind: 'ChatCreationFailed';
25
+ /**
26
+ * Builds the error from the attempt that failed.
27
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
28
+ */
5
29
  constructor(mode: ChatMode, persistent: boolean);
6
30
  }
@@ -1,6 +1,35 @@
1
1
  import { ChatMode } from '../../types';
2
2
  import { BaseError } from '../base-error';
3
3
 
4
+ /**
5
+ * The server put the session into a different chat mode from the one that was requested, and the
6
+ * new mode cannot stream video.
7
+ *
8
+ * Raised while {@link AgentManager.connect | connect()} runs, when the chat the server created came
9
+ * back in a mode other than the requested {@link AgentManagerOptions.mode | mode} and that mode is
10
+ * not {@link ChatMode.Functional | Functional} — {@link ChatMode.TextOnly | TextOnly} or
11
+ * {@link ChatMode.Maintenance | Maintenance}, for instance. The comparison only runs when `mode` was
12
+ * set in the options, so a session that never asked for a mode never sees this error. The SDK
13
+ * disconnects the stream it had just opened and `connect()` resolves anyway, so no video will play
14
+ * and {@link AgentManagerCallbacks.onSrcObjectReady | onSrcObjectReady} will not fire again: the
15
+ * session continues as a text chat.
16
+ *
17
+ * It is delivered to {@link AgentManagerCallbacks.onError | onError} and never thrown, so
18
+ * `connect()` does not reject on it.
19
+ * {@link AgentManagerCallbacks.onModeChange | onModeChange} fires with the new mode just before it.
20
+ * Treat it as a signal to switch the interface to text, not as a connection failure.
21
+ * {@link BaseError.kind | kind} is `'ChatModeDowngraded'`.
22
+ *
23
+ * @category Errors
24
+ */
4
25
  export declare class ChatModeDowngraded extends BaseError {
26
+ /**
27
+ * Always `'ChatModeDowngraded'`. Branch on it to tell this failure from the other SDK errors.
28
+ */
29
+ readonly kind: 'ChatModeDowngraded';
30
+ /**
31
+ * Builds the error from the mode the session ended up in.
32
+ * @internal The SDK builds this itself; applications catch the error rather than construct it.
33
+ */
5
34
  constructor(mode: ChatMode);
6
35
  }