@tavus/widget 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
@@ -2962,7 +2962,7 @@ var Cn = class extends Error {
2962
2962
  }
2963
2963
  }, wn = {
2964
2964
  name: "@tavus/widget",
2965
- version: "0.13.0",
2965
+ version: "0.14.0",
2966
2966
  variant: "widget"
2967
2967
  }, Tn = /* @__PURE__ */ new Set([
2968
2968
  "Error",
@@ -14720,14 +14720,14 @@ function Lm(e, t) {
14720
14720
  return t ? e instanceof ln && e.status === 401 : !1;
14721
14721
  }
14722
14722
  function Rm({ children: e }) {
14723
- let { deploymentId: t, client: n, config: r, telemetry: i } = F(_r), a = N(() => ({ current: null }), [n, t]), { memoryStores: o, conversationalContext: s, customGreeting: c } = F(ct), l = Df(), u = wf()?.store.devices, d = Of(), f = F(Gp), p = N(() => Ot("idle"), []), m = N(() => Ot(null), []), h = N(() => Ot([]), []), g = N(() => Ot(""), []), _ = N(() => Ot(null), []), v = N(() => Ot(null), []), y = N(() => Ot(null), []), b = N(() => Ot(null), []), x = M(null), S = M(null), C = N(() => Ot(null), []), w = M(null), T = M([]), E = N(() => xm(), []), D = N(() => /* @__PURE__ */ new Set(), []), ee = N(() => Ot("idle"), []), O = f?.flowSignal ?? ee, te = P((e) => {
14724
- y.value = e;
14725
- }, [y]), ne = P((e) => {
14723
+ let { deploymentId: t, client: n, config: r, telemetry: i } = F(_r), a = N(() => ({ current: null }), [n, t]), { memoryStores: o, conversationalContext: s, customGreeting: c } = F(ct), l = Df(), u = wf()?.store.devices, d = Of(), f = F(Gp), p = N(() => Ot("idle"), []), m = N(() => Ot(null), []), h = N(() => Ot(null), []), g = N(() => Ot([]), []), _ = N(() => Ot(""), []), v = N(() => Ot(null), []), y = N(() => Ot(null), []), b = N(() => Ot(null), []), x = N(() => Ot(null), []), S = M(null), C = M(null), w = N(() => Ot(null), []), T = M(null), E = M(null), D = M([]), ee = N(() => xm(), []), O = N(() => /* @__PURE__ */ new Set(), []), te = N(() => Ot("idle"), []), ne = f?.flowSignal ?? te, re = P((e) => {
14726
14724
  b.value = e;
14727
- }, [b]);
14725
+ }, [b]), ie = P((e) => {
14726
+ x.value = e;
14727
+ }, [x]);
14728
14728
  j(() => {
14729
14729
  if (!l?.on || !i) return;
14730
- let e, t = C.subscribe((t) => {
14730
+ let e, t = w.subscribe((t) => {
14731
14731
  if (e?.(), e = void 0, t === null) return;
14732
14732
  let r = {
14733
14733
  conversation_id: t,
@@ -14779,44 +14779,44 @@ function Rm({ children: e }) {
14779
14779
  l,
14780
14780
  i,
14781
14781
  n,
14782
- C
14782
+ w
14783
14783
  ]);
14784
- let re = P(() => {
14785
- let e = C.peek();
14786
- return e !== null && (C.value = null, m.peek()?.conversationId === e);
14787
- }, [C, m]);
14784
+ let ae = P(() => {
14785
+ let e = w.peek();
14786
+ return e !== null && (w.value = null, m.peek()?.conversationId === e);
14787
+ }, [w, m]);
14788
14788
  jf("joined-meeting", () => {
14789
- let e = C.peek();
14789
+ let e = w.peek();
14790
14790
  e !== null && e === m.peek()?.conversationId && p.peek() === "connecting" && (p.value = "connected", Sm.info("Connected to meeting"));
14791
14791
  }), jf("left-meeting", () => {
14792
- re() && (wp(T.current), p.value = "ended", im(), Sm.info("Left meeting"));
14792
+ ae() && (wp(D.current), p.value = "ended", im(), Sm.info("Left meeting"));
14793
14793
  }), jf("error", () => {
14794
- re() && (wp(T.current), i?.record({
14794
+ ae() && (wp(D.current), i?.record({
14795
14795
  stage: "join",
14796
14796
  outcome: "failed",
14797
14797
  code: "meeting_error",
14798
14798
  conversation_id: m.peek()?.conversationId
14799
- }), v.value = "Meeting error", p.value = "error");
14799
+ }), y.value = "Meeting error", p.value = "error");
14800
14800
  });
14801
- let ie = P(() => C.peek() === null ? d === "joining-meeting" || d === "joined-meeting" : !1, [C, d]), ae = P(() => w.current, []);
14801
+ let oe = P(() => w.peek() === null ? d === "joining-meeting" || d === "joined-meeting" : !1, [w, d]), k = P(() => T.current, []);
14802
14802
  tn(() => {
14803
14803
  let e = p.value;
14804
- if (e === "connected") for (let e of D) e.onConnect?.();
14805
- else if (e === "ended" || e === "disconnecting") for (let e of D) e.onDisconnect?.();
14804
+ if (e === "connected") for (let e of O) e.onConnect?.();
14805
+ else if (e === "ended" || e === "disconnecting") for (let e of O) e.onDisconnect?.();
14806
14806
  else if (e === "error") {
14807
- let e = v.peek() ?? "Unknown error";
14808
- for (let t of D) t.onError?.({
14807
+ let e = y.peek() ?? "Unknown error";
14808
+ for (let t of O) t.onError?.({
14809
14809
  code: "CONVERSATION_ERROR",
14810
14810
  message: e
14811
14811
  });
14812
14812
  }
14813
14813
  }), tn(() => {
14814
- let e = O.value;
14815
- for (let t of D) t.onModeChange?.(e);
14814
+ let e = ne.value;
14815
+ for (let t of O) t.onModeChange?.(e);
14816
14816
  }), Mf({ onAppMessage: P((e) => {
14817
14817
  bm(e?.data, {
14818
14818
  appendChatMessage(e, t) {
14819
- e === "user" && E.consumeMatch(t) || (h.value = [...h.peek(), {
14819
+ e === "user" && ee.consumeMatch(t) || (g.value = [...g.peek(), {
14820
14820
  id: crypto.randomUUID(),
14821
14821
  sender: e,
14822
14822
  text: t,
@@ -14824,35 +14824,37 @@ function Rm({ children: e }) {
14824
14824
  }]);
14825
14825
  },
14826
14826
  setCaption(e, t, n) {
14827
- g.value = e, _.value = n, x.current !== null && (clearTimeout(x.current), x.current = null), t && (x.current = setTimeout(() => {
14828
- g.value = "", _.value = null, x.current = null;
14827
+ _.value = e, v.value = n, S.current !== null && (clearTimeout(S.current), S.current = null), t && (S.current = setTimeout(() => {
14828
+ _.value = "", v.value = null, S.current = null;
14829
14829
  }, Cm));
14830
14830
  }
14831
14831
  });
14832
14832
  let t = vm(e?.data);
14833
- t && Pm(t, D, E);
14833
+ t && Pm(t, O, ee);
14834
14834
  }, [
14835
- h,
14836
14835
  g,
14837
14836
  _,
14838
- E,
14839
- D
14837
+ v,
14838
+ ee,
14839
+ O
14840
14840
  ]) }), j(() => () => {
14841
- x.current !== null && (clearTimeout(x.current), x.current = null);
14841
+ S.current !== null && (clearTimeout(S.current), S.current = null);
14842
14842
  }, []);
14843
- let oe = M(!1), k = P((e = !1) => {
14844
- 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");
14843
+ let se = M(!1), ce = P((e = !1) => {
14844
+ let t = E.current !== null && !E.current.claimed;
14845
+ !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");
14845
14846
  }, [
14846
14847
  m,
14847
- p,
14848
14848
  h,
14849
+ p,
14849
14850
  g,
14850
14851
  _,
14852
+ v,
14851
14853
  i
14852
- ]), se = P(() => {
14853
- let e = m.peek()?.conversationId ?? null, r = S.current;
14854
+ ]), le = P(() => {
14855
+ let e = m.peek()?.conversationId ?? null, r = C.current;
14854
14856
  if (r?.conversationId === e) return r.promise;
14855
- p.value = "disconnecting", wp(T.current);
14857
+ p.value = "disconnecting", wp(D.current);
14856
14858
  let a = !1, o = e ? dr(i, "end", () => mn(n, t, e, { keepalive: !0 }), e).catch((e) => {
14857
14859
  a = !0, Sm.error("End conversation API failed", e);
14858
14860
  }) : Promise.resolve(), s;
@@ -14878,13 +14880,13 @@ function Rm({ children: e }) {
14878
14880
  conversation_id: e ?? void 0
14879
14881
  }), Sm.error("Daily leave failed", t);
14880
14882
  }), u = c.then(() => {
14881
- w.current === u && (w.current = null);
14883
+ T.current === u && (T.current = null);
14882
14884
  });
14883
- w.current = u;
14885
+ T.current = u;
14884
14886
  let d = Promise.all([o, c]).then(() => {
14885
- S.current?.promise === d && (C.peek() === e && (C.value = null), p.value = "ended", a && (S.current = null));
14887
+ C.current?.promise === d && (w.peek() === e && (w.value = null), p.value = "ended", a && (C.current = null));
14886
14888
  });
14887
- return S.current = {
14889
+ return C.current = {
14888
14890
  conversationId: e,
14889
14891
  promise: d
14890
14892
  }, d;
@@ -14894,49 +14896,101 @@ function Rm({ children: e }) {
14894
14896
  l,
14895
14897
  m,
14896
14898
  p,
14897
- C,
14899
+ w,
14898
14900
  i
14899
- ]), ce = P(async (e, d) => {
14900
- let f = null, h = [];
14901
- try {
14902
- oe.current || k(), oe.current = !1, p.value = "connecting", v.value = null;
14903
- let g = e, _ = y.peek();
14904
- _ && g?.password == null && (g = {
14905
- ...g,
14906
- password: _
14907
- });
14908
- let x = r.value.customization.conversation.unique_memory_tag === !0;
14909
- if (!g?.memory_stores) {
14910
- let e = o ?? (x ? [Xp(t)] : []);
14911
- e.length && (g = {
14912
- ...g,
14913
- memory_stores: e
14914
- });
14915
- }
14916
- g = Fm(g, s, c);
14917
- let S = b.peek();
14918
- S && g?.captcha_token == null && (g = {
14919
- ...g,
14920
- captcha_token: S
14921
- });
14922
- let E = await Wp(n, t, r.peek().start_security, g, d, i, a, () => {
14923
- b.value = null;
14901
+ ]), ue = P(async (e, l) => {
14902
+ let u = e, d = b.peek();
14903
+ d && u?.password == null && (u = {
14904
+ ...u,
14905
+ password: d
14906
+ });
14907
+ let f = r.value.customization.conversation.unique_memory_tag === !0;
14908
+ if (!u?.memory_stores) {
14909
+ let e = o ?? (f ? [Xp(t)] : []);
14910
+ e.length && (u = {
14911
+ ...u,
14912
+ memory_stores: e
14924
14913
  });
14925
- if (f = E.conversation_id, m.value = {
14926
- conversationId: E.conversation_id,
14927
- conversationName: E.conversation_name,
14928
- conversationUrl: E.conversation_url,
14929
- callbackUrl: E.callback_url,
14930
- createdAt: E.created_at,
14931
- magicGrid: E.magic_grid === !0
14932
- }, console.info("[Tavus:Conversation] Conversation created:", E.conversation_id), d?.signal?.aborted) throw d.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
14933
- let D = r.value.customization.conversation.modality === "chat", ee = w.current;
14934
- ee && await wm(ee, d?.signal);
14935
- let O = Cp(E.conversation_url, D, d?.devices, h);
14936
- 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 dr(i, "join", () => Tm(l, O, d?.signal), E.conversation_id, {
14914
+ }
14915
+ u = Fm(u, s, c);
14916
+ let p = x.peek();
14917
+ p && u?.captcha_token == null && (u = {
14918
+ ...u,
14919
+ captcha_token: p
14920
+ });
14921
+ let m = await Wp(n, t, r.peek().start_security, u, l, i, a, () => {
14922
+ x.value = null;
14923
+ });
14924
+ return console.info("[Tavus:Conversation] Conversation created:", m.conversation_id), {
14925
+ conversationId: m.conversation_id,
14926
+ conversationName: m.conversation_name,
14927
+ conversationUrl: m.conversation_url,
14928
+ callbackUrl: m.callback_url,
14929
+ createdAt: m.created_at,
14930
+ magicGrid: m.magic_grid === !0
14931
+ };
14932
+ }, [
14933
+ n,
14934
+ a,
14935
+ i,
14936
+ t,
14937
+ b,
14938
+ x,
14939
+ r,
14940
+ o,
14941
+ s,
14942
+ c
14943
+ ]), de = P((e) => dr(i, "end", () => mn(n, t, e.conversationId, { keepalive: !0 }), e.conversationId).catch((e) => {
14944
+ Sm.error("End created conversation API failed", e);
14945
+ }), [
14946
+ n,
14947
+ t,
14948
+ i
14949
+ ]), fe = P(() => {
14950
+ let e = E.current;
14951
+ return !e || e.claimed ? null : (e.claimed = !0, e.promise.catch(() => null));
14952
+ }, []), pe = P(async () => {
14953
+ let e = fe(), t = h.peek();
14954
+ h.value = null;
14955
+ let n = e ? await e : null;
14956
+ await Promise.all([t, n].filter((e) => e !== null).map(de));
14957
+ }, [
14958
+ fe,
14959
+ h,
14960
+ de
14961
+ ]), me = P((e, t) => {
14962
+ let n = E.current;
14963
+ if (n && !n.claimed) return n.promise;
14964
+ let a = pe();
14965
+ i?.beginAttempt?.();
14966
+ let o = { claimed: !1 };
14967
+ return o.promise = a.then(() => ue(e, t)).then((e) => (E.current === o && (E.current = null), o.claimed || (h.value = e), e), (e) => {
14968
+ throw E.current === o && (E.current = null), Lm(e, r.value.has_password === !0) && (b.value = null), Sm.error("Create failed", e), e;
14969
+ }), E.current = o, o.promise;
14970
+ }, [
14971
+ pe,
14972
+ i,
14973
+ ue,
14974
+ h,
14975
+ r,
14976
+ b
14977
+ ]), he = M(pe);
14978
+ he.current = pe, j(() => () => void he.current(), []);
14979
+ let ge = P(async (e, t) => {
14980
+ let n = null, a = [];
14981
+ try {
14982
+ se.current || ce(), se.current = !1, p.value = "connecting", y.value = null;
14983
+ let o = h.peek(), s = o ? null : fe(), c = o ?? (s ? await s : null) ?? await ue(e, t);
14984
+ if (n = c.conversationId, ht(() => {
14985
+ o && (h.value = null), m.value = c;
14986
+ }), t?.signal?.aborted) throw t.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
14987
+ let d = r.value.customization.conversation.modality === "chat", f = T.current;
14988
+ f && await wm(f, t?.signal);
14989
+ let g = Cp(c.conversationUrl, d, t?.devices, a);
14990
+ if (u?.setProvidedTracks(typeof g?.audioSource == "object" ? g.audioSource : void 0, typeof g?.videoSource == "object" ? g.videoSource : void 0), w.value = c.conversationId, await dr(i, "join", () => Tm(l, g, t?.signal), c.conversationId, {
14937
14991
  operation: "daily.join",
14938
14992
  component: "conversation"
14939
- }), Em(l, D, d?.devices) && Im(l)) {
14993
+ }), Em(l, d, t?.devices) && Im(l)) {
14940
14994
  let e = new Tp();
14941
14995
  throw ur(i, e, {
14942
14996
  stage: "permissions",
@@ -14947,37 +15001,33 @@ function Rm({ children: e }) {
14947
15001
  handled: !0
14948
15002
  }), e;
14949
15003
  }
14950
- T.current.push(...h), oe.current = !1;
15004
+ D.current.push(...a), se.current = !1;
14951
15005
  } catch (e) {
14952
- throw wp(h), await se(), f && (m.value = null), Lm(e, r.value.has_password === !0) && (y.value = null), Sm.error("Start failed", e), v.value = String(e), p.value = "error", e;
15006
+ throw wp(a), await le(), n && (m.value = null), Lm(e, r.value.has_password === !0) && (b.value = null), Sm.error("Start failed", e), y.value = String(e), p.value = "error", e;
14953
15007
  }
14954
15008
  }, [
14955
- n,
14956
- a,
14957
15009
  i,
14958
- t,
14959
15010
  l,
14960
15011
  u,
14961
15012
  p,
14962
- v,
14963
- m,
14964
15013
  y,
15014
+ m,
15015
+ h,
15016
+ fe,
14965
15017
  b,
14966
15018
  r,
14967
- o,
14968
- s,
14969
- c,
14970
- k,
14971
- se,
14972
- C
14973
- ]), le = P((e) => {
15019
+ ue,
15020
+ ce,
15021
+ le,
15022
+ w
15023
+ ]), _e = P((e) => {
14974
15024
  if (!l) return;
14975
15025
  let t = m.peek();
14976
15026
  if (!t) {
14977
15027
  Sm.warn("sendChat called before session was established; dropping message");
14978
15028
  return;
14979
15029
  }
14980
- E.markSent(e), l.sendAppMessage(cm(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*"), h.value = [...h.peek(), {
15030
+ ee.markSent(e), l.sendAppMessage(cm(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*"), g.value = [...g.peek(), {
14981
15031
  id: crypto.randomUUID(),
14982
15032
  sender: "user",
14983
15033
  text: e,
@@ -14985,11 +15035,11 @@ function Rm({ children: e }) {
14985
15035
  }];
14986
15036
  }, [
14987
15037
  l,
14988
- h,
15038
+ g,
14989
15039
  m,
14990
- E,
15040
+ ee,
14991
15041
  r
14992
- ]), ue = P((e) => {
15042
+ ]), ve = P((e) => {
14993
15043
  if (!l) {
14994
15044
  Sm.warn("sendMessage called before Daily was ready; dropping message");
14995
15045
  return;
@@ -14999,42 +15049,46 @@ function Rm({ children: e }) {
14999
15049
  Sm.warn("sendMessage called before session was established; dropping message");
15000
15050
  return;
15001
15051
  }
15002
- e.event_type === "conversation.respond" && E.markSent(e.properties.text), l.sendAppMessage(ym(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*");
15052
+ e.event_type === "conversation.respond" && ee.markSent(e.properties.text), l.sendAppMessage(ym(t.conversationId, e, r.peek().customization.conversation.modality === "chat"), "*");
15003
15053
  }, [
15004
15054
  l,
15005
15055
  m,
15006
- E,
15056
+ ee,
15007
15057
  r
15008
- ]), de = P((e) => {
15009
- D.add(e);
15010
- }, [D]), fe = P((e) => {
15011
- D.delete(e);
15012
- }, [D]), pe = N(() => ({
15058
+ ]), ye = P((e) => {
15059
+ O.add(e);
15060
+ }, [O]), be = P((e) => {
15061
+ O.delete(e);
15062
+ }, [O]), xe = N(() => ({
15013
15063
  state: p,
15014
15064
  session: m,
15015
- chatMessages: h,
15016
- captionText: g,
15017
- captionRole: _,
15018
- error: v,
15019
- password: y,
15020
- setPassword: te,
15021
- captchaToken: b,
15022
- setCaptchaToken: ne,
15023
- mode: O,
15024
- start: ce,
15025
- end: se,
15026
- sendChat: le,
15027
- sendMessage: ue,
15065
+ createdSession: h,
15066
+ chatMessages: g,
15067
+ captionText: _,
15068
+ captionRole: v,
15069
+ error: y,
15070
+ password: b,
15071
+ setPassword: re,
15072
+ captchaToken: x,
15073
+ setCaptchaToken: ie,
15074
+ mode: ne,
15075
+ start: ge,
15076
+ create: me,
15077
+ discardCreatedConversation: pe,
15078
+ end: le,
15079
+ sendChat: _e,
15080
+ sendMessage: ve,
15028
15081
  conversation: {
15029
- start: ce,
15030
- end: se,
15031
- sendMessage: ue
15032
- },
15033
- __registerSubscriber: de,
15034
- __unregisterSubscriber: fe,
15035
- __beginAttempt: k,
15036
- isSharedCallBusy: ie,
15037
- pendingLeave: ae
15082
+ start: ge,
15083
+ create: me,
15084
+ end: le,
15085
+ sendMessage: ve
15086
+ },
15087
+ __registerSubscriber: ye,
15088
+ __unregisterSubscriber: be,
15089
+ __beginAttempt: ce,
15090
+ isSharedCallBusy: oe,
15091
+ pendingLeave: k
15038
15092
  }), [
15039
15093
  p,
15040
15094
  m,
@@ -15043,22 +15097,25 @@ function Rm({ children: e }) {
15043
15097
  _,
15044
15098
  v,
15045
15099
  y,
15046
- te,
15047
15100
  b,
15101
+ re,
15102
+ x,
15103
+ ie,
15048
15104
  ne,
15049
- O,
15050
- ce,
15051
- se,
15105
+ ge,
15106
+ me,
15107
+ pe,
15052
15108
  le,
15053
- ue,
15054
- de,
15055
- fe,
15056
- k,
15057
- ie,
15058
- ae
15109
+ _e,
15110
+ ve,
15111
+ ye,
15112
+ be,
15113
+ ce,
15114
+ oe,
15115
+ k
15059
15116
  ]);
15060
15117
  return /* @__PURE__ */ I(Dm.Provider, {
15061
- value: pe,
15118
+ value: xe,
15062
15119
  children: e
15063
15120
  });
15064
15121
  }
@@ -15235,30 +15292,42 @@ function Xm({ children: e }) {
15235
15292
  stage: "captcha",
15236
15293
  outcome: "interactive"
15237
15294
  }), u.value = e;
15238
- }, [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({
15295
+ }, [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({
15239
15296
  stage: "captcha",
15240
15297
  outcome: "started"
15241
15298
  })), s.value = !0, new Promise((t) => {
15242
- let n = !1, a, o, s = u.subscribe((e) => {
15243
- clearTimeout(a), !e && (a = setTimeout(() => y("Captcha mint timed out", "timeout"), Jm));
15244
- }), c = (r) => {
15245
- if (n) return;
15246
- n = !0, clearTimeout(a), s(), e?.removeEventListener("abort", l), o?.();
15247
- let i = d.current.indexOf(c);
15248
- i !== -1 && d.current.splice(i, 1), t(r);
15249
- }, l = () => {
15250
- c({
15251
- kind: "unavailable",
15252
- reason: "cancelled"
15253
- }), d.current.length === 0 && (r?.record({
15299
+ let a = !1, o, s, c, l = (n) => {
15300
+ if (a) return;
15301
+ a = !0, clearTimeout(o), c?.(), e?.removeEventListener("abort", m), s?.();
15302
+ let r = d.current.indexOf(l);
15303
+ r !== -1 && d.current.splice(r, 1), t(n);
15304
+ }, p = (e) => {
15305
+ l(e), d.current.length === 0 && (r?.record({
15254
15306
  stage: "captcha",
15255
15307
  outcome: "cancelled",
15308
+ code: e.reason,
15256
15309
  duration_ms: performance.now() - f.current
15257
15310
  }), v());
15258
- };
15259
- o = i?.captchaToken.subscribe((e) => {
15260
- e !== null && c({ kind: "token" });
15261
- }), d.current.push(c), e?.aborted ? l() : e?.addEventListener("abort", l, { once: !0 });
15311
+ }, m = () => p({
15312
+ kind: "unavailable",
15313
+ reason: "cancelled"
15314
+ });
15315
+ if (d.current.push(l), c = u.subscribe((e) => {
15316
+ if (clearTimeout(o), e && !n) {
15317
+ p({
15318
+ kind: "unavailable",
15319
+ reason: "interactive"
15320
+ });
15321
+ return;
15322
+ }
15323
+ e || (o = setTimeout(() => y("Captcha mint timed out", "timeout"), Jm));
15324
+ }), a) {
15325
+ c();
15326
+ return;
15327
+ }
15328
+ s = i?.captchaToken.subscribe((e) => {
15329
+ e !== null && l({ kind: "token" });
15330
+ }), e?.aborted ? m() : e?.addEventListener("abort", m, { once: !0 });
15262
15331
  })) : { kind: "token" }, [
15263
15332
  s,
15264
15333
  t,
@@ -15481,270 +15550,317 @@ var _h = nn("Flow"), vh = [
15481
15550
  "ended"
15482
15551
  ];
15483
15552
  function yh({ children: e }) {
15484
- let { config: t, retryInit: n, telemetry: r } = Zm(), { cameraOnStart: i } = F(ct), { start: a, end: o, session: s, state: c, __beginAttempt: l, isSharedCallBusy: u, pendingLeave: d } = F(Dm), f = t.value.deployment_id ?? "", p = ah(f), m = P(() => {
15553
+ let { config: t, retryInit: n, telemetry: r } = Zm(), { cameraOnStart: i } = F(ct), { start: a, create: o, discardCreatedConversation: s, end: c, session: l, createdSession: u, state: d, __beginAttempt: f, isSharedCallBusy: p, pendingLeave: m } = F(Dm), h = t.value.deployment_id ?? "", g = ah(h), _ = M(null), v = P(() => {
15485
15554
  let e = t.value, n = e.limits?.daily_call_limit_per_user;
15486
15555
  return n == null || e.channel !== "widget" && e.channel !== "embed" ? null : n;
15487
- }, [t]), h = F(Ym), [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 } = dh();
15556
+ }, [t]), y = F(Ym), [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 } = dh();
15488
15557
  j(() => {
15489
- if (!b || ![
15558
+ if (!w || ![
15490
15559
  "blocked",
15491
15560
  "unsupported",
15492
15561
  "not-found",
15493
15562
  "in-use"
15494
- ].includes(b.status)) return;
15495
- let e = b.status === "blocked" ? "NotAllowedError" : b.status === "not-found" ? "NotFoundError" : b.status === "in-use" ? "NotReadableError" : "unsupported";
15563
+ ].includes(w.status)) return;
15564
+ let e = w.status === "blocked" ? "NotAllowedError" : w.status === "not-found" ? "NotFoundError" : w.status === "in-use" ? "NotReadableError" : "unsupported";
15496
15565
  r?.record({
15497
15566
  stage: "permissions",
15498
15567
  outcome: "failed",
15499
15568
  code: e,
15500
- operation: b.kind === "camera" ? "media.camera" : "media.microphone",
15569
+ operation: w.kind === "camera" ? "media.camera" : "media.microphone",
15501
15570
  component: "permissions",
15502
15571
  handled: !0
15503
15572
  });
15504
- }, [b, r]);
15505
- let te = N(() => Ot("idle"), []);
15573
+ }, [w, r]);
15574
+ let ae = N(() => Ot("idle"), []);
15506
15575
  j(() => {
15507
- te.value = g;
15508
- }, [g, te]), tn(() => {
15576
+ ae.value = b;
15577
+ }, [b, ae]);
15578
+ let oe = P(() => u.peek() !== null || _.current !== null, [u]), k = P(() => {
15579
+ let e = d.peek();
15580
+ return e === "connecting" || e === "connected";
15581
+ }, [d]);
15582
+ tn(() => {
15509
15583
  let e = t.value, n = e.limits?.daily_call_limit_per_user;
15510
- n != null && (e.channel === "widget" || e.channel === "embed") && te.value === "idle" && p.value >= n && (C("daily_limit"), T(!1), _("unavailable"));
15584
+ n != null && (e.channel === "widget" || e.channel === "embed") && ae.value === "idle" && g.value >= n && !oe() && !k() && (D("daily_limit"), O(!1), x("unavailable"));
15511
15585
  });
15512
- 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(() => {
15513
- let e = se.current;
15514
- se.current = null, e?.resolve();
15515
- }, []), ue = P(async (e = new AbortController()) => {
15516
- ce.current = e;
15517
- let { signal: r } = e, o = oe.current;
15518
- y(!0);
15586
+ let se = M(!1), ce = M(!1), le = P((e) => !ce.current && (Np(e) && !t.peek().captcha || Pp(e) && !t.peek().start_security), [t]), ue = M(async () => {}), de = M(!1), fe = M({}), pe = M(null), me = M(null), he = P(() => {
15587
+ let e = me.current;
15588
+ me.current = null, e?.resolve();
15589
+ }, []), ge = M(null), _e = P(async (e = new AbortController()) => {
15590
+ ge.current = e;
15591
+ let { signal: r } = e, o = fe.current;
15592
+ C(!0);
15519
15593
  let s = [];
15520
15594
  try {
15521
15595
  let e = t.peek().customization;
15522
15596
  if (o.haircheck === "provided" && e.conversation.modality !== "chat") {
15523
15597
  let t = o.devices ??= {};
15524
15598
  if (t.microphone ??= {}, t.camera ??= { enabled: e.conversation.modality === "video" && i === "on" }, s.push(...await xp(t)), r.aborted) return;
15525
- let n = d();
15599
+ let n = m();
15526
15600
  if (n && await n, r.aborted) return;
15527
15601
  }
15528
- let n = await h?.ensureToken(r) ?? { kind: "not-required" };
15602
+ let n = oe(), c = n ? { kind: "not-required" } : await y?.ensureToken(r) ?? { kind: "not-required" };
15529
15603
  if (r.aborted) return;
15530
- if (n.kind === "unavailable") {
15531
- C(n.reason === "unsupported" ? "captcha_unsupported" : "error"), T(n.reason === "timeout" || n.reason === "exhausted"), _("unavailable");
15604
+ if (c.kind === "unavailable") {
15605
+ D(c.reason === "unsupported" ? "captcha_unsupported" : "error"), O(c.reason === "timeout" || c.reason === "exhausted"), x("unavailable");
15532
15606
  return;
15533
15607
  }
15534
15608
  if (await a(void 0, {
15535
15609
  signal: r,
15536
15610
  devices: o.devices
15537
15611
  }), r.aborted) return;
15538
- ne.current = !1, re.current = !1, m() != null && oh(f), _("call");
15612
+ se.current = !1, ce.current = !1, !n && v() != null && oh(h), x("call");
15539
15613
  } catch (i) {
15540
15614
  if (r.aborted) return;
15541
- if (i instanceof bp) throw i.name === "NotAllowedError" ? (x({
15615
+ if (i instanceof bp) throw i.name === "NotAllowedError" ? (T({
15542
15616
  kind: i.device,
15543
15617
  status: "blocked"
15544
- }), _("idle")) : (C("error"), T(!0), _("unavailable")), i;
15618
+ }), x("idle")) : (D("error"), O(!0), x("unavailable")), i;
15545
15619
  let a = Ap(i);
15546
15620
  if (Ep(i)) {
15547
- le(), x({
15621
+ he(), T({
15548
15622
  kind: "microphone",
15549
15623
  status: "blocked"
15550
- }), _("idle");
15624
+ }), x("idle");
15551
15625
  return;
15552
15626
  }
15553
- if ((Np(i) && !t.peek().captcha || Pp(i) && !t.peek().start_security) && !re.current) return re.current = !0, _h.info("/start requires protection the loaded config lacks; refreshing config"), await n(), r.aborted ? void 0 : (l(!0), await ie.current(e));
15554
- if (Fp(i) && !ne.current) {
15555
- ne.current = !0, y(!1), _("idle");
15627
+ if (le(i)) return ce.current = !0, _h.info("/start requires protection the loaded config lacks; refreshing config"), await n(), r.aborted ? void 0 : (f(!0), await ue.current(e));
15628
+ if (Fp(i) && !se.current) {
15629
+ se.current = !0, C(!1), x("idle");
15556
15630
  return;
15557
15631
  }
15558
- if (ne.current = !1, Lp(i)) {
15559
- _h.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");
15632
+ if (se.current = !1, Lp(i)) {
15633
+ _h.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");
15560
15634
  return;
15561
15635
  }
15562
15636
  if (a.status === 401 && t.value.has_password === !0) {
15563
- _("idle");
15637
+ x("idle");
15564
15638
  return;
15565
15639
  }
15566
15640
  let o = zp(i, a.kind) ?? "busy";
15567
- C(o), T(a.retryable), _("unavailable");
15641
+ D(o), O(a.retryable), x("unavailable");
15568
15642
  } finally {
15569
- wp(s), ce.current === e && (ce.current = null), y(!1);
15643
+ wp(s), ge.current === e && (ge.current = null), C(!1);
15570
15644
  }
15571
15645
  }, [
15572
15646
  a,
15647
+ oe,
15573
15648
  t,
15574
- m,
15575
- f,
15649
+ v,
15576
15650
  h,
15651
+ y,
15577
15652
  n,
15578
15653
  le,
15579
- l,
15654
+ he,
15655
+ f,
15580
15656
  i,
15581
- d
15657
+ m
15582
15658
  ]);
15583
- ie.current = ue;
15584
- let de = P(async () => {
15585
- let e = se.current;
15659
+ ue.current = _e;
15660
+ let ve = P(async () => {
15661
+ let e = v();
15662
+ if (e != null && g.value >= e && !oe()) throw D("daily_limit"), O(!1), x("unavailable"), Error("Daily conversation limit reached for this visitor");
15663
+ let t = _.current;
15664
+ if (t) return t.promise;
15665
+ let r = new AbortController(), i = {
15666
+ controller: r,
15667
+ promise: (async () => {
15668
+ let e = async () => {
15669
+ let t = await y?.ensureToken(r.signal, { waitForHuman: !1 }) ?? { kind: "not-required" };
15670
+ if (t.kind === "unavailable") throw Error(`Bot check unavailable: ${t.reason}`);
15671
+ if (r.signal.aborted) throw Error("Conversation creation cancelled");
15672
+ try {
15673
+ return await o();
15674
+ } catch (t) {
15675
+ if (!le(t)) throw t;
15676
+ return ce.current = !0, _h.info("/start requires protection the loaded config lacks; refreshing config"), await n(), e();
15677
+ }
15678
+ }, t = await e();
15679
+ return ce.current = !1, v() != null && oh(h), t;
15680
+ })()
15681
+ };
15682
+ return _.current = i, i.promise.finally(() => {
15683
+ _.current === i && (_.current = null);
15684
+ });
15685
+ }, [
15686
+ v,
15687
+ g,
15688
+ oe,
15689
+ y,
15690
+ o,
15691
+ le,
15692
+ n,
15693
+ h
15694
+ ]);
15695
+ j(() => () => _.current?.controller.abort(), []);
15696
+ let ye = P(async () => {
15697
+ let e = me.current;
15586
15698
  if (e) {
15587
- x(null);
15699
+ T(null);
15588
15700
  try {
15589
- await ue(e.controller);
15701
+ await _e(e.controller);
15590
15702
  } finally {
15591
- se.current === e && (se.current = null), e.resolve();
15703
+ me.current === e && (me.current = null), e.resolve();
15592
15704
  }
15593
15705
  }
15594
- }, [ue]), fe = P(() => {
15595
- let e = se.current;
15706
+ }, [_e]), be = P(() => {
15707
+ let e = me.current;
15596
15708
  if (e && !e.proceeding) {
15597
- if (e.proceeding = !0, t.peek().customization.conversation.modality === "video" && i === "on" && !D.isGranted && !D.isBlocked) {
15598
- x({
15709
+ if (e.proceeding = !0, t.peek().customization.conversation.modality === "video" && i === "on" && !ne.isGranted && !ne.isBlocked) {
15710
+ T({
15599
15711
  kind: "camera",
15600
- status: D.status
15601
- }), O().finally(() => {
15602
- de();
15712
+ status: ne.status
15713
+ }), ie().finally(() => {
15714
+ ye();
15603
15715
  });
15604
15716
  return;
15605
15717
  }
15606
- de();
15718
+ ye();
15607
15719
  }
15608
15720
  }, [
15609
15721
  t,
15610
15722
  i,
15611
- D,
15612
- O,
15613
- de
15723
+ ne,
15724
+ ie,
15725
+ ye
15614
15726
  ]);
15615
15727
  j(() => {
15616
- if (se.current && b?.kind === "microphone") {
15617
- if (b.status !== E.status && x({
15728
+ if (me.current && w?.kind === "microphone") {
15729
+ if (w.status !== te.status && T({
15618
15730
  kind: "microphone",
15619
- status: E.status
15620
- }), E.isGranted) {
15621
- fe();
15731
+ status: te.status
15732
+ }), te.isGranted) {
15733
+ be();
15622
15734
  return;
15623
15735
  }
15624
- if (E.isBlocked) {
15625
- let e = se.current;
15626
- se.current = null, y(!1), e.resolve();
15736
+ if (te.isBlocked) {
15737
+ let e = me.current;
15738
+ me.current = null, C(!1), e.resolve();
15627
15739
  }
15628
15740
  }
15629
15741
  }, [
15630
- b,
15631
- E,
15632
- fe
15742
+ w,
15743
+ te,
15744
+ be
15633
15745
  ]);
15634
- let pe = P(() => {
15635
- if (se.current) return se.current.promise;
15746
+ let xe = P(() => {
15747
+ if (me.current) return me.current.promise;
15636
15748
  let e, t = new Promise((t) => {
15637
15749
  e = t;
15638
15750
  });
15639
- return se.current = {
15751
+ return me.current = {
15640
15752
  promise: t,
15641
15753
  resolve: e,
15642
15754
  proceeding: !1,
15643
15755
  controller: new AbortController()
15644
- }, y(!0), E.isGranted ? fe() : E.isBlocked ? (x({
15756
+ }, C(!0), te.isGranted ? be() : te.isBlocked ? (T({
15645
15757
  kind: "microphone",
15646
- status: E.status
15647
- }), se.current = null, y(!1), e()) : (x({
15758
+ status: te.status
15759
+ }), me.current = null, C(!1), e()) : (T({
15648
15760
  kind: "microphone",
15649
- status: E.status
15650
- }), ee()), t;
15761
+ status: te.status
15762
+ }), re()), t;
15651
15763
  }, [
15652
- E,
15653
- ee,
15654
- fe
15655
- ]), me = P(async (e) => {
15656
- if (e !== void 0 && gh(e), !vh.includes(g)) return;
15657
- oe.current = e === void 0 ? {} : {
15764
+ te,
15765
+ re,
15766
+ be
15767
+ ]), Se = P(async (e) => {
15768
+ if (e !== void 0 && gh(e), !vh.includes(b)) return;
15769
+ fe.current = e === void 0 ? {} : {
15658
15770
  ...e,
15659
15771
  devices: e.devices && {
15660
15772
  microphone: e.devices.microphone && { ...e.devices.microphone },
15661
15773
  camera: e.devices.camera && { ...e.devices.camera }
15662
15774
  }
15663
15775
  };
15664
- 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();
15665
- if (c != null && p.value >= c) {
15666
- C("daily_limit"), T(!1), _("unavailable");
15776
+ 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();
15777
+ if (c != null && g.value >= c && !oe()) {
15778
+ D("daily_limit"), O(!1), x("unavailable");
15667
15779
  return;
15668
15780
  }
15669
- if (u()) {
15670
- C("busy"), T(!0), _("unavailable");
15781
+ if (p()) {
15782
+ D("busy"), O(!0), x("unavailable");
15671
15783
  return;
15672
15784
  }
15673
- let f = d();
15674
- if (f && !a && await f, l(), o && !ae.current) {
15675
- _("haircheck");
15785
+ let l = m();
15786
+ if (l && !a && await l, f(), o && !de.current) {
15787
+ x("haircheck");
15676
15788
  return;
15677
15789
  }
15678
- return s ? pe() : ue();
15790
+ return s ? xe() : _e();
15679
15791
  }, [
15680
- g,
15792
+ b,
15681
15793
  t,
15682
- pe,
15683
- ue,
15684
- m,
15794
+ xe,
15795
+ _e,
15796
+ v,
15797
+ g,
15798
+ oe,
15799
+ f,
15685
15800
  p,
15686
- l,
15687
- u,
15688
- d
15689
- ]), he = P((e) => {
15690
- if (k.current) return k.current;
15801
+ m
15802
+ ]), Ce = P((e) => {
15803
+ if (pe.current) return pe.current;
15691
15804
  let t, n, r = new Promise((e, r) => {
15692
15805
  t = e, n = r;
15693
15806
  });
15694
- return k.current = r, me(e).then(() => {
15695
- k.current = null, t();
15807
+ return pe.current = r, Se(e).then(() => {
15808
+ pe.current = null, t();
15696
15809
  }, (e) => {
15697
- k.current = null, n(e);
15810
+ pe.current = null, n(e);
15698
15811
  }), r;
15699
- }, [me]), ge = P(async () => {
15700
- g === "haircheck" && (ae.current = !0, await ue());
15701
- }, [g, ue]), _e = P(() => {
15702
- let e = se.current, t = e?.controller ?? ce.current;
15703
- e && (se.current = null, e.resolve(), x(null)), t?.abort(), t && y(!1), g === "haircheck" && _("idle");
15704
- }, [g]), ve = P(() => {
15705
- g === "call" && _("ended");
15706
- }, [g]);
15812
+ }, [Se]), we = P(async () => {
15813
+ b === "haircheck" && (de.current = !0, await _e());
15814
+ }, [b, _e]), Te = P(() => {
15815
+ let e = me.current, t = e?.controller ?? ge.current;
15816
+ e && (me.current = null, e.resolve(), T(null)), t?.abort(), t && C(!1), b === "haircheck" && x("idle"), _.current?.controller.abort(), s();
15817
+ }, [b, s]), Ee = P(() => {
15818
+ b === "call" && x("ended");
15819
+ }, [b]);
15707
15820
  j(() => {
15708
15821
  let e = () => {
15709
- let e = se.current !== null || ce.current !== null, t = g === "haircheck" || g === "call", n = s.peek() !== null, r = n && c.peek() !== "ended";
15710
- (e || t || n) && (_e(), (g === "call" || r) && _("ended"), o());
15822
+ let e = me.current !== null || ge.current !== null, t = b === "haircheck" || b === "call", n = l.peek() !== null, r = n && d.peek() !== "ended";
15823
+ Te(), (e || t || n) && ((b === "call" || r) && x("ended"), c());
15711
15824
  };
15712
15825
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
15713
15826
  }, [
15714
- g,
15715
- s,
15827
+ b,
15828
+ l,
15829
+ d,
15830
+ Te,
15716
15831
  c,
15717
- _e,
15718
- o
15832
+ s
15719
15833
  ]);
15720
- let ye = P(() => {
15721
- C(null), T(!1), _("idle");
15722
- }, []), be = N(() => ({
15723
- flowSignal: te,
15724
- setFlowState: _,
15725
- isStarting: v,
15726
- permissionRequest: b,
15727
- unavailableCause: S,
15728
- canRetry: w,
15729
- start: he,
15730
- join: ge,
15731
- cancel: _e,
15732
- leave: ve,
15733
- restart: ye
15834
+ let De = P(() => {
15835
+ D(null), O(!1), x("idle");
15836
+ }, []), Oe = N(() => ({
15837
+ flowSignal: ae,
15838
+ setFlowState: x,
15839
+ isStarting: S,
15840
+ permissionRequest: w,
15841
+ unavailableCause: E,
15842
+ canRetry: ee,
15843
+ start: Ce,
15844
+ create: ve,
15845
+ join: we,
15846
+ cancel: Te,
15847
+ leave: Ee,
15848
+ restart: De
15734
15849
  }), [
15735
- te,
15736
- v,
15737
- b,
15850
+ ae,
15738
15851
  S,
15739
15852
  w,
15740
- he,
15741
- ge,
15742
- _e,
15853
+ E,
15854
+ ee,
15855
+ Ce,
15743
15856
  ve,
15744
- ye
15857
+ we,
15858
+ Te,
15859
+ Ee,
15860
+ De
15745
15861
  ]);
15746
15862
  return /* @__PURE__ */ I(Gp.Provider, {
15747
- value: be,
15863
+ value: Oe,
15748
15864
  children: e
15749
15865
  });
15750
15866
  }
@@ -15773,10 +15889,21 @@ function wh({ children: e }) {
15773
15889
  let a = {
15774
15890
  tavus: {
15775
15891
  start: t.start,
15892
+ create: t.create,
15776
15893
  end: t.end,
15777
15894
  sendChat: t.sendChat,
15778
15895
  sendMessage: t.sendMessage
15779
15896
  },
15897
+ createConversation: async () => {
15898
+ try {
15899
+ return { conversationId: (await (r ? r.create() : t.create())).conversationId };
15900
+ } catch (e) {
15901
+ throw xh.error("createConversation failed", e), l("tavus:error", {
15902
+ code: "CONVERSATION_CREATE_FAILED",
15903
+ message: e instanceof Error ? e.message : String(e)
15904
+ }), e;
15905
+ }
15906
+ },
15780
15907
  startConversation: async (e) => {
15781
15908
  try {
15782
15909
  e !== void 0 && gh(e), r ? await r.start(e) : await t.start(void 0, { devices: e?.devices });
@@ -15794,7 +15921,7 @@ function wh({ children: e }) {
15794
15921
  r?.leave();
15795
15922
  return;
15796
15923
  }
15797
- r?.cancel(), e !== "haircheck" && t.session.peek() && await t.end();
15924
+ r?.cancel(), await t.discardCreatedConversation(), e !== "haircheck" && t.session.peek() && await t.end();
15798
15925
  } catch (e) {
15799
15926
  xh.error("endConversation failed", e);
15800
15927
  }
@@ -15820,7 +15947,7 @@ function wh({ children: e }) {
15820
15947
  });
15821
15948
  },
15822
15949
  destroy: () => {
15823
- t.session.peek() && t.end(), e.remove();
15950
+ t.discardCreatedConversation(), t.session.peek() && t.end(), e.remove();
15824
15951
  }
15825
15952
  }, c = i ? {
15826
15953
  ...a,
@@ -15839,25 +15966,29 @@ function wh({ children: e }) {
15839
15966
  i,
15840
15967
  l
15841
15968
  ]);
15842
- let u = M(!1);
15969
+ let u = M(null);
15970
+ j(() => t.createdSession.subscribe((e) => {
15971
+ e !== null && e.conversationId !== u.current && (u.current = e.conversationId, l("tavus:conversation-created", { conversationId: e.conversationId }));
15972
+ }), [t, l]);
15973
+ let d = M(!1);
15843
15974
  j(() => {
15844
- u.current || o.value && n && (u.current = !0, l("tavus:ready", { deploymentId: n.deploymentId }));
15975
+ d.current || o.value && n && (d.current = !0, l("tavus:ready", { deploymentId: n.deploymentId }));
15845
15976
  }, [
15846
15977
  o.value,
15847
15978
  n,
15848
15979
  l
15849
15980
  ]);
15850
- let d = M(null), f = M(/* @__PURE__ */ new Set());
15981
+ let f = M(null), p = M(/* @__PURE__ */ new Set());
15851
15982
  j(() => t.state.subscribe((e) => {
15852
- if (e !== d.current) switch (d.current = e, e) {
15983
+ if (e !== f.current) switch (f.current = e, e) {
15853
15984
  case "connected": {
15854
15985
  let n = t.session.peek()?.conversationId ?? "";
15855
- f.current.add(n), l("tavus:conversation-started", { conversationId: n }), l("tavus:state-change", { state: e });
15986
+ p.current.add(n), l("tavus:conversation-started", { conversationId: n }), l("tavus:state-change", { state: e });
15856
15987
  break;
15857
15988
  }
15858
15989
  case "ended": {
15859
15990
  let n = t.session.peek()?.conversationId ?? "";
15860
- f.current.delete(n), l("tavus:conversation-ended", { conversationId: n }), l("tavus:state-change", { state: e });
15991
+ p.current.delete(n), l("tavus:conversation-ended", { conversationId: n }), l("tavus:state-change", { state: e });
15861
15992
  break;
15862
15993
  }
15863
15994
  case "error":
@@ -15909,12 +16040,12 @@ function wh({ children: e }) {
15909
16040
  };
15910
16041
  return t.__registerSubscriber(e), () => t.__unregisterSubscriber(e);
15911
16042
  }, [t, l]);
15912
- let p = N(() => ({
16043
+ let m = N(() => ({
15913
16044
  shadowHost: o,
15914
16045
  dispatchEvent: l
15915
16046
  }), [o, l]);
15916
16047
  return /* @__PURE__ */ I(Sh.Provider, {
15917
- value: p,
16048
+ value: m,
15918
16049
  children: [/* @__PURE__ */ I("div", {
15919
16050
  ref: c,
15920
16051
  style: "display:contents"
@@ -30271,6 +30402,7 @@ function VI() {
30271
30402
  //#region src/integration.ts
30272
30403
  var HI = [
30273
30404
  "tavus:chat-message",
30405
+ "tavus:conversation-created",
30274
30406
  "tavus:conversation-ended",
30275
30407
  "tavus:conversation-started",
30276
30408
  "tavus:error",
@@ -30296,6 +30428,10 @@ var HI = [
30296
30428
  close() {
30297
30429
  this.getElement().close?.();
30298
30430
  }
30431
+ createConversation() {
30432
+ let e = this.getElement();
30433
+ return e.createConversation ? e.createConversation() : Promise.reject(/* @__PURE__ */ Error(`<${this.tagName}> is not ready yet — wait for tavus:ready`));
30434
+ }
30299
30435
  startConversation(e) {
30300
30436
  this.getElement().startConversation?.(e);
30301
30437
  }