@inkeep/agents-ui 0.0.0-dev-20260513213554 → 0.0.0-dev-20260528130902
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/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +74 -76
- 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
|
@@ -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
|
};
|