@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.iife.js +12 -12
- package/dist/index.mjs +438 -302
- package/dist/integration.d.ts +18 -1
- package/package.json +1 -1
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.
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
14782
|
+
w
|
|
14783
14783
|
]);
|
|
14784
|
-
let
|
|
14785
|
-
let e =
|
|
14786
|
-
return e !== null && (
|
|
14787
|
-
}, [
|
|
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 =
|
|
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
|
-
|
|
14792
|
+
ae() && (wp(D.current), p.value = "ended", im(), Sm.info("Left meeting"));
|
|
14793
14793
|
}), jf("error", () => {
|
|
14794
|
-
|
|
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
|
-
}),
|
|
14799
|
+
}), y.value = "Meeting error", p.value = "error");
|
|
14800
14800
|
});
|
|
14801
|
-
let
|
|
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
|
|
14805
|
-
else if (e === "ended" || e === "disconnecting") for (let e of
|
|
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 =
|
|
14808
|
-
for (let t of
|
|
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 =
|
|
14815
|
-
for (let t of
|
|
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" &&
|
|
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
|
-
|
|
14828
|
-
|
|
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,
|
|
14833
|
+
t && Pm(t, O, ee);
|
|
14834
14834
|
}, [
|
|
14835
|
-
h,
|
|
14836
14835
|
g,
|
|
14837
14836
|
_,
|
|
14838
|
-
|
|
14839
|
-
|
|
14837
|
+
v,
|
|
14838
|
+
ee,
|
|
14839
|
+
O
|
|
14840
14840
|
]) }), j(() => () => {
|
|
14841
|
-
|
|
14841
|
+
S.current !== null && (clearTimeout(S.current), S.current = null);
|
|
14842
14842
|
}, []);
|
|
14843
|
-
let
|
|
14844
|
-
|
|
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
|
-
]),
|
|
14853
|
-
let e = m.peek()?.conversationId ?? null, r =
|
|
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(
|
|
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
|
-
|
|
14883
|
+
T.current === u && (T.current = null);
|
|
14882
14884
|
});
|
|
14883
|
-
|
|
14885
|
+
T.current = u;
|
|
14884
14886
|
let d = Promise.all([o, c]).then(() => {
|
|
14885
|
-
|
|
14887
|
+
C.current?.promise === d && (w.peek() === e && (w.value = null), p.value = "ended", a && (C.current = null));
|
|
14886
14888
|
});
|
|
14887
|
-
return
|
|
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
|
-
|
|
14899
|
+
w,
|
|
14898
14900
|
i
|
|
14899
|
-
]),
|
|
14900
|
-
let
|
|
14901
|
-
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
|
|
14905
|
-
|
|
14906
|
-
|
|
14907
|
-
|
|
14908
|
-
|
|
14909
|
-
|
|
14910
|
-
|
|
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
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
|
|
14935
|
-
|
|
14936
|
-
|
|
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,
|
|
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
|
-
|
|
15004
|
+
D.current.push(...a), se.current = !1;
|
|
14951
15005
|
} catch (e) {
|
|
14952
|
-
throw wp(
|
|
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
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15038
|
+
g,
|
|
14989
15039
|
m,
|
|
14990
|
-
|
|
15040
|
+
ee,
|
|
14991
15041
|
r
|
|
14992
|
-
]),
|
|
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" &&
|
|
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
|
-
|
|
15056
|
+
ee,
|
|
15007
15057
|
r
|
|
15008
|
-
]),
|
|
15009
|
-
|
|
15010
|
-
}, [
|
|
15011
|
-
|
|
15012
|
-
}, [
|
|
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
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
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:
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
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
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15105
|
+
ge,
|
|
15106
|
+
me,
|
|
15107
|
+
pe,
|
|
15052
15108
|
le,
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
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:
|
|
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
|
|
15243
|
-
|
|
15244
|
-
|
|
15245
|
-
|
|
15246
|
-
|
|
15247
|
-
|
|
15248
|
-
|
|
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
|
-
|
|
15260
|
-
|
|
15261
|
-
})
|
|
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,
|
|
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]),
|
|
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 (!
|
|
15558
|
+
if (!w || ![
|
|
15490
15559
|
"blocked",
|
|
15491
15560
|
"unsupported",
|
|
15492
15561
|
"not-found",
|
|
15493
15562
|
"in-use"
|
|
15494
|
-
].includes(
|
|
15495
|
-
let e =
|
|
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:
|
|
15569
|
+
operation: w.kind === "camera" ? "media.camera" : "media.microphone",
|
|
15501
15570
|
component: "permissions",
|
|
15502
15571
|
handled: !0
|
|
15503
15572
|
});
|
|
15504
|
-
}, [
|
|
15505
|
-
let
|
|
15573
|
+
}, [w, r]);
|
|
15574
|
+
let ae = N(() => Ot("idle"), []);
|
|
15506
15575
|
j(() => {
|
|
15507
|
-
|
|
15508
|
-
}, [
|
|
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") &&
|
|
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
|
|
15513
|
-
let e =
|
|
15514
|
-
|
|
15515
|
-
}, []),
|
|
15516
|
-
|
|
15517
|
-
let { signal: r } = e, o =
|
|
15518
|
-
|
|
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 =
|
|
15599
|
+
let n = m();
|
|
15526
15600
|
if (n && await n, r.aborted) return;
|
|
15527
15601
|
}
|
|
15528
|
-
let n = await
|
|
15602
|
+
let n = oe(), c = n ? { kind: "not-required" } : await y?.ensureToken(r) ?? { kind: "not-required" };
|
|
15529
15603
|
if (r.aborted) return;
|
|
15530
|
-
if (
|
|
15531
|
-
|
|
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
|
-
|
|
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" ? (
|
|
15615
|
+
if (i instanceof bp) throw i.name === "NotAllowedError" ? (T({
|
|
15542
15616
|
kind: i.device,
|
|
15543
15617
|
status: "blocked"
|
|
15544
|
-
}),
|
|
15618
|
+
}), x("idle")) : (D("error"), O(!0), x("unavailable")), i;
|
|
15545
15619
|
let a = Ap(i);
|
|
15546
15620
|
if (Ep(i)) {
|
|
15547
|
-
|
|
15621
|
+
he(), T({
|
|
15548
15622
|
kind: "microphone",
|
|
15549
15623
|
status: "blocked"
|
|
15550
|
-
}),
|
|
15624
|
+
}), x("idle");
|
|
15551
15625
|
return;
|
|
15552
15626
|
}
|
|
15553
|
-
if ((
|
|
15554
|
-
if (Fp(i) && !
|
|
15555
|
-
|
|
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 (
|
|
15559
|
-
_h.error(`/start rejected: origin ${window.location.origin} is not on this deployment's allowed-origins list. Add it in the Tavus portal.`),
|
|
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
|
-
|
|
15637
|
+
x("idle");
|
|
15564
15638
|
return;
|
|
15565
15639
|
}
|
|
15566
15640
|
let o = zp(i, a.kind) ?? "busy";
|
|
15567
|
-
|
|
15641
|
+
D(o), O(a.retryable), x("unavailable");
|
|
15568
15642
|
} finally {
|
|
15569
|
-
wp(s),
|
|
15643
|
+
wp(s), ge.current === e && (ge.current = null), C(!1);
|
|
15570
15644
|
}
|
|
15571
15645
|
}, [
|
|
15572
15646
|
a,
|
|
15647
|
+
oe,
|
|
15573
15648
|
t,
|
|
15574
|
-
|
|
15575
|
-
f,
|
|
15649
|
+
v,
|
|
15576
15650
|
h,
|
|
15651
|
+
y,
|
|
15577
15652
|
n,
|
|
15578
15653
|
le,
|
|
15579
|
-
|
|
15654
|
+
he,
|
|
15655
|
+
f,
|
|
15580
15656
|
i,
|
|
15581
|
-
|
|
15657
|
+
m
|
|
15582
15658
|
]);
|
|
15583
|
-
|
|
15584
|
-
let
|
|
15585
|
-
let e =
|
|
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
|
-
|
|
15699
|
+
T(null);
|
|
15588
15700
|
try {
|
|
15589
|
-
await
|
|
15701
|
+
await _e(e.controller);
|
|
15590
15702
|
} finally {
|
|
15591
|
-
|
|
15703
|
+
me.current === e && (me.current = null), e.resolve();
|
|
15592
15704
|
}
|
|
15593
15705
|
}
|
|
15594
|
-
}, [
|
|
15595
|
-
let e =
|
|
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" && !
|
|
15598
|
-
|
|
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:
|
|
15601
|
-
}),
|
|
15602
|
-
|
|
15712
|
+
status: ne.status
|
|
15713
|
+
}), ie().finally(() => {
|
|
15714
|
+
ye();
|
|
15603
15715
|
});
|
|
15604
15716
|
return;
|
|
15605
15717
|
}
|
|
15606
|
-
|
|
15718
|
+
ye();
|
|
15607
15719
|
}
|
|
15608
15720
|
}, [
|
|
15609
15721
|
t,
|
|
15610
15722
|
i,
|
|
15611
|
-
|
|
15612
|
-
|
|
15613
|
-
|
|
15723
|
+
ne,
|
|
15724
|
+
ie,
|
|
15725
|
+
ye
|
|
15614
15726
|
]);
|
|
15615
15727
|
j(() => {
|
|
15616
|
-
if (
|
|
15617
|
-
if (
|
|
15728
|
+
if (me.current && w?.kind === "microphone") {
|
|
15729
|
+
if (w.status !== te.status && T({
|
|
15618
15730
|
kind: "microphone",
|
|
15619
|
-
status:
|
|
15620
|
-
}),
|
|
15621
|
-
|
|
15731
|
+
status: te.status
|
|
15732
|
+
}), te.isGranted) {
|
|
15733
|
+
be();
|
|
15622
15734
|
return;
|
|
15623
15735
|
}
|
|
15624
|
-
if (
|
|
15625
|
-
let e =
|
|
15626
|
-
|
|
15736
|
+
if (te.isBlocked) {
|
|
15737
|
+
let e = me.current;
|
|
15738
|
+
me.current = null, C(!1), e.resolve();
|
|
15627
15739
|
}
|
|
15628
15740
|
}
|
|
15629
15741
|
}, [
|
|
15630
|
-
|
|
15631
|
-
|
|
15632
|
-
|
|
15742
|
+
w,
|
|
15743
|
+
te,
|
|
15744
|
+
be
|
|
15633
15745
|
]);
|
|
15634
|
-
let
|
|
15635
|
-
if (
|
|
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
|
|
15751
|
+
return me.current = {
|
|
15640
15752
|
promise: t,
|
|
15641
15753
|
resolve: e,
|
|
15642
15754
|
proceeding: !1,
|
|
15643
15755
|
controller: new AbortController()
|
|
15644
|
-
},
|
|
15756
|
+
}, C(!0), te.isGranted ? be() : te.isBlocked ? (T({
|
|
15645
15757
|
kind: "microphone",
|
|
15646
|
-
status:
|
|
15647
|
-
}),
|
|
15758
|
+
status: te.status
|
|
15759
|
+
}), me.current = null, C(!1), e()) : (T({
|
|
15648
15760
|
kind: "microphone",
|
|
15649
|
-
status:
|
|
15650
|
-
}),
|
|
15761
|
+
status: te.status
|
|
15762
|
+
}), re()), t;
|
|
15651
15763
|
}, [
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
]),
|
|
15656
|
-
if (e !== void 0 && gh(e), !vh.includes(
|
|
15657
|
-
|
|
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 =
|
|
15665
|
-
if (c != null &&
|
|
15666
|
-
|
|
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 (
|
|
15670
|
-
|
|
15781
|
+
if (p()) {
|
|
15782
|
+
D("busy"), O(!0), x("unavailable");
|
|
15671
15783
|
return;
|
|
15672
15784
|
}
|
|
15673
|
-
let
|
|
15674
|
-
if (
|
|
15675
|
-
|
|
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 ?
|
|
15790
|
+
return s ? xe() : _e();
|
|
15679
15791
|
}, [
|
|
15680
|
-
|
|
15792
|
+
b,
|
|
15681
15793
|
t,
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15794
|
+
xe,
|
|
15795
|
+
_e,
|
|
15796
|
+
v,
|
|
15797
|
+
g,
|
|
15798
|
+
oe,
|
|
15799
|
+
f,
|
|
15685
15800
|
p,
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
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
|
|
15695
|
-
|
|
15807
|
+
return pe.current = r, Se(e).then(() => {
|
|
15808
|
+
pe.current = null, t();
|
|
15696
15809
|
}, (e) => {
|
|
15697
|
-
|
|
15810
|
+
pe.current = null, n(e);
|
|
15698
15811
|
}), r;
|
|
15699
|
-
}, [
|
|
15700
|
-
|
|
15701
|
-
}, [
|
|
15702
|
-
let e =
|
|
15703
|
-
e && (
|
|
15704
|
-
}, [
|
|
15705
|
-
|
|
15706
|
-
}, [
|
|
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 =
|
|
15710
|
-
(e || t || n) && (
|
|
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
|
-
|
|
15715
|
-
|
|
15827
|
+
b,
|
|
15828
|
+
l,
|
|
15829
|
+
d,
|
|
15830
|
+
Te,
|
|
15716
15831
|
c,
|
|
15717
|
-
|
|
15718
|
-
o
|
|
15832
|
+
s
|
|
15719
15833
|
]);
|
|
15720
|
-
let
|
|
15721
|
-
|
|
15722
|
-
}, []),
|
|
15723
|
-
flowSignal:
|
|
15724
|
-
setFlowState:
|
|
15725
|
-
isStarting:
|
|
15726
|
-
permissionRequest:
|
|
15727
|
-
unavailableCause:
|
|
15728
|
-
canRetry:
|
|
15729
|
-
start:
|
|
15730
|
-
|
|
15731
|
-
|
|
15732
|
-
|
|
15733
|
-
|
|
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
|
-
|
|
15736
|
-
v,
|
|
15737
|
-
b,
|
|
15850
|
+
ae,
|
|
15738
15851
|
S,
|
|
15739
15852
|
w,
|
|
15740
|
-
|
|
15741
|
-
|
|
15742
|
-
|
|
15853
|
+
E,
|
|
15854
|
+
ee,
|
|
15855
|
+
Ce,
|
|
15743
15856
|
ve,
|
|
15744
|
-
|
|
15857
|
+
we,
|
|
15858
|
+
Te,
|
|
15859
|
+
Ee,
|
|
15860
|
+
De
|
|
15745
15861
|
]);
|
|
15746
15862
|
return /* @__PURE__ */ I(Gp.Provider, {
|
|
15747
|
-
value:
|
|
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(
|
|
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
|
-
|
|
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
|
|
15981
|
+
let f = M(null), p = M(/* @__PURE__ */ new Set());
|
|
15851
15982
|
j(() => t.state.subscribe((e) => {
|
|
15852
|
-
if (e !==
|
|
15983
|
+
if (e !== f.current) switch (f.current = e, e) {
|
|
15853
15984
|
case "connected": {
|
|
15854
15985
|
let n = t.session.peek()?.conversationId ?? "";
|
|
15855
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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
|
}
|