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

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"),h="[sentinel]",v="https://cdn.jsdelivr.net/npm/altcha@3.0.9/dist/main/altcha.min.js",w="sha384-SAvZpYmIwEwxkbER1dijvBKm10sobAn/28KXy+Z7/lGbsCshTPhYrFJ2kU7LKiFM",y=1e4,E=3e4;let f=null;function T(){if(typeof customElements>"u"||customElements.get("altcha-widget"))return Promise.resolve();if(f)return f;const u=r=>e=>{f=null,r(e)};return f=new Promise((r,e)=>{const t=u(e);if(document.querySelector(`script[src="${v}"]`)){customElements.whenDefined("altcha-widget").then(()=>r()).catch(t);return}const n=document.createElement("script");n.src=v,n.integrity=w,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(h,"failed to load widget script"),t(new Error("Failed to load altcha-widget script"))},document.head.appendChild(n)}),f}function P(u){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",u),e.setAttribute("auto","onload"),e.setAttribute("hidefooter","true"),e.setAttribute("hidelogo","true"),r.appendChild(e);let t=null,i,n="mounted",s=!1,l=!1,o=null;const m=()=>{s||(i=void 0,n="resetting",e.reset?.(),e.verify?.())},p=()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=null,s&&(s=!1,i=void 0,n="resetting",e.reset?.(),e.verify?.())},E)},g=c=>{const a=c.detail;a&&(n=a.state??n,a.state==="verified"&&a.payload&&(l=!0,i=a.payload,t&&(t(a.payload),t=null)),a.state==="error"&&(i=void 0,t&&(t(void 0),t=null),l||(s=!0,console.warn(h,"Sentinel unavailable, requests will proceed without bot protection"),p())))};return e.addEventListener("statechange",g),{getPayload:()=>{if(s)return Promise.resolve(void 0);if(i){const c=i;return i=void 0,m(),Promise.resolve(c)}return n==="verified"&&m(),new Promise(c=>{t=c,setTimeout(()=>{t===c&&(t=null,c(void 0))},y)})},startNextSolve:m,destroy:()=>{e.removeEventListener("statechange",g),o&&(clearTimeout(o),o=null),t=null,r.remove()}}}const S=({baseUrl:u,shouldBypassCaptcha:r=!1})=>{const e=d.useRef(null),t=d.useRef(null),i=d.useCallback(()=>e.current?Promise.resolve():(t.current||(t.current=T().then(()=>{if(!e.current){const l=`${u}/run/auth/sentinel/challenge`;e.current=P(l)}}).catch(l=>{console.error(h,"failed to mount widget",l),t.current=null})),t.current),[u]);d.useEffect(()=>{if(!r)return i(),()=>{e.current?.destroy(),e.current=null,t.current=null}},[r,i]);const n=d.useCallback(async()=>{if(r)return{};await i();const l=e.current;if(!l)return{};const o=await l.getPayload();return o?{"x-inkeep-challenge-solution":btoa(JSON.stringify({payload:o}))}:{}},[r,i]),s=d.useCallback(()=>{e.current?.startNextSolve()},[]);return{getCaptchaHeader:n,invalidate:s}};exports.useCaptcha=S;
@@ -1,15 +1,15 @@
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;
2
+ import { useRef as v, useCallback as m, useEffect as E } from "react";
3
+ const h = "[sentinel]", p = "https://cdn.jsdelivr.net/npm/altcha@3.0.9/dist/main/altcha.min.js", y = "sha384-SAvZpYmIwEwxkbER1dijvBKm10sobAn/28KXy+Z7/lGbsCshTPhYrFJ2kU7LKiFM", T = 1e4, P = 3e4;
4
4
  let d = null;
5
- function E() {
5
+ function A() {
6
6
  if (typeof customElements > "u" || customElements.get("altcha-widget")) return Promise.resolve();
7
7
  if (d) return d;
8
- const c = (r) => (e) => {
8
+ const u = (r) => (e) => {
9
9
  d = null, r(e);
10
10
  };
11
11
  return d = new Promise((r, e) => {
12
- const t = c(e);
12
+ const t = u(e);
13
13
  if (document.querySelector(
14
14
  `script[src="${p}"]`
15
15
  )) {
@@ -17,72 +17,76 @@ function E() {
17
17
  return;
18
18
  }
19
19
  const n = document.createElement("script");
20
- n.src = p, n.integrity = w, n.crossOrigin = "anonymous", n.type = "module", n.async = !0, n.onload = () => {
20
+ n.src = p, n.integrity = y, n.crossOrigin = "anonymous", n.type = "module", n.async = !0, n.onload = () => {
21
21
  customElements.whenDefined("altcha-widget").then(() => r()).catch(() => t(new Error("altcha-widget custom element never registered")));
22
22
  }, n.onerror = () => {
23
- console.error(m, "failed to load widget script"), t(new Error("Failed to load altcha-widget script"));
23
+ console.error(h, "failed to load widget script"), t(new Error("Failed to load altcha-widget script"));
24
24
  }, document.head.appendChild(n);
25
25
  }), d;
26
26
  }
27
- function P(c) {
27
+ function S(u) {
28
28
  const r = document.createElement("div");
29
29
  r.style.cssText = "position:fixed;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;pointer-events:none", document.body.appendChild(r);
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) => {
36
- 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,
31
+ e.setAttribute("challenge", u), e.setAttribute("auto", "onload"), e.setAttribute("hidefooter", "true"), e.setAttribute("hidelogo", "true"), r.appendChild(e);
32
+ let t = null, i, n = "mounted", s = !1, l = !1, o = null;
33
+ const f = () => {
34
+ s || (i = void 0, n = "resetting", e.reset?.(), e.verify?.());
35
+ }, w = () => {
36
+ o && clearTimeout(o), o = setTimeout(() => {
37
+ o = null, s && (s = !1, i = void 0, n = "resetting", e.reset?.(), e.verify?.());
38
+ }, P);
39
+ }, g = (c) => {
40
+ const a = c.detail;
41
+ a && (n = a.state ?? n, a.state === "verified" && a.payload && (l = !0, i = a.payload, t && (t(a.payload), t = null)), a.state === "error" && (i = void 0, t && (t(void 0), t = null), l || (s = !0, console.warn(
42
+ h,
39
43
  "Sentinel unavailable, requests will proceed without bot protection"
40
- ))));
44
+ ), w())));
41
45
  };
42
- return e.addEventListener("statechange", h), { getPayload: () => {
43
- if (u) return Promise.resolve(void 0);
46
+ return e.addEventListener("statechange", g), { getPayload: () => {
47
+ if (s) return Promise.resolve(void 0);
44
48
  if (i) {
45
- const l = i;
46
- return i = void 0, a(), Promise.resolve(l);
49
+ const c = i;
50
+ return i = void 0, f(), Promise.resolve(c);
47
51
  }
48
- return n === "verified" && a(), new Promise((l) => {
49
- t = l, setTimeout(() => {
50
- t === l && (t = null, l(void 0));
51
- }, y);
52
+ return n === "verified" && f(), new Promise((c) => {
53
+ t = c, setTimeout(() => {
54
+ t === c && (t = null, c(void 0));
55
+ }, T);
52
56
  });
53
- }, startNextSolve: a, destroy: () => {
54
- e.removeEventListener("statechange", h), t = null, r.remove();
57
+ }, startNextSolve: f, destroy: () => {
58
+ e.removeEventListener("statechange", g), o && (clearTimeout(o), o = null), t = null, r.remove();
55
59
  } };
56
60
  }
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(() => {
61
+ const x = ({ baseUrl: u, shouldBypassCaptcha: r = !1 }) => {
62
+ const e = v(null), t = v(null), i = m(() => e.current ? Promise.resolve() : (t.current || (t.current = A().then(() => {
59
63
  if (!e.current) {
60
- const o = `${c}/run/auth/sentinel/challenge`;
61
- e.current = P(o);
64
+ const l = `${u}/run/auth/sentinel/challenge`;
65
+ e.current = S(l);
62
66
  }
63
- }).catch((o) => {
64
- console.error(m, "failed to mount widget", o), t.current = null;
65
- })), t.current), [c]);
66
- v(() => {
67
+ }).catch((l) => {
68
+ console.error(h, "failed to mount widget", l), t.current = null;
69
+ })), t.current), [u]);
70
+ E(() => {
67
71
  if (!r)
68
72
  return i(), () => {
69
73
  e.current?.destroy(), e.current = null, t.current = null;
70
74
  };
71
75
  }, [r, i]);
72
- const n = f(async () => {
76
+ const n = m(async () => {
73
77
  if (r) return {};
74
78
  await i();
75
- const o = e.current;
76
- if (!o) return {};
77
- const a = await o.getPayload();
78
- return a ? {
79
- "x-inkeep-challenge-solution": btoa(JSON.stringify({ payload: a }))
79
+ const l = e.current;
80
+ if (!l) return {};
81
+ const o = await l.getPayload();
82
+ return o ? {
83
+ "x-inkeep-challenge-solution": btoa(JSON.stringify({ payload: o }))
80
84
  } : {};
81
- }, [r, i]), u = f(() => {
85
+ }, [r, i]), s = m(() => {
82
86
  e.current?.startNextSolve();
83
87
  }, []);
84
- return { getCaptchaHeader: n, invalidate: u };
88
+ return { getCaptchaHeader: n, invalidate: s };
85
89
  };
86
90
  export {
87
- b as useCaptcha
91
+ x as useCaptcha
88
92
  };
@@ -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 k(e,r){if(e===400&&typeof r=="object"&&r!==null){const t=(r.detail??"").toLowerCase();if(t.includes("challenge")||t.includes("bot protection")||t.includes("proof-of-work"))return"captcha"}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,c)=>{r[c]=t}),r}return Array.isArray(e)?Object.fromEntries(e):e}function A(e,r,t,c){return{...e?{"x-inkeep-app-id":e}:{},...r?{Authorization:`Bearer ${r}`}:{},...E(c),...t}}function C({appId:e,authToken:r,getCaptchaHeader:t,invalidateCaptcha:c,refreshSession:f}){const o=u.useRef(e);o.current=e;const i=u.useRef(r);i.current=r;const w=u.useRef(t);w.current=t;const l=u.useRef(c);l.current=c;const a=u.useRef(f);return a.current=f,{fetchWithAuth:u.useCallback(async(d,s)=>{const j=A(o.current,i.current,{},s?.headers),n=await fetch(d,{...s,headers:j});if(n.status!==400&&n.status!==401)return n;let h;try{h=await n.clone().json()}catch{return n}const p=k(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 y=A(o.current,R,{},s?.headers);return fetch(d,{...s,headers:y})}return n},[])}}exports.parseAuthError=k;exports.useInkeepApiClient=C;
@@ -15,10 +15,13 @@ 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 (Sentinel) failure
19
+ * - 401 + detail matching JWT/bearer messages → session token failure
20
+ *
21
+ * Legacy "proof-of-work" wording is still matched so older server versions are handled
22
+ * gracefully during the rolling deploy window.
20
23
  */
21
- export declare function parseAuthError(status: number, body: unknown): 'pow' | 'session' | null;
24
+ export declare function parseAuthError(status: number, body: unknown): 'captcha' | 'session' | null;
22
25
  /**
23
26
  * Returns a stable `fetchWithAuth` function that automatically:
24
27
  * - Injects auth headers (x-inkeep-app-id, Authorization, x-inkeep-challenge-solution)
@@ -3,7 +3,8 @@ import { useRef as s, useCallback as E } from "react";
3
3
  function m(e, r) {
4
4
  if (e === 400 && typeof r == "object" && r !== null) {
5
5
  const t = (r.detail ?? "").toLowerCase();
6
- if (t.includes("challenge") || t.includes("proof-of-work")) return "pow";
6
+ if (t.includes("challenge") || t.includes("bot protection") || t.includes("proof-of-work"))
7
+ return "captcha";
7
8
  }
8
9
  if (e === 401 && typeof r == "object" && r !== null) {
9
10
  const t = r.detail ?? "";
@@ -22,7 +23,7 @@ function y(e) {
22
23
  }
23
24
  return Array.isArray(e) ? Object.fromEntries(e) : e;
24
25
  }
25
- function A(e, r, t, c) {
26
+ function R(e, r, t, c) {
26
27
  return {
27
28
  ...e ? { "x-inkeep-app-id": e } : {},
28
29
  ...r ? { Authorization: `Bearer ${r}` } : {},
@@ -42,28 +43,28 @@ function H({
42
43
  o.current = e;
43
44
  const i = s(r);
44
45
  i.current = r;
45
- const R = s(t);
46
- R.current = t;
46
+ const w = s(t);
47
+ w.current = t;
47
48
  const l = s(c);
48
49
  l.current = c;
49
50
  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 });
51
+ return a.current = f, { fetchWithAuth: E(async (h, u) => {
52
+ const k = R(o.current, i.current, {}, u?.headers), n = await fetch(h, { ...u, headers: k });
52
53
  if (n.status !== 400 && n.status !== 401) return n;
53
- let h;
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 = m(n.status, d);
61
+ if (p === "captcha")
61
62
  return l.current(), n;
62
63
  if (p === "session" && a.current) {
63
- const w = await a.current();
64
- if (!w) return n;
65
- const j = A(o.current, w, {}, u?.headers);
66
- return fetch(d, { ...u, headers: j });
64
+ const A = await a.current();
65
+ if (!A) return n;
66
+ const j = R(o.current, A, {}, u?.headers);
67
+ return fetch(h, { ...u, headers: j });
67
68
  }
68
69
  return n;
69
70
  }, []) };
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-20260528142533",
4
4
  "description": "",
5
5
  "homepage": "",
6
6
  "repository": {