@inkeep/agents-ui 0.15.13 → 0.15.14
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/index.cjs +1 -1
- package/dist/index.js +230 -222
- package/dist/primitives/atoms/icons/built-in-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/built-in-icons.d.ts +2 -0
- package/dist/primitives/atoms/icons/built-in-icons.js +33 -31
- package/dist/primitives/atoms/icons/inkeep-default-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/inkeep-default-icons.js +4 -1
- package/dist/primitives/components/chat-history/index.cjs +1 -0
- package/dist/primitives/components/chat-history/index.d.ts +27 -0
- package/dist/primitives/components/chat-history/index.js +105 -0
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -0
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +23 -6
- package/dist/primitives/components/embedded-chat/use-captcha.js +67 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +12 -3
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +252 -144
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.d.ts +2 -0
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +120 -70
- package/dist/primitives/components/embedded-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat.d.ts +5 -2
- package/dist/primitives/components/embedded-chat.js +1010 -967
- package/dist/primitives/components/index.cjs +1 -1
- package/dist/primitives/components/index.d.ts +1 -0
- package/dist/primitives/components/index.js +20 -18
- package/dist/primitives/hooks/use-anonymous-session.cjs +1 -0
- package/dist/primitives/hooks/use-anonymous-session.d.ts +12 -0
- package/dist/primitives/hooks/use-anonymous-session.js +57 -0
- package/dist/primitives/hooks/use-conversation-loader.cjs +1 -0
- package/dist/primitives/hooks/use-conversation-loader.d.ts +13 -0
- package/dist/primitives/hooks/use-conversation-loader.js +36 -0
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -0
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +33 -0
- package/dist/primitives/hooks/use-inkeep-api-client.js +87 -0
- package/dist/primitives/hooks/use-local-storage.cjs +1 -0
- package/dist/primitives/hooks/use-local-storage.d.ts +8 -0
- package/dist/primitives/hooks/use-local-storage.js +26 -0
- package/dist/primitives/index.cjs +1 -1
- package/dist/primitives/index.js +157 -151
- 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-history-provider.cjs +1 -0
- package/dist/primitives/providers/chat-history-provider.d.ts +32 -0
- package/dist/primitives/providers/chat-history-provider.js +105 -0
- package/dist/primitives/providers/index.cjs +1 -1
- package/dist/primitives/providers/index.d.ts +1 -0
- package/dist/primitives/providers/index.js +55 -52
- package/dist/primitives/utils/component-ids.cjs +1 -1
- package/dist/primitives/utils/component-ids.d.ts +32 -0
- package/dist/primitives/utils/component-ids.js +19 -1
- package/dist/primitives/utils/default-settings.cjs +1 -1
- package/dist/primitives/utils/default-settings.d.ts +2 -0
- package/dist/primitives/utils/default-settings.js +6 -4
- package/dist/react/chat-button.cjs +1 -1
- package/dist/react/chat-button.js +42 -38
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +256 -230
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +230 -222
- package/dist/react/sidebar-chat.cjs +1 -1
- package/dist/react/sidebar-chat.js +26 -22
- package/dist/styled/components/chat-bubble.cjs +1 -1
- package/dist/styled/components/chat-bubble.js +1 -1
- package/dist/styled/components/chat-history.cjs +1 -0
- package/dist/styled/components/chat-history.d.ts +15 -0
- package/dist/styled/components/chat-history.js +197 -0
- package/dist/styled/components/data-summary-group.cjs +1 -1
- package/dist/styled/components/data-summary-group.js +24 -24
- package/dist/styled/components/embedded-chat/session-loading.cjs +1 -0
- package/dist/styled/components/embedded-chat/session-loading.d.ts +1 -0
- package/dist/styled/components/embedded-chat/session-loading.js +26 -0
- package/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.d.ts +7 -1
- package/dist/styled/components/embedded-chat.js +615 -563
- package/dist/styled/components/embedded-search.cjs +1 -1
- package/dist/styled/components/embedded-search.js +1 -1
- package/dist/styled/components/index.cjs +1 -1
- package/dist/styled/components/index.d.ts +1 -0
- package/dist/styled/components/index.js +22 -20
- package/dist/styled/components/sidebar-chat.cjs +1 -1
- package/dist/styled/components/sidebar-chat.js +1 -1
- package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.cjs +1 -1
- package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.js +3 -2
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +193 -185
- package/dist/styled/inkeep.css.cjs +146 -4
- package/dist/styled/inkeep.css.js +146 -4
- package/dist/types/config/ai.d.ts +17 -1
- package/dist/types/config/base.d.ts +21 -0
- package/dist/types/icons/built-in.d.ts +1 -1
- package/dist/types/icons/custom.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./factory.cjs"),a=require("./embedded-chat.cjs"),o=require("./sidebar-chat/index.cjs"),i=require("./embedded-chat/chat-provider.cjs"),d=require("./embedded-search.cjs"),e=require("./embedded-search/search-provider.cjs"),c=require("./modal.cjs"),t=require("./modal/modal-provider.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./factory.cjs"),a=require("./embedded-chat.cjs"),o=require("./sidebar-chat/index.cjs"),i=require("./embedded-chat/chat-provider.cjs"),d=require("./embedded-search.cjs"),e=require("./embedded-search/search-provider.cjs"),c=require("./modal.cjs"),t=require("./modal/modal-provider.cjs"),s=require("./chat-button.cjs"),u=require("./searchbar.cjs"),h=require("./chat-bubble/index.cjs"),m=require("./data-summaries.cjs"),v=require("./chat-history/index.cjs");exports.ikp=r.ikp;exports.jsxFactory=r.jsxFactory;exports.EmbeddedChatPrimitive=a;exports.SidebarChatPrimitive=o;exports.ChatProvider=i.ChatProvider;exports.useChat=i.useChat;exports.EmbeddedSearchPrimitive=d;exports.SearchProvider=e.SearchProvider;exports.SearchProviderImpl=e.SearchProviderImpl;exports.useSearch=e.useSearch;exports.ModalPrimitive=c;exports.ModalProvider=t.ModalProvider;exports.useModal=t.useModal;exports.ChatButtonPrimitive=s;exports.SearchBarPrimitive=u;exports.ChatBubblePrimitive=h;exports.DataSummaryPrimitive=m;exports.ChatHistoryPrimitive=v;
|
|
@@ -10,3 +10,4 @@ export * as ChatButtonPrimitive from './chat-button';
|
|
|
10
10
|
export * as SearchBarPrimitive from './searchbar';
|
|
11
11
|
export * as ChatBubblePrimitive from './chat-bubble';
|
|
12
12
|
export * as DataSummaryPrimitive from './data-summaries';
|
|
13
|
+
export * as ChatHistoryPrimitive from './chat-history';
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import { ikp as h, jsxFactory as
|
|
1
|
+
import { ikp as h, jsxFactory as f } from "./factory.js";
|
|
2
2
|
import * as r from "./embedded-chat.js";
|
|
3
3
|
import * as e from "./sidebar-chat/index.js";
|
|
4
|
-
import { ChatProvider as
|
|
4
|
+
import { ChatProvider as P, useChat as c } from "./embedded-chat/chat-provider.js";
|
|
5
5
|
import * as a from "./embedded-search.js";
|
|
6
|
-
import { SearchProvider as
|
|
7
|
-
import * as
|
|
8
|
-
import { ModalProvider as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
6
|
+
import { SearchProvider as b, SearchProviderImpl as u, useSearch as C } from "./embedded-search/search-provider.js";
|
|
7
|
+
import * as t from "./modal.js";
|
|
8
|
+
import { ModalProvider as n, useModal as B } from "./modal/modal-provider.js";
|
|
9
|
+
import * as i from "./chat-button.js";
|
|
10
|
+
import * as o from "./searchbar.js";
|
|
11
11
|
import * as m from "./chat-bubble/index.js";
|
|
12
12
|
import * as d from "./data-summaries.js";
|
|
13
|
+
import * as s from "./chat-history/index.js";
|
|
13
14
|
export {
|
|
14
15
|
m as ChatBubblePrimitive,
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
i as ChatButtonPrimitive,
|
|
17
|
+
s as ChatHistoryPrimitive,
|
|
18
|
+
P as ChatProvider,
|
|
17
19
|
d as DataSummaryPrimitive,
|
|
18
20
|
r as EmbeddedChatPrimitive,
|
|
19
21
|
a as EmbeddedSearchPrimitive,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
t as ModalPrimitive,
|
|
23
|
+
n as ModalProvider,
|
|
24
|
+
o as SearchBarPrimitive,
|
|
25
|
+
b as SearchProvider,
|
|
26
|
+
u as SearchProviderImpl,
|
|
25
27
|
e as SidebarChatPrimitive,
|
|
26
28
|
h as ikp,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
f as jsxFactory,
|
|
30
|
+
c as useChat,
|
|
31
|
+
B as useModal,
|
|
32
|
+
C as useSearch
|
|
31
33
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),E=require("./use-local-storage.cjs"),T=require("./use-inkeep-api-client.cjs"),b=30*1e3,d=()=>{},g=async()=>({}),F=({baseUrl:o,appId:n,getCaptchaHeader:A,invalidateCaptcha:S,optOutAllAnalytics:m})=>{const p=n&&!m?`inkeep_session_${n}`:null,[u,f]=E.useLocalStorage(p),{fetchWithAuth:h}=T.useInkeepApiClient({appId:n,authToken:void 0,getCaptchaHeader:A??g,invalidateCaptcha:S??d}),i=e.useRef(o);i.current=o;const a=e.useRef(n);a.current=n;const y=e.useRef(f);y.current=f;const R=e.useRef(h);R.current=h;const s=e.useRef(null),c=e.useCallback(async t=>{if(!i.current||!a.current)return null;if(!t&&s.current)return s.current;const w=`${i.current}/run/auth/apps/${a.current}/anonymous-session`,k=(async()=>{try{const r=await R.current(w,{method:"POST",headers:{"Content-Type":"application/json"},signal:t});if(!r.ok)throw new Error(`Failed to fetch anonymous session: ${r.status}`);const l=await r.json();return y.current({token:l.token,expiresAt:l.expiresAt}),l.token}catch(r){return r instanceof Error&&r.name==="AbortError"||console.error("[useAnonymousSession]",r),null}finally{t||(s.current=null)}})();return t||(s.current=k),k},[]);e.useEffect(()=>{if(!o||!n||u&&new Date(u.expiresAt).getTime()-b>Date.now()||s.current)return;const t=new AbortController;return c(t.signal),()=>t.abort()},[o,n,u,c]);const C=e.useCallback(()=>c(),[c]);return{sessionToken:u?.token??null,refreshSession:C}};exports.useAnonymousSession=F;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface UseAnonymousSessionOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
appId?: string;
|
|
4
|
+
getCaptchaHeader?: () => Promise<Record<string, string>>;
|
|
5
|
+
invalidateCaptcha?: () => void;
|
|
6
|
+
optOutAllAnalytics?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useAnonymousSession: ({ baseUrl, appId, getCaptchaHeader, invalidateCaptcha, optOutAllAnalytics, }: UseAnonymousSessionOptions) => {
|
|
9
|
+
sessionToken: string | null;
|
|
10
|
+
refreshSession: () => Promise<string | null>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef as o, useCallback as k, useEffect as F } from "react";
|
|
3
|
+
import { useLocalStorage as T } from "./use-local-storage.js";
|
|
4
|
+
import { useInkeepApiClient as x } from "./use-inkeep-api-client.js";
|
|
5
|
+
const _ = 30 * 1e3, $ = () => {
|
|
6
|
+
}, d = async () => ({}), D = ({
|
|
7
|
+
baseUrl: s,
|
|
8
|
+
appId: e,
|
|
9
|
+
getCaptchaHeader: A,
|
|
10
|
+
invalidateCaptcha: R,
|
|
11
|
+
optOutAllAnalytics: S
|
|
12
|
+
}) => {
|
|
13
|
+
const w = e && !S ? `inkeep_session_${e}` : null, [c, l] = T(w), { fetchWithAuth: h } = x({
|
|
14
|
+
appId: e,
|
|
15
|
+
authToken: void 0,
|
|
16
|
+
getCaptchaHeader: A ?? d,
|
|
17
|
+
invalidateCaptcha: R ?? $
|
|
18
|
+
}), i = o(s);
|
|
19
|
+
i.current = s;
|
|
20
|
+
const a = o(e);
|
|
21
|
+
a.current = e;
|
|
22
|
+
const m = o(l);
|
|
23
|
+
m.current = l;
|
|
24
|
+
const p = o(h);
|
|
25
|
+
p.current = h;
|
|
26
|
+
const r = o(null), u = k(async (n) => {
|
|
27
|
+
if (!i.current || !a.current) return null;
|
|
28
|
+
if (!n && r.current) return r.current;
|
|
29
|
+
const E = `${i.current}/run/auth/apps/${a.current}/anonymous-session`, y = (async () => {
|
|
30
|
+
try {
|
|
31
|
+
const t = await p.current(E, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "Content-Type": "application/json" },
|
|
34
|
+
signal: n
|
|
35
|
+
});
|
|
36
|
+
if (!t.ok) throw new Error(`Failed to fetch anonymous session: ${t.status}`);
|
|
37
|
+
const f = await t.json();
|
|
38
|
+
return m.current({ token: f.token, expiresAt: f.expiresAt }), f.token;
|
|
39
|
+
} catch (t) {
|
|
40
|
+
return t instanceof Error && t.name === "AbortError" || console.error("[useAnonymousSession]", t), null;
|
|
41
|
+
} finally {
|
|
42
|
+
n || (r.current = null);
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
return n || (r.current = y), y;
|
|
46
|
+
}, []);
|
|
47
|
+
F(() => {
|
|
48
|
+
if (!s || !e || c && new Date(c.expiresAt).getTime() - _ > Date.now() || r.current) return;
|
|
49
|
+
const n = new AbortController();
|
|
50
|
+
return u(n.signal), () => n.abort();
|
|
51
|
+
}, [s, e, c, u]);
|
|
52
|
+
const C = k(() => u(), [u]);
|
|
53
|
+
return { sessionToken: c?.token ?? null, refreshSession: C };
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
D as useAnonymousSession
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),v=require("./use-inkeep-api-client.cjs"),C=()=>{},p=({baseUrl:o,appId:s,authToken:n,getCaptchaHeader:a,invalidateCaptcha:i,refreshSession:c})=>{const{fetchWithAuth:t}=v.useInkeepApiClient({appId:s,authToken:n,getCaptchaHeader:a,invalidateCaptcha:i??C,refreshSession:c});return{loadConversation:d.useCallback(async(u,l)=>{if(!o||!n)return null;try{const e=`${o}/run/v1/conversations/${u}`,r=await t(e,{signal:l});if(!r.ok)throw new Error(`Failed to load conversation: ${r.status}`);return(await r.json()).data?.messages??[]}catch(e){return e instanceof Error&&e.name==="AbortError"||console.error("[useConversationLoader]",e),null}},[o,n,t])}};exports.useConversationLoader=p;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Message } from '../../types/index.ts';
|
|
2
|
+
interface UseConversationLoaderOptions {
|
|
3
|
+
baseUrl: string | undefined;
|
|
4
|
+
appId: string | undefined;
|
|
5
|
+
authToken: string | null;
|
|
6
|
+
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
|
+
invalidateCaptcha?: () => void;
|
|
8
|
+
refreshSession?: () => Promise<string | null>;
|
|
9
|
+
}
|
|
10
|
+
export declare const useConversationLoader: ({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseConversationLoaderOptions) => {
|
|
11
|
+
loadConversation: (conversationId: string, signal?: AbortSignal) => Promise<Message[] | null>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as d } from "react";
|
|
3
|
+
import { useInkeepApiClient as v } from "./use-inkeep-api-client.js";
|
|
4
|
+
const f = () => {
|
|
5
|
+
}, w = ({
|
|
6
|
+
baseUrl: r,
|
|
7
|
+
appId: s,
|
|
8
|
+
authToken: n,
|
|
9
|
+
getCaptchaHeader: a,
|
|
10
|
+
invalidateCaptcha: i,
|
|
11
|
+
refreshSession: c
|
|
12
|
+
}) => {
|
|
13
|
+
const { fetchWithAuth: e } = v({
|
|
14
|
+
appId: s,
|
|
15
|
+
authToken: n,
|
|
16
|
+
getCaptchaHeader: a,
|
|
17
|
+
invalidateCaptcha: i ?? f,
|
|
18
|
+
refreshSession: c
|
|
19
|
+
});
|
|
20
|
+
return { loadConversation: d(
|
|
21
|
+
async (l, u) => {
|
|
22
|
+
if (!r || !n) return null;
|
|
23
|
+
try {
|
|
24
|
+
const o = `${r}/run/v1/conversations/${l}`, t = await e(o, { signal: u });
|
|
25
|
+
if (!t.ok) throw new Error(`Failed to load conversation: ${t.status}`);
|
|
26
|
+
return (await t.json()).data?.messages ?? [];
|
|
27
|
+
} catch (o) {
|
|
28
|
+
return o instanceof Error && o.name === "AbortError" || console.error("[useConversationLoader]", o), null;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[r, n, e]
|
|
32
|
+
) };
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
w as useConversationLoader
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function y(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 H(e){if(!e)return{};if(e instanceof Headers){const r={};return e.forEach((t,c)=>{r[c]=t}),r}return Array.isArray(e)?Object.fromEntries(e):e}function p(e,r,t,c){return{...e?{"x-inkeep-app-id":e}:{},...r?{Authorization:`Bearer ${r}`}:{},...H(c),...t}}function g({appId:e,authToken:r,getCaptchaHeader:t,invalidateCaptcha:c,refreshSession:R}){const a=u.useRef(e);a.current=e;const i=u.useRef(r);i.current=r;const o=u.useRef(t);o.current=t;const w=u.useRef(c);w.current=c;const h=u.useRef(R);return h.current=R,{fetchWithAuth:u.useCallback(async(l,s)=>{const C=await o.current(),j=p(a.current,i.current,C,s?.headers),n=await fetch(l,{...s,headers:j});if(n.status!==400&&n.status!==401)return n;let A;try{A=await n.clone().json()}catch{return n}const k=y(n.status,A);if(k==="pow"){w.current();const f=await o.current(),d=p(a.current,i.current,f,s?.headers);return fetch(l,{...s,headers:d})}if(k==="session"&&h.current){const f=await h.current();if(!f)return n;const d=await o.current(),E=p(a.current,f,d,s?.headers);return fetch(l,{...s,headers:E})}return n},[])}}exports.parseAuthError=y;exports.useInkeepApiClient=g;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface UseInkeepApiClientOptions {
|
|
2
|
+
appId: string | undefined;
|
|
3
|
+
/** The bearer token to send as Authorization — pass undefined for unauthenticated calls. */
|
|
4
|
+
authToken: string | null | undefined;
|
|
5
|
+
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
6
|
+
invalidateCaptcha: () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Called when a 401 session error is detected.
|
|
9
|
+
* Should refresh the anonymous session and return the new token, or null on failure.
|
|
10
|
+
* Hook point for future rolling-token support — pass undefined to skip session retry.
|
|
11
|
+
*/
|
|
12
|
+
refreshSession?: () => Promise<string | null>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parses an API error response body to determine the failure type.
|
|
16
|
+
*
|
|
17
|
+
* The Run API returns:
|
|
18
|
+
* - 400 + detail containing "challenge" or "proof-of-work" → PoW failure
|
|
19
|
+
* - 401 + detail matching JWT/bearer messages → session token failure
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseAuthError(status: number, body: unknown): 'pow' | 'session' | null;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a stable `fetchWithAuth` function that automatically:
|
|
24
|
+
* - Injects auth headers (x-inkeep-app-id, Authorization, x-inkeep-challenge-solution)
|
|
25
|
+
* - Retries once on PoW errors (400) with a fresh captcha solution
|
|
26
|
+
* - Retries once on session errors (401) by refreshing the session token (when refreshSession is provided)
|
|
27
|
+
*
|
|
28
|
+
* All options are kept in refs so `fetchWithAuth` is created once and never needs to be re-created.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useInkeepApiClient({ appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseInkeepApiClientOptions): {
|
|
31
|
+
fetchWithAuth: (url: string, init?: RequestInit) => Promise<Response>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef as u, useCallback as y } from "react";
|
|
3
|
+
function E(e, r) {
|
|
4
|
+
if (e === 400 && typeof r == "object" && r !== null) {
|
|
5
|
+
const t = (r.detail ?? "").toLowerCase();
|
|
6
|
+
if (t.includes("challenge") || t.includes("proof-of-work")) return "pow";
|
|
7
|
+
}
|
|
8
|
+
if (e === 401 && typeof r == "object" && r !== null) {
|
|
9
|
+
const t = r.detail ?? "";
|
|
10
|
+
if (t.includes("Invalid end-user JWT") || t.includes("Bearer token required"))
|
|
11
|
+
return "session";
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function m(e) {
|
|
16
|
+
if (!e) return {};
|
|
17
|
+
if (e instanceof Headers) {
|
|
18
|
+
const r = {};
|
|
19
|
+
return e.forEach((t, c) => {
|
|
20
|
+
r[c] = t;
|
|
21
|
+
}), r;
|
|
22
|
+
}
|
|
23
|
+
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
24
|
+
}
|
|
25
|
+
function p(e, r, t, c) {
|
|
26
|
+
return {
|
|
27
|
+
...e ? { "x-inkeep-app-id": e } : {},
|
|
28
|
+
...r ? { Authorization: `Bearer ${r}` } : {},
|
|
29
|
+
...m(c),
|
|
30
|
+
// captcha last — must not be overridden by caller headers
|
|
31
|
+
...t
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function x({
|
|
35
|
+
appId: e,
|
|
36
|
+
authToken: r,
|
|
37
|
+
getCaptchaHeader: t,
|
|
38
|
+
invalidateCaptcha: c,
|
|
39
|
+
refreshSession: w
|
|
40
|
+
}) {
|
|
41
|
+
const a = u(e);
|
|
42
|
+
a.current = e;
|
|
43
|
+
const i = u(r);
|
|
44
|
+
i.current = r;
|
|
45
|
+
const o = u(t);
|
|
46
|
+
o.current = t;
|
|
47
|
+
const A = u(c);
|
|
48
|
+
A.current = c;
|
|
49
|
+
const h = u(w);
|
|
50
|
+
return h.current = w, { fetchWithAuth: y(async (d, s) => {
|
|
51
|
+
const C = await o.current(), H = p(
|
|
52
|
+
a.current,
|
|
53
|
+
i.current,
|
|
54
|
+
C,
|
|
55
|
+
s?.headers
|
|
56
|
+
), n = await fetch(d, { ...s, headers: H });
|
|
57
|
+
if (n.status !== 400 && n.status !== 401) return n;
|
|
58
|
+
let R;
|
|
59
|
+
try {
|
|
60
|
+
R = await n.clone().json();
|
|
61
|
+
} catch {
|
|
62
|
+
return n;
|
|
63
|
+
}
|
|
64
|
+
const k = E(n.status, R);
|
|
65
|
+
if (k === "pow") {
|
|
66
|
+
A.current();
|
|
67
|
+
const f = await o.current(), l = p(
|
|
68
|
+
a.current,
|
|
69
|
+
i.current,
|
|
70
|
+
f,
|
|
71
|
+
s?.headers
|
|
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 });
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
}, []) };
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
E as parseAuthError,
|
|
86
|
+
x as useInkeepApiClient
|
|
87
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),u=t=>{const[l,o]=r.useState(()=>{if(!t)return null;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):null}catch{return null}}),a=r.useCallback(e=>{if(o(e),!!t)try{e===null?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return[l,a]};exports.useLocalStorage=u;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syncs a value with localStorage. Pass `null` as the key to disable persistence
|
|
3
|
+
* (state still works in-memory but nothing is read from or written to localStorage).
|
|
4
|
+
*
|
|
5
|
+
* Gracefully handles environments where localStorage is unavailable (e.g. private
|
|
6
|
+
* browsing, iframe sandboxing, storage quota exceeded).
|
|
7
|
+
*/
|
|
8
|
+
export declare const useLocalStorage: <T>(key: string | null) => [T | null, (value: T | null) => void];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as n, useCallback as a } from "react";
|
|
3
|
+
const u = (t) => {
|
|
4
|
+
const [r, l] = n(() => {
|
|
5
|
+
if (!t) return null;
|
|
6
|
+
try {
|
|
7
|
+
const e = localStorage.getItem(t);
|
|
8
|
+
return e !== null ? JSON.parse(e) : null;
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}), o = a(
|
|
13
|
+
(e) => {
|
|
14
|
+
if (l(e), !!t)
|
|
15
|
+
try {
|
|
16
|
+
e === null ? localStorage.removeItem(t) : localStorage.setItem(t, JSON.stringify(e));
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
[t]
|
|
21
|
+
);
|
|
22
|
+
return [r, o];
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
u as useLocalStorage
|
|
26
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./providers/attachment-item-provider.cjs"),C=require("./providers/attachments-bar-provider.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./providers/attachment-item-provider.cjs"),C=require("./providers/attachments-bar-provider.cjs"),h=require("./providers/base-events-provider.cjs"),n=require("./providers/chat-form-provider.cjs"),l=require("./providers/chat-history-provider.cjs"),i=require("./providers/config-provider.cjs"),p=require("./providers/feedback-item-provider.cjs"),v=require("./providers/feedback-provider.cjs"),P=require("./providers/form-field-provider.cjs"),d=require("./providers/help-menu-provider.cjs"),I=require("./providers/markdown-provider.cjs"),S=require("./providers/message-attachments-provider.cjs"),u=require("./providers/message-provider.cjs"),y=require("./providers/root-provider.cjs"),b=require("./providers/source-item-provider.cjs"),F=require("./providers/theme-provider.cjs"),q=require("./providers/widget-provider.cjs"),t=require("./providers/sidebar-chat-provider.cjs"),s=require("./providers/chat-bubble-provider.cjs"),g=require("./components/factory.cjs"),A=require("./components/embedded-chat.cjs"),f=require("./components/sidebar-chat/index.cjs"),M=require("./components/embedded-chat/chat-provider.cjs"),R=require("./components/embedded-search.cjs"),m=require("./components/embedded-search/search-provider.cjs"),w=require("./components/modal.cjs"),B=require("./components/modal/modal-provider.cjs"),H=require("./components/chat-button.cjs"),O=require("./components/searchbar.cjs"),E=require("./components/chat-bubble/index.cjs"),T=require("./components/data-summaries.cjs"),W=require("./components/chat-history/index.cjs"),x=require("./hooks/use-boolean.cjs"),D=require("./hooks/use-component-classnames.cjs"),z=require("./hooks/use-container-size.cjs"),L=require("./hooks/use-inkeep-open-state.cjs"),j=require("./hooks/use-copy-to-clipboard.cjs"),Q=require("./hooks/use-instant-update.cjs"),U=require("./hooks/use-is-mounted.cjs"),$=require("./hooks/use-media-query.cjs"),K=require("./hooks/use-resize-observer.cjs"),N=require("./hooks/use-scrolling-fades.cjs"),G=require("./hooks/use-settle-action.cjs"),J=require("./hooks/use-simple-scroll.cjs"),o=require("./utils/misc.cjs"),e=require("./utils/component-ids.cjs"),k=require("./utils/compose-refs.cjs"),V=require("./utils/merge-props.cjs"),X=require("./atoms/portal.cjs"),Y=require("./atoms/icons/custom-icon.cjs"),Z=require("./atoms/icons/built-in-icon-renderer.cjs"),_=require("./atoms/portal-with-theme.cjs"),r=require("./atoms/cmdk/index.cjs"),ee=require("./atoms/error-boundary.cjs"),a=require("./atoms/shadow/context.cjs");exports.AttachmentItemProvider=c.AttachmentItemProvider;exports.useAttachmentItem=c.useAttachmentItem;exports.AttachmentsBarProvider=C.AttachmentsBarProvider;exports.useAttachmentsBar=C.useAttachmentsBar;exports.BaseEventsProvider=h.BaseEventsProvider;exports.useBaseEvents=h.useBaseEvents;exports.ChatFormProvider=n.ChatFormProvider;exports.useChatForm=n.useChatForm;exports.useChatFormState=n.useChatFormState;exports.ChatHistoryProvider=l.ChatHistoryProvider;exports.useChatHistory=l.useChatHistory;exports.InkeepConfigProvider=i.InkeepConfigProvider;exports.WebWidgetInteractionType=i.WebWidgetInteractionType;exports.useInkeepConfig=i.useInkeepConfig;exports.FeedbackItemProvider=p.FeedbackItemProvider;exports.useFeedbackItem=p.useFeedbackItem;exports.FeedbackProvider=v.FeedbackProvider;exports.useMessageFeedback=v.useMessageFeedback;exports.FormFieldProvider=P.FormFieldProvider;exports.useFormField=P.useFormField;exports.HelpMenuProvider=d.HelpMenuProvider;exports.useHelpMenu=d.useHelpMenu;exports.useHelpMenuState=d.useHelpMenuState;exports.ChatMarkdownProvider=I.ChatMarkdownProvider;exports.useChatMarkdown=I.useChatMarkdown;exports.MessageAttachmentsProvider=S.MessageAttachmentsProvider;exports.useMessageAttachments=S.useMessageAttachments;exports.MessageProvider=u.MessageProvider;exports.useMessage=u.useMessage;exports.useOptionalMessage=u.useOptionalMessage;exports.RootProvider=y.RootProvider;exports.SourceItemProvider=b.SourceItemProvider;exports.useSourceItem=b.useSourceItem;exports.ThemeProvider=F.ThemeProvider;exports.WidgetProvider=q.WidgetProvider;exports.useWidget=q.useWidget;exports.SidebarChatProvider=t.SidebarChatProvider;exports.useInkeepSidebarChat=t.useInkeepSidebarChat;exports.useOptionalSidebarChat=t.useOptionalSidebarChat;exports.useSidebarChat=t.useSidebarChat;exports.ChatBubbleProvider=s.ChatBubbleProvider;exports.useChatBubble=s.useChatBubble;exports.useInkeepChatBubble=s.useInkeepChatBubble;exports.useOptionalChatBubble=s.useOptionalChatBubble;exports.ikp=g.ikp;exports.jsxFactory=g.jsxFactory;exports.EmbeddedChatPrimitive=A;exports.SidebarChatPrimitive=f;exports.ChatProvider=M.ChatProvider;exports.useChat=M.useChat;exports.EmbeddedSearchPrimitive=R;exports.SearchProvider=m.SearchProvider;exports.SearchProviderImpl=m.SearchProviderImpl;exports.useSearch=m.useSearch;exports.ModalPrimitive=w;exports.ModalProvider=B.ModalProvider;exports.useModal=B.useModal;exports.ChatButtonPrimitive=H;exports.SearchBarPrimitive=O;exports.ChatBubblePrimitive=E;exports.DataSummaryPrimitive=T;exports.ChatHistoryPrimitive=W;exports.useBoolean=x.useBoolean;exports.useComponentClassNames=D.useComponentClassNames;exports.useContainerSize=z.useContainerSize;exports.useInkeepOpenState=L.useInkeepOpenState;exports.useCopyToClipboard=j.useCopyToClipboard;exports.useInstantUpdate=Q.useInstantUpdate;exports.useIsMounted=U.useIsMounted;exports.useMediaQuery=$.useMediaQuery;exports.useResizeObserver=K.useResizeObserver;exports.useScrollingFades=N.useScrollingFades;exports.useSettleAction=G.useSettleAction;exports.useSimpleScroll=J.useSimpleScroll;exports.callAll=o.callAll;exports.dataAttr=o.dataAttr;exports.getInitials=o.getInitials;exports.getMessageContent=o.getMessageContent;exports.isString=o.isString;exports.maybeRender=o.maybeRender;exports.toKebabCase=o.toKebabCase;exports.ChatBubbleComponentIds=e.ChatBubbleComponentIds;exports.DataSummaryComponentIds=e.DataSummaryComponentIds;exports.SearchBarComponentIds=e.SearchBarComponentIds;exports.SidebarChatComponentIds=e.SidebarChatComponentIds;exports.aiChatComponentIds=e.aiChatComponentIds;exports.aiChatHistoryComponentIds=e.aiChatHistoryComponentIds;exports.aiSearchComponentIds=e.aiSearchComponentIds;exports.chatButtonComponentIds=e.chatButtonComponentIds;exports.componentIDs=e.componentIDs;exports.markDownComponentIds=e.markDownComponentIds;exports.miscellanousComponentIds=e.miscellanousComponentIds;exports.modalComponentIds=e.modalComponentIds;exports.composeRefs=k.composeRefs;exports.useComposedRefs=k.useComposedRefs;exports.mergeProps=V.mergeProps;exports.Portal=X.Portal;exports.CustomIcon=Y.CustomIcon;exports.BuiltInIconRenderer=Z.BuiltInIconRenderer;exports.PortalWithTheme=_.PortalWithTheme;exports.Command=r.Command;exports.CommandDialog=r.CommandDialog;exports.CommandEmpty=r.CommandEmpty;exports.CommandInput=r.CommandInput;exports.CommandItem=r.CommandItem;exports.CommandList=r.CommandList;exports.CommandLoading=r.CommandLoading;exports.CommandRoot=r.CommandRoot;exports.CommandSeparator=r.CommandSeparator;exports.defaultFilter=r.defaultFilter;exports.useCommandState=r.useCommandState;exports.useCommandStore=r.useCommandStore;exports.ErrorBoundary=ee.ErrorBoundary;exports.InkeepShadow=a.InkeepShadow;exports.InkeepShadowProvider=a.InkeepShadowProvider;exports.ShadowContext=a.ShadowContext;exports.useShadow=a.useShadow;
|