@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.
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +3 -2
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-captcha.js +48 -44
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +6 -3
- package/dist/primitives/hooks/use-inkeep-api-client.js +15 -14
- package/package.json +1 -1
|
@@ -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
|
|
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): '
|
|
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
|
|
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
|
|
3
|
-
const
|
|
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
|
|
5
|
+
function A() {
|
|
6
6
|
if (typeof customElements > "u" || customElements.get("altcha-widget")) return Promise.resolve();
|
|
7
7
|
if (d) return d;
|
|
8
|
-
const
|
|
8
|
+
const u = (r) => (e) => {
|
|
9
9
|
d = null, r(e);
|
|
10
10
|
};
|
|
11
11
|
return d = new Promise((r, e) => {
|
|
12
|
-
const t =
|
|
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 =
|
|
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(
|
|
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
|
|
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",
|
|
32
|
-
let t = null, i, n = "mounted",
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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",
|
|
43
|
-
if (
|
|
46
|
+
return e.addEventListener("statechange", g), { getPayload: () => {
|
|
47
|
+
if (s) return Promise.resolve(void 0);
|
|
44
48
|
if (i) {
|
|
45
|
-
const
|
|
46
|
-
return i = void 0,
|
|
49
|
+
const c = i;
|
|
50
|
+
return i = void 0, f(), Promise.resolve(c);
|
|
47
51
|
}
|
|
48
|
-
return n === "verified" &&
|
|
49
|
-
t =
|
|
50
|
-
t ===
|
|
51
|
-
},
|
|
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:
|
|
54
|
-
e.removeEventListener("statechange",
|
|
57
|
+
}, startNextSolve: f, destroy: () => {
|
|
58
|
+
e.removeEventListener("statechange", g), o && (clearTimeout(o), o = null), t = null, r.remove();
|
|
55
59
|
} };
|
|
56
60
|
}
|
|
57
|
-
const
|
|
58
|
-
const e =
|
|
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
|
|
61
|
-
e.current =
|
|
64
|
+
const l = `${u}/run/auth/sentinel/challenge`;
|
|
65
|
+
e.current = S(l);
|
|
62
66
|
}
|
|
63
|
-
}).catch((
|
|
64
|
-
console.error(
|
|
65
|
-
})), t.current), [
|
|
66
|
-
|
|
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 =
|
|
76
|
+
const n = m(async () => {
|
|
73
77
|
if (r) return {};
|
|
74
78
|
await i();
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
77
|
-
const
|
|
78
|
-
return
|
|
79
|
-
"x-inkeep-challenge-solution": btoa(JSON.stringify({ payload:
|
|
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]),
|
|
85
|
+
}, [r, i]), s = m(() => {
|
|
82
86
|
e.current?.startNextSolve();
|
|
83
87
|
}, []);
|
|
84
|
-
return { getCaptchaHeader: n, invalidate:
|
|
88
|
+
return { getCaptchaHeader: n, invalidate: s };
|
|
85
89
|
};
|
|
86
90
|
export {
|
|
87
|
-
|
|
91
|
+
x as useCaptcha
|
|
88
92
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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 "
|
|
19
|
-
* - 401 + detail matching JWT/bearer messages
|
|
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): '
|
|
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"))
|
|
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
|
|
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
|
|
46
|
-
|
|
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 (
|
|
51
|
-
const 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
|
|
54
|
+
let d;
|
|
54
55
|
try {
|
|
55
|
-
|
|
56
|
+
d = await n.clone().json();
|
|
56
57
|
} catch {
|
|
57
58
|
return n;
|
|
58
59
|
}
|
|
59
|
-
const p = m(n.status,
|
|
60
|
-
if (p === "
|
|
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
|
|
64
|
-
if (!
|
|
65
|
-
const j =
|
|
66
|
-
return fetch(
|
|
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
|
}, []) };
|