@inkeep/agents-ui 0.16.4 → 0.17.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/primitives/components/embedded-chat/chat-error-helpers.cjs +2 -2
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +3 -2
- package/dist/primitives/components/embedded-chat/chat-error-helpers.js +3 -3
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +2 -22
- package/dist/primitives/components/embedded-chat/use-captcha.js +85 -60
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +201 -197
- package/dist/primitives/components/embedded-chat.d.ts +1 -1
- package/dist/primitives/hooks/use-anonymous-session.cjs +1 -1
- package/dist/primitives/hooks/use-anonymous-session.js +70 -65
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +8 -3
- package/dist/primitives/hooks/use-inkeep-api-client.js +47 -59
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-auth-provider.cjs +1 -1
- package/dist/primitives/providers/chat-auth-provider.js +29 -32
- package/dist/primitives/providers/chat-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +1 -1
- package/dist/types/events.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,96 +1,101 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as o, useEffect as l, useCallback as
|
|
3
|
-
import { useLocalStorage as
|
|
4
|
-
import { useInkeepApiClient as
|
|
5
|
-
const
|
|
6
|
-
},
|
|
7
|
-
function
|
|
8
|
-
return new Date(n.expiresAt).getTime() -
|
|
2
|
+
import { useRef as o, useEffect as l, useCallback as D } from "react";
|
|
3
|
+
import { useLocalStorage as X } from "./use-local-storage.js";
|
|
4
|
+
import { useInkeepApiClient as z } from "./use-inkeep-api-client.js";
|
|
5
|
+
const j = 30 * 1e3, H = 2147483647, K = () => {
|
|
6
|
+
}, T = async () => ({});
|
|
7
|
+
function F(n) {
|
|
8
|
+
return new Date(n.expiresAt).getTime() - j <= Date.now();
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const G = ({
|
|
11
11
|
baseUrl: n,
|
|
12
|
-
appId:
|
|
13
|
-
getCaptchaHeader:
|
|
14
|
-
invalidateCaptcha:
|
|
15
|
-
optOutAllAnalytics:
|
|
16
|
-
enabled:
|
|
12
|
+
appId: t,
|
|
13
|
+
getCaptchaHeader: k,
|
|
14
|
+
invalidateCaptcha: L,
|
|
15
|
+
optOutAllAnalytics: y,
|
|
16
|
+
enabled: e = !0
|
|
17
17
|
}) => {
|
|
18
|
-
const
|
|
18
|
+
const B = e && t && !y ? `inkeep_session_${t}` : null, [u, h] = X(B), w = o(e);
|
|
19
19
|
l(() => {
|
|
20
|
-
const r =
|
|
21
|
-
if (
|
|
20
|
+
const r = w.current;
|
|
21
|
+
if (w.current = e, r && !e && t && !y) {
|
|
22
22
|
try {
|
|
23
|
-
localStorage.removeItem(`inkeep_session_${
|
|
23
|
+
localStorage.removeItem(`inkeep_session_${t}`);
|
|
24
24
|
} catch {
|
|
25
25
|
}
|
|
26
26
|
h(null);
|
|
27
27
|
}
|
|
28
|
-
}, [
|
|
29
|
-
const { fetchWithAuth:
|
|
30
|
-
appId:
|
|
28
|
+
}, [e, t, y, h]);
|
|
29
|
+
const { fetchWithAuth: x } = z({
|
|
30
|
+
appId: t,
|
|
31
31
|
authToken: void 0,
|
|
32
|
-
getCaptchaHeader:
|
|
33
|
-
invalidateCaptcha:
|
|
34
|
-
}),
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const f = o(
|
|
39
|
-
f.current =
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
32
|
+
getCaptchaHeader: k ?? T,
|
|
33
|
+
invalidateCaptcha: L ?? K
|
|
34
|
+
}), A = o(n);
|
|
35
|
+
A.current = n;
|
|
36
|
+
const R = o(t);
|
|
37
|
+
R.current = t;
|
|
38
|
+
const f = o(u);
|
|
39
|
+
f.current = u;
|
|
40
|
+
const M = o(h);
|
|
41
|
+
M.current = h;
|
|
42
|
+
const _ = o(x);
|
|
43
|
+
_.current = x;
|
|
44
|
+
const g = o(k ?? T);
|
|
45
|
+
g.current = k ?? T;
|
|
46
|
+
const a = o(null), C = o(e);
|
|
47
|
+
C.current = e;
|
|
48
|
+
const s = D(async (r) => {
|
|
49
|
+
if (!C.current || !A.current || !R.current) return null;
|
|
48
50
|
if (!r && a.current)
|
|
49
51
|
return a.current;
|
|
50
|
-
const
|
|
52
|
+
const c = `${A.current}/run/auth/apps/${R.current}/anonymous-session`, m = (async () => {
|
|
51
53
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
54
|
+
const i = { "Content-Type": "application/json" }, p = f.current?.token;
|
|
55
|
+
p && (i.Authorization = `Bearer ${p}`);
|
|
56
|
+
const W = await g.current();
|
|
57
|
+
Object.assign(i, W);
|
|
58
|
+
const E = await _.current(c, {
|
|
55
59
|
method: "POST",
|
|
56
|
-
headers:
|
|
60
|
+
headers: i,
|
|
57
61
|
signal: r
|
|
58
62
|
});
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
if (!E.ok)
|
|
64
|
+
throw new Error(`Failed to fetch anonymous session: ${E.status}`);
|
|
65
|
+
const S = await E.json();
|
|
66
|
+
return M.current({ token: S.token, expiresAt: S.expiresAt }), S.token;
|
|
67
|
+
} catch (i) {
|
|
68
|
+
return i instanceof Error && i.name === "AbortError" || console.error("[anon-session] fetch failed", i), null;
|
|
64
69
|
} finally {
|
|
65
70
|
r || (a.current = null);
|
|
66
71
|
}
|
|
67
72
|
})();
|
|
68
73
|
return r || (a.current = m), m;
|
|
69
|
-
}, []),
|
|
74
|
+
}, []), $ = o(!1);
|
|
70
75
|
l(() => {
|
|
71
|
-
if (!
|
|
72
|
-
const r =
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
return s(
|
|
76
|
-
}, [n,
|
|
77
|
-
if (!
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
const m = setTimeout(() => s(), Math.min(
|
|
76
|
+
if (!e || !n || !t) return;
|
|
77
|
+
const r = !$.current;
|
|
78
|
+
if ($.current = !0, !r && f.current && !F(f.current) || a.current) return;
|
|
79
|
+
const c = new AbortController();
|
|
80
|
+
return s(c.signal), () => c.abort();
|
|
81
|
+
}, [n, t, e, s]), l(() => {
|
|
82
|
+
if (!e || !n || !t || !u?.expiresAt) return;
|
|
83
|
+
const v = new Date(u.expiresAt).getTime() - j - Date.now();
|
|
84
|
+
if (v <= 0) return;
|
|
85
|
+
const m = setTimeout(() => s(), Math.min(v, H));
|
|
81
86
|
return () => clearTimeout(m);
|
|
82
|
-
}, [n,
|
|
83
|
-
if (!
|
|
87
|
+
}, [n, t, e, u?.expiresAt, s]), l(() => {
|
|
88
|
+
if (!e || !n || !t) return;
|
|
84
89
|
const r = () => {
|
|
85
90
|
if (document.visibilityState !== "visible") return;
|
|
86
|
-
const
|
|
87
|
-
(!
|
|
91
|
+
const c = f.current;
|
|
92
|
+
(!c || F(c)) && s();
|
|
88
93
|
};
|
|
89
94
|
return document.addEventListener("visibilitychange", r), () => document.removeEventListener("visibilitychange", r);
|
|
90
|
-
}, [n,
|
|
91
|
-
const
|
|
92
|
-
return { sessionToken:
|
|
95
|
+
}, [n, t, e, s]);
|
|
96
|
+
const P = D(() => s(), [s]);
|
|
97
|
+
return { sessionToken: u?.token ?? null, refreshSession: P };
|
|
93
98
|
};
|
|
94
99
|
export {
|
|
95
|
-
|
|
100
|
+
G as useAnonymousSession
|
|
96
101
|
};
|
|
@@ -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,10 +15,15 @@ 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 "
|
|
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)
|
|
22
|
+
*
|
|
23
|
+
* Legacy "proof-of-work" wording is still matched so older server versions are handled
|
|
24
|
+
* gracefully during the rolling deploy window.
|
|
20
25
|
*/
|
|
21
|
-
export declare function parseAuthError(status: number, body: unknown): '
|
|
26
|
+
export declare function parseAuthError(status: number, body: unknown): 'captcha' | 'session' | null;
|
|
22
27
|
/**
|
|
23
28
|
* Returns a stable `fetchWithAuth` function that automatically:
|
|
24
29
|
* - Injects auth headers (x-inkeep-app-id, Authorization, x-inkeep-challenge-solution)
|
|
@@ -1,87 +1,75 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as
|
|
3
|
-
function E(
|
|
4
|
-
if (
|
|
5
|
-
const t = (
|
|
6
|
-
if (t.includes("challenge") || t.includes("proof-of-work"))
|
|
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
|
+
if (t.includes("challenge") || t.includes("bot protection") || t.includes("proof-of-work"))
|
|
7
|
+
return "captcha";
|
|
7
8
|
}
|
|
8
|
-
if (
|
|
9
|
-
const t =
|
|
9
|
+
if (r === 401 && typeof e == "object" && e !== null) {
|
|
10
|
+
const t = e.detail ?? "";
|
|
10
11
|
if (t.includes("Invalid end-user JWT") || t.includes("Bearer token required"))
|
|
11
12
|
return "session";
|
|
12
13
|
}
|
|
13
|
-
return null;
|
|
14
|
+
return r === 403 && typeof e == "object" && e !== null && (e.detail ?? "").toLowerCase().includes("bot protection") ? "captcha" : null;
|
|
14
15
|
}
|
|
15
|
-
function m(
|
|
16
|
-
if (!
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
}),
|
|
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;
|
|
22
23
|
}
|
|
23
|
-
return Array.isArray(
|
|
24
|
+
return Array.isArray(r) ? Object.fromEntries(r) : r;
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function A(r, e, t, c) {
|
|
26
27
|
return {
|
|
27
|
-
...
|
|
28
|
-
...
|
|
28
|
+
...r ? { "x-inkeep-app-id": r } : {},
|
|
29
|
+
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
29
30
|
...m(c),
|
|
30
31
|
// captcha last — must not be overridden by caller headers
|
|
31
32
|
...t
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
-
appId:
|
|
36
|
-
authToken:
|
|
35
|
+
function W({
|
|
36
|
+
appId: r,
|
|
37
|
+
authToken: e,
|
|
37
38
|
getCaptchaHeader: t,
|
|
38
39
|
invalidateCaptcha: c,
|
|
39
|
-
refreshSession:
|
|
40
|
+
refreshSession: i
|
|
40
41
|
}) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
C,
|
|
55
|
-
s?.headers
|
|
56
|
-
), n = await fetch(d, { ...s, headers: H });
|
|
57
|
-
if (n.status !== 400 && n.status !== 401) return n;
|
|
58
|
-
let R;
|
|
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
|
+
const l = s(c);
|
|
49
|
+
l.current = c;
|
|
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
|
+
let d;
|
|
59
55
|
try {
|
|
60
|
-
|
|
56
|
+
d = await n.clone().json();
|
|
61
57
|
} catch {
|
|
62
58
|
return n;
|
|
63
59
|
}
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
73
|
-
return fetch(d, { ...s, headers: l });
|
|
74
|
-
}
|
|
75
|
-
if (k === "session" && h.current) {
|
|
76
|
-
const f = await h.current();
|
|
77
|
-
if (!f) return n;
|
|
78
|
-
const l = await o.current(), j = p(a.current, f, l, s?.headers);
|
|
79
|
-
return fetch(d, { ...s, headers: j });
|
|
60
|
+
const p = E(n.status, d);
|
|
61
|
+
if (p === "captcha")
|
|
62
|
+
return l.current(), n;
|
|
63
|
+
if (p === "session" && a.current) {
|
|
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 });
|
|
80
68
|
}
|
|
81
69
|
return n;
|
|
82
70
|
}, []) };
|
|
83
71
|
}
|
|
84
72
|
export {
|
|
85
73
|
E as parseAuthError,
|
|
86
|
-
|
|
74
|
+
W as useInkeepApiClient
|
|
87
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.17.0",a=t.useMemo(()=>({widgetLibraryVersion:c,componentType:o,tags:r}),[o,r,c]),v={logEvent:t.useCallback(async u=>{const E={...a,...u.properties,...i},d={eventName:u.eventName,properties:E};return s.onEvent?.(d)},[s,a,i])};return l.jsx(n.Provider,{value:v,children:e})},m=()=>{const e=t.useContext(n);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsContext=n;exports.BaseEventsProvider=g;exports.useBaseEvents=m;
|
|
@@ -3,7 +3,7 @@ import { jsx as u } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext as E, useMemo as d, useCallback as l, useContext as g } from "react";
|
|
4
4
|
import { useInkeepConfig as x } from "./config-provider.js";
|
|
5
5
|
const c = E(void 0), b = ({ children: e }) => {
|
|
6
|
-
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.
|
|
6
|
+
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.17.0", i = d(
|
|
7
7
|
() => ({
|
|
8
8
|
widgetLibraryVersion: r,
|
|
9
9
|
componentType: o,
|
|
@@ -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 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;
|
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useContext as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { useAnonymousSession as L } from "../hooks/use-anonymous-session.js";
|
|
11
|
-
const p = S(void 0), J = ({ children: t }) => {
|
|
12
|
-
const { baseSettings: n, aiChatSettings: l } = x(), { shouldBypassCaptcha: d, privacyPreferences: f } = n, { baseUrl: i, appId: m, apiKey: o } = l, C = w(), A = B(), b = I(), v = C?.isOpen ?? A?.isOpen ?? b?.isOpen ?? !0, { authToken: s, isLoading: a, refreshToken: k } = P(), g = !!n.getAuthToken, e = !!s, { getCaptchaHeader: r, invalidate: u } = R({
|
|
2
|
+
import { jsx as k } from "react/jsx-runtime";
|
|
3
|
+
import { useContext as g, createContext as T } from "react";
|
|
4
|
+
import { useInkeepConfig as y } from "./config-provider.js";
|
|
5
|
+
import { useAuthToken as b } from "../hooks/use-auth-token.js";
|
|
6
|
+
import { useCaptcha as x } from "../components/embedded-chat/use-captcha.js";
|
|
7
|
+
import { useAnonymousSession as S } from "../hooks/use-anonymous-session.js";
|
|
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({
|
|
13
10
|
baseUrl: i,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}), { sessionToken:
|
|
11
|
+
appId: a,
|
|
12
|
+
shouldBypassCaptcha: A || !!o
|
|
13
|
+
}), { sessionToken: c, refreshSession: p } = S({
|
|
17
14
|
baseUrl: i,
|
|
18
|
-
appId:
|
|
19
|
-
getCaptchaHeader:
|
|
15
|
+
appId: a,
|
|
16
|
+
getCaptchaHeader: h,
|
|
20
17
|
invalidateCaptcha: u,
|
|
21
|
-
optOutAllAnalytics:
|
|
22
|
-
enabled: !e && !
|
|
23
|
-
}),
|
|
18
|
+
optOutAllAnalytics: d?.optOutAllAnalytics,
|
|
19
|
+
enabled: !e && !r
|
|
20
|
+
}), v = {
|
|
24
21
|
authToken: s,
|
|
25
22
|
isAuthenticated: e,
|
|
26
|
-
isAuthLoading:
|
|
27
|
-
isAuthConfigured:
|
|
28
|
-
refreshAuthToken:
|
|
29
|
-
sessionToken:
|
|
30
|
-
refreshSession:
|
|
31
|
-
getCaptchaHeader:
|
|
23
|
+
isAuthLoading: r,
|
|
24
|
+
isAuthConfigured: m,
|
|
25
|
+
refreshAuthToken: C,
|
|
26
|
+
sessionToken: c,
|
|
27
|
+
refreshSession: p,
|
|
28
|
+
getCaptchaHeader: h,
|
|
32
29
|
invalidateCaptcha: u,
|
|
33
|
-
effectiveAuthToken: o ?? (e ? s :
|
|
34
|
-
applicableRefreshSession: o || e ? void 0 :
|
|
30
|
+
effectiveAuthToken: o ?? (e ? s : c),
|
|
31
|
+
applicableRefreshSession: o || e ? void 0 : p
|
|
35
32
|
};
|
|
36
|
-
return /* @__PURE__ */
|
|
37
|
-
},
|
|
38
|
-
const t =
|
|
33
|
+
return /* @__PURE__ */ k(f.Provider, { value: v, children: t });
|
|
34
|
+
}, H = () => {
|
|
35
|
+
const t = g(f);
|
|
39
36
|
if (!t)
|
|
40
37
|
throw new Error("useChatAuth must be used within a ChatAuthProvider");
|
|
41
38
|
return t;
|
|
42
39
|
};
|
|
43
40
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
E as ChatAuthProvider,
|
|
42
|
+
H as useChatAuth
|
|
46
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.17.0",a=u.useMemo(()=>({widgetLibraryVersion:c,componentType:i}),[i,c]),{effectiveAuthToken:b,applicableRefreshSession:f,getCaptchaHeader:E,invalidateCaptcha:P}=O.useChatAuth(),{baseUrl:m,appId:A,analyticsApiBaseUrl:C,headers:I}=h,p=y?.optOutAllAnalytics??!1,{logEvent:l}=U.useEventsApi({baseUrl:C??m,appId:A,authToken:b,getCaptchaHeader:E,invalidateCaptcha:P,refreshSession:f,headers:I}),k={logEvent:u.useCallback(async s=>{const q={eventName:s.eventName,properties:{...a,...t?{tags:t}:{},...s.properties,...r}};if(!p){const e=s.properties??{},v=typeof e.conversationId=="string"?e.conversationId:void 0,d=typeof e.messageId=="string"?e.messageId:void 0,S=!!o&&Object.keys(o).length>0,w={...t?{tags:t}:{},...r??{}},T={...a,...s.properties};l({body:{type:s.eventName,...v?{conversationId:v}:{},...d?{messageId:d}:{},...S?{userProperties:o}:{},properties:w,metadata:T}})}try{return await n.onEvent?.(q)}catch(e){console.warn("[events] onEvent callback threw",e)}},[n,a,t,r,l,p,o])};return j.jsx(x.BaseEventsContext.Provider,{value:k,children:g})};exports.ChatBaseEventsProvider=M;
|
|
@@ -6,7 +6,7 @@ import { useChatAuth as O } from "./chat-auth-provider.js";
|
|
|
6
6
|
import { useEventsApi as j } from "../hooks/use-events-api.js";
|
|
7
7
|
import { BaseEventsContext as M } from "./base-events-provider.js";
|
|
8
8
|
const F = ({ children: m }) => {
|
|
9
|
-
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.
|
|
9
|
+
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.17.0", a = x(
|
|
10
10
|
() => ({
|
|
11
11
|
widgetLibraryVersion: c,
|
|
12
12
|
componentType: i
|
package/dist/types/events.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@zag-js/react": "^1.38.1",
|
|
73
73
|
"@zag-js/remove-scroll": "^1.38.1",
|
|
74
74
|
"ai": "6.0.44",
|
|
75
|
-
"altcha
|
|
75
|
+
"altcha": "^3.0.9",
|
|
76
76
|
"aria-hidden": "^1.2.4",
|
|
77
77
|
"class-variance-authority": "0.7.1",
|
|
78
78
|
"clsx": "2.1.1",
|