@inkeep/agents-ui 0.15.13 → 0.15.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +230 -222
  3. package/dist/primitives/atoms/icons/built-in-icons.cjs +1 -1
  4. package/dist/primitives/atoms/icons/built-in-icons.d.ts +2 -0
  5. package/dist/primitives/atoms/icons/built-in-icons.js +33 -31
  6. package/dist/primitives/atoms/icons/inkeep-default-icons.cjs +1 -1
  7. package/dist/primitives/atoms/icons/inkeep-default-icons.js +4 -1
  8. package/dist/primitives/components/chat-history/index.cjs +1 -0
  9. package/dist/primitives/components/chat-history/index.d.ts +27 -0
  10. package/dist/primitives/components/chat-history/index.js +105 -0
  11. package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -0
  12. package/dist/primitives/components/embedded-chat/use-captcha.d.ts +23 -6
  13. package/dist/primitives/components/embedded-chat/use-captcha.js +67 -0
  14. package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
  15. package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +12 -3
  16. package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +252 -144
  17. package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
  18. package/dist/primitives/components/embedded-chat/use-stream-processor.d.ts +2 -0
  19. package/dist/primitives/components/embedded-chat/use-stream-processor.js +120 -70
  20. package/dist/primitives/components/embedded-chat.cjs +3 -3
  21. package/dist/primitives/components/embedded-chat.d.ts +5 -2
  22. package/dist/primitives/components/embedded-chat.js +1010 -967
  23. package/dist/primitives/components/index.cjs +1 -1
  24. package/dist/primitives/components/index.d.ts +1 -0
  25. package/dist/primitives/components/index.js +20 -18
  26. package/dist/primitives/hooks/use-anonymous-session.cjs +1 -0
  27. package/dist/primitives/hooks/use-anonymous-session.d.ts +12 -0
  28. package/dist/primitives/hooks/use-anonymous-session.js +57 -0
  29. package/dist/primitives/hooks/use-conversation-loader.cjs +1 -0
  30. package/dist/primitives/hooks/use-conversation-loader.d.ts +13 -0
  31. package/dist/primitives/hooks/use-conversation-loader.js +36 -0
  32. package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -0
  33. package/dist/primitives/hooks/use-inkeep-api-client.d.ts +33 -0
  34. package/dist/primitives/hooks/use-inkeep-api-client.js +87 -0
  35. package/dist/primitives/hooks/use-local-storage.cjs +1 -0
  36. package/dist/primitives/hooks/use-local-storage.d.ts +8 -0
  37. package/dist/primitives/hooks/use-local-storage.js +26 -0
  38. package/dist/primitives/index.cjs +1 -1
  39. package/dist/primitives/index.js +157 -151
  40. package/dist/primitives/providers/base-events-provider.cjs +1 -1
  41. package/dist/primitives/providers/base-events-provider.js +1 -1
  42. package/dist/primitives/providers/chat-history-provider.cjs +1 -0
  43. package/dist/primitives/providers/chat-history-provider.d.ts +32 -0
  44. package/dist/primitives/providers/chat-history-provider.js +105 -0
  45. package/dist/primitives/providers/index.cjs +1 -1
  46. package/dist/primitives/providers/index.d.ts +1 -0
  47. package/dist/primitives/providers/index.js +55 -52
  48. package/dist/primitives/utils/component-ids.cjs +1 -1
  49. package/dist/primitives/utils/component-ids.d.ts +32 -0
  50. package/dist/primitives/utils/component-ids.js +19 -1
  51. package/dist/primitives/utils/default-settings.cjs +1 -1
  52. package/dist/primitives/utils/default-settings.d.ts +2 -0
  53. package/dist/primitives/utils/default-settings.js +6 -4
  54. package/dist/react/chat-button.cjs +1 -1
  55. package/dist/react/chat-button.js +42 -38
  56. package/dist/react/embedded-chat.cjs +1 -1
  57. package/dist/react/embedded-chat.js +256 -230
  58. package/dist/react/index.cjs +1 -1
  59. package/dist/react/index.js +230 -222
  60. package/dist/react/sidebar-chat.cjs +1 -1
  61. package/dist/react/sidebar-chat.js +26 -22
  62. package/dist/styled/components/chat-bubble.cjs +1 -1
  63. package/dist/styled/components/chat-bubble.js +1 -1
  64. package/dist/styled/components/chat-history.cjs +1 -0
  65. package/dist/styled/components/chat-history.d.ts +15 -0
  66. package/dist/styled/components/chat-history.js +197 -0
  67. package/dist/styled/components/data-summary-group.cjs +1 -1
  68. package/dist/styled/components/data-summary-group.js +24 -24
  69. package/dist/styled/components/embedded-chat/session-loading.cjs +1 -0
  70. package/dist/styled/components/embedded-chat/session-loading.d.ts +1 -0
  71. package/dist/styled/components/embedded-chat/session-loading.js +26 -0
  72. package/dist/styled/components/embedded-chat.cjs +1 -1
  73. package/dist/styled/components/embedded-chat.d.ts +7 -1
  74. package/dist/styled/components/embedded-chat.js +615 -563
  75. package/dist/styled/components/embedded-search.cjs +1 -1
  76. package/dist/styled/components/embedded-search.js +1 -1
  77. package/dist/styled/components/index.cjs +1 -1
  78. package/dist/styled/components/index.d.ts +1 -0
  79. package/dist/styled/components/index.js +22 -20
  80. package/dist/styled/components/sidebar-chat.cjs +1 -1
  81. package/dist/styled/components/sidebar-chat.js +1 -1
  82. package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.cjs +1 -1
  83. package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.js +3 -2
  84. package/dist/styled/index.cjs +1 -1
  85. package/dist/styled/index.js +193 -185
  86. package/dist/styled/inkeep.css.cjs +146 -4
  87. package/dist/styled/inkeep.css.js +146 -4
  88. package/dist/types/config/ai.d.ts +17 -1
  89. package/dist/types/config/base.d.ts +21 -0
  90. package/dist/types/icons/built-in.d.ts +1 -1
  91. package/dist/types/icons/custom.d.ts +3 -0
  92. 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 O, IoBookOutline as g, IoCheckmarkOutline as f, IoCloseOutline as w, IoReturnDownForward as S, IoChevronForwardOutline as b, IoReturnDownBackOutline as P, IoCopy as B, IoCopyOutline as T, IoSearch as R, IoThumbsDownSharp as U, IoThumbsUpSharp as v, IoLinkOutline as y, IoInformationCircleOutline as G, IoSend as A, IoDocumentSharp as x, IoDocumentTextSharp as H, 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, Globe as ro, CornerDownLeft as no, Check as ao, Copy as io, Command as lo, CircleCheck as to, ArrowLeft as uo, Search as Lo, Table as ho, BriefcaseBusiness as so, ChevronUp as Co, ChevronRight as co, SquarePen as mo, Pencil as po, Mail as Io, Phone as Fo, Database as ko, BookText as Do } from "lucide-react";
8
- const Po = {
9
- FaBook: Do,
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: ko,
11
+ FaDatabase: fo,
12
12
  FaStackOverflow: E,
13
13
  FaChrome: q,
14
- FaPhone: Fo,
15
- FaEnvelope: Io,
16
- FaPencil: po,
14
+ FaPhone: Do,
15
+ FaEnvelope: ko,
16
+ FaPencil: Fo,
17
17
  FaBlog: e,
18
18
  FaSort: t,
19
- FaPenSquare: mo,
20
- FaChevronRight: co,
21
- FaChevronUp: Co,
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: H,
27
- IoDocumentSharp: x,
28
- IoSend: A,
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: P,
37
- IoChevronForwardOutline: b,
38
- IoReturnDownForward: S,
36
+ IoReturnDownBackOutline: b,
37
+ IoChevronForwardOutline: S,
38
+ IoReturnDownForward: P,
39
39
  IoCloseOutline: w,
40
- IoCheckmarkOutline: f,
41
- IoBookOutline: g,
42
- IoReaderOutline: O,
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: so,
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: ho,
60
- FaMagnifyingGlass: Lo,
61
- LuArrowLeft: uo,
62
- LuCircleCheck: to,
63
- LuCommand: lo,
64
- LuCopy: io,
65
- LuCheck: ao,
66
- LuCornerDownLeft: no,
67
- LuGlobe: ro,
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
- Po as iconMap
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
- fetchUrl: string;
3
+ baseUrl: string;
4
4
  shouldBypassCaptcha?: boolean;
5
5
  shouldMakeInitialRequest?: boolean;
6
6
  }
7
- export declare const fetchAndSolveChallenge: (fetchUrl: string) => Promise<Payload | undefined>;
8
- export declare const useCaptcha: ({ fetchUrl, shouldBypassCaptcha, shouldMakeInitialRequest, }: UseCaptchaOptions) => {
9
- getSolution: () => Promise<Payload | undefined>;
10
- prefetchSolution: () => void;
11
- invalidateSolution: () => void;
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 re=require("@ai-sdk/react"),ae=require("ai"),n=require("react"),oe=require("../../providers/config-provider.cjs"),ie=require("../../hooks/use-media-query.cjs"),U=require("../../utils/generate-uid.cjs"),ce=require("../../providers/base-events-provider.cjs"),ue=require("../../providers/chat-form-provider.cjs"),le=require("../../providers/widget-provider.cjs"),pe=require("@radix-ui/react-use-controllable-state"),de=require("../../hooks/use-streaming-events.cjs"),O=`Hmm..
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.`,ge=()=>{const{baseSettings:C,aiChatSettings:l}=oe.useInkeepConfig(),[r="",I]=pe.useControllableState({prop:l.conversationId,defaultProp:l.conversationId??""}),{logEvent:o}=ce.useBaseEvents(),{setConversationId:B,emitToParent:p}=de.useStreamingEvents(),[i,d]=n.useState(""),H=e=>d(e.target.value),{filters:M}=C,{onInputMessageChange:W,filters:w,agentUrl:_,context:g,headers:m,apiKey:f}=l,z=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${C.organizationDisplayName??"Administrator"}`;default:return O}},[K,h]=n.useState([]),[L,q]=n.useState(null),$=()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString()}),j=n.useMemo(()=>new ae.DefaultChatTransport({api:_,headers:{...f?{Authorization:`Bearer ${f}`}:{},...m},body:{requestContext:g}}),[_,f,m,g]),{messages:c,sendMessage:F,addToolApprovalResponse:G,status:x,setMessages:A,stop:Q,error:v}=re.useChat({transport:j,onData(e){p(e.type,e.data)},async onFinish(){p("completion",{conversationId:r}),await o({eventName:"assistant_message_received",properties:{conversationId:r}}),o({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.log("onError",e.message),o({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),A(u=>{const s=[...u],t=s[s.length-1];if(t){const a=z(e);t.role==="user"?s.push({id:U.generateUid(16),role:"assistant",parts:[{type:"text",text:a}]}):t.parts=[{type:"text",text:a}]}return s})}}),P=x==="submitted",S=x==="streaming",J=n.useMemo(()=>{const e=a=>{if(!a||typeof a!="object")return!1;const N=a;return typeof N.type=="string"&&N.type.startsWith("tool-")},s=[...c??[]].reverse().find(a=>a.role==="assistant");if(!s)return!1;const t=s.parts?.at(-1);return!(!e(t)||t.state!=="output-available"||!t.approval?.id||S)},[c,S]),R=S||J,k=P||R,V=c.length===0,y=!i.trim()||k,Z=ie.useMediaQuery("(max-width: 768px)"),[X,E]=n.useState(null);n.useEffect(()=>{v&&E(v)},[v]);const Y=()=>E(null),D=n.useRef(null);n.useEffect(()=>{W?.(i)},[i]);const ee=e=>{e.key==="Enter"&&!e.shiftKey&&!y&&!e.nativeEvent.isComposing&&(e.preventDefault(),b())},b=async(e=i)=>{if(y&&(!e||e.trim().length===0))return;h([]),d(""),await o({eventName:"user_message_submitted",properties:{conversationId:r}});const u=M||w?JSON.stringify({...M,...w}):void 0,s={...m};u&&(s["inkeep-filters"]=u);let t=r;t||(t=`conv_${U.generateUid(16)}`,I(t)),B(t),F({text:e},{headers:{...$(),...s},body:{conversationId:t,requestContext:g}})},te=()=>{Q().then(()=>{p("aborted",{conversationId:r})})},T=()=>{Y(),A([]),I(""),h([]),q(null),o({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},{openForm:se}=ue.useChatForm(),ne=le.useWidget();return n.useImperativeHandle(l.chatFunctionsRef,()=>({submitMessage:b,updateInputMessage(e){d(e)},clearChat:T,openForm:e=>{ne?.setView("chat"),se(e,void 0)},focusInput:()=>{D.current?.focus()}})),{messages:c,sendMessage:F,addToolApprovalResponse:G,isLoading:P,isStreaming:R,isBusy:k,error:X,setError:E,isSubmitDisabled:y,input:i,handleInputChange:H,handleInputKeyDown:ee,handleSubmit:b,stop:te,clear:T,isEmpty:c.length===0,inputRef:D,isMobile:Z,messageAttachments:K,setMessageAttachments:h,selectedWorkflow:L,setSelectedWorkflow:q,isNewChat:V,conversationId:r}};exports.DEFAULT_ERROR_MESSAGE=O;exports.useInkeepChat=ge;
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, ChatAddToolApproveResponseFunction } from 'ai';
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: ChatAddToolApproveResponseFunction;
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
  };