@inkeep/agents-ui 0.0.0-dev-20260528131439 → 0.0.0-dev-20260528153706

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