@inkeep/agents-ui 0.0.0-dev-20260501021535 → 0.0.0-dev-20260501170253

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.
Files changed (35) hide show
  1. 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
  2. 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
  3. package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +4 -2
  4. package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
  5. package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +0 -2
  6. package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +237 -262
  7. package/dist/primitives/hooks/use-anonymous-session.cjs +1 -1
  8. package/dist/primitives/hooks/use-anonymous-session.d.ts +1 -3
  9. package/dist/primitives/hooks/use-anonymous-session.js +51 -56
  10. package/dist/primitives/hooks/use-conversation-loader.cjs +1 -1
  11. package/dist/primitives/hooks/use-conversation-loader.d.ts +1 -3
  12. package/dist/primitives/hooks/use-conversation-loader.js +15 -20
  13. package/dist/primitives/hooks/use-feedback-api.cjs +1 -1
  14. package/dist/primitives/hooks/use-feedback-api.d.ts +1 -3
  15. package/dist/primitives/hooks/use-feedback-api.js +16 -22
  16. package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
  17. package/dist/primitives/hooks/use-inkeep-api-client.d.ts +8 -11
  18. package/dist/primitives/hooks/use-inkeep-api-client.js +36 -64
  19. package/dist/primitives/providers/botid-initializer.cjs +1 -0
  20. package/dist/primitives/providers/botid-initializer.d.ts +15 -0
  21. package/dist/primitives/providers/botid-initializer.js +29 -0
  22. package/dist/primitives/providers/chat-history-provider.cjs +1 -1
  23. package/dist/primitives/providers/chat-history-provider.js +35 -39
  24. package/dist/primitives/providers/feedback-provider.cjs +1 -1
  25. package/dist/primitives/providers/feedback-provider.js +26 -35
  26. package/dist/primitives/providers/root-provider.cjs +1 -1
  27. package/dist/primitives/providers/root-provider.js +13 -9
  28. package/dist/primitives/utils/default-settings.cjs +1 -1
  29. package/dist/primitives/utils/default-settings.d.ts +1 -0
  30. package/dist/primitives/utils/default-settings.js +6 -5
  31. package/dist/types/config/ai.d.ts +8 -0
  32. package/package.json +2 -2
  33. package/dist/primitives/components/embedded-chat/use-captcha.cjs +0 -1
  34. package/dist/primitives/components/embedded-chat/use-captcha.d.ts +0 -30
  35. 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"),j=require("./use-local-storage.cjs"),p=require("./use-inkeep-api-client.cjs"),_=30*1e3,q=2147483647,P=()=>{},B=async()=>({});function x(s){return new Date(s.expiresAt).getTime()-_<=Date.now()}const W=({baseUrl:s,appId:t,getCaptchaHeader:$,invalidateCaptcha:D,optOutAllAnalytics:m,enabled:n=!0})=>{const F=n&&t&&!m?`inkeep_session_${t}`:null,[c,h]=j.useLocalStorage(F),E=e.useRef(n);e.useEffect(()=>{const r=E.current;if(E.current=n,r&&!n&&t&&!m){try{localStorage.removeItem(`inkeep_session_${t}`)}catch{}h(null)}},[n,t,m,h]);const{fetchWithAuth:v}=p.useInkeepApiClient({appId:t,authToken:void 0,getCaptchaHeader:$??B,invalidateCaptcha:D??P}),R=e.useRef(s);R.current=s;const y=e.useRef(t);y.current=t;const f=e.useRef(c);f.current=c;const T=e.useRef(h);T.current=h;const g=e.useRef(v);g.current=v;const a=e.useRef(null),w=e.useRef(n);w.current=n;const o=e.useCallback(async r=>{if(!w.current||!R.current||!y.current)return null;if(!r&&a.current)return a.current;const u=`${R.current}/run/auth/apps/${y.current}/anonymous-session`,l=(async()=>{try{const i={"Content-Type":"application/json"},M=f.current?.token;M&&(i.Authorization=`Bearer ${M}`);const A=await g.current(u,{method:"POST",headers:i,signal:r});if(!A.ok)throw new Error(`Failed to fetch anonymous session: ${A.status}`);const S=await A.json();return T.current({token:S.token,expiresAt:S.expiresAt}),S.token}catch(i){return i instanceof Error&&i.name==="AbortError"||console.error("[anonymous-session] fetch failed",i),null}finally{r||(a.current=null)}})();return r||(a.current=l),l},[]),C=e.useRef(!1);e.useEffect(()=>{if(!n||!s||!t)return;const r=!C.current;if(C.current=!0,!r&&f.current&&!x(f.current)||a.current)return;const u=new AbortController;return o(u.signal),()=>u.abort()},[s,t,n,o]),e.useEffect(()=>{if(!n||!s||!t||!c?.expiresAt)return;const k=new Date(c.expiresAt).getTime()-_-Date.now();if(k<=0)return;const l=setTimeout(()=>o(),Math.min(k,q));return()=>clearTimeout(l)},[s,t,n,c?.expiresAt,o]),e.useEffect(()=>{if(!n||!s||!t)return;const r=()=>{if(document.visibilityState!=="visible")return;const u=f.current;(!u||x(u))&&o()};return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[s,t,n,o]);const L=e.useCallback(()=>o(),[o]);return{sessionToken:c?.token??null,refreshSession:L}};exports.useAnonymousSession=W;
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, getCaptchaHeader, invalidateCaptcha, optOutAllAnalytics, enabled, }: UseAnonymousSessionOptions) => {
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 l, useCallback as g } from "react";
3
- import { useLocalStorage as B } from "./use-local-storage.js";
4
- import { useInkeepApiClient as P } from "./use-inkeep-api-client.js";
5
- const p = 30 * 1e3, W = 2147483647, X = () => {
6
- }, z = async () => ({});
7
- function $(n) {
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 Y = ({
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 L = t && e && !k ? `inkeep_session_${e}` : null, [c, h] = B(L), S = o(t);
19
- l(() => {
20
- const r = S.current;
21
- if (S.current = t, r && !t && e && !k) {
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
- h(null);
23
+ m(null);
27
24
  }
28
- }, [t, e, k, h]);
29
- const { fetchWithAuth: T } = P({
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(c);
39
- f.current = c;
40
- const w = o(h);
41
- w.current = h;
42
- const x = o(T);
43
- x.current = T;
44
- const a = o(null), M = o(t);
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 = g(async (r) => {
41
+ const s = $(async (r) => {
47
42
  if (!M.current || !y.current || !A.current) return null;
48
- if (!r && a.current)
49
- return a.current;
50
- const i = `${y.current}/run/auth/apps/${A.current}/anonymous-session`, m = (async () => {
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 u = { "Content-Type": "application/json" }, _ = f.current?.token;
53
- _ && (u.Authorization = `Bearer ${_}`);
54
- const v = await x.current(i, {
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: u,
51
+ headers: c,
57
52
  signal: r
58
53
  });
59
- if (!v.ok) throw new Error(`Failed to fetch anonymous session: ${v.status}`);
60
- const E = await v.json();
61
- return w.current({ token: E.token, expiresAt: E.expiresAt }), E.token;
62
- } catch (u) {
63
- return u instanceof Error && u.name === "AbortError" || console.error("[anonymous-session] fetch failed", u), null;
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 || (a.current = null);
60
+ r || (h.current = null);
66
61
  }
67
62
  })();
68
- return r || (a.current = m), m;
69
- }, []), C = o(!1);
70
- l(() => {
63
+ return r || (h.current = l), l;
64
+ }, []), _ = o(!1);
65
+ a(() => {
71
66
  if (!t || !n || !e) return;
72
- const r = !C.current;
73
- if (C.current = !0, !r && f.current && !$(f.current) || a.current) return;
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]), l(() => {
77
- if (!t || !n || !e || !c?.expiresAt) return;
78
- const R = new Date(c.expiresAt).getTime() - p - Date.now();
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 m = setTimeout(() => s(), Math.min(R, W));
81
- return () => clearTimeout(m);
82
- }, [n, e, t, c?.expiresAt, s]), l(() => {
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 || $(i)) && s();
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 j = g(() => s(), [s]);
92
- return { sessionToken: c?.token ?? null, refreshSession: j };
86
+ const L = $(() => s(), [s]);
87
+ return { sessionToken: u?.token ?? null, refreshSession: L };
93
88
  };
94
89
  export {
95
- Y as useAnonymousSession
90
+ K as useAnonymousSession
96
91
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),v=require("./use-inkeep-api-client.cjs"),C=()=>{},p=({baseUrl:o,appId:s,authToken:n,getCaptchaHeader:a,invalidateCaptcha:i,refreshSession:c})=>{const{fetchWithAuth:t}=v.useInkeepApiClient({appId:s,authToken:n,getCaptchaHeader:a,invalidateCaptcha:i??C,refreshSession:c});return{loadConversation:d.useCallback(async(u,l)=>{if(!o||!n)return null;try{const e=`${o}/run/v1/conversations/${u}`,r=await t(e,{signal:l});if(!r.ok)throw new Error(`Failed to load conversation: ${r.status}`);return(await r.json()).data?.messages??[]}catch(e){return e instanceof Error&&e.name==="AbortError"||console.error("[useConversationLoader]",e),null}},[o,n,t])}};exports.useConversationLoader=p;
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, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseConversationLoaderOptions) => {
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 d } from "react";
3
- import { useInkeepApiClient as v } from "./use-inkeep-api-client.js";
4
- const f = () => {
5
- }, w = ({
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
- getCaptchaHeader: a,
10
- invalidateCaptcha: i,
11
- refreshSession: c
8
+ refreshSession: a
12
9
  }) => {
13
- const { fetchWithAuth: e } = v({
10
+ const { fetchWithAuth: e } = l({
14
11
  appId: s,
15
12
  authToken: n,
16
- getCaptchaHeader: a,
17
- invalidateCaptcha: i ?? f,
18
- refreshSession: c
13
+ refreshSession: a
19
14
  });
20
- return { loadConversation: d(
21
- async (l, u) => {
22
- if (!r || !n) return null;
15
+ return { loadConversation: u(
16
+ async (i, c) => {
17
+ if (!o || !n) return null;
23
18
  try {
24
- const o = `${r}/run/v1/conversations/${l}`, t = await e(o, { signal: u });
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 (o) {
28
- return o instanceof Error && o.name === "AbortError" || console.error("[useConversationLoader]", o), null;
22
+ } catch (r) {
23
+ return r instanceof Error && r.name === "AbortError" || console.error("[useConversationLoader]", r), null;
29
24
  }
30
25
  },
31
- [r, n, e]
26
+ [o, n, e]
32
27
  ) };
33
28
  };
34
29
  export {
35
- w as useConversationLoader
30
+ C as useConversationLoader
36
31
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),f=require("./use-inkeep-api-client.cjs"),k=()=>{};function y({baseUrl:e,appId:s,authToken:t,getCaptchaHeader:c,invalidateCaptcha:o,refreshSession:r}){const{fetchWithAuth:i}=f.useInkeepApiClient({appId:s,authToken:t,getCaptchaHeader:c,invalidateCaptcha:o??k,refreshSession:r});return{submitFeedback:l.useCallback(async({conversationId:u,messageId:a,type:d,details:p})=>{if(!e||!t)return;const b=`${e}/run/v1/feedback`,n=await i(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversationId:u,messageId:a,type:d,details:p})});if(!n.ok)throw new Error(`Feedback submission failed: ${n.status}`);return n.json()},[e,t,i])}}exports.useFeedbackApi=y;
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, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseFeedbackApiOptions): {
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 b } from "react";
3
- import { useInkeepApiClient as m } from "./use-inkeep-api-client.js";
4
- const k = () => {
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: o,
6
+ appId: s,
9
7
  authToken: t,
10
- getCaptchaHeader: s,
11
- invalidateCaptcha: r,
12
- refreshSession: c
8
+ refreshSession: o
13
9
  }) {
14
- const { fetchWithAuth: i } = m({
15
- appId: o,
10
+ const { fetchWithAuth: n } = p({
11
+ appId: s,
16
12
  authToken: t,
17
- getCaptchaHeader: s,
18
- invalidateCaptcha: r ?? k,
19
- refreshSession: c
13
+ refreshSession: o
20
14
  });
21
- return { submitFeedback: b(
22
- async ({ conversationId: a, messageId: u, type: p, details: d }) => {
15
+ return { submitFeedback: f(
16
+ async ({ conversationId: r, messageId: c, type: u, details: a }) => {
23
17
  if (!e || !t) return;
24
- const f = `${e}/run/v1/feedback`, n = await i(f, {
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: a, messageId: u, type: p, details: d })
21
+ body: JSON.stringify({ conversationId: r, messageId: c, type: u, details: a })
28
22
  });
29
- if (!n.ok) throw new Error(`Feedback submission failed: ${n.status}`);
30
- return n.json();
23
+ if (!i.ok) throw new Error(`Feedback submission failed: ${i.status}`);
24
+ return i.json();
31
25
  },
32
- [e, t, i]
26
+ [e, t, n]
33
27
  ) };
34
28
  }
35
29
  export {
36
- C as useFeedbackApi
30
+ l as useFeedbackApi
37
31
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function y(e,r){if(e===400&&typeof r=="object"&&r!==null){const t=(r.detail??"").toLowerCase();if(t.includes("challenge")||t.includes("proof-of-work"))return"pow"}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 H(e){if(!e)return{};if(e instanceof Headers){const r={};return e.forEach((t,c)=>{r[c]=t}),r}return Array.isArray(e)?Object.fromEntries(e):e}function p(e,r,t,c){return{...e?{"x-inkeep-app-id":e}:{},...r?{Authorization:`Bearer ${r}`}:{},...H(c),...t}}function g({appId:e,authToken:r,getCaptchaHeader:t,invalidateCaptcha:c,refreshSession:R}){const a=u.useRef(e);a.current=e;const i=u.useRef(r);i.current=r;const o=u.useRef(t);o.current=t;const w=u.useRef(c);w.current=c;const h=u.useRef(R);return h.current=R,{fetchWithAuth:u.useCallback(async(l,s)=>{const C=await o.current(),j=p(a.current,i.current,C,s?.headers),n=await fetch(l,{...s,headers:j});if(n.status!==400&&n.status!==401)return n;let A;try{A=await n.clone().json()}catch{return n}const k=y(n.status,A);if(k==="pow"){w.current();const f=await o.current(),d=p(a.current,i.current,f,s?.headers);return fetch(l,{...s,headers:d})}if(k==="session"&&h.current){const f=await h.current();if(!f)return n;const d=await o.current(),E=p(a.current,f,d,s?.headers);return fetch(l,{...s,headers:E})}return n},[])}}exports.parseAuthError=y;exports.useInkeepApiClient=g;
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 an API error response body to determine the failure type.
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): 'pow' | 'session' | null;
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, x-inkeep-challenge-solution)
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, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseInkeepApiClientOptions): {
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 u, useCallback as y } from "react";
3
- function E(e, r) {
4
- if (e === 400 && typeof r == "object" && r !== null) {
5
- const t = (r.detail ?? "").toLowerCase();
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 m(e) {
16
- if (!e) return {};
17
- if (e instanceof Headers) {
18
- const r = {};
19
- return e.forEach((t, c) => {
20
- r[c] = t;
21
- }), r;
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(e) ? Object.fromEntries(e) : e;
19
+ return Array.isArray(r) ? Object.fromEntries(r) : r;
24
20
  }
25
- function p(e, r, t, c) {
21
+ function d(r, e, t) {
26
22
  return {
27
- ...e ? { "x-inkeep-app-id": e } : {},
28
- ...r ? { Authorization: `Bearer ${r}` } : {},
29
- ...m(c),
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 x({
35
- appId: e,
36
- authToken: r,
37
- getCaptchaHeader: t,
38
- invalidateCaptcha: c,
39
- refreshSession: w
28
+ function j({
29
+ appId: r,
30
+ authToken: e,
31
+ refreshSession: t
40
32
  }) {
41
- const a = u(e);
33
+ const s = o(r);
34
+ s.current = r;
35
+ const a = o(e);
42
36
  a.current = e;
43
- const i = u(r);
44
- i.current = r;
45
- const o = u(t);
46
- o.current = t;
47
- const A = u(c);
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
- R = await n.clone().json();
43
+ i = await n.clone().json();
61
44
  } catch {
62
45
  return n;
63
46
  }
64
- const k = E(n.status, R);
65
- if (k === "pow") {
66
- A.current();
67
- const f = await o.current(), l = p(
68
- a.current,
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
- E as parseAuthError,
86
- x as useInkeepApiClient
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 a=require("react"),d=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"),l=require("./config-provider.cjs");function f(){const{baseSettings:s,aiChatSettings:c}=l.useInkeepConfig(),{shouldBypassCaptcha:t}=s,{baseUrl:n,apiKey:i,botProtectionLevel:r}=c,o=a.useRef(!1);return a.useEffect(()=>{if(o.current||t||i||!n)return;const e={checkLevel:r};try{d.initBotId({protect:[{path:"/run/auth/apps/*/anonymous-session",method:"POST",advancedOptions:e},{path:"/run/api/chat",method:"POST",advancedOptions:e},{path:"/run/v1/feedback",method:"POST",advancedOptions:e}]}),o.current=!0}catch(u){console.warn("[botid] initBotId failed",u)}},[n,i,t,r]),null}exports.BotIdInitializer=f;
@@ -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,29 @@
1
+ "use client";
2
+ import { useRef as u, useEffect as p } from "react";
3
+ import { initBotId as f } 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 h } from "./config-provider.js";
5
+ function I() {
6
+ const { baseSettings: a, aiChatSettings: s } = h(), { shouldBypassCaptcha: e } = a, { baseUrl: n, apiKey: o, botProtectionLevel: r } = s, i = u(!1);
7
+ return p(() => {
8
+ if (i.current || e || o || !n) return;
9
+ const t = { checkLevel: r };
10
+ try {
11
+ f({
12
+ protect: [
13
+ {
14
+ path: "/run/auth/apps/*/anonymous-session",
15
+ method: "POST",
16
+ advancedOptions: t
17
+ },
18
+ { path: "/run/api/chat", method: "POST", advancedOptions: t },
19
+ { path: "/run/v1/feedback", method: "POST", advancedOptions: t }
20
+ ]
21
+ }), i.current = !0;
22
+ } catch (c) {
23
+ console.warn("[botid] initBotId failed", c);
24
+ }
25
+ }, [n, o, e, r]), null;
26
+ }
27
+ export {
28
+ I as BotIdInitializer
29
+ };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("react/jsx-runtime"),e=require("react"),te=require("../components/embedded-chat/chat-provider.cjs"),se=require("./config-provider.cjs"),ne=require("../hooks/use-inkeep-api-client.cjs"),U=e.createContext(void 0),K=25;function re(t){const{stop:u,clear:f,conversationId:l,isStreaming:y,loadAndRestoreSession:R,authToken:s,refreshSession:Z,getCaptchaHeader:_,invalidateCaptcha:z}=te.useChat(),{aiChatSettings:B,baseSettings:J}=se.useInkeepConfig(),{baseUrl:S,appId:H,apiKey:Q}=B,a=!!J.getAuthToken,o=!Q&&!!H&&(!!s||a),{fetchWithAuth:I}=ne.useInkeepApiClient({appId:H,authToken:s,getCaptchaHeader:_,invalidateCaptcha:z,refreshSession:Z}),[v,b]=e.useState(!1),[P,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=P;const O=e.useRef(I);O.current=I;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 N=new Set(i.map(d=>d.id));return[...i,...p.filter(d=>!N.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 V=e.useCallback(()=>{!k&&w&&c(m+1)},[k,w,m,c]),X=e.useCallback(()=>{u(),f(),t!=="sidepane"&&b(!1)},[t,u,f]),Y=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:P,isLoading:k,hasMore:w,loadMore:V,startNewConversation:X,loadSession:Y}}const oe=({layout:t,children:u})=>{const f=re(t);return ee.jsx(U.Provider,{value:f,children:typeof u=="function"?u(f):u})},ie=()=>{const t=e.useContext(U);if(!t)throw new Error("useChatHistory must be used within a ChatHistoryProvider");return t};exports.ChatHistoryProvider=oe;exports.useChatHistory=ie;
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;