@inkeep/agents-ui 0.0.0-dev-20260514122955 → 0.0.0-dev-20260528131439
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/use-captcha.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +1 -22
- package/dist/primitives/components/embedded-chat/use-captcha.js +81 -60
- package/dist/primitives/components/embedded-chat.d.ts +1 -1
- package/dist/primitives/hooks/use-anonymous-session.cjs +1 -1
- package/dist/primitives/hooks/use-anonymous-session.js +70 -65
- package/dist/primitives/hooks/use-events-api.cjs +1 -1
- package/dist/primitives/hooks/use-events-api.d.ts +3 -1
- package/dist/primitives/hooks/use-events-api.js +30 -29
- package/dist/primitives/hooks/use-feedback-api.cjs +1 -1
- package/dist/primitives/hooks/use-feedback-api.d.ts +3 -1
- package/dist/primitives/hooks/use-feedback-api.js +27 -26
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
- package/dist/primitives/hooks/use-inkeep-api-client.js +29 -42
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-auth-provider.cjs +1 -1
- package/dist/primitives/providers/chat-auth-provider.js +24 -28
- package/dist/primitives/providers/chat-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +33 -33
- package/dist/primitives/providers/feedback-provider.cjs +1 -1
- package/dist/primitives/providers/feedback-provider.js +19 -18
- package/package.json +1 -1
|
@@ -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"),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,29 +1,8 @@
|
|
|
1
|
-
import { Payload } from 'altcha-lib/types';
|
|
2
1
|
interface UseCaptchaOptions {
|
|
3
2
|
baseUrl: string;
|
|
4
3
|
shouldBypassCaptcha?: boolean;
|
|
5
|
-
shouldMakeInitialRequest?: boolean;
|
|
6
4
|
}
|
|
7
|
-
|
|
8
|
-
payload: Payload;
|
|
9
|
-
expiresAt: number | null;
|
|
10
|
-
}
|
|
11
|
-
export declare const fetchAndSolveChallenge: (fetchUrl: string) => Promise<SolvedEntry | undefined>;
|
|
12
|
-
/**
|
|
13
|
-
* Manages the PoW captcha lifecycle for /run/* API requests.
|
|
14
|
-
*
|
|
15
|
-
* - getCaptchaHeader(): atomically consumes the current pre-fetched challenge,
|
|
16
|
-
* immediately kicks off the next fetch so a fresh solution is always warm, and
|
|
17
|
-
* returns the ready-to-use `{ 'x-inkeep-challenge-solution': '...' }` header
|
|
18
|
-
* (or {} when bypassing or on failure). Checks token expiry and falls back to
|
|
19
|
-
* the already-started pre-fetch if the resolved token is stale.
|
|
20
|
-
*
|
|
21
|
-
* - invalidate(): discards any in-flight solution and starts a fresh fetch.
|
|
22
|
-
* Call this on request errors to recover from a rejected/stale challenge.
|
|
23
|
-
*
|
|
24
|
-
* All hooks are called unconditionally — bypass logic lives inside callbacks.
|
|
25
|
-
*/
|
|
26
|
-
export declare const useCaptcha: ({ baseUrl, shouldBypassCaptcha, shouldMakeInitialRequest, }: UseCaptchaOptions) => {
|
|
5
|
+
export declare const useCaptcha: ({ baseUrl, shouldBypassCaptcha }: UseCaptchaOptions) => {
|
|
27
6
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
28
7
|
invalidate: () => void;
|
|
29
8
|
};
|
|
@@ -1,67 +1,88 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function E(
|
|
6
|
-
|
|
7
|
-
|
|
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() {
|
|
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);
|
|
10
|
+
};
|
|
11
|
+
return d = new Promise((r, e) => {
|
|
12
|
+
const t = c(e);
|
|
13
|
+
if (document.querySelector(
|
|
14
|
+
`script[src="${p}"]`
|
|
15
|
+
)) {
|
|
16
|
+
customElements.whenDefined("altcha-widget").then(() => r()).catch(t);
|
|
17
|
+
return;
|
|
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;
|
|
8
26
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}, k = ({
|
|
31
|
-
baseUrl: i,
|
|
32
|
-
shouldBypassCaptcha: e = !1,
|
|
33
|
-
shouldMakeInitialRequest: c = !0
|
|
34
|
-
}) => {
|
|
35
|
-
const s = `${i}/run/auth/pow/challenge`, t = p(null), r = p(null), n = h(() => {
|
|
36
|
-
const o = y(s);
|
|
37
|
-
t.current = o, o.then((l) => {
|
|
38
|
-
l && (r.current = l.expiresAt);
|
|
39
|
-
});
|
|
40
|
-
}, [s]), g = h(async () => {
|
|
41
|
-
if (e) return {};
|
|
42
|
-
t.current || n();
|
|
43
|
-
const o = t.current;
|
|
44
|
-
t.current = null, n();
|
|
45
|
-
const l = t.current, f = await o;
|
|
46
|
-
if (!f) {
|
|
47
|
-
const a = await l;
|
|
48
|
-
return a ? { "x-inkeep-challenge-solution": btoa(JSON.stringify(a.payload)) } : {};
|
|
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);
|
|
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,
|
|
39
|
+
"Sentinel unavailable, requests will proceed without bot protection"
|
|
40
|
+
))));
|
|
41
|
+
};
|
|
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);
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
return n === "verified" && a(), new Promise((l) => {
|
|
49
|
+
t = l, setTimeout(() => {
|
|
50
|
+
t === l && (t = null, l(void 0));
|
|
51
|
+
}, y);
|
|
52
|
+
});
|
|
53
|
+
}, startNextSolve: a, destroy: () => {
|
|
54
|
+
e.removeEventListener("statechange", h), t = null, r.remove();
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
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);
|
|
53
62
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}, [
|
|
63
|
+
}).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;
|
|
70
|
+
};
|
|
71
|
+
}, [r, i]);
|
|
72
|
+
const n = f(async () => {
|
|
73
|
+
if (r) return {};
|
|
74
|
+
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 }))
|
|
80
|
+
} : {};
|
|
81
|
+
}, [r, i]), u = f(() => {
|
|
82
|
+
e.current?.startNextSolve();
|
|
83
|
+
}, []);
|
|
84
|
+
return { getCaptchaHeader: n, invalidate: u };
|
|
63
85
|
};
|
|
64
86
|
export {
|
|
65
|
-
|
|
66
|
-
k as useCaptcha
|
|
87
|
+
b as useCaptcha
|
|
67
88
|
};
|
|
@@ -294,7 +294,7 @@ export declare const EmbeddedChatPrimitiveFormFieldSelectTrigger: React.ForwardR
|
|
|
294
294
|
declare const PrimitiveFormFieldSelectValue: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>, "_id"> & Partial<Pick<SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>, "_id">>>;
|
|
295
295
|
export declare const EmbeddedChatPrimitiveFormFieldSelectValue: (props: ComponentPropsWithRef<typeof PrimitiveFormFieldSelectValue>) => import("react/jsx-runtime").JSX.Element;
|
|
296
296
|
export declare const EmbeddedChatPrimitiveFormFieldSelectIcon: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectIconProps & React.RefAttributes<HTMLSpanElement>, "children" | "asChild" | "_id"> & Partial<Pick<SelectPrimitive.SelectIconProps & React.RefAttributes<HTMLSpanElement>, "children" | "asChild" | "_id">>>;
|
|
297
|
-
export declare const EmbeddedChatPrimitiveFormFieldSelectContent: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "
|
|
297
|
+
export declare const EmbeddedChatPrimitiveFormFieldSelectContent: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "_id" | "position"> & Partial<Pick<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "_id" | "position">>>;
|
|
298
298
|
export declare const EmbeddedChatPrimitiveFormFieldSelectViewport: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectViewportProps & React.RefAttributes<HTMLDivElement>, "_id"> & Partial<Pick<SelectPrimitive.SelectViewportProps & React.RefAttributes<HTMLDivElement>, "_id">>>;
|
|
299
299
|
export declare const EmbeddedChatPrimitiveFormFieldSelectItem: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, "_id"> & Partial<Pick<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, "_id">>>;
|
|
300
300
|
export declare const EmbeddedChatPrimitiveFormFieldSelectItemText: React.ForwardRefExoticComponent< PolymorphicProps & Omit<SelectPrimitive.SelectItemTextProps & React.RefAttributes<HTMLSpanElement>, "_id"> & Partial<Pick<SelectPrimitive.SelectItemTextProps & React.RefAttributes<HTMLSpanElement>, "_id">>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),P=require("./use-local-storage.cjs"),B=require("./use-inkeep-api-client.cjs"),D=30*1e3,W=2147483647,X=()=>{},v=async()=>({});function j(s){return new Date(s.expiresAt).getTime()-D<=Date.now()}const z=({baseUrl:s,appId:t,getCaptchaHeader:R,invalidateCaptcha:F,optOutAllAnalytics:m,enabled:n=!0})=>{const L=n&&t&&!m?`inkeep_session_${t}`:null,[i,h]=P.useLocalStorage(L),T=e.useRef(n);e.useEffect(()=>{const r=T.current;if(T.current=n,r&&!n&&t&&!m){try{localStorage.removeItem(`inkeep_session_${t}`)}catch{}h(null)}},[n,t,m,h]);const{fetchWithAuth:w}=B.useInkeepApiClient({appId:t,authToken:void 0,getCaptchaHeader:R??v,invalidateCaptcha:F??X}),k=e.useRef(s);k.current=s;const y=e.useRef(t);y.current=t;const f=e.useRef(i);f.current=i;const g=e.useRef(h);g.current=h;const M=e.useRef(w);M.current=w;const x=e.useRef(R??v);x.current=R??v;const a=e.useRef(null),C=e.useRef(n);C.current=n;const o=e.useCallback(async r=>{if(!C.current||!k.current||!y.current)return null;if(!r&&a.current)return a.current;const u=`${k.current}/run/auth/apps/${y.current}/anonymous-session`,l=(async()=>{try{const c={"Content-Type":"application/json"},$=f.current?.token;$&&(c.Authorization=`Bearer ${$}`);const q=await x.current();Object.assign(c,q);const S=await M.current(u,{method:"POST",headers:c,signal:r});if(!S.ok)throw new Error(`Failed to fetch anonymous session: ${S.status}`);const E=await S.json();return g.current({token:E.token,expiresAt:E.expiresAt}),E.token}catch(c){return c instanceof Error&&c.name==="AbortError"||console.error("[anon-session] fetch failed",c),null}finally{r||(a.current=null)}})();return r||(a.current=l),l},[]),_=e.useRef(!1);e.useEffect(()=>{if(!n||!s||!t)return;const r=!_.current;if(_.current=!0,!r&&f.current&&!j(f.current)||a.current)return;const u=new AbortController;return o(u.signal),()=>u.abort()},[s,t,n,o]),e.useEffect(()=>{if(!n||!s||!t||!i?.expiresAt)return;const A=new Date(i.expiresAt).getTime()-D-Date.now();if(A<=0)return;const l=setTimeout(()=>o(),Math.min(A,W));return()=>clearTimeout(l)},[s,t,n,i?.expiresAt,o]),e.useEffect(()=>{if(!n||!s||!t)return;const r=()=>{if(document.visibilityState!=="visible")return;const u=f.current;(!u||j(u))&&o()};return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[s,t,n,o]);const p=e.useCallback(()=>o(),[o]);return{sessionToken:i?.token??null,refreshSession:p}};exports.useAnonymousSession=z;
|
|
@@ -1,96 +1,101 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as o, useEffect as l, useCallback as
|
|
3
|
-
import { useLocalStorage as
|
|
4
|
-
import { useInkeepApiClient as
|
|
5
|
-
const
|
|
6
|
-
},
|
|
7
|
-
function
|
|
8
|
-
return new Date(n.expiresAt).getTime() -
|
|
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
|
|
10
|
+
const G = ({
|
|
11
11
|
baseUrl: n,
|
|
12
|
-
appId:
|
|
13
|
-
getCaptchaHeader:
|
|
14
|
-
invalidateCaptcha:
|
|
15
|
-
optOutAllAnalytics:
|
|
16
|
-
enabled:
|
|
12
|
+
appId: t,
|
|
13
|
+
getCaptchaHeader: k,
|
|
14
|
+
invalidateCaptcha: L,
|
|
15
|
+
optOutAllAnalytics: y,
|
|
16
|
+
enabled: e = !0
|
|
17
17
|
}) => {
|
|
18
|
-
const
|
|
18
|
+
const B = e && t && !y ? `inkeep_session_${t}` : null, [u, h] = X(B), w = o(e);
|
|
19
19
|
l(() => {
|
|
20
|
-
const r =
|
|
21
|
-
if (
|
|
20
|
+
const r = w.current;
|
|
21
|
+
if (w.current = e, r && !e && t && !y) {
|
|
22
22
|
try {
|
|
23
|
-
localStorage.removeItem(`inkeep_session_${
|
|
23
|
+
localStorage.removeItem(`inkeep_session_${t}`);
|
|
24
24
|
} catch {
|
|
25
25
|
}
|
|
26
26
|
h(null);
|
|
27
27
|
}
|
|
28
|
-
}, [
|
|
29
|
-
const { fetchWithAuth:
|
|
30
|
-
appId:
|
|
28
|
+
}, [e, t, y, h]);
|
|
29
|
+
const { fetchWithAuth: x } = z({
|
|
30
|
+
appId: t,
|
|
31
31
|
authToken: void 0,
|
|
32
|
-
getCaptchaHeader:
|
|
33
|
-
invalidateCaptcha:
|
|
34
|
-
}),
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const f = o(
|
|
39
|
-
f.current =
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
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
|
|
52
|
+
const c = `${A.current}/run/auth/apps/${R.current}/anonymous-session`, m = (async () => {
|
|
51
53
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
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:
|
|
60
|
+
headers: i,
|
|
57
61
|
signal: r
|
|
58
62
|
});
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}, []),
|
|
74
|
+
}, []), $ = o(!1);
|
|
70
75
|
l(() => {
|
|
71
|
-
if (!
|
|
72
|
-
const r =
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
return s(
|
|
76
|
-
}, [n,
|
|
77
|
-
if (!
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
const m = setTimeout(() => s(), Math.min(
|
|
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,
|
|
83
|
-
if (!
|
|
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
|
|
87
|
-
(!
|
|
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,
|
|
91
|
-
const
|
|
92
|
-
return { sessionToken:
|
|
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
|
-
|
|
100
|
+
G as useAnonymousSession
|
|
96
101
|
};
|
|
@@ -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 c=require("react"),f=require("./use-inkeep-api-client.cjs"),h=()=>{};function g({baseUrl:e,appId:a,authToken:r,getCaptchaHeader:u,invalidateCaptcha:l,refreshSession:p,headers:o}){const{fetchWithAuth:s}=f.useInkeepApiClient({appId:a,authToken:r,getCaptchaHeader:u,invalidateCaptcha:l??h,refreshSession:p}),i=c.useRef(o);return i.current=o,{logEvent:c.useCallback(async({body:v})=>{if(e)try{const t=`${e}/run/v1/events`,n=await s(t,{method:"POST",headers:{"Content-Type":"application/json",...i.current},body:JSON.stringify(v)});if(!n.ok){const d=await n.text().catch(()=>"<unreadable>");console.warn(`[events-api] log failed: ${n.status}`,d)}}catch(t){console.warn("[events-api] log threw",t)}},[e,s])}}exports.useEventsApi=g;
|
|
@@ -5,6 +5,8 @@ interface UseEventsApiOptions {
|
|
|
5
5
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
6
6
|
invalidateCaptcha?: () => void;
|
|
7
7
|
refreshSession?: () => Promise<string | null>;
|
|
8
|
+
/** Consumer-provided headers from `aiChatSettings.headers`. */
|
|
9
|
+
headers?: Record<string, string>;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Mirrors the backend's `EventApiInsertSchema` for /run/v1/events.
|
|
@@ -23,7 +25,7 @@ interface LogEventBody {
|
|
|
23
25
|
interface LogEventParams {
|
|
24
26
|
body: LogEventBody;
|
|
25
27
|
}
|
|
26
|
-
export declare function useEventsApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseEventsApiOptions): {
|
|
28
|
+
export declare function useEventsApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, headers, }: UseEventsApiOptions): {
|
|
27
29
|
logEvent: ({ body }: LogEventParams) => Promise<void>;
|
|
28
30
|
};
|
|
29
31
|
export {};
|
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
const
|
|
2
|
+
import { useRef as h, useCallback as v } from "react";
|
|
3
|
+
import { useInkeepApiClient as d } from "./use-inkeep-api-client.js";
|
|
4
|
+
const g = () => {
|
|
5
5
|
};
|
|
6
|
-
function
|
|
6
|
+
function C({
|
|
7
7
|
baseUrl: t,
|
|
8
|
-
appId:
|
|
9
|
-
authToken:
|
|
10
|
-
getCaptchaHeader:
|
|
11
|
-
invalidateCaptcha:
|
|
12
|
-
refreshSession:
|
|
8
|
+
appId: s,
|
|
9
|
+
authToken: c,
|
|
10
|
+
getCaptchaHeader: i,
|
|
11
|
+
invalidateCaptcha: u,
|
|
12
|
+
refreshSession: l,
|
|
13
|
+
headers: o
|
|
13
14
|
}) {
|
|
14
|
-
const { fetchWithAuth:
|
|
15
|
-
appId:
|
|
16
|
-
authToken:
|
|
17
|
-
getCaptchaHeader:
|
|
18
|
-
invalidateCaptcha:
|
|
19
|
-
refreshSession:
|
|
20
|
-
});
|
|
21
|
-
return { logEvent:
|
|
22
|
-
async ({ body:
|
|
23
|
-
if (
|
|
15
|
+
const { fetchWithAuth: a } = d({
|
|
16
|
+
appId: s,
|
|
17
|
+
authToken: c,
|
|
18
|
+
getCaptchaHeader: i,
|
|
19
|
+
invalidateCaptcha: u ?? g,
|
|
20
|
+
refreshSession: l
|
|
21
|
+
}), r = h(o);
|
|
22
|
+
return r.current = o, { logEvent: v(
|
|
23
|
+
async ({ body: p }) => {
|
|
24
|
+
if (t)
|
|
24
25
|
try {
|
|
25
|
-
const
|
|
26
|
+
const e = `${t}/run/v1/events`, n = await a(e, {
|
|
26
27
|
method: "POST",
|
|
27
|
-
headers: { "Content-Type": "application/json" },
|
|
28
|
-
body: JSON.stringify(
|
|
28
|
+
headers: { "Content-Type": "application/json", ...r.current },
|
|
29
|
+
body: JSON.stringify(p)
|
|
29
30
|
});
|
|
30
|
-
if (!
|
|
31
|
-
const
|
|
32
|
-
console.warn(`[events-api] log failed: ${
|
|
31
|
+
if (!n.ok) {
|
|
32
|
+
const f = await n.text().catch(() => "<unreadable>");
|
|
33
|
+
console.warn(`[events-api] log failed: ${n.status}`, f);
|
|
33
34
|
}
|
|
34
|
-
} catch (
|
|
35
|
-
console.warn("[events-api] log threw",
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn("[events-api] log threw", e);
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
|
-
[t,
|
|
39
|
+
[t, a]
|
|
39
40
|
) };
|
|
40
41
|
}
|
|
41
42
|
export {
|
|
42
|
-
|
|
43
|
+
C as useEventsApi
|
|
43
44
|
};
|
|
@@ -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 c=require("react"),h=require("./use-inkeep-api-client.cjs"),y=()=>{};function m({baseUrl:e,appId:o,authToken:r,getCaptchaHeader:u,invalidateCaptcha:a,refreshSession:d,headers:n}){const{fetchWithAuth:i}=h.useInkeepApiClient({appId:o,authToken:r,getCaptchaHeader:u,invalidateCaptcha:a??y,refreshSession:d}),s=c.useRef(n);return s.current=n,{submitFeedback:c.useCallback(async({conversationId:p,messageId:b,type:f,details:k})=>{if(!e)return;const l=`${e}/run/v1/feedback`,t=await i(l,{method:"POST",headers:{"Content-Type":"application/json",...s.current},body:JSON.stringify({conversationId:p,messageId:b,type:f,details:k})});if(!t.ok)throw new Error(`Feedback submission failed: ${t.status}`);return t.json()},[e,i])}}exports.useFeedbackApi=m;
|
|
@@ -6,6 +6,8 @@ interface UseFeedbackApiOptions {
|
|
|
6
6
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
7
|
invalidateCaptcha?: () => void;
|
|
8
8
|
refreshSession?: () => Promise<string | null>;
|
|
9
|
+
/** Consumer-provided headers from `aiChatSettings.headers`. */
|
|
10
|
+
headers?: Record<string, string>;
|
|
9
11
|
}
|
|
10
12
|
interface SubmitFeedbackParams {
|
|
11
13
|
conversationId: string;
|
|
@@ -13,7 +15,7 @@ interface SubmitFeedbackParams {
|
|
|
13
15
|
type: FeedbackType;
|
|
14
16
|
details?: string | null;
|
|
15
17
|
}
|
|
16
|
-
export declare function useFeedbackApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseFeedbackApiOptions): {
|
|
18
|
+
export declare function useFeedbackApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, headers, }: UseFeedbackApiOptions): {
|
|
17
19
|
submitFeedback: ({ conversationId, messageId, type, details }: SubmitFeedbackParams) => Promise<any>;
|
|
18
20
|
};
|
|
19
21
|
export {};
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
const
|
|
2
|
+
import { useRef as m, useCallback as h } from "react";
|
|
3
|
+
import { useInkeepApiClient as l } from "./use-inkeep-api-client.js";
|
|
4
|
+
const y = () => {
|
|
5
5
|
};
|
|
6
|
-
function
|
|
6
|
+
function A({
|
|
7
7
|
baseUrl: e,
|
|
8
|
-
appId:
|
|
9
|
-
authToken:
|
|
10
|
-
getCaptchaHeader:
|
|
11
|
-
invalidateCaptcha:
|
|
12
|
-
refreshSession:
|
|
8
|
+
appId: r,
|
|
9
|
+
authToken: s,
|
|
10
|
+
getCaptchaHeader: c,
|
|
11
|
+
invalidateCaptcha: u,
|
|
12
|
+
refreshSession: a,
|
|
13
|
+
headers: n
|
|
13
14
|
}) {
|
|
14
|
-
const { fetchWithAuth:
|
|
15
|
-
appId:
|
|
16
|
-
authToken:
|
|
17
|
-
getCaptchaHeader:
|
|
18
|
-
invalidateCaptcha:
|
|
19
|
-
refreshSession:
|
|
20
|
-
});
|
|
21
|
-
return { submitFeedback:
|
|
22
|
-
async ({ conversationId:
|
|
23
|
-
if (!e
|
|
24
|
-
const
|
|
15
|
+
const { fetchWithAuth: o } = l({
|
|
16
|
+
appId: r,
|
|
17
|
+
authToken: s,
|
|
18
|
+
getCaptchaHeader: c,
|
|
19
|
+
invalidateCaptcha: u ?? y,
|
|
20
|
+
refreshSession: a
|
|
21
|
+
}), i = m(n);
|
|
22
|
+
return i.current = n, { submitFeedback: h(
|
|
23
|
+
async ({ conversationId: f, messageId: p, type: d, details: b }) => {
|
|
24
|
+
if (!e) return;
|
|
25
|
+
const k = `${e}/run/v1/feedback`, t = await o(k, {
|
|
25
26
|
method: "POST",
|
|
26
|
-
headers: { "Content-Type": "application/json" },
|
|
27
|
-
body: JSON.stringify({ conversationId:
|
|
27
|
+
headers: { "Content-Type": "application/json", ...i.current },
|
|
28
|
+
body: JSON.stringify({ conversationId: f, messageId: p, type: d, details: b })
|
|
28
29
|
});
|
|
29
|
-
if (!
|
|
30
|
-
return
|
|
30
|
+
if (!t.ok) throw new Error(`Feedback submission failed: ${t.status}`);
|
|
31
|
+
return t.json();
|
|
31
32
|
},
|
|
32
|
-
[e,
|
|
33
|
+
[e, o]
|
|
33
34
|
) };
|
|
34
35
|
}
|
|
35
36
|
export {
|
|
36
|
-
|
|
37
|
+
A as useFeedbackApi
|
|
37
38
|
};
|
|
@@ -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 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,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useRef as
|
|
3
|
-
function
|
|
2
|
+
import { useRef as s, useCallback as E } from "react";
|
|
3
|
+
function m(e, r) {
|
|
4
4
|
if (e === 400 && typeof r == "object" && r !== null) {
|
|
5
5
|
const t = (r.detail ?? "").toLowerCase();
|
|
6
6
|
if (t.includes("challenge") || t.includes("proof-of-work")) return "pow";
|
|
@@ -12,7 +12,7 @@ function E(e, r) {
|
|
|
12
12
|
}
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function y(e) {
|
|
16
16
|
if (!e) return {};
|
|
17
17
|
if (e instanceof Headers) {
|
|
18
18
|
const r = {};
|
|
@@ -22,66 +22,53 @@ function m(e) {
|
|
|
22
22
|
}
|
|
23
23
|
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function A(e, r, t, c) {
|
|
26
26
|
return {
|
|
27
27
|
...e ? { "x-inkeep-app-id": e } : {},
|
|
28
28
|
...r ? { Authorization: `Bearer ${r}` } : {},
|
|
29
|
-
...
|
|
29
|
+
...y(c),
|
|
30
30
|
// captcha last — must not be overridden by caller headers
|
|
31
31
|
...t
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function H({
|
|
35
35
|
appId: e,
|
|
36
36
|
authToken: r,
|
|
37
37
|
getCaptchaHeader: t,
|
|
38
38
|
invalidateCaptcha: c,
|
|
39
|
-
refreshSession:
|
|
39
|
+
refreshSession: f
|
|
40
40
|
}) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const i =
|
|
41
|
+
const o = s(e);
|
|
42
|
+
o.current = e;
|
|
43
|
+
const i = s(r);
|
|
44
44
|
i.current = r;
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
const
|
|
52
|
-
a.current,
|
|
53
|
-
i.current,
|
|
54
|
-
C,
|
|
55
|
-
s?.headers
|
|
56
|
-
), n = await fetch(d, { ...s, headers: H });
|
|
45
|
+
const R = s(t);
|
|
46
|
+
R.current = t;
|
|
47
|
+
const l = s(c);
|
|
48
|
+
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 });
|
|
57
52
|
if (n.status !== 400 && n.status !== 401) return n;
|
|
58
|
-
let
|
|
53
|
+
let h;
|
|
59
54
|
try {
|
|
60
|
-
|
|
55
|
+
h = await n.clone().json();
|
|
61
56
|
} catch {
|
|
62
57
|
return n;
|
|
63
58
|
}
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 });
|
|
59
|
+
const p = m(n.status, h);
|
|
60
|
+
if (p === "pow")
|
|
61
|
+
return l.current(), n;
|
|
62
|
+
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 });
|
|
80
67
|
}
|
|
81
68
|
return n;
|
|
82
69
|
}, []) };
|
|
83
70
|
}
|
|
84
71
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
m as parseAuthError,
|
|
73
|
+
H as useInkeepApiClient
|
|
87
74
|
};
|
|
@@ -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.
|
|
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.5",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.
|
|
6
|
+
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.16.5", 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
|
|
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,46 +1,42 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useContext as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
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 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({
|
|
13
10
|
baseUrl: i,
|
|
14
|
-
shouldBypassCaptcha:
|
|
15
|
-
|
|
16
|
-
}), { sessionToken: h, refreshSession: c } = L({
|
|
11
|
+
shouldBypassCaptcha: l || !!o
|
|
12
|
+
}), { sessionToken: u, refreshSession: c } = S({
|
|
17
13
|
baseUrl: i,
|
|
18
|
-
appId:
|
|
14
|
+
appId: d,
|
|
19
15
|
getCaptchaHeader: r,
|
|
20
|
-
invalidateCaptcha:
|
|
21
|
-
optOutAllAnalytics:
|
|
16
|
+
invalidateCaptcha: h,
|
|
17
|
+
optOutAllAnalytics: A?.optOutAllAnalytics,
|
|
22
18
|
enabled: !e && !a
|
|
23
|
-
}),
|
|
19
|
+
}), v = {
|
|
24
20
|
authToken: s,
|
|
25
21
|
isAuthenticated: e,
|
|
26
22
|
isAuthLoading: a,
|
|
27
|
-
isAuthConfigured:
|
|
28
|
-
refreshAuthToken:
|
|
29
|
-
sessionToken:
|
|
23
|
+
isAuthConfigured: m,
|
|
24
|
+
refreshAuthToken: C,
|
|
25
|
+
sessionToken: u,
|
|
30
26
|
refreshSession: c,
|
|
31
27
|
getCaptchaHeader: r,
|
|
32
|
-
invalidateCaptcha:
|
|
33
|
-
effectiveAuthToken: o ?? (e ? s :
|
|
28
|
+
invalidateCaptcha: h,
|
|
29
|
+
effectiveAuthToken: o ?? (e ? s : u),
|
|
34
30
|
applicableRefreshSession: o || e ? void 0 : c
|
|
35
31
|
};
|
|
36
|
-
return /* @__PURE__ */
|
|
37
|
-
},
|
|
38
|
-
const t =
|
|
32
|
+
return /* @__PURE__ */ k(p.Provider, { value: v, children: t });
|
|
33
|
+
}, H = () => {
|
|
34
|
+
const t = g(p);
|
|
39
35
|
if (!t)
|
|
40
36
|
throw new Error("useChatAuth must be used within a ChatAuthProvider");
|
|
41
37
|
return t;
|
|
42
38
|
};
|
|
43
39
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
E as ChatAuthProvider,
|
|
41
|
+
H as useChatAuth
|
|
46
42
|
};
|
|
@@ -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 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.5",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,73 +1,73 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import { useChatAuth as
|
|
6
|
-
import { useEventsApi as
|
|
7
|
-
import { BaseEventsContext as
|
|
8
|
-
const
|
|
9
|
-
const { baseSettings:
|
|
2
|
+
import { jsx as U } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo as x, useCallback as B } from "react";
|
|
4
|
+
import { useInkeepConfig as N } from "./config-provider.js";
|
|
5
|
+
import { useChatAuth as O } from "./chat-auth-provider.js";
|
|
6
|
+
import { useEventsApi as j } from "../hooks/use-events-api.js";
|
|
7
|
+
import { BaseEventsContext as M } from "./base-events-provider.js";
|
|
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.5", a = x(
|
|
10
10
|
() => ({
|
|
11
|
-
widgetLibraryVersion:
|
|
12
|
-
componentType:
|
|
11
|
+
widgetLibraryVersion: c,
|
|
12
|
+
componentType: i
|
|
13
13
|
}),
|
|
14
|
-
[
|
|
15
|
-
), { effectiveAuthToken:
|
|
14
|
+
[i, c]
|
|
15
|
+
), { effectiveAuthToken: h, applicableRefreshSession: u, getCaptchaHeader: y, invalidateCaptcha: b } = O(), { baseUrl: A, appId: E, analyticsApiBaseUrl: C, headers: I } = g, p = f?.optOutAllAnalytics ?? !1, { logEvent: l } = j({
|
|
16
16
|
baseUrl: C ?? A,
|
|
17
17
|
appId: E,
|
|
18
|
-
authToken:
|
|
18
|
+
authToken: h,
|
|
19
19
|
getCaptchaHeader: y,
|
|
20
20
|
invalidateCaptcha: b,
|
|
21
|
-
refreshSession:
|
|
22
|
-
|
|
21
|
+
refreshSession: u,
|
|
22
|
+
headers: I
|
|
23
|
+
}), P = { logEvent: B(
|
|
23
24
|
async (s) => {
|
|
24
|
-
const
|
|
25
|
+
const k = {
|
|
25
26
|
eventName: s.eventName,
|
|
26
27
|
properties: {
|
|
27
28
|
...a,
|
|
28
29
|
...t ? { tags: t } : {},
|
|
29
30
|
...s.properties,
|
|
30
|
-
...
|
|
31
|
+
...n
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
if (!
|
|
34
|
-
const e = s.properties ?? {},
|
|
34
|
+
if (!p) {
|
|
35
|
+
const e = s.properties ?? {}, v = typeof e.conversationId == "string" ? e.conversationId : void 0, d = typeof e.messageId == "string" ? e.messageId : void 0, w = !!o && Object.keys(o).length > 0, S = {
|
|
35
36
|
...t ? { tags: t } : {},
|
|
36
|
-
...
|
|
37
|
-
},
|
|
37
|
+
...n ?? {}
|
|
38
|
+
}, T = {
|
|
38
39
|
...a,
|
|
39
40
|
...s.properties
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
+
l({
|
|
42
43
|
body: {
|
|
43
44
|
type: s.eventName,
|
|
44
|
-
...
|
|
45
|
+
...v ? { conversationId: v } : {},
|
|
45
46
|
...d ? { messageId: d } : {},
|
|
46
|
-
...
|
|
47
|
-
properties:
|
|
48
|
-
metadata:
|
|
47
|
+
...w ? { userProperties: o } : {},
|
|
48
|
+
properties: S,
|
|
49
|
+
metadata: T
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
try {
|
|
53
|
-
return await
|
|
54
|
+
return await r.onEvent?.(k);
|
|
54
55
|
} catch (e) {
|
|
55
56
|
console.warn("[events] onEvent callback threw", e);
|
|
56
57
|
}
|
|
57
58
|
},
|
|
58
59
|
[
|
|
59
|
-
|
|
60
|
+
r,
|
|
60
61
|
a,
|
|
61
62
|
t,
|
|
62
|
-
|
|
63
|
-
v,
|
|
63
|
+
n,
|
|
64
64
|
l,
|
|
65
|
-
|
|
65
|
+
p,
|
|
66
66
|
o
|
|
67
67
|
]
|
|
68
68
|
) };
|
|
69
|
-
return /* @__PURE__ */
|
|
69
|
+
return /* @__PURE__ */ U(M.Provider, { value: P, children: m });
|
|
70
70
|
};
|
|
71
71
|
export {
|
|
72
|
-
|
|
72
|
+
F as ChatBaseEventsProvider
|
|
73
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),a=require("react"),T=require("../components/embedded-chat/chat-provider.cjs"),F=require("../utils/misc.cjs"),A=require("./config-provider.cjs"),E=require("./base-events-provider.cjs"),j=require("../hooks/use-feedback-api.cjs"),l=a.createContext(void 0);function y(){const{baseSettings:t,aiChatSettings:c}=A.useInkeepConfig(),[p,g]=a.useState(null),[f,C]=a.useState({}),{conversationId:o,messages:r,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}=T.useChat(),{analyticsProperties:d}=t,{logEvent:b}=E.useBaseEvents(),{submitFeedback:k}=j.useFeedbackApi({baseUrl:c.baseUrl,appId:c.appId,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}),i=a.useCallback(async(e,s,u)=>{C(n=>({...n,[e]:{type:s,messageId:e,details:u}})),t.onFeedback?t.onFeedback({type:s,messageId:e,details:u,properties:d}).catch(n=>console.warn("[feedback] onFeedback error:",n)):k({conversationId:o,messageId:e,type:s,details:u}).catch(n=>console.warn("[feedback] submitFeedbackToApi error:",n));const v=r.findIndex(n=>n.id===e),x=r[v],S={conversationId:o,question:F.getMessageContent(r[v-1]),answer:F.getMessageContent(x),messageId:e,details:u};b({eventName:s==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:S}),s==="negative"&&b({eventName:"user_escalation_indicated",properties:{escalationType:"downvote",conversationId:o,messageId:e}})},[r,o,d,t,b,k]),_=a.useCallback(async e=>{i(e,"positive")},[i]),w=a.useCallback(async(e,s)=>{i(e,"negative",s)},[i]);return{feedback:f,currentFeedback:p,setCurrentFeedback:g,submitPositiveFeedback:_,submitNegativeFeedback:w}}const N=({children:t})=>{const c=y();return M.jsx(l.Provider,{value:c,children:t})},R=()=>{const t=a.useContext(l);if(!t)throw new Error("useFeedback must be used within a FeedbackProvider");return t};exports.FeedbackProvider=N;exports.useMessageFeedback=R;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),a=require("react"),T=require("../components/embedded-chat/chat-provider.cjs"),F=require("../utils/misc.cjs"),A=require("./config-provider.cjs"),E=require("./base-events-provider.cjs"),j=require("../hooks/use-feedback-api.cjs"),l=a.createContext(void 0);function y(){const{baseSettings:t,aiChatSettings:c}=A.useInkeepConfig(),[p,g]=a.useState(null),[f,C]=a.useState({}),{conversationId:o,messages:r,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}=T.useChat(),{analyticsProperties:d}=t,{logEvent:b}=E.useBaseEvents(),{submitFeedback:k}=j.useFeedbackApi({baseUrl:c.baseUrl,appId:c.appId,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q,headers:c.headers}),i=a.useCallback(async(e,s,u)=>{C(n=>({...n,[e]:{type:s,messageId:e,details:u}})),t.onFeedback?t.onFeedback({type:s,messageId:e,details:u,properties:d}).catch(n=>console.warn("[feedback] onFeedback error:",n)):k({conversationId:o,messageId:e,type:s,details:u}).catch(n=>console.warn("[feedback] submitFeedbackToApi error:",n));const v=r.findIndex(n=>n.id===e),x=r[v],S={conversationId:o,question:F.getMessageContent(r[v-1]),answer:F.getMessageContent(x),messageId:e,details:u};b({eventName:s==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:S}),s==="negative"&&b({eventName:"user_escalation_indicated",properties:{escalationType:"downvote",conversationId:o,messageId:e}})},[r,o,d,t,b,k]),_=a.useCallback(async e=>{i(e,"positive")},[i]),w=a.useCallback(async(e,s)=>{i(e,"negative",s)},[i]);return{feedback:f,currentFeedback:p,setCurrentFeedback:g,submitPositiveFeedback:_,submitNegativeFeedback:w}}const N=({children:t})=>{const c=y();return M.jsx(l.Provider,{value:c,children:t})},R=()=>{const t=a.useContext(l);if(!t)throw new Error("useFeedback must be used within a FeedbackProvider");return t};exports.FeedbackProvider=N;exports.useMessageFeedback=R;
|
|
@@ -8,9 +8,9 @@ import { useBaseEvents as q } from "./base-events-provider.js";
|
|
|
8
8
|
import { useFeedbackApi as y } from "../hooks/use-feedback-api.js";
|
|
9
9
|
const f = M(void 0);
|
|
10
10
|
function B() {
|
|
11
|
-
const { baseSettings: t, aiChatSettings: n } = j(), [F, l] = m(null), [
|
|
11
|
+
const { baseSettings: t, aiChatSettings: n } = j(), [F, l] = m(null), [h, C] = m({}), {
|
|
12
12
|
conversationId: a,
|
|
13
|
-
messages:
|
|
13
|
+
messages: r,
|
|
14
14
|
authToken: g,
|
|
15
15
|
getCaptchaHeader: _,
|
|
16
16
|
invalidateCaptcha: w,
|
|
@@ -21,23 +21,24 @@ function B() {
|
|
|
21
21
|
authToken: g,
|
|
22
22
|
getCaptchaHeader: _,
|
|
23
23
|
invalidateCaptcha: w,
|
|
24
|
-
refreshSession: x
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
refreshSession: x,
|
|
25
|
+
headers: n.headers
|
|
26
|
+
}), c = d(
|
|
27
|
+
async (e, s, i) => {
|
|
28
|
+
C((o) => ({ ...o, [e]: { type: s, messageId: e, details: i } })), t.onFeedback ? t.onFeedback({ type: s, messageId: e, details: i, properties: u }).catch((o) => console.warn("[feedback] onFeedback error:", o)) : k({ conversationId: a, messageId: e, type: s, details: i }).catch(
|
|
29
|
+
(o) => console.warn("[feedback] submitFeedbackToApi error:", o)
|
|
29
30
|
);
|
|
30
|
-
const p =
|
|
31
|
+
const p = r.findIndex((o) => o.id === e), T = r[p], A = {
|
|
31
32
|
conversationId: a,
|
|
32
|
-
question: v(
|
|
33
|
+
question: v(r[p - 1]),
|
|
33
34
|
answer: v(T),
|
|
34
35
|
messageId: e,
|
|
35
36
|
details: i
|
|
36
37
|
};
|
|
37
38
|
b({
|
|
38
|
-
eventName:
|
|
39
|
+
eventName: s === "positive" ? "assistant_positive_feedback_submitted" : "assistant_negative_feedback_submitted",
|
|
39
40
|
properties: A
|
|
40
|
-
}),
|
|
41
|
+
}), s === "negative" && b({
|
|
41
42
|
eventName: "user_escalation_indicated",
|
|
42
43
|
properties: {
|
|
43
44
|
escalationType: "downvote",
|
|
@@ -46,20 +47,20 @@ function B() {
|
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
49
|
},
|
|
49
|
-
[
|
|
50
|
+
[r, a, u, t, b, k]
|
|
50
51
|
), P = d(
|
|
51
52
|
async (e) => {
|
|
52
|
-
|
|
53
|
+
c(e, "positive");
|
|
53
54
|
},
|
|
54
|
-
[
|
|
55
|
+
[c]
|
|
55
56
|
), S = d(
|
|
56
|
-
async (e,
|
|
57
|
-
|
|
57
|
+
async (e, s) => {
|
|
58
|
+
c(e, "negative", s);
|
|
58
59
|
},
|
|
59
|
-
[
|
|
60
|
+
[c]
|
|
60
61
|
);
|
|
61
62
|
return {
|
|
62
|
-
feedback:
|
|
63
|
+
feedback: h,
|
|
63
64
|
currentFeedback: F,
|
|
64
65
|
setCurrentFeedback: l,
|
|
65
66
|
submitPositiveFeedback: P,
|