@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.iife.js +28 -28
- package/dist/index.mjs +438 -302
- package/dist/integration.d.ts +18 -1
- package/package.json +1 -1
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.
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
14835
|
+
w
|
|
14836
14836
|
]);
|
|
14837
|
-
let
|
|
14838
|
-
let e =
|
|
14839
|
-
return e !== null && (
|
|
14840
|
-
}, [
|
|
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 =
|
|
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
|
-
|
|
14845
|
+
ae() && (Pp(D.current), p.value = "ended", mm(), Mm.info("Left meeting"));
|
|
14846
14846
|
}), Vf("error", () => {
|
|
14847
|
-
|
|
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
|
-
}),
|
|
14852
|
+
}), y.value = "Meeting error", p.value = "error");
|
|
14853
14853
|
});
|
|
14854
|
-
let
|
|
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
|
|
14858
|
-
else if (e === "ended" || e === "disconnecting") for (let e of
|
|
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 =
|
|
14861
|
-
for (let t of
|
|
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 =
|
|
14868
|
-
for (let t of
|
|
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" &&
|
|
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
|
-
|
|
14881
|
-
|
|
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,
|
|
14886
|
+
t && Wm(t, O, ee);
|
|
14887
14887
|
}, [
|
|
14888
|
-
h,
|
|
14889
14888
|
g,
|
|
14890
14889
|
_,
|
|
14891
|
-
|
|
14892
|
-
|
|
14890
|
+
v,
|
|
14891
|
+
ee,
|
|
14892
|
+
O
|
|
14893
14893
|
]) }), j(() => () => {
|
|
14894
|
-
|
|
14894
|
+
S.current !== null && (clearTimeout(S.current), S.current = null);
|
|
14895
14895
|
}, []);
|
|
14896
|
-
let
|
|
14897
|
-
|
|
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
|
-
]),
|
|
14906
|
-
let e = m.peek()?.conversationId ?? null, r =
|
|
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(
|
|
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
|
-
|
|
14936
|
+
T.current === u && (T.current = null);
|
|
14935
14937
|
});
|
|
14936
|
-
|
|
14938
|
+
T.current = u;
|
|
14937
14939
|
let d = Promise.all([o, c]).then(() => {
|
|
14938
|
-
|
|
14940
|
+
C.current?.promise === d && (w.peek() === e && (w.value = null), p.value = "ended", a && (C.current = null));
|
|
14939
14941
|
});
|
|
14940
|
-
return
|
|
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
|
-
|
|
14952
|
+
w,
|
|
14951
14953
|
i
|
|
14952
|
-
]),
|
|
14953
|
-
let
|
|
14954
|
-
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
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
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
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,
|
|
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
|
-
|
|
15057
|
+
D.current.push(...a), se.current = !1;
|
|
15004
15058
|
} catch (e) {
|
|
15005
|
-
throw Pp(
|
|
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
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15091
|
+
g,
|
|
15042
15092
|
m,
|
|
15043
|
-
|
|
15093
|
+
ee,
|
|
15044
15094
|
r
|
|
15045
|
-
]),
|
|
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" &&
|
|
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
|
-
|
|
15109
|
+
ee,
|
|
15060
15110
|
r
|
|
15061
|
-
]),
|
|
15062
|
-
|
|
15063
|
-
}, [
|
|
15064
|
-
|
|
15065
|
-
}, [
|
|
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
|
-
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
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:
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
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
|
-
|
|
15103
|
-
|
|
15104
|
-
|
|
15158
|
+
ge,
|
|
15159
|
+
me,
|
|
15160
|
+
pe,
|
|
15105
15161
|
le,
|
|
15106
|
-
|
|
15107
|
-
|
|
15108
|
-
|
|
15109
|
-
|
|
15110
|
-
|
|
15111
|
-
|
|
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:
|
|
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
|
|
15296
|
-
|
|
15297
|
-
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
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
|
-
|
|
15313
|
-
|
|
15314
|
-
})
|
|
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,
|
|
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]),
|
|
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 (!
|
|
15611
|
+
if (!w || ![
|
|
15543
15612
|
"blocked",
|
|
15544
15613
|
"unsupported",
|
|
15545
15614
|
"not-found",
|
|
15546
15615
|
"in-use"
|
|
15547
|
-
].includes(
|
|
15548
|
-
let e =
|
|
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:
|
|
15622
|
+
operation: w.kind === "camera" ? "media.camera" : "media.microphone",
|
|
15554
15623
|
component: "permissions",
|
|
15555
15624
|
handled: !0
|
|
15556
15625
|
});
|
|
15557
|
-
}, [
|
|
15558
|
-
let
|
|
15626
|
+
}, [w, r]);
|
|
15627
|
+
let ae = N(() => Rt("idle"), []);
|
|
15559
15628
|
j(() => {
|
|
15560
|
-
|
|
15561
|
-
}, [
|
|
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") &&
|
|
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
|
|
15566
|
-
let e =
|
|
15567
|
-
|
|
15568
|
-
}, []),
|
|
15569
|
-
|
|
15570
|
-
let { signal: r } = e, o =
|
|
15571
|
-
|
|
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 =
|
|
15652
|
+
let n = m();
|
|
15579
15653
|
if (n && await n, r.aborted) return;
|
|
15580
15654
|
}
|
|
15581
|
-
let n = await
|
|
15655
|
+
let n = oe(), c = n ? { kind: "not-required" } : await y?.ensureToken(r) ?? { kind: "not-required" };
|
|
15582
15656
|
if (r.aborted) return;
|
|
15583
|
-
if (
|
|
15584
|
-
|
|
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
|
-
|
|
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" ? (
|
|
15668
|
+
if (i instanceof Ap) throw i.name === "NotAllowedError" ? (T({
|
|
15595
15669
|
kind: i.device,
|
|
15596
15670
|
status: "blocked"
|
|
15597
|
-
}),
|
|
15671
|
+
}), x("idle")) : (D("error"), O(!0), x("unavailable")), i;
|
|
15598
15672
|
let a = Bp(i);
|
|
15599
15673
|
if (Ip(i)) {
|
|
15600
|
-
|
|
15674
|
+
he(), T({
|
|
15601
15675
|
kind: "microphone",
|
|
15602
15676
|
status: "blocked"
|
|
15603
|
-
}),
|
|
15677
|
+
}), x("idle");
|
|
15604
15678
|
return;
|
|
15605
15679
|
}
|
|
15606
|
-
if ((
|
|
15607
|
-
if (Gp(i) && !
|
|
15608
|
-
|
|
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 (
|
|
15612
|
-
Dh.error(`/start rejected: origin ${window.location.origin} is not on this deployment's allowed-origins list. Add it in the Tavus portal.`),
|
|
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
|
-
|
|
15690
|
+
x("idle");
|
|
15617
15691
|
return;
|
|
15618
15692
|
}
|
|
15619
15693
|
let o = Yp(i, a.kind) ?? "busy";
|
|
15620
|
-
|
|
15694
|
+
D(o), O(a.retryable), x("unavailable");
|
|
15621
15695
|
} finally {
|
|
15622
|
-
Pp(s),
|
|
15696
|
+
Pp(s), ge.current === e && (ge.current = null), C(!1);
|
|
15623
15697
|
}
|
|
15624
15698
|
}, [
|
|
15625
15699
|
a,
|
|
15700
|
+
oe,
|
|
15626
15701
|
t,
|
|
15627
|
-
|
|
15628
|
-
f,
|
|
15702
|
+
v,
|
|
15629
15703
|
h,
|
|
15704
|
+
y,
|
|
15630
15705
|
n,
|
|
15631
15706
|
le,
|
|
15632
|
-
|
|
15707
|
+
he,
|
|
15708
|
+
f,
|
|
15633
15709
|
i,
|
|
15634
|
-
|
|
15710
|
+
m
|
|
15635
15711
|
]);
|
|
15636
|
-
|
|
15637
|
-
let
|
|
15638
|
-
let e =
|
|
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
|
-
|
|
15752
|
+
T(null);
|
|
15641
15753
|
try {
|
|
15642
|
-
await
|
|
15754
|
+
await _e(e.controller);
|
|
15643
15755
|
} finally {
|
|
15644
|
-
|
|
15756
|
+
me.current === e && (me.current = null), e.resolve();
|
|
15645
15757
|
}
|
|
15646
15758
|
}
|
|
15647
|
-
}, [
|
|
15648
|
-
let e =
|
|
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" && !
|
|
15651
|
-
|
|
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:
|
|
15654
|
-
}),
|
|
15655
|
-
|
|
15765
|
+
status: ne.status
|
|
15766
|
+
}), ie().finally(() => {
|
|
15767
|
+
ye();
|
|
15656
15768
|
});
|
|
15657
15769
|
return;
|
|
15658
15770
|
}
|
|
15659
|
-
|
|
15771
|
+
ye();
|
|
15660
15772
|
}
|
|
15661
15773
|
}, [
|
|
15662
15774
|
t,
|
|
15663
15775
|
i,
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15776
|
+
ne,
|
|
15777
|
+
ie,
|
|
15778
|
+
ye
|
|
15667
15779
|
]);
|
|
15668
15780
|
j(() => {
|
|
15669
|
-
if (
|
|
15670
|
-
if (
|
|
15781
|
+
if (me.current && w?.kind === "microphone") {
|
|
15782
|
+
if (w.status !== te.status && T({
|
|
15671
15783
|
kind: "microphone",
|
|
15672
|
-
status:
|
|
15673
|
-
}),
|
|
15674
|
-
|
|
15784
|
+
status: te.status
|
|
15785
|
+
}), te.isGranted) {
|
|
15786
|
+
be();
|
|
15675
15787
|
return;
|
|
15676
15788
|
}
|
|
15677
|
-
if (
|
|
15678
|
-
let e =
|
|
15679
|
-
|
|
15789
|
+
if (te.isBlocked) {
|
|
15790
|
+
let e = me.current;
|
|
15791
|
+
me.current = null, C(!1), e.resolve();
|
|
15680
15792
|
}
|
|
15681
15793
|
}
|
|
15682
15794
|
}, [
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
15795
|
+
w,
|
|
15796
|
+
te,
|
|
15797
|
+
be
|
|
15686
15798
|
]);
|
|
15687
|
-
let
|
|
15688
|
-
if (
|
|
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
|
|
15804
|
+
return me.current = {
|
|
15693
15805
|
promise: t,
|
|
15694
15806
|
resolve: e,
|
|
15695
15807
|
proceeding: !1,
|
|
15696
15808
|
controller: new AbortController()
|
|
15697
|
-
},
|
|
15809
|
+
}, C(!0), te.isGranted ? be() : te.isBlocked ? (T({
|
|
15698
15810
|
kind: "microphone",
|
|
15699
|
-
status:
|
|
15700
|
-
}),
|
|
15811
|
+
status: te.status
|
|
15812
|
+
}), me.current = null, C(!1), e()) : (T({
|
|
15701
15813
|
kind: "microphone",
|
|
15702
|
-
status:
|
|
15703
|
-
}),
|
|
15814
|
+
status: te.status
|
|
15815
|
+
}), re()), t;
|
|
15704
15816
|
}, [
|
|
15705
|
-
|
|
15706
|
-
|
|
15707
|
-
|
|
15708
|
-
]),
|
|
15709
|
-
if (e !== void 0 && Eh(e), !Oh.includes(
|
|
15710
|
-
|
|
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 =
|
|
15718
|
-
if (c != null &&
|
|
15719
|
-
|
|
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 (
|
|
15723
|
-
|
|
15834
|
+
if (p()) {
|
|
15835
|
+
D("busy"), O(!0), x("unavailable");
|
|
15724
15836
|
return;
|
|
15725
15837
|
}
|
|
15726
|
-
let
|
|
15727
|
-
if (
|
|
15728
|
-
|
|
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 ?
|
|
15843
|
+
return s ? xe() : _e();
|
|
15732
15844
|
}, [
|
|
15733
|
-
|
|
15845
|
+
b,
|
|
15734
15846
|
t,
|
|
15735
|
-
|
|
15736
|
-
|
|
15737
|
-
|
|
15847
|
+
xe,
|
|
15848
|
+
_e,
|
|
15849
|
+
v,
|
|
15850
|
+
g,
|
|
15851
|
+
oe,
|
|
15852
|
+
f,
|
|
15738
15853
|
p,
|
|
15739
|
-
|
|
15740
|
-
|
|
15741
|
-
|
|
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
|
|
15748
|
-
|
|
15860
|
+
return pe.current = r, Se(e).then(() => {
|
|
15861
|
+
pe.current = null, t();
|
|
15749
15862
|
}, (e) => {
|
|
15750
|
-
|
|
15863
|
+
pe.current = null, n(e);
|
|
15751
15864
|
}), r;
|
|
15752
|
-
}, [
|
|
15753
|
-
|
|
15754
|
-
}, [
|
|
15755
|
-
let e =
|
|
15756
|
-
e && (
|
|
15757
|
-
}, [
|
|
15758
|
-
|
|
15759
|
-
}, [
|
|
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 =
|
|
15763
|
-
(e || t || n) && (
|
|
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
|
-
|
|
15768
|
-
|
|
15880
|
+
b,
|
|
15881
|
+
l,
|
|
15882
|
+
d,
|
|
15883
|
+
Te,
|
|
15769
15884
|
c,
|
|
15770
|
-
|
|
15771
|
-
o
|
|
15885
|
+
s
|
|
15772
15886
|
]);
|
|
15773
|
-
let
|
|
15774
|
-
|
|
15775
|
-
}, []),
|
|
15776
|
-
flowSignal:
|
|
15777
|
-
setFlowState:
|
|
15778
|
-
isStarting:
|
|
15779
|
-
permissionRequest:
|
|
15780
|
-
unavailableCause:
|
|
15781
|
-
canRetry:
|
|
15782
|
-
start:
|
|
15783
|
-
|
|
15784
|
-
|
|
15785
|
-
|
|
15786
|
-
|
|
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
|
-
|
|
15789
|
-
v,
|
|
15790
|
-
b,
|
|
15903
|
+
ae,
|
|
15791
15904
|
S,
|
|
15792
15905
|
w,
|
|
15793
|
-
|
|
15794
|
-
|
|
15795
|
-
|
|
15906
|
+
E,
|
|
15907
|
+
ee,
|
|
15908
|
+
Ce,
|
|
15796
15909
|
ve,
|
|
15797
|
-
|
|
15910
|
+
we,
|
|
15911
|
+
Te,
|
|
15912
|
+
Ee,
|
|
15913
|
+
De
|
|
15798
15914
|
]);
|
|
15799
15915
|
return /* @__PURE__ */ I(tm.Provider, {
|
|
15800
|
-
value:
|
|
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(
|
|
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
|
-
|
|
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
|
|
16034
|
+
let f = M(null), p = M(/* @__PURE__ */ new Set());
|
|
15904
16035
|
j(() => t.state.subscribe((e) => {
|
|
15905
|
-
if (e !==
|
|
16036
|
+
if (e !== f.current) switch (f.current = e, e) {
|
|
15906
16037
|
case "connected": {
|
|
15907
16038
|
let n = t.session.peek()?.conversationId ?? "";
|
|
15908
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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
|
}
|