@d-id/client-sdk 3.0.0-staging.417 → 3.0.0-staging.419

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.
@@ -1,9 +1,9 @@
1
1
  var It = Object.defineProperty;
2
2
  var Et = (e, t, r) => t in e ? It(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var b = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
4
- var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(pe || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), me = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(me || {}), ye = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ye || {}), I = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(I || {}), Le = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(Le || {}), kt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(kt || {}), A = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(A || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), ge = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(ge || {}), Oe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Oe || {}), Tt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e))(Tt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_t || {});
5
- const Un = (...e) => {
6
- }, ft = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
3
+ var x = (e, t, r) => Et(e, typeof t != "symbol" ? t + "" : t, r);
4
+ var Re = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e.SttLanguage = "did.stt-language", e.Presentation = "did.presentation", e))(Re || {}), L = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(L || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(pe || {}), C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), me = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(me || {}), ye = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ye || {}), T = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e.TurnStarted = "turn/started", e.TurnEnded = "turn/ended", e))(T || {}), Le = /* @__PURE__ */ ((e) => (e.Started = "tool-call/started", e.Done = "tool-call/done", e.Error = "tool-call/error", e))(Le || {}), Tt = /* @__PURE__ */ ((e) => (e.Presentation = "did.presentation", e))(Tt || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(I || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), ge = /* @__PURE__ */ ((e) => (e.Ok = "ok", e.UnknownError = "unknown_error", e.NetworkIssue = "network_issue", e.MessageLimit = "message_limit", e.TimeLimit = "time_limit", e.Inactivity = "inactivity", e.EndedByAgent = "ended_by_agent", e))(ge || {}), Oe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Oe || {}), kt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Elevenlabs = "elevenlabs", e))(kt || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_t || {});
5
+ const Jn = (...e) => {
6
+ }, ft = (e) => new Promise((t) => setTimeout(t, e)), Z = (e = 16) => {
7
7
  const t = new Uint8Array(e);
8
8
  return globalThis.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
9
9
  };
@@ -12,25 +12,25 @@ function je(e) {
12
12
  return window.localStorage.setItem("did_external_key_id", e), e;
13
13
  let t = window.localStorage.getItem("did_external_key_id");
14
14
  if (!t) {
15
- let r = Q();
15
+ let r = Z();
16
16
  window.localStorage.setItem("did_external_key_id", r), t = r;
17
17
  }
18
18
  return t;
19
19
  }
20
20
  let mt;
21
- function Te() {
22
- return mt ?? (mt = Q());
21
+ function ke() {
22
+ return mt ?? (mt = Z());
23
23
  }
24
24
  function At() {
25
- mt = Q();
25
+ mt = Z();
26
26
  }
27
27
  function gt(e, t) {
28
28
  if (e.type === "bearer")
29
- return `Bearer ${e.token}~${Te()}`;
29
+ return `Bearer ${e.token}~${ke()}`;
30
30
  if (e.type === "basic")
31
- return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${Te()}`;
31
+ return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${ke()}`;
32
32
  if (e.type === "key")
33
- return `Client-Key ${e.clientKey}.${je(t)}_${Te()}`;
33
+ return `Client-Key ${e.clientKey}.${je(t)}_${ke()}`;
34
34
  throw new Error(`Unknown auth type: ${e}`);
35
35
  }
36
36
  const Pt = 45 * 1e3, bt = "X-Playground-Chat", He = 2e3, Ie = "https://api.d-id.com", xt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa";
@@ -88,7 +88,7 @@ class q extends Error {
88
88
  };
89
89
  }
90
90
  }
91
- function Jn(e) {
91
+ function Hn(e) {
92
92
  return e instanceof Error && typeof e.kind == "string";
93
93
  }
94
94
  class jt extends q {
@@ -101,7 +101,7 @@ class jt extends q {
101
101
  /**
102
102
  * Always `'ChatCreationFailed'`. Branch on it to tell this failure from the other SDK errors.
103
103
  */
104
- b(this, "kind", "ChatCreationFailed");
104
+ x(this, "kind", "ChatCreationFailed");
105
105
  }
106
106
  }
107
107
  class Bt extends q {
@@ -114,7 +114,7 @@ class Bt extends q {
114
114
  /**
115
115
  * Always `'ChatModeDowngraded'`. Branch on it to tell this failure from the other SDK errors.
116
116
  */
117
- b(this, "kind", "ChatModeDowngraded");
117
+ x(this, "kind", "ChatModeDowngraded");
118
118
  }
119
119
  }
120
120
  function $t(e) {
@@ -136,7 +136,7 @@ class ht extends q {
136
136
  /**
137
137
  * Always `'HttpError'`. Branch on it to tell this failure from the other SDK errors.
138
138
  */
139
- b(this, "kind", "HttpError");
139
+ x(this, "kind", "HttpError");
140
140
  /**
141
141
  * The Agents API's own classification of the failure — the `kind` from D-ID's
142
142
  * `{ kind, description }` error body — and `'HttpError'` when the response was not that
@@ -147,11 +147,11 @@ class ht extends q {
147
147
  * Use {@link HttpError.status | status} for the transport-level branch, this for the API-level
148
148
  * one, and {@link BaseError.kind | kind} to tell an `HttpError` from the SDK's other errors.
149
149
  */
150
- b(this, "code");
150
+ x(this, "code");
151
151
  /**
152
152
  * HTTP status code of the response, such as `401`, `404` or `500`.
153
153
  */
154
- b(this, "status");
154
+ x(this, "status");
155
155
  /**
156
156
  * Path of the request that failed, relative to the API client's base path — for example
157
157
  * `/agt_x/chat/cht_y` for a message sent to a chat.
@@ -159,13 +159,13 @@ class ht extends q {
159
159
  * Absent when the error was constructed without call context. {@link NetworkError.endpoint}
160
160
  * is the same value on a transport failure.
161
161
  */
162
- b(this, "endpoint");
162
+ x(this, "endpoint");
163
163
  /**
164
164
  * HTTP method of the request that failed, such as `GET` or `POST`.
165
165
  *
166
166
  * Absent when the error was constructed without call context.
167
167
  */
168
- b(this, "method");
168
+ x(this, "method");
169
169
  this.code = (s == null ? void 0 : s.kind) ?? "HttpError", this.status = r, this.endpoint = o.endpoint, this.method = o.method;
170
170
  }
171
171
  /**
@@ -198,35 +198,35 @@ class Nt extends q {
198
198
  /**
199
199
  * Always `'NetworkError'`. Branch on it to tell this failure from the other SDK errors.
200
200
  */
201
- b(this, "kind", "NetworkError");
201
+ x(this, "kind", "NetworkError");
202
202
  /**
203
203
  * Path of the request that failed, relative to the API client's base path — for example
204
204
  * `/agt_x/chat/cht_y`.
205
205
  */
206
- b(this, "endpoint");
206
+ x(this, "endpoint");
207
207
  /**
208
208
  * HTTP method of the request that failed, such as `GET` or `POST`.
209
209
  */
210
- b(this, "method");
210
+ x(this, "method");
211
211
  /**
212
212
  * How long the request ran before it failed, in milliseconds.
213
213
  *
214
214
  * A value close to zero usually means the request never left the browser; a large one points
215
215
  * at a connection that was established and then lost.
216
216
  */
217
- b(this, "durationMs");
217
+ x(this, "durationMs");
218
218
  /**
219
219
  * The browser's `navigator.onLine` at the moment of the failure — `false` when the device
220
220
  * reported itself offline.
221
221
  */
222
- b(this, "online");
222
+ x(this, "online");
223
223
  /**
224
224
  * The page's `document.visibilityState` at the moment of the failure.
225
225
  *
226
226
  * `'hidden'` means the tab was in the background, where browsers throttle or suspend network
227
227
  * activity.
228
228
  */
229
- b(this, "visibility");
229
+ x(this, "visibility");
230
230
  this.endpoint = a.endpoint, this.method = a.method, this.durationMs = a.durationMs, this.online = a.online, this.visibility = a.visibility;
231
231
  }
232
232
  /**
@@ -259,7 +259,7 @@ class pt extends q {
259
259
  /**
260
260
  * Always `'StreamError'`. Branch on it to tell this failure from the other SDK errors.
261
261
  */
262
- b(this, "kind", "StreamError");
262
+ x(this, "kind", "StreamError");
263
263
  }
264
264
  }
265
265
  class R extends q {
@@ -275,7 +275,7 @@ class R extends q {
275
275
  /**
276
276
  * Always `'ValidationError'`. Branch on it to tell this failure from the other SDK errors.
277
277
  */
278
- b(this, "kind", "ValidationError");
278
+ x(this, "kind", "ValidationError");
279
279
  this.key = a;
280
280
  }
281
281
  }
@@ -289,10 +289,10 @@ class zt extends q {
289
289
  /**
290
290
  * Always `'WSError'` — note the capitalization, which does not match the class name.
291
291
  */
292
- b(this, "kind", "WSError");
292
+ x(this, "kind", "WSError");
293
293
  }
294
294
  }
295
- const yt = (e) => e.type, Ot = (e) => e.type === pe.Expressive ? "v4" : e.type === pe.Clip ? "v3-pro" : "v2", Fe = (e) => e === pe.Expressive, _e = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), te = (e) => e && [x.DirectPlayback, x.Off].includes(e), We = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
295
+ const yt = (e) => e.type, Ot = (e) => e.type === pe.Expressive ? "v4" : e.type === pe.Clip ? "v3-pro" : "v2", Fe = (e) => e === pe.Expressive, _e = (e) => [L.TextOnly, L.Playground, L.Maintenance].includes(e), te = (e) => e && [L.DirectPlayback, L.Off].includes(e), We = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ft = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
296
296
  function Vt(e) {
297
297
  const t = e.split("?")[0].split("#")[0].toLowerCase();
298
298
  return Ft.some((r) => t.endsWith(r));
@@ -375,7 +375,7 @@ async function Be(e, t) {
375
375
  }
376
376
  class Ye {
377
377
  constructor(t) {
378
- b(this, "status", 429);
378
+ x(this, "status", 429);
379
379
  this.response = t;
380
380
  }
381
381
  }
@@ -531,7 +531,7 @@ function nt(e) {
531
531
  function Pe(e) {
532
532
  return e instanceof q ? e.toJson() : { kind: "UnknownError", message: qt(e) || "UnknownError" };
533
533
  }
534
- const Zt = "3.0.0-staging.417", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Y = [];
534
+ const Zt = "3.0.0-staging.419", en = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", St = 50, Q = [];
535
535
  let be = !1;
536
536
  async function Ct(e) {
537
537
  const t = await fetch(en, {
@@ -543,15 +543,15 @@ async function Ct(e) {
543
543
  throw new Error(`Mixpanel responded with ${t.status}`);
544
544
  }
545
545
  function tn(e) {
546
- Y.push(e), Y.splice(St);
546
+ Q.push(e), Q.splice(St);
547
547
  }
548
548
  function $e() {
549
- if (be || !Y.length)
549
+ if (be || !Q.length)
550
550
  return;
551
551
  be = !0;
552
- const e = Y.splice(0, Y.length);
552
+ const e = Q.splice(0, Q.length);
553
553
  Ct(e).catch(() => {
554
- Y.unshift(...e), Y.splice(St);
554
+ Q.unshift(...e), Q.splice(St);
555
555
  }).finally(() => {
556
556
  be = !1;
557
557
  });
@@ -570,7 +570,7 @@ function nn(e) {
570
570
  ...e.mixpanelAdditionalProperties || {}
571
571
  },
572
572
  isEnabled: e.isEnabled ?? !0,
573
- getRandom: Q,
573
+ getRandom: Z,
574
574
  enrich(a) {
575
575
  this.additionalProperties = { ...this.additionalProperties, ...a };
576
576
  },
@@ -623,7 +623,7 @@ function Ve() {
623
623
  }
624
624
  const K = Ve(), Ne = Ve(), rt = Ve();
625
625
  function Mt(e) {
626
- return e === x.Playground ? { headers: { [bt]: "true" } } : {};
626
+ return e === L.Playground ? { headers: { [bt]: "true" } } : {};
627
627
  }
628
628
  async function Dt(e, t, r, a, o = !1, s) {
629
629
  return s ? { chat: s, chatMode: a } : (te(a) || (s = await t.newChat(e.id, { persist: o }, Mt(a)), r.track("agent-chat", {
@@ -692,10 +692,10 @@ function dn(e) {
692
692
  return cn[e.close_reason] ?? e.close_reason;
693
693
  }
694
694
  const un = [
695
- I.StreamVideoDone,
696
- I.StreamVideoError,
697
- I.StreamVideoRejected
698
- ], at = [I.StreamFailed, I.StreamVideoError, I.StreamVideoRejected];
695
+ T.StreamVideoDone,
696
+ T.StreamVideoError,
697
+ T.StreamVideoRejected
698
+ ], at = [T.StreamFailed, T.StreamVideoError, T.StreamVideoRejected];
699
699
  function it(e) {
700
700
  if (e.answer !== void 0)
701
701
  return e.answer;
@@ -769,7 +769,7 @@ function mn(e, t, r, a, o) {
769
769
  onMessage: (d, h) => {
770
770
  var f, g, l;
771
771
  if ("content" in h) {
772
- const p = d === I.ChatAnswer ? F.Answer : d === I.ChatAudioTranscribed ? F.Transcribe : d;
772
+ const p = d === T.ChatAnswer ? F.Answer : d === T.ChatAudioTranscribed ? F.Transcribe : d;
773
773
  fn(
774
774
  p,
775
775
  h,
@@ -784,10 +784,10 @@ function mn(e, t, r, a, o) {
784
784
  mode: t.chatMode
785
785
  });
786
786
  } else {
787
- const p = I;
787
+ const p = T;
788
788
  if (d = d, d === p.StreamVideoCreated) {
789
- const M = tt(h, a, { mode: t.chatMode });
790
- if (e.linkTrack("agent-video", M, p.StreamVideoCreated, ["start"]), h.sentiment) {
789
+ const D = tt(h, a, { mode: t.chatMode });
790
+ if (e.linkTrack("agent-video", D, p.StreamVideoCreated, ["start"]), h.sentiment) {
791
791
  const S = t.messages[t.messages.length - 1];
792
792
  if ((S == null ? void 0 : S.role) === "assistant") {
793
793
  const P = { ...S, sentiment: h.sentiment };
@@ -796,8 +796,8 @@ function mn(e, t, r, a, o) {
796
796
  }
797
797
  }
798
798
  if (un.includes(d)) {
799
- const M = d.split("/")[1], S = tt(h, a, { mode: t.chatMode });
800
- at.includes(d) ? e.track("agent-video", { ...S, event: M }) : e.linkTrack("agent-video", { ...S, event: M }, d, ["done"]);
799
+ const D = d.split("/")[1], S = tt(h, a, { mode: t.chatMode });
800
+ at.includes(d) ? e.track("agent-video", { ...S, event: D }) : e.linkTrack("agent-video", { ...S, event: D }, d, ["done"]);
801
801
  }
802
802
  at.includes(d) && ((l = (g = r.callbacks).onError) == null || l.call(g, new pt(`Stream failed with event ${d}`), {
803
803
  streamId: (f = t.streamingManager) == null ? void 0 : f.streamId
@@ -1015,7 +1015,7 @@ function Rt(e, t) {
1015
1015
  return null;
1016
1016
  }
1017
1017
  const fe = 10;
1018
- function Hn(e, t) {
1018
+ function Wn(e, t) {
1019
1019
  let r = !1, a = !1, o = null, s = 0, i = 0, u = {};
1020
1020
  async function n() {
1021
1021
  if (r) {
@@ -1074,21 +1074,21 @@ function Rn() {
1074
1074
  function In(e, t, r, a, o) {
1075
1075
  let s = null, i = [], u, n = 0, d = !1, h = me.Unknown, f = me.Unknown, g = 0, l = 0;
1076
1076
  const p = Rn();
1077
- async function M() {
1077
+ async function D() {
1078
1078
  const S = await e();
1079
1079
  if (!S)
1080
1080
  return;
1081
- const { isReceiving: P, avgJitterDelayInInterval: V, freezeCount: L } = p(S), ne = Sn(S);
1081
+ const { isReceiving: P, avgJitterDelayInInterval: U, freezeCount: j } = p(S), ne = Sn(S);
1082
1082
  if (P)
1083
- n = 0, g = L - l, f = V < Mn ? me.Strong : V > Dn && g > 1 ? me.Weak : h, f !== h && (o == null || o(f), h = f, l += g, g = 0), d || (a == null || a(C.Start), u = i[i.length - 1], i = [], d = !0), i.push(ne);
1083
+ n = 0, g = j - l, f = U < Mn ? me.Strong : U > Dn && g > 1 ? me.Weak : h, f !== h && (o == null || o(f), h = f, l += g, g = 0), d || (a == null || a(C.Start), u = i[i.length - 1], i = [], d = !0), i.push(ne);
1084
1084
  else if (d && (n++, n >= Cn)) {
1085
1085
  const re = st(i, De, u);
1086
- a == null || a(C.Stop, re ?? void 0), t() || r(), l = L, d = !1;
1086
+ a == null || a(C.Stop, re ?? void 0), t() || r(), l = j, d = !1;
1087
1087
  }
1088
1088
  }
1089
1089
  return {
1090
1090
  start: () => {
1091
- s || (s = setInterval(M, De));
1091
+ s || (s = setInterval(D, De));
1092
1092
  },
1093
1093
  stop: () => {
1094
1094
  s && (clearInterval(s), s = null);
@@ -1105,24 +1105,24 @@ const En = () => {
1105
1105
  function ot(e) {
1106
1106
  switch (e) {
1107
1107
  case "connected":
1108
- return A.Connected;
1108
+ return I.Connected;
1109
1109
  case "checking":
1110
- return A.Connecting;
1110
+ return I.Connecting;
1111
1111
  case "failed":
1112
- return A.Fail;
1112
+ return I.Fail;
1113
1113
  case "new":
1114
- return A.New;
1114
+ return I.New;
1115
1115
  case "closed":
1116
- return A.Closed;
1116
+ return I.Closed;
1117
1117
  case "disconnected":
1118
- return A.Disconnected;
1118
+ return I.Disconnected;
1119
1119
  case "completed":
1120
- return A.Completed;
1120
+ return I.Completed;
1121
1121
  default:
1122
- return A.New;
1122
+ return I.New;
1123
1123
  }
1124
1124
  }
1125
- const kn = (e) => (t) => {
1125
+ const Tn = (e) => (t) => {
1126
1126
  const [r, a = ""] = t.split(/:(.+)/);
1127
1127
  try {
1128
1128
  const o = JSON.parse(a);
@@ -1131,7 +1131,7 @@ const kn = (e) => (t) => {
1131
1131
  return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: o }), { subject: r, data: a };
1132
1132
  }
1133
1133
  };
1134
- function Tn({
1134
+ function kn({
1135
1135
  statsSignal: e,
1136
1136
  dataChannelSignal: t,
1137
1137
  onVideoStateChange: r,
@@ -1159,7 +1159,7 @@ function ct({
1159
1159
  report: s,
1160
1160
  log: i
1161
1161
  }) {
1162
- o === H.Legacy ? Tn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: i }) : o === H.Fluent && _n({
1162
+ o === H.Legacy ? kn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: r, report: s, log: i }) : o === H.Fluent && _n({
1163
1163
  statsSignal: e,
1164
1164
  dataChannelSignal: t,
1165
1165
  onVideoStateChange: r,
@@ -1170,45 +1170,45 @@ function ct({
1170
1170
  }
1171
1171
  async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ie, analytics: i }, u) {
1172
1172
  var le;
1173
- const n = hn(r, "WebRTCStreamingManager"), d = kn(n);
1173
+ const n = hn(r, "WebRTCStreamingManager"), d = Tn(n);
1174
1174
  let h = !1, f = !1, g = C.Stop, l = C.Stop;
1175
- const { startConnection: p, sendStreamRequest: M, close: S, createStream: P, addIceCandidate: V } = gn(
1175
+ const { startConnection: p, sendStreamRequest: D, close: S, createStream: P, addIceCandidate: U } = gn(
1176
1176
  o,
1177
1177
  s,
1178
1178
  e,
1179
1179
  a.onError
1180
1180
  ), {
1181
- id: L,
1181
+ id: j,
1182
1182
  offer: ne,
1183
1183
  ice_servers: re,
1184
- session_id: z,
1185
- fluent: Z,
1184
+ session_id: N,
1185
+ fluent: ee,
1186
1186
  interrupt_enabled: we
1187
1187
  } = await P(t, u);
1188
- if (!z)
1188
+ if (!N)
1189
1189
  throw new Error("Could not create session_id");
1190
- (le = a.onStreamCreated) == null || le.call(a, { streamId: L, sessionId: z, agentId: e });
1190
+ (le = a.onStreamCreated) == null || le.call(a, { streamId: j, sessionId: N, agentId: e });
1191
1191
  const ae = (w) => {
1192
1192
  var v;
1193
- return (v = a.onError) == null ? void 0 : v.call(a, w, { streamId: L });
1194
- }, E = new (En())({ iceServers: re }), G = E.createDataChannel("JanusDataChannel"), j = Z ? H.Fluent : H.Legacy;
1193
+ return (v = a.onError) == null ? void 0 : v.call(a, w, { streamId: j });
1194
+ }, k = new (En())({ iceServers: re }), G = k.createDataChannel("JanusDataChannel"), B = ee ? H.Fluent : H.Legacy;
1195
1195
  i.enrich({
1196
- "stream-type": j
1196
+ "stream-type": B
1197
1197
  });
1198
- const ee = t.stream_warmup && !Z, ve = () => h, ie = () => {
1198
+ const X = t.stream_warmup && !ee, ve = () => h, ie = () => {
1199
1199
  var w;
1200
- h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (w = a.onConnectionStateChange) == null || w.call(a, A.Connected));
1201
- }, X = In(
1202
- () => E.getStats(),
1200
+ h = !0, f && (n("CALLBACK: onConnectionStateChange(Connected)"), (w = a.onConnectionStateChange) == null || w.call(a, I.Connected));
1201
+ }, Y = In(
1202
+ () => k.getStats(),
1203
1203
  ve,
1204
1204
  ie,
1205
1205
  (w, v) => ct({
1206
1206
  statsSignal: l = w,
1207
- dataChannelSignal: j === H.Legacy ? g : void 0,
1207
+ dataChannelSignal: B === H.Legacy ? g : void 0,
1208
1208
  onVideoStateChange: a.onVideoStateChange,
1209
1209
  onAgentActivityStateChange: a.onAgentActivityStateChange,
1210
1210
  report: v,
1211
- streamType: j,
1211
+ streamType: B,
1212
1212
  log: n
1213
1213
  }),
1214
1214
  (w) => {
@@ -1216,41 +1216,41 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ie,
1216
1216
  return (v = a.onConnectivityStateChange) == null ? void 0 : v.call(a, w);
1217
1217
  }
1218
1218
  );
1219
- X.start(), E.onicecandidate = (w) => {
1219
+ Y.start(), k.onicecandidate = (w) => {
1220
1220
  n("peerConnection.onicecandidate", w);
1221
1221
  try {
1222
- w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? V(
1223
- L,
1222
+ w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? U(
1223
+ j,
1224
1224
  {
1225
1225
  candidate: w.candidate.candidate,
1226
1226
  sdpMid: w.candidate.sdpMid,
1227
1227
  sdpMLineIndex: w.candidate.sdpMLineIndex
1228
1228
  },
1229
- z,
1229
+ N,
1230
1230
  u
1231
- ) : V(L, { candidate: null }, z, u);
1231
+ ) : U(j, { candidate: null }, N, u);
1232
1232
  } catch (v) {
1233
1233
  ae(v);
1234
1234
  }
1235
1235
  }, G.onopen = () => {
1236
- f = !0, (!ee || h) && ie();
1236
+ f = !0, (!X || h) && ie();
1237
1237
  };
1238
- let U = null;
1238
+ let V = null;
1239
1239
  const se = (w) => {
1240
1240
  var v;
1241
- U = w, (v = a.onVideoIdChange) == null || v.call(a, w);
1241
+ V = w, (v = a.onVideoIdChange) == null || v.call(a, w);
1242
1242
  };
1243
1243
  function Se(w, v) {
1244
- if (w === I.StreamStarted && typeof v == "object" && "metadata" in v) {
1244
+ if (w === T.StreamStarted && typeof v == "object" && "metadata" in v) {
1245
1245
  const c = v.metadata;
1246
1246
  se(c.videoId);
1247
1247
  }
1248
- w === I.StreamDone && se(null), g = w === I.StreamStarted ? C.Start : C.Stop, ct({
1249
- statsSignal: j === H.Legacy ? l : void 0,
1248
+ w === T.StreamDone && se(null), g = w === T.StreamStarted ? C.Start : C.Stop, ct({
1249
+ statsSignal: B === H.Legacy ? l : void 0,
1250
1250
  dataChannelSignal: g,
1251
1251
  onVideoStateChange: a.onVideoStateChange,
1252
1252
  onAgentActivityStateChange: a.onAgentActivityStateChange,
1253
- streamType: j,
1253
+ streamType: B,
1254
1254
  log: n
1255
1255
  });
1256
1256
  }
@@ -1260,25 +1260,25 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ie,
1260
1260
  c && i.enrich({ streamMetadata: c }), (m = a.onStreamReady) == null || m.call(a);
1261
1261
  }
1262
1262
  const ce = {
1263
- [I.StreamStarted]: Se,
1264
- [I.StreamDone]: Se,
1265
- [I.StreamReady]: oe
1263
+ [T.StreamStarted]: Se,
1264
+ [T.StreamDone]: Se,
1265
+ [T.StreamReady]: oe
1266
1266
  };
1267
1267
  G.onmessage = (w) => {
1268
1268
  var m;
1269
1269
  const { subject: v, data: c } = d(w.data);
1270
1270
  (m = ce[v]) == null || m.call(ce, v, c);
1271
- }, E.oniceconnectionstatechange = () => {
1271
+ }, k.oniceconnectionstatechange = () => {
1272
1272
  var v;
1273
- n("peerConnection.oniceconnectionstatechange => " + E.iceConnectionState);
1274
- const w = ot(E.iceConnectionState);
1275
- w !== A.Connected && ((v = a.onConnectionStateChange) == null || v.call(a, w, `webrtc:ice-${E.iceConnectionState}`));
1276
- }, E.ontrack = (w) => {
1273
+ n("peerConnection.oniceconnectionstatechange => " + k.iceConnectionState);
1274
+ const w = ot(k.iceConnectionState);
1275
+ w !== I.Connected && ((v = a.onConnectionStateChange) == null || v.call(a, w, `webrtc:ice-${k.iceConnectionState}`));
1276
+ }, k.ontrack = (w) => {
1277
1277
  var v;
1278
1278
  n("peerConnection.ontrack", w), n("CALLBACK: onSrcObjectReady"), (v = a.onSrcObjectReady) == null || v.call(a, w.streams[0]);
1279
- }, await E.setRemoteDescription(ne), n("set remote description OK");
1280
- const de = await E.createAnswer();
1281
- n("create answer OK"), await E.setLocalDescription(de), n("set local description OK"), await p(L, de, z, u), n("start connection OK");
1279
+ }, await k.setRemoteDescription(ne), n("set remote description OK");
1280
+ const de = await k.createAnswer();
1281
+ n("create answer OK"), await k.setLocalDescription(de), n("set local description OK"), await p(j, de, N, u), n("start connection OK");
1282
1282
  async function ue(w, v) {
1283
1283
  if (!h || G.readyState !== "open") {
1284
1284
  n("Data channel is not ready for sending messages"), ae(new pt("Data channel is not ready for sending messages"));
@@ -1296,49 +1296,49 @@ async function An(e, t, { debug: r = !1, callbacks: a, auth: o, baseURL: s = Ie,
1296
1296
  * @param payload
1297
1297
  */
1298
1298
  speak(w) {
1299
- return M(L, z, w);
1299
+ return D(j, N, w);
1300
1300
  },
1301
1301
  /**
1302
1302
  * Method to close RTC connection
1303
1303
  */
1304
1304
  async disconnect() {
1305
1305
  var w;
1306
- if (L) {
1307
- const v = ot(E.iceConnectionState);
1308
- if (E) {
1309
- if (v === A.New) {
1310
- X.stop();
1306
+ if (j) {
1307
+ const v = ot(k.iceConnectionState);
1308
+ if (k) {
1309
+ if (v === I.New) {
1310
+ Y.stop();
1311
1311
  return;
1312
1312
  }
1313
- E.close(), E.oniceconnectionstatechange = null, E.onnegotiationneeded = null, E.onicecandidate = null, E.ontrack = null;
1313
+ k.close(), k.oniceconnectionstatechange = null, k.onnegotiationneeded = null, k.onicecandidate = null, k.ontrack = null;
1314
1314
  }
1315
1315
  try {
1316
- v === A.Connected && await S(L, z).catch((c) => {
1316
+ v === I.Connected && await S(j, N).catch((c) => {
1317
1317
  });
1318
1318
  } catch (c) {
1319
1319
  n("Error on close stream connection", c);
1320
1320
  }
1321
- (w = a.onAgentActivityStateChange) == null || w.call(a, ye.Idle), X.stop();
1321
+ (w = a.onAgentActivityStateChange) == null || w.call(a, ye.Idle), Y.stop();
1322
1322
  }
1323
1323
  },
1324
1324
  sendDataChannelMessage: ue,
1325
1325
  /**
1326
1326
  * Session identifier information, should be returned in the body of all streaming requests
1327
1327
  */
1328
- sessionId: z,
1328
+ sessionId: N,
1329
1329
  /**
1330
1330
  * Id of current RTC stream
1331
1331
  */
1332
- streamId: L,
1333
- streamType: j,
1332
+ streamId: j,
1333
+ streamType: B,
1334
1334
  interruptAvailable: we ?? !1,
1335
1335
  isInterruptible: !0,
1336
1336
  interrupt(w) {
1337
- if (!we || j !== H.Fluent || !U || !h || G.readyState !== "open")
1337
+ if (!we || B !== H.Fluent || !V || !h || G.readyState !== "open")
1338
1338
  return !1;
1339
1339
  const v = {
1340
- type: I.StreamInterrupt,
1341
- videoId: U,
1340
+ type: T.StreamInterrupt,
1341
+ videoId: V,
1342
1342
  timestamp: Date.now()
1343
1343
  };
1344
1344
  return ue(Re.Interrupt, JSON.stringify(v)), !0;
@@ -1357,7 +1357,7 @@ async function Pn(e, t, r, a) {
1357
1357
  const { version: s, ...i } = t;
1358
1358
  switch (i.transport.provider) {
1359
1359
  case Oe.Livekit:
1360
- const { createLiveKitStreamingManager: u } = await import("./livekit-manager-DF70NOGW.js");
1360
+ const { createLiveKitStreamingManager: u } = await import("./livekit-manager-BY7TXE80.js");
1361
1361
  return u(o, i, r);
1362
1362
  default:
1363
1363
  throw new Error(`Unsupported transport provider: ${i.transport.provider}`);
@@ -1406,7 +1406,7 @@ function Nn(e, t, r, a, o) {
1406
1406
  }
1407
1407
  function dt(e, t, r, a, o) {
1408
1408
  e === C.Start ? r.linkTrack("agent-video", { event: "start", ...o, "stream-type": a }, "start", [
1409
- I.StreamVideoCreated
1409
+ T.StreamVideoCreated
1410
1410
  ]) : e === C.Stop && r.linkTrack(
1411
1411
  "agent-video",
1412
1412
  {
@@ -1414,7 +1414,7 @@ function dt(e, t, r, a, o) {
1414
1414
  "stream-type": a
1415
1415
  },
1416
1416
  "done",
1417
- [I.StreamVideoDone]
1417
+ [T.StreamVideoDone]
1418
1418
  );
1419
1419
  }
1420
1420
  function zn(e, t, r, a, o) {
@@ -1422,7 +1422,7 @@ function zn(e, t, r, a, o) {
1422
1422
  "agent-video",
1423
1423
  { event: "start", latency: K.get(!0), "stream-type": o },
1424
1424
  "start",
1425
- [I.StreamVideoCreated]
1425
+ [T.StreamVideoCreated]
1426
1426
  ) : e === C.Stop && a.linkTrack(
1427
1427
  "agent-video",
1428
1428
  {
@@ -1431,7 +1431,7 @@ function zn(e, t, r, a, o) {
1431
1431
  ...r
1432
1432
  },
1433
1433
  "done",
1434
- [I.StreamVideoDone]
1434
+ [T.StreamVideoDone]
1435
1435
  );
1436
1436
  }
1437
1437
  function On(e, t, r) {
@@ -1471,7 +1471,7 @@ function ut(e, t, r, a) {
1471
1471
  ...t.callbacks,
1472
1472
  onConnectionStateChange: (f, g) => {
1473
1473
  var l, p;
1474
- (p = (l = t.callbacks).onConnectionStateChange) == null || p.call(l, f, g), Bn(f, g, r), f === A.Connected && (i ? o(i) : u = !0);
1474
+ (p = (l = t.callbacks).onConnectionStateChange) == null || p.call(l, f, g), Bn(f, g, r), f === I.Connected && (i ? o(i) : u = !0);
1475
1475
  },
1476
1476
  onVideoStateChange: (f, g) => {
1477
1477
  var l, p;
@@ -1526,7 +1526,7 @@ async function Fn(e, t, r, a, o) {
1526
1526
  if (Fe(e.avatar.type)) {
1527
1527
  const g = await ut(e, t, a), l = `${bn}_${g.sessionId}`, p = (/* @__PURE__ */ new Date()).toISOString();
1528
1528
  return { chatResult: {
1529
- chatMode: x.Functional,
1529
+ chatMode: L.Functional,
1530
1530
  chat: {
1531
1531
  id: l,
1532
1532
  agent_id: e.id,
@@ -1535,7 +1535,7 @@ async function Fn(e, t, r, a, o) {
1535
1535
  modified: p,
1536
1536
  agent_id__created_at: p,
1537
1537
  agent_id__modified_at: p,
1538
- chat_mode: x.Functional,
1538
+ chat_mode: L.Functional,
1539
1539
  messages: []
1540
1540
  }
1541
1541
  }, streamingManager: g };
@@ -1543,29 +1543,29 @@ async function Fn(e, t, r, a, o) {
1543
1543
  const g = new AbortController(), l = g.signal;
1544
1544
  let p;
1545
1545
  try {
1546
- const M = Dt(
1546
+ const D = Dt(
1547
1547
  e,
1548
1548
  r,
1549
1549
  a,
1550
1550
  t.mode,
1551
1551
  t.persistentChat,
1552
1552
  o
1553
- ), S = ut(e, t, a, l).then((L) => (p = L, L)), [P, V] = await Promise.all([M, S]);
1554
- return { chatResult: P, streamingManager: V };
1555
- } catch (M) {
1553
+ ), S = ut(e, t, a, l).then((j) => (p = j, j)), [P, U] = await Promise.all([D, S]);
1554
+ return { chatResult: P, streamingManager: U };
1555
+ } catch (D) {
1556
1556
  throw g.abort(), p && await p.disconnect().catch(() => {
1557
- }), M;
1557
+ }), D;
1558
1558
  }
1559
1559
  }
1560
1560
  }, { chatResult: i, streamingManager: u } = await s(), { chat: n, chatMode: d } = i;
1561
- return d && t.mode !== void 0 && d !== t.mode && d !== x.Functional ? ((f = (h = t.callbacks).onError) == null || f.call(h, new Bt(d)), u == null || u.disconnect(), { chat: n }) : { chat: n, streamingManager: u };
1561
+ return d && t.mode !== void 0 && d !== t.mode && d !== L.Functional ? ((f = (h = t.callbacks).onError) == null || f.call(h, new Bt(d)), u == null || u.disconnect(), { chat: n }) : { chat: n, streamingManager: u };
1562
1562
  }
1563
- const xe = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", lt = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance";
1564
- async function Wn(e, t) {
1563
+ const xe = "ChatMode.Off and ChatMode.DirectPlayback are not supported for Expressive agents", lt = "callbacks.onSrcObjectReady is required in every chat mode that streams video; it is optional only in ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance", Vn = [I.Disconnected, I.Closed, I.Fail];
1564
+ async function Kn(e, t) {
1565
1565
  var de, ue, le, w, v;
1566
1566
  const r = { ...t.callbacks };
1567
1567
  let a = !0;
1568
- const o = ((de = t.analytics) == null ? void 0 : de.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || Ie, u = t.mode || x.Functional;
1568
+ const o = ((de = t.analytics) == null ? void 0 : de.mixpanelKey) || Lt, s = t.wsURL || xt, i = t.baseURL || Ie, u = t.mode || L.Functional;
1569
1569
  if (!r.onSrcObjectReady && !_e(u))
1570
1570
  throw new R(lt);
1571
1571
  const n = {
@@ -1581,7 +1581,7 @@ async function Wn(e, t) {
1581
1581
  nt(() => {
1582
1582
  d.track("agent-sdk", { event: "init" }, h);
1583
1583
  });
1584
- let f = A.New, g;
1584
+ let f = I.New, g;
1585
1585
  const l = {
1586
1586
  ...r,
1587
1587
  onError(c, m) {
@@ -1596,20 +1596,20 @@ async function Wn(e, t) {
1596
1596
  var m;
1597
1597
  g = c, (m = r.onStreamCreated) == null || m.call(r, c);
1598
1598
  }
1599
- }, p = { ...t, callbacks: l }, M = Ht(p.auth, i, l.onError, p.externalId), S = await M.getRuntimeById(e);
1599
+ }, p = { ...t, callbacks: l }, D = Ht(p.auth, i, l.onError, p.externalId), S = await D.getRuntimeById(e);
1600
1600
  p.debug = p.debug || ((w = S == null ? void 0 : S.advanced_settings) == null ? void 0 : w.ui_debug_mode);
1601
1601
  const P = Fe(S.avatar.type);
1602
1602
  if (P && te(u))
1603
1603
  throw new R(xe);
1604
- P && import("./livekit-manager-DF70NOGW.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
1604
+ P && import("./livekit-manager-BY7TXE80.js").then(({ preloadLiveKit: c }) => c()).catch(() => {
1605
1605
  }), d.enrich(Kt(S));
1606
- const { onMessage: V, clearQueue: L } = mn(d, n, p, S, (c) => {
1606
+ const { onMessage: U, clearQueue: j } = mn(d, n, p, S, (c) => {
1607
1607
  var m, y;
1608
- (m = n.socketManager) == null || m.disconnect(), (y = l.onConnectionStateChange) == null || y.call(l, A.Disconnected, c);
1608
+ (m = n.socketManager) == null || m.disconnect(), (y = l.onConnectionStateChange) == null || y.call(l, I.Disconnected, c);
1609
1609
  });
1610
- n.messages = rn(p.initialMessages), (v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer");
1610
+ n.messages = rn(p.initialMessages), n.messages.length && ((v = l.onNewMessage) == null || v.call(l, [...n.messages], "answer"));
1611
1611
  const ne = (c) => d.enrich({ videoId: c }), re = (c) => {
1612
- var B;
1612
+ var z;
1613
1613
  const m = (c == null ? void 0 : c.type) ?? "click", y = n.streamingManager;
1614
1614
  if (!(y != null && y.interruptAvailable) || !y.isInterruptible || !y.interrupt(m))
1615
1615
  return;
@@ -1618,56 +1618,56 @@ async function Wn(e, t) {
1618
1618
  video_duration_to_interrupt: Ne.get(!0),
1619
1619
  message_duration_to_interrupt: K.get(!0)
1620
1620
  });
1621
- const T = n.messages[n.messages.length - 1];
1622
- T && (T.interrupted = !0, (B = l.onNewMessage) == null || B.call(l, [...n.messages], "answer"));
1623
- }, z = /* @__PURE__ */ new Map();
1624
- function Z(c) {
1621
+ const E = n.messages[n.messages.length - 1];
1622
+ E && (E.interrupted = !0, (z = l.onNewMessage) == null || z.call(l, [...n.messages], "answer"));
1623
+ }, N = /* @__PURE__ */ new Map();
1624
+ function ee(c) {
1625
1625
  return async (m) => {
1626
- const y = z.get(c);
1626
+ const y = N.get(c);
1627
1627
  if (!y)
1628
1628
  throw new Error(`No handler registered for client tool: ${c}`);
1629
- const D = JSON.parse(m.payload);
1630
- return y(D);
1629
+ const M = JSON.parse(m.payload);
1630
+ return y(M);
1631
1631
  };
1632
1632
  }
1633
1633
  function we() {
1634
- var c, m, y, D;
1635
- for (const [T] of z)
1636
- (m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, T), (D = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || D.call(y, T, Z(T));
1634
+ var c, m, y, M;
1635
+ for (const [E] of N)
1636
+ (m = (c = n.streamingManager) == null ? void 0 : c.unregisterRpcMethod) == null || m.call(c, E), (M = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || M.call(y, E, ee(E));
1637
1637
  }
1638
1638
  function ae(c, m) {
1639
- var D, T;
1639
+ var M, E;
1640
1640
  if (!P)
1641
1641
  throw new R("registerClientTool is only available on Expressive (V4) agents");
1642
- const y = !z.has(c);
1643
- z.set(c, m), y && ((T = (D = n.streamingManager) == null ? void 0 : D.registerRpcMethod) == null || T.call(D, c, Z(c)));
1642
+ const y = !N.has(c);
1643
+ N.set(c, m), y && ((E = (M = n.streamingManager) == null ? void 0 : M.registerRpcMethod) == null || E.call(M, c, ee(c)));
1644
1644
  }
1645
- function E(c) {
1645
+ function k(c) {
1646
1646
  var m, y;
1647
- z.delete(c), (y = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || y.call(m, c);
1647
+ N.delete(c), (y = (m = n.streamingManager) == null ? void 0 : m.unregisterRpcMethod) == null || y.call(m, c);
1648
1648
  }
1649
1649
  const G = Date.now();
1650
1650
  nt(() => {
1651
1651
  d.track("agent-sdk", { event: "loaded", ...Wt(S) }, G);
1652
1652
  });
1653
- let j, ee = !1;
1653
+ let B, X = !1;
1654
1654
  function ve(c) {
1655
- return ee = !1, j = Promise.resolve().then(c).finally(() => {
1656
- j = void 0;
1657
- }), j;
1655
+ return X = !1, B = Promise.resolve().then(c).finally(() => {
1656
+ B = void 0;
1657
+ }), B;
1658
1658
  }
1659
1659
  function ie(c) {
1660
- return j || ve(() => X(c));
1660
+ return B || ve(() => Y(c));
1661
1661
  }
1662
- async function X(c) {
1663
- var J, Ee, ke, $;
1664
- if (ee)
1662
+ async function Y(c) {
1663
+ var J, Ee, Te, $;
1664
+ if (X)
1665
1665
  return;
1666
- At(), (J = l.onConnectionStateChange) == null || J.call(l, A.Connecting), K.reset(), c && !a && (delete n.chat, (Ee = l.onNewMessage) == null || Ee.call(l, [...n.messages], "answer"));
1666
+ n.streamingManager && await V(), At(), (J = l.onConnectionStateChange) == null || J.call(l, I.Connecting), K.reset(), c && !a && (delete n.chat, (Ee = l.onNewMessage) == null || Ee.call(l, [...n.messages], "answer"));
1667
1667
  const m = se(n.chatMode) ? on(
1668
1668
  p.auth,
1669
1669
  s,
1670
- { onMessage: V, onError: l.onError },
1670
+ { onMessage: U, onError: l.onError },
1671
1671
  p.externalId
1672
1672
  ) : Promise.resolve(void 0), y = Be(
1673
1673
  () => Fn(
@@ -1678,11 +1678,11 @@ async function Wn(e, t) {
1678
1678
  callbacks: {
1679
1679
  ...l,
1680
1680
  onVideoIdChange: ne,
1681
- onMessage: V
1681
+ onMessage: U
1682
1682
  },
1683
- rpcMethods: new Map([...z.keys()].map((N) => [N, Z(N)]))
1683
+ rpcMethods: new Map([...N.keys()].map((O) => [O, ee(O)]))
1684
1684
  },
1685
- M,
1685
+ D,
1686
1686
  d,
1687
1687
  n.chat
1688
1688
  ),
@@ -1690,36 +1690,36 @@ async function Wn(e, t) {
1690
1690
  limit: 3,
1691
1691
  timeout: Pt,
1692
1692
  timeoutErrorMessage: "Timeout initializing the stream",
1693
- shouldRetryFn: (N) => (N == null ? void 0 : N.message) !== "Could not connect" && !(N instanceof ht && (N.status === 429 || N.code === "InsufficientCreditsError")),
1693
+ shouldRetryFn: (O) => !(O instanceof ht && (O.status === 429 || O.code === "InsufficientCreditsError")),
1694
1694
  delayMs: 1e3
1695
1695
  }
1696
- ).catch((N) => {
1696
+ ).catch(async (O) => {
1697
1697
  var Ce;
1698
1698
  throw m.then((W) => W == null ? void 0 : W.disconnect()).catch(() => {
1699
- }), oe(x.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, A.Fail), N;
1700
- }), D = (ke = n.chat) == null ? void 0 : ke.id, [T, { streamingManager: B, chat: k }] = await Promise.all([m, y]), O = !!k && k.id !== D;
1701
- if (k && O && (($ = l.onNewChat) == null || $.call(l, k.id)), n.streamingManager = B, n.socketManager = T, n.chat = k, ee) {
1702
- await U();
1699
+ }), await oe(L.Maintenance), (Ce = l.onConnectionStateChange) == null || Ce.call(l, I.Fail), O;
1700
+ }), M = (Te = n.chat) == null ? void 0 : Te.id, [E, { streamingManager: z, chat: _ }] = await Promise.all([m, y]), b = !!_ && _.id !== M;
1701
+ if (_ && b && (($ = l.onNewChat) == null || $.call(l, _.id)), n.streamingManager = z, n.socketManager = E, n.chat = _, X) {
1702
+ await V();
1703
1703
  return;
1704
1704
  }
1705
1705
  we(), a = !1, d.enrich({
1706
- chatId: k == null ? void 0 : k.id,
1707
- streamId: B == null ? void 0 : B.streamId,
1706
+ chatId: _ == null ? void 0 : _.id,
1707
+ streamId: z == null ? void 0 : z.streamId,
1708
1708
  mode: n.chatMode
1709
1709
  });
1710
- const _ = (O ? k == null ? void 0 : k.chat_mode : void 0) ?? n.chatMode;
1711
- if (P && te(_)) {
1712
- console.warn(`[AgentManager] Ignoring chat mode "${_}": ${xe}`);
1710
+ const A = (b ? _ == null ? void 0 : _.chat_mode : void 0) ?? n.chatMode;
1711
+ if (P && te(A)) {
1712
+ console.warn(`[AgentManager] Ignoring chat mode "${A}": ${xe}`);
1713
1713
  return;
1714
1714
  }
1715
- await oe(_);
1715
+ await oe(A);
1716
1716
  }
1717
- async function U() {
1717
+ async function V() {
1718
1718
  var c, m, y;
1719
- (c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (y = l.onConnectionStateChange) == null || y.call(l, A.Disconnected);
1719
+ (c = n.socketManager) == null || c.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, g = void 0, (y = l.onConnectionStateChange) == null || y.call(l, I.Disconnected);
1720
1720
  }
1721
1721
  function se(c) {
1722
- return !P && c !== x.DirectPlayback;
1722
+ return !P && c !== L.DirectPlayback;
1723
1723
  }
1724
1724
  function Se(c) {
1725
1725
  const m = !te(c);
@@ -1730,7 +1730,7 @@ async function Wn(e, t) {
1730
1730
  if (c !== n.chatMode) {
1731
1731
  d.track("agent-mode-change", { mode: c }), n.chatMode = c;
1732
1732
  const y = !!n.streamingManager || !!n.socketManager;
1733
- (c !== x.Functional || y && !Se(c)) && await U(), (m = l.onModeChange) == null || m.call(l, c);
1733
+ (c !== L.Functional || y && !Se(c)) && await V(), (m = l.onModeChange) == null || m.call(l, c);
1734
1734
  }
1735
1735
  }
1736
1736
  async function ce(c) {
@@ -1751,18 +1751,18 @@ async function Wn(e, t) {
1751
1751
  // A copy: the same array instance is held by `agent.starter_message`, and handing it out
1752
1752
  // made `manager.starterMessages` an alias the application could write through.
1753
1753
  starterMessages: [...S.starter_message ?? []],
1754
- getSttToken: () => M.getSttToken(S.id),
1754
+ getSttToken: () => D.getSttToken(S.id),
1755
1755
  getChatMode: () => n.chatMode,
1756
1756
  getConnectionState: () => f,
1757
1757
  getSessionInfo: () => g,
1758
1758
  changeMode: ce,
1759
- enrichAnalytics: d.enrich,
1759
+ enrichAnalytics: (c) => d.enrich(c),
1760
1760
  async connect() {
1761
1761
  if (!l.onSrcObjectReady && !_e(n.chatMode))
1762
1762
  throw new R(lt);
1763
- if (j)
1764
- return j;
1765
- if (n.streamingManager)
1763
+ if (B)
1764
+ return X = !1, B;
1765
+ if (n.streamingManager && !Vn.includes(f))
1766
1766
  throw new R("Already connected; call disconnect() first");
1767
1767
  await ie(!0), n.streamingManager && d.track("agent-chat", {
1768
1768
  event: "connect",
@@ -1770,7 +1770,7 @@ async function Wn(e, t) {
1770
1770
  });
1771
1771
  },
1772
1772
  async reconnect() {
1773
- if (j)
1773
+ if (B)
1774
1774
  throw new R("A connect() is in flight; wait for it before calling reconnect()");
1775
1775
  return ve(async () => {
1776
1776
  const c = n.streamingManager;
@@ -1779,11 +1779,11 @@ async function Wn(e, t) {
1779
1779
  try {
1780
1780
  await c.reconnect();
1781
1781
  } catch (y) {
1782
- const D = Pe(y);
1783
- m = D.code ?? D.kind, await U(), await X(!1);
1782
+ const M = Pe(y);
1783
+ m = M.code ?? M.kind, await V(), await Y(!1);
1784
1784
  }
1785
1785
  else
1786
- await U(), await X(!1);
1786
+ await V(), await Y(!1);
1787
1787
  d.track("agent-chat", {
1788
1788
  event: "reconnect",
1789
1789
  mode: n.chatMode,
@@ -1795,7 +1795,7 @@ async function Wn(e, t) {
1795
1795
  });
1796
1796
  },
1797
1797
  async disconnect() {
1798
- j && (ee = !0), await U(), d.track("agent-chat", {
1798
+ B && (X = !0), await V(), d.track("agent-chat", {
1799
1799
  event: "disconnect",
1800
1800
  mode: n.chatMode
1801
1801
  });
@@ -1848,7 +1848,7 @@ async function Wn(e, t) {
1848
1848
  return (c = n.streamingManager) != null && c.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
1849
1849
  },
1850
1850
  async chat(c) {
1851
- var T, B, k;
1851
+ var E, z, _;
1852
1852
  const m = () => {
1853
1853
  if (te(n.chatMode))
1854
1854
  throw new R(`${n.chatMode} is enabled, chat is disabled`);
@@ -1856,31 +1856,31 @@ async function Wn(e, t) {
1856
1856
  throw new R(`Message cannot be more than ${He} characters`);
1857
1857
  if (c.length === 0)
1858
1858
  throw new R("Message cannot be empty");
1859
- if (n.chatMode === x.Maintenance)
1859
+ if (n.chatMode === L.Maintenance)
1860
1860
  throw new R("Chat is in maintenance mode");
1861
- if (![x.TextOnly, x.Playground].includes(n.chatMode)) {
1861
+ if (![L.TextOnly, L.Playground].includes(n.chatMode)) {
1862
1862
  if (!n.streamingManager)
1863
1863
  throw new R("Streaming manager is not initialized");
1864
1864
  if (!n.chat)
1865
1865
  throw new R("Chat is not initialized");
1866
1866
  }
1867
1867
  }, y = async () => {
1868
- var O;
1868
+ var b;
1869
1869
  if (!n.chat) {
1870
- const _ = await Dt(
1870
+ const A = await Dt(
1871
1871
  S,
1872
- M,
1872
+ D,
1873
1873
  d,
1874
1874
  n.chatMode,
1875
1875
  p.persistentChat
1876
1876
  );
1877
- if (!_.chat)
1877
+ if (!A.chat)
1878
1878
  throw new jt(n.chatMode, !!p.persistentChat);
1879
- n.chat = _.chat, (O = l.onNewChat) == null || O.call(l, n.chat.id);
1879
+ n.chat = A.chat, (b = l.onNewChat) == null || b.call(l, n.chat.id);
1880
1880
  }
1881
1881
  return n.chat.id;
1882
- }, D = async (O, _) => {
1883
- const J = n.chatMode === x.Playground;
1882
+ }, M = async (b, A) => {
1883
+ const J = n.chatMode === L.Playground;
1884
1884
  return Be(P && !J ? async () => {
1885
1885
  var $;
1886
1886
  return await (($ = n.streamingManager) == null ? void 0 : $.sendDataChannelMessage(
@@ -1888,15 +1888,15 @@ async function Wn(e, t) {
1888
1888
  c
1889
1889
  )), Promise.resolve({});
1890
1890
  } : async () => {
1891
- var $, N;
1892
- return M.chat(
1891
+ var $, O;
1892
+ return D.chat(
1893
1893
  S.id,
1894
- _,
1894
+ A,
1895
1895
  {
1896
1896
  chatMode: n.chatMode,
1897
1897
  streamId: ($ = n.streamingManager) == null ? void 0 : $.streamId,
1898
- sessionId: (N = n.streamingManager) == null ? void 0 : N.sessionId,
1899
- messages: O.map(({ matches: Ce, ...W }) => W)
1898
+ sessionId: (O = n.streamingManager) == null ? void 0 : O.sessionId,
1899
+ messages: b.map(({ matches: Ce, ...W }) => W)
1900
1900
  },
1901
1901
  {
1902
1902
  ...Mt(n.chatMode),
@@ -1907,84 +1907,84 @@ async function Wn(e, t) {
1907
1907
  limit: 2,
1908
1908
  shouldRetryFn: ($) => {
1909
1909
  var W, Ue, Je;
1910
- const N = (W = $ == null ? void 0 : $.message) == null ? void 0 : W.includes("missing or invalid session_id");
1911
- return !((Ue = $ == null ? void 0 : $.message) == null ? void 0 : Ue.includes("Stream Error")) && !N ? ((Je = l.onError) == null || Je.call(l, $), !1) : !0;
1910
+ const O = (W = $ == null ? void 0 : $.message) == null ? void 0 : W.includes("missing or invalid session_id");
1911
+ return !((Ue = $ == null ? void 0 : $.message) == null ? void 0 : Ue.includes("Stream Error")) && !O ? ((Je = l.onError) == null || Je.call(l, $), !1) : !0;
1912
1912
  },
1913
1913
  onRetry: async () => {
1914
- await U(), await ie(!1);
1914
+ await V(), await ie(!1);
1915
1915
  }
1916
1916
  });
1917
1917
  };
1918
1918
  try {
1919
- L(), m(), n.messages.push({
1920
- id: Q(),
1919
+ j(), m(), n.messages.push({
1920
+ id: Z(),
1921
1921
  role: "user",
1922
1922
  content: c,
1923
1923
  parts: he(c),
1924
1924
  createdAt: new Date(K.update()).toISOString()
1925
- }), (T = l.onNewMessage) == null || T.call(l, [...n.messages], "user");
1926
- const O = await y(), _ = await D([...n.messages], O);
1927
- return _.result && n.messages.push({
1928
- id: Q(),
1925
+ }), (E = l.onNewMessage) == null || E.call(l, [...n.messages], "user");
1926
+ const b = await y(), A = await M([...n.messages], b);
1927
+ return A.result && n.messages.push({
1928
+ id: Z(),
1929
1929
  role: "assistant",
1930
- content: _.result,
1931
- parts: he(_.result),
1930
+ content: A.result,
1931
+ parts: he(A.result),
1932
1932
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1933
- context: _.context,
1934
- matches: _.matches
1933
+ context: A.context,
1934
+ matches: A.matches
1935
1935
  }), d.track("agent-message-send", {
1936
1936
  event: "success",
1937
1937
  messages: n.messages.length + 1
1938
- }), _.result && ((B = l.onNewMessage) == null || B.call(l, [...n.messages], "answer"), d.track("agent-message-received", {
1938
+ }), A.result && ((z = l.onNewMessage) == null || z.call(l, [...n.messages], "answer"), d.track("agent-message-received", {
1939
1939
  latency: K.get(!0),
1940
1940
  messages: n.messages.length
1941
- })), _;
1942
- } catch (O) {
1943
- throw ((k = n.messages[n.messages.length - 1]) == null ? void 0 : k.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
1941
+ })), A;
1942
+ } catch (b) {
1943
+ throw ((_ = n.messages[n.messages.length - 1]) == null ? void 0 : _.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
1944
1944
  event: "error",
1945
1945
  messages: n.messages.length,
1946
- error: Pe(O)
1947
- }), O;
1946
+ error: Pe(b)
1947
+ }), b;
1948
1948
  }
1949
1949
  },
1950
1950
  async rate(c, m, y) {
1951
- var B, k, O, _;
1952
- const D = n.messages.find((J) => J.id === c);
1951
+ var z, _, b, A;
1952
+ const M = n.messages.find((J) => J.id === c);
1953
1953
  if (n.chat) {
1954
- if (!D)
1954
+ if (!M)
1955
1955
  throw new R("Message not found");
1956
1956
  } else throw new R("Chat is not initialized");
1957
- const T = ((B = D.matches) == null ? void 0 : B.map((J) => [J.document_id, J.id])) ?? [];
1957
+ const E = ((z = M.matches) == null ? void 0 : z.map((J) => [J.document_id, J.id])) ?? [];
1958
1958
  return d.track("agent-rate", {
1959
1959
  event: y ? "update" : "create",
1960
1960
  thumb: m === 1 ? "up" : "down",
1961
- knowledge_id: ((k = S.knowledge) == null ? void 0 : k.id) ?? "",
1962
- matches: T,
1961
+ knowledge_id: ((_ = S.knowledge) == null ? void 0 : _.id) ?? "",
1962
+ matches: E,
1963
1963
  score: m
1964
- }), y ? M.updateRating(S.id, n.chat.id, y, {
1965
- knowledge_id: ((O = S.knowledge) == null ? void 0 : O.id) ?? "",
1964
+ }), y ? D.updateRating(S.id, n.chat.id, y, {
1965
+ knowledge_id: ((b = S.knowledge) == null ? void 0 : b.id) ?? "",
1966
1966
  message_id: c,
1967
- matches: T,
1967
+ matches: E,
1968
1968
  score: m
1969
- }) : M.createRating(S.id, n.chat.id, {
1970
- knowledge_id: ((_ = S.knowledge) == null ? void 0 : _.id) ?? "",
1969
+ }) : D.createRating(S.id, n.chat.id, {
1970
+ knowledge_id: ((A = S.knowledge) == null ? void 0 : A.id) ?? "",
1971
1971
  message_id: c,
1972
- matches: T,
1972
+ matches: E,
1973
1973
  score: m
1974
1974
  });
1975
1975
  },
1976
1976
  async deleteRate(c) {
1977
1977
  if (!n.chat)
1978
1978
  throw new R("Chat is not initialized");
1979
- return d.track("agent-rate-delete", { type: "text" }), M.deleteRating(S.id, n.chat.id, c);
1979
+ return d.track("agent-rate-delete", { type: "text" }), D.deleteRating(S.id, n.chat.id, c);
1980
1980
  },
1981
1981
  async submitFeedback(c, m) {
1982
1982
  if (!n.chat)
1983
1983
  throw new R("Chat is not initialized");
1984
- return d.track("agent-feedback", { rating: c, hasAnswer: !!m }), M.submitFeedback(S.id, n.chat.id, { rating: c, answer: m });
1984
+ return d.track("agent-feedback", { rating: c, hasAnswer: !!m }), D.submitFeedback(S.id, n.chat.id, { rating: c, answer: m });
1985
1985
  },
1986
1986
  async speak(c) {
1987
- var B, k;
1987
+ var _, b;
1988
1988
  function m() {
1989
1989
  return typeof c == "string" ? {
1990
1990
  type: "text",
@@ -1998,42 +1998,41 @@ async function Wn(e, t) {
1998
1998
  sentiment: c.sentiment
1999
1999
  } : c;
2000
2000
  }
2001
- const y = m();
2002
- d.track("agent-speak", y), K.update(), n.messages && y.type === "text" && (n.messages.push({
2003
- id: Q(),
2001
+ const y = _e(n.chatMode);
2002
+ if (!y && !n.streamingManager)
2003
+ throw new R("Please connect to the agent first");
2004
+ const M = m();
2005
+ d.track("agent-speak", M), K.update(), n.messages && M.type === "text" && (n.messages.push({
2006
+ id: Z(),
2004
2007
  role: "assistant",
2005
- content: y.input,
2006
- parts: he(y.input),
2008
+ content: M.input,
2009
+ parts: he(M.input),
2007
2010
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
2008
- }), (B = l.onNewMessage) == null || B.call(l, [...n.messages], "answer"));
2009
- const D = { duration: 0, videoId: "", status: "success" };
2010
- if (_e(n.chatMode))
2011
- return D;
2012
- if (!n.streamingManager)
2013
- throw new R("Please connect to the agent first");
2014
- return await n.streamingManager.speak({
2015
- script: y,
2016
- metadata: { chat_id: (k = n.chat) == null ? void 0 : k.id, agent_id: S.id }
2017
- }) ?? D;
2011
+ }), (_ = l.onNewMessage) == null || _.call(l, [...n.messages], "answer"));
2012
+ const E = { duration: 0, videoId: "", status: "success" };
2013
+ return y || !n.streamingManager ? E : await n.streamingManager.speak({
2014
+ script: M,
2015
+ metadata: { chat_id: (b = n.chat) == null ? void 0 : b.id, agent_id: S.id }
2016
+ }) ?? E;
2018
2017
  },
2019
2018
  interrupt: re,
2020
2019
  registerClientTool: ae,
2021
- unregisterClientTool: E
2020
+ unregisterClientTool: k
2022
2021
  };
2023
2022
  }
2024
- function Kn(e) {
2023
+ function qn(e) {
2025
2024
  return e.some((t) => t.executionMode === "blocking");
2026
2025
  }
2027
2026
  export {
2028
2027
  ye as A,
2029
2028
  q as B,
2030
2029
  F as C,
2031
- kt as D,
2030
+ Tt as D,
2032
2031
  ht as H,
2033
2032
  Re as I,
2034
2033
  Nt as N,
2035
- Tt as P,
2036
- I as S,
2034
+ kt as P,
2035
+ T as S,
2037
2036
  Le as T,
2038
2037
  R as V,
2039
2038
  zt as W,
@@ -2042,23 +2041,23 @@ export {
2042
2041
  vt as c,
2043
2042
  Ie as d,
2044
2043
  pt as e,
2045
- A as f,
2044
+ I as f,
2046
2045
  me as g,
2047
2046
  In as h,
2048
- Hn as i,
2047
+ Wn as i,
2049
2048
  C as j,
2050
2049
  pe as k,
2051
2050
  K as l,
2052
2051
  jt as m,
2053
- Un as n,
2054
- x as o,
2052
+ Jn as n,
2053
+ L as o,
2055
2054
  Bt as p,
2056
2055
  ge as q,
2057
2056
  _t as r,
2058
- Wn as s,
2057
+ Kn as s,
2059
2058
  Pe as t,
2060
- Kn as u,
2061
- Jn as v,
2059
+ qn as u,
2060
+ Hn as v,
2062
2061
  wt as w
2063
2062
  };
2064
- //# sourceMappingURL=index-BhhDKHW-.js.map
2063
+ //# sourceMappingURL=index-D-HEM_62.js.map