@inkeep/agents-ui 0.15.13 → 0.15.15
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/dist/types/js/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -3,29 +3,29 @@ import { GrBlog as e } from "./collections/gr.js";
|
|
|
3
3
|
import { BiLogoTelegram as r, BiLogoDiscordAlt as n, BiLogoDiscourse as a } from "./collections/bi.js";
|
|
4
4
|
import { PiFilePdf as i, PiFilePdfFill as l, PiCaretUpDownFill as t } from "./collections/pi.js";
|
|
5
5
|
import { FiEdit as u } from "./collections/fi.js";
|
|
6
|
-
import { IoOpenOutline as L, IoMail as h, IoHomeOutline as s, IoCheckmarkDoneOutline as C, IoPencilOutline as c, IoPlayCircleOutline as m, IoTerminal as p, IoLogoGithub as o, IoLogoDiscord as I, IoChatbubblesOutline as F, IoDocumentTextOutline as k, IoPeopleOutline as D, IoHelpBuoyOutline as d, IoReaderOutline as
|
|
7
|
-
import { Send as j, Headset as z, Calendar as J, CornerDownRight as K, Sparkles as N, LoaderCircle as Q, ChevronDown as V, BookOpen as W, ArrowUpRight as X, User as Y, Users as Z, ThumbsUp as _, ThumbsDown as $, Repeat as oo, Link as eo,
|
|
8
|
-
const
|
|
9
|
-
FaBook:
|
|
6
|
+
import { IoOpenOutline as L, IoMail as h, IoHomeOutline as s, IoCheckmarkDoneOutline as C, IoPencilOutline as c, IoPlayCircleOutline as m, IoTerminal as p, IoLogoGithub as o, IoLogoDiscord as I, IoChatbubblesOutline as F, IoDocumentTextOutline as k, IoPeopleOutline as D, IoHelpBuoyOutline as d, IoReaderOutline as f, IoBookOutline as O, IoCheckmarkOutline as g, IoCloseOutline as w, IoReturnDownForward as P, IoChevronForwardOutline as S, IoReturnDownBackOutline as b, IoCopy as B, IoCopyOutline as T, IoSearch as R, IoThumbsDownSharp as U, IoThumbsUpSharp as v, IoLinkOutline as y, IoInformationCircleOutline as G, IoSend as H, IoDocumentSharp as A, IoDocumentTextSharp as x, IoLogoSlack as M, IoLogoChrome as q, IoLogoStackoverflow as E } from "./collections/io5.js";
|
|
7
|
+
import { Send as j, Headset as z, Calendar as J, CornerDownRight as K, Sparkles as N, LoaderCircle as Q, ChevronDown as V, BookOpen as W, ArrowUpRight as X, User as Y, Users as Z, ThumbsUp as _, ThumbsDown as $, Repeat as oo, Link as eo, PanelLeft as ro, History as no, Globe as ao, CornerDownLeft as io, Check as lo, Copy as to, Command as uo, CircleCheck as Lo, ArrowLeft as ho, Search as so, Table as Co, BriefcaseBusiness as co, ChevronUp as mo, ChevronRight as po, SquarePen as Io, Pencil as Fo, Mail as ko, Phone as Do, Database as fo, BookText as Oo } from "lucide-react";
|
|
8
|
+
const To = {
|
|
9
|
+
FaBook: Oo,
|
|
10
10
|
FaGithub: o,
|
|
11
|
-
FaDatabase:
|
|
11
|
+
FaDatabase: fo,
|
|
12
12
|
FaStackOverflow: E,
|
|
13
13
|
FaChrome: q,
|
|
14
|
-
FaPhone:
|
|
15
|
-
FaEnvelope:
|
|
16
|
-
FaPencil:
|
|
14
|
+
FaPhone: Do,
|
|
15
|
+
FaEnvelope: ko,
|
|
16
|
+
FaPencil: Fo,
|
|
17
17
|
FaBlog: e,
|
|
18
18
|
FaSort: t,
|
|
19
|
-
FaPenSquare:
|
|
20
|
-
FaChevronRight:
|
|
21
|
-
FaChevronUp:
|
|
19
|
+
FaPenSquare: Io,
|
|
20
|
+
FaChevronRight: po,
|
|
21
|
+
FaChevronUp: mo,
|
|
22
22
|
FaFilePdf: l,
|
|
23
23
|
FaDiscourse: a,
|
|
24
24
|
FaDiscord: n,
|
|
25
25
|
FaSlack: M,
|
|
26
|
-
IoDocumentTextSharp:
|
|
27
|
-
IoDocumentSharp:
|
|
28
|
-
IoSend:
|
|
26
|
+
IoDocumentTextSharp: x,
|
|
27
|
+
IoDocumentSharp: A,
|
|
28
|
+
IoSend: H,
|
|
29
29
|
IoInformationCircleOutline: G,
|
|
30
30
|
IoLinkOutline: y,
|
|
31
31
|
IoThumbsUpSharp: v,
|
|
@@ -33,13 +33,13 @@ const Po = {
|
|
|
33
33
|
IoSearch: R,
|
|
34
34
|
IoCopyOutline: T,
|
|
35
35
|
IoCopy: B,
|
|
36
|
-
IoReturnDownBackOutline:
|
|
37
|
-
IoChevronForwardOutline:
|
|
38
|
-
IoReturnDownForward:
|
|
36
|
+
IoReturnDownBackOutline: b,
|
|
37
|
+
IoChevronForwardOutline: S,
|
|
38
|
+
IoReturnDownForward: P,
|
|
39
39
|
IoCloseOutline: w,
|
|
40
|
-
IoCheckmarkOutline:
|
|
41
|
-
IoBookOutline:
|
|
42
|
-
IoReaderOutline:
|
|
40
|
+
IoCheckmarkOutline: g,
|
|
41
|
+
IoBookOutline: O,
|
|
42
|
+
IoReaderOutline: f,
|
|
43
43
|
IoHelpBuoyOutline: d,
|
|
44
44
|
IoPeopleOutline: D,
|
|
45
45
|
IoDocumentTextOutline: k,
|
|
@@ -48,7 +48,7 @@ const Po = {
|
|
|
48
48
|
IoLogoDiscord: I,
|
|
49
49
|
IoLogoGithub: o,
|
|
50
50
|
IoTerminal: p,
|
|
51
|
-
FaBriefcase:
|
|
51
|
+
FaBriefcase: co,
|
|
52
52
|
IoPlayCircleOutline: m,
|
|
53
53
|
IoPencilOutline: c,
|
|
54
54
|
IoCheckmarkDoneOutline: C,
|
|
@@ -56,15 +56,17 @@ const Po = {
|
|
|
56
56
|
IoMail: h,
|
|
57
57
|
IoOpenOutline: L,
|
|
58
58
|
FaTelegram: r,
|
|
59
|
-
FaTable:
|
|
60
|
-
FaMagnifyingGlass:
|
|
61
|
-
LuArrowLeft:
|
|
62
|
-
LuCircleCheck:
|
|
63
|
-
LuCommand:
|
|
64
|
-
LuCopy:
|
|
65
|
-
LuCheck:
|
|
66
|
-
LuCornerDownLeft:
|
|
67
|
-
LuGlobe:
|
|
59
|
+
FaTable: Co,
|
|
60
|
+
FaMagnifyingGlass: so,
|
|
61
|
+
LuArrowLeft: ho,
|
|
62
|
+
LuCircleCheck: Lo,
|
|
63
|
+
LuCommand: uo,
|
|
64
|
+
LuCopy: to,
|
|
65
|
+
LuCheck: lo,
|
|
66
|
+
LuCornerDownLeft: io,
|
|
67
|
+
LuGlobe: ao,
|
|
68
|
+
LuHistory: no,
|
|
69
|
+
LuPanelLeft: ro,
|
|
68
70
|
LuLink: eo,
|
|
69
71
|
LuRepeat: oo,
|
|
70
72
|
LuThumbsDown: $,
|
|
@@ -83,5 +85,5 @@ const Po = {
|
|
|
83
85
|
LuSend: j
|
|
84
86
|
};
|
|
85
87
|
export {
|
|
86
|
-
|
|
88
|
+
To as iconMap
|
|
87
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={search:"IoSearch",thumbsUp:"LuThumbsUp",thumbsDown:"LuThumbsDown",messageCopy:"LuCopy",messageCopied:"LuCheck",messageRevise:"FiEdit",codeCopy:"LuCopy",codeCopied:"LuCheck",openLinkInNewTab:"LuArrowUpRight",openLinkInSameTab:"LuCornerDownLeft",newLine:"LuCornerDownRight",breadcrumbSeparator:"FaChevronRight",switchToSearch:"IoSearch",switchToChat:"LuSparkles",chatSubmit:"LuSend",close:"IoCloseOutline",info:"IoInformationCircleOutline",command:"LuCommand",chatButtonClose:"LuChevronDown"};exports.defaultBuiltInIcons=e;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={search:"IoSearch",thumbsUp:"LuThumbsUp",thumbsDown:"LuThumbsDown",messageCopy:"LuCopy",messageCopied:"LuCheck",messageRevise:"FiEdit",codeCopy:"LuCopy",codeCopied:"LuCheck",openLinkInNewTab:"LuArrowUpRight",openLinkInSameTab:"LuCornerDownLeft",newLine:"LuCornerDownRight",breadcrumbSeparator:"FaChevronRight",switchToSearch:"IoSearch",switchToChat:"LuSparkles",chatSubmit:"LuSend",close:"IoCloseOutline",info:"IoInformationCircleOutline",command:"LuCommand",chatButtonClose:"LuChevronDown",chatHistory:"LuHistory",chatHistoryPanel:"LuPanelLeft",backToChat:"LuArrowLeft"};exports.defaultBuiltInIcons=e;
|
|
@@ -18,7 +18,10 @@ const e = {
|
|
|
18
18
|
close: "IoCloseOutline",
|
|
19
19
|
info: "IoInformationCircleOutline",
|
|
20
20
|
command: "LuCommand",
|
|
21
|
-
chatButtonClose: "LuChevronDown"
|
|
21
|
+
chatButtonClose: "LuChevronDown",
|
|
22
|
+
chatHistory: "LuHistory",
|
|
23
|
+
chatHistoryPanel: "LuPanelLeft",
|
|
24
|
+
backToChat: "LuArrowLeft"
|
|
22
25
|
};
|
|
23
26
|
export {
|
|
24
27
|
e as defaultBuiltInIcons
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),a=require("react"),e=require("../factory.cjs"),s=require("../../providers/chat-history-provider.cjs"),x=require("../../utils/misc.cjs"),m=require("../../utils/compose-event-handlers.cjs"),E=require("../../atoms/icons/custom-icon.cjs"),T=e.ikp("div",{_id:"aiChatHistory"}),H=t=>{const{isOpen:i}=s.useChatHistory();return r.jsx(T,{"data-hidden":x.dataAttr(!i),...t})},d=e.ikp("div",{_id:"aiChatHistory__Header"}),w=e.ikp(E.CustomIcon,{_id:"aiChatHistory__BackButtonIcon"}),_=a.memo(t=>r.jsx(w,{...t,iconKey:"backToChat"})),R=e.ikp("button",{_id:"aiChatHistory__BackButton"}),l=({onClick:t,...i})=>{const{setIsOpen:o}=s.useChatHistory();return r.jsx(R,{type:"button",onClick:m.composeEventHandlers(t,()=>o(!1)),...i})},P=e.ikp("h2",{_id:"aiChatHistory__Title"}),q=e.ikp("div",{_id:"aiChatHistory__List"}),p=a.forwardRef(({children:t,...i},o)=>{const{hasMore:n,loadMore:h,isLoading:u,sessions:b}=s.useChatHistory(),y=a.useRef(null),c=b.length>0&&n;return a.useEffect(()=>{const C=y.current;if(!C||!c)return;const v=new IntersectionObserver(j=>{j[0]?.isIntersecting&&n&&!u&&h()},{threshold:.1});return v.observe(C),()=>v.disconnect()},[n,u,h,c]),r.jsxs(q,{ref:o,...i,children:[t,c&&r.jsx("div",{ref:y,"data-part":"sentinel","aria-hidden":"true",style:{height:1}})]})}),N=e.ikp("button",{_id:"aiChatHistory__Item"}),k=a.memo(({sessionId:t,onClick:i,...o})=>{const{loadSession:n}=s.useChatHistory();return r.jsx(N,{type:"button",onClick:m.composeEventHandlers(i,()=>n(t)),...o})}),B=e.ikp("span",{_id:"aiChatHistory__ItemTitle"}),I=e.ikp("span",{_id:"aiChatHistory__ItemDate"}),D=e.ikp("div",{_id:"aiChatHistory__EmptyState"}),f=t=>{const{sessions:i,isLoading:o}=s.useChatHistory();return i.length>0||o?null:r.jsx(D,{...t})},F=e.ikp("div",{_id:"aiChatHistory__LoadingState"}),g=t=>{const{isLoading:i}=s.useChatHistory();return i?r.jsx(F,{...t}):null},S=e.ikp("div",{_id:"aiChatHistory__Footer"}),O=e.ikp("button",{_id:"aiChatHistory__NewConversationButton"}),L=({onClick:t,...i})=>{const{startNewConversation:o}=s.useChatHistory();return r.jsx(O,{type:"button",onClick:m.composeEventHandlers(t,o),...i})};exports.BackButton=l;exports.BackButtonIcon=_;exports.ChatHistoryPrimitiveBackButton=l;exports.ChatHistoryPrimitiveBackButtonIcon=_;exports.ChatHistoryPrimitiveEmptyState=f;exports.ChatHistoryPrimitiveFooter=S;exports.ChatHistoryPrimitiveHeader=d;exports.ChatHistoryPrimitiveItem=k;exports.ChatHistoryPrimitiveItemDate=I;exports.ChatHistoryPrimitiveItemTitle=B;exports.ChatHistoryPrimitiveList=p;exports.ChatHistoryPrimitiveLoadingState=g;exports.ChatHistoryPrimitiveNewConversationButton=L;exports.ChatHistoryPrimitiveRoot=H;exports.ChatHistoryPrimitiveTitle=P;exports.EmptyState=f;exports.Footer=S;exports.Header=d;exports.Item=k;exports.ItemDate=I;exports.ItemTitle=B;exports.List=p;exports.LoadingState=g;exports.NewConversationButton=L;exports.Root=H;exports.Title=P;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ForwardRefExoticComponent, DetailedHTMLProps, HTMLAttributes, MemoExoticComponent, ButtonHTMLAttributes, RefAttributes } from 'react';
|
|
2
|
+
import { PolymorphicProps } from '..';
|
|
3
|
+
import { CustomIconProps } from '../..';
|
|
4
|
+
declare const PrimitiveRoot: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
5
|
+
export declare const ChatHistoryPrimitiveRoot: (props: ComponentPropsWithRef<typeof PrimitiveRoot>) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const ChatHistoryPrimitiveHeader: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
7
|
+
declare const PrimitiveBackButtonIcon: ForwardRefExoticComponent< PolymorphicProps & Omit< CustomIconProps, "_id"> & Partial<Pick< CustomIconProps, "_id">>>;
|
|
8
|
+
export declare const ChatHistoryPrimitiveBackButtonIcon: MemoExoticComponent<(props: ComponentPropsWithRef<typeof PrimitiveBackButtonIcon>) => import("react/jsx-runtime").JSX.Element>;
|
|
9
|
+
declare const PrimitiveBackButton: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id">>>;
|
|
10
|
+
export declare const ChatHistoryPrimitiveBackButton: ({ onClick, ...props }: ComponentPropsWithRef<typeof PrimitiveBackButton>) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const ChatHistoryPrimitiveTitle: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "_id">>>;
|
|
12
|
+
export declare const ChatHistoryPrimitiveList: ForwardRefExoticComponent<Omit< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>, "ref"> & RefAttributes<HTMLDivElement>>;
|
|
13
|
+
declare const PrimitiveItem: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id">>>;
|
|
14
|
+
export interface ChatHistoryPrimitiveItemProps extends ComponentPropsWithRef<typeof PrimitiveItem> {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const ChatHistoryPrimitiveItem: MemoExoticComponent<({ sessionId, onClick, ...props }: ChatHistoryPrimitiveItemProps) => import("react/jsx-runtime").JSX.Element>;
|
|
18
|
+
export declare const ChatHistoryPrimitiveItemTitle: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id">>>;
|
|
19
|
+
export declare const ChatHistoryPrimitiveItemDate: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id">>>;
|
|
20
|
+
declare const PrimitiveEmptyState: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
21
|
+
export declare const ChatHistoryPrimitiveEmptyState: (props: ComponentPropsWithRef<typeof PrimitiveEmptyState>) => import("react/jsx-runtime").JSX.Element | null;
|
|
22
|
+
declare const PrimitiveLoadingState: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
23
|
+
export declare const ChatHistoryPrimitiveLoadingState: (props: ComponentPropsWithRef<typeof PrimitiveLoadingState>) => import("react/jsx-runtime").JSX.Element | null;
|
|
24
|
+
export declare const ChatHistoryPrimitiveFooter: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
25
|
+
declare const PrimitiveNewConversationButton: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "_id">>>;
|
|
26
|
+
export declare const ChatHistoryPrimitiveNewConversationButton: ({ onClick, ...props }: ComponentPropsWithRef<typeof PrimitiveNewConversationButton>) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export { ChatHistoryPrimitiveRoot as Root, ChatHistoryPrimitiveHeader as Header, ChatHistoryPrimitiveBackButton as BackButton, ChatHistoryPrimitiveBackButtonIcon as BackButtonIcon, ChatHistoryPrimitiveTitle as Title, ChatHistoryPrimitiveList as List, ChatHistoryPrimitiveItem as Item, ChatHistoryPrimitiveItemTitle as ItemTitle, ChatHistoryPrimitiveItemDate as ItemDate, ChatHistoryPrimitiveEmptyState as EmptyState, ChatHistoryPrimitiveLoadingState as LoadingState, ChatHistoryPrimitiveFooter as Footer, ChatHistoryPrimitiveNewConversationButton as NewConversationButton, };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { jsx as s, jsxs as H } from "react/jsx-runtime";
|
|
2
|
+
import { memo as C, forwardRef as l, useRef as p, useEffect as P } from "react";
|
|
3
|
+
import { ikp as o } from "../factory.js";
|
|
4
|
+
import { useChatHistory as r } from "../../providers/chat-history-provider.js";
|
|
5
|
+
import { dataAttr as B } from "../../utils/misc.js";
|
|
6
|
+
import { composeEventHandlers as c } from "../../utils/compose-event-handlers.js";
|
|
7
|
+
import { CustomIcon as f } from "../../atoms/icons/custom-icon.js";
|
|
8
|
+
const I = o("div", { _id: "aiChatHistory" }), j = (t) => {
|
|
9
|
+
const { isOpen: i } = r();
|
|
10
|
+
return /* @__PURE__ */ s(I, { "data-hidden": B(!i), ...t });
|
|
11
|
+
}, M = o("div", { _id: "aiChatHistory__Header" }), k = o(f, {
|
|
12
|
+
_id: "aiChatHistory__BackButtonIcon"
|
|
13
|
+
}), A = C(
|
|
14
|
+
(t) => /* @__PURE__ */ s(k, { ...t, iconKey: "backToChat" })
|
|
15
|
+
), g = o("button", { _id: "aiChatHistory__BackButton" }), K = ({
|
|
16
|
+
onClick: t,
|
|
17
|
+
...i
|
|
18
|
+
}) => {
|
|
19
|
+
const { setIsOpen: e } = r();
|
|
20
|
+
return /* @__PURE__ */ s(
|
|
21
|
+
g,
|
|
22
|
+
{
|
|
23
|
+
type: "button",
|
|
24
|
+
onClick: c(t, () => e(!1)),
|
|
25
|
+
...i
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}, q = o("h2", { _id: "aiChatHistory__Title" }), L = o("div", { _id: "aiChatHistory__List" }), z = l(({ children: t, ...i }, e) => {
|
|
29
|
+
const { hasMore: n, loadMore: m, isLoading: d, sessions: _ } = r(), h = p(null), a = _.length > 0 && n;
|
|
30
|
+
return P(() => {
|
|
31
|
+
const u = h.current;
|
|
32
|
+
if (!u || !a) return;
|
|
33
|
+
const v = new IntersectionObserver(
|
|
34
|
+
(y) => {
|
|
35
|
+
y[0]?.isIntersecting && n && !d && m();
|
|
36
|
+
},
|
|
37
|
+
{ threshold: 0.1 }
|
|
38
|
+
);
|
|
39
|
+
return v.observe(u), () => v.disconnect();
|
|
40
|
+
}, [n, d, m, a]), /* @__PURE__ */ H(L, { ref: e, ...i, children: [
|
|
41
|
+
t,
|
|
42
|
+
a && /* @__PURE__ */ s("div", { ref: h, "data-part": "sentinel", "aria-hidden": "true", style: { height: 1 } })
|
|
43
|
+
] });
|
|
44
|
+
}), b = o("button", { _id: "aiChatHistory__Item" }), G = C(
|
|
45
|
+
({ sessionId: t, onClick: i, ...e }) => {
|
|
46
|
+
const { loadSession: n } = r();
|
|
47
|
+
return /* @__PURE__ */ s(
|
|
48
|
+
b,
|
|
49
|
+
{
|
|
50
|
+
type: "button",
|
|
51
|
+
onClick: c(i, () => n(t)),
|
|
52
|
+
...e
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
), J = o("span", { _id: "aiChatHistory__ItemTitle" }), Q = o("span", { _id: "aiChatHistory__ItemDate" }), S = o("div", { _id: "aiChatHistory__EmptyState" }), U = (t) => {
|
|
57
|
+
const { sessions: i, isLoading: e } = r();
|
|
58
|
+
return i.length > 0 || e ? null : /* @__PURE__ */ s(S, { ...t });
|
|
59
|
+
}, w = o("div", { _id: "aiChatHistory__LoadingState" }), V = (t) => {
|
|
60
|
+
const { isLoading: i } = r();
|
|
61
|
+
return i ? /* @__PURE__ */ s(w, { ...t }) : null;
|
|
62
|
+
}, W = o("div", { _id: "aiChatHistory__Footer" }), T = o("button", {
|
|
63
|
+
_id: "aiChatHistory__NewConversationButton"
|
|
64
|
+
}), X = ({
|
|
65
|
+
onClick: t,
|
|
66
|
+
...i
|
|
67
|
+
}) => {
|
|
68
|
+
const { startNewConversation: e } = r();
|
|
69
|
+
return /* @__PURE__ */ s(
|
|
70
|
+
T,
|
|
71
|
+
{
|
|
72
|
+
type: "button",
|
|
73
|
+
onClick: c(t, e),
|
|
74
|
+
...i
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
K as BackButton,
|
|
80
|
+
A as BackButtonIcon,
|
|
81
|
+
K as ChatHistoryPrimitiveBackButton,
|
|
82
|
+
A as ChatHistoryPrimitiveBackButtonIcon,
|
|
83
|
+
U as ChatHistoryPrimitiveEmptyState,
|
|
84
|
+
W as ChatHistoryPrimitiveFooter,
|
|
85
|
+
M as ChatHistoryPrimitiveHeader,
|
|
86
|
+
G as ChatHistoryPrimitiveItem,
|
|
87
|
+
Q as ChatHistoryPrimitiveItemDate,
|
|
88
|
+
J as ChatHistoryPrimitiveItemTitle,
|
|
89
|
+
z as ChatHistoryPrimitiveList,
|
|
90
|
+
V as ChatHistoryPrimitiveLoadingState,
|
|
91
|
+
X as ChatHistoryPrimitiveNewConversationButton,
|
|
92
|
+
j as ChatHistoryPrimitiveRoot,
|
|
93
|
+
q as ChatHistoryPrimitiveTitle,
|
|
94
|
+
U as EmptyState,
|
|
95
|
+
W as Footer,
|
|
96
|
+
M as Header,
|
|
97
|
+
G as Item,
|
|
98
|
+
Q as ItemDate,
|
|
99
|
+
J as ItemTitle,
|
|
100
|
+
z as List,
|
|
101
|
+
V as LoadingState,
|
|
102
|
+
X as NewConversationButton,
|
|
103
|
+
j as Root,
|
|
104
|
+
q as Title
|
|
105
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("altcha-lib"),c=require("react"),x=30*1e3;function b(l){const e=/[?&]expires=(\d+)/.exec(l);return e?Number.parseInt(e[1],10)*1e3:null}const p=async l=>{try{const e=await fetch(l,{method:"GET"});if(!e.ok)throw new Error(`Failed to fetch challenge: ${e.statusText}`);const i=await e.json(),{challenge:u,algorithm:n,salt:r,maxnumber:t}=i,{promise:g}=await w.solveChallenge(u,r,n,t),f=await g||void 0;if(!f)throw new Error("Challenge not solved");return{payload:{number:f.number,...i},expiresAt:b(r)}}catch(e){console.warn("[captcha] Error fetching/solving challenge:",e);return}},m=({baseUrl:l,shouldBypassCaptcha:e=!1,shouldMakeInitialRequest:i=!0})=>{const u=`${l}/run/auth/pow/challenge`,n=c.useRef(null),r=c.useRef(null),t=c.useCallback(()=>{const o=p(u);n.current=o,o.then(a=>{a&&(r.current=a.expiresAt)})},[u]),g=c.useCallback(async()=>{if(e)return{};n.current||t();const o=n.current;n.current=null,t();const a=n.current,h=await o;if(!h){const s=await a;return s?{"x-inkeep-challenge-solution":btoa(JSON.stringify(s.payload))}:{}}if(h.expiresAt!==null&&Date.now()>=h.expiresAt){const s=await a;return s?{"x-inkeep-challenge-solution":btoa(JSON.stringify(s.payload))}:{}}return{"x-inkeep-challenge-solution":btoa(JSON.stringify(h.payload))}},[e,t]),f=c.useCallback(()=>{e||t()},[e,t]);return c.useEffect(()=>{if(!i||e)return;const o=r.current!==null&&Date.now()>=r.current-x;(!n.current||o)&&t()},[i,e,t]),{getCaptchaHeader:g,invalidate:f}};exports.fetchAndSolveChallenge=p;exports.useCaptcha=m;
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { Payload } from 'altcha-lib/types';
|
|
2
2
|
interface UseCaptchaOptions {
|
|
3
|
-
|
|
3
|
+
baseUrl: string;
|
|
4
4
|
shouldBypassCaptcha?: boolean;
|
|
5
5
|
shouldMakeInitialRequest?: boolean;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
interface SolvedEntry {
|
|
8
|
+
payload: Payload;
|
|
9
|
+
expiresAt: number | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const fetchAndSolveChallenge: (fetchUrl: string) => Promise<SolvedEntry | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Manages the PoW captcha lifecycle for /run/* API requests.
|
|
14
|
+
*
|
|
15
|
+
* - getCaptchaHeader(): atomically consumes the current pre-fetched challenge,
|
|
16
|
+
* immediately kicks off the next fetch so a fresh solution is always warm, and
|
|
17
|
+
* returns the ready-to-use `{ 'x-inkeep-challenge-solution': '...' }` header
|
|
18
|
+
* (or {} when bypassing or on failure). Checks token expiry and falls back to
|
|
19
|
+
* the already-started pre-fetch if the resolved token is stale.
|
|
20
|
+
*
|
|
21
|
+
* - invalidate(): discards any in-flight solution and starts a fresh fetch.
|
|
22
|
+
* Call this on request errors to recover from a rejected/stale challenge.
|
|
23
|
+
*
|
|
24
|
+
* All hooks are called unconditionally — bypass logic lives inside callbacks.
|
|
25
|
+
*/
|
|
26
|
+
export declare const useCaptcha: ({ baseUrl, shouldBypassCaptcha, shouldMakeInitialRequest, }: UseCaptchaOptions) => {
|
|
27
|
+
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
28
|
+
invalidate: () => void;
|
|
12
29
|
};
|
|
13
30
|
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { solveChallenge as m } from "altcha-lib";
|
|
3
|
+
import { useRef as p, useCallback as h, useEffect as x } from "react";
|
|
4
|
+
const w = 30 * 1e3;
|
|
5
|
+
function E(i) {
|
|
6
|
+
const e = /[?&]expires=(\d+)/.exec(i);
|
|
7
|
+
return e ? Number.parseInt(e[1], 10) * 1e3 : null;
|
|
8
|
+
}
|
|
9
|
+
const y = async (i) => {
|
|
10
|
+
try {
|
|
11
|
+
const e = await fetch(i, { method: "GET" });
|
|
12
|
+
if (!e.ok)
|
|
13
|
+
throw new Error(`Failed to fetch challenge: ${e.statusText}`);
|
|
14
|
+
const c = await e.json(), { challenge: s, algorithm: t, salt: r, maxnumber: n } = c, { promise: g } = await m(
|
|
15
|
+
s,
|
|
16
|
+
r,
|
|
17
|
+
t,
|
|
18
|
+
n
|
|
19
|
+
), u = await g || void 0;
|
|
20
|
+
if (!u)
|
|
21
|
+
throw new Error("Challenge not solved");
|
|
22
|
+
return {
|
|
23
|
+
payload: { number: u.number, ...c },
|
|
24
|
+
expiresAt: E(r)
|
|
25
|
+
};
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.warn("[captcha] Error fetching/solving challenge:", e);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}, k = ({
|
|
31
|
+
baseUrl: i,
|
|
32
|
+
shouldBypassCaptcha: e = !1,
|
|
33
|
+
shouldMakeInitialRequest: c = !0
|
|
34
|
+
}) => {
|
|
35
|
+
const s = `${i}/run/auth/pow/challenge`, t = p(null), r = p(null), n = h(() => {
|
|
36
|
+
const o = y(s);
|
|
37
|
+
t.current = o, o.then((l) => {
|
|
38
|
+
l && (r.current = l.expiresAt);
|
|
39
|
+
});
|
|
40
|
+
}, [s]), g = h(async () => {
|
|
41
|
+
if (e) return {};
|
|
42
|
+
t.current || n();
|
|
43
|
+
const o = t.current;
|
|
44
|
+
t.current = null, n();
|
|
45
|
+
const l = t.current, f = await o;
|
|
46
|
+
if (!f) {
|
|
47
|
+
const a = await l;
|
|
48
|
+
return a ? { "x-inkeep-challenge-solution": btoa(JSON.stringify(a.payload)) } : {};
|
|
49
|
+
}
|
|
50
|
+
if (f.expiresAt !== null && Date.now() >= f.expiresAt) {
|
|
51
|
+
const a = await l;
|
|
52
|
+
return a ? { "x-inkeep-challenge-solution": btoa(JSON.stringify(a.payload)) } : {};
|
|
53
|
+
}
|
|
54
|
+
return { "x-inkeep-challenge-solution": btoa(JSON.stringify(f.payload)) };
|
|
55
|
+
}, [e, n]), u = h(() => {
|
|
56
|
+
e || n();
|
|
57
|
+
}, [e, n]);
|
|
58
|
+
return x(() => {
|
|
59
|
+
if (!c || e) return;
|
|
60
|
+
const o = r.current !== null && Date.now() >= r.current - w;
|
|
61
|
+
(!t.current || o) && n();
|
|
62
|
+
}, [c, e, n]), { getCaptchaHeader: g, invalidate: u };
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
y as fetchAndSolveChallenge,
|
|
66
|
+
k as useCaptcha
|
|
67
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
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 Ne=require("@ai-sdk/react"),Oe=require("ai"),t=require("react"),Pe=require("../modal/modal-provider.cjs"),_e=require("../../providers/chat-bubble-provider.cjs"),Fe=require("../../providers/sidebar-chat-provider.cjs"),Be=require("../../providers/config-provider.cjs"),De=require("./use-captcha.cjs"),Ue=require("../../hooks/use-media-query.cjs"),Le=require("../../hooks/use-anonymous-session.cjs"),He=require("../../hooks/use-conversation-loader.cjs"),H=require("../../utils/generate-uid.cjs"),$e=require("../../providers/base-events-provider.cjs"),ze=require("../../providers/chat-form-provider.cjs"),We=require("../../providers/widget-provider.cjs"),Ke=require("@radix-ui/react-use-controllable-state"),je=require("../../hooks/use-streaming-events.cjs"),Ge=require("../../hooks/use-inkeep-api-client.cjs");function Je(f){const l=f.message??"";let r=Number(f.code)||Number(f.statusCode);if(Number.isNaN(r))try{r=Number(JSON.parse(l).status)}catch{}const d=Ge.parseAuthError(r,{detail:l});return d!==null?d:r===401?"session":null}const $=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,Qe=()=>{const{baseSettings:f,aiChatSettings:l}=Be.useInkeepConfig(),[r="",d]=Ke.useControllableState({prop:l.conversationId,defaultProp:l.conversationId??""}),ce=Pe.useModal(),ue=_e.useOptionalChatBubble(),le=Fe.useOptionalSidebarChat(),{logEvent:h}=$e.useBaseEvents(),{setConversationId:de,emitToParent:C}=je.useStreamingEvents(),[v,k]=t.useState(""),pe=e=>k(e.target.value),{shouldBypassCaptcha:z,filters:W,privacyPreferences:fe}=f,{onInputMessageChange:ge,filters:K,baseUrl:S,agentUrl:me,context:j,headers:G,appId:y,apiKey:p}=l,he=ce?.isOpen??ue?.isOpen??le?.isOpen??!0,{getCaptchaHeader:b,invalidate:u}=De.useCaptcha({baseUrl:S,shouldBypassCaptcha:z||!!p,shouldMakeInitialRequest:he}),J=t.useRef(b);J.current=b;const Q=me||`${S}/run/api/chat`,{sessionToken:q,refreshSession:w}=Le.useAnonymousSession({baseUrl:S,appId:y,getCaptchaHeader:b,invalidateCaptcha:u,optOutAllAnalytics:fe?.optOutAllAnalytics}),{loadConversation:V}=He.useConversationLoader({baseUrl:S,appId:y,authToken:p??q,getCaptchaHeader:b,invalidateCaptcha:u,refreshSession:p?void 0:w}),[ve,Z]=t.useState(!1),R=t.useRef(null);R.current=q;const g=t.useRef(0),X=t.useRef(null),x=t.useRef(null),Y=t.useRef(G);Y.current=G;const T=t.useRef(void 0);T.current=W||K?JSON.stringify({...W,...K}):void 0;const ye=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return $}},[be,I]=t.useState([]),[Ce,N]=t.useState(null),Se=t.useMemo(()=>new Oe.DefaultChatTransport({api:Q,headers:()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...y?{"x-inkeep-app-id":y}:{},...R.current?{Authorization:`Bearer ${R.current}`}:{},...p?{Authorization:`Bearer ${p}`}:{},...T.current?{"inkeep-filters":T.current}:{},...Y.current}),prepareSendMessagesRequest:async e=>{const s=await J.current();return{body:{...e.body,id:e.id,messages:e.messages,trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...s}}},body:{requestContext:j}}),[Q,j,y,p]),{messages:A,sendMessage:O,addToolApprovalResponse:P,status:ee,setMessages:m,stop:te,error:_}=Ne.useChat({transport:Se,onData(e){C(e.type,e.data)},async onFinish(){C("completion",{conversationId:r}),await h({eventName:"assistant_message_received",properties:{conversationId:r}}),h({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.error("onError",{code:e.code,message:e.message});const s=z||p?null:Je(e);if(s!==null&&g.current<1){g.current++;const i=x.current,a=X.current;(async()=>{if(s==="session"){const o=await w();o&&(R.current=o)}else u();if(i){P(i);return}a&&(m(o=>{let n=[...o];return n.at(-1)?.role==="assistant"&&(n=n.slice(0,-1)),n.at(-1)?.role==="user"&&(n=n.slice(0,-1)),n}),O({text:a.content},{body:a.body}))})().catch(()=>{g.current=0,u(),m(o=>{const n=[...o],L=n[n.length-1];if(!L)return n;const ie=$;return L.role==="user"?n.push({id:H.generateUid(16),role:"assistant",parts:[{type:"text",text:ie}]}):L.parts=[{type:"text",text:ie}],n})});return}g.current=0,s!==null&&u(),h({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),m(i=>{const a=[...i],c=a[a.length-1];if(c){const o=ye(e);c.role==="user"?a.push({id:H.generateUid(16),role:"assistant",parts:[{type:"text",text:o}]}):c.parts=[{type:"text",text:o}]}return a})}}),se=ee==="submitted",F=ee==="streaming",Re=t.useMemo(()=>{const e=c=>{if(!c||typeof c!="object")return!1;const o=c;return typeof o.type=="string"&&o.type.startsWith("tool-")},i=[...A??[]].reverse().find(c=>c.role==="assistant");if(!i)return!1;const a=i.parts?.at(-1);return!(!e(a)||a.state!=="output-available"||!a.approval?.id||F)},[A,F]),re=F||Re,ne=se||re,Ie=A.length===0,B=!v.trim()||ne,Ae=Ue.useMediaQuery("(max-width: 768px)"),[Ee,E]=t.useState(null);t.useEffect(()=>{_&&E(_)},[_]);const Me=()=>E(null),ae=t.useRef(null);t.useEffect(()=>{ge?.(v)},[v]);const ke=e=>{e.key==="Enter"&&!e.shiftKey&&!B&&!e.nativeEvent.isComposing&&(e.preventDefault(),D())},D=async(e=v)=>{if(B&&(!e||e.trim().length===0))return;I([]),k(""),g.current=0,x.current=null,await h({eventName:"user_message_submitted",properties:{conversationId:r}});let s=r;s||(s=`conv_${H.generateUid(16)}`,d(s)),de(s),X.current={content:e,body:{conversationId:s}},O({text:e},{body:{conversationId:s}})},qe=t.useCallback(e=>{g.current=0,x.current=e,P(e)},[P]),U=t.useCallback(()=>{te().then(()=>{C("aborted",{conversationId:r})})},[te,r,C]),oe=()=>{Me(),m([]),d(""),I([]),N(null),u(),h({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},M=t.useCallback((e,s)=>{E(null),m(s),d(e),I([]),N(null),u()},[m,d,u]),we=t.useCallback(async(e,s)=>{U(),M(e,[]),Z(!0);try{const i=await V(e,s);i!==null&&M(e,i)}finally{s?.aborted||Z(!1)}},[M,V,U]),{openForm:xe}=ze.useChatForm(),Te=We.useWidget();return t.useImperativeHandle(l.chatFunctionsRef,()=>({submitMessage:D,updateInputMessage(e){k(e)},clearChat:oe,openForm:e=>{Te?.setView("chat"),xe(e,void 0)},focusInput:()=>{ae.current?.focus()}})),{messages:A,sendMessage:O,addToolApprovalResponse:qe,isLoading:se,isStreaming:re,isBusy:ne,error:Ee,setError:E,isSubmitDisabled:B,input:v,handleInputChange:pe,handleInputKeyDown:ke,handleSubmit:D,stop:U,clear:oe,inputRef:ae,isMobile:Ae,messageAttachments:be,setMessageAttachments:I,selectedWorkflow:Ce,setSelectedWorkflow:N,isNewChat:Ie,conversationId:r,restoreSession:M,loadAndRestoreSession:we,isSessionLoading:ve,sessionToken:q,refreshSession:w,getCaptchaHeader:b,invalidateCaptcha:u}};exports.DEFAULT_ERROR_MESSAGE=$;exports.useInkeepChat=Qe;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KeyboardEvent, Dispatch, SetStateAction, RefObject } from 'react';
|
|
2
2
|
import { Message, MessageAttachment, Workflow } from '../../../types/index.ts';
|
|
3
|
-
import { FileUIPart, ChatRequestOptions
|
|
3
|
+
import { FileUIPart, ChatRequestOptions } from 'ai';
|
|
4
4
|
export declare const DEFAULT_ERROR_MESSAGE = "Hmm.. \n\nIt seems I might be having some issues right now. Please clear the chat and try again.";
|
|
5
5
|
export declare const useInkeepChat: () => {
|
|
6
6
|
messages: Message[];
|
|
@@ -23,7 +23,10 @@ export declare const useInkeepChat: () => {
|
|
|
23
23
|
parts?: never;
|
|
24
24
|
messageId?: string;
|
|
25
25
|
} | undefined, options?: ChatRequestOptions) => Promise<void>;
|
|
26
|
-
addToolApprovalResponse:
|
|
26
|
+
addToolApprovalResponse: (approval: {
|
|
27
|
+
id: string;
|
|
28
|
+
approved: boolean;
|
|
29
|
+
}) => void;
|
|
27
30
|
isLoading: boolean;
|
|
28
31
|
isStreaming: boolean;
|
|
29
32
|
isBusy: boolean;
|
|
@@ -36,7 +39,6 @@ export declare const useInkeepChat: () => {
|
|
|
36
39
|
handleSubmit: (content?: string) => Promise<void>;
|
|
37
40
|
stop: () => void;
|
|
38
41
|
clear: () => void;
|
|
39
|
-
isEmpty: boolean;
|
|
40
42
|
inputRef: RefObject<HTMLTextAreaElement | null>;
|
|
41
43
|
isMobile: boolean;
|
|
42
44
|
messageAttachments: MessageAttachment[];
|
|
@@ -45,4 +47,11 @@ export declare const useInkeepChat: () => {
|
|
|
45
47
|
setSelectedWorkflow: Dispatch<SetStateAction<Workflow | null>>;
|
|
46
48
|
isNewChat: boolean;
|
|
47
49
|
conversationId: string;
|
|
50
|
+
restoreSession: (sessionId: string, loadedMessages: Message[]) => void;
|
|
51
|
+
loadAndRestoreSession: (sessionId: string, signal?: AbortSignal) => Promise<void>;
|
|
52
|
+
isSessionLoading: boolean;
|
|
53
|
+
sessionToken: string | null;
|
|
54
|
+
refreshSession: () => Promise<string | null>;
|
|
55
|
+
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
56
|
+
invalidateCaptcha: () => void;
|
|
48
57
|
};
|