@inkeep/agents-ui 0.0.0-dev-20260528172136 → 0.0.0-dev-20260529062200
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.cjs +2 -2
- package/dist/primitives/components/embedded-chat/chat-error-helpers.js +3 -3
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-captcha.js +62 -76
- package/package.json +2 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../hooks/use-inkeep-api-client.cjs");function
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../hooks/use-inkeep-api-client.cjs");function s(t){const e=Number(t.code)||Number(t.statusCode);if(e&&!Number.isNaN(e))return e;try{const r=Number(JSON.parse(t.message??"").status);return r&&!Number.isNaN(r)?r:null}catch{return null}}function o(t){const e=s(t),r=n.parseAuthError(e??0,{detail:t.message??""});return r!==null?r:e===401?"session":e===403?"captcha":null}function a(t){const e=s(t);return e===400||e===429}const u=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,i="Please try again.",E="You're sending requests too quickly. Please wait a moment and try again.",c=8e3;exports.DEFAULT_ERROR_MESSAGE=u;exports.RATE_LIMIT_MESSAGE=E;exports.RECOVERABLE_FALLBACK_MESSAGE=i;exports.RECOVERABLE_NOTIFICATION_DURATION_MS=c;exports.isRecoverableError=a;exports.resolveHttpStatusCode=s;exports.resolveStreamingAuthError=o;
|
|
@@ -10,9 +10,9 @@ function n(t) {
|
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function o(t) {
|
|
14
14
|
const e = n(t), s = r(e ?? 0, { detail: t.message ?? "" });
|
|
15
|
-
return s !== null ? s : e === 401 ? "session" : null;
|
|
15
|
+
return s !== null ? s : e === 401 ? "session" : e === 403 ? "captcha" : null;
|
|
16
16
|
}
|
|
17
17
|
function u(t) {
|
|
18
18
|
const e = n(t);
|
|
@@ -28,5 +28,5 @@ export {
|
|
|
28
28
|
m as RECOVERABLE_NOTIFICATION_DURATION_MS,
|
|
29
29
|
u as isRecoverableError,
|
|
30
30
|
n as resolveHttpStatusCode,
|
|
31
|
-
|
|
31
|
+
o as resolveStreamingAuthError
|
|
32
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty
|
|
1
|
+
"use client";"use strict";var P=Object.create;var p=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var L=(r,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of S(n))!_.call(r,t)&&t!==e&&p(r,t,{get:()=>n[t],enumerable:!(o=A(n,t))||o.enumerable});return r};var O=(r,n,e)=>(e=r!=null?P(b(r)):{},L(n||!r||!r.__esModule?p(e,"default",{value:r,enumerable:!0}):e,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),y="[sentinel]",x=45e3,C=3e4,N=3,M=250;let v=null;function Y(){return typeof customElements>"u"||customElements.get("altcha-widget")?Promise.resolve():v||(v=import("altcha").then(()=>customElements.whenDefined("altcha-widget")).then(()=>{}).catch(r=>{throw v=null,console.error(y,"failed to load altcha widget module",r),r instanceof Error?r:new Error("Failed to load altcha widget module")}),v)}function k(r){const n=document.createElement("div");n.style.cssText="position:fixed;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;pointer-events:none",document.body.appendChild(n);const e=document.createElement("altcha-widget");e.setAttribute("challenge",r),e.setAttribute("auto","onload"),e.setAttribute("hidefooter","true"),e.setAttribute("hidelogo","true"),n.appendChild(e);let o=[],t,u="mounted",s=!1,g=!1,c=null,i=null,d=0,m=!1;const h=a=>{const l=o;o=[];for(const T of l)T(a)},E=()=>{s||m||(t=void 0,u="resetting",e.reset?.(),e.verify?.())},w=()=>{c&&clearTimeout(c),c=setTimeout(()=>{c=null,!(!s||m)&&(s=!1,t=void 0,u="resetting",e.reset?.(),e.verify?.())},C)},R=a=>{const l=a.detail;l&&(u=l.state??u,l.state==="verified"&&l.payload&&(g=!0,d=0,t=l.payload,h(l.payload)),l.state==="error"&&(t=void 0,d++,!g&&d>=N?(h(void 0),s=!0,console.warn(y,`Sentinel unavailable after ${d} consecutive errors, requests will proceed without bot protection`),w()):(i&&clearTimeout(i),i=setTimeout(()=>{i=null,!(m||s)&&(u="resetting",e.reset?.(),e.verify?.())},M))))};return e.addEventListener("statechange",R),{getPayload:()=>{if(m||s)return Promise.resolve(void 0);if(t){const a=t;return t=void 0,E(),Promise.resolve(a)}return u==="verified"&&E(),new Promise(a=>{o.push(a),setTimeout(()=>{const l=o.indexOf(a);l!==-1&&(o.splice(l,1),a(void 0))},x)})},startNextSolve:E,destroy:()=>{m=!0,e.removeEventListener("statechange",R),c&&(clearTimeout(c),c=null),i&&(clearTimeout(i),i=null),h(void 0),n.remove()}}}const D=({baseUrl:r,appId:n,shouldBypassCaptcha:e=!1})=>{const o=f.useRef(null),t=f.useRef(null),u=f.useRef(!1),s=f.useCallback(()=>o.current?Promise.resolve():t.current?t.current:n?(t.current=Y().then(()=>{if(!u.current&&!o.current){const i=`${r}/run/auth/sentinel/challenge?appId=${encodeURIComponent(n)}`;o.current=k(i)}}).catch(i=>{console.error(y,"failed to mount widget",i),t.current=null}),t.current):Promise.resolve(),[r,n]);f.useEffect(()=>{if(u.current=!1,!e)return s(),()=>{u.current=!0,o.current?.destroy(),o.current=null,t.current=null}},[e,s]);const g=f.useCallback(async()=>{if(e)return{};await s();const i=o.current;if(!i)return{};const d=await i.getPayload();return d?{"x-inkeep-challenge-solution":btoa(JSON.stringify({payload:d}))}:{}},[e,s]),c=f.useCallback(()=>{o.current?.startNextSolve()},[]);return{getCaptchaHeader:g,invalidate:c}};exports.useCaptcha=D;
|
|
@@ -1,97 +1,83 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
2
|
+
import { useRef as E, useCallback as p, useEffect as P } from "react";
|
|
3
|
+
const y = "[sentinel]", A = 45e3, _ = 3e4, S = 3, L = 250;
|
|
4
|
+
let m = null;
|
|
5
5
|
function x() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
return f = new Promise((o, e) => {
|
|
12
|
-
const r = u(e);
|
|
13
|
-
if (document.querySelector(
|
|
14
|
-
`script[src="${y}"]`
|
|
15
|
-
)) {
|
|
16
|
-
customElements.whenDefined("altcha-widget").then(() => o()).catch(r);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
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(() => o()).catch(() => r(new Error("altcha-widget custom element never registered")));
|
|
22
|
-
}, t.onerror = () => {
|
|
23
|
-
console.error(p, "failed to load widget script"), r(new Error("Failed to load altcha-widget script"));
|
|
24
|
-
}, document.head.appendChild(t);
|
|
25
|
-
}), f;
|
|
6
|
+
return typeof customElements > "u" || customElements.get("altcha-widget") ? Promise.resolve() : m || (m = import("altcha").then(() => customElements.whenDefined("altcha-widget")).then(() => {
|
|
7
|
+
}).catch((c) => {
|
|
8
|
+
throw m = null, console.error(y, "failed to load altcha widget module", c), c instanceof Error ? c : new Error("Failed to load altcha widget module");
|
|
9
|
+
}), m);
|
|
26
10
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
|
|
11
|
+
function O(c) {
|
|
12
|
+
const a = document.createElement("div");
|
|
13
|
+
a.style.cssText = "position:fixed;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;pointer-events:none", document.body.appendChild(a);
|
|
30
14
|
const e = document.createElement("altcha-widget");
|
|
31
|
-
e.setAttribute("challenge",
|
|
32
|
-
let
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
for (const
|
|
15
|
+
e.setAttribute("challenge", c), e.setAttribute("auto", "onload"), e.setAttribute("hidefooter", "true"), e.setAttribute("hidelogo", "true"), a.appendChild(e);
|
|
16
|
+
let n = [], t, l = "mounted", i = !1, v = !1, s = null, r = null, d = 0, f = !1;
|
|
17
|
+
const g = (u) => {
|
|
18
|
+
const o = n;
|
|
19
|
+
n = [];
|
|
20
|
+
for (const T of o) T(u);
|
|
37
21
|
}, h = () => {
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
),
|
|
22
|
+
i || f || (t = void 0, l = "resetting", e.reset?.(), e.verify?.());
|
|
23
|
+
}, w = () => {
|
|
24
|
+
s && clearTimeout(s), s = setTimeout(() => {
|
|
25
|
+
s = null, !(!i || f) && (i = !1, t = void 0, l = "resetting", e.reset?.(), e.verify?.());
|
|
26
|
+
}, _);
|
|
27
|
+
}, R = (u) => {
|
|
28
|
+
const o = u.detail;
|
|
29
|
+
o && (l = o.state ?? l, o.state === "verified" && o.payload && (v = !0, d = 0, t = o.payload, g(o.payload)), o.state === "error" && (t = void 0, d++, !v && d >= S ? (g(void 0), i = !0, console.warn(
|
|
30
|
+
y,
|
|
31
|
+
`Sentinel unavailable after ${d} consecutive errors, requests will proceed without bot protection`
|
|
32
|
+
), w()) : (r && clearTimeout(r), r = setTimeout(() => {
|
|
33
|
+
r = null, !(f || i) && (l = "resetting", e.reset?.(), e.verify?.());
|
|
34
|
+
}, L))));
|
|
49
35
|
};
|
|
50
|
-
return e.addEventListener("statechange",
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
return
|
|
36
|
+
return e.addEventListener("statechange", R), { getPayload: () => {
|
|
37
|
+
if (f || i) return Promise.resolve(void 0);
|
|
38
|
+
if (t) {
|
|
39
|
+
const u = t;
|
|
40
|
+
return t = void 0, h(), Promise.resolve(u);
|
|
55
41
|
}
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
},
|
|
42
|
+
return l === "verified" && h(), new Promise((u) => {
|
|
43
|
+
n.push(u), setTimeout(() => {
|
|
44
|
+
const o = n.indexOf(u);
|
|
45
|
+
o !== -1 && (n.splice(o, 1), u(void 0));
|
|
46
|
+
}, A);
|
|
61
47
|
});
|
|
62
48
|
}, startNextSolve: h, destroy: () => {
|
|
63
|
-
|
|
49
|
+
f = !0, e.removeEventListener("statechange", R), s && (clearTimeout(s), s = null), r && (clearTimeout(r), r = null), g(void 0), a.remove();
|
|
64
50
|
} };
|
|
65
51
|
}
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
69
|
-
const
|
|
70
|
-
|
|
52
|
+
const Y = ({ baseUrl: c, appId: a, shouldBypassCaptcha: e = !1 }) => {
|
|
53
|
+
const n = E(null), t = E(null), l = E(!1), i = p(() => n.current ? Promise.resolve() : t.current ? t.current : a ? (t.current = x().then(() => {
|
|
54
|
+
if (!l.current && !n.current) {
|
|
55
|
+
const r = `${c}/run/auth/sentinel/challenge?appId=${encodeURIComponent(a)}`;
|
|
56
|
+
n.current = O(r);
|
|
71
57
|
}
|
|
72
|
-
}).catch((
|
|
73
|
-
console.error(
|
|
74
|
-
}),
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
78
|
-
|
|
58
|
+
}).catch((r) => {
|
|
59
|
+
console.error(y, "failed to mount widget", r), t.current = null;
|
|
60
|
+
}), t.current) : Promise.resolve(), [c, a]);
|
|
61
|
+
P(() => {
|
|
62
|
+
if (l.current = !1, !e)
|
|
63
|
+
return i(), () => {
|
|
64
|
+
l.current = !0, n.current?.destroy(), n.current = null, t.current = null;
|
|
79
65
|
};
|
|
80
|
-
}, [e,
|
|
81
|
-
const
|
|
66
|
+
}, [e, i]);
|
|
67
|
+
const v = p(async () => {
|
|
82
68
|
if (e) return {};
|
|
83
|
-
await
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
86
|
-
const d = await
|
|
69
|
+
await i();
|
|
70
|
+
const r = n.current;
|
|
71
|
+
if (!r) return {};
|
|
72
|
+
const d = await r.getPayload();
|
|
87
73
|
return d ? {
|
|
88
74
|
"x-inkeep-challenge-solution": btoa(JSON.stringify({ payload: d }))
|
|
89
75
|
} : {};
|
|
90
|
-
}, [e,
|
|
91
|
-
|
|
76
|
+
}, [e, i]), s = p(() => {
|
|
77
|
+
n.current?.startNextSolve();
|
|
92
78
|
}, []);
|
|
93
|
-
return { getCaptchaHeader:
|
|
79
|
+
return { getCaptchaHeader: v, invalidate: s };
|
|
94
80
|
};
|
|
95
81
|
export {
|
|
96
|
-
|
|
82
|
+
Y as useCaptcha
|
|
97
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260529062200",
|
|
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
|
|
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",
|