@tavus/embed 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3015,7 +3015,7 @@ var Nn = class extends Error {
3015
3015
  }
3016
3016
  }, Pn = {
3017
3017
  name: "@tavus/embed",
3018
- version: "0.13.0",
3018
+ version: "0.14.0",
3019
3019
  variant: "embed"
3020
3020
  }, Fn = /* @__PURE__ */ new Set([
3021
3021
  "Error",
@@ -14773,14 +14773,14 @@ function qm(e, t) {
14773
14773
  return t ? e instanceof yn && e.status === 401 : !1;
14774
14774
  }
14775
14775
  function Jm({ children: e }) {
14776
- let { deploymentId: t, client: n, config: r, telemetry: i } = F(Dr), a = N(() => ({ current: null }), [n, t]), { memoryStores: o, conversationalContext: s, customGreeting: c } = F(vt), l = Lf(), u = Pf()?.store.devices, d = Rf(), f = F(tm), p = N(() => Rt("idle"), []), m = N(() => Rt(null), []), h = N(() => Rt([]), []), g = N(() => Rt(""), []), _ = N(() => Rt(null), []), v = N(() => Rt(null), []), y = N(() => Rt(null), []), b = N(() => Rt(null), []), x = M(null), S = M(null), C = N(() => Rt(null), []), w = M(null), T = M([]), E = N(() => jm(), []), D = N(() => /* @__PURE__ */ new Set(), []), ee = N(() => Rt("idle"), []), O = f?.flowSignal ?? ee, te = P((e) => {
14777
- y.value = e;
14778
- }, [y]), ne = P((e) => {
14776
+ let { deploymentId: t, client: n, config: r, telemetry: i } = F(Dr), a = N(() => ({ current: null }), [n, t]), { memoryStores: o, conversationalContext: s, customGreeting: c } = F(vt), l = Lf(), u = Pf()?.store.devices, d = Rf(), f = F(tm), p = N(() => Rt("idle"), []), m = N(() => Rt(null), []), h = N(() => Rt(null), []), g = N(() => Rt([]), []), _ = N(() => Rt(""), []), v = N(() => Rt(null), []), y = N(() => Rt(null), []), b = N(() => Rt(null), []), x = N(() => Rt(null), []), S = M(null), C = M(null), w = N(() => Rt(null), []), T = M(null), E = M(null), D = M([]), ee = N(() => jm(), []), O = N(() => /* @__PURE__ */ new Set(), []), te = N(() => Rt("idle"), []), ne = f?.flowSignal ?? te, re = P((e) => {
14779
14777
  b.value = e;
14780
- }, [b]);
14778
+ }, [b]), ie = P((e) => {
14779
+ x.value = e;
14780
+ }, [x]);
14781
14781
  j(() => {
14782
14782
  if (!l?.on || !i) return;
14783
- let e, t = C.subscribe((t) => {
14783
+ let e, t = w.subscribe((t) => {
14784
14784
  if (e?.(), e = void 0, t === null) return;
14785
14785
  let r = {
14786
14786
  conversation_id: t,
@@ -14832,44 +14832,44 @@ function Jm({ children: e }) {
14832
14832
  l,
14833
14833
  i,
14834
14834
  n,
14835
- C
14835
+ w
14836
14836
  ]);
14837
- let re = P(() => {
14838
- let e = C.peek();
14839
- return e !== null && (C.value = null, m.peek()?.conversationId === e);
14840
- }, [C, m]);
14837
+ let ae = P(() => {
14838
+ let e = w.peek();
14839
+ return e !== null && (w.value = null, m.peek()?.conversationId === e);
14840
+ }, [w, m]);
14841
14841
  Vf("joined-meeting", () => {
14842
- let e = C.peek();
14842
+ let e = w.peek();
14843
14843
  e !== null && e === m.peek()?.conversationId && p.peek() === "connecting" && (p.value = "connected", Mm.info("Connected to meeting"));
14844
14844
  }), Vf("left-meeting", () => {
14845
- re() && (Pp(T.current), p.value = "ended", mm(), Mm.info("Left meeting"));
14845
+ ae() && (Pp(D.current), p.value = "ended", mm(), Mm.info("Left meeting"));
14846
14846
  }), Vf("error", () => {
14847
- re() && (Pp(T.current), i?.record({
14847
+ ae() && (Pp(D.current), i?.record({
14848
14848
  stage: "join",
14849
14849
  outcome: "failed",
14850
14850
  code: "meeting_error",
14851
14851
  conversation_id: m.peek()?.conversationId
14852
- }), v.value = "Meeting error", p.value = "error");
14852
+ }), y.value = "Meeting error", p.value = "error");
14853
14853
  });
14854
- let ie = P(() => C.peek() === null ? d === "joining-meeting" || d === "joined-meeting" : !1, [C, d]), ae = P(() => w.current, []);
14854
+ let oe = P(() => w.peek() === null ? d === "joining-meeting" || d === "joined-meeting" : !1, [w, d]), k = P(() => T.current, []);
14855
14855
  fn(() => {
14856
14856
  let e = p.value;
14857
- if (e === "connected") for (let e of D) e.onConnect?.();
14858
- else if (e === "ended" || e === "disconnecting") for (let e of D) e.onDisconnect?.();
14857
+ if (e === "connected") for (let e of O) e.onConnect?.();
14858
+ else if (e === "ended" || e === "disconnecting") for (let e of O) e.onDisconnect?.();
14859
14859
  else if (e === "error") {
14860
- let e = v.peek() ?? "Unknown error";
14861
- for (let t of D) t.onError?.({
14860
+ let e = y.peek() ?? "Unknown error";
14861
+ for (let t of O) t.onError?.({
14862
14862
  code: "CONVERSATION_ERROR",
14863
14863
  message: e
14864
14864
  });
14865
14865
  }
14866
14866
  }), fn(() => {
14867
- let e = O.value;
14868
- for (let t of D) t.onModeChange?.(e);
14867
+ let e = ne.value;
14868
+ for (let t of O) t.onModeChange?.(e);
14869
14869
  }), Hf({ onAppMessage: P((e) => {
14870
14870
  Am(e?.data, {
14871
14871
  appendChatMessage(e, t) {
14872
- e === "user" && E.consumeMatch(t) || (h.value = [...h.peek(), {
14872
+ e === "user" && ee.consumeMatch(t) || (g.value = [...g.peek(), {
14873
14873
  id: crypto.randomUUID(),
14874
14874
  sender: e,
14875
14875
  text: t,
@@ -14877,35 +14877,37 @@ function Jm({ children: e }) {
14877
14877
  }]);
14878
14878
  },
14879
14879
  setCaption(e, t, n) {
14880
- g.value = e, _.value = n, x.current !== null && (clearTimeout(x.current), x.current = null), t && (x.current = setTimeout(() => {
14881
- g.value = "", _.value = null, x.current = null;
14880
+ _.value = e, v.value = n, S.current !== null && (clearTimeout(S.current), S.current = null), t && (S.current = setTimeout(() => {
14881
+ _.value = "", v.value = null, S.current = null;
14882
14882
  }, Nm));
14883
14883
  }
14884
14884
  });
14885
14885
  let t = Om(e?.data);
14886
- t && Wm(t, D, E);
14886
+ t && Wm(t, O, ee);
14887
14887
  }, [
14888
- h,
14889
14888
  g,
14890
14889
  _,
14891
- E,
14892
- D
14890
+ v,
14891
+ ee,
14892
+ O
14893
14893
  ]) }), j(() => () => {
14894
- x.current !== null && (clearTimeout(x.current), x.current = null);
14894
+ S.current !== null && (clearTimeout(S.current), S.current = null);
14895
14895
  }, []);
14896
- let oe = M(!1), k = P((e = !1) => {
14897
- e || i?.beginAttempt?.(), oe.current = !0, S.current = null, m.value = null, h.value = [], g.value = "", _.value = null, x.current !== null && (clearTimeout(x.current), x.current = null), (p.peek() === "ended" || p.peek() === "error") && (p.value = "idle");
14896
+ let se = M(!1), ce = P((e = !1) => {
14897
+ let t = E.current !== null && !E.current.claimed;
14898
+ !e && h.peek() === null && !t && i?.beginAttempt?.(), se.current = !0, C.current = null, m.value = null, g.value = [], _.value = "", v.value = null, S.current !== null && (clearTimeout(S.current), S.current = null), (p.peek() === "ended" || p.peek() === "error") && (p.value = "idle");
14898
14899
  }, [
14899
14900
  m,
14900
- p,
14901
14901
  h,
14902
+ p,
14902
14903
  g,
14903
14904
  _,
14905
+ v,
14904
14906
  i
14905
- ]), se = P(() => {
14906
- let e = m.peek()?.conversationId ?? null, r = S.current;
14907
+ ]), le = P(() => {
14908
+ let e = m.peek()?.conversationId ?? null, r = C.current;
14907
14909
  if (r?.conversationId === e) return r.promise;
14908
- p.value = "disconnecting", Pp(T.current);
14910
+ p.value = "disconnecting", Pp(D.current);
14909
14911
  let a = !1, o = e ? xr(i, "end", () => wn(n, t, e, { keepalive: !0 }), e).catch((e) => {
14910
14912
  a = !0, Mm.error("End conversation API failed", e);
14911
14913
  }) : Promise.resolve(), s;
@@ -14931,13 +14933,13 @@ function Jm({ children: e }) {
14931
14933
  conversation_id: e ?? void 0
14932
14934
  }), Mm.error("Daily leave failed", t);
14933
14935
  }), u = c.then(() => {
14934
- w.current === u && (w.current = null);
14936
+ T.current === u && (T.current = null);
14935
14937
  });
14936
- w.current = u;
14938
+ T.current = u;
14937
14939
  let d = Promise.all([o, c]).then(() => {
14938
- S.current?.promise === d && (C.peek() === e && (C.value = null), p.value = "ended", a && (S.current = null));
14940
+ C.current?.promise === d && (w.peek() === e && (w.value = null), p.value = "ended", a && (C.current = null));
14939
14941
  });
14940
- return S.current = {
14942
+ return C.current = {
14941
14943
  conversationId: e,
14942
14944
  promise: d
14943
14945
  }, d;
@@ -14947,49 +14949,101 @@ function Jm({ children: e }) {
14947
14949
  l,
14948
14950
  m,
14949
14951
  p,
14950
- C,
14952
+ w,
14951
14953
  i
14952
- ]), ce = P(async (e, d) => {
14953
- let f = null, h = [];
14954
- try {
14955
- oe.current || k(), oe.current = !1, p.value = "connecting", v.value = null;
14956
- let g = e, _ = y.peek();
14957
- _ && g?.password == null && (g = {
14958
- ...g,
14959
- password: _
14960
- });
14961
- let x = r.value.customization.conversation.unique_memory_tag === !0;
14962
- if (!g?.memory_stores) {
14963
- let e = o ?? (x ? [om(t)] : []);
14964
- e.length && (g = {
14965
- ...g,
14966
- memory_stores: e
14967
- });
14968
- }
14969
- g = Gm(g, s, c);
14970
- let S = b.peek();
14971
- S && g?.captcha_token == null && (g = {
14972
- ...g,
14973
- captcha_token: S
14974
- });
14975
- let E = await em(n, t, r.peek().start_security, g, d, i, a, () => {
14976
- b.value = null;
14954
+ ]), ue = P(async (e, l) => {
14955
+ let u = e, d = b.peek();
14956
+ d && u?.password == null && (u = {
14957
+ ...u,
14958
+ password: d
14959
+ });
14960
+ let f = r.value.customization.conversation.unique_memory_tag === !0;
14961
+ if (!u?.memory_stores) {
14962
+ let e = o ?? (f ? [om(t)] : []);
14963
+ e.length && (u = {
14964
+ ...u,
14965
+ memory_stores: e
14977
14966
  });
14978
- if (f = E.conversation_id, m.value = {
14979
- conversationId: E.conversation_id,
14980
- conversationName: E.conversation_name,
14981
- conversationUrl: E.conversation_url,
14982
- callbackUrl: E.callback_url,
14983
- createdAt: E.created_at,
14984
- magicGrid: E.magic_grid === !0
14985
- }, console.info("[Tavus:Conversation] Conversation created:", E.conversation_id), d?.signal?.aborted) throw d.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
14986
- let D = r.value.customization.conversation.modality === "chat", ee = w.current;
14987
- ee && await Pm(ee, d?.signal);
14988
- let O = Np(E.conversation_url, D, d?.devices, h);
14989
- if (u?.setProvidedTracks(typeof O?.audioSource == "object" ? O.audioSource : void 0, typeof O?.videoSource == "object" ? O.videoSource : void 0), C.value = E.conversation_id, await xr(i, "join", () => Fm(l, O, d?.signal), E.conversation_id, {
14967
+ }
14968
+ u = Gm(u, s, c);
14969
+ let p = x.peek();
14970
+ p && u?.captcha_token == null && (u = {
14971
+ ...u,
14972
+ captcha_token: p
14973
+ });
14974
+ let m = await em(n, t, r.peek().start_security, u, l, i, a, () => {
14975
+ x.value = null;
14976
+ });
14977
+ return console.info("[Tavus:Conversation] Conversation created:", m.conversation_id), {
14978
+ conversationId: m.conversation_id,
14979
+ conversationName: m.conversation_name,
14980
+ conversationUrl: m.conversation_url,
14981
+ callbackUrl: m.callback_url,
14982
+ createdAt: m.created_at,
14983
+ magicGrid: m.magic_grid === !0
14984
+ };
14985
+ }, [
14986
+ n,
14987
+ a,
14988
+ i,
14989
+ t,
14990
+ b,
14991
+ x,
14992
+ r,
14993
+ o,
14994
+ s,
14995
+ c
14996
+ ]), de = P((e) => xr(i, "end", () => wn(n, t, e.conversationId, { keepalive: !0 }), e.conversationId).catch((e) => {
14997
+ Mm.error("End created conversation API failed", e);
14998
+ }), [
14999
+ n,
15000
+ t,
15001
+ i
15002
+ ]), fe = P(() => {
15003
+ let e = E.current;
15004
+ return !e || e.claimed ? null : (e.claimed = !0, e.promise.catch(() => null));
15005
+ }, []), pe = P(async () => {
15006
+ let e = fe(), t = h.peek();
15007
+ h.value = null;
15008
+ let n = e ? await e : null;
15009
+ await Promise.all([t, n].filter((e) => e !== null).map(de));
15010
+ }, [
15011
+ fe,
15012
+ h,
15013
+ de
15014
+ ]), me = P((e, t) => {
15015
+ let n = E.current;
15016
+ if (n && !n.claimed) return n.promise;
15017
+ let a = pe();
15018
+ i?.beginAttempt?.();
15019
+ let o = { claimed: !1 };
15020
+ return o.promise = a.then(() => ue(e, t)).then((e) => (E.current === o && (E.current = null), o.claimed || (h.value = e), e), (e) => {
15021
+ throw E.current === o && (E.current = null), qm(e, r.value.has_password === !0) && (b.value = null), Mm.error("Create failed", e), e;
15022
+ }), E.current = o, o.promise;
15023
+ }, [
15024
+ pe,
15025
+ i,
15026
+ ue,
15027
+ h,
15028
+ r,
15029
+ b
15030
+ ]), he = M(pe);
15031
+ he.current = pe, j(() => () => void he.current(), []);
15032
+ let ge = P(async (e, t) => {
15033
+ let n = null, a = [];
15034
+ try {
15035
+ se.current || ce(), se.current = !1, p.value = "connecting", y.value = null;
15036
+ let o = h.peek(), s = o ? null : fe(), c = o ?? (s ? await s : null) ?? await ue(e, t);
15037
+ if (n = c.conversationId, Tt(() => {
15038
+ o && (h.value = null), m.value = c;
15039
+ }), t?.signal?.aborted) throw t.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
15040
+ let d = r.value.customization.conversation.modality === "chat", f = T.current;
15041
+ f && await Pm(f, t?.signal);
15042
+ let g = Np(c.conversationUrl, d, t?.devices, a);
15043
+ if (u?.setProvidedTracks(typeof g?.audioSource == "object" ? g.audioSource : void 0, typeof g?.videoSource == "object" ? g.videoSource : void 0), w.value = c.conversationId, await xr(i, "join", () => Fm(l, g, t?.signal), c.conversationId, {
14990
15044
  operation: "daily.join",
14991
15045
  component: "conversation"
14992
- }), Im(l, D, d?.devices) && Km(l)) {
15046
+ }), Im(l, d, t?.devices) && Km(l)) {
14993
15047
  let e = new Fp();
14994
15048
  throw br(i, e, {
14995
15049
  stage: "permissions",
@@ -15000,37 +15054,33 @@ function Jm({ children: e }) {
15000
15054
  handled: !0
15001
15055
  }), e;
15002
15056
  }
15003
- T.current.push(...h), oe.current = !1;
15057
+ D.current.push(...a), se.current = !1;
15004
15058
  } catch (e) {
15005
- throw Pp(h), await se(), f && (m.value = null), qm(e, r.value.has_password === !0) && (y.value = null), Mm.error("Start failed", e), v.value = String(e), p.value = "error", e;
15059
+ throw Pp(a), await le(), n && (m.value = null), qm(e, r.value.has_password === !0) && (b.value = null), Mm.error("Start failed", e), y.value = String(e), p.value = "error", e;
15006
15060
  }
15007
15061
  }, [
15008
- n,
15009
- a,
15010
15062
  i,
15011
- t,
15012
15063
  l,
15013
15064
  u,
15014
15065
  p,
15015
- v,
15016
- m,
15017
15066
  y,
15067
+ m,
15068
+ h,
15069
+ fe,
15018
15070
  b,
15019
15071
  r,
15020
- o,
15021
- s,
15022
- c,
15023
- k,
15024
- se,
15025
- C
15026
- ]), le = P((e) => {
15072
+ ue,
15073
+ ce,
15074
+ le,
15075
+ w
15076
+ ]), _e = P((e) => {
15027
15077
  if (!l) return;
15028
15078
  let t = m.peek();
15029
15079
  if (!t) {
15030
15080
  Mm.warn("sendChat called before session was established; dropping message");
15031
15081
  return;
15032
15082
  }
15033
- E.markSent(e), l.sendAppMessage(vm(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*"), h.value = [...h.peek(), {
15083
+ ee.markSent(e), l.sendAppMessage(vm(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*"), g.value = [...g.peek(), {
15034
15084
  id: crypto.randomUUID(),
15035
15085
  sender: "user",
15036
15086
  text: e,
@@ -15038,11 +15088,11 @@ function Jm({ children: e }) {
15038
15088
  }];
15039
15089
  }, [
15040
15090
  l,
15041
- h,
15091
+ g,
15042
15092
  m,
15043
- E,
15093
+ ee,
15044
15094
  r
15045
- ]), ue = P((e) => {
15095
+ ]), ve = P((e) => {
15046
15096
  if (!l) {
15047
15097
  Mm.warn("sendMessage called before Daily was ready; dropping message");
15048
15098
  return;
@@ -15052,42 +15102,46 @@ function Jm({ children: e }) {
15052
15102
  Mm.warn("sendMessage called before session was established; dropping message");
15053
15103
  return;
15054
15104
  }
15055
- e.event_type === "conversation.respond" && E.markSent(e.properties.text), l.sendAppMessage(km(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*");
15105
+ e.event_type === "conversation.respond" && ee.markSent(e.properties.text), l.sendAppMessage(km(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*");
15056
15106
  }, [
15057
15107
  l,
15058
15108
  m,
15059
- E,
15109
+ ee,
15060
15110
  r
15061
- ]), de = P((e) => {
15062
- D.add(e);
15063
- }, [D]), fe = P((e) => {
15064
- D.delete(e);
15065
- }, [D]), pe = N(() => ({
15111
+ ]), ye = P((e) => {
15112
+ O.add(e);
15113
+ }, [O]), be = P((e) => {
15114
+ O.delete(e);
15115
+ }, [O]), xe = N(() => ({
15066
15116
  state: p,
15067
15117
  session: m,
15068
- chatMessages: h,
15069
- captionText: g,
15070
- captionRole: _,
15071
- error: v,
15072
- password: y,
15073
- setPassword: te,
15074
- captchaToken: b,
15075
- setCaptchaToken: ne,
15076
- mode: O,
15077
- start: ce,
15078
- end: se,
15079
- sendChat: le,
15080
- sendMessage: ue,
15118
+ createdSession: h,
15119
+ chatMessages: g,
15120
+ captionText: _,
15121
+ captionRole: v,
15122
+ error: y,
15123
+ password: b,
15124
+ setPassword: re,
15125
+ captchaToken: x,
15126
+ setCaptchaToken: ie,
15127
+ mode: ne,
15128
+ start: ge,
15129
+ create: me,
15130
+ discardCreatedConversation: pe,
15131
+ end: le,
15132
+ sendChat: _e,
15133
+ sendMessage: ve,
15081
15134
  conversation: {
15082
- start: ce,
15083
- end: se,
15084
- sendMessage: ue
15085
- },
15086
- __registerSubscriber: de,
15087
- __unregisterSubscriber: fe,
15088
- __beginAttempt: k,
15089
- isSharedCallBusy: ie,
15090
- pendingLeave: ae
15135
+ start: ge,
15136
+ create: me,
15137
+ end: le,
15138
+ sendMessage: ve
15139
+ },
15140
+ __registerSubscriber: ye,
15141
+ __unregisterSubscriber: be,
15142
+ __beginAttempt: ce,
15143
+ isSharedCallBusy: oe,
15144
+ pendingLeave: k
15091
15145
  }), [
15092
15146
  p,
15093
15147
  m,
@@ -15096,22 +15150,25 @@ function Jm({ children: e }) {
15096
15150
  _,
15097
15151
  v,
15098
15152
  y,
15099
- te,
15100
15153
  b,
15154
+ re,
15155
+ x,
15156
+ ie,
15101
15157
  ne,
15102
- O,
15103
- ce,
15104
- se,
15158
+ ge,
15159
+ me,
15160
+ pe,
15105
15161
  le,
15106
- ue,
15107
- de,
15108
- fe,
15109
- k,
15110
- ie,
15111
- ae
15162
+ _e,
15163
+ ve,
15164
+ ye,
15165
+ be,
15166
+ ce,
15167
+ oe,
15168
+ k
15112
15169
  ]);
15113
15170
  return /* @__PURE__ */ I(Lm.Provider, {
15114
- value: pe,
15171
+ value: xe,
15115
15172
  children: e
15116
15173
  });
15117
15174
  }
@@ -15288,30 +15345,42 @@ function oh({ children: e }) {
15288
15345
  stage: "captcha",
15289
15346
  outcome: "interactive"
15290
15347
  }), u.value = e;
15291
- }, [u, r]), w = P(async (e) => (t.peek().captcha ?? null) === null ? { kind: "not-required" } : (i?.captchaToken.peek() ?? null) === null ? (l.peek() && (l.value = !1, c.value = c.peek() + 1), s.peek() || (f.current = performance.now(), r?.record({
15348
+ }, [u, r]), w = P(async (e, { waitForHuman: n = !0 } = {}) => (t.peek().captcha ?? null) === null ? { kind: "not-required" } : (i?.captchaToken.peek() ?? null) === null ? (l.peek() && (l.value = !1, c.value = c.peek() + 1), s.peek() || (f.current = performance.now(), r?.record({
15292
15349
  stage: "captcha",
15293
15350
  outcome: "started"
15294
15351
  })), s.value = !0, new Promise((t) => {
15295
- let n = !1, a, o, s = u.subscribe((e) => {
15296
- clearTimeout(a), !e && (a = setTimeout(() => y("Captcha mint timed out", "timeout"), ih));
15297
- }), c = (r) => {
15298
- if (n) return;
15299
- n = !0, clearTimeout(a), s(), e?.removeEventListener("abort", l), o?.();
15300
- let i = d.current.indexOf(c);
15301
- i !== -1 && d.current.splice(i, 1), t(r);
15302
- }, l = () => {
15303
- c({
15304
- kind: "unavailable",
15305
- reason: "cancelled"
15306
- }), d.current.length === 0 && (r?.record({
15352
+ let a = !1, o, s, c, l = (n) => {
15353
+ if (a) return;
15354
+ a = !0, clearTimeout(o), c?.(), e?.removeEventListener("abort", m), s?.();
15355
+ let r = d.current.indexOf(l);
15356
+ r !== -1 && d.current.splice(r, 1), t(n);
15357
+ }, p = (e) => {
15358
+ l(e), d.current.length === 0 && (r?.record({
15307
15359
  stage: "captcha",
15308
15360
  outcome: "cancelled",
15361
+ code: e.reason,
15309
15362
  duration_ms: performance.now() - f.current
15310
15363
  }), v());
15311
- };
15312
- o = i?.captchaToken.subscribe((e) => {
15313
- e !== null && c({ kind: "token" });
15314
- }), d.current.push(c), e?.aborted ? l() : e?.addEventListener("abort", l, { once: !0 });
15364
+ }, m = () => p({
15365
+ kind: "unavailable",
15366
+ reason: "cancelled"
15367
+ });
15368
+ if (d.current.push(l), c = u.subscribe((e) => {
15369
+ if (clearTimeout(o), e && !n) {
15370
+ p({
15371
+ kind: "unavailable",
15372
+ reason: "interactive"
15373
+ });
15374
+ return;
15375
+ }
15376
+ e || (o = setTimeout(() => y("Captcha mint timed out", "timeout"), ih));
15377
+ }), a) {
15378
+ c();
15379
+ return;
15380
+ }
15381
+ s = i?.captchaToken.subscribe((e) => {
15382
+ e !== null && l({ kind: "token" });
15383
+ }), e?.aborted ? m() : e?.addEventListener("abort", m, { once: !0 });
15315
15384
  })) : { kind: "token" }, [
15316
15385
  s,
15317
15386
  t,
@@ -15534,270 +15603,317 @@ var Dh = pn("Flow"), Oh = [
15534
15603
  "ended"
15535
15604
  ];
15536
15605
  function kh({ children: e }) {
15537
- let { config: t, retryInit: n, telemetry: r } = sh(), { cameraOnStart: i } = F(vt), { start: a, end: o, session: s, state: c, __beginAttempt: l, isSharedCallBusy: u, pendingLeave: d } = F(Lm), f = t.value.deployment_id ?? "", p = hh(f), m = P(() => {
15606
+ let { config: t, retryInit: n, telemetry: r } = sh(), { cameraOnStart: i } = F(vt), { start: a, create: o, discardCreatedConversation: s, end: c, session: l, createdSession: u, state: d, __beginAttempt: f, isSharedCallBusy: p, pendingLeave: m } = F(Lm), h = t.value.deployment_id ?? "", g = hh(h), _ = M(null), v = P(() => {
15538
15607
  let e = t.value, n = e.limits?.daily_call_limit_per_user;
15539
15608
  return n == null || e.channel !== "widget" && e.channel !== "embed" ? null : n;
15540
- }, [t]), h = F(ah), [g, _] = A("idle"), [v, y] = A(!1), [b, x] = A(null), [S, C] = A(null), [w, T] = A(!1), { mic: E, camera: D, requestMic: ee, requestCamera: O } = xh();
15609
+ }, [t]), y = F(ah), [b, x] = A("idle"), [S, C] = A(!1), [w, T] = A(null), [E, D] = A(null), [ee, O] = A(!1), { mic: te, camera: ne, requestMic: re, requestCamera: ie } = xh();
15541
15610
  j(() => {
15542
- if (!b || ![
15611
+ if (!w || ![
15543
15612
  "blocked",
15544
15613
  "unsupported",
15545
15614
  "not-found",
15546
15615
  "in-use"
15547
- ].includes(b.status)) return;
15548
- let e = b.status === "blocked" ? "NotAllowedError" : b.status === "not-found" ? "NotFoundError" : b.status === "in-use" ? "NotReadableError" : "unsupported";
15616
+ ].includes(w.status)) return;
15617
+ let e = w.status === "blocked" ? "NotAllowedError" : w.status === "not-found" ? "NotFoundError" : w.status === "in-use" ? "NotReadableError" : "unsupported";
15549
15618
  r?.record({
15550
15619
  stage: "permissions",
15551
15620
  outcome: "failed",
15552
15621
  code: e,
15553
- operation: b.kind === "camera" ? "media.camera" : "media.microphone",
15622
+ operation: w.kind === "camera" ? "media.camera" : "media.microphone",
15554
15623
  component: "permissions",
15555
15624
  handled: !0
15556
15625
  });
15557
- }, [b, r]);
15558
- let te = N(() => Rt("idle"), []);
15626
+ }, [w, r]);
15627
+ let ae = N(() => Rt("idle"), []);
15559
15628
  j(() => {
15560
- te.value = g;
15561
- }, [g, te]), fn(() => {
15629
+ ae.value = b;
15630
+ }, [b, ae]);
15631
+ let oe = P(() => u.peek() !== null || _.current !== null, [u]), k = P(() => {
15632
+ let e = d.peek();
15633
+ return e === "connecting" || e === "connected";
15634
+ }, [d]);
15635
+ fn(() => {
15562
15636
  let e = t.value, n = e.limits?.daily_call_limit_per_user;
15563
- n != null && (e.channel === "widget" || e.channel === "embed") && te.value === "idle" && p.value >= n && (C("daily_limit"), T(!1), _("unavailable"));
15637
+ n != null && (e.channel === "widget" || e.channel === "embed") && ae.value === "idle" && g.value >= n && !oe() && !k() && (D("daily_limit"), O(!1), x("unavailable"));
15564
15638
  });
15565
- let ne = M(!1), re = M(!1), ie = M(async () => {}), ae = M(!1), oe = M({}), k = M(null), se = M(null), ce = M(null), le = P(() => {
15566
- let e = se.current;
15567
- se.current = null, e?.resolve();
15568
- }, []), ue = P(async (e = new AbortController()) => {
15569
- ce.current = e;
15570
- let { signal: r } = e, o = oe.current;
15571
- y(!0);
15639
+ let se = M(!1), ce = M(!1), le = P((e) => !ce.current && (Up(e) && !t.peek().captcha || Wp(e) && !t.peek().start_security), [t]), ue = M(async () => {}), de = M(!1), fe = M({}), pe = M(null), me = M(null), he = P(() => {
15640
+ let e = me.current;
15641
+ me.current = null, e?.resolve();
15642
+ }, []), ge = M(null), _e = P(async (e = new AbortController()) => {
15643
+ ge.current = e;
15644
+ let { signal: r } = e, o = fe.current;
15645
+ C(!0);
15572
15646
  let s = [];
15573
15647
  try {
15574
15648
  let e = t.peek().customization;
15575
15649
  if (o.haircheck === "provided" && e.conversation.modality !== "chat") {
15576
15650
  let t = o.devices ??= {};
15577
15651
  if (t.microphone ??= {}, t.camera ??= { enabled: e.conversation.modality === "video" && i === "on" }, s.push(...await jp(t)), r.aborted) return;
15578
- let n = d();
15652
+ let n = m();
15579
15653
  if (n && await n, r.aborted) return;
15580
15654
  }
15581
- let n = await h?.ensureToken(r) ?? { kind: "not-required" };
15655
+ let n = oe(), c = n ? { kind: "not-required" } : await y?.ensureToken(r) ?? { kind: "not-required" };
15582
15656
  if (r.aborted) return;
15583
- if (n.kind === "unavailable") {
15584
- C(n.reason === "unsupported" ? "captcha_unsupported" : "error"), T(n.reason === "timeout" || n.reason === "exhausted"), _("unavailable");
15657
+ if (c.kind === "unavailable") {
15658
+ D(c.reason === "unsupported" ? "captcha_unsupported" : "error"), O(c.reason === "timeout" || c.reason === "exhausted"), x("unavailable");
15585
15659
  return;
15586
15660
  }
15587
15661
  if (await a(void 0, {
15588
15662
  signal: r,
15589
15663
  devices: o.devices
15590
15664
  }), r.aborted) return;
15591
- ne.current = !1, re.current = !1, m() != null && gh(f), _("call");
15665
+ se.current = !1, ce.current = !1, !n && v() != null && gh(h), x("call");
15592
15666
  } catch (i) {
15593
15667
  if (r.aborted) return;
15594
- if (i instanceof Ap) throw i.name === "NotAllowedError" ? (x({
15668
+ if (i instanceof Ap) throw i.name === "NotAllowedError" ? (T({
15595
15669
  kind: i.device,
15596
15670
  status: "blocked"
15597
- }), _("idle")) : (C("error"), T(!0), _("unavailable")), i;
15671
+ }), x("idle")) : (D("error"), O(!0), x("unavailable")), i;
15598
15672
  let a = Bp(i);
15599
15673
  if (Ip(i)) {
15600
- le(), x({
15674
+ he(), T({
15601
15675
  kind: "microphone",
15602
15676
  status: "blocked"
15603
- }), _("idle");
15677
+ }), x("idle");
15604
15678
  return;
15605
15679
  }
15606
- if ((Up(i) && !t.peek().captcha || Wp(i) && !t.peek().start_security) && !re.current) return re.current = !0, Dh.info("/start requires protection the loaded config lacks; refreshing config"), await n(), r.aborted ? void 0 : (l(!0), await ie.current(e));
15607
- if (Gp(i) && !ne.current) {
15608
- ne.current = !0, y(!1), _("idle");
15680
+ if (le(i)) return ce.current = !0, Dh.info("/start requires protection the loaded config lacks; refreshing config"), await n(), r.aborted ? void 0 : (f(!0), await ue.current(e));
15681
+ if (Gp(i) && !se.current) {
15682
+ se.current = !0, C(!1), x("idle");
15609
15683
  return;
15610
15684
  }
15611
- if (ne.current = !1, qp(i)) {
15612
- Dh.error(`/start rejected: origin ${window.location.origin} is not on this deployment's allowed-origins list. Add it in the Tavus portal.`), C("error"), T(!1), _("unavailable");
15685
+ if (se.current = !1, qp(i)) {
15686
+ Dh.error(`/start rejected: origin ${window.location.origin} is not on this deployment's allowed-origins list. Add it in the Tavus portal.`), D("error"), O(!1), x("unavailable");
15613
15687
  return;
15614
15688
  }
15615
15689
  if (a.status === 401 && t.value.has_password === !0) {
15616
- _("idle");
15690
+ x("idle");
15617
15691
  return;
15618
15692
  }
15619
15693
  let o = Yp(i, a.kind) ?? "busy";
15620
- C(o), T(a.retryable), _("unavailable");
15694
+ D(o), O(a.retryable), x("unavailable");
15621
15695
  } finally {
15622
- Pp(s), ce.current === e && (ce.current = null), y(!1);
15696
+ Pp(s), ge.current === e && (ge.current = null), C(!1);
15623
15697
  }
15624
15698
  }, [
15625
15699
  a,
15700
+ oe,
15626
15701
  t,
15627
- m,
15628
- f,
15702
+ v,
15629
15703
  h,
15704
+ y,
15630
15705
  n,
15631
15706
  le,
15632
- l,
15707
+ he,
15708
+ f,
15633
15709
  i,
15634
- d
15710
+ m
15635
15711
  ]);
15636
- ie.current = ue;
15637
- let de = P(async () => {
15638
- let e = se.current;
15712
+ ue.current = _e;
15713
+ let ve = P(async () => {
15714
+ let e = v();
15715
+ if (e != null && g.value >= e && !oe()) throw D("daily_limit"), O(!1), x("unavailable"), Error("Daily conversation limit reached for this visitor");
15716
+ let t = _.current;
15717
+ if (t) return t.promise;
15718
+ let r = new AbortController(), i = {
15719
+ controller: r,
15720
+ promise: (async () => {
15721
+ let e = async () => {
15722
+ let t = await y?.ensureToken(r.signal, { waitForHuman: !1 }) ?? { kind: "not-required" };
15723
+ if (t.kind === "unavailable") throw Error(`Bot check unavailable: ${t.reason}`);
15724
+ if (r.signal.aborted) throw Error("Conversation creation cancelled");
15725
+ try {
15726
+ return await o();
15727
+ } catch (t) {
15728
+ if (!le(t)) throw t;
15729
+ return ce.current = !0, Dh.info("/start requires protection the loaded config lacks; refreshing config"), await n(), e();
15730
+ }
15731
+ }, t = await e();
15732
+ return ce.current = !1, v() != null && gh(h), t;
15733
+ })()
15734
+ };
15735
+ return _.current = i, i.promise.finally(() => {
15736
+ _.current === i && (_.current = null);
15737
+ });
15738
+ }, [
15739
+ v,
15740
+ g,
15741
+ oe,
15742
+ y,
15743
+ o,
15744
+ le,
15745
+ n,
15746
+ h
15747
+ ]);
15748
+ j(() => () => _.current?.controller.abort(), []);
15749
+ let ye = P(async () => {
15750
+ let e = me.current;
15639
15751
  if (e) {
15640
- x(null);
15752
+ T(null);
15641
15753
  try {
15642
- await ue(e.controller);
15754
+ await _e(e.controller);
15643
15755
  } finally {
15644
- se.current === e && (se.current = null), e.resolve();
15756
+ me.current === e && (me.current = null), e.resolve();
15645
15757
  }
15646
15758
  }
15647
- }, [ue]), fe = P(() => {
15648
- let e = se.current;
15759
+ }, [_e]), be = P(() => {
15760
+ let e = me.current;
15649
15761
  if (e && !e.proceeding) {
15650
- if (e.proceeding = !0, t.peek().customization.conversation.modality === "video" && i === "on" && !D.isGranted && !D.isBlocked) {
15651
- x({
15762
+ if (e.proceeding = !0, t.peek().customization.conversation.modality === "video" && i === "on" && !ne.isGranted && !ne.isBlocked) {
15763
+ T({
15652
15764
  kind: "camera",
15653
- status: D.status
15654
- }), O().finally(() => {
15655
- de();
15765
+ status: ne.status
15766
+ }), ie().finally(() => {
15767
+ ye();
15656
15768
  });
15657
15769
  return;
15658
15770
  }
15659
- de();
15771
+ ye();
15660
15772
  }
15661
15773
  }, [
15662
15774
  t,
15663
15775
  i,
15664
- D,
15665
- O,
15666
- de
15776
+ ne,
15777
+ ie,
15778
+ ye
15667
15779
  ]);
15668
15780
  j(() => {
15669
- if (se.current && b?.kind === "microphone") {
15670
- if (b.status !== E.status && x({
15781
+ if (me.current && w?.kind === "microphone") {
15782
+ if (w.status !== te.status && T({
15671
15783
  kind: "microphone",
15672
- status: E.status
15673
- }), E.isGranted) {
15674
- fe();
15784
+ status: te.status
15785
+ }), te.isGranted) {
15786
+ be();
15675
15787
  return;
15676
15788
  }
15677
- if (E.isBlocked) {
15678
- let e = se.current;
15679
- se.current = null, y(!1), e.resolve();
15789
+ if (te.isBlocked) {
15790
+ let e = me.current;
15791
+ me.current = null, C(!1), e.resolve();
15680
15792
  }
15681
15793
  }
15682
15794
  }, [
15683
- b,
15684
- E,
15685
- fe
15795
+ w,
15796
+ te,
15797
+ be
15686
15798
  ]);
15687
- let pe = P(() => {
15688
- if (se.current) return se.current.promise;
15799
+ let xe = P(() => {
15800
+ if (me.current) return me.current.promise;
15689
15801
  let e, t = new Promise((t) => {
15690
15802
  e = t;
15691
15803
  });
15692
- return se.current = {
15804
+ return me.current = {
15693
15805
  promise: t,
15694
15806
  resolve: e,
15695
15807
  proceeding: !1,
15696
15808
  controller: new AbortController()
15697
- }, y(!0), E.isGranted ? fe() : E.isBlocked ? (x({
15809
+ }, C(!0), te.isGranted ? be() : te.isBlocked ? (T({
15698
15810
  kind: "microphone",
15699
- status: E.status
15700
- }), se.current = null, y(!1), e()) : (x({
15811
+ status: te.status
15812
+ }), me.current = null, C(!1), e()) : (T({
15701
15813
  kind: "microphone",
15702
- status: E.status
15703
- }), ee()), t;
15814
+ status: te.status
15815
+ }), re()), t;
15704
15816
  }, [
15705
- E,
15706
- ee,
15707
- fe
15708
- ]), me = P(async (e) => {
15709
- if (e !== void 0 && Eh(e), !Oh.includes(g)) return;
15710
- oe.current = e === void 0 ? {} : {
15817
+ te,
15818
+ re,
15819
+ be
15820
+ ]), Se = P(async (e) => {
15821
+ if (e !== void 0 && Eh(e), !Oh.includes(b)) return;
15822
+ fe.current = e === void 0 ? {} : {
15711
15823
  ...e,
15712
15824
  devices: e.devices && {
15713
15825
  microphone: e.devices.microphone && { ...e.devices.microphone },
15714
15826
  camera: e.devices.camera && { ...e.devices.camera }
15715
15827
  }
15716
15828
  };
15717
- let n = t.peek().customization, r = n.show_haircheck, i = n.conversation.modality, a = e?.haircheck === "provided", o = r && i !== "chat" && !a, s = !r && i !== "chat" && !a, c = m();
15718
- if (c != null && p.value >= c) {
15719
- C("daily_limit"), T(!1), _("unavailable");
15829
+ let n = t.peek().customization, r = n.show_haircheck, i = n.conversation.modality, a = e?.haircheck === "provided", o = r && i !== "chat" && !a, s = !r && i !== "chat" && !a, c = v();
15830
+ if (c != null && g.value >= c && !oe()) {
15831
+ D("daily_limit"), O(!1), x("unavailable");
15720
15832
  return;
15721
15833
  }
15722
- if (u()) {
15723
- C("busy"), T(!0), _("unavailable");
15834
+ if (p()) {
15835
+ D("busy"), O(!0), x("unavailable");
15724
15836
  return;
15725
15837
  }
15726
- let f = d();
15727
- if (f && !a && await f, l(), o && !ae.current) {
15728
- _("haircheck");
15838
+ let l = m();
15839
+ if (l && !a && await l, f(), o && !de.current) {
15840
+ x("haircheck");
15729
15841
  return;
15730
15842
  }
15731
- return s ? pe() : ue();
15843
+ return s ? xe() : _e();
15732
15844
  }, [
15733
- g,
15845
+ b,
15734
15846
  t,
15735
- pe,
15736
- ue,
15737
- m,
15847
+ xe,
15848
+ _e,
15849
+ v,
15850
+ g,
15851
+ oe,
15852
+ f,
15738
15853
  p,
15739
- l,
15740
- u,
15741
- d
15742
- ]), he = P((e) => {
15743
- if (k.current) return k.current;
15854
+ m
15855
+ ]), Ce = P((e) => {
15856
+ if (pe.current) return pe.current;
15744
15857
  let t, n, r = new Promise((e, r) => {
15745
15858
  t = e, n = r;
15746
15859
  });
15747
- return k.current = r, me(e).then(() => {
15748
- k.current = null, t();
15860
+ return pe.current = r, Se(e).then(() => {
15861
+ pe.current = null, t();
15749
15862
  }, (e) => {
15750
- k.current = null, n(e);
15863
+ pe.current = null, n(e);
15751
15864
  }), r;
15752
- }, [me]), ge = P(async () => {
15753
- g === "haircheck" && (ae.current = !0, await ue());
15754
- }, [g, ue]), _e = P(() => {
15755
- let e = se.current, t = e?.controller ?? ce.current;
15756
- e && (se.current = null, e.resolve(), x(null)), t?.abort(), t && y(!1), g === "haircheck" && _("idle");
15757
- }, [g]), ve = P(() => {
15758
- g === "call" && _("ended");
15759
- }, [g]);
15865
+ }, [Se]), we = P(async () => {
15866
+ b === "haircheck" && (de.current = !0, await _e());
15867
+ }, [b, _e]), Te = P(() => {
15868
+ let e = me.current, t = e?.controller ?? ge.current;
15869
+ e && (me.current = null, e.resolve(), T(null)), t?.abort(), t && C(!1), b === "haircheck" && x("idle"), _.current?.controller.abort(), s();
15870
+ }, [b, s]), Ee = P(() => {
15871
+ b === "call" && x("ended");
15872
+ }, [b]);
15760
15873
  j(() => {
15761
15874
  let e = () => {
15762
- let e = se.current !== null || ce.current !== null, t = g === "haircheck" || g === "call", n = s.peek() !== null, r = n && c.peek() !== "ended";
15763
- (e || t || n) && (_e(), (g === "call" || r) && _("ended"), o());
15875
+ let e = me.current !== null || ge.current !== null, t = b === "haircheck" || b === "call", n = l.peek() !== null, r = n && d.peek() !== "ended";
15876
+ Te(), (e || t || n) && ((b === "call" || r) && x("ended"), c());
15764
15877
  };
15765
15878
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
15766
15879
  }, [
15767
- g,
15768
- s,
15880
+ b,
15881
+ l,
15882
+ d,
15883
+ Te,
15769
15884
  c,
15770
- _e,
15771
- o
15885
+ s
15772
15886
  ]);
15773
- let ye = P(() => {
15774
- C(null), T(!1), _("idle");
15775
- }, []), be = N(() => ({
15776
- flowSignal: te,
15777
- setFlowState: _,
15778
- isStarting: v,
15779
- permissionRequest: b,
15780
- unavailableCause: S,
15781
- canRetry: w,
15782
- start: he,
15783
- join: ge,
15784
- cancel: _e,
15785
- leave: ve,
15786
- restart: ye
15887
+ let De = P(() => {
15888
+ D(null), O(!1), x("idle");
15889
+ }, []), Oe = N(() => ({
15890
+ flowSignal: ae,
15891
+ setFlowState: x,
15892
+ isStarting: S,
15893
+ permissionRequest: w,
15894
+ unavailableCause: E,
15895
+ canRetry: ee,
15896
+ start: Ce,
15897
+ create: ve,
15898
+ join: we,
15899
+ cancel: Te,
15900
+ leave: Ee,
15901
+ restart: De
15787
15902
  }), [
15788
- te,
15789
- v,
15790
- b,
15903
+ ae,
15791
15904
  S,
15792
15905
  w,
15793
- he,
15794
- ge,
15795
- _e,
15906
+ E,
15907
+ ee,
15908
+ Ce,
15796
15909
  ve,
15797
- ye
15910
+ we,
15911
+ Te,
15912
+ Ee,
15913
+ De
15798
15914
  ]);
15799
15915
  return /* @__PURE__ */ I(tm.Provider, {
15800
- value: be,
15916
+ value: Oe,
15801
15917
  children: e
15802
15918
  });
15803
15919
  }
@@ -15826,10 +15942,21 @@ function Ph({ children: e }) {
15826
15942
  let a = {
15827
15943
  tavus: {
15828
15944
  start: t.start,
15945
+ create: t.create,
15829
15946
  end: t.end,
15830
15947
  sendChat: t.sendChat,
15831
15948
  sendMessage: t.sendMessage
15832
15949
  },
15950
+ createConversation: async () => {
15951
+ try {
15952
+ return { conversationId: (await (r ? r.create() : t.create())).conversationId };
15953
+ } catch (e) {
15954
+ throw jh.error("createConversation failed", e), l("tavus:error", {
15955
+ code: "CONVERSATION_CREATE_FAILED",
15956
+ message: e instanceof Error ? e.message : String(e)
15957
+ }), e;
15958
+ }
15959
+ },
15833
15960
  startConversation: async (e) => {
15834
15961
  try {
15835
15962
  e !== void 0 && Eh(e), r ? await r.start(e) : await t.start(void 0, { devices: e?.devices });
@@ -15847,7 +15974,7 @@ function Ph({ children: e }) {
15847
15974
  r?.leave();
15848
15975
  return;
15849
15976
  }
15850
- r?.cancel(), e !== "haircheck" && t.session.peek() && await t.end();
15977
+ r?.cancel(), await t.discardCreatedConversation(), e !== "haircheck" && t.session.peek() && await t.end();
15851
15978
  } catch (e) {
15852
15979
  jh.error("endConversation failed", e);
15853
15980
  }
@@ -15873,7 +16000,7 @@ function Ph({ children: e }) {
15873
16000
  });
15874
16001
  },
15875
16002
  destroy: () => {
15876
- t.session.peek() && t.end(), e.remove();
16003
+ t.discardCreatedConversation(), t.session.peek() && t.end(), e.remove();
15877
16004
  }
15878
16005
  }, c = i ? {
15879
16006
  ...a,
@@ -15892,25 +16019,29 @@ function Ph({ children: e }) {
15892
16019
  i,
15893
16020
  l
15894
16021
  ]);
15895
- let u = M(!1);
16022
+ let u = M(null);
16023
+ j(() => t.createdSession.subscribe((e) => {
16024
+ e !== null && e.conversationId !== u.current && (u.current = e.conversationId, l("tavus:conversation-created", { conversationId: e.conversationId }));
16025
+ }), [t, l]);
16026
+ let d = M(!1);
15896
16027
  j(() => {
15897
- u.current || o.value && n && (u.current = !0, l("tavus:ready", { deploymentId: n.deploymentId }));
16028
+ d.current || o.value && n && (d.current = !0, l("tavus:ready", { deploymentId: n.deploymentId }));
15898
16029
  }, [
15899
16030
  o.value,
15900
16031
  n,
15901
16032
  l
15902
16033
  ]);
15903
- let d = M(null), f = M(/* @__PURE__ */ new Set());
16034
+ let f = M(null), p = M(/* @__PURE__ */ new Set());
15904
16035
  j(() => t.state.subscribe((e) => {
15905
- if (e !== d.current) switch (d.current = e, e) {
16036
+ if (e !== f.current) switch (f.current = e, e) {
15906
16037
  case "connected": {
15907
16038
  let n = t.session.peek()?.conversationId ?? "";
15908
- f.current.add(n), l("tavus:conversation-started", { conversationId: n }), l("tavus:state-change", { state: e });
16039
+ p.current.add(n), l("tavus:conversation-started", { conversationId: n }), l("tavus:state-change", { state: e });
15909
16040
  break;
15910
16041
  }
15911
16042
  case "ended": {
15912
16043
  let n = t.session.peek()?.conversationId ?? "";
15913
- f.current.delete(n), l("tavus:conversation-ended", { conversationId: n }), l("tavus:state-change", { state: e });
16044
+ p.current.delete(n), l("tavus:conversation-ended", { conversationId: n }), l("tavus:state-change", { state: e });
15914
16045
  break;
15915
16046
  }
15916
16047
  case "error":
@@ -15962,12 +16093,12 @@ function Ph({ children: e }) {
15962
16093
  };
15963
16094
  return t.__registerSubscriber(e), () => t.__unregisterSubscriber(e);
15964
16095
  }, [t, l]);
15965
- let p = N(() => ({
16096
+ let m = N(() => ({
15966
16097
  shadowHost: o,
15967
16098
  dispatchEvent: l
15968
16099
  }), [o, l]);
15969
16100
  return /* @__PURE__ */ I(Mh.Provider, {
15970
- value: p,
16101
+ value: m,
15971
16102
  children: [/* @__PURE__ */ I("div", {
15972
16103
  ref: c,
15973
16104
  style: "display:contents"
@@ -30194,6 +30325,7 @@ pn("Widget");
30194
30325
  //#region src/integration.ts
30195
30326
  var aL = [
30196
30327
  "tavus:chat-message",
30328
+ "tavus:conversation-created",
30197
30329
  "tavus:conversation-ended",
30198
30330
  "tavus:conversation-started",
30199
30331
  "tavus:error",
@@ -30219,6 +30351,10 @@ var aL = [
30219
30351
  close() {
30220
30352
  this.getElement().close?.();
30221
30353
  }
30354
+ createConversation() {
30355
+ let e = this.getElement();
30356
+ return e.createConversation ? e.createConversation() : Promise.reject(/* @__PURE__ */ Error(`<${this.tagName}> is not ready yet — wait for tavus:ready`));
30357
+ }
30222
30358
  startConversation(e) {
30223
30359
  this.getElement().startConversation?.(e);
30224
30360
  }