@inkeep/agents-ui 0.15.26 → 0.15.27
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 +166 -174
- package/dist/primitives/atoms/dialog.cjs +1 -1
- package/dist/primitives/atoms/dialog.js +110 -106
- package/dist/primitives/atoms/file-upload.cjs +1 -0
- package/dist/primitives/atoms/file-upload.d.ts +35 -0
- package/dist/primitives/atoms/file-upload.js +45 -0
- package/dist/primitives/atoms/icons/built-in-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/built-in-icons.d.ts +8 -1
- package/dist/primitives/atoms/icons/built-in-icons.js +86 -79
- package/dist/primitives/atoms/icons/collections/pi.cjs +1 -1
- package/dist/primitives/atoms/icons/collections/pi.d.ts +6 -0
- package/dist/primitives/atoms/icons/collections/pi.js +103 -13
- package/dist/primitives/atoms/icons/inkeep-default-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/inkeep-default-icons.js +9 -1
- package/dist/primitives/components/embedded-chat/file-upload-input.cjs +1 -0
- package/dist/primitives/components/embedded-chat/file-upload-input.d.ts +68 -0
- package/dist/primitives/components/embedded-chat/file-upload-input.js +328 -0
- package/dist/primitives/components/embedded-chat/image-preview-modal.cjs +1 -0
- package/dist/primitives/components/embedded-chat/image-preview-modal.d.ts +15 -0
- package/dist/primitives/components/embedded-chat/image-preview-modal.js +71 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +7 -5
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +277 -237
- package/dist/primitives/components/embedded-chat.cjs +4 -4
- package/dist/primitives/components/embedded-chat.d.ts +7 -116
- package/dist/primitives/components/embedded-chat.js +1082 -1484
- package/dist/primitives/components/embedded-search.d.ts +1 -1
- package/dist/primitives/hooks/index.cjs +1 -1
- package/dist/primitives/hooks/index.js +15 -14
- package/dist/primitives/hooks/use-input-notification.cjs +1 -0
- package/dist/primitives/hooks/use-input-notification.d.ts +9 -0
- package/dist/primitives/hooks/use-input-notification.js +18 -0
- package/dist/primitives/hooks/use-scrolling-fades.cjs +1 -1
- package/dist/primitives/hooks/use-scrolling-fades.d.ts +1 -0
- package/dist/primitives/hooks/use-scrolling-fades.js +21 -5
- package/dist/primitives/index.cjs +1 -1
- package/dist/primitives/index.js +146 -154
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/feedback-provider.cjs +1 -1
- package/dist/primitives/providers/feedback-provider.js +37 -38
- package/dist/primitives/providers/image-preview-provider.cjs +1 -0
- package/dist/primitives/providers/image-preview-provider.d.ts +15 -0
- package/dist/primitives/providers/image-preview-provider.js +23 -0
- package/dist/primitives/providers/index.cjs +1 -1
- package/dist/primitives/providers/index.d.ts +0 -3
- package/dist/primitives/providers/index.js +54 -63
- package/dist/primitives/utils/component-ids.cjs +1 -1
- package/dist/primitives/utils/component-ids.d.ts +54 -98
- package/dist/primitives/utils/component-ids.js +44 -66
- package/dist/primitives/utils/default-settings.cjs +1 -1
- package/dist/primitives/utils/default-settings.d.ts +0 -2
- package/dist/primitives/utils/default-settings.js +6 -8
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +283 -287
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +166 -174
- package/dist/styled/components/chat-history.cjs +1 -1
- package/dist/styled/components/chat-history.d.ts +1 -1
- package/dist/styled/components/chat-history.js +31 -29
- package/dist/styled/components/embedded-chat/file-upload-input.cjs +1 -0
- package/dist/styled/components/embedded-chat/file-upload-input.d.ts +20 -0
- package/dist/styled/components/embedded-chat/file-upload-input.js +300 -0
- package/dist/styled/components/embedded-chat/image-preview-modal.cjs +1 -0
- package/dist/styled/components/embedded-chat/image-preview-modal.d.ts +11 -0
- package/dist/styled/components/embedded-chat/image-preview-modal.js +77 -0
- package/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.d.ts +4 -50
- package/dist/styled/components/embedded-chat.js +567 -1010
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +89 -88
- package/dist/styled/components/ui/recipes/citation.d.ts +1 -1
- package/dist/styled/components/ui/recipes/index.cjs +1 -1
- package/dist/styled/components/ui/recipes/index.d.ts +0 -1
- package/dist/styled/components/ui/recipes/index.js +31 -33
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +154 -162
- package/dist/styled/inkeep.css.cjs +241 -61
- package/dist/styled/inkeep.css.js +241 -61
- package/dist/types/config/ai.d.ts +1 -10
- package/dist/types/icons/built-in.d.ts +1 -1
- package/dist/types/icons/custom.d.ts +8 -0
- package/dist/types/index.d.ts +0 -1
- package/package.json +7 -6
- package/dist/primitives/providers/attachment-item-provider.cjs +0 -1
- package/dist/primitives/providers/attachment-item-provider.d.ts +0 -9
- package/dist/primitives/providers/attachment-item-provider.js +0 -13
- package/dist/primitives/providers/attachments-bar-provider.cjs +0 -1
- package/dist/primitives/providers/attachments-bar-provider.d.ts +0 -30
- package/dist/primitives/providers/attachments-bar-provider.js +0 -57
- package/dist/primitives/providers/message-attachments-provider.cjs +0 -1
- package/dist/primitives/providers/message-attachments-provider.d.ts +0 -13
- package/dist/primitives/providers/message-attachments-provider.js +0 -27
- package/dist/primitives/utils/get-message-metadata.d.ts +0 -8
- package/dist/styled/components/ui/recipes/attachment.cjs +0 -1
- package/dist/styled/components/ui/recipes/attachment.d.ts +0 -4
- package/dist/styled/components/ui/recipes/attachment.js +0 -28
- package/dist/types/config/settings/workflow.d.ts +0 -86
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),t=require("../../atoms/dialog.cjs"),l=require("../../atoms/icons/custom-icon.cjs"),m=require("../../providers/image-preview-provider.cjs"),s=require("../../utils/compose-event-handlers.cjs"),a=require("../factory.cjs"),P=a.ikp(t.Root,{_id:"aiChatImagePreviewModal"}),g=i=>{const{onOpenChange:e,...d}=i,{imagePreview:o,closeImagePreview:n}=m.useImagePreview();return r.jsx(P,{open:o!==null,onOpenChange:s.composeEventHandlers(e,v=>{v||n()}),...d})},c=a.ikp(t.Overlay,{_id:"aiChatImagePreviewModal__Overlay"}),I=a.ikp(t.Content,{_id:"aiChatImagePreviewModal__Content"}),w=i=>{const{imagePreview:e}=m.useImagePreview(),{children:d,...o}=i;return r.jsxs(I,{"aria-label":e?.name??"Image preview","aria-describedby":void 0,...o,children:[r.jsx(t.Title,{className:"sr-only",children:e?.name??"Image preview"}),d]})},C=a.ikp("img",{_id:"aiChatImagePreviewModal__Image"}),h=i=>{const{imagePreview:e}=m.useImagePreview();return r.jsx(C,{src:e?.url,alt:e?.name??"Image preview",...i})},M=a.ikp("div",{_id:"aiChatImagePreviewModal__Footer"}),u=a.ikp("span",{_id:"aiChatImagePreviewModal__FileName"}),b=i=>{const{imagePreview:e}=m.useImagePreview();return r.jsx(u,{...i,children:e?.name})},_=a.ikp(t.Close,{_id:"aiChatImagePreviewModal__Close",children:r.jsx(l.CustomIcon,{iconKey:"close"})});exports.EmbeddedChatPrimitiveImagePreviewModal=g;exports.EmbeddedChatPrimitiveImagePreviewModalClose=_;exports.EmbeddedChatPrimitiveImagePreviewModalContent=w;exports.EmbeddedChatPrimitiveImagePreviewModalFileName=b;exports.EmbeddedChatPrimitiveImagePreviewModalFooter=M;exports.EmbeddedChatPrimitiveImagePreviewModalImage=h;exports.EmbeddedChatPrimitiveImagePreviewModalOverlay=c;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ForwardRefExoticComponent, RefAttributes, DetailedHTMLProps, ImgHTMLAttributes, HTMLAttributes } from 'react';
|
|
2
|
+
import { PolymorphicProps } from '..';
|
|
3
|
+
import * as DialogPrimitive from '../../atoms/dialog';
|
|
4
|
+
declare const PrimitiveImagePreviewModal: ForwardRefExoticComponent< PolymorphicProps & Omit<DialogPrimitive.DialogProps, "_id"> & Partial<Pick<DialogPrimitive.DialogProps, "_id">>>;
|
|
5
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModal: (props: ComponentPropsWithRef<typeof PrimitiveImagePreviewModal>) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalOverlay: ForwardRefExoticComponent< PolymorphicProps & Omit<DialogPrimitive.DialogOverlayProps & RefAttributes<HTMLDivElement>, "_id"> & Partial<Pick<DialogPrimitive.DialogOverlayProps & RefAttributes<HTMLDivElement>, "_id">>>;
|
|
7
|
+
declare const PrimitiveImagePreviewModalContent: ForwardRefExoticComponent< PolymorphicProps & Omit<DialogPrimitive.DialogContentProps & RefAttributes<HTMLDivElement>, "_id"> & Partial<Pick<DialogPrimitive.DialogContentProps & RefAttributes<HTMLDivElement>, "_id">>>;
|
|
8
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalContent: (props: ComponentPropsWithRef<typeof PrimitiveImagePreviewModalContent>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare const PrimitiveImagePreviewModalImage: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "_id"> & Partial<Pick< DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "_id">>>;
|
|
10
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalImage: (props: ComponentPropsWithRef<typeof PrimitiveImagePreviewModalImage>) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalFooter: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
12
|
+
declare const PrimitiveImagePreviewModalFileName: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "_id">>>;
|
|
13
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalFileName: (props: ComponentPropsWithRef<typeof PrimitiveImagePreviewModalFileName>) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const EmbeddedChatPrimitiveImagePreviewModalClose: ForwardRefExoticComponent< PolymorphicProps & Omit<DialogPrimitive.DialogCloseProps & RefAttributes<HTMLButtonElement>, "children" | "_id"> & Partial<Pick<DialogPrimitive.DialogCloseProps & RefAttributes<HTMLButtonElement>, "children" | "_id">>>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as r, jsxs as l } from "react/jsx-runtime";
|
|
3
|
+
import { Overlay as v, Title as s, Close as P, Root as g, Content as c } from "../../atoms/dialog.js";
|
|
4
|
+
import { CustomIcon as w } from "../../atoms/icons/custom-icon.js";
|
|
5
|
+
import { useImagePreview as o } from "../../providers/image-preview-provider.js";
|
|
6
|
+
import { composeEventHandlers as I } from "../../utils/compose-event-handlers.js";
|
|
7
|
+
import { ikp as a } from "../factory.js";
|
|
8
|
+
const C = a(g, {
|
|
9
|
+
_id: "aiChatImagePreviewModal"
|
|
10
|
+
}), F = (i) => {
|
|
11
|
+
const { onOpenChange: e, ...m } = i, { imagePreview: t, closeImagePreview: d } = o();
|
|
12
|
+
return /* @__PURE__ */ r(
|
|
13
|
+
C,
|
|
14
|
+
{
|
|
15
|
+
open: t !== null,
|
|
16
|
+
onOpenChange: I(e, (n) => {
|
|
17
|
+
n || d();
|
|
18
|
+
}),
|
|
19
|
+
...m
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
}, O = a(v, {
|
|
23
|
+
_id: "aiChatImagePreviewModal__Overlay"
|
|
24
|
+
}), h = a(c, {
|
|
25
|
+
_id: "aiChatImagePreviewModal__Content"
|
|
26
|
+
}), N = (i) => {
|
|
27
|
+
const { imagePreview: e } = o(), { children: m, ...t } = i;
|
|
28
|
+
return /* @__PURE__ */ l(
|
|
29
|
+
h,
|
|
30
|
+
{
|
|
31
|
+
"aria-label": e?.name ?? "Image preview",
|
|
32
|
+
"aria-describedby": void 0,
|
|
33
|
+
...t,
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ r(s, { className: "sr-only", children: e?.name ?? "Image preview" }),
|
|
36
|
+
m
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}, _ = a("img", {
|
|
41
|
+
_id: "aiChatImagePreviewModal__Image"
|
|
42
|
+
}), x = (i) => {
|
|
43
|
+
const { imagePreview: e } = o();
|
|
44
|
+
return /* @__PURE__ */ r(
|
|
45
|
+
_,
|
|
46
|
+
{
|
|
47
|
+
src: e?.url,
|
|
48
|
+
alt: e?.name ?? "Image preview",
|
|
49
|
+
...i
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}, j = a("div", {
|
|
53
|
+
_id: "aiChatImagePreviewModal__Footer"
|
|
54
|
+
}), M = a("span", {
|
|
55
|
+
_id: "aiChatImagePreviewModal__FileName"
|
|
56
|
+
}), k = (i) => {
|
|
57
|
+
const { imagePreview: e } = o();
|
|
58
|
+
return /* @__PURE__ */ r(M, { ...i, children: e?.name });
|
|
59
|
+
}, H = a(P, {
|
|
60
|
+
_id: "aiChatImagePreviewModal__Close",
|
|
61
|
+
children: /* @__PURE__ */ r(w, { iconKey: "close" })
|
|
62
|
+
});
|
|
63
|
+
export {
|
|
64
|
+
F as EmbeddedChatPrimitiveImagePreviewModal,
|
|
65
|
+
H as EmbeddedChatPrimitiveImagePreviewModalClose,
|
|
66
|
+
N as EmbeddedChatPrimitiveImagePreviewModalContent,
|
|
67
|
+
k as EmbeddedChatPrimitiveImagePreviewModalFileName,
|
|
68
|
+
j as EmbeddedChatPrimitiveImagePreviewModalFooter,
|
|
69
|
+
x as EmbeddedChatPrimitiveImagePreviewModalImage,
|
|
70
|
+
O as EmbeddedChatPrimitiveImagePreviewModalOverlay
|
|
71
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
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 Ve=require("@ai-sdk/react"),Se=require("./file-upload-input.cjs"),Ze=require("ai"),t=require("react"),Xe=require("../modal/modal-provider.cjs"),Ye=require("../../providers/chat-bubble-provider.cjs"),et=require("../../providers/sidebar-chat-provider.cjs"),tt=require("../../providers/config-provider.cjs"),st=require("./use-captcha.cjs"),rt=require("../../hooks/use-media-query.cjs"),nt=require("../../hooks/use-anonymous-session.cjs"),at=require("../../hooks/use-auth-token.cjs"),ot=require("../../hooks/use-conversation-loader.cjs"),O=require("../../utils/generate-uid.cjs"),it=require("../../providers/base-events-provider.cjs"),ut=require("../../providers/chat-form-provider.cjs"),ct=require("../../providers/widget-provider.cjs"),lt=require("@radix-ui/react-use-controllable-state"),dt=require("../../hooks/use-streaming-events.cjs"),pt=require("../../hooks/use-inkeep-api-client.cjs"),ft=require("../../hooks/use-input-notification.cjs");function ht(g){const m=g.message??"";let r=Number(g.code)||Number(g.statusCode);if(Number.isNaN(r))try{r=Number(JSON.parse(m).status)}catch{}const d=pt.parseAuthError(r,{detail:m});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.`,
|
|
4
|
-
`)??"";t.useEffect(()=>{
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,gt=()=>{const{baseSettings:g,aiChatSettings:m}=tt.useInkeepConfig(),[r="",d]=lt.useControllableState({prop:m.conversationId,defaultProp:m.conversationId??""}),Ae=Xe.useModal(),Ie=Ye.useOptionalChatBubble(),we=et.useOptionalSidebarChat(),{logEvent:v}=it.useBaseEvents(),{setConversationId:ke,emitToParent:T}=dt.useStreamingEvents(),Y=t.useRef(r);t.useEffect(()=>{const e=Y.current;Y.current=r,e!==r&&v({eventName:"chat_conversation_changed",properties:{conversationId:r,previousConversationId:e}})},[r,v]);const[C,E]=t.useState(""),Te=e=>E(e.target.value),{shouldBypassCaptcha:ee,filters:te,privacyPreferences:Ee,userProperties:U}=g,{authToken:M,isLoading:Me,refreshToken:se}=at.useAuthToken(),re=!!g.getAuthToken,p=!!M,{onInputMessageChange:qe,filters:ne,baseUrl:q,agentUrl:xe,context:ae,headers:oe,appId:R,apiKey:y,files:S}=m,Fe=Ae?.isOpen??Ie?.isOpen??we?.isOpen??!0,{getCaptchaHeader:A,invalidate:c}=st.useCaptcha({baseUrl:q,shouldBypassCaptcha:ee||!!y,shouldMakeInitialRequest:Fe}),ie=t.useRef(A);ie.current=A;const ue=xe||`${q}/run/api/chat`,{sessionToken:D,refreshSession:L}=nt.useAnonymousSession({baseUrl:q,appId:R,getCaptchaHeader:A,invalidateCaptcha:c,optOutAllAnalytics:Ee?.optOutAllAnalytics,enabled:!p&&!Me}),{loadConversation:ce}=ot.useConversationLoader({baseUrl:q,appId:R,authToken:y??(p?M:D),getCaptchaHeader:A,invalidateCaptcha:c,refreshSession:y||p?void 0:L}),[Pe,le]=t.useState(!1),$=t.useRef(null);$.current=D;const B=t.useRef(null);B.current=M;const z=t.useRef(void 0);z.current=U&&Object.keys(U).length>0?JSON.stringify(U):void 0;const b=t.useRef(0),de=t.useRef(null),H=t.useRef(null),I=t.useRef(void 0),Ne=S?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
4
|
+
`)??"";t.useEffect(()=>{I.current=S?.length?S:void 0},[Ne]);const pe=t.useRef(oe);pe.current=oe;const K=t.useRef(void 0);K.current=te||ne?JSON.stringify({...te,...ne}):void 0;const Oe=e=>{switch(e.code){case 400:return e.message;case 401:return re?"Authentication failed. Please try again.":_;case 403:return`There seems to be a configuration error. Please contact ${g.organizationDisplayName??"Administrator"}`;default:return _}},[x,j]=t.useState([]),_e=t.useMemo(()=>new Ze.DefaultChatTransport({api:ue,headers:()=>{const e=y??B.current??$.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...R?{"x-inkeep-app-id":R}:{},...e?{Authorization:`Bearer ${e}`}:{},...K.current?{"inkeep-filters":K.current}:{},...z.current?{"x-inkeep-user-properties":z.current}:{},...pe.current}},prepareSendMessagesRequest:async e=>{const u=await ie.current(),s=e.messages[e.messages.length-1];return s||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:s?[s]:[],trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...u}}},body:{requestContext:ae}}),[ue,ae,R,y]),{messages:F,sendMessage:J,addToolApprovalResponse:G,status:fe,setMessages:h,stop:P,error:Q}=Ve.useChat({transport:_e,onData(e){T(e.type,e.data)},async onFinish(){T("completion",{conversationId:r}),await v({eventName:"assistant_message_received",properties:{conversationId:r}}),v({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.error("onError",{code:e.code,message:e.message});const u=ee||y?null:ht(e);if(u!==null&&b.current<1){b.current++;const s=H.current,n=de.current;(async()=>{if(u==="session"&&re){const a=await se();if(!a)throw new Error("Auth token refresh failed");B.current=a}else if(u==="session"){const a=await L();a&&($.current=a)}else c();if(s){G(s);return}n&&(h(a=>{let o=[...a];return o.at(-1)?.role==="assistant"&&(o=o.slice(0,-1)),o.at(-1)?.role==="user"&&(o=o.slice(0,-1)),o}),J(n.files?.length?{parts:[{type:"text",text:n.content},...n.files]}:{text:n.content},{body:n.body}))})().catch(()=>{b.current=0,c(),h(a=>{const o=[...a],f=o[o.length-1];if(!f)return o;const l=_;return f.role==="user"?o.push({id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:l}]}):f.parts=[{type:"text",text:l}],o})});return}b.current=0,u!==null&&c(),v({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),h(s=>{const n=[...s],i=n[n.length-1];if(i){const a=Oe(e);i.role==="user"?n.push({id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:a}]}):i.parts=[{type:"text",text:a}]}return n})}}),he=t.useRef(p);t.useEffect(()=>{const e=he.current;he.current=p,e!==p&&(P(),w(null),h([]),d(""),E(""),j([]),c())},[p,P,h,d,c]);const ge=fe==="submitted",W=fe==="streaming",Ue=t.useMemo(()=>{const e=i=>{if(!i||typeof i!="object")return!1;const a=i;return typeof a.type=="string"&&a.type.startsWith("tool-")},s=[...F??[]].reverse().find(i=>i.role==="assistant");if(!s)return!1;const n=s.parts?.at(-1);return!(!e(n)||n.state!=="output-available"||!n.approval?.id||W)},[F,W]),me=W||Ue,ve=ge||me,De=F.length===0,V=!C.trim()&&x.length===0||ve,Le=rt.useMediaQuery("(max-width: 768px)"),[$e,w]=t.useState(null);t.useEffect(()=>{Q&&w(Q)},[Q]);const Be=()=>w(null),{inputNotification:ze,showInputNotification:ye,clearInputNotification:He}=ft.useInputNotification(),be=t.useRef(null);t.useEffect(()=>{qe?.(C)},[C]);const Ke=e=>{e.key==="Enter"&&!e.shiftKey&&!V&&!e.nativeEvent.isComposing&&(e.preventDefault(),Z())},Z=async(e=C)=>{if(V&&(!e||e.trim().length===0)&&x.length===0)return;const u=x;j([]),E(""),b.current=0,H.current=null,await v({eventName:"user_message_submitted",properties:{conversationId:r}});let s=r;s||(s=`conv_${O.generateUid(16)}`,d(s)),ke(s);const n=I.current;I.current=void 0;let i,a;if(n?.length){let o;try{o=await Promise.all(u.map(f=>{const l=Se.normalizeFileType(f);return new Promise((We,Re)=>{const k=new FileReader;k.onload=()=>{if(typeof k.result!="string"){Re(new Error(`Failed to read file "${l.name}"`));return}We({type:"file",url:k.result,mediaType:l.type,filename:l.name})},k.onerror=()=>Re(new Error(`Failed to read file "${l.name}"`)),k.readAsDataURL(l)})}))}catch{ye({title:"Failed to attach files",message:"Could not read one or more files. Please try again."});return}a=[...o,...n],i=e.trim()?{parts:[{type:"text",text:e},...a]}:{parts:a}}else if(u.length>0){const o=new DataTransfer;for(const l of u)o.items.add(Se.normalizeFileType(l));const f=o.files;i=e.trim()?{text:e,files:f}:{files:f}}else i={text:e};de.current={content:e,body:{conversationId:s},files:a},J(i,{body:{conversationId:s}})},je=t.useCallback(e=>{b.current=0,H.current=e,G(e)},[G]),X=t.useCallback(()=>{P().then(()=>{T("aborted",{conversationId:r})})},[P,r,T]),Ce=()=>{Be(),h([]),d(""),c(),I.current=S?.length?S:void 0,v({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},N=t.useCallback((e,u)=>{w(null),h(u),d(e),c(),I.current=void 0},[h,d,c]),Je=t.useCallback(async(e,u)=>{X(),N(e,[]),le(!0);try{const s=await ce(e,u),n=s?.[s.length-1],i=s!==null&&n?.role==="user"?[...s,{id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:s;i!==null&&N(e,i)}finally{u?.aborted||le(!1)}},[N,ce,X]),{openForm:Ge}=ut.useChatForm(),Qe=ct.useWidget();return t.useImperativeHandle(m.chatFunctionsRef,()=>({submitMessage:Z,updateInputMessage(e){E(e)},clearChat:Ce,openForm:e=>{Qe?.setView("chat"),Ge(e,void 0)},focusInput:()=>{be.current?.focus()}})),{messages:F,sendMessage:J,addToolApprovalResponse:je,isLoading:ge,isStreaming:me,isBusy:ve,error:$e,setError:w,isSubmitDisabled:V,input:C,handleInputChange:Te,handleInputKeyDown:Ke,handleSubmit:Z,stop:X,clear:Ce,inputRef:be,isMobile:Le,files:x,setFiles:j,isNewChat:De,conversationId:r,restoreSession:N,loadAndRestoreSession:Je,isSessionLoading:Pe,authToken:p?M:D,refreshSession:p?se:L,getCaptchaHeader:A,invalidateCaptcha:c,inputNotification:ze,showInputNotification:ye,clearInputNotification:He}};exports.DEFAULT_ERROR_MESSAGE=_;exports.useInkeepChat=gt;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyboardEvent, Dispatch, SetStateAction, RefObject } from 'react';
|
|
2
2
|
import { FileUIPart, ChatRequestOptions } from 'ai';
|
|
3
|
-
import { Message
|
|
3
|
+
import { Message } from '../../../types/index.ts';
|
|
4
|
+
import { InputNotification } from '../../hooks/use-input-notification';
|
|
4
5
|
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
6
|
export declare const useInkeepChat: () => {
|
|
6
7
|
messages: Message[];
|
|
@@ -41,10 +42,8 @@ export declare const useInkeepChat: () => {
|
|
|
41
42
|
clear: () => void;
|
|
42
43
|
inputRef: RefObject<HTMLTextAreaElement | null>;
|
|
43
44
|
isMobile: boolean;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
selectedWorkflow: Workflow | null;
|
|
47
|
-
setSelectedWorkflow: Dispatch<SetStateAction<Workflow | null>>;
|
|
45
|
+
files: File[];
|
|
46
|
+
setFiles: Dispatch<SetStateAction<File[]>>;
|
|
48
47
|
isNewChat: boolean;
|
|
49
48
|
conversationId: string;
|
|
50
49
|
restoreSession: (sessionId: string, loadedMessages: Message[]) => void;
|
|
@@ -54,4 +53,7 @@ export declare const useInkeepChat: () => {
|
|
|
54
53
|
refreshSession: () => Promise<string | null>;
|
|
55
54
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
56
55
|
invalidateCaptcha: () => void;
|
|
56
|
+
inputNotification: InputNotification | null;
|
|
57
|
+
showInputNotification: (n: InputNotification, durationMs?: number) => void;
|
|
58
|
+
clearInputNotification: () => void;
|
|
57
59
|
};
|