@inkeep/agents-ui 0.15.16 → 0.15.17

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.
@@ -1 +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;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),b=require("./use-local-storage.cjs"),_=require("./use-inkeep-api-client.cjs"),M=30*1e3,$=2147483647,D=()=>{},F=async()=>({});function C(n){return new Date(n.expiresAt).getTime()-M<=Date.now()}const L=({baseUrl:n,appId:t,getCaptchaHeader:d,invalidateCaptcha:g,optOutAllAnalytics:p})=>{const w=t&&!p?`inkeep_session_${t}`:null,[u,R]=b.useLocalStorage(w),{fetchWithAuth:k}=_.useInkeepApiClient({appId:t,authToken:void 0,getCaptchaHeader:d??F,invalidateCaptcha:g??D}),l=e.useRef(n);l.current=n;const h=e.useRef(t);h.current=t;const c=e.useRef(u);c.current=u;const S=e.useRef(R);S.current=R;const T=e.useRef(k);T.current=k;const f=e.useRef(null),s=e.useCallback(async r=>{if(!l.current||!h.current)return null;if(!r&&f.current)return f.current;const o=`${l.current}/run/auth/apps/${h.current}/anonymous-session`,a=(async()=>{try{const i={"Content-Type":"application/json"},v=c.current?.token;v&&(i.Authorization=`Bearer ${v}`);const A=await T.current(o,{method:"POST",headers:i,signal:r});if(!A.ok)throw new Error(`Failed to fetch anonymous session: ${A.status}`);const y=await A.json();return S.current({token:y.token,expiresAt:y.expiresAt}),y.token}catch(i){return i instanceof Error&&i.name==="AbortError"||console.error("[anonymous-session] fetch failed",i),null}finally{r||(f.current=null)}})();return r||(f.current=a),a},[]),E=e.useRef(!1);e.useEffect(()=>{if(!n||!t)return;const r=!E.current;if(E.current=!0,!r&&c.current&&!C(c.current)||f.current)return;const o=new AbortController;return s(o.signal),()=>o.abort()},[n,t,s]),e.useEffect(()=>{if(!n||!t||!u?.expiresAt)return;const m=new Date(u.expiresAt).getTime()-M-Date.now();if(m<=0)return;const a=setTimeout(()=>s(),Math.min(m,$));return()=>clearTimeout(a)},[n,t,u?.expiresAt,s]),e.useEffect(()=>{if(!n||!t)return;const r=()=>{if(document.visibilityState!=="visible")return;const o=c.current;(!o||C(o))&&s()};return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[n,t,s]);const x=e.useCallback(()=>s(),[s]);return{sessionToken:u?.token??null,refreshSession:x}};exports.useAnonymousSession=L;
@@ -1,57 +1,82 @@
1
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,
2
+ import { useRef as s, useCallback as E, useEffect as k } from "react";
3
+ import { useLocalStorage as D } from "./use-local-storage.js";
4
+ import { useInkeepApiClient as F } from "./use-inkeep-api-client.js";
5
+ const M = 30 * 1e3, b = 2147483647, L = () => {
6
+ }, j = async () => ({});
7
+ function w(t) {
8
+ return new Date(t.expiresAt).getTime() - M <= Date.now();
9
+ }
10
+ const X = ({
11
+ baseUrl: t,
8
12
  appId: e,
9
- getCaptchaHeader: A,
10
- invalidateCaptcha: R,
11
- optOutAllAnalytics: S
13
+ getCaptchaHeader: C,
14
+ invalidateCaptcha: d,
15
+ optOutAllAnalytics: g
12
16
  }) => {
13
- const w = e && !S ? `inkeep_session_${e}` : null, [c, l] = T(w), { fetchWithAuth: h } = x({
17
+ const _ = e && !g ? `inkeep_session_${e}` : null, [i, T] = D(_), { fetchWithAuth: R } = F({
14
18
  appId: e,
15
19
  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 () => {
20
+ getCaptchaHeader: C ?? j,
21
+ invalidateCaptcha: d ?? L
22
+ }), l = s(t);
23
+ l.current = t;
24
+ const h = s(e);
25
+ h.current = e;
26
+ const u = s(i);
27
+ u.current = i;
28
+ const S = s(T);
29
+ S.current = T;
30
+ const p = s(R);
31
+ p.current = R;
32
+ const f = s(null), r = E(async (n) => {
33
+ if (!l.current || !h.current) return null;
34
+ if (!n && f.current)
35
+ return f.current;
36
+ const o = `${l.current}/run/auth/apps/${h.current}/anonymous-session`, a = (async () => {
30
37
  try {
31
- const t = await p.current(E, {
38
+ const c = { "Content-Type": "application/json" }, x = u.current?.token;
39
+ x && (c.Authorization = `Bearer ${x}`);
40
+ const A = await p.current(o, {
32
41
  method: "POST",
33
- headers: { "Content-Type": "application/json" },
42
+ headers: c,
34
43
  signal: n
35
44
  });
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;
45
+ if (!A.ok) throw new Error(`Failed to fetch anonymous session: ${A.status}`);
46
+ const y = await A.json();
47
+ return S.current({ token: y.token, expiresAt: y.expiresAt }), y.token;
48
+ } catch (c) {
49
+ return c instanceof Error && c.name === "AbortError" || console.error("[anonymous-session] fetch failed", c), null;
41
50
  } finally {
42
- n || (r.current = null);
51
+ n || (f.current = null);
43
52
  }
44
53
  })();
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
+ return n || (f.current = a), a;
55
+ }, []), v = s(!1);
56
+ k(() => {
57
+ if (!t || !e) return;
58
+ const n = !v.current;
59
+ if (v.current = !0, !n && u.current && !w(u.current) || f.current) return;
60
+ const o = new AbortController();
61
+ return r(o.signal), () => o.abort();
62
+ }, [t, e, r]), k(() => {
63
+ if (!t || !e || !i?.expiresAt) return;
64
+ const m = new Date(i.expiresAt).getTime() - M - Date.now();
65
+ if (m <= 0) return;
66
+ const a = setTimeout(() => r(), Math.min(m, b));
67
+ return () => clearTimeout(a);
68
+ }, [t, e, i?.expiresAt, r]), k(() => {
69
+ if (!t || !e) return;
70
+ const n = () => {
71
+ if (document.visibilityState !== "visible") return;
72
+ const o = u.current;
73
+ (!o || w(o)) && r();
74
+ };
75
+ return document.addEventListener("visibilitychange", n), () => document.removeEventListener("visibilitychange", n);
76
+ }, [t, e, r]);
77
+ const $ = E(() => r(), [r]);
78
+ return { sessionToken: i?.token ?? null, refreshSession: $ };
54
79
  };
55
80
  export {
56
- D as useAnonymousSession
81
+ X as useAnonymousSession
57
82
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.15",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.17",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
@@ -5,7 +5,7 @@ import { useInkeepConfig as g } from "./config-provider.js";
5
5
  const a = d(void 0), P = ({ children: e }) => {
6
6
  const { baseSettings: t, componentType: o } = g(), { tags: s, analyticsProperties: n } = t, r = u(
7
7
  () => ({
8
- widgetLibraryVersion: "0.15.15",
8
+ widgetLibraryVersion: "0.15.17",
9
9
  componentType: o,
10
10
  tags: s
11
11
  }),
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("react/jsx-runtime"),e=require("react"),Y=require("../components/embedded-chat/chat-provider.cjs"),N=require("./config-provider.cjs"),ee=require("../hooks/use-inkeep-api-client.cjs"),F=e.createContext(void 0),D=25;function te(t){const{stop:a,clear:c,conversationId:u,isStreaming:H,loadAndRestoreSession:P,sessionToken:f,refreshSession:W,getCaptchaHeader:G,invalidateCaptcha:K}=Y.useChat(),{aiChatSettings:U}=N.useInkeepConfig(),{baseUrl:h,appId:k,apiKey:Z}=U,r=!Z&&!!k,C=f,{fetchWithAuth:I}=ee.useInkeepApiClient({appId:k,authToken:C,getCaptchaHeader:G,invalidateCaptcha:K,refreshSession:W}),[p,S]=e.useState(!1),[R,E]=e.useState([]),[g,x]=e.useState(!1),[m,_]=e.useState(0),[v,z]=e.useState(!1),b=e.useRef(!1),q=e.useRef(null),j=e.useRef([]);j.current=R;const M=e.useRef(I);M.current=I;const o=e.useCallback(async(s,i=!1)=>{if(!(!h||!C||!r)){x(!0);try{const w=`${h}/run/v1/conversations?page=${s+1}&limit=${D}`,y=await M.current(w);if(!y.ok)throw new Error(`Failed to fetch conversations: ${y.status}`);const L=await y.json(),d=(L.data??[]).map(n=>({id:n.id,title:n.title??"",createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt)}));E(n=>{if(s===0&&!i)return d;if(s===0&&i){const l=new Set(d.map(A=>A.id));return[...d,...n.slice(D).filter(A=>!l.has(A.id))]}const V=new Set(n.map(l=>l.id));return[...n,...d.filter(l=>!V.has(l.id))]});const{page:O,pages:T}=L.pagination??{};z(O!=null&&T!=null?O<T:!1),i||_(s)}catch(w){console.error("[useChatHistory] Failed to load conversations:",w)}finally{x(!1)}}},[h,C,r]);e.useEffect(()=>{!p||!f||!r||(t==="stack"?(E([]),o(0)):b.current||(b.current=!0,o(0)))},[p,f,r,t,o]);const $=e.useRef("");e.useEffect(()=>{r&&t==="sidepane"&&(!u||!H||b.current&&$.current!==u&&(j.current.some(s=>s.id===u)||($.current=u,o(0,!0))))},[u,r,t,o,H]);const B=e.useCallback(()=>{!g&&v&&o(m+1)},[g,v,m,o]),J=e.useCallback(()=>{a(),c(),t!=="sidepane"&&S(!1)},[t,a,c]),Q=e.useCallback(async s=>{q.current?.abort();const i=new AbortController;q.current=i,await P(s,i.signal),!i.signal.aborted&&t!=="sidepane"&&S(!1)},[t,P]);return{isEnabled:r,isOpen:p,setIsOpen:S,sessions:R,isLoading:g,hasMore:v,loadMore:B,startNewConversation:J,loadSession:Q}}const se=({layout:t,children:a})=>{const c=te(t);return X.jsx(F.Provider,{value:c,children:typeof a=="function"?a(c):a})},ne=()=>{const t=e.useContext(F);if(!t)throw new Error("useChatHistory must be used within a ChatHistoryProvider");return t};exports.ChatHistoryProvider=se;exports.useChatHistory=ne;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("react/jsx-runtime"),e=require("react"),Y=require("../components/embedded-chat/chat-provider.cjs"),N=require("./config-provider.cjs"),ee=require("../hooks/use-inkeep-api-client.cjs"),F=e.createContext(void 0),D=25;function te(t){const{stop:a,clear:c,conversationId:u,isStreaming:H,loadAndRestoreSession:P,sessionToken:f,refreshSession:W,getCaptchaHeader:G,invalidateCaptcha:K}=Y.useChat(),{aiChatSettings:U}=N.useInkeepConfig(),{baseUrl:h,appId:k,apiKey:Z}=U,o=!Z&&!!k,C=f,{fetchWithAuth:I}=ee.useInkeepApiClient({appId:k,authToken:C,getCaptchaHeader:G,invalidateCaptcha:K,refreshSession:W}),[p,S]=e.useState(!1),[R,E]=e.useState([]),[g,x]=e.useState(!1),[m,_]=e.useState(0),[v,z]=e.useState(!1),b=e.useRef(!1),q=e.useRef(null),j=e.useRef([]);j.current=R;const M=e.useRef(I);M.current=I;const i=e.useCallback(async(s,n=!1)=>{if(!(!h||!C||!o)){n||x(!0);try{const w=`${h}/run/v1/conversations?page=${s+1}&limit=${D}`,y=await M.current(w);if(!y.ok)throw new Error(`Failed to fetch conversations: ${y.status}`);const L=await y.json(),d=(L.data??[]).map(r=>({id:r.id,title:r.title??"",createdAt:new Date(r.createdAt),updatedAt:new Date(r.updatedAt)}));E(r=>{if(s===0&&!n)return d;if(s===0&&n){const l=new Set(d.map(A=>A.id));return[...d,...r.slice(D).filter(A=>!l.has(A.id))]}const V=new Set(r.map(l=>l.id));return[...r,...d.filter(l=>!V.has(l.id))]});const{page:O,pages:T}=L.pagination??{};z(O!=null&&T!=null?O<T:!1),n||_(s)}catch(w){console.error("[useChatHistory] Failed to load conversations:",w)}finally{x(!1)}}},[h,C,o]);e.useEffect(()=>{!p||!f||!o||(t==="stack"?(E([]),i(0)):b.current||(b.current=!0,i(0)))},[p,f,o,t,i]);const $=e.useRef("");e.useEffect(()=>{o&&t==="sidepane"&&(!u||!H||b.current&&$.current!==u&&(j.current.some(s=>s.id===u)||($.current=u,i(0,!0))))},[u,o,t,i,H]);const B=e.useCallback(()=>{!g&&v&&i(m+1)},[g,v,m,i]),J=e.useCallback(()=>{a(),c(),t!=="sidepane"&&S(!1)},[t,a,c]),Q=e.useCallback(async s=>{q.current?.abort();const n=new AbortController;q.current=n,await P(s,n.signal),!n.signal.aborted&&t!=="sidepane"&&S(!1)},[t,P]);return{isEnabled:o,isOpen:p,setIsOpen:S,sessions:R,isLoading:g,hasMore:v,loadMore:B,startNewConversation:J,loadSession:Q}}const se=({layout:t,children:a})=>{const c=te(t);return X.jsx(F.Provider,{value:c,children:typeof a=="function"?a(c):a})},ne=()=>{const t=e.useContext(F);if(!t)throw new Error("useChatHistory must be used within a ChatHistoryProvider");return t};exports.ChatHistoryProvider=se;exports.useChatHistory=ne;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as tt } from "react/jsx-runtime";
3
- import { createContext as et, useContext as st, useState as u, useRef as d, useCallback as h, useEffect as G } from "react";
3
+ import { createContext as et, useContext as st, useState as f, useRef as d, useCallback as h, useEffect as G } from "react";
4
4
  import { useChat as nt } from "../components/embedded-chat/chat-provider.js";
5
5
  import { useInkeepConfig as rt } from "./config-provider.js";
6
6
  import { useInkeepApiClient as ot } from "../hooks/use-inkeep-api-client.js";
@@ -16,70 +16,70 @@ function it(t) {
16
16
  refreshSession: Z,
17
17
  getCaptchaHeader: _,
18
18
  invalidateCaptcha: q
19
- } = nt(), { aiChatSettings: z } = rt(), { baseUrl: C, appId: k, apiKey: B } = z, n = !B && !!k, g = p, { fetchWithAuth: x } = ot({
19
+ } = nt(), { aiChatSettings: z } = rt(), { baseUrl: C, appId: k, apiKey: B } = z, r = !B && !!k, g = p, { fetchWithAuth: x } = ot({
20
20
  appId: k,
21
21
  authToken: g,
22
22
  getCaptchaHeader: _,
23
23
  invalidateCaptcha: q,
24
24
  refreshSession: Z
25
- }), [w, m] = u(!1), [E, R] = u([]), [S, $] = u(!1), [L, J] = u(0), [v, Q] = u(!1), A = d(!1), M = d(null), j = d([]);
25
+ }), [w, m] = f(!1), [E, $] = f([]), [S, L] = f(!1), [M, J] = f(0), [v, Q] = f(!1), A = d(!1), R = d(null), j = d([]);
26
26
  j.current = E;
27
27
  const D = d(x);
28
28
  D.current = x;
29
- const r = h(
30
- async (e, o = !1) => {
31
- if (!(!C || !g || !n)) {
32
- $(!0);
29
+ const o = h(
30
+ async (e, s = !1) => {
31
+ if (!(!C || !g || !r)) {
32
+ s || L(!0);
33
33
  try {
34
34
  const b = `${C}/run/v1/conversations?page=${e + 1}&limit=${K}`, H = await D.current(b);
35
35
  if (!H.ok) throw new Error(`Failed to fetch conversations: ${H.status}`);
36
- const O = await H.json(), l = (O.data ?? []).map((s) => ({
37
- id: s.id,
38
- title: s.title ?? "",
39
- createdAt: new Date(s.createdAt),
40
- updatedAt: new Date(s.updatedAt)
36
+ const O = await H.json(), l = (O.data ?? []).map((n) => ({
37
+ id: n.id,
38
+ title: n.title ?? "",
39
+ createdAt: new Date(n.createdAt),
40
+ updatedAt: new Date(n.updatedAt)
41
41
  }));
42
- R((s) => {
43
- if (e === 0 && !o) return l;
44
- if (e === 0 && o) {
45
- const f = new Set(l.map((I) => I.id));
46
- return [...l, ...s.slice(K).filter((I) => !f.has(I.id))];
42
+ $((n) => {
43
+ if (e === 0 && !s) return l;
44
+ if (e === 0 && s) {
45
+ const u = new Set(l.map((I) => I.id));
46
+ return [...l, ...n.slice(K).filter((I) => !u.has(I.id))];
47
47
  }
48
- const N = new Set(s.map((f) => f.id));
49
- return [...s, ...l.filter((f) => !N.has(f.id))];
48
+ const N = new Set(n.map((u) => u.id));
49
+ return [...n, ...l.filter((u) => !N.has(u.id))];
50
50
  });
51
51
  const { page: T, pages: W } = O.pagination ?? {};
52
- Q(T != null && W != null ? T < W : !1), o || J(e);
52
+ Q(T != null && W != null ? T < W : !1), s || J(e);
53
53
  } catch (b) {
54
54
  console.error("[useChatHistory] Failed to load conversations:", b);
55
55
  } finally {
56
- $(!1);
56
+ L(!1);
57
57
  }
58
58
  }
59
59
  },
60
- [C, g, n]
60
+ [C, g, r]
61
61
  );
62
62
  G(() => {
63
- !w || !p || !n || (t === "stack" ? (R([]), r(0)) : A.current || (A.current = !0, r(0)));
64
- }, [w, p, n, t, r]);
63
+ !w || !p || !r || (t === "stack" ? ($([]), o(0)) : A.current || (A.current = !0, o(0)));
64
+ }, [w, p, r, t, o]);
65
65
  const F = d("");
66
66
  G(() => {
67
- n && t === "sidepane" && (!c || !y || A.current && F.current !== c && (j.current.some((e) => e.id === c) || (F.current = c, r(0, !0))));
68
- }, [c, n, t, r, y]);
67
+ r && t === "sidepane" && (!c || !y || A.current && F.current !== c && (j.current.some((e) => e.id === c) || (F.current = c, o(0, !0))));
68
+ }, [c, r, t, o, y]);
69
69
  const V = h(() => {
70
- !S && v && r(L + 1);
71
- }, [S, v, L, r]), X = h(() => {
70
+ !S && v && o(M + 1);
71
+ }, [S, v, M, o]), X = h(() => {
72
72
  i(), a(), t !== "sidepane" && m(!1);
73
73
  }, [t, i, a]), Y = h(
74
74
  async (e) => {
75
- M.current?.abort();
76
- const o = new AbortController();
77
- M.current = o, await P(e, o.signal), !o.signal.aborted && t !== "sidepane" && m(!1);
75
+ R.current?.abort();
76
+ const s = new AbortController();
77
+ R.current = s, await P(e, s.signal), !s.signal.aborted && t !== "sidepane" && m(!1);
78
78
  },
79
79
  [t, P]
80
80
  );
81
81
  return {
82
- isEnabled: n,
82
+ isEnabled: r,
83
83
  isOpen: w,
84
84
  setIsOpen: m,
85
85
  sessions: E,
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),f=require("merge-anything"),n=require("react"),t=require("../utils/default-settings.cjs"),m=require("../atoms/shadow/context.cjs"),s={ChatButton:"ChatButton",CustomTrigger:"CustomTrigger",SearchBar:"SearchBar",EmbeddedChat:"EmbeddedChat",EmbeddedSearch:"EmbeddedSearch",EmbeddedSearchAndChat:"EmbeddedSearchAndChat",SidebarChat:"SidebarChat"},a={prefix:"ikp",aiChatSettings:t.defaultInkeepAIChatSettings,baseSettings:t.defaultInkeepBaseSettings,searchSettings:t.defaultInkeepSearchSettings,componentType:s.EmbeddedChat},d=n.createContext(a),p=({children:e,value:r})=>{const c=m.useShadow(),u=(o,i,C)=>["baseSettings","searchSettings","aiChatSettings"].includes(C)&&!i?o:i,g={baseSettings:c??{}},h=n.useMemo(()=>f.mergeAndCompare(u,a,g,r??{}),[r]);return S.jsx(d.Provider,{value:h,children:e})},b=()=>{const e=n.useContext(d);if(!e)throw new Error("useInkeepConfig must be used within a ConfigProvider");return e};exports.InkeepConfigProvider=p;exports.WebWidgetInteractionType=s;exports.useInkeepConfig=b;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),b=require("merge-anything"),r=require("react"),n=require("../utils/default-settings.cjs"),f=require("../atoms/shadow/context.cjs"),s={ChatButton:"ChatButton",CustomTrigger:"CustomTrigger",SearchBar:"SearchBar",EmbeddedChat:"EmbeddedChat",EmbeddedSearch:"EmbeddedSearch",EmbeddedSearchAndChat:"EmbeddedSearchAndChat",SidebarChat:"SidebarChat"},o={prefix:"ikp",aiChatSettings:n.defaultInkeepAIChatSettings,baseSettings:n.defaultInkeepBaseSettings,searchSettings:n.defaultInkeepSearchSettings,componentType:s.EmbeddedChat},d=r.createContext(o),p=({children:t,value:i})=>{const c=f.useShadow(),g=(e,a,C)=>["baseSettings","searchSettings","aiChatSettings"].includes(C)&&!a?e:a,u={baseSettings:c??{}},h=r.useMemo(()=>{const e=b.mergeAndCompare(g,o,u,i??{});return e.aiChatSettings?.baseUrl&&(e.aiChatSettings.baseUrl=e.aiChatSettings.baseUrl.replace(/\/+$/,"")),e},[i]);return S.jsx(d.Provider,{value:h,children:t})},m=()=>{const t=r.useContext(d);if(!t)throw new Error("useInkeepConfig must be used within a ConfigProvider");return t};exports.InkeepConfigProvider=p;exports.WebWidgetInteractionType=s;exports.useInkeepConfig=m;
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { jsx as m } from "react/jsx-runtime";
3
- import { mergeAndCompare as C } from "merge-anything";
4
- import { useMemo as g, createContext as u, useContext as f } from "react";
5
- import { defaultInkeepSearchSettings as p, defaultInkeepBaseSettings as S, defaultInkeepAIChatSettings as b } from "../utils/default-settings.js";
6
- import { useShadow as I } from "../atoms/shadow/context.js";
7
- const k = {
2
+ import { jsx as C } from "react/jsx-runtime";
3
+ import { mergeAndCompare as g } from "merge-anything";
4
+ import { useMemo as m, createContext as S, useContext as u } from "react";
5
+ import { defaultInkeepSearchSettings as f, defaultInkeepBaseSettings as p, defaultInkeepAIChatSettings as b } from "../utils/default-settings.js";
6
+ import { useShadow as l } from "../atoms/shadow/context.js";
7
+ const I = {
8
8
  ChatButton: "ChatButton",
9
9
  CustomTrigger: "CustomTrigger",
10
10
  SearchBar: "SearchBar",
@@ -12,26 +12,29 @@ const k = {
12
12
  EmbeddedSearch: "EmbeddedSearch",
13
13
  EmbeddedSearchAndChat: "EmbeddedSearchAndChat",
14
14
  SidebarChat: "SidebarChat"
15
- }, o = {
15
+ }, a = {
16
16
  prefix: "ikp",
17
17
  // Default prefix
18
18
  aiChatSettings: b,
19
- baseSettings: S,
20
- searchSettings: p,
21
- componentType: k.EmbeddedChat
22
- }, a = u(o), A = ({ children: e, value: t }) => {
23
- const i = I(), s = (n, r, h) => ["baseSettings", "searchSettings", "aiChatSettings"].includes(h) && !r ? n : r, d = {
19
+ baseSettings: p,
20
+ searchSettings: f,
21
+ componentType: I.EmbeddedChat
22
+ }, o = S(a), A = ({ children: t, value: n }) => {
23
+ const i = l(), s = (e, r, h) => ["baseSettings", "searchSettings", "aiChatSettings"].includes(h) && !r ? e : r, d = {
24
24
  baseSettings: i ?? {}
25
- }, c = g(() => C(s, o, d, t ?? {}), [t]);
26
- return /* @__PURE__ */ m(a.Provider, { value: c, children: e });
25
+ }, c = m(() => {
26
+ const e = g(s, a, d, n ?? {});
27
+ return e.aiChatSettings?.baseUrl && (e.aiChatSettings.baseUrl = e.aiChatSettings.baseUrl.replace(/\/+$/, "")), e;
28
+ }, [n]);
29
+ return /* @__PURE__ */ C(o.Provider, { value: c, children: t });
27
30
  }, T = () => {
28
- const e = f(a);
29
- if (!e)
31
+ const t = u(o);
32
+ if (!t)
30
33
  throw new Error("useInkeepConfig must be used within a ConfigProvider");
31
- return e;
34
+ return t;
32
35
  };
33
36
  export {
34
37
  A as InkeepConfigProvider,
35
- k as WebWidgetInteractionType,
38
+ I as WebWidgetInteractionType,
36
39
  T as useInkeepConfig
37
40
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("react"),t=require("../styled/components/embedded-chat.cjs"),c=require("../styled/components/chat-history.cjs"),j=require("../styled/components/modal.cjs"),k=require("../styled/components/shadow.cjs"),b=require("../styled/components/message.cjs"),T=require("../primitives/providers/chat-history-provider.cjs"),u=require("../primitives/providers/config-provider.cjs"),B=require("../primitives/providers/root-provider.cjs"),y=require("../primitives/providers/widget-provider.cjs"),C=require("../primitives/components/embedded-chat/chat-provider.cjs"),S=require("../primitives/components/modal/modal-provider.cjs"),h=require("../primitives/utils/misc.cjs"),F=require("../primitives/atoms/portal-with-theme.cjs"),H=require("../primitives/atoms/error-boundary.cjs"),E=require("./modal.cjs"),v=require("./widget-toggle.cjs");function w(r){const{baseSettings:s,aiChatSettings:n}=r;return e.jsx(H.ErrorBoundary,{children:e.jsx(k.Shadow,{wrapperStyles:{height:"inherit",width:"inherit"},children:e.jsx(B.RootProvider,{config:{baseSettings:s,aiChatSettings:n},componentType:u.WebWidgetInteractionType.EmbeddedChat,children:e.jsx(A,{...r})})})})}function I(r){const{children:s,onToggleView:n,isHidden:o,shouldAutoFocusInput:i=!n}=r;return e.jsx(t.Provider,{isHidden:o,shouldAutoFocusInput:i,children:s})}function A(r){return e.jsx(I,{...r,children:e.jsx(M,{...r})})}function M(r){const{onToggleView:s,variant:n,header:o=f}=r,i=S.useModal(),d=y.useWidget(),a=i&&!d?E.ModalContent:m.Fragment;return e.jsx(a,{children:e.jsxs(t.Wrapper,{variant:n??(s?"no-shadow":"container-with-shadow"),"data-composite":h.dataAttr(!!r.onToggleView||i?.isOpen),children:[e.jsx(Q,{}),e.jsxs(t.Root,{children:[o&&e.jsx(o,{...r}),e.jsx(L,{}),e.jsx(V,{})]}),e.jsx(R,{}),e.jsx($,{})]})})}const f=r=>{const{onToggleView:s,askAILabel:n,searchLabel:o}=r,{aiChatSettings:i}=u.useInkeepConfig(),d=i.isChatHistoryButtonVisible,a=!!s||d;return e.jsx(t.Header,{"data-show-toolbar":h.dataAttr(a),children:a?e.jsxs(t.HeaderToolbar,{"data-show-widget-toggle":h.dataAttr(!!s),children:[e.jsx(t.HeaderToolbarWrapper,{children:d&&e.jsx(t.ChatHistoryTrigger,{})}),s&&e.jsx(v.WidgetToggle,{onToggleView:s,askAILabel:n,searchLabel:o,view:"chat"}),e.jsx(j.Close,{})]}):e.jsx(j.Close,{})})};function L(){const{isSessionLoading:r}=C.useChat();return e.jsx(t.Content,{children:e.jsxs(t.ContentScrollArea,{children:[e.jsx(t.ContentScrollAreaViewport,{children:r?e.jsx(t.MessagesSessionLoading,{}):e.jsx(P,{})}),e.jsx(t.ContentScrollAreaScrollbar,{children:e.jsx(t.ContentScrollAreaThumb,{})}),e.jsx(t.ContentScrollAreaCorner,{})]})})}function P(){const{aiChatSettings:{components:r}}=u.useInkeepConfig();return e.jsx(t.Messages,{children:({messages:s,isLoading:n})=>{const o=s.at(-1),i=(a,g)=>{const l=r?.[a];if(!l)return console.warn(`Component "${a}" not found in components config`),null;try{if(typeof l=="function"&&l.length<=1)return m.createElement(l,g);const x=l(g,document.createElement("div"),null);return m.isValidElement(x)||typeof x=="string"?x:null}catch(x){return console.error(`🔍 [renderComponent] Error rendering component "${a}":`,x),null}},d=a=>e.jsx(t.Markdown,{text:a});return e.jsxs(e.Fragment,{children:[e.jsx(D,{}),s.map(a=>e.jsxs(t.MessageWrapper,{message:a,children:[e.jsx(p,{}),e.jsxs(t.MessageContentWrapper,{children:[e.jsx(t.MessageContent,{children:r?.IkpMessage?e.jsx(t.DynamicComponent,{name:"IkpMessage",props:{message:a,renderComponent:i,renderMarkdown:d},componentDef:r.IkpMessage}):e.jsxs(e.Fragment,{children:[e.jsx(b.EmbeddedChatMessagePart,{isLast:o?.id===a.id}),e.jsx(_,{})]})}),e.jsx(W,{}),e.jsx(q,{})]})]},a.id)),n&&o?.parts.length&&e.jsxs(t.MessageWrapper,{message:{id:"___loader___",role:"assistant",parts:[{type:"text",text:"Thinking..."}]},children:[e.jsx(p,{}),e.jsx(t.MessageLoading,{})]})]})}})}function D(){return e.jsxs(t.IntroMessageWrapper,{children:[e.jsxs(t.MessageHeader,{children:[e.jsx(t.MessageAvatar,{children:e.jsx(t.MessageAvatarContent,{children:e.jsx(t.MessageAvatarImage,{})})}),e.jsx(t.MessageName,{})]}),e.jsxs(t.MessageContentWrapper,{children:[e.jsx(t.MessageContent,{children:e.jsx(b.EmbeddedChatMessagePart,{isLast:!1})}),e.jsxs(t.Disclaimer,{children:[e.jsx(t.DisclaimerLabel,{}),e.jsx(t.DisclaimerTrigger,{}),e.jsxs(t.DisclaimerContent,{children:[e.jsx(t.DisclaimerText,{}),e.jsx(t.DisclaimerArrow,{})]})]}),e.jsxs(t.ExampleQuestions,{children:[e.jsx(t.ExampleQuestionsLabel,{}),e.jsx(t.ExampleQuestionsList,{children:r=>r.map(s=>e.jsx(t.ExampleQuestion,{children:e.jsx(t.ExampleQuestionButton,{question:s})},typeof s=="object"?s.label:s))})]})]})]})}function p(){return e.jsxs(t.MessageHeader,{children:[e.jsx(t.MessageAvatar,{children:e.jsx(t.MessageAvatarContent,{children:e.jsx(t.MessageAvatarImage,{})})}),e.jsx(t.MessageName,{})]})}function W(){return e.jsxs(t.MessageAttachments,{children:[e.jsx(t.MessageAttachmentsList,{children:r=>r.map(s=>e.jsxs(t.MessageAttachmentsItem,{attachment:s,children:[e.jsx(t.MessageAttachmentsItemIcon,{}),e.jsx(t.MessageAttachmentsItemTitle,{})]},s.id))}),e.jsx(t.MessageAttachmentsPreview,{children:e.jsx(F.PortalWithTheme,{children:e.jsx(t.MessageAttachmentsPreviewOverlay,{children:e.jsxs(t.MessageAttachmentsPreviewContent,{children:[e.jsx(t.MessageAttachmentsPreviewHeader,{}),e.jsx(t.MessageAttachmentsPreviewClose,{}),e.jsx(t.MessageAttachmentsPreviewBody,{})]})})})})]})}function q(){return e.jsxs(t.MessageToolbar,{children:[e.jsx(t.MessageCustomActions,{children:r=>r.map((s,n)=>e.jsx(t.MessageCustomAction,{action:s},`action-${n}`))}),e.jsx(t.MessageAction,{action:"copy"}),e.jsx(t.MessageAction,{action:"upvote"}),e.jsx(t.MessageAction,{action:"downvote"})]})}function _(){return e.jsxs(t.MessageSources,{children:[e.jsx(t.MessageSourcesHeader,{}),e.jsx(t.MessageSourcesList,{children:r=>r.map((s,n)=>e.jsxs(t.MessageSourceItem,{href:s.url,source:s,children:[e.jsx(t.MessageSourceItemBreadcrumbs,{children:s.breadcrumbs?.map(o=>e.jsxs(m.Fragment,{children:[o,e.jsx(t.MessageSourceItemBreadcrumbIcon,{})]},o))}),e.jsx(t.MessageSourceItemIcon,{}),e.jsx(t.MessageSourceItemTitle,{}),e.jsx(t.MessageSourceItemTag,{}),e.jsx(t.MessageSourceItemDescription,{children:o=>o.map((i,d)=>e.jsx(t.MessageSourceItemDescriptionPart,{part:i},`part-${d}`))}),e.jsx(t.MessageSourceItemIndicator,{})]},n))})]})}function V(){return e.jsxs(t.Footer,{children:[e.jsx(N,{}),e.jsx(O,{})]})}function N(){return e.jsxs(t.InputFieldset,{children:[e.jsxs(t.InputGroup,{children:[e.jsx(t.Input,{}),e.jsx(t.SendButton,{children:e.jsx(t.SendButtonIcon,{})})]}),e.jsxs(t.AttachmentsBar,{children:[e.jsx(t.AttachmentsBarList,{children:r=>r.map(s=>e.jsxs(t.AttachmentsBarAttachment,{attachment:s,children:[e.jsx(t.AttachmentsBarAttachmentIcon,{}),e.jsx(t.AttachmentsBarAttachmentTitle,{}),e.jsx(t.AttachmentsBarAttachmentDelete,{})]},s.id))}),e.jsxs(t.AttachmentsBarActions,{children:[e.jsxs(t.AttachmentsBarInfoTip,{children:[e.jsx(t.AttachmentsBarInfoTipIcon,{}),e.jsx(t.AttachmentsBarInfoTipText,{})]}),e.jsx(t.AttachmentsBarInputs,{children:r=>r.map(s=>e.jsx(t.AttachmentsBarInput,{input:s,children:s.displayName},s.id))})]}),e.jsx(F.PortalWithTheme,{children:e.jsx(t.AttachmentsBarModal,{children:e.jsx(t.AttachmentsBarModalOverlay,{children:e.jsxs(t.AttachmentsBarModalContent,{children:[e.jsxs(t.AttachmentsBarModalHeader,{children:[e.jsx(t.AttachmentsBarModalHeading,{}),e.jsx(t.AttachmentsBarModalDescription,{}),e.jsx(t.AttachmentsBarModalHelp,{})]}),e.jsx(t.AttachmentsBarModalClose,{}),e.jsx(t.AttachmentsBarModalBody,{children:e.jsxs(t.AttachmentsBarForm,{children:[e.jsxs(t.AttachmentsBarFormTitle,{children:[e.jsx(t.AttachmentsBarFormTitleLabel,{}),e.jsx(t.AttachmentsBarFormTitleInput,{}),e.jsx(t.AttachmentsBarFormTitleError,{})]}),e.jsxs(t.AttachmentsBarFormContent,{children:[e.jsx(t.AttachmentsBarFormContentLabel,{}),e.jsx(t.AttachmentsBarFormContentInput,{}),e.jsx(t.AttachmentsBarFormContentError,{})]}),e.jsx(t.AttachmentsBarFormSubmitButton,{})]})})]})})})})]})]})}function O(){return e.jsxs(t.ActionBar,{children:[e.jsxs(t.TaglineContainer,{children:[e.jsx(t.TaglineText,{}),e.jsx(t.TaglineLogo,{}),e.jsx(t.TaglineBrandName,{})]}),e.jsxs(t.Actions,{children:[e.jsx(t.HelpActions,{children:({pinned:r,unpinned:s})=>e.jsxs(e.Fragment,{children:[r.map(n=>e.jsx(t.HelpAction,{action:n},n.name)),s.length>0&&e.jsx(t.HelpActionsTrigger,{}),e.jsxs(t.HelpActionsMenu,{children:[e.jsx(t.HelpActionsMenuArrow,{}),s.map(n=>e.jsxs(t.HelpActionsMenuItem,{action:n,children:[e.jsx(t.HelpActionsMenuItemIcon,{action:n}),n.name]},n.name))]})]})}),e.jsxs(t.ChatAction,{action:"copy",children:[e.jsx(t.ChatActionLabel,{action:"copy"}),e.jsx(t.ChatActionFeedback,{action:"copy"})]}),e.jsx(t.ChatAction,{action:"clear"}),e.jsx(t.ChatAction,{action:"stop"})]})]})}function Q(){const{sessions:r}=T.useChatHistory(),{conversationId:s}=C.useChat();return e.jsxs(c.EmbeddedChatHistoryRoot,{children:[e.jsxs(c.EmbeddedChatHistoryHeader,{children:[e.jsxs(c.EmbeddedChatHistoryBackButton,{children:[e.jsx(c.EmbeddedChatHistoryBackButtonIcon,{iconKey:"backToChat"}),"Back to chat"]}),e.jsx(c.EmbeddedChatHistoryTitle,{}),e.jsx(j.Close,{})]}),e.jsxs(c.EmbeddedChatHistoryList,{children:[r.map(n=>e.jsxs(c.EmbeddedChatHistoryItem,{sessionId:n.id,"data-active":h.dataAttr(n.id===s),children:[e.jsx(c.EmbeddedChatHistoryItemTitle,{children:n.title}),e.jsx(c.EmbeddedChatHistoryItemDate,{children:c.formatSessionDate(n.updatedAt)})]},n.id)),e.jsx(c.EmbeddedChatHistoryEmptyState,{}),e.jsx(c.EmbeddedChatHistoryLoadingState,{})]}),e.jsx(c.EmbeddedChatHistoryFooter,{children:e.jsx(c.EmbeddedChatHistoryNewConversationButton,{})})]})}function R(){return e.jsx(F.PortalWithTheme,{children:e.jsx(t.FeedbackModal,{children:e.jsx(t.FeedbackModalOverlay,{children:e.jsxs(t.FeedbackModalContent,{children:[e.jsx(t.FeedbackModalHeader,{}),e.jsx(t.FeedbackModalClose,{}),e.jsx(t.FeedbackModalBody,{children:e.jsxs(t.FeedbackForm,{children:[e.jsxs(t.FeedbackItem,{name:"unrelated_response",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"inaccurate_statement",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"inaccurate_code_snippet",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"irrelevant_citations",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{})]}),e.jsx(t.FeedbackSubmitButton,{})]})})]})})})})}function $(){return e.jsxs(t.FormWrapper,{children:[e.jsx(t.FormClose,{}),e.jsxs(t.Form,{children:[e.jsxs(t.FormHeader,{children:[e.jsx(t.FormHeading,{}),e.jsx(t.FormDescription,{})]}),e.jsx(t.FormContent,{children:r=>e.jsxs(e.Fragment,{children:[r.map((s,n)=>e.jsxs(t.FormField,{field:s,autoFocus:n===0,children:[e.jsx(t.FormFieldLabel,{}),s.inputType==="text"&&e.jsx(t.FormFieldText,{}),s.inputType==="email"&&e.jsx(t.FormFieldEmail,{}),s.inputType==="file"&&e.jsx(t.FormFieldFile,{}),s.inputType==="textarea"&&e.jsx(t.FormFieldTextArea,{}),s.inputType==="checkbox"&&e.jsx(t.FormFieldCheckbox,{children:e.jsx(t.FormFieldCheckboxIndicator,{})}),s.inputType==="select"&&e.jsxs(t.FormFieldSelect,{children:[e.jsxs(t.FormFieldSelectTrigger,{children:[e.jsx(t.FormFieldSelectValue,{}),e.jsx(t.FormFieldSelectIcon,{})]}),e.jsx(t.FormFieldSelectContent,{children:e.jsx(t.FormFieldSelectViewport,{children:s.items.map(o=>e.jsxs(t.FormFieldSelectItem,{value:o.value,children:[e.jsx(t.FormFieldSelectItemText,{children:o.label}),e.jsx(t.FormFieldSelectItemIndicator,{})]},o.value))})})]}),s.inputType==="combobox"&&e.jsxs(t.FormFieldCombobox,{children:[e.jsxs(t.FormFieldComboboxControl,{children:["multiple"in s&&s.multiple&&e.jsx(t.FormFieldComboboxSelectedTags,{}),e.jsx(t.FormFieldComboboxInput,{}),e.jsx(t.FormFieldComboboxTrigger,{})]}),e.jsx(t.FormFieldComboboxPositioner,{children:e.jsx(t.FormFieldComboboxContent,{children:e.jsx(t.FormFieldComboboxList,{children:e.jsx(t.FormFieldComboboxListItems,{children:o=>o.length===0?e.jsx(t.FormFieldComboboxListEmpty,{}):o.map(i=>e.jsxs(t.FormFieldComboboxItem,{item:i,children:[e.jsx(t.FormFieldComboboxItemText,{children:i.label}),e.jsx(t.FormFieldComboboxItemIndicator,{})]},i.value))})})})})]}),e.jsx(t.FormFieldDescription,{}),e.jsx(t.FormFieldError,{})]},s.name)),e.jsx(t.FormError,{})]})}),e.jsxs(t.FormFooter,{children:[e.jsx(t.FormCancel,{}),e.jsx(t.FormSubmit,{})]})]}),e.jsxs(t.FormSuccess,{children:[e.jsx(t.FormSuccessHeading,{}),e.jsx(t.FormSuccessMessage,{}),e.jsx(t.FormSuccessButton,{})]})]})}exports.InkeepEmbeddedChat=w;exports.InkeepEmbeddedChatImpl=A;exports.InkeepEmbeddedChatImplContent=M;exports.InkeepEmbeddedChatProvider=I;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("react"),t=require("../styled/components/embedded-chat.cjs"),i=require("../styled/components/chat-history.cjs"),F=require("../styled/components/modal.cjs"),T=require("../styled/components/shadow.cjs"),C=require("../styled/components/message.cjs"),B=require("../primitives/providers/chat-history-provider.cjs"),g=require("../primitives/providers/config-provider.cjs"),y=require("../primitives/providers/root-provider.cjs"),S=require("../primitives/providers/widget-provider.cjs"),I=require("../primitives/components/embedded-chat/chat-provider.cjs"),H=require("../primitives/components/modal/modal-provider.cjs"),u=require("../primitives/utils/misc.cjs"),p=require("../primitives/atoms/portal-with-theme.cjs"),E=require("../primitives/atoms/error-boundary.cjs"),v=require("./modal.cjs"),w=require("./widget-toggle.cjs");function f(r){const{baseSettings:s,aiChatSettings:n}=r;return e.jsx(E.ErrorBoundary,{children:e.jsx(T.Shadow,{wrapperStyles:{height:"inherit",width:"inherit"},children:e.jsx(y.RootProvider,{config:{baseSettings:s,aiChatSettings:n},componentType:g.WebWidgetInteractionType.EmbeddedChat,children:e.jsx(M,{...r})})})})}function A(r){const{children:s,onToggleView:n,isHidden:o,shouldAutoFocusInput:a=!n}=r;return e.jsx(t.Provider,{isHidden:o,shouldAutoFocusInput:a,children:s})}function M(r){return e.jsx(A,{...r,children:e.jsx(k,{...r})})}function k(r){const{onToggleView:s,variant:n,header:o=L}=r,a=H.useModal(),d=S.useWidget(),l=a&&!d?v.ModalContent:j.Fragment;return e.jsx(l,{children:e.jsxs(t.Wrapper,{variant:n??(s?"no-shadow":"container-with-shadow"),"data-composite":u.dataAttr(!!r.onToggleView||a?.isOpen),children:[e.jsx(R,{}),e.jsxs(t.Root,{children:[o&&e.jsx(o,{...r}),e.jsx(P,{}),e.jsx(N,{})]}),e.jsx($,{}),e.jsx(G,{})]})})}const L=r=>{const{onToggleView:s,askAILabel:n,searchLabel:o}=r,{aiChatSettings:a}=g.useInkeepConfig(),d=a.isChatHistoryButtonVisible,l=!!s||d;return e.jsx(t.Header,{"data-show-toolbar":u.dataAttr(l),children:l?e.jsxs(t.HeaderToolbar,{"data-show-widget-toggle":u.dataAttr(!!s),children:[e.jsx(t.HeaderToolbarWrapper,{children:d&&e.jsx(t.ChatHistoryTrigger,{})}),s&&e.jsx(w.WidgetToggle,{onToggleView:s,askAILabel:n,searchLabel:o,view:"chat"}),e.jsx(F.Close,{})]}):e.jsx(F.Close,{})})};function P(){const{isSessionLoading:r}=I.useChat();return e.jsx(t.Content,{children:e.jsxs(t.ContentScrollArea,{children:[e.jsx(t.ContentScrollAreaViewport,{children:r?e.jsx(t.MessagesSessionLoading,{}):e.jsx(D,{})}),e.jsx(t.ContentScrollAreaScrollbar,{children:e.jsx(t.ContentScrollAreaThumb,{})}),e.jsx(t.ContentScrollAreaCorner,{})]})})}function D(){const{aiChatSettings:{components:r}}=g.useInkeepConfig();return e.jsx(t.Messages,{children:({messages:s,isLoading:n,isStreaming:o})=>{const a=s.at(-1),d=(c,x)=>{const m=r?.[c];if(!m)return console.warn(`Component "${c}" not found in components config`),null;try{if(typeof m=="function"&&m.length<=1)return j.createElement(m,x);const h=m(x,document.createElement("div"),null);return j.isValidElement(h)||typeof h=="string"?h:null}catch(h){return console.error(`🔍 [renderComponent] Error rendering component "${c}":`,h),null}},l=c=>e.jsx(t.Markdown,{text:c});return e.jsxs(e.Fragment,{children:[e.jsx(W,{}),s.map(c=>{const x=a?.id===c.id;return e.jsxs(t.MessageWrapper,{message:c,children:[e.jsx(b,{}),e.jsxs(t.MessageContentWrapper,{children:[e.jsx(t.MessageContent,{children:r?.IkpMessage?e.jsx(t.DynamicComponent,{name:"IkpMessage",props:{message:c,renderComponent:d,renderMarkdown:l},componentDef:r.IkpMessage}):e.jsxs(e.Fragment,{children:[e.jsx(C.EmbeddedChatMessagePart,{isLast:x}),(!o||!x)&&e.jsx(V,{})]})}),e.jsx(q,{}),e.jsx(_,{})]})]},c.id)}),n&&a?.parts.length&&e.jsxs(t.MessageWrapper,{message:{id:"___loader___",role:"assistant",parts:[{type:"text",text:"Thinking..."}]},children:[e.jsx(b,{}),e.jsx(t.MessageLoading,{})]})]})}})}function W(){return e.jsxs(t.IntroMessageWrapper,{children:[e.jsxs(t.MessageHeader,{children:[e.jsx(t.MessageAvatar,{children:e.jsx(t.MessageAvatarContent,{children:e.jsx(t.MessageAvatarImage,{})})}),e.jsx(t.MessageName,{})]}),e.jsxs(t.MessageContentWrapper,{children:[e.jsx(t.MessageContent,{children:e.jsx(C.EmbeddedChatMessagePart,{isLast:!1})}),e.jsxs(t.Disclaimer,{children:[e.jsx(t.DisclaimerLabel,{}),e.jsx(t.DisclaimerTrigger,{}),e.jsxs(t.DisclaimerContent,{children:[e.jsx(t.DisclaimerText,{}),e.jsx(t.DisclaimerArrow,{})]})]}),e.jsxs(t.ExampleQuestions,{children:[e.jsx(t.ExampleQuestionsLabel,{}),e.jsx(t.ExampleQuestionsList,{children:r=>r.map(s=>e.jsx(t.ExampleQuestion,{children:e.jsx(t.ExampleQuestionButton,{question:s})},typeof s=="object"?s.label:s))})]})]})]})}function b(){return e.jsxs(t.MessageHeader,{children:[e.jsx(t.MessageAvatar,{children:e.jsx(t.MessageAvatarContent,{children:e.jsx(t.MessageAvatarImage,{})})}),e.jsx(t.MessageName,{})]})}function q(){return e.jsxs(t.MessageAttachments,{children:[e.jsx(t.MessageAttachmentsList,{children:r=>r.map(s=>e.jsxs(t.MessageAttachmentsItem,{attachment:s,children:[e.jsx(t.MessageAttachmentsItemIcon,{}),e.jsx(t.MessageAttachmentsItemTitle,{})]},s.id))}),e.jsx(t.MessageAttachmentsPreview,{children:e.jsx(p.PortalWithTheme,{children:e.jsx(t.MessageAttachmentsPreviewOverlay,{children:e.jsxs(t.MessageAttachmentsPreviewContent,{children:[e.jsx(t.MessageAttachmentsPreviewHeader,{}),e.jsx(t.MessageAttachmentsPreviewClose,{}),e.jsx(t.MessageAttachmentsPreviewBody,{})]})})})})]})}function _(){return e.jsxs(t.MessageToolbar,{children:[e.jsx(t.MessageCustomActions,{children:r=>r.map((s,n)=>e.jsx(t.MessageCustomAction,{action:s},`action-${n}`))}),e.jsx(t.MessageAction,{action:"copy"}),e.jsx(t.MessageAction,{action:"upvote"}),e.jsx(t.MessageAction,{action:"downvote"})]})}function V(){return e.jsxs(t.MessageSources,{children:[e.jsx(t.MessageSourcesHeader,{}),e.jsx(t.MessageSourcesList,{children:r=>r.map((s,n)=>e.jsxs(t.MessageSourceItem,{href:s.url,source:s,children:[e.jsx(t.MessageSourceItemBreadcrumbs,{children:s.breadcrumbs?.map(o=>e.jsxs(j.Fragment,{children:[o,e.jsx(t.MessageSourceItemBreadcrumbIcon,{})]},o))}),e.jsx(t.MessageSourceItemIcon,{}),e.jsx(t.MessageSourceItemTitle,{}),e.jsx(t.MessageSourceItemTag,{}),e.jsx(t.MessageSourceItemDescription,{children:o=>o.map((a,d)=>e.jsx(t.MessageSourceItemDescriptionPart,{part:a},`part-${d}`))}),e.jsx(t.MessageSourceItemIndicator,{})]},n))})]})}function N(){return e.jsxs(t.Footer,{children:[e.jsx(O,{}),e.jsx(Q,{})]})}function O(){return e.jsxs(t.InputFieldset,{children:[e.jsxs(t.InputGroup,{children:[e.jsx(t.Input,{}),e.jsx(t.SendButton,{children:e.jsx(t.SendButtonIcon,{})})]}),e.jsxs(t.AttachmentsBar,{children:[e.jsx(t.AttachmentsBarList,{children:r=>r.map(s=>e.jsxs(t.AttachmentsBarAttachment,{attachment:s,children:[e.jsx(t.AttachmentsBarAttachmentIcon,{}),e.jsx(t.AttachmentsBarAttachmentTitle,{}),e.jsx(t.AttachmentsBarAttachmentDelete,{})]},s.id))}),e.jsxs(t.AttachmentsBarActions,{children:[e.jsxs(t.AttachmentsBarInfoTip,{children:[e.jsx(t.AttachmentsBarInfoTipIcon,{}),e.jsx(t.AttachmentsBarInfoTipText,{})]}),e.jsx(t.AttachmentsBarInputs,{children:r=>r.map(s=>e.jsx(t.AttachmentsBarInput,{input:s,children:s.displayName},s.id))})]}),e.jsx(p.PortalWithTheme,{children:e.jsx(t.AttachmentsBarModal,{children:e.jsx(t.AttachmentsBarModalOverlay,{children:e.jsxs(t.AttachmentsBarModalContent,{children:[e.jsxs(t.AttachmentsBarModalHeader,{children:[e.jsx(t.AttachmentsBarModalHeading,{}),e.jsx(t.AttachmentsBarModalDescription,{}),e.jsx(t.AttachmentsBarModalHelp,{})]}),e.jsx(t.AttachmentsBarModalClose,{}),e.jsx(t.AttachmentsBarModalBody,{children:e.jsxs(t.AttachmentsBarForm,{children:[e.jsxs(t.AttachmentsBarFormTitle,{children:[e.jsx(t.AttachmentsBarFormTitleLabel,{}),e.jsx(t.AttachmentsBarFormTitleInput,{}),e.jsx(t.AttachmentsBarFormTitleError,{})]}),e.jsxs(t.AttachmentsBarFormContent,{children:[e.jsx(t.AttachmentsBarFormContentLabel,{}),e.jsx(t.AttachmentsBarFormContentInput,{}),e.jsx(t.AttachmentsBarFormContentError,{})]}),e.jsx(t.AttachmentsBarFormSubmitButton,{})]})})]})})})})]})]})}function Q(){return e.jsxs(t.ActionBar,{children:[e.jsxs(t.TaglineContainer,{children:[e.jsx(t.TaglineText,{}),e.jsx(t.TaglineLogo,{}),e.jsx(t.TaglineBrandName,{})]}),e.jsxs(t.Actions,{children:[e.jsx(t.HelpActions,{children:({pinned:r,unpinned:s})=>e.jsxs(e.Fragment,{children:[r.map(n=>e.jsx(t.HelpAction,{action:n},n.name)),s.length>0&&e.jsx(t.HelpActionsTrigger,{}),e.jsxs(t.HelpActionsMenu,{children:[e.jsx(t.HelpActionsMenuArrow,{}),s.map(n=>e.jsxs(t.HelpActionsMenuItem,{action:n,children:[e.jsx(t.HelpActionsMenuItemIcon,{action:n}),n.name]},n.name))]})]})}),e.jsxs(t.ChatAction,{action:"copy",children:[e.jsx(t.ChatActionLabel,{action:"copy"}),e.jsx(t.ChatActionFeedback,{action:"copy"})]}),e.jsx(t.ChatAction,{action:"clear"}),e.jsx(t.ChatAction,{action:"stop"})]})]})}function R(){const{sessions:r}=B.useChatHistory(),{conversationId:s}=I.useChat();return e.jsxs(i.EmbeddedChatHistoryRoot,{children:[e.jsxs(i.EmbeddedChatHistoryHeader,{children:[e.jsxs(i.EmbeddedChatHistoryBackButton,{children:[e.jsx(i.EmbeddedChatHistoryBackButtonIcon,{iconKey:"backToChat"}),"Back to chat"]}),e.jsx(i.EmbeddedChatHistoryTitle,{}),e.jsx(F.Close,{})]}),e.jsxs(i.EmbeddedChatHistoryList,{children:[r.map(n=>e.jsxs(i.EmbeddedChatHistoryItem,{sessionId:n.id,"data-active":u.dataAttr(n.id===s),children:[e.jsx(i.EmbeddedChatHistoryItemTitle,{children:n.title}),e.jsx(i.EmbeddedChatHistoryItemDate,{children:i.formatSessionDate(n.updatedAt)})]},n.id)),e.jsx(i.EmbeddedChatHistoryEmptyState,{}),e.jsx(i.EmbeddedChatHistoryLoadingState,{})]}),e.jsx(i.EmbeddedChatHistoryFooter,{children:e.jsx(i.EmbeddedChatHistoryNewConversationButton,{})})]})}function $(){return e.jsx(p.PortalWithTheme,{children:e.jsx(t.FeedbackModal,{children:e.jsx(t.FeedbackModalOverlay,{children:e.jsxs(t.FeedbackModalContent,{children:[e.jsx(t.FeedbackModalHeader,{}),e.jsx(t.FeedbackModalClose,{}),e.jsx(t.FeedbackModalBody,{children:e.jsxs(t.FeedbackForm,{children:[e.jsxs(t.FeedbackItem,{name:"unrelated_response",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"inaccurate_statement",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"inaccurate_code_snippet",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{}),e.jsx(t.FeedbackItemDescription,{})]}),e.jsxs(t.FeedbackItem,{name:"irrelevant_citations",children:[e.jsx(t.FeedbackItemCheckbox,{children:e.jsx(t.FeedbackItemCheckboxIndicator,{})}),e.jsx(t.FeedbackItemLabel,{})]}),e.jsx(t.FeedbackSubmitButton,{})]})})]})})})})}function G(){return e.jsxs(t.FormWrapper,{children:[e.jsx(t.FormClose,{}),e.jsxs(t.Form,{children:[e.jsxs(t.FormHeader,{children:[e.jsx(t.FormHeading,{}),e.jsx(t.FormDescription,{})]}),e.jsx(t.FormContent,{children:r=>e.jsxs(e.Fragment,{children:[r.map((s,n)=>e.jsxs(t.FormField,{field:s,autoFocus:n===0,children:[e.jsx(t.FormFieldLabel,{}),s.inputType==="text"&&e.jsx(t.FormFieldText,{}),s.inputType==="email"&&e.jsx(t.FormFieldEmail,{}),s.inputType==="file"&&e.jsx(t.FormFieldFile,{}),s.inputType==="textarea"&&e.jsx(t.FormFieldTextArea,{}),s.inputType==="checkbox"&&e.jsx(t.FormFieldCheckbox,{children:e.jsx(t.FormFieldCheckboxIndicator,{})}),s.inputType==="select"&&e.jsxs(t.FormFieldSelect,{children:[e.jsxs(t.FormFieldSelectTrigger,{children:[e.jsx(t.FormFieldSelectValue,{}),e.jsx(t.FormFieldSelectIcon,{})]}),e.jsx(t.FormFieldSelectContent,{children:e.jsx(t.FormFieldSelectViewport,{children:s.items.map(o=>e.jsxs(t.FormFieldSelectItem,{value:o.value,children:[e.jsx(t.FormFieldSelectItemText,{children:o.label}),e.jsx(t.FormFieldSelectItemIndicator,{})]},o.value))})})]}),s.inputType==="combobox"&&e.jsxs(t.FormFieldCombobox,{children:[e.jsxs(t.FormFieldComboboxControl,{children:["multiple"in s&&s.multiple&&e.jsx(t.FormFieldComboboxSelectedTags,{}),e.jsx(t.FormFieldComboboxInput,{}),e.jsx(t.FormFieldComboboxTrigger,{})]}),e.jsx(t.FormFieldComboboxPositioner,{children:e.jsx(t.FormFieldComboboxContent,{children:e.jsx(t.FormFieldComboboxList,{children:e.jsx(t.FormFieldComboboxListItems,{children:o=>o.length===0?e.jsx(t.FormFieldComboboxListEmpty,{}):o.map(a=>e.jsxs(t.FormFieldComboboxItem,{item:a,children:[e.jsx(t.FormFieldComboboxItemText,{children:a.label}),e.jsx(t.FormFieldComboboxItemIndicator,{})]},a.value))})})})})]}),e.jsx(t.FormFieldDescription,{}),e.jsx(t.FormFieldError,{})]},s.name)),e.jsx(t.FormError,{})]})}),e.jsxs(t.FormFooter,{children:[e.jsx(t.FormCancel,{}),e.jsx(t.FormSubmit,{})]})]}),e.jsxs(t.FormSuccess,{children:[e.jsx(t.FormSuccessHeading,{}),e.jsx(t.FormSuccessMessage,{}),e.jsx(t.FormSuccessButton,{})]})]})}exports.InkeepEmbeddedChat=f;exports.InkeepEmbeddedChatImpl=M;exports.InkeepEmbeddedChatImplContent=k;exports.InkeepEmbeddedChatProvider=A;