@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.
@@ -1,96 +1,101 @@
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 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 Y = ({
10
+ const G = ({
11
11
  baseUrl: n,
12
- appId: e,
13
- getCaptchaHeader: D,
14
- invalidateCaptcha: F,
15
- optOutAllAnalytics: k,
16
- enabled: t = !0
12
+ appId: t,
13
+ getCaptchaHeader: k,
14
+ invalidateCaptcha: L,
15
+ optOutAllAnalytics: y,
16
+ enabled: e = !0
17
17
  }) => {
18
- const L = t && e && !k ? `inkeep_session_${e}` : null, [c, h] = B(L), S = o(t);
18
+ const B = e && t && !y ? `inkeep_session_${t}` : null, [u, h] = X(B), w = o(e);
19
19
  l(() => {
20
- const r = S.current;
21
- if (S.current = t, r && !t && e && !k) {
20
+ const r = w.current;
21
+ if (w.current = e, r && !e && t && !y) {
22
22
  try {
23
- localStorage.removeItem(`inkeep_session_${e}`);
23
+ localStorage.removeItem(`inkeep_session_${t}`);
24
24
  } catch {
25
25
  }
26
26
  h(null);
27
27
  }
28
- }, [t, e, k, h]);
29
- const { fetchWithAuth: T } = P({
30
- appId: e,
28
+ }, [e, t, y, h]);
29
+ const { fetchWithAuth: x } = z({
30
+ appId: t,
31
31
  authToken: void 0,
32
- getCaptchaHeader: D ?? z,
33
- invalidateCaptcha: F ?? X
34
- }), y = o(n);
35
- y.current = n;
36
- const A = o(e);
37
- 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);
45
- M.current = t;
46
- const s = g(async (r) => {
47
- if (!M.current || !y.current || !A.current) return null;
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 i = `${y.current}/run/auth/apps/${A.current}/anonymous-session`, m = (async () => {
52
+ const c = `${A.current}/run/auth/apps/${R.current}/anonymous-session`, m = (async () => {
51
53
  try {
52
- const u = { "Content-Type": "application/json" }, _ = f.current?.token;
53
- _ && (u.Authorization = `Bearer ${_}`);
54
- const v = await x.current(i, {
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: u,
60
+ headers: i,
57
61
  signal: r
58
62
  });
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;
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
- }, []), C = o(!1);
74
+ }, []), $ = o(!1);
70
75
  l(() => {
71
- if (!t || !n || !e) return;
72
- const r = !C.current;
73
- if (C.current = !0, !r && f.current && !$(f.current) || a.current) return;
74
- const i = new AbortController();
75
- 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();
79
- if (R <= 0) return;
80
- const m = setTimeout(() => s(), Math.min(R, W));
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, e, t, c?.expiresAt, s]), l(() => {
83
- if (!t || !n || !e) return;
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 i = f.current;
87
- (!i || $(i)) && s();
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, e, t, s]);
91
- const j = g(() => s(), [s]);
92
- return { sessionToken: c?.token ?? null, refreshSession: j };
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
- Y as useAnonymousSession
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 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 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 "proof-of-work" PoW failure
19
- * - 401 + detail matching JWT/bearer messages → session token failure
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): 'pow' | 'session' | null;
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 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";
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 (e === 401 && typeof r == "object" && r !== null) {
9
- const t = r.detail ?? "";
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(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;
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(e) ? Object.fromEntries(e) : e;
24
+ return Array.isArray(r) ? Object.fromEntries(r) : r;
24
25
  }
25
- function p(e, r, t, c) {
26
+ function A(r, e, t, c) {
26
27
  return {
27
- ...e ? { "x-inkeep-app-id": e } : {},
28
- ...r ? { Authorization: `Bearer ${r}` } : {},
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 x({
35
- appId: e,
36
- authToken: r,
35
+ function W({
36
+ appId: r,
37
+ authToken: e,
37
38
  getCaptchaHeader: t,
38
39
  invalidateCaptcha: c,
39
- refreshSession: w
40
+ refreshSession: i
40
41
  }) {
41
- const a = u(e);
42
- 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;
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
- R = await n.clone().json();
56
+ d = await n.clone().json();
61
57
  } catch {
62
58
  return n;
63
59
  }
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 });
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
- x as useInkeepApiClient
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.16.4",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;
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.16.4", i = d(
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 S=require("react/jsx-runtime"),d=require("react"),T=require("./config-provider.cjs"),O=require("../components/modal/modal-provider.cjs"),m=require("./chat-bubble-provider.cjs"),x=require("./sidebar-chat-provider.cjs"),B=require("../hooks/use-auth-token.cjs"),R=require("../components/embedded-chat/use-captcha.cjs"),w=require("../hooks/use-anonymous-session.cjs"),l=d.createContext(void 0),I=({children:e})=>{const{baseSettings:n,aiChatSettings:p}=T.useInkeepConfig(),{shouldBypassCaptcha:C,privacyPreferences:A}=n,{baseUrl:i,appId:b,apiKey:s}=p,v=O.useModal(),f=m.useOptionalChatBubble(),g=x.useOptionalSidebarChat(),k=v?.isOpen??f?.isOpen??g?.isOpen??!0,{authToken:o,isLoading:a,refreshToken:q}=B.useAuthToken(),y=!!n.getAuthToken,t=!!o,{getCaptchaHeader:r,invalidate:u}=R.useCaptcha({baseUrl:i,shouldBypassCaptcha:C||!!s,shouldMakeInitialRequest:k}),{sessionToken:c,refreshSession:h}=w.useAnonymousSession({baseUrl:i,appId:b,getCaptchaHeader:r,invalidateCaptcha:u,optOutAllAnalytics:A?.optOutAllAnalytics,enabled:!t&&!a}),P={authToken:o,isAuthenticated:t,isAuthLoading:a,isAuthConfigured:y,refreshAuthToken:q,sessionToken:c,refreshSession:h,getCaptchaHeader:r,invalidateCaptcha:u,effectiveAuthToken:s??(t?o:c),applicableRefreshSession:s||t?void 0:h};return S.jsx(l.Provider,{value:P,children:e})},j=()=>{const e=d.useContext(l);if(!e)throw new Error("useChatAuth must be used within a ChatAuthProvider");return e};exports.ChatAuthProvider=I;exports.useChatAuth=j;
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 T } from "react/jsx-runtime";
3
- import { useContext as y, createContext as S } from "react";
4
- import { useInkeepConfig as x } from "./config-provider.js";
5
- import { useModal as w } from "../components/modal/modal-provider.js";
6
- import { useOptionalChatBubble as B } from "./chat-bubble-provider.js";
7
- import { useOptionalSidebarChat as I } from "./sidebar-chat-provider.js";
8
- import { useAuthToken as P } from "../hooks/use-auth-token.js";
9
- import { useCaptcha as R } from "../components/embedded-chat/use-captcha.js";
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
- shouldBypassCaptcha: d || !!o,
15
- shouldMakeInitialRequest: v
16
- }), { sessionToken: h, refreshSession: c } = L({
11
+ appId: a,
12
+ shouldBypassCaptcha: A || !!o
13
+ }), { sessionToken: c, refreshSession: p } = S({
17
14
  baseUrl: i,
18
- appId: m,
19
- getCaptchaHeader: r,
15
+ appId: a,
16
+ getCaptchaHeader: h,
20
17
  invalidateCaptcha: u,
21
- optOutAllAnalytics: f?.optOutAllAnalytics,
22
- enabled: !e && !a
23
- }), O = {
18
+ optOutAllAnalytics: d?.optOutAllAnalytics,
19
+ enabled: !e && !r
20
+ }), v = {
24
21
  authToken: s,
25
22
  isAuthenticated: e,
26
- isAuthLoading: a,
27
- isAuthConfigured: g,
28
- refreshAuthToken: k,
29
- sessionToken: h,
30
- refreshSession: c,
31
- getCaptchaHeader: r,
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 : h),
34
- applicableRefreshSession: o || e ? void 0 : c
30
+ effectiveAuthToken: o ?? (e ? s : c),
31
+ applicableRefreshSession: o || e ? void 0 : p
35
32
  };
36
- return /* @__PURE__ */ T(p.Provider, { value: O, children: t });
37
- }, N = () => {
38
- const t = y(p);
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
- J as ChatAuthProvider,
45
- N as useChatAuth
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.16.4",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;
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.16.4", a = x(
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
@@ -50,6 +50,7 @@ export interface UserMessageSubmittedEvent {
50
50
  eventName: 'user_message_submitted';
51
51
  properties: {
52
52
  conversationId?: string;
53
+ messageId?: string;
53
54
  };
54
55
  }
55
56
  export interface UserEscalationIndicatedEvent {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-ui",
3
- "version": "0.16.4",
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-lib": "^1.2.0",
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",