@inkeep/agents-ui 0.0.0-dev-20260401193828 → 0.0.0-dev-20260402200940
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 +78 -77
- 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 +6 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +282 -237
- package/dist/primitives/components/embedded-chat.cjs +5 -5
- package/dist/primitives/components/embedded-chat.d.ts +6 -5
- package/dist/primitives/components/embedded-chat.js +934 -907
- 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 +69 -68
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- 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/utils/component-ids.cjs +1 -1
- package/dist/primitives/utils/component-ids.d.ts +54 -0
- package/dist/primitives/utils/component-ids.js +37 -10
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +305 -260
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +78 -77
- 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 +2 -0
- package/dist/styled/components/embedded-chat.js +479 -449
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +89 -88
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +77 -76
- package/dist/styled/inkeep.css.cjs +253 -7
- package/dist/styled/inkeep.css.js +253 -7
- package/dist/types/icons/built-in.d.ts +1 -1
- package/dist/types/icons/custom.d.ts +8 -0
- package/package.json +7 -6
|
@@ -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 et=require("@ai-sdk/react"),we=require("./file-upload-input.cjs"),tt=require("ai"),t=require("react"),st=require("../modal/modal-provider.cjs"),rt=require("../../providers/chat-bubble-provider.cjs"),nt=require("../../providers/sidebar-chat-provider.cjs"),at=require("../../providers/config-provider.cjs"),ot=require("./use-captcha.cjs"),it=require("../../hooks/use-media-query.cjs"),ut=require("../../hooks/use-anonymous-session.cjs"),ct=require("../../hooks/use-auth-token.cjs"),lt=require("../../hooks/use-conversation-loader.cjs"),U=require("../../utils/generate-uid.cjs"),dt=require("../../providers/base-events-provider.cjs"),ft=require("../../providers/chat-form-provider.cjs"),pt=require("../../providers/widget-provider.cjs"),ht=require("@radix-ui/react-use-controllable-state"),gt=require("../../hooks/use-streaming-events.cjs"),mt=require("../../hooks/use-inkeep-api-client.cjs"),vt=require("../../hooks/use-input-notification.cjs");function yt(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=mt.parseAuthError(r,{detail:m});return d!==null?d:r===401?"session":null}const D=`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.`,bt=()=>{const{baseSettings:g,aiChatSettings:m}=at.useInkeepConfig(),[r="",d]=ht.useControllableState({prop:m.conversationId,defaultProp:m.conversationId??""}),ke=st.useModal(),Ie=rt.useOptionalChatBubble(),Te=nt.useOptionalSidebarChat(),{logEvent:v}=dt.useBaseEvents(),{setConversationId:Ee,emitToParent:E}=gt.useStreamingEvents(),te=t.useRef(r);t.useEffect(()=>{const e=te.current;te.current=r,e!==r&&v({eventName:"chat_conversation_changed",properties:{conversationId:r,previousConversationId:e}})},[r,v]);const[C,M]=t.useState(""),Me=e=>M(e.target.value),{shouldBypassCaptcha:se,filters:re,privacyPreferences:qe,userProperties:L}=g,{authToken:q,isLoading:xe,refreshToken:ne}=ct.useAuthToken(),ae=!!g.getAuthToken,f=!!q,{onInputMessageChange:Fe,filters:oe,baseUrl:x,agentUrl:Pe,context:ie,headers:ue,appId:R,apiKey:y,files:S}=m,Ne=ke?.isOpen??Ie?.isOpen??Te?.isOpen??!0,{getCaptchaHeader:A,invalidate:c}=ot.useCaptcha({baseUrl:x,shouldBypassCaptcha:se||!!y,shouldMakeInitialRequest:Ne}),ce=t.useRef(A);ce.current=A;const le=Pe||`${x}/run/api/chat`,{sessionToken:$,refreshSession:B}=ut.useAnonymousSession({baseUrl:x,appId:R,getCaptchaHeader:A,invalidateCaptcha:c,optOutAllAnalytics:qe?.optOutAllAnalytics,enabled:!f&&!xe}),{loadConversation:de}=lt.useConversationLoader({baseUrl:x,appId:R,authToken:y??(f?q:$),getCaptchaHeader:A,invalidateCaptcha:c,refreshSession:y||f?void 0:B}),[Oe,fe]=t.useState(!1),z=t.useRef(null);z.current=$;const H=t.useRef(null);H.current=q;const K=t.useRef(void 0);K.current=L&&Object.keys(L).length>0?JSON.stringify(L):void 0;const b=t.useRef(0),pe=t.useRef(null),W=t.useRef(null),w=t.useRef(void 0),_e=S?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
4
|
+
`)??"";t.useEffect(()=>{w.current=S?.length?S:void 0},[_e]);const he=t.useRef(ue);he.current=ue;const j=t.useRef(void 0);j.current=re||oe?JSON.stringify({...re,...oe}):void 0;const Ue=e=>{switch(e.code){case 400:return e.message;case 401:return ae?"Authentication failed. Please try again.":D;case 403:return`There seems to be a configuration error. Please contact ${g.organizationDisplayName??"Administrator"}`;default:return D}},[De,k]=t.useState([]),[Le,F]=t.useState(null),[P,J]=t.useState([]),$e=t.useMemo(()=>new tt.DefaultChatTransport({api:le,headers:()=>{const e=y??H.current??z.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}`}:{},...j.current?{"inkeep-filters":j.current}:{},...K.current?{"x-inkeep-user-properties":K.current}:{},...he.current}},prepareSendMessagesRequest:async e=>{const u=await ce.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:ie}}),[le,ie,R,y]),{messages:N,sendMessage:G,addToolApprovalResponse:Q,status:ge,setMessages:h,stop:O,error:V}=et.useChat({transport:$e,onData(e){E(e.type,e.data)},async onFinish(){E("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=se||y?null:yt(e);if(u!==null&&b.current<1){b.current++;const s=W.current,n=pe.current;(async()=>{if(u==="session"&&ae){const a=await ne();if(!a)throw new Error("Auth token refresh failed");H.current=a}else if(u==="session"){const a=await B();a&&(z.current=a)}else c();if(s){Q(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}),G(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],p=o[o.length-1];if(!p)return o;const l=D;return p.role==="user"?o.push({id:U.generateUid(16),role:"assistant",parts:[{type:"text",text:l}]}):p.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=Ue(e);i.role==="user"?n.push({id:U.generateUid(16),role:"assistant",parts:[{type:"text",text:a}]}):i.parts=[{type:"text",text:a}]}return n})}}),me=t.useRef(f);t.useEffect(()=>{const e=me.current;me.current=f,e!==f&&(O(),I(null),h([]),d(""),M(""),k([]),J([]),F(null),c())},[f,O,h,d,c]);const ve=ge==="submitted",Z=ge==="streaming",Be=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=[...N??[]].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||Z)},[N,Z]),ye=Z||Be,be=ve||ye,ze=N.length===0,X=!C.trim()&&P.length===0||be,He=it.useMediaQuery("(max-width: 768px)"),[Ke,I]=t.useState(null);t.useEffect(()=>{V&&I(V)},[V]);const We=()=>I(null),{inputNotification:je,showInputNotification:Ce,clearInputNotification:Je}=vt.useInputNotification(),Re=t.useRef(null);t.useEffect(()=>{Fe?.(C)},[C]);const Ge=e=>{e.key==="Enter"&&!e.shiftKey&&!X&&!e.nativeEvent.isComposing&&(e.preventDefault(),Y())},Y=async(e=C)=>{if(X&&(!e||e.trim().length===0)&&P.length===0)return;const u=P;J([]),k([]),M(""),b.current=0,W.current=null,await v({eventName:"user_message_submitted",properties:{conversationId:r}});let s=r;s||(s=`conv_${U.generateUid(16)}`,d(s)),Ee(s);const n=w.current;w.current=void 0;let i,a;if(n?.length){let o;try{o=await Promise.all(u.map(p=>{const l=we.normalizeFileType(p);return new Promise((Ye,Ae)=>{const T=new FileReader;T.onload=()=>{if(typeof T.result!="string"){Ae(new Error(`Failed to read file "${l.name}"`));return}Ye({type:"file",url:T.result,mediaType:l.type,filename:l.name})},T.onerror=()=>Ae(new Error(`Failed to read file "${l.name}"`)),T.readAsDataURL(l)})}))}catch{Ce({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(we.normalizeFileType(l));const p=o.files;i=e.trim()?{text:e,files:p}:{files:p}}else i={text:e};pe.current={content:e,body:{conversationId:s},files:a},G(i,{body:{conversationId:s}})},Qe=t.useCallback(e=>{b.current=0,W.current=e,Q(e)},[Q]),ee=t.useCallback(()=>{O().then(()=>{E("aborted",{conversationId:r})})},[O,r,E]),Se=()=>{We(),h([]),d(""),k([]),F(null),c(),w.current=S?.length?S:void 0,v({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},_=t.useCallback((e,u)=>{I(null),h(u),d(e),k([]),F(null),c(),w.current=void 0},[h,d,c]),Ve=t.useCallback(async(e,u)=>{ee(),_(e,[]),fe(!0);try{const s=await de(e,u),n=s?.[s.length-1],i=s!==null&&n?.role==="user"?[...s,{id:U.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&&_(e,i)}finally{u?.aborted||fe(!1)}},[_,de,ee]),{openForm:Ze}=ft.useChatForm(),Xe=pt.useWidget();return t.useImperativeHandle(m.chatFunctionsRef,()=>({submitMessage:Y,updateInputMessage(e){M(e)},clearChat:Se,openForm:e=>{Xe?.setView("chat"),Ze(e,void 0)},focusInput:()=>{Re.current?.focus()}})),{messages:N,sendMessage:G,addToolApprovalResponse:Qe,isLoading:ve,isStreaming:ye,isBusy:be,error:Ke,setError:I,isSubmitDisabled:X,input:C,handleInputChange:Me,handleInputKeyDown:Ge,handleSubmit:Y,stop:ee,clear:Se,inputRef:Re,isMobile:He,messageAttachments:De,setMessageAttachments:k,selectedWorkflow:Le,setSelectedWorkflow:F,files:P,setFiles:J,isNewChat:ze,conversationId:r,restoreSession:_,loadAndRestoreSession:Ve,isSessionLoading:Oe,authToken:f?q:$,refreshSession:f?ne:B,getCaptchaHeader:A,invalidateCaptcha:c,inputNotification:je,showInputNotification:Ce,clearInputNotification:Je}};exports.DEFAULT_ERROR_MESSAGE=D;exports.useInkeepChat=bt;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyboardEvent, Dispatch, SetStateAction, RefObject } from 'react';
|
|
2
2
|
import { FileUIPart, ChatRequestOptions } from 'ai';
|
|
3
3
|
import { Message, MessageAttachment, Workflow } 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[];
|
|
@@ -45,6 +46,8 @@ export declare const useInkeepChat: () => {
|
|
|
45
46
|
setMessageAttachments: Dispatch<SetStateAction<MessageAttachment[]>>;
|
|
46
47
|
selectedWorkflow: Workflow | null;
|
|
47
48
|
setSelectedWorkflow: Dispatch<SetStateAction<Workflow | null>>;
|
|
49
|
+
files: File[];
|
|
50
|
+
setFiles: Dispatch<SetStateAction<File[]>>;
|
|
48
51
|
isNewChat: boolean;
|
|
49
52
|
conversationId: string;
|
|
50
53
|
restoreSession: (sessionId: string, loadedMessages: Message[]) => void;
|
|
@@ -54,4 +57,7 @@ export declare const useInkeepChat: () => {
|
|
|
54
57
|
refreshSession: () => Promise<string | null>;
|
|
55
58
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
56
59
|
invalidateCaptcha: () => void;
|
|
60
|
+
inputNotification: InputNotification | null;
|
|
61
|
+
showInputNotification: (n: InputNotification, durationMs?: number) => void;
|
|
62
|
+
clearInputNotification: () => void;
|
|
57
63
|
};
|