@inkeep/agents-ui 0.0.0-dev-20260501021535 → 0.0.0-dev-20260501182500
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/node_modules/.pnpm/botid@1.5.11_next@16.2.4_@babel_core@7.29.0_@opentelemetry_api@1.9.1_react-dom@19.3.0-c_6ac35f5bf61166da3243b6cf36e09c95/node_modules/botid/dist/client/core/index.cjs +1 -0
- package/dist/node_modules/.pnpm/botid@1.5.11_next@16.2.4_@babel_core@7.29.0_@opentelemetry_api@1.9.1_react-dom@19.3.0-c_6ac35f5bf61166da3243b6cf36e09c95/node_modules/botid/dist/client/core/index.js +160 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +4 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +0 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +237 -262
- package/dist/primitives/hooks/use-anonymous-session.cjs +1 -1
- package/dist/primitives/hooks/use-anonymous-session.d.ts +1 -3
- package/dist/primitives/hooks/use-anonymous-session.js +51 -56
- package/dist/primitives/hooks/use-conversation-loader.cjs +1 -1
- package/dist/primitives/hooks/use-conversation-loader.d.ts +1 -3
- package/dist/primitives/hooks/use-conversation-loader.js +15 -20
- package/dist/primitives/hooks/use-feedback-api.cjs +1 -1
- package/dist/primitives/hooks/use-feedback-api.d.ts +1 -3
- package/dist/primitives/hooks/use-feedback-api.js +16 -22
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +8 -11
- package/dist/primitives/hooks/use-inkeep-api-client.js +36 -64
- package/dist/primitives/providers/botid-initializer.cjs +1 -0
- package/dist/primitives/providers/botid-initializer.d.ts +15 -0
- package/dist/primitives/providers/botid-initializer.js +64 -0
- package/dist/primitives/providers/chat-history-provider.cjs +1 -1
- package/dist/primitives/providers/chat-history-provider.js +35 -39
- package/dist/primitives/providers/feedback-provider.cjs +1 -1
- package/dist/primitives/providers/feedback-provider.js +26 -35
- package/dist/primitives/providers/root-provider.cjs +1 -1
- package/dist/primitives/providers/root-provider.js +13 -9
- package/dist/primitives/utils/default-settings.cjs +1 -1
- package/dist/primitives/utils/default-settings.d.ts +1 -0
- package/dist/primitives/utils/default-settings.js +6 -5
- package/dist/types/config/ai.d.ts +8 -0
- package/package.json +2 -2
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +0 -1
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +0 -30
- package/dist/primitives/components/embedded-chat/use-captcha.js +0 -67
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),F=require("./use-local-storage.cjs"),L=require("./use-inkeep-api-client.cjs"),C=30*1e3,j=2147483647;function _(s){return new Date(s.expiresAt).getTime()-C<=Date.now()}const q=({baseUrl:s,appId:t,optOutAllAnalytics:m,enabled:r=!0})=>{const $=r&&t&&!m?`inkeep_session_${t}`:null,[i,a]=F.useLocalStorage($),E=e.useRef(r);e.useEffect(()=>{const n=E.current;if(E.current=r,n&&!r&&t&&!m){try{localStorage.removeItem(`inkeep_session_${t}`)}catch{}a(null)}},[r,t,m,a]);const{fetchWithAuth:T}=L.useInkeepApiClient({appId:t,authToken:void 0}),R=e.useRef(s);R.current=s;const k=e.useRef(t);k.current=t;const f=e.useRef(i);f.current=i;const v=e.useRef(a);v.current=a;const w=e.useRef(T);w.current=T;const l=e.useRef(null),M=e.useRef(r);M.current=r;const o=e.useCallback(async n=>{if(!M.current||!R.current||!k.current)return null;if(!n&&l.current)return l.current;const u=`${R.current}/run/auth/apps/${k.current}/anonymous-session`,h=(async()=>{try{const c={"Content-Type":"application/json"},x=f.current?.token;x&&(c.Authorization=`Bearer ${x}`);const A=await w.current(u,{method:"POST",headers:c,signal:n});if(!A.ok)throw new Error(`Failed to fetch anonymous session: ${A.status}`);const S=await A.json();return v.current({token:S.token,expiresAt:S.expiresAt}),S.token}catch(c){return c instanceof Error&&c.name==="AbortError"||console.error("[anonymous-session] fetch failed",c),null}finally{n||(l.current=null)}})();return n||(l.current=h),h},[]),g=e.useRef(!1);e.useEffect(()=>{if(!r||!s||!t)return;const n=!g.current;if(g.current=!0,!n&&f.current&&!_(f.current)||l.current)return;const u=new AbortController;return o(u.signal),()=>u.abort()},[s,t,r,o]),e.useEffect(()=>{if(!r||!s||!t||!i?.expiresAt)return;const y=new Date(i.expiresAt).getTime()-C-Date.now();if(y<=0)return;const h=setTimeout(()=>o(),Math.min(y,j));return()=>clearTimeout(h)},[s,t,r,i?.expiresAt,o]),e.useEffect(()=>{if(!r||!s||!t)return;const n=()=>{if(document.visibilityState!=="visible")return;const u=f.current;(!u||_(u))&&o()};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[s,t,r,o]);const D=e.useCallback(()=>o(),[o]);return{sessionToken:i?.token??null,refreshSession:D}};exports.useAnonymousSession=q;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
interface UseAnonymousSessionOptions {
|
|
2
2
|
baseUrl?: string;
|
|
3
3
|
appId?: string;
|
|
4
|
-
getCaptchaHeader?: () => Promise<Record<string, string>>;
|
|
5
|
-
invalidateCaptcha?: () => void;
|
|
6
4
|
optOutAllAnalytics?: boolean;
|
|
7
5
|
enabled?: boolean;
|
|
8
6
|
}
|
|
9
|
-
export declare const useAnonymousSession: ({ baseUrl, appId,
|
|
7
|
+
export declare const useAnonymousSession: ({ baseUrl, appId, optOutAllAnalytics, enabled, }: UseAnonymousSessionOptions) => {
|
|
10
8
|
sessionToken: string | null;
|
|
11
9
|
refreshSession: () => Promise<string | null>;
|
|
12
10
|
};
|
|
@@ -1,96 +1,91 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as o, useEffect as
|
|
3
|
-
import { useLocalStorage as
|
|
4
|
-
import { useInkeepApiClient as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return new Date(n.expiresAt).getTime() - p <= Date.now();
|
|
2
|
+
import { useRef as o, useEffect as a, useCallback as $ } from "react";
|
|
3
|
+
import { useLocalStorage as j } from "./use-local-storage.js";
|
|
4
|
+
import { useInkeepApiClient as B } from "./use-inkeep-api-client.js";
|
|
5
|
+
const D = 30 * 1e3, P = 2147483647;
|
|
6
|
+
function C(n) {
|
|
7
|
+
return new Date(n.expiresAt).getTime() - D <= Date.now();
|
|
9
8
|
}
|
|
10
|
-
const
|
|
9
|
+
const K = ({
|
|
11
10
|
baseUrl: n,
|
|
12
11
|
appId: e,
|
|
13
|
-
getCaptchaHeader: D,
|
|
14
|
-
invalidateCaptcha: F,
|
|
15
12
|
optOutAllAnalytics: k,
|
|
16
13
|
enabled: t = !0
|
|
17
14
|
}) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const r =
|
|
21
|
-
if (
|
|
15
|
+
const F = t && e && !k ? `inkeep_session_${e}` : null, [u, m] = j(F), T = o(t);
|
|
16
|
+
a(() => {
|
|
17
|
+
const r = T.current;
|
|
18
|
+
if (T.current = t, r && !t && e && !k) {
|
|
22
19
|
try {
|
|
23
20
|
localStorage.removeItem(`inkeep_session_${e}`);
|
|
24
21
|
} catch {
|
|
25
22
|
}
|
|
26
|
-
|
|
23
|
+
m(null);
|
|
27
24
|
}
|
|
28
|
-
}, [t, e, k,
|
|
29
|
-
const { fetchWithAuth:
|
|
25
|
+
}, [t, e, k, m]);
|
|
26
|
+
const { fetchWithAuth: v } = B({
|
|
30
27
|
appId: e,
|
|
31
|
-
authToken: void 0
|
|
32
|
-
getCaptchaHeader: D ?? z,
|
|
33
|
-
invalidateCaptcha: F ?? X
|
|
28
|
+
authToken: void 0
|
|
34
29
|
}), y = o(n);
|
|
35
30
|
y.current = n;
|
|
36
31
|
const A = o(e);
|
|
37
32
|
A.current = e;
|
|
38
|
-
const f = o(
|
|
39
|
-
f.current =
|
|
40
|
-
const w = o(
|
|
41
|
-
w.current =
|
|
42
|
-
const x = o(
|
|
43
|
-
x.current =
|
|
44
|
-
const
|
|
33
|
+
const f = o(u);
|
|
34
|
+
f.current = u;
|
|
35
|
+
const w = o(m);
|
|
36
|
+
w.current = m;
|
|
37
|
+
const x = o(v);
|
|
38
|
+
x.current = v;
|
|
39
|
+
const h = o(null), M = o(t);
|
|
45
40
|
M.current = t;
|
|
46
|
-
const s =
|
|
41
|
+
const s = $(async (r) => {
|
|
47
42
|
if (!M.current || !y.current || !A.current) return null;
|
|
48
|
-
if (!r &&
|
|
49
|
-
return
|
|
50
|
-
const i = `${y.current}/run/auth/apps/${A.current}/anonymous-session`,
|
|
43
|
+
if (!r && h.current)
|
|
44
|
+
return h.current;
|
|
45
|
+
const i = `${y.current}/run/auth/apps/${A.current}/anonymous-session`, l = (async () => {
|
|
51
46
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
47
|
+
const c = { "Content-Type": "application/json" }, g = f.current?.token;
|
|
48
|
+
g && (c.Authorization = `Bearer ${g}`);
|
|
49
|
+
const E = await x.current(i, {
|
|
55
50
|
method: "POST",
|
|
56
|
-
headers:
|
|
51
|
+
headers: c,
|
|
57
52
|
signal: r
|
|
58
53
|
});
|
|
59
|
-
if (!
|
|
60
|
-
const
|
|
61
|
-
return w.current({ token:
|
|
62
|
-
} catch (
|
|
63
|
-
return
|
|
54
|
+
if (!E.ok) throw new Error(`Failed to fetch anonymous session: ${E.status}`);
|
|
55
|
+
const S = await E.json();
|
|
56
|
+
return w.current({ token: S.token, expiresAt: S.expiresAt }), S.token;
|
|
57
|
+
} catch (c) {
|
|
58
|
+
return c instanceof Error && c.name === "AbortError" || console.error("[anonymous-session] fetch failed", c), null;
|
|
64
59
|
} finally {
|
|
65
|
-
r || (
|
|
60
|
+
r || (h.current = null);
|
|
66
61
|
}
|
|
67
62
|
})();
|
|
68
|
-
return r || (
|
|
69
|
-
}, []),
|
|
70
|
-
|
|
63
|
+
return r || (h.current = l), l;
|
|
64
|
+
}, []), _ = o(!1);
|
|
65
|
+
a(() => {
|
|
71
66
|
if (!t || !n || !e) return;
|
|
72
|
-
const r = !
|
|
73
|
-
if (
|
|
67
|
+
const r = !_.current;
|
|
68
|
+
if (_.current = !0, !r && f.current && !C(f.current) || h.current) return;
|
|
74
69
|
const i = new AbortController();
|
|
75
70
|
return s(i.signal), () => i.abort();
|
|
76
|
-
}, [n, e, t, s]),
|
|
77
|
-
if (!t || !n || !e || !
|
|
78
|
-
const R = new Date(
|
|
71
|
+
}, [n, e, t, s]), a(() => {
|
|
72
|
+
if (!t || !n || !e || !u?.expiresAt) return;
|
|
73
|
+
const R = new Date(u.expiresAt).getTime() - D - Date.now();
|
|
79
74
|
if (R <= 0) return;
|
|
80
|
-
const
|
|
81
|
-
return () => clearTimeout(
|
|
82
|
-
}, [n, e, t,
|
|
75
|
+
const l = setTimeout(() => s(), Math.min(R, P));
|
|
76
|
+
return () => clearTimeout(l);
|
|
77
|
+
}, [n, e, t, u?.expiresAt, s]), a(() => {
|
|
83
78
|
if (!t || !n || !e) return;
|
|
84
79
|
const r = () => {
|
|
85
80
|
if (document.visibilityState !== "visible") return;
|
|
86
81
|
const i = f.current;
|
|
87
|
-
(!i ||
|
|
82
|
+
(!i || C(i)) && s();
|
|
88
83
|
};
|
|
89
84
|
return document.addEventListener("visibilitychange", r), () => document.removeEventListener("visibilitychange", r);
|
|
90
85
|
}, [n, e, t, s]);
|
|
91
|
-
const
|
|
92
|
-
return { sessionToken:
|
|
86
|
+
const L = $(() => s(), [s]);
|
|
87
|
+
return { sessionToken: u?.token ?? null, refreshSession: L };
|
|
93
88
|
};
|
|
94
89
|
export {
|
|
95
|
-
|
|
90
|
+
K as useAnonymousSession
|
|
96
91
|
};
|
|
@@ -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 c=require("react"),l=require("./use-inkeep-api-client.cjs"),d=({baseUrl:r,appId:s,authToken:o,refreshSession:a})=>{const{fetchWithAuth:t}=l.useInkeepApiClient({appId:s,authToken:o,refreshSession:a});return{loadConversation:c.useCallback(async(i,u)=>{if(!r||!o)return null;try{const e=`${r}/run/v1/conversations/${i}`,n=await t(e,{signal:u});if(!n.ok)throw new Error(`Failed to load conversation: ${n.status}`);return(await n.json()).data?.messages??[]}catch(e){return e instanceof Error&&e.name==="AbortError"||console.error("[useConversationLoader]",e),null}},[r,o,t])}};exports.useConversationLoader=d;
|
|
@@ -3,11 +3,9 @@ interface UseConversationLoaderOptions {
|
|
|
3
3
|
baseUrl: string | undefined;
|
|
4
4
|
appId: string | undefined;
|
|
5
5
|
authToken: string | null;
|
|
6
|
-
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
|
-
invalidateCaptcha?: () => void;
|
|
8
6
|
refreshSession?: () => Promise<string | null>;
|
|
9
7
|
}
|
|
10
|
-
export declare const useConversationLoader: ({ baseUrl, appId, authToken,
|
|
8
|
+
export declare const useConversationLoader: ({ baseUrl, appId, authToken, refreshSession, }: UseConversationLoaderOptions) => {
|
|
11
9
|
loadConversation: (conversationId: string, signal?: AbortSignal) => Promise<Message[] | null>;
|
|
12
10
|
};
|
|
13
11
|
export {};
|
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
baseUrl: r,
|
|
2
|
+
import { useCallback as u } from "react";
|
|
3
|
+
import { useInkeepApiClient as l } from "./use-inkeep-api-client.js";
|
|
4
|
+
const C = ({
|
|
5
|
+
baseUrl: o,
|
|
7
6
|
appId: s,
|
|
8
7
|
authToken: n,
|
|
9
|
-
|
|
10
|
-
invalidateCaptcha: i,
|
|
11
|
-
refreshSession: c
|
|
8
|
+
refreshSession: a
|
|
12
9
|
}) => {
|
|
13
|
-
const { fetchWithAuth: e } =
|
|
10
|
+
const { fetchWithAuth: e } = l({
|
|
14
11
|
appId: s,
|
|
15
12
|
authToken: n,
|
|
16
|
-
|
|
17
|
-
invalidateCaptcha: i ?? f,
|
|
18
|
-
refreshSession: c
|
|
13
|
+
refreshSession: a
|
|
19
14
|
});
|
|
20
|
-
return { loadConversation:
|
|
21
|
-
async (
|
|
22
|
-
if (!
|
|
15
|
+
return { loadConversation: u(
|
|
16
|
+
async (i, c) => {
|
|
17
|
+
if (!o || !n) return null;
|
|
23
18
|
try {
|
|
24
|
-
const
|
|
19
|
+
const r = `${o}/run/v1/conversations/${i}`, t = await e(r, { signal: c });
|
|
25
20
|
if (!t.ok) throw new Error(`Failed to load conversation: ${t.status}`);
|
|
26
21
|
return (await t.json()).data?.messages ?? [];
|
|
27
|
-
} catch (
|
|
28
|
-
return
|
|
22
|
+
} catch (r) {
|
|
23
|
+
return r instanceof Error && r.name === "AbortError" || console.error("[useConversationLoader]", r), null;
|
|
29
24
|
}
|
|
30
25
|
},
|
|
31
|
-
[
|
|
26
|
+
[o, n, e]
|
|
32
27
|
) };
|
|
33
28
|
};
|
|
34
29
|
export {
|
|
35
|
-
|
|
30
|
+
C as useConversationLoader
|
|
36
31
|
};
|
|
@@ -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 b=require("react"),p=require("./use-inkeep-api-client.cjs");function l({baseUrl:e,appId:s,authToken:t,refreshSession:c}){const{fetchWithAuth:n}=p.useInkeepApiClient({appId:s,authToken:t,refreshSession:c});return{submitFeedback:b.useCallback(async({conversationId:r,messageId:u,type:o,details:a})=>{if(!e||!t)return;const d=`${e}/run/v1/feedback`,i=await n(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversationId:r,messageId:u,type:o,details:a})});if(!i.ok)throw new Error(`Feedback submission failed: ${i.status}`);return i.json()},[e,t,n])}}exports.useFeedbackApi=l;
|
|
@@ -3,8 +3,6 @@ interface UseFeedbackApiOptions {
|
|
|
3
3
|
baseUrl: string | undefined;
|
|
4
4
|
appId: string | undefined;
|
|
5
5
|
authToken: string | null | undefined;
|
|
6
|
-
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
|
-
invalidateCaptcha?: () => void;
|
|
8
6
|
refreshSession?: () => Promise<string | null>;
|
|
9
7
|
}
|
|
10
8
|
interface SubmitFeedbackParams {
|
|
@@ -13,7 +11,7 @@ interface SubmitFeedbackParams {
|
|
|
13
11
|
type: FeedbackType;
|
|
14
12
|
details?: string | null;
|
|
15
13
|
}
|
|
16
|
-
export declare function useFeedbackApi({ baseUrl, appId, authToken,
|
|
14
|
+
export declare function useFeedbackApi({ baseUrl, appId, authToken, refreshSession, }: UseFeedbackApiOptions): {
|
|
17
15
|
submitFeedback: ({ conversationId, messageId, type, details }: SubmitFeedbackParams) => Promise<any>;
|
|
18
16
|
};
|
|
19
17
|
export {};
|
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
function C({
|
|
2
|
+
import { useCallback as f } from "react";
|
|
3
|
+
import { useInkeepApiClient as p } from "./use-inkeep-api-client.js";
|
|
4
|
+
function l({
|
|
7
5
|
baseUrl: e,
|
|
8
|
-
appId:
|
|
6
|
+
appId: s,
|
|
9
7
|
authToken: t,
|
|
10
|
-
|
|
11
|
-
invalidateCaptcha: r,
|
|
12
|
-
refreshSession: c
|
|
8
|
+
refreshSession: o
|
|
13
9
|
}) {
|
|
14
|
-
const { fetchWithAuth:
|
|
15
|
-
appId:
|
|
10
|
+
const { fetchWithAuth: n } = p({
|
|
11
|
+
appId: s,
|
|
16
12
|
authToken: t,
|
|
17
|
-
|
|
18
|
-
invalidateCaptcha: r ?? k,
|
|
19
|
-
refreshSession: c
|
|
13
|
+
refreshSession: o
|
|
20
14
|
});
|
|
21
|
-
return { submitFeedback:
|
|
22
|
-
async ({ conversationId:
|
|
15
|
+
return { submitFeedback: f(
|
|
16
|
+
async ({ conversationId: r, messageId: c, type: u, details: a }) => {
|
|
23
17
|
if (!e || !t) return;
|
|
24
|
-
const
|
|
18
|
+
const d = `${e}/run/v1/feedback`, i = await n(d, {
|
|
25
19
|
method: "POST",
|
|
26
20
|
headers: { "Content-Type": "application/json" },
|
|
27
|
-
body: JSON.stringify({ conversationId:
|
|
21
|
+
body: JSON.stringify({ conversationId: r, messageId: c, type: u, details: a })
|
|
28
22
|
});
|
|
29
|
-
if (!
|
|
30
|
-
return
|
|
23
|
+
if (!i.ok) throw new Error(`Feedback submission failed: ${i.status}`);
|
|
24
|
+
return i.json();
|
|
31
25
|
},
|
|
32
|
-
[e, t,
|
|
26
|
+
[e, t, n]
|
|
33
27
|
) };
|
|
34
28
|
}
|
|
35
29
|
export {
|
|
36
|
-
|
|
30
|
+
l as useFeedbackApi
|
|
37
31
|
};
|
|
@@ -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 c=require("react");function l(e,r){if(e===401&&typeof r=="object"&&r!==null){const t=r.detail??"";if(t.includes("Invalid end-user JWT")||t.includes("Bearer token required"))return"session"}return null}function R(e){if(!e)return{};if(e instanceof Headers){const r={};return e.forEach((t,s)=>{r[s]=t}),r}return Array.isArray(e)?Object.fromEntries(e):e}function h(e,r,t){return{...e?{"x-inkeep-app-id":e}:{},...r?{Authorization:`Bearer ${r}`}:{},...R(t)}}function y({appId:e,authToken:r,refreshSession:t}){const s=c.useRef(e);s.current=e;const a=c.useRef(r);a.current=r;const o=c.useRef(t);return o.current=t,{fetchWithAuth:c.useCallback(async(f,u)=>{const p=h(s.current,a.current,u?.headers),n=await fetch(f,{...u,headers:p});if(n.status!==401)return n;let i;try{i=await n.clone().json()}catch{return n}if(l(n.status,i)==="session"&&o.current){const d=await o.current();if(!d)return n;const A=h(s.current,d,u?.headers);return fetch(f,{...u,headers:A})}return n},[])}}exports.parseAuthError=l;exports.useInkeepApiClient=y;
|
|
@@ -2,8 +2,6 @@ interface UseInkeepApiClientOptions {
|
|
|
2
2
|
appId: string | undefined;
|
|
3
3
|
/** The bearer token to send as Authorization — pass undefined for unauthenticated calls. */
|
|
4
4
|
authToken: string | null | undefined;
|
|
5
|
-
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
6
|
-
invalidateCaptcha: () => void;
|
|
7
5
|
/**
|
|
8
6
|
* Called when a 401 session error is detected.
|
|
9
7
|
* Should refresh the anonymous session and return the new token, or null on failure.
|
|
@@ -12,22 +10,21 @@ interface UseInkeepApiClientOptions {
|
|
|
12
10
|
refreshSession?: () => Promise<string | null>;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
|
-
* Parses
|
|
16
|
-
*
|
|
17
|
-
* The Run API returns:
|
|
18
|
-
* - 400 + detail containing "challenge" or "proof-of-work" → PoW failure
|
|
19
|
-
* - 401 + detail matching JWT/bearer messages → session token failure
|
|
13
|
+
* Parses a 401 error response body to determine whether it's a session-token failure
|
|
14
|
+
* eligible for transparent refresh.
|
|
20
15
|
*/
|
|
21
|
-
export declare function parseAuthError(status: number, body: unknown): '
|
|
16
|
+
export declare function parseAuthError(status: number, body: unknown): 'session' | null;
|
|
22
17
|
/**
|
|
23
18
|
* Returns a stable `fetchWithAuth` function that automatically:
|
|
24
|
-
* - Injects auth headers (x-inkeep-app-id, Authorization
|
|
25
|
-
* - Retries once on PoW errors (400) with a fresh captcha solution
|
|
19
|
+
* - Injects auth headers (x-inkeep-app-id, Authorization)
|
|
26
20
|
* - Retries once on session errors (401) by refreshing the session token (when refreshSession is provided)
|
|
27
21
|
*
|
|
22
|
+
* Bot-protection headers are attached transparently by the BotID client SDK
|
|
23
|
+
* (initialized in RootProvider) — no header plumbing needed here.
|
|
24
|
+
*
|
|
28
25
|
* All options are kept in refs so `fetchWithAuth` is created once and never needs to be re-created.
|
|
29
26
|
*/
|
|
30
|
-
export declare function useInkeepApiClient({ appId, authToken,
|
|
27
|
+
export declare function useInkeepApiClient({ appId, authToken, refreshSession, }: UseInkeepApiClientOptions): {
|
|
31
28
|
fetchWithAuth: (url: string, init?: RequestInit) => Promise<Response>;
|
|
32
29
|
};
|
|
33
30
|
export {};
|
|
@@ -1,87 +1,59 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
const t =
|
|
6
|
-
if (t.includes("challenge") || t.includes("proof-of-work")) return "pow";
|
|
7
|
-
}
|
|
8
|
-
if (e === 401 && typeof r == "object" && r !== null) {
|
|
9
|
-
const t = r.detail ?? "";
|
|
2
|
+
import { useRef as o, useCallback as A } from "react";
|
|
3
|
+
function y(r, e) {
|
|
4
|
+
if (r === 401 && typeof e == "object" && e !== null) {
|
|
5
|
+
const t = e.detail ?? "";
|
|
10
6
|
if (t.includes("Invalid end-user JWT") || t.includes("Bearer token required"))
|
|
11
7
|
return "session";
|
|
12
8
|
}
|
|
13
9
|
return null;
|
|
14
10
|
}
|
|
15
|
-
function
|
|
16
|
-
if (!
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
}),
|
|
11
|
+
function E(r) {
|
|
12
|
+
if (!r) return {};
|
|
13
|
+
if (r instanceof Headers) {
|
|
14
|
+
const e = {};
|
|
15
|
+
return r.forEach((t, s) => {
|
|
16
|
+
e[s] = t;
|
|
17
|
+
}), e;
|
|
22
18
|
}
|
|
23
|
-
return Array.isArray(
|
|
19
|
+
return Array.isArray(r) ? Object.fromEntries(r) : r;
|
|
24
20
|
}
|
|
25
|
-
function
|
|
21
|
+
function d(r, e, t) {
|
|
26
22
|
return {
|
|
27
|
-
...
|
|
28
|
-
...
|
|
29
|
-
...
|
|
30
|
-
// captcha last — must not be overridden by caller headers
|
|
31
|
-
...t
|
|
23
|
+
...r ? { "x-inkeep-app-id": r } : {},
|
|
24
|
+
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
25
|
+
...E(t)
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
|
-
function
|
|
35
|
-
appId:
|
|
36
|
-
authToken:
|
|
37
|
-
|
|
38
|
-
invalidateCaptcha: c,
|
|
39
|
-
refreshSession: w
|
|
28
|
+
function j({
|
|
29
|
+
appId: r,
|
|
30
|
+
authToken: e,
|
|
31
|
+
refreshSession: t
|
|
40
32
|
}) {
|
|
41
|
-
const
|
|
33
|
+
const s = o(r);
|
|
34
|
+
s.current = r;
|
|
35
|
+
const a = o(e);
|
|
42
36
|
a.current = e;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
A.current = c;
|
|
49
|
-
const h = u(w);
|
|
50
|
-
return h.current = w, { fetchWithAuth: y(async (d, s) => {
|
|
51
|
-
const C = await o.current(), H = p(
|
|
52
|
-
a.current,
|
|
53
|
-
i.current,
|
|
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;
|
|
37
|
+
const c = o(t);
|
|
38
|
+
return c.current = t, { fetchWithAuth: A(async (f, u) => {
|
|
39
|
+
const l = d(s.current, a.current, u?.headers), n = await fetch(f, { ...u, headers: l });
|
|
40
|
+
if (n.status !== 401) return n;
|
|
41
|
+
let i;
|
|
59
42
|
try {
|
|
60
|
-
|
|
43
|
+
i = await n.clone().json();
|
|
61
44
|
} catch {
|
|
62
45
|
return n;
|
|
63
46
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
i.current,
|
|
70
|
-
f,
|
|
71
|
-
s?.headers
|
|
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 });
|
|
47
|
+
if (y(n.status, i) === "session" && c.current) {
|
|
48
|
+
const h = await c.current();
|
|
49
|
+
if (!h) return n;
|
|
50
|
+
const p = d(s.current, h, u?.headers);
|
|
51
|
+
return fetch(f, { ...u, headers: p });
|
|
80
52
|
}
|
|
81
53
|
return n;
|
|
82
54
|
}, []) };
|
|
83
55
|
}
|
|
84
56
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
y as parseAuthError,
|
|
58
|
+
j as useInkeepApiClient
|
|
87
59
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react"),w=require("../../node_modules/.pnpm/botid@1.5.11_next@16.2.4_@babel_core@7.29.0_@opentelemetry_api@1.9.1_react-dom@19.3.0-c_6ac35f5bf61166da3243b6cf36e09c95/node_modules/botid/dist/client/core/index.cjs"),I=require("./config-provider.cjs");function _(){const{baseSettings:f,aiChatSettings:b}=I.useInkeepConfig(),{shouldBypassCaptcha:l}=f,{baseUrl:a,apiKey:d,botProtectionLevel:u}=b,h=g.useRef(!1);return g.useEffect(()=>{if(h.current||l||d||!a)return;if(typeof window<"u"&&!window.__INKEEP_FETCH_DEBUG__){window.__INKEEP_FETCH_DEBUG__=!0;const n=window.fetch;window.fetch=async function(e,i){let s;typeof e=="string"?s=e:e instanceof URL?s=e.toString():s=e.url;try{const t=new URL(s,location.href);if(t.pathname.startsWith("/run/")){const r=new Headers(i?.headers??(e instanceof Request?e.headers:void 0)),m=i?.method??(e instanceof Request?e.method:"GET");console.log("[botid-debug] fetch →",{url:t.toString(),method:m,locationOrigin:location.origin,targetOrigin:t.origin,sameOrigin:t.origin===location.origin,hasXIsHuman:r.has("x-is-human"),xIsHumanLength:r.get("x-is-human")?.length??null,xPath:r.get("x-path"),xMethod:r.get("x-method")});const c=await n.call(this,e,i);return console.log("[botid-debug] fetch ←",{url:t.toString(),status:c.status,statusText:c.statusText}),c}}catch{}return n.call(this,e,i)}}const o={checkLevel:u};try{console.log("[botid-debug] calling initBotId",{baseUrl:a,advancedOptions:o}),w.initBotId({protect:[{path:"/run/auth/apps/*/anonymous-session",method:"POST",advancedOptions:o},{path:"/run/api/chat",method:"POST",advancedOptions:o},{path:"/run/v1/feedback",method:"POST",advancedOptions:o}]}),h.current=!0,console.log("[botid-debug] initBotId returned successfully")}catch(n){console.warn("[botid-debug] initBotId threw",n)}},[a,d,l,u]),null}exports.BotIdInitializer=_;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot Vercel BotID client initializer. Mounts once at the top of the widget
|
|
3
|
+
* tree, calls `initBotId({ protect })` if bot protection is enabled and we have
|
|
4
|
+
* a baseUrl. The BotID SDK then patches `window.fetch` and `XMLHttpRequest` to
|
|
5
|
+
* attach `x-is-human` headers on requests matching the protect list.
|
|
6
|
+
*
|
|
7
|
+
* Initialization is gated:
|
|
8
|
+
* - Skipped when `shouldBypassCaptcha` is true (server-side API key flow).
|
|
9
|
+
* - Skipped when `apiKey` is set (consumer authenticated server-side already).
|
|
10
|
+
* - Skipped when no `baseUrl` is configured (nothing to protect against).
|
|
11
|
+
*
|
|
12
|
+
* Initialization is idempotent — `initBotId` is called at most once per page
|
|
13
|
+
* session even if the widget remounts.
|
|
14
|
+
*/
|
|
15
|
+
export declare function BotIdInitializer(): null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef as w, useEffect as b } from "react";
|
|
3
|
+
import { initBotId as I } from "../../node_modules/.pnpm/botid@1.5.11_next@16.2.4_@babel_core@7.29.0_@opentelemetry_api@1.9.1_react-dom@19.3.0-c_6ac35f5bf61166da3243b6cf36e09c95/node_modules/botid/dist/client/core/index.js";
|
|
4
|
+
import { useInkeepConfig as _ } from "./config-provider.js";
|
|
5
|
+
function B() {
|
|
6
|
+
const { baseSettings: f, aiChatSettings: g } = _(), { shouldBypassCaptcha: l } = f, { baseUrl: a, apiKey: h, botProtectionLevel: d } = g, u = w(!1);
|
|
7
|
+
return b(() => {
|
|
8
|
+
if (u.current || l || h || !a) return;
|
|
9
|
+
if (typeof window < "u" && !window.__INKEEP_FETCH_DEBUG__) {
|
|
10
|
+
window.__INKEEP_FETCH_DEBUG__ = !0;
|
|
11
|
+
const n = window.fetch;
|
|
12
|
+
window.fetch = async function(t, s) {
|
|
13
|
+
let i;
|
|
14
|
+
typeof t == "string" ? i = t : t instanceof URL ? i = t.toString() : i = t.url;
|
|
15
|
+
try {
|
|
16
|
+
const e = new URL(i, location.href);
|
|
17
|
+
if (e.pathname.startsWith("/run/")) {
|
|
18
|
+
const r = new Headers(
|
|
19
|
+
s?.headers ?? (t instanceof Request ? t.headers : void 0)
|
|
20
|
+
), m = s?.method ?? (t instanceof Request ? t.method : "GET");
|
|
21
|
+
console.log("[botid-debug] fetch →", {
|
|
22
|
+
url: e.toString(),
|
|
23
|
+
method: m,
|
|
24
|
+
locationOrigin: location.origin,
|
|
25
|
+
targetOrigin: e.origin,
|
|
26
|
+
sameOrigin: e.origin === location.origin,
|
|
27
|
+
hasXIsHuman: r.has("x-is-human"),
|
|
28
|
+
xIsHumanLength: r.get("x-is-human")?.length ?? null,
|
|
29
|
+
xPath: r.get("x-path"),
|
|
30
|
+
xMethod: r.get("x-method")
|
|
31
|
+
});
|
|
32
|
+
const c = await n.call(this, t, s);
|
|
33
|
+
return console.log("[botid-debug] fetch ←", {
|
|
34
|
+
url: e.toString(),
|
|
35
|
+
status: c.status,
|
|
36
|
+
statusText: c.statusText
|
|
37
|
+
}), c;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
return n.call(this, t, s);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const o = { checkLevel: d };
|
|
45
|
+
try {
|
|
46
|
+
console.log("[botid-debug] calling initBotId", { baseUrl: a, advancedOptions: o }), I({
|
|
47
|
+
protect: [
|
|
48
|
+
{
|
|
49
|
+
path: "/run/auth/apps/*/anonymous-session",
|
|
50
|
+
method: "POST",
|
|
51
|
+
advancedOptions: o
|
|
52
|
+
},
|
|
53
|
+
{ path: "/run/api/chat", method: "POST", advancedOptions: o },
|
|
54
|
+
{ path: "/run/v1/feedback", method: "POST", advancedOptions: o }
|
|
55
|
+
]
|
|
56
|
+
}), u.current = !0, console.log("[botid-debug] initBotId returned successfully");
|
|
57
|
+
} catch (n) {
|
|
58
|
+
console.warn("[botid-debug] initBotId threw", n);
|
|
59
|
+
}
|
|
60
|
+
}, [a, h, l, d]), null;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
B as BotIdInitializer
|
|
64
|
+
};
|
|
@@ -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"),e=require("react"),N=require("../components/embedded-chat/chat-provider.cjs"),ee=require("./config-provider.cjs"),te=require("../hooks/use-inkeep-api-client.cjs"),U=e.createContext(void 0),K=25;function se(t){const{stop:u,clear:f,conversationId:l,isStreaming:y,loadAndRestoreSession:R,authToken:s,refreshSession:Z}=N.useChat(),{aiChatSettings:_,baseSettings:z}=ee.useInkeepConfig(),{baseUrl:S,appId:I,apiKey:B}=_,a=!!z.getAuthToken,o=!B&&!!I&&(!!s||a),{fetchWithAuth:P}=te.useInkeepApiClient({appId:I,authToken:s,refreshSession:Z}),[v,b]=e.useState(!1),[H,E]=e.useState([]),[k,x]=e.useState(!s&&o),[m,q]=e.useState(0),[w,T]=e.useState(!1),h=e.useRef(!1),j=e.useRef(null),M=e.useRef(a),$=e.useRef(s);e.useEffect(()=>{const r=M.current,n=$.current;M.current=a,$.current=s,(r!==a||n!==null&&s!==null&&n!==s)&&(E([]),q(0),T(!1),h.current=!1)},[a,s]);const L=e.useRef([]);L.current=H;const O=e.useRef(P);O.current=P;const c=e.useCallback(async(r,n=!1)=>{if(!(!S||!s||!o)){n||x(!0);try{const C=`${S}/run/v1/conversations?page=${r+1}&limit=${K}`,g=await O.current(C);if(!g.ok)throw new Error(`Failed to fetch conversations: ${g.status}`);const F=await g.json(),p=(F.data??[]).map(i=>({id:i.id,title:i.title??"",createdAt:new Date(i.createdAt),updatedAt:new Date(i.updatedAt)}));E(i=>{if(r===0&&!n)return p;if(r===0&&n){const d=new Set(p.map(A=>A.id));return[...p,...i.slice(K).filter(A=>!d.has(A.id))]}const X=new Set(i.map(d=>d.id));return[...i,...p.filter(d=>!X.has(d.id))]});const{page:W,pages:G}=F.pagination??{};T(W!=null&&G!=null?W<G:!1),n||q(r)}catch(C){console.error("[useChatHistory] Failed to load conversations:",C)}finally{x(!1)}}},[S,s,o]);e.useEffect(()=>{!v||!s&&!a||!o||(t==="stack"?c(0):!h.current&&s&&(h.current=!0,c(0)))},[v,s,a,o,t,c]);const D=e.useRef("");e.useEffect(()=>{o&&t==="sidepane"&&(!l||!y||h.current&&D.current!==l&&(L.current.some(r=>r.id===l)||(D.current=l,c(0,!0))))},[l,o,t,c,y]);const J=e.useCallback(()=>{!k&&w&&c(m+1)},[k,w,m,c]),Q=e.useCallback(()=>{u(),f(),t!=="sidepane"&&b(!1)},[t,u,f]),V=e.useCallback(async r=>{j.current?.abort();const n=new AbortController;j.current=n,await R(r,n.signal),!n.signal.aborted&&t!=="sidepane"&&b(!1)},[t,R]);return{isEnabled:o,isOpen:v,setIsOpen:b,sessions:H,isLoading:k,hasMore:w,loadMore:J,startNewConversation:Q,loadSession:V}}const ne=({layout:t,children:u})=>{const f=se(t);return Y.jsx(U.Provider,{value:f,children:typeof u=="function"?u(f):u})},re=()=>{const t=e.useContext(U);if(!t)throw new Error("useChatHistory must be used within a ChatHistoryProvider");return t};exports.ChatHistoryProvider=ne;exports.useChatHistory=re;
|