@inkeep/agents-ui 0.0.0-dev-20260528142533 → 0.0.0-dev-20260528163433
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/primitives/components/embedded-chat/use-captcha.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +2 -1
- package/dist/primitives/components/embedded-chat/use-captcha.js +75 -70
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +4 -2
- package/dist/primitives/hooks/use-inkeep-api-client.js +40 -40
- package/dist/primitives/providers/chat-auth-provider.cjs +1 -1
- package/dist/primitives/providers/chat-auth-provider.js +19 -18
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),v="[sentinel]",y="https://cdn.jsdelivr.net/npm/altcha@3.0.9/dist/main/altcha.min.js",P="sha384-SAvZpYmIwEwxkbER1dijvBKm10sobAn/28KXy+Z7/lGbsCshTPhYrFJ2kU7LKiFM",T=1e4,R=3e4;let m=null;function S(){if(typeof customElements>"u"||customElements.get("altcha-widget"))return Promise.resolve();if(m)return m;const d=o=>e=>{m=null,o(e)};return m=new Promise((o,e)=>{const r=d(e);if(document.querySelector(`script[src="${y}"]`)){customElements.whenDefined("altcha-widget").then(()=>o()).catch(r);return}const t=document.createElement("script");t.src=y,t.integrity=P,t.crossOrigin="anonymous",t.type="module",t.async=!0,t.onload=()=>{customElements.whenDefined("altcha-widget").then(()=>o()).catch(()=>r(new Error("altcha-widget custom element never registered")))},t.onerror=()=>{console.error(v,"failed to load widget script"),r(new Error("Failed to load altcha-widget script"))},document.head.appendChild(t)}),m}function b(d){const o=document.createElement("div");o.style.cssText="position:fixed;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;pointer-events:none",document.body.appendChild(o);const e=document.createElement("altcha-widget");e.setAttribute("challenge",d),e.setAttribute("auto","onload"),e.setAttribute("hidefooter","true"),e.setAttribute("hidelogo","true"),o.appendChild(e);let r=[],n,t="mounted",l=!1,h=!1,c=null,s=!1;const f=a=>{const i=r;r=[];for(const E of i)E(a)},g=()=>{l||s||(n=void 0,t="resetting",e.reset?.(),e.verify?.())},w=()=>{c&&clearTimeout(c),c=setTimeout(()=>{c=null,!(!l||s)&&(l=!1,n=void 0,t="resetting",e.reset?.(),e.verify?.())},R)},p=a=>{const i=a.detail;i&&(t=i.state??t,i.state==="verified"&&i.payload&&(h=!0,n=i.payload,f(i.payload)),i.state==="error"&&(n=void 0,f(void 0),h||(l=!0,console.warn(v,"Sentinel unavailable, requests will proceed without bot protection"),w())))};return e.addEventListener("statechange",p),{getPayload:()=>{if(s||l)return Promise.resolve(void 0);if(n){const a=n;return n=void 0,g(),Promise.resolve(a)}return t==="verified"&&g(),new Promise(a=>{r.push(a),setTimeout(()=>{const i=r.indexOf(a);i!==-1&&(r.splice(i,1),a(void 0))},T)})},startNextSolve:g,destroy:()=>{s=!0,e.removeEventListener("statechange",p),c&&(clearTimeout(c),c=null),f(void 0),o.remove()}}}const A=({baseUrl:d,appId:o,shouldBypassCaptcha:e=!1})=>{const r=u.useRef(null),n=u.useRef(null),t=u.useRef(!1),l=u.useCallback(()=>r.current?Promise.resolve():n.current?n.current:o?(n.current=S().then(()=>{if(!t.current&&!r.current){const s=`${d}/run/auth/sentinel/challenge?appId=${encodeURIComponent(o)}`;r.current=b(s)}}).catch(s=>{console.error(v,"failed to mount widget",s),n.current=null}),n.current):Promise.resolve(),[d,o]);u.useEffect(()=>{if(t.current=!1,!e)return l(),()=>{t.current=!0,r.current?.destroy(),r.current=null,n.current=null}},[e,l]);const h=u.useCallback(async()=>{if(e)return{};await l();const s=r.current;if(!s)return{};const f=await s.getPayload();return f?{"x-inkeep-challenge-solution":btoa(JSON.stringify({payload:f}))}:{}},[e,l]),c=u.useCallback(()=>{r.current?.startNextSolve()},[]);return{getCaptchaHeader:h,invalidate:c}};exports.useCaptcha=A;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
interface UseCaptchaOptions {
|
|
2
2
|
baseUrl: string;
|
|
3
|
+
appId: string | undefined;
|
|
3
4
|
shouldBypassCaptcha?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const useCaptcha: ({ baseUrl, shouldBypassCaptcha }: UseCaptchaOptions) => {
|
|
6
|
+
export declare const useCaptcha: ({ baseUrl, appId, shouldBypassCaptcha }: UseCaptchaOptions) => {
|
|
6
7
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
8
|
invalidate: () => void;
|
|
8
9
|
};
|
|
@@ -1,92 +1,97 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as v, useCallback as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
2
|
+
import { useRef as v, useCallback as g, useEffect as T } from "react";
|
|
3
|
+
const p = "[sentinel]", y = "https://cdn.jsdelivr.net/npm/altcha@3.0.9/dist/main/altcha.min.js", A = "sha384-SAvZpYmIwEwxkbER1dijvBKm10sobAn/28KXy+Z7/lGbsCshTPhYrFJ2kU7LKiFM", R = 1e4, S = 3e4;
|
|
4
|
+
let f = null;
|
|
5
|
+
function x() {
|
|
6
6
|
if (typeof customElements > "u" || customElements.get("altcha-widget")) return Promise.resolve();
|
|
7
|
-
if (
|
|
8
|
-
const u = (
|
|
9
|
-
|
|
7
|
+
if (f) return f;
|
|
8
|
+
const u = (o) => (e) => {
|
|
9
|
+
f = null, o(e);
|
|
10
10
|
};
|
|
11
|
-
return
|
|
12
|
-
const
|
|
11
|
+
return f = new Promise((o, e) => {
|
|
12
|
+
const r = u(e);
|
|
13
13
|
if (document.querySelector(
|
|
14
|
-
`script[src="${
|
|
14
|
+
`script[src="${y}"]`
|
|
15
15
|
)) {
|
|
16
|
-
customElements.whenDefined("altcha-widget").then(() =>
|
|
16
|
+
customElements.whenDefined("altcha-widget").then(() => o()).catch(r);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
customElements.whenDefined("altcha-widget").then(() =>
|
|
22
|
-
},
|
|
23
|
-
console.error(
|
|
24
|
-
}, document.head.appendChild(
|
|
25
|
-
}),
|
|
19
|
+
const t = document.createElement("script");
|
|
20
|
+
t.src = y, t.integrity = A, t.crossOrigin = "anonymous", t.type = "module", t.async = !0, t.onload = () => {
|
|
21
|
+
customElements.whenDefined("altcha-widget").then(() => o()).catch(() => r(new Error("altcha-widget custom element never registered")));
|
|
22
|
+
}, t.onerror = () => {
|
|
23
|
+
console.error(p, "failed to load widget script"), r(new Error("Failed to load altcha-widget script"));
|
|
24
|
+
}, document.head.appendChild(t);
|
|
25
|
+
}), f;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
function b(u) {
|
|
28
|
+
const o = document.createElement("div");
|
|
29
|
+
o.style.cssText = "position:fixed;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;pointer-events:none", document.body.appendChild(o);
|
|
30
30
|
const e = document.createElement("altcha-widget");
|
|
31
|
-
e.setAttribute("challenge", u), e.setAttribute("auto", "onload"), e.setAttribute("hidefooter", "true"), e.setAttribute("hidelogo", "true"),
|
|
32
|
-
let
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
e.setAttribute("challenge", u), e.setAttribute("auto", "onload"), e.setAttribute("hidefooter", "true"), e.setAttribute("hidelogo", "true"), o.appendChild(e);
|
|
32
|
+
let r = [], n, t = "mounted", l = !1, m = !1, c = null, s = !1;
|
|
33
|
+
const d = (a) => {
|
|
34
|
+
const i = r;
|
|
35
|
+
r = [];
|
|
36
|
+
for (const P of i) P(a);
|
|
37
|
+
}, h = () => {
|
|
38
|
+
l || s || (n = void 0, t = "resetting", e.reset?.(), e.verify?.());
|
|
39
|
+
}, E = () => {
|
|
40
|
+
c && clearTimeout(c), c = setTimeout(() => {
|
|
41
|
+
c = null, !(!l || s) && (l = !1, n = void 0, t = "resetting", e.reset?.(), e.verify?.());
|
|
42
|
+
}, S);
|
|
43
|
+
}, w = (a) => {
|
|
44
|
+
const i = a.detail;
|
|
45
|
+
i && (t = i.state ?? t, i.state === "verified" && i.payload && (m = !0, n = i.payload, d(i.payload)), i.state === "error" && (n = void 0, d(void 0), m || (l = !0, console.warn(
|
|
46
|
+
p,
|
|
43
47
|
"Sentinel unavailable, requests will proceed without bot protection"
|
|
44
|
-
),
|
|
48
|
+
), E())));
|
|
45
49
|
};
|
|
46
|
-
return e.addEventListener("statechange",
|
|
47
|
-
if (s) return Promise.resolve(void 0);
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
return
|
|
50
|
+
return e.addEventListener("statechange", w), { getPayload: () => {
|
|
51
|
+
if (s || l) return Promise.resolve(void 0);
|
|
52
|
+
if (n) {
|
|
53
|
+
const a = n;
|
|
54
|
+
return n = void 0, h(), Promise.resolve(a);
|
|
51
55
|
}
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return t === "verified" && h(), new Promise((a) => {
|
|
57
|
+
r.push(a), setTimeout(() => {
|
|
58
|
+
const i = r.indexOf(a);
|
|
59
|
+
i !== -1 && (r.splice(i, 1), a(void 0));
|
|
60
|
+
}, R);
|
|
56
61
|
});
|
|
57
|
-
}, startNextSolve:
|
|
58
|
-
e.removeEventListener("statechange",
|
|
62
|
+
}, startNextSolve: h, destroy: () => {
|
|
63
|
+
s = !0, e.removeEventListener("statechange", w), c && (clearTimeout(c), c = null), d(void 0), o.remove();
|
|
59
64
|
} };
|
|
60
65
|
}
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
+
const L = ({ baseUrl: u, appId: o, shouldBypassCaptcha: e = !1 }) => {
|
|
67
|
+
const r = v(null), n = v(null), t = v(!1), l = g(() => r.current ? Promise.resolve() : n.current ? n.current : o ? (n.current = x().then(() => {
|
|
68
|
+
if (!t.current && !r.current) {
|
|
69
|
+
const s = `${u}/run/auth/sentinel/challenge?appId=${encodeURIComponent(o)}`;
|
|
70
|
+
r.current = b(s);
|
|
66
71
|
}
|
|
67
|
-
}).catch((
|
|
68
|
-
console.error(
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
if (!
|
|
72
|
-
return
|
|
73
|
-
|
|
72
|
+
}).catch((s) => {
|
|
73
|
+
console.error(p, "failed to mount widget", s), n.current = null;
|
|
74
|
+
}), n.current) : Promise.resolve(), [u, o]);
|
|
75
|
+
T(() => {
|
|
76
|
+
if (t.current = !1, !e)
|
|
77
|
+
return l(), () => {
|
|
78
|
+
t.current = !0, r.current?.destroy(), r.current = null, n.current = null;
|
|
74
79
|
};
|
|
75
|
-
}, [
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
await
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
81
|
-
const
|
|
82
|
-
return
|
|
83
|
-
"x-inkeep-challenge-solution": btoa(JSON.stringify({ payload:
|
|
80
|
+
}, [e, l]);
|
|
81
|
+
const m = g(async () => {
|
|
82
|
+
if (e) return {};
|
|
83
|
+
await l();
|
|
84
|
+
const s = r.current;
|
|
85
|
+
if (!s) return {};
|
|
86
|
+
const d = await s.getPayload();
|
|
87
|
+
return d ? {
|
|
88
|
+
"x-inkeep-challenge-solution": btoa(JSON.stringify({ payload: d }))
|
|
84
89
|
} : {};
|
|
85
|
-
}, [
|
|
86
|
-
|
|
90
|
+
}, [e, l]), c = g(() => {
|
|
91
|
+
r.current?.startNextSolve();
|
|
87
92
|
}, []);
|
|
88
|
-
return { getCaptchaHeader:
|
|
93
|
+
return { getCaptchaHeader: m, invalidate: c };
|
|
89
94
|
};
|
|
90
95
|
export {
|
|
91
|
-
|
|
96
|
+
L as useCaptcha
|
|
92
97
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function w(r,e){if(r===400&&typeof e=="object"&&e!==null){const t=(e.detail??"").toLowerCase();if(t.includes("challenge")||t.includes("bot protection")||t.includes("proof-of-work"))return"captcha"}if(r===401&&typeof e=="object"&&e!==null){const t=e.detail??"";if(t.includes("Invalid end-user JWT")||t.includes("Bearer token required"))return"session"}return r===403&&typeof e=="object"&&e!==null&&(e.detail??"").toLowerCase().includes("bot protection")?"captcha":null}function E(r){if(!r)return{};if(r instanceof Headers){const e={};return r.forEach((t,c)=>{e[c]=t}),e}return Array.isArray(r)?Object.fromEntries(r):r}function A(r,e,t,c){return{...r?{"x-inkeep-app-id":r}:{},...e?{Authorization:`Bearer ${e}`}:{},...E(c),...t}}function g({appId:r,authToken:e,getCaptchaHeader:t,invalidateCaptcha:c,refreshSession:i}){const o=u.useRef(r);o.current=r;const f=u.useRef(e);f.current=e;const j=u.useRef(t);j.current=t;const l=u.useRef(c);l.current=c;const a=u.useRef(i);return a.current=i,{fetchWithAuth:u.useCallback(async(d,s)=>{const k=A(o.current,f.current,{},s?.headers),n=await fetch(d,{...s,headers:k});if(n.status!==400&&n.status!==401&&n.status!==403)return n;let h;try{h=await n.clone().json()}catch{return n}const p=w(n.status,h);if(p==="captcha")return l.current(),n;if(p==="session"&&a.current){const R=await a.current();if(!R)return n;const C=A(o.current,R,{},s?.headers);return fetch(d,{...s,headers:C})}return n},[])}}exports.parseAuthError=w;exports.useInkeepApiClient=g;
|
|
@@ -15,8 +15,10 @@ interface UseInkeepApiClientOptions {
|
|
|
15
15
|
* Parses an API error response body to determine the failure type.
|
|
16
16
|
*
|
|
17
17
|
* The Run API returns:
|
|
18
|
-
* - 400 + detail containing "challenge" or "bot protection"
|
|
19
|
-
* - 401 + detail matching JWT/bearer messages
|
|
18
|
+
* - 400 + detail containing "challenge" or "bot protection" → captcha format failure
|
|
19
|
+
* - 401 + detail matching JWT/bearer messages → session token failure
|
|
20
|
+
* - 403 + detail containing "bot protection verification failed" → captcha rejected
|
|
21
|
+
* (Sentinel classified as bot OR payload was replayed)
|
|
20
22
|
*
|
|
21
23
|
* Legacy "proof-of-work" wording is still matched so older server versions are handled
|
|
22
24
|
* gracefully during the rolling deploy window.
|
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as s, useCallback as
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
const t = (
|
|
2
|
+
import { useRef as s, useCallback as C } from "react";
|
|
3
|
+
function E(r, e) {
|
|
4
|
+
if (r === 400 && typeof e == "object" && e !== null) {
|
|
5
|
+
const t = (e.detail ?? "").toLowerCase();
|
|
6
6
|
if (t.includes("challenge") || t.includes("bot protection") || t.includes("proof-of-work"))
|
|
7
7
|
return "captcha";
|
|
8
8
|
}
|
|
9
|
-
if (
|
|
10
|
-
const t =
|
|
9
|
+
if (r === 401 && typeof e == "object" && e !== null) {
|
|
10
|
+
const t = e.detail ?? "";
|
|
11
11
|
if (t.includes("Invalid end-user JWT") || t.includes("Bearer token required"))
|
|
12
12
|
return "session";
|
|
13
13
|
}
|
|
14
|
-
return null;
|
|
14
|
+
return r === 403 && typeof e == "object" && e !== null && (e.detail ?? "").toLowerCase().includes("bot protection") ? "captcha" : null;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
if (!
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
}),
|
|
16
|
+
function m(r) {
|
|
17
|
+
if (!r) return {};
|
|
18
|
+
if (r instanceof Headers) {
|
|
19
|
+
const e = {};
|
|
20
|
+
return r.forEach((t, c) => {
|
|
21
|
+
e[c] = t;
|
|
22
|
+
}), e;
|
|
23
23
|
}
|
|
24
|
-
return Array.isArray(
|
|
24
|
+
return Array.isArray(r) ? Object.fromEntries(r) : r;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function A(r, e, t, c) {
|
|
27
27
|
return {
|
|
28
|
-
...
|
|
29
|
-
...
|
|
30
|
-
...
|
|
28
|
+
...r ? { "x-inkeep-app-id": r } : {},
|
|
29
|
+
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
30
|
+
...m(c),
|
|
31
31
|
// captcha last — must not be overridden by caller headers
|
|
32
32
|
...t
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
appId:
|
|
37
|
-
authToken:
|
|
35
|
+
function W({
|
|
36
|
+
appId: r,
|
|
37
|
+
authToken: e,
|
|
38
38
|
getCaptchaHeader: t,
|
|
39
39
|
invalidateCaptcha: c,
|
|
40
|
-
refreshSession:
|
|
40
|
+
refreshSession: i
|
|
41
41
|
}) {
|
|
42
|
-
const o = s(
|
|
43
|
-
o.current =
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
42
|
+
const o = s(r);
|
|
43
|
+
o.current = r;
|
|
44
|
+
const f = s(e);
|
|
45
|
+
f.current = e;
|
|
46
|
+
const R = s(t);
|
|
47
|
+
R.current = t;
|
|
48
48
|
const l = s(c);
|
|
49
49
|
l.current = c;
|
|
50
|
-
const a = s(
|
|
51
|
-
return a.current =
|
|
52
|
-
const
|
|
53
|
-
if (n.status !== 400 && n.status !== 401) return n;
|
|
50
|
+
const a = s(i);
|
|
51
|
+
return a.current = i, { fetchWithAuth: C(async (h, u) => {
|
|
52
|
+
const j = A(o.current, f.current, {}, u?.headers), n = await fetch(h, { ...u, headers: j });
|
|
53
|
+
if (n.status !== 400 && n.status !== 401 && n.status !== 403) return n;
|
|
54
54
|
let d;
|
|
55
55
|
try {
|
|
56
56
|
d = await n.clone().json();
|
|
57
57
|
} catch {
|
|
58
58
|
return n;
|
|
59
59
|
}
|
|
60
|
-
const p =
|
|
60
|
+
const p = E(n.status, d);
|
|
61
61
|
if (p === "captcha")
|
|
62
62
|
return l.current(), n;
|
|
63
63
|
if (p === "session" && a.current) {
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
const
|
|
67
|
-
return fetch(h, { ...u, headers:
|
|
64
|
+
const w = await a.current();
|
|
65
|
+
if (!w) return n;
|
|
66
|
+
const k = A(o.current, w, {}, u?.headers);
|
|
67
|
+
return fetch(h, { ...u, headers: k });
|
|
68
68
|
}
|
|
69
69
|
return n;
|
|
70
70
|
}, []) };
|
|
71
71
|
}
|
|
72
72
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
E as parseAuthError,
|
|
74
|
+
W as useInkeepApiClient
|
|
75
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),d=require("react"),T=require("./config-provider.cjs"),S=require("../hooks/use-auth-token.cjs"),b=require("../components/embedded-chat/use-captcha.cjs"),P=require("../hooks/use-anonymous-session.cjs"),l=d.createContext(void 0),q=({children:e})=>{const{baseSettings:o,aiChatSettings:p}=T.useInkeepConfig(),{shouldBypassCaptcha:C,privacyPreferences:f}=o,{baseUrl:i,appId:u,apiKey:s}=p,{authToken:n,isLoading:a,refreshToken:v}=S.useAuthToken(),g=!!o.getAuthToken,t=!!n,{getCaptchaHeader:r,invalidate:c}=b.useCaptcha({baseUrl:i,appId:u,shouldBypassCaptcha:C||!!s}),{sessionToken:h,refreshSession:A}=P.useAnonymousSession({baseUrl:i,appId:u,getCaptchaHeader:r,invalidateCaptcha:c,optOutAllAnalytics:f?.optOutAllAnalytics,enabled:!t&&!a}),k={authToken:n,isAuthenticated:t,isAuthLoading:a,isAuthConfigured:g,refreshAuthToken:v,sessionToken:h,refreshSession:A,getCaptchaHeader:r,invalidateCaptcha:c,effectiveAuthToken:s??(t?n:h),applicableRefreshSession:s||t?void 0:A};return y.jsx(l.Provider,{value:k,children:e})},x=()=>{const e=d.useContext(l);if(!e)throw new Error("useChatAuth must be used within a ChatAuthProvider");return e};exports.ChatAuthProvider=q;exports.useChatAuth=x;
|
|
@@ -5,33 +5,34 @@ import { useInkeepConfig as y } from "./config-provider.js";
|
|
|
5
5
|
import { useAuthToken as b } from "../hooks/use-auth-token.js";
|
|
6
6
|
import { useCaptcha as x } from "../components/embedded-chat/use-captcha.js";
|
|
7
7
|
import { useAnonymousSession as S } from "../hooks/use-anonymous-session.js";
|
|
8
|
-
const
|
|
9
|
-
const { baseSettings: n, aiChatSettings:
|
|
8
|
+
const f = T(void 0), E = ({ children: t }) => {
|
|
9
|
+
const { baseSettings: n, aiChatSettings: l } = y(), { shouldBypassCaptcha: A, privacyPreferences: d } = n, { baseUrl: i, appId: a, apiKey: o } = l, { authToken: s, isLoading: r, refreshToken: C } = b(), m = !!n.getAuthToken, e = !!s, { getCaptchaHeader: h, invalidate: u } = x({
|
|
10
10
|
baseUrl: i,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
appId: a,
|
|
12
|
+
shouldBypassCaptcha: A || !!o
|
|
13
|
+
}), { sessionToken: c, refreshSession: p } = S({
|
|
13
14
|
baseUrl: i,
|
|
14
|
-
appId:
|
|
15
|
-
getCaptchaHeader:
|
|
16
|
-
invalidateCaptcha:
|
|
17
|
-
optOutAllAnalytics:
|
|
18
|
-
enabled: !e && !
|
|
15
|
+
appId: a,
|
|
16
|
+
getCaptchaHeader: h,
|
|
17
|
+
invalidateCaptcha: u,
|
|
18
|
+
optOutAllAnalytics: d?.optOutAllAnalytics,
|
|
19
|
+
enabled: !e && !r
|
|
19
20
|
}), v = {
|
|
20
21
|
authToken: s,
|
|
21
22
|
isAuthenticated: e,
|
|
22
|
-
isAuthLoading:
|
|
23
|
+
isAuthLoading: r,
|
|
23
24
|
isAuthConfigured: m,
|
|
24
25
|
refreshAuthToken: C,
|
|
25
|
-
sessionToken:
|
|
26
|
-
refreshSession:
|
|
27
|
-
getCaptchaHeader:
|
|
28
|
-
invalidateCaptcha:
|
|
29
|
-
effectiveAuthToken: o ?? (e ? s :
|
|
30
|
-
applicableRefreshSession: o || e ? void 0 :
|
|
26
|
+
sessionToken: c,
|
|
27
|
+
refreshSession: p,
|
|
28
|
+
getCaptchaHeader: h,
|
|
29
|
+
invalidateCaptcha: u,
|
|
30
|
+
effectiveAuthToken: o ?? (e ? s : c),
|
|
31
|
+
applicableRefreshSession: o || e ? void 0 : p
|
|
31
32
|
};
|
|
32
|
-
return /* @__PURE__ */ k(
|
|
33
|
+
return /* @__PURE__ */ k(f.Provider, { value: v, children: t });
|
|
33
34
|
}, H = () => {
|
|
34
|
-
const t = g(
|
|
35
|
+
const t = g(f);
|
|
35
36
|
if (!t)
|
|
36
37
|
throw new Error("useChatAuth must be used within a ChatAuthProvider");
|
|
37
38
|
return t;
|