@pickaxeproject/react 4.5.2 → 4.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),a=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Addons/Auth/hooks/useAuthContext.js"),t=require("../../Addons/Auth/hooks/useAuth.js"),l=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/pickaxe/useDimensionContext.js"),o=require("../../Addons/Scroll/hooks/useScrollContext.js"),r=require("../../../../hooks/studio/useStyleFontSize.js"),c=require("../../../../hooks/pickaxe/useConversation.js"),d=require("../../Addons/Artifact/hooks/useArtifactContext.js"),u=require("framer-motion"),x=require("../../../Icons/lock.svg.js"),m=require("../../../Core/ErrorAlert.js"),j=require("../../common/PickaxeHead.js"),f=require("../../common/PickaxeEmbedHead.js"),h=require("../../common/PickaxeUpgradeCard.js"),p=require("../../common/PickaxeSkeleton.js"),g=require("../../common/PickaxeHistoryButton.js"),b=require("../../Addons/Scroll/ScrollLockView.js"),v=require("../../Addons/Artifact/Renderer/index.js"),y=require("./Message.js"),k=require("./CustomMessage.js"),w=require("../../Addons/IceBreaker/index.js"),N=require("../../common/PickaxeBranding.js"),C=require("../../../../common/cn.js");exports.default=({additionalScrollHeight:O,smitheryAuthData:q,isForceHideInfo:S,isInputFocused:A,onSubmit:P,resubmitPrompt:I})=>{var L,R,H,M,D;const{sessionId:B,deploymentType:E,pickaxe:F,translations:z,misc:T,isNewChat:$,isRtl:W,isEmbed:_,isEmailLogin:U,isShowIceBreaker:V,setSessionId:G,setLastSessionId:J}=a.usePickaxeContext(),{emailInput:K,isLoggedOut:Q,isSending:X,isResendDisabled:Y,isSent:Z}=i.useAuthContext(),{onSend:ee}=t.useAuth(),{scrollContainerRef:se}=o.useScrollContext(),{messages:ae,limitData:ie,error:te}=l.useResponseContext(),{height:le,width:ne}=n.useDimensionContext(),{currentArtifact:oe,chatPopupType:re,currentPopupType:ce}=d.useArtifactContext(),de=c.useConversation(),ue=r.useStyleFontSize(),xe=s.useMemo((()=>(null==F?void 0:F.icebreakers)?F.icebreakers.slice(0,3):[]),[null==F?void 0:F.icebreakers]),me=s.useMemo((()=>{const e=!!de.data&&de.data.messages.length>1;return!S&&de.isSuccess&&$&&!e}),[S,de.isSuccess,$,de.data]),je=s.useMemo((()=>!(null==F?void 0:F.chatflag)&&(null==F?void 0:F.enablechatresponses)&&ae.length>0),[F,ae]),fe=s.useMemo((()=>!!de.data&&de.data.messages.some((e=>"intromessage"===e.area))),[de.data]),he="chat-input"===E&&U&&Q&&Z,pe=V&&!A&&!fe&&me&&ne>767,ge=V&&!A&&(fe||ne<=767),be=()=>{J(B),G("")};return e.jsxs("div",Object.assign({ref:se,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-4 scrollbar scrollbar-thin",style:{height:`calc(${le}px - 74px)`,paddingBottom:`${O+16}px`}},{children:[e.jsx(u.AnimatePresence,{children:!!oe&&"inline"===ce&&e.jsx(u.motion.div,Object.assign({className:C.default("absolute top-0 z-20 w-full px-4 py-2",re),style:{height:`calc(${le-O}px - 80px)`},initial:{opacity:0,y:-20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2,ease:"easeOut"}},{children:e.jsx(v.default,{type:"inline",className:"pxe-artifact-inline h-full shadow",artifact:{id:oe.id,version:oe.version}})}))}),e.jsxs("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px]"},{children:[me&&_&&e.jsx("div",Object.assign({className:C.default("absolute right-4 top-3 flex items-center gap-2","popup"===E&&"right-12")},{children:e.jsx(g.default,{tip:(null==z?void 0:z["chat-history"])||"Chat History",onClick:be})})),e.jsx(j.default,Object.assign({className:C.default("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",me&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxDescriptionChars:500},!he&&{onIconClick:be})),_&&!de.isLoading&&e.jsx(f.default,Object.assign({className:C.default("opacity-0 transition-all duration-500 ease-in-out h-0 w-full sticky top-0 z-10",!me&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",historyBtnTip:(null==z?void 0:z["chat-history"])||"Chat History"},!he&&{onIconClick:be,onHistoryClick:be})),e.jsxs("div",Object.assign({className:C.default("flex flex-col flex-grow mt-6 transition-all duration-300 ease-in-out w-full px-4",_&&!de.isLoading&&!me&&"mt-0")},{children:[pe&&e.jsx("div",Object.assign({className:C.default("grid grid-cols-3 gap-4",2===xe.length&&"grid-cols-2",1===xe.length&&"grid-cols-1")},{children:e.jsx(w.default,{type:"center",data:xe,onSend:P})})),he?e.jsx("div",Object.assign({className:"flex flex-col w-full"},{children:e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[e.jsx(k.default,Object.assign({chatRole:"user"},{children:e.jsxs("div",Object.assign({className:"flex items-center gap-x-3"},{children:[e.jsx(x.default,{className:"h-6 w-6 shrink-0"}),e.jsx("p",Object.assign({className:"font-semilight"},{children:K}))]}))})),e.jsx(k.default,Object.assign({chatRole:"assistant"},{children:e.jsxs("p",Object.assign({className:"py-3 font-semilight"},{children:[`${null!==(H=null==z?void 0:z["we-sent-your-an-activation-link"])&&void 0!==H?H:"We sent you an activation link. Please be sure to check your spam folder too."} `,e.jsx("span",Object.assign({className:"underline underline-offset-2 cursor-pointer",onClick:()=>{Y||X||ee(!0)}},{children:X?null!==(M=null==z?void 0:z.resending)&&void 0!==M?M:"Resending...":null!==(D=null==z?void 0:z.resend)&&void 0!==D?D:"Resend"}))]}))}))]}))})):e.jsx(e.Fragment,{children:de.isLoading&&!(null==F?void 0:F.enablechatresponses)?e.jsxs("div",Object.assign({className:"grid w-full max-w-[800px] grid-cols-1 gap-y-6 px-6 pt-10"},{children:[$&&e.jsxs("div",Object.assign({className:"flex flex-col items-center w-full"},{children:[e.jsx(p.default,{className:"w-[72px] h-[72px]"}),e.jsx(p.default,{className:"h-[20px] mt-6 w-full"}),e.jsx(p.default,{className:"h-[20px] mt-2 w-full"}),e.jsx(p.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"})]})),e.jsx(p.default,{className:"h-10 w-[70%] animate-pulse justify-self-end rounded"}),e.jsx(p.default,{className:"h-[150px] w-[70%] animate-pulse rounded"}),e.jsx(p.default,{className:"h-10 w-[50%] animate-pulse justify-self-end rounded"})]})):de.isError?e.jsx("div",Object.assign({className:"flex w-full justify-center"},{children:e.jsxs("p",Object.assign({className:C.default(ue.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e.jsx("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):de.data||je?e.jsxs("div",Object.assign({className:"flex flex-col w-full flex-grow justify-between"},{children:[e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[(null!==(R=null===(L=de.data)||void 0===L?void 0:L.messages)&&void 0!==R?R:[]).map(((s,a)=>e.jsx(y.default,{index:a,message:s},a))),ae.map(((s,a)=>{var i,t;return e.jsx(y.default,{smitheryData:q,resubmitPrompt:I,index:(null!==(t=null===(i=de.data)||void 0===i?void 0:i.messages.length)&&void 0!==t?t:0)+a,message:s,isLastMessage:a===ae.length-1},a)})),ie?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(h.default,{})})):te?e.jsx("div",Object.assign({className:C.default("flex items-center gap-x-3",W?"justify-end":"justify-start")},{children:e.jsx(m.default,{error:te})})):null]})),e.jsxs("div",Object.assign({className:C.default("flex flex-col",!T.isWhiteLabel||ge&&"mt-4")},{children:[!T.isWhiteLabel&&e.jsx(N.default,{containerClassName:C.default("justify-end",ge&&"mb-2")}),ge&&e.jsx("div",Object.assign({className:"flex flex-col items-end gap-2"},{children:e.jsx(w.default,{type:"right",data:xe,onSend:P})})),e.jsx(b.default,{})]}))]})):null})]}))]}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),a=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Addons/Auth/hooks/useAuthContext.js"),t=require("../../Addons/Auth/hooks/useAuth.js"),l=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/pickaxe/useDimensionContext.js"),o=require("../../Addons/Scroll/hooks/useScrollContext.js"),r=require("../../../../hooks/studio/useStyleFontSize.js"),c=require("../../../../hooks/pickaxe/useConversation.js"),d=require("../../Addons/Artifact/hooks/useArtifactContext.js"),u=require("framer-motion"),x=require("../../../Icons/lock.svg.js"),m=require("../../../Core/ErrorAlert.js"),j=require("../../common/PickaxeHead.js"),f=require("../../common/PickaxeEmbedHead.js"),h=require("../../common/PickaxeUpgradeCard.js"),p=require("../../common/PickaxeSkeleton.js"),g=require("../../common/PickaxeHistoryButton.js"),b=require("../../Addons/Scroll/ScrollLockView.js"),v=require("../../Addons/Artifact/Renderer/index.js"),y=require("./Message.js"),k=require("./CustomMessage.js"),w=require("../../Addons/IceBreaker/index.js"),N=require("../../common/PickaxeBranding.js"),C=require("../../../../common/cn.js");exports.default=({additionalScrollHeight:O,smitheryAuthData:q,isForceHideInfo:S,isInputFocused:A,onSubmit:P,resubmitPrompt:I})=>{var L,R,H,M,D;const{sessionId:B,deploymentType:E,pickaxe:F,translations:z,misc:T,isNewChat:$,isRtl:W,isEmbed:_,isEmailLogin:U,isShowIceBreaker:V,setSessionId:G,setLastSessionId:J}=a.usePickaxeContext(),{emailInput:K,isLoggedOut:Q,isSending:X,isResendDisabled:Y,isSent:Z}=i.useAuthContext(),{onSend:ee}=t.useAuth(),{scrollContainerRef:se}=o.useScrollContext(),{messages:ae,limitData:ie,error:te}=l.useResponseContext(),{height:le,width:ne}=n.useDimensionContext(),{currentArtifact:oe,chatPopupType:re,currentPopupType:ce}=d.useArtifactContext(),de=c.useConversation(),ue=r.useStyleFontSize(),xe=s.useMemo((()=>(null==F?void 0:F.icebreakers)?F.icebreakers.slice(0,3):[]),[null==F?void 0:F.icebreakers]),me=s.useMemo((()=>{const e=!!de.data&&de.data.messages.length>1;return!S&&de.isSuccess&&$&&!e}),[S,de.isSuccess,$,de.data]),je=s.useMemo((()=>!(null==F?void 0:F.chatflag)&&(null==F?void 0:F.enablechatresponses)&&ae.length>0),[F,ae]),fe=s.useMemo((()=>!!de.data&&de.data.messages.some((e=>"intromessage"===e.area))),[de.data]),he="chat-input"===E&&U&&Q&&Z,pe=V&&!A&&!fe&&me&&ne>767,ge=V&&!A&&(fe||ne<=767),be=()=>{J(B),G("")};return e.jsxs("div",Object.assign({ref:se,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-4 scrollbar scrollbar-thin",style:{height:`calc(${le}px - 74px)`,paddingBottom:`${O+32}px`}},{children:[e.jsx(u.AnimatePresence,{children:!!oe&&"inline"===ce&&e.jsx(u.motion.div,Object.assign({className:C.default("absolute top-0 z-20 w-full px-4 py-2",re),style:{height:`calc(${le-O}px - 80px)`},initial:{opacity:0,y:-20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2,ease:"easeOut"}},{children:e.jsx(v.default,{type:"inline",className:"pxe-artifact-inline h-full shadow",artifact:{id:oe.id,version:oe.version}})}))}),e.jsxs("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px]"},{children:[me&&_&&e.jsx("div",Object.assign({className:C.default("absolute right-4 top-3 flex items-center gap-2","popup"===E&&"right-12")},{children:e.jsx(g.default,{tip:(null==z?void 0:z["chat-history"])||"Chat History",onClick:be})})),e.jsx(j.default,Object.assign({className:C.default("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",me&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxDescriptionChars:500},!he&&{onIconClick:be})),_&&!de.isLoading&&e.jsx(f.default,Object.assign({className:C.default("opacity-0 transition-all duration-500 ease-in-out h-0 w-full sticky top-0 z-10",!me&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",historyBtnTip:(null==z?void 0:z["chat-history"])||"Chat History"},!he&&{onIconClick:be,onHistoryClick:be})),e.jsxs("div",Object.assign({className:C.default("flex flex-col flex-grow mt-6 transition-all duration-300 ease-in-out w-full px-4",_&&!de.isLoading&&!me&&"mt-0")},{children:[pe&&e.jsx("div",Object.assign({className:C.default("grid grid-cols-3 gap-4",2===xe.length&&"grid-cols-2",1===xe.length&&"grid-cols-1")},{children:e.jsx(w.default,{type:"center",data:xe,onSend:P})})),he?e.jsx("div",Object.assign({className:"flex flex-col w-full"},{children:e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[e.jsx(k.default,Object.assign({chatRole:"user"},{children:e.jsxs("div",Object.assign({className:"flex items-center gap-x-3"},{children:[e.jsx(x.default,{className:"h-6 w-6 shrink-0"}),e.jsx("p",Object.assign({className:"font-semilight"},{children:K}))]}))})),e.jsx(k.default,Object.assign({chatRole:"assistant"},{children:e.jsxs("p",Object.assign({className:"py-3 font-semilight"},{children:[`${null!==(H=null==z?void 0:z["we-sent-your-an-activation-link"])&&void 0!==H?H:"We sent you an activation link. Please be sure to check your spam folder too."} `,e.jsx("span",Object.assign({className:"underline underline-offset-2 cursor-pointer",onClick:()=>{Y||X||ee(!0)}},{children:X?null!==(M=null==z?void 0:z.resending)&&void 0!==M?M:"Resending...":null!==(D=null==z?void 0:z.resend)&&void 0!==D?D:"Resend"}))]}))}))]}))})):e.jsx(e.Fragment,{children:de.isLoading&&!(null==F?void 0:F.enablechatresponses)?e.jsxs("div",Object.assign({className:"grid w-full max-w-[800px] grid-cols-1 gap-y-6 px-6 pt-10"},{children:[$&&e.jsxs("div",Object.assign({className:"flex flex-col items-center w-full"},{children:[e.jsx(p.default,{className:"w-[72px] h-[72px]"}),e.jsx(p.default,{className:"h-[20px] mt-6 w-full"}),e.jsx(p.default,{className:"h-[20px] mt-2 w-full"}),e.jsx(p.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"})]})),e.jsx(p.default,{className:"h-10 w-[70%] animate-pulse justify-self-end rounded"}),e.jsx(p.default,{className:"h-[150px] w-[70%] animate-pulse rounded"}),e.jsx(p.default,{className:"h-10 w-[50%] animate-pulse justify-self-end rounded"})]})):de.isError?e.jsx("div",Object.assign({className:"flex w-full justify-center"},{children:e.jsxs("p",Object.assign({className:C.default(ue.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e.jsx("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):de.data||je?e.jsxs("div",Object.assign({className:"flex flex-col w-full flex-grow justify-between"},{children:[e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[(null!==(R=null===(L=de.data)||void 0===L?void 0:L.messages)&&void 0!==R?R:[]).map(((s,a)=>e.jsx(y.default,{index:a,message:s},a))),ae.map(((s,a)=>{var i,t;return e.jsx(y.default,{smitheryData:q,resubmitPrompt:I,index:(null!==(t=null===(i=de.data)||void 0===i?void 0:i.messages.length)&&void 0!==t?t:0)+a,message:s,isLastMessage:a===ae.length-1},a)})),ie?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(h.default,{})})):te?e.jsx("div",Object.assign({className:C.default("flex items-center gap-x-3",W?"justify-end":"justify-start")},{children:e.jsx(m.default,{error:te})})):null]})),e.jsxs("div",Object.assign({className:C.default("flex flex-col",!T.isWhiteLabel||ge&&"mt-4")},{children:[!T.isWhiteLabel&&e.jsx(N.default,{containerClassName:C.default("justify-end",ge&&"mb-2")}),ge&&e.jsx("div",Object.assign({className:"flex flex-col items-end gap-2"},{children:e.jsx(w.default,{type:"right",data:xe,onSend:P})})),e.jsx(b.default,{})]}))]})):null})]}))]}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react");require("../../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js");var n=require("react-speech-recognition"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),c=require("../Addons/Auth/hooks/useAuthContext.js"),u=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../Addons/Document/hooks/useDocument.js"),f=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),g=require("../../../hooks/core/useHover.js"),h=require("../../../hooks/core/useMediaQuery.js"),m=require("../../../common/documents.js"),v=require("eventsource-parser"),b=require("../../Icons/attach-vertical.svg.js"),j=require("../../Icons/arrow-right.svg.js"),y=require("../../Icons/microphone.svg.js"),x=require("../../Icons/stop.svg.js"),O=require("../Addons/Document/List.js"),k=require("../../Core/Textarea.js"),w=require("../../Core/ErrorAlert.js"),S=require("../../../common/error.js"),C=require("../../../common/cn.js");function N(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var I=N(n);const q=s.forwardRef((({resubmitPrompt:N,onFocus:q,onBlur:A,onInputHeightChange:_,initSmitheryAuthData:E},D)=>{var R,T,H;const{origin:F,pickaxeId:L,sessionId:P,sender:W,senderType:M,deploymentId:$,deploymentType:J,pickaxe:z,styles:B,colors:V,locale:U,forceMobile:G,isNewChat:K,isRtl:Q,isEmailLogin:X,isShowFeedbackMessage:Y,setIsNewChat:Z,setIsShowIceBreaker:ee,onGenerateComplete:te}=i.usePickaxeContext(),{token:se,isLoggedOut:ne,isSent:ie}=c.useAuthContext(),{messages:re,limits:oe,isGenerating:ae,setMessages:le,setStatus:ce,setLimitData:ue,setError:de}=r.useResponseContext(),{documents:fe,isUploading:pe,documentError:ge,onFileUpload:he,setDocuments:me,setDocumentError:ve}=d.useDocument(),{scrollStartSession:be,scrollEndSession:je,scrollToBottom:ye}=f.useScroll({auto:!0}),{artifacts:xe,currentPopupType:Oe,setArtifacts:ke,setCurrentArtifact:we}=p.useArtifactContext(),Se=l.useConversation(),Ce=u.useSubmit(),[Ne,Ie]=s.useState(""),[qe,Ae]=s.useState(!1),[_e,Ee]=s.useState(!1),De=s.useRef(null),Re=s.useRef(""),Te=s.useRef(null),He=s.useRef(null),Fe=s.useRef(null),{transcript:Le,listening:Pe,resetTranscript:We,browserSupportsSpeechRecognition:Me}=n.useSpeechRecognition(),[$e]=h.useMediaQuery("(max-width: 480px)"),Je=g.useHover(),{isHover:ze}=Je,Be=e.__rest(Je,["isHover"]),Ve=g.useHover(),{isHover:Ue}=Ve,Ge=e.__rest(Ve,["isHover"]),Ke=g.useHover(),{isHover:Qe}=Ke,Xe=e.__rest(Ke,["isHover"]),[Ye,Ze]=s.useState(!1),et=a.useStyleFontSize(),tt=o.useStyleInput(),st=null===(R=null==z?void 0:z.documentuploadtype)||void 0===R?void 0:R.startsWith("enduserupload"),nt=Me&&(null==z?void 0:z.enablevoicetotext),it="chat-input"===J&&K&&!ie,rt="chat-input"===J&&X&&ne&&ie,ot=qe||_e,at=s.useMemo((()=>{var e,t,s;return!!K&&(!!z&&(!Se.isLoading&&(!((null!==(t=null===(e=Se.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=z.icebreakers)||void 0===s?void 0:s.length)&&(!Y&&!it)))))}),[z,K,Y,it,Se.data,Se.isLoading]),lt=s.useMemo((()=>{if(ae||pe)return!1;const e=fe.length>0&&fe.every((e=>"finished"===e.status));return!(!Ne.trim()&&!e)&&fe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[ae,pe,Ne,fe]);s.useImperativeHandle(D,(()=>({onSubmit:ct}))),s.useEffect((()=>{ee(at)}),[at]),s.useEffect((()=>{var e;if(N){const t=Array.from(re),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;ct(s,!0)}}),[N]),s.useEffect((()=>{if(!Pe)return;const e=Re.current?`${Re.current} `:"";Ie(`${e}${Le}`)}),[Le,Pe]),s.useEffect((()=>{if(!He.current)return;(()=>{if(!He.current)return;let e=He.current.scrollHeight>52;Ne.includes("\n")||fe.length?e=!0:Ne.trim()||(e=!1),Ae(e)})()}),[Ne,fe]),s.useEffect((()=>{const e=He.current,t=Fe.current;if(!e||!t||qe||Ne.includes("\n"))return void Ee(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=Ne,document.body.appendChild(i);const r=i.offsetWidth;i.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;Ee(r>l)}),[Ne,qe]);const ct=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n;try{if(ae||pe)return;const i=fe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),r=i.length>0,o=null!=t?t:Ne;if(!o&&!r)return;de(""),ve(""),ue(null),Ie(""),Z(!1),ce("fetching"),be(),ye();const a=null!==(n=null===(e=null==z?void 0:z.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&i.length>0,l=[...s?Array.from(re.slice(0,re.length-1)):Array.from(re),...s?[]:[{id:re.length+1,role:"user",parts:[{type:"text",content:o,isVisible:!0}],documentIds:a?i:[]}],{id:re.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];le(l),ye(),a&&me([]);const c=(yield Ce.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({origin:F,pickaxeId:L,sessionId:P,senderType:M,value:o},a&&{documentIds:i}),W&&{sender:W}),se&&{studioSessionToken:se}),$&&{deploymentId:$}))).body;if(!c)throw new Error("Streaming error");const u=l.length-1,d=new TextDecoder;Te.current=c.getReader();const f=[];let p="",g=!0,h=!1,m=[...null!=xe?xe:[]];const b=v.createParser({onEvent:e=>{var t,s;if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&E){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);t&&t[1]&&s&&s[1]&&n&&n[1]&&(g=!1,E({smitheryId:t[1],serverId:s[1],name:n[1]}))}}else if("object"==typeof e&&null!==e){const t=e;"unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name&&(g=!1,E({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}))}}else if("text-start"===n.type)p="",f.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t}),le([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:re.length+1,role:"assistant",parts:f})]);else if("text-delta"===n.type)p+=n.delta,f[f.length-1].content=p,le([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:re.length+1,role:"assistant",parts:f})]);else if("text-end"===n.type)p="";else if("reasoning-start"===n.type)p="",f.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s}),le([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:re.length+1,role:"assistant",parts:f})]);else if("reasoning-delta"===n.type)p+=n.delta,f[f.length-1].content=p,le([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:re.length+1,role:"assistant",parts:f})]);else if("reasoning-end"===n.type)p="";else if(n.type.startsWith("data-")){const e=n;f.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0}),le([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:re.length+1,role:"assistant",parts:f})])}}else if("artifact_created"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ke(m),Oe.startsWith("inline")||we({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),ke(m),Oe.startsWith("inline")||we({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ke(m),Oe.startsWith("inline")||we({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");m=m.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),ke(m)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);ke(m.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);de(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(g=!1)}});for(;g&&Te.current;){const{value:e,done:t}=yield Te.current.read();if(t){g=!1;break}const s=d.decode(e);s&&(h||(ce("streaming"),h=!0),b.feed(s))}null==te||te(P)}catch(e){if("AbortError"===e.name)return;let t=S.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(oe).find((([e])=>t.includes(e)));s?ue(s[1]):de(t)}finally{ye(),ce("idle"),je(),Te.current=null}}));return rt?null:t.jsx("div",Object.assign({className:C.default("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!it&&"px-4 pb-4"),dir:Q?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({className:C.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===B.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},tt),Ye&&{backgroundColor:"#EEEEEE"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),Ze(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),Ze(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),Ze(!0)},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),Ze(!1);const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(Z(!1),yield he(e))}))},{children:[Pe&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(T=V.accent)&&void 0!==T?T:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:V.text+"90"}},{children:"Listening..."}))]})),!ae&&fe.length>0&&t.jsx(O.default,{className:"p-4 pb-0",isDisabled:ae}),t.jsx(k.default,Object.assign({ref:He,className:C.default(et.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Ne.trim()&&!Ne.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap",Q?"text-right":"text-left",ot&&"mb-12",Pe&&"text-transparent"),value:Ne,placeholder:null!==(H=null==z?void 0:z.placeholdertext)&&void 0!==H?H:Q?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Ie(e),_){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void _(0);if(t>=11)return;let s=0;t>1&&(s=50),_(24*(t-1)+s)}},onKeyDown:e=>{G||$e||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),pe||ae||ct()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),Z(!1),yield he(e))}))},q&&{onFocus:q},A&&{onBlur:A},{dir:Q?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Fe,className:C.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",ot?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!ot&&tt.backgroundColor&&{backgroundColor:tt.backgroundColor}),{borderTopRightRadius:B.cornerRadius+"px",borderBottomRightRadius:B.cornerRadius+"px"})},{children:ae?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{Te.current&&(Te.current.cancel(),Te.current=null),ce("idle")},style:{backgroundColor:V.accent,color:V.accentText}},{children:t.jsx(x.default,{className:"h-4 w-4 shrink-0"})})):Pe?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:I.default.stopListening,style:{backgroundColor:V.accent,color:V.accentText}},{children:t.jsx(x.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[st&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Ue?V.accent+"10":void 0,color:Ue?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{var e;return null===(e=De.current)||void 0===e?void 0:e.click()}},Ge,{children:[t.jsx("input",{id:"file-upload",ref:De,type:"file",accept:[...m.allowedFileMimeTypes,...m.allowedImageMimeTypes,...m.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){Z(!1),yield he(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(b.default,{className:"h-6 w-6 shrink-0"})]})),nt&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Pe?V.accent:Qe?V.accent+"10":void 0,color:Pe?V.accentText:Qe?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{Pe?I.default.stopListening():(Re.current=Ne,We(),I.default.startListening({continuous:!0,interimResults:!0,language:U||"en-US"}))}},Xe,{children:t.jsx(y.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:ze||lt?V.accent:V.accent+"10",color:ze||lt?V.accentText:V.accent+"80"},disabled:!lt,onClick:()=>ct()},Be,{children:t.jsx(j.default,{className:C.default("h-6 w-6 shrink-0",Q&&"scale-x-[-1] transform")})}))]})}))]})),ge&&t.jsx(w.default,{error:ge,className:"mt-3"})]}))}))}));q.displayName="Input",exports.default=q;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react");require("../../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js");var n=require("react-speech-recognition"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),c=require("../../../hooks/pickaxe/useDimensionContext.js"),u=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../../../hooks/pickaxe/useSubmit.js"),f=require("../Addons/Document/hooks/useDocument.js"),p=require("../Addons/Scroll/hooks/useScroll.js"),g=require("../Addons/Artifact/hooks/useArtifactContext.js"),h=require("../../../hooks/core/useHover.js"),m=require("../../../hooks/core/useMediaQuery.js"),v=require("../../../common/documents.js"),b=require("eventsource-parser"),j=require("../../Icons/attach-vertical.svg.js"),x=require("../../Icons/arrow-right.svg.js"),y=require("../../Icons/microphone.svg.js"),O=require("../../Icons/stop.svg.js"),k=require("../Addons/Document/List.js"),w=require("../../Core/Textarea.js"),S=require("../../Core/ErrorAlert.js"),C=require("../../../common/error.js"),N=require("../../../common/cn.js");function q(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var I=q(n);const A=s.forwardRef((({resubmitPrompt:q,onFocus:A,onBlur:_,onInputHeightChange:E,initSmitheryAuthData:R},D)=>{var T,H,F;const{origin:L,pickaxeId:P,sessionId:W,sender:M,senderType:$,deploymentId:z,deploymentType:J,pickaxe:B,styles:V,colors:U,locale:G,forceMobile:K,isNewChat:Q,isRtl:Y,isEmailLogin:X,isShowFeedbackMessage:Z,setIsNewChat:ee,setIsShowIceBreaker:te,onGenerateComplete:se}=r.usePickaxeContext(),{token:ne,isLoggedOut:re,isSent:ie}=u.useAuthContext(),{messages:oe,limits:ae,isGenerating:le,setMessages:ce,setStatus:ue,setLimitData:de,setError:fe}=i.useResponseContext(),{documents:pe,isUploading:ge,documentError:he,onFileUpload:me,setDocuments:ve,setDocumentError:be}=f.useDocument(),{scrollStartSession:je,scrollEndSession:xe,scrollToBottom:ye}=p.useScroll({auto:!0}),{artifacts:Oe,currentPopupType:ke,setArtifacts:we,setCurrentArtifact:Se}=g.useArtifactContext(),{height:Ce}=c.useDimensionContext(),Ne=l.useConversation(),qe=d.useSubmit(),[Ie,Ae]=s.useState(""),[_e,Ee]=s.useState(!1),[Re,De]=s.useState(!1),Te=s.useRef(null),He=s.useRef(""),Fe=s.useRef(null),Le=s.useRef(null),Pe=s.useRef(null),We=s.useRef(null),Me=Math.max(.2*Ce,100),{transcript:$e,listening:ze,resetTranscript:Je,browserSupportsSpeechRecognition:Be}=n.useSpeechRecognition(),[Ve]=m.useMediaQuery("(max-width: 480px)"),Ue=h.useHover(),{isHover:Ge}=Ue,Ke=e.__rest(Ue,["isHover"]),Qe=h.useHover(),{isHover:Ye}=Qe,Xe=e.__rest(Qe,["isHover"]),Ze=h.useHover(),{isHover:et}=Ze,tt=e.__rest(Ze,["isHover"]),[st,nt]=s.useState(!1),rt=a.useStyleFontSize(),it=o.useStyleInput(),ot=null===(T=null==B?void 0:B.documentuploadtype)||void 0===T?void 0:T.startsWith("enduserupload"),at=Be&&(null==B?void 0:B.enablevoicetotext),lt="chat-input"===J&&Q&&!ie,ct="chat-input"===J&&X&&re&&ie,ut=_e||Re,dt=s.useMemo((()=>{var e,t,s;return!!Q&&(!!B&&(!Ne.isLoading&&(!((null!==(t=null===(e=Ne.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=B.icebreakers)||void 0===s?void 0:s.length)&&(!Z&&!lt)))))}),[B,Q,Z,lt,Ne.data,Ne.isLoading]),ft=s.useMemo((()=>{if(le||ge)return!1;const e=pe.length>0&&pe.every((e=>"finished"===e.status));return!(!Ie.trim()&&!e)&&pe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[le,ge,Ie,pe]);s.useImperativeHandle(D,(()=>({onSubmit:pt}))),s.useEffect((()=>{te(dt)}),[dt]),s.useEffect((()=>{var e;if(q){const t=Array.from(oe),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;pt(s,!0)}}),[q]),s.useEffect((()=>{if(!We.current||!E)return;const e=new ResizeObserver((e=>{for(const t of e)E(t.contentRect.height)}));return e.observe(We.current),()=>{e.disconnect()}}),[E]),s.useEffect((()=>{if(!ze)return;const e=He.current?`${He.current} `:"";Ae(`${e}${$e}`)}),[$e,ze]),s.useEffect((()=>{if(!Le.current)return;(()=>{if(!Le.current)return;let e=Le.current.scrollHeight>52;Ie.includes("\n")||pe.length?e=!0:Ie.trim()||(e=!1),Ee(e)})()}),[Ie,pe]),s.useEffect((()=>{const e=Le.current,t=Pe.current;if(!e||!t||_e||Ie.includes("\n"))return void De(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,r=document.createElement("span");Object.assign(r.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),r.textContent=Ie,document.body.appendChild(r);const i=r.offsetWidth;r.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;De(i>l)}),[Ie,_e]);const pt=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n;try{if(le||ge)return;const r=pe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),i=r.length>0,o=null!=t?t:Ie;if(!o&&!i)return;fe(""),be(""),de(null),Ae(""),ee(!1),ue("fetching"),je(),ye();const a=null!==(n=null===(e=null==B?void 0:B.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&r.length>0,l=[...s?Array.from(oe.slice(0,oe.length-1)):Array.from(oe),...s?[]:[{id:oe.length+1,role:"user",parts:[{type:"text",content:o,isVisible:!0}],documentIds:a?r:[]}],{id:oe.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];ce(l),ye(),a&&ve([]);const c=(yield qe.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({origin:L,pickaxeId:P,sessionId:W,senderType:$,value:o},a&&{documentIds:r}),M&&{sender:M}),ne&&{studioSessionToken:ne}),z&&{deploymentId:z}))).body;if(!c)throw new Error("Streaming error");const u=l.length-1,d=new TextDecoder;Fe.current=c.getReader();const f=[];let p="",g=!0,h=!1,m=[...null!=Oe?Oe:[]];const v=b.createParser({onEvent:e=>{var t,s;if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&R){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);t&&t[1]&&s&&s[1]&&n&&n[1]&&(g=!1,R({smitheryId:t[1],serverId:s[1],name:n[1]}))}}else if("object"==typeof e&&null!==e){const t=e;"unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name&&(g=!1,R({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}))}}else if("text-start"===n.type)p="",f.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t}),ce([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:oe.length+1,role:"assistant",parts:f})]);else if("text-delta"===n.type)p+=n.delta,f[f.length-1].content=p,ce([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:oe.length+1,role:"assistant",parts:f})]);else if("text-end"===n.type)p="";else if("reasoning-start"===n.type)p="",f.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s}),ce([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:oe.length+1,role:"assistant",parts:f})]);else if("reasoning-delta"===n.type)p+=n.delta,f[f.length-1].content=p,ce([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:oe.length+1,role:"assistant",parts:f})]);else if("reasoning-end"===n.type)p="";else if(n.type.startsWith("data-")){const e=n;f.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0}),ce([...l.slice(0,u),Object.assign(Object.assign({},l[l.length-1]),{id:oe.length+1,role:"assistant",parts:f})])}}else if("artifact_created"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(m),ke.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),we(m),ke.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(m),ke.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");m=m.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),we(m)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);we(m.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);fe(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(g=!1)}});for(;g&&Fe.current;){const{value:e,done:t}=yield Fe.current.read();if(t){g=!1;break}const s=d.decode(e);s&&(h||(ue("streaming"),h=!0),v.feed(s))}null==se||se(W)}catch(e){if("AbortError"===e.name)return;let t=C.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(ae).find((([e])=>t.includes(e)));s?de(s[1]):fe(t)}finally{ye(),ue("idle"),xe(),Fe.current=null}}));return ct?null:t.jsx("div",Object.assign({className:N.default("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!lt&&"px-4 pb-8"),dir:Y?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:We,className:N.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===V.formFieldStyle&&"shadow"),style:Object.assign(Object.assign(Object.assign({},it),st&&{backgroundColor:"#EEEEEE"}),{maxHeight:`${Me}px`,overflowY:"auto"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),nt(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),nt(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),nt(!0)},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),nt(!1);const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(ee(!1),yield me(e))}))},{children:[ze&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(H=U.accent)&&void 0!==H?H:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:U.text+"90"}},{children:"Listening..."}))]})),!le&&pe.length>0&&t.jsx(k.default,{className:"p-4 pb-0",isDisabled:le}),t.jsx(w.default,Object.assign({ref:Le,className:N.default(rt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Ie.trim()&&!Ie.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",Y?"text-right":"text-left",ut&&"mb-12",ze&&"text-transparent"),value:Ie,placeholder:null!==(F=null==B?void 0:B.placeholdertext)&&void 0!==F?F:Y?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Ae(e),E){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void E(0);if(t>=11)return;let s=0;t>1&&(s=50),E(24*(t-1)+s)}},onKeyDown:e=>{K||Ve||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ge||le||pt()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),ee(!1),yield me(e))}))},A&&{onFocus:A},_&&{onBlur:_},{dir:Y?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Pe,className:N.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",ut?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!ut&&it.backgroundColor&&{backgroundColor:it.backgroundColor}),{borderTopRightRadius:V.cornerRadius+"px",borderBottomRightRadius:V.cornerRadius+"px"})},{children:le?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{Fe.current&&(Fe.current.cancel(),Fe.current=null),ue("idle")},style:{backgroundColor:U.accent,color:U.accentText}},{children:t.jsx(O.default,{className:"h-4 w-4 shrink-0"})})):ze?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:I.default.stopListening,style:{backgroundColor:U.accent,color:U.accentText}},{children:t.jsx(O.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[ot&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Ye?U.accent+"10":void 0,color:Ye?U.accent:U.accent+"80"},disabled:ge||le,onClick:()=>{var e;return null===(e=Te.current)||void 0===e?void 0:e.click()}},Xe,{children:[t.jsx("input",{id:"file-upload",ref:Te,type:"file",accept:[...v.allowedFileMimeTypes,...v.allowedImageMimeTypes,...v.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){ee(!1),yield me(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(j.default,{className:"h-6 w-6 shrink-0"})]})),at&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:ze?U.accent:et?U.accent+"10":void 0,color:ze?U.accentText:et?U.accent:U.accent+"80"},disabled:ge||le,onClick:()=>{ze?I.default.stopListening():(He.current=Ie,Je(),I.default.startListening({continuous:!0,interimResults:!0,language:G||"en-US"}))}},tt,{children:t.jsx(y.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Ge||ft?U.accent:U.accent+"10",color:Ge||ft?U.accentText:U.accent+"80"},disabled:!ft,onClick:()=>pt()},Ke,{children:t.jsx(x.default,{className:N.default("h-6 w-6 shrink-0",Y&&"scale-x-[-1] transform")})}))]})}))]})),he&&t.jsx(S.default,{error:he,className:"mt-3"})]}))}))}));A.displayName="Input",exports.default=A;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),r=require("./PickaxeIcon.js"),l=require("./PickaxeHistoryButton.js"),n=require("./PickaxeLogoutButton.js"),c=require("../../../common/cn.js");exports.default=({className:u,iconClassName:a,historyBtnTip:d,showHistory:x,onIconClick:p,onHistoryClick:j})=>{const{deploymentType:h,pickaxe:m,misc:f,colors:k,translations:g}=t.usePickaxeContext(),{isLoggedIn:y}=i.useAuthContext(),v=o.useStyleFontSize(),b=s.useMemo((()=>({title:(null==m?void 0:m.formtitle)||"",description:(null==m?void 0:m.formdescription)||""})),[m]);return f.isTitle||f.isDescription||!f.isWhiteLabel?e.jsxs("div",Object.assign({className:c.default("flex min-h-[56px] items-center justify-between gap-4 px-4",u),style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-4"},{children:[f.isProfileImage&&e.jsx(r.default,Object.assign({src:null==m?void 0:m.coverphoto,alt:`${null==m?void 0:m.formtitle}'s Profile Picture`,width:32,height:32,className:c.default("h-[32px] w-[32px] shrink-0 rounded-full",a,!!p&&"cursor-pointer")},p&&{onClick:p})),f.isTitle&&e.jsx("p",Object.assign({className:c.default(v.b1)},{children:b.title}))]})),!!j&&e.jsxs("div",Object.assign({className:c.default("popup"===h&&"pr-12","flex")},{children:[e.jsx(l.default,{tip:d,onClick:j}),y&&x&&e.jsx(n.default,{tip:(null==g?void 0:g["log-out"])||"Log Out"})]}))]})):null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),r=require("./PickaxeIcon.js"),l=require("./PickaxeHistoryButton.js"),n=require("./PickaxeLogoutButton.js"),c=require("../../../common/cn.js");exports.default=({className:u,iconClassName:a,historyBtnTip:d,onIconClick:x,onHistoryClick:p})=>{const{deploymentType:j,pickaxe:m,misc:f,colors:h,translations:k}=t.usePickaxeContext(),{isLoggedIn:g}=i.useAuthContext(),y=o.useStyleFontSize(),v=s.useMemo((()=>({title:(null==m?void 0:m.formtitle)||"",description:(null==m?void 0:m.formdescription)||""})),[m]);return f.isTitle||f.isDescription||!f.isWhiteLabel?e.jsxs("div",Object.assign({className:c.default("flex min-h-[56px] items-center justify-between gap-4 px-4",u),style:{backgroundColor:h.secondary,color:h.secondaryText}},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-4"},{children:[f.isProfileImage&&e.jsx(r.default,Object.assign({src:null==m?void 0:m.coverphoto,alt:`${null==m?void 0:m.formtitle}'s Profile Picture`,width:32,height:32,className:c.default("h-[32px] w-[32px] shrink-0 rounded-full",a,!!x&&"cursor-pointer")},x&&{onClick:x})),f.isTitle&&e.jsx("p",Object.assign({className:c.default(y.b1)},{children:v.title}))]})),!!p&&e.jsxs("div",Object.assign({className:c.default("popup"===j&&"pr-12","flex")},{children:[e.jsx(l.default,{tip:d,onClick:p}),g&&e.jsx(n.default,{tip:(null==k?void 0:k["log-out"])||"Log Out"})]}))]})):null};
@@ -2,9 +2,8 @@ interface PickaxeEmbedHeadProps {
2
2
  className?: string;
3
3
  iconClassName?: string;
4
4
  historyBtnTip?: string;
5
- showHistory?: boolean;
6
5
  onIconClick?: () => void;
7
6
  onHistoryClick?: () => void;
8
7
  }
9
- declare const PickaxeEmbedHead: ({ className, iconClassName, historyBtnTip, showHistory, onIconClick, onHistoryClick, }: PickaxeEmbedHeadProps) => import("react/jsx-runtime").JSX.Element | null;
8
+ declare const PickaxeEmbedHead: ({ className, iconClassName, historyBtnTip, onIconClick, onHistoryClick, }: PickaxeEmbedHeadProps) => import("react/jsx-runtime").JSX.Element | null;
10
9
  export default PickaxeEmbedHead;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as s,Fragment as i}from"react/jsx-runtime";import{useMemo as t}from"react";import{usePickaxeContext as a}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as o}from"../../Addons/Auth/hooks/useAuthContext.js";import{useAuth as l}from"../../Addons/Auth/hooks/useAuth.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDimensionContext as r}from"../../../../hooks/pickaxe/useDimensionContext.js";import{useScrollContext as c}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as m}from"../../../../hooks/studio/useStyleFontSize.js";import{useConversation as d}from"../../../../hooks/pickaxe/useConversation.js";import{useArtifactContext as p}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{AnimatePresence as u,motion as h}from"framer-motion";import f from"../../../Icons/lock.svg.js";import g from"../../../Core/ErrorAlert.js";import x from"../../common/PickaxeHead.js";import j from"../../common/PickaxeEmbedHead.js";import b from"../../common/PickaxeUpgradeCard.js";import v from"../../common/PickaxeSkeleton.js";import y from"../../common/PickaxeHistoryButton.js";import k from"../../Addons/Scroll/ScrollLockView.js";import w from"../../Addons/Artifact/Renderer/index.js";import N from"./Message.js";import O from"./CustomMessage.js";import C from"../../Addons/IceBreaker/index.js";import S from"../../common/PickaxeBranding.js";import A from"../../../../common/cn.js";const P=({additionalScrollHeight:P,smitheryAuthData:I,isForceHideInfo:L,isInputFocused:H,onSubmit:R,resubmitPrompt:B})=>{var D,E,T,$,z;const{sessionId:F,deploymentType:M,pickaxe:W,translations:U,misc:V,isNewChat:_,isRtl:q,isEmbed:G,isEmailLogin:J,isShowIceBreaker:K,setSessionId:Q,setLastSessionId:X}=a(),{emailInput:Y,isLoggedOut:Z,isSending:ee,isResendDisabled:se,isSent:ie}=o(),{onSend:te}=l(),{scrollContainerRef:ae}=c(),{messages:oe,limitData:le,error:ne}=n(),{height:re,width:ce}=r(),{currentArtifact:me,chatPopupType:de,currentPopupType:pe}=p(),ue=d(),he=m(),fe=t((()=>(null==W?void 0:W.icebreakers)?W.icebreakers.slice(0,3):[]),[null==W?void 0:W.icebreakers]),ge=t((()=>{const e=!!ue.data&&ue.data.messages.length>1;return!L&&ue.isSuccess&&_&&!e}),[L,ue.isSuccess,_,ue.data]),xe=t((()=>!(null==W?void 0:W.chatflag)&&(null==W?void 0:W.enablechatresponses)&&oe.length>0),[W,oe]),je=t((()=>!!ue.data&&ue.data.messages.some((e=>"intromessage"===e.area))),[ue.data]),be="chat-input"===M&&J&&Z&&ie,ve=K&&!H&&!je&&ge&&ce>767,ye=K&&!H&&(je||ce<=767),ke=()=>{X(F),Q("")};return e("div",Object.assign({ref:ae,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-4 scrollbar scrollbar-thin",style:{height:`calc(${re}px - 74px)`,paddingBottom:`${P+16}px`}},{children:[s(u,{children:!!me&&"inline"===pe&&s(h.div,Object.assign({className:A("absolute top-0 z-20 w-full px-4 py-2",de),style:{height:`calc(${re-P}px - 80px)`},initial:{opacity:0,y:-20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2,ease:"easeOut"}},{children:s(w,{type:"inline",className:"pxe-artifact-inline h-full shadow",artifact:{id:me.id,version:me.version}})}))}),e("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px]"},{children:[ge&&G&&s("div",Object.assign({className:A("absolute right-4 top-3 flex items-center gap-2","popup"===M&&"right-12")},{children:s(y,{tip:(null==U?void 0:U["chat-history"])||"Chat History",onClick:ke})})),s(x,Object.assign({className:A("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",ge&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxDescriptionChars:500},!be&&{onIconClick:ke})),G&&!ue.isLoading&&s(j,Object.assign({className:A("opacity-0 transition-all duration-500 ease-in-out h-0 w-full sticky top-0 z-10",!ge&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",historyBtnTip:(null==U?void 0:U["chat-history"])||"Chat History"},!be&&{onIconClick:ke,onHistoryClick:ke})),e("div",Object.assign({className:A("flex flex-col flex-grow mt-6 transition-all duration-300 ease-in-out w-full px-4",G&&!ue.isLoading&&!ge&&"mt-0")},{children:[ve&&s("div",Object.assign({className:A("grid grid-cols-3 gap-4",2===fe.length&&"grid-cols-2",1===fe.length&&"grid-cols-1")},{children:s(C,{type:"center",data:fe,onSend:R})})),be?s("div",Object.assign({className:"flex flex-col w-full"},{children:e("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[s(O,Object.assign({chatRole:"user"},{children:e("div",Object.assign({className:"flex items-center gap-x-3"},{children:[s(f,{className:"h-6 w-6 shrink-0"}),s("p",Object.assign({className:"font-semilight"},{children:Y}))]}))})),s(O,Object.assign({chatRole:"assistant"},{children:e("p",Object.assign({className:"py-3 font-semilight"},{children:[`${null!==(T=null==U?void 0:U["we-sent-your-an-activation-link"])&&void 0!==T?T:"We sent you an activation link. Please be sure to check your spam folder too."} `,s("span",Object.assign({className:"underline underline-offset-2 cursor-pointer",onClick:()=>{se||ee||te(!0)}},{children:ee?null!==($=null==U?void 0:U.resending)&&void 0!==$?$:"Resending...":null!==(z=null==U?void 0:U.resend)&&void 0!==z?z:"Resend"}))]}))}))]}))})):s(i,{children:ue.isLoading&&!(null==W?void 0:W.enablechatresponses)?e("div",Object.assign({className:"grid w-full max-w-[800px] grid-cols-1 gap-y-6 px-6 pt-10"},{children:[_&&e("div",Object.assign({className:"flex flex-col items-center w-full"},{children:[s(v,{className:"w-[72px] h-[72px]"}),s(v,{className:"h-[20px] mt-6 w-full"}),s(v,{className:"h-[20px] mt-2 w-full"}),s(v,{className:"h-[20px] mt-2 w-full max-w-[400px]"})]})),s(v,{className:"h-10 w-[70%] animate-pulse justify-self-end rounded"}),s(v,{className:"h-[150px] w-[70%] animate-pulse rounded"}),s(v,{className:"h-10 w-[50%] animate-pulse justify-self-end rounded"})]})):ue.isError?s("div",Object.assign({className:"flex w-full justify-center"},{children:e("p",Object.assign({className:A(he.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",s("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):ue.data||xe?e("div",Object.assign({className:"flex flex-col w-full flex-grow justify-between"},{children:[e("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[(null!==(E=null===(D=ue.data)||void 0===D?void 0:D.messages)&&void 0!==E?E:[]).map(((e,i)=>s(N,{index:i,message:e},i))),oe.map(((e,i)=>{var t,a;return s(N,{smitheryData:I,resubmitPrompt:B,index:(null!==(a=null===(t=ue.data)||void 0===t?void 0:t.messages.length)&&void 0!==a?a:0)+i,message:e,isLastMessage:i===oe.length-1},i)})),le?s("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:s(b,{})})):ne?s("div",Object.assign({className:A("flex items-center gap-x-3",q?"justify-end":"justify-start")},{children:s(g,{error:ne})})):null]})),e("div",Object.assign({className:A("flex flex-col",!V.isWhiteLabel||ye&&"mt-4")},{children:[!V.isWhiteLabel&&s(S,{containerClassName:A("justify-end",ye&&"mb-2")}),ye&&s("div",Object.assign({className:"flex flex-col items-end gap-2"},{children:s(C,{type:"right",data:fe,onSend:R})})),s(k,{})]}))]})):null})]}))]}))]}))};export{P as default};
1
+ import{jsxs as e,jsx as s,Fragment as i}from"react/jsx-runtime";import{useMemo as t}from"react";import{usePickaxeContext as a}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as o}from"../../Addons/Auth/hooks/useAuthContext.js";import{useAuth as l}from"../../Addons/Auth/hooks/useAuth.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDimensionContext as r}from"../../../../hooks/pickaxe/useDimensionContext.js";import{useScrollContext as c}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as m}from"../../../../hooks/studio/useStyleFontSize.js";import{useConversation as d}from"../../../../hooks/pickaxe/useConversation.js";import{useArtifactContext as p}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{AnimatePresence as u,motion as h}from"framer-motion";import f from"../../../Icons/lock.svg.js";import g from"../../../Core/ErrorAlert.js";import x from"../../common/PickaxeHead.js";import j from"../../common/PickaxeEmbedHead.js";import b from"../../common/PickaxeUpgradeCard.js";import v from"../../common/PickaxeSkeleton.js";import y from"../../common/PickaxeHistoryButton.js";import k from"../../Addons/Scroll/ScrollLockView.js";import w from"../../Addons/Artifact/Renderer/index.js";import N from"./Message.js";import O from"./CustomMessage.js";import C from"../../Addons/IceBreaker/index.js";import S from"../../common/PickaxeBranding.js";import A from"../../../../common/cn.js";const P=({additionalScrollHeight:P,smitheryAuthData:I,isForceHideInfo:L,isInputFocused:H,onSubmit:R,resubmitPrompt:B})=>{var D,E,T,$,z;const{sessionId:F,deploymentType:M,pickaxe:W,translations:U,misc:V,isNewChat:_,isRtl:q,isEmbed:G,isEmailLogin:J,isShowIceBreaker:K,setSessionId:Q,setLastSessionId:X}=a(),{emailInput:Y,isLoggedOut:Z,isSending:ee,isResendDisabled:se,isSent:ie}=o(),{onSend:te}=l(),{scrollContainerRef:ae}=c(),{messages:oe,limitData:le,error:ne}=n(),{height:re,width:ce}=r(),{currentArtifact:me,chatPopupType:de,currentPopupType:pe}=p(),ue=d(),he=m(),fe=t((()=>(null==W?void 0:W.icebreakers)?W.icebreakers.slice(0,3):[]),[null==W?void 0:W.icebreakers]),ge=t((()=>{const e=!!ue.data&&ue.data.messages.length>1;return!L&&ue.isSuccess&&_&&!e}),[L,ue.isSuccess,_,ue.data]),xe=t((()=>!(null==W?void 0:W.chatflag)&&(null==W?void 0:W.enablechatresponses)&&oe.length>0),[W,oe]),je=t((()=>!!ue.data&&ue.data.messages.some((e=>"intromessage"===e.area))),[ue.data]),be="chat-input"===M&&J&&Z&&ie,ve=K&&!H&&!je&&ge&&ce>767,ye=K&&!H&&(je||ce<=767),ke=()=>{X(F),Q("")};return e("div",Object.assign({ref:ae,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-4 scrollbar scrollbar-thin",style:{height:`calc(${re}px - 74px)`,paddingBottom:`${P+32}px`}},{children:[s(u,{children:!!me&&"inline"===pe&&s(h.div,Object.assign({className:A("absolute top-0 z-20 w-full px-4 py-2",de),style:{height:`calc(${re-P}px - 80px)`},initial:{opacity:0,y:-20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.2,ease:"easeOut"}},{children:s(w,{type:"inline",className:"pxe-artifact-inline h-full shadow",artifact:{id:me.id,version:me.version}})}))}),e("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px]"},{children:[ge&&G&&s("div",Object.assign({className:A("absolute right-4 top-3 flex items-center gap-2","popup"===M&&"right-12")},{children:s(y,{tip:(null==U?void 0:U["chat-history"])||"Chat History",onClick:ke})})),s(x,Object.assign({className:A("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",ge&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxDescriptionChars:500},!be&&{onIconClick:ke})),G&&!ue.isLoading&&s(j,Object.assign({className:A("opacity-0 transition-all duration-500 ease-in-out h-0 w-full sticky top-0 z-10",!ge&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",historyBtnTip:(null==U?void 0:U["chat-history"])||"Chat History"},!be&&{onIconClick:ke,onHistoryClick:ke})),e("div",Object.assign({className:A("flex flex-col flex-grow mt-6 transition-all duration-300 ease-in-out w-full px-4",G&&!ue.isLoading&&!ge&&"mt-0")},{children:[ve&&s("div",Object.assign({className:A("grid grid-cols-3 gap-4",2===fe.length&&"grid-cols-2",1===fe.length&&"grid-cols-1")},{children:s(C,{type:"center",data:fe,onSend:R})})),be?s("div",Object.assign({className:"flex flex-col w-full"},{children:e("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[s(O,Object.assign({chatRole:"user"},{children:e("div",Object.assign({className:"flex items-center gap-x-3"},{children:[s(f,{className:"h-6 w-6 shrink-0"}),s("p",Object.assign({className:"font-semilight"},{children:Y}))]}))})),s(O,Object.assign({chatRole:"assistant"},{children:e("p",Object.assign({className:"py-3 font-semilight"},{children:[`${null!==(T=null==U?void 0:U["we-sent-your-an-activation-link"])&&void 0!==T?T:"We sent you an activation link. Please be sure to check your spam folder too."} `,s("span",Object.assign({className:"underline underline-offset-2 cursor-pointer",onClick:()=>{se||ee||te(!0)}},{children:ee?null!==($=null==U?void 0:U.resending)&&void 0!==$?$:"Resending...":null!==(z=null==U?void 0:U.resend)&&void 0!==z?z:"Resend"}))]}))}))]}))})):s(i,{children:ue.isLoading&&!(null==W?void 0:W.enablechatresponses)?e("div",Object.assign({className:"grid w-full max-w-[800px] grid-cols-1 gap-y-6 px-6 pt-10"},{children:[_&&e("div",Object.assign({className:"flex flex-col items-center w-full"},{children:[s(v,{className:"w-[72px] h-[72px]"}),s(v,{className:"h-[20px] mt-6 w-full"}),s(v,{className:"h-[20px] mt-2 w-full"}),s(v,{className:"h-[20px] mt-2 w-full max-w-[400px]"})]})),s(v,{className:"h-10 w-[70%] animate-pulse justify-self-end rounded"}),s(v,{className:"h-[150px] w-[70%] animate-pulse rounded"}),s(v,{className:"h-10 w-[50%] animate-pulse justify-self-end rounded"})]})):ue.isError?s("div",Object.assign({className:"flex w-full justify-center"},{children:e("p",Object.assign({className:A(he.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",s("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):ue.data||xe?e("div",Object.assign({className:"flex flex-col w-full flex-grow justify-between"},{children:[e("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[(null!==(E=null===(D=ue.data)||void 0===D?void 0:D.messages)&&void 0!==E?E:[]).map(((e,i)=>s(N,{index:i,message:e},i))),oe.map(((e,i)=>{var t,a;return s(N,{smitheryData:I,resubmitPrompt:B,index:(null!==(a=null===(t=ue.data)||void 0===t?void 0:t.messages.length)&&void 0!==a?a:0)+i,message:e,isLastMessage:i===oe.length-1},i)})),le?s("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:s(b,{})})):ne?s("div",Object.assign({className:A("flex items-center gap-x-3",q?"justify-end":"justify-start")},{children:s(g,{error:ne})})):null]})),e("div",Object.assign({className:A("flex flex-col",!V.isWhiteLabel||ye&&"mt-4")},{children:[!V.isWhiteLabel&&s(S,{containerClassName:A("justify-end",ye&&"mb-2")}),ye&&s("div",Object.assign({className:"flex flex-col items-end gap-2"},{children:s(C,{type:"right",data:fe,onSend:R})})),s(k,{})]}))]})):null})]}))]}))]}))};export{P as default};
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as n,Fragment as o}from"react/jsx-runtime";import{forwardRef as i,useState as r,useRef as a,useMemo as l,useImperativeHandle as c,useEffect as d}from"react";import"../../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js";import u,{useSpeechRecognition as m}from"react-speech-recognition";import{usePickaxeContext as p}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as f}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as g}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as h}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as v}from"../../../hooks/pickaxe/useConversation.js";import{useAuthContext as b}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as y}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as j}from"../Addons/Document/hooks/useDocument.js";import{useScroll as x}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as O}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as k}from"../../../hooks/core/useHover.js";import{useMediaQuery as w}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as S,allowedImageMimeTypes as N,additionalAllowedFileExtensions as C}from"../../../common/documents.js";import{createParser as I}from"eventsource-parser";import A from"../../Icons/attach-vertical.svg.js";import D from"../../Icons/arrow-right.svg.js";import E from"../../Icons/microphone.svg.js";import T from"../../Icons/stop.svg.js";import R from"../Addons/Document/List.js";import L from"../../Core/Textarea.js";import W from"../../Core/ErrorAlert.js";import _ from"../../../common/error.js";import H from"../../../common/cn.js";const F=i((({resubmitPrompt:i,onFocus:F,onBlur:P,onInputHeightChange:$,initSmitheryAuthData:J},B)=>{var V,z,M;const{origin:U,pickaxeId:q,sessionId:G,sender:K,senderType:Q,deploymentId:X,deploymentType:Y,pickaxe:Z,styles:ee,colors:te,locale:se,forceMobile:ne,isNewChat:oe,isRtl:ie,isEmailLogin:re,isShowFeedbackMessage:ae,setIsNewChat:le,setIsShowIceBreaker:ce,onGenerateComplete:de}=p(),{token:ue,isLoggedOut:me,isSent:pe}=b(),{messages:fe,limits:ge,isGenerating:he,setMessages:ve,setStatus:be,setLimitData:ye,setError:je}=f(),{documents:xe,isUploading:Oe,documentError:ke,onFileUpload:we,setDocuments:Se,setDocumentError:Ne}=j(),{scrollStartSession:Ce,scrollEndSession:Ie,scrollToBottom:Ae}=x({auto:!0}),{artifacts:De,currentPopupType:Ee,setArtifacts:Te,setCurrentArtifact:Re}=O(),Le=v(),We=y(),[_e,He]=r(""),[Fe,Pe]=r(!1),[$e,Je]=r(!1),Be=a(null),Ve=a(""),ze=a(null),Me=a(null),Ue=a(null),{transcript:qe,listening:Ge,resetTranscript:Ke,browserSupportsSpeechRecognition:Qe}=m(),[Xe]=w("(max-width: 480px)"),Ye=k(),{isHover:Ze}=Ye,et=e(Ye,["isHover"]),tt=k(),{isHover:st}=tt,nt=e(tt,["isHover"]),ot=k(),{isHover:it}=ot,rt=e(ot,["isHover"]),[at,lt]=r(!1),ct=h(),dt=g(),ut=null===(V=null==Z?void 0:Z.documentuploadtype)||void 0===V?void 0:V.startsWith("enduserupload"),mt=Qe&&(null==Z?void 0:Z.enablevoicetotext),pt="chat-input"===Y&&oe&&!pe,ft="chat-input"===Y&&re&&me&&pe,gt=Fe||$e,ht=l((()=>{var e,t,s;return!!oe&&(!!Z&&(!Le.isLoading&&(!((null!==(t=null===(e=Le.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=Z.icebreakers)||void 0===s?void 0:s.length)&&(!ae&&!pt)))))}),[Z,oe,ae,pt,Le.data,Le.isLoading]),vt=l((()=>{if(he||Oe)return!1;const e=xe.length>0&&xe.every((e=>"finished"===e.status));return!(!_e.trim()&&!e)&&xe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[he,Oe,_e,xe]);c(B,(()=>({onSubmit:bt}))),d((()=>{ce(ht)}),[ht]),d((()=>{var e;if(i){const t=Array.from(fe),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;bt(s,!0)}}),[i]),d((()=>{if(!Ge)return;const e=Ve.current?`${Ve.current} `:"";He(`${e}${qe}`)}),[qe,Ge]),d((()=>{if(!Me.current)return;(()=>{if(!Me.current)return;let e=Me.current.scrollHeight>52;_e.includes("\n")||xe.length?e=!0:_e.trim()||(e=!1),Pe(e)})()}),[_e,xe]),d((()=>{const e=Me.current,t=Ue.current;if(!e||!t||Fe||_e.includes("\n"))return void Je(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=_e,document.body.appendChild(o);const i=o.offsetWidth;o.remove();const r=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;Je(i>l)}),[_e,Fe]);const bt=(e,s=!1)=>t(void 0,void 0,void 0,(function*(){var t,n;try{if(he||Oe)return;const o=xe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),i=o.length>0,r=null!=e?e:_e;if(!r&&!i)return;je(""),Ne(""),ye(null),He(""),le(!1),be("fetching"),Ce(),Ae();const a=null!==(n=null===(t=null==Z?void 0:Z.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==n&&n&&o.length>0,l=[...s?Array.from(fe.slice(0,fe.length-1)):Array.from(fe),...s?[]:[{id:fe.length+1,role:"user",parts:[{type:"text",content:r,isVisible:!0}],documentIds:a?o:[]}],{id:fe.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];ve(l),Ae(),a&&Se([]);const c=(yield We.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({origin:U,pickaxeId:q,sessionId:G,senderType:Q,value:r},a&&{documentIds:o}),K&&{sender:K}),ue&&{studioSessionToken:ue}),X&&{deploymentId:X}))).body;if(!c)throw new Error("Streaming error");const d=l.length-1,u=new TextDecoder;ze.current=c.getReader();const m=[];let p="",f=!0,g=!1,h=[...null!=De?De:[]];const v=I({onEvent:e=>{var t,s;if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&J){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);t&&t[1]&&s&&s[1]&&n&&n[1]&&(f=!1,J({smitheryId:t[1],serverId:s[1],name:n[1]}))}}else if("object"==typeof e&&null!==e){const t=e;"unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name&&(f=!1,J({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}))}}else if("text-start"===n.type)p="",m.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t}),ve([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:fe.length+1,role:"assistant",parts:m})]);else if("text-delta"===n.type)p+=n.delta,m[m.length-1].content=p,ve([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:fe.length+1,role:"assistant",parts:m})]);else if("text-end"===n.type)p="";else if("reasoning-start"===n.type)p="",m.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s}),ve([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:fe.length+1,role:"assistant",parts:m})]);else if("reasoning-delta"===n.type)p+=n.delta,m[m.length-1].content=p,ve([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:fe.length+1,role:"assistant",parts:m})]);else if("reasoning-end"===n.type)p="";else if(n.type.startsWith("data-")){const e=n;m.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0}),ve([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:fe.length+1,role:"assistant",parts:m})])}}else if("artifact_created"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(h),Ee.startsWith("inline")||Re({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Te(h),Ee.startsWith("inline")||Re({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(h),Ee.startsWith("inline")||Re({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");h=h.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Te(h)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Te(h.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);je(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(f=!1)}});for(;f&&ze.current;){const{value:e,done:t}=yield ze.current.read();if(t){f=!1;break}const s=u.decode(e);s&&(g||(be("streaming"),g=!0),v.feed(s))}null==de||de(G)}catch(e){if("AbortError"===e.name)return;let t=_(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(ge).find((([e])=>t.includes(e)));s?ye(s[1]):je(t)}finally{Ae(),be("idle"),Ie(),ze.current=null}}));return ft?null:s("div",Object.assign({className:H("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!pt&&"px-4 pb-4"),dir:ie?"rtl":"ltr"},{children:n("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[n("div",Object.assign({className:H("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===ee.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},dt),at&&{backgroundColor:"#EEEEEE"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),lt(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),lt(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),lt(!0)},onDrop:e=>t(void 0,void 0,void 0,(function*(){e.preventDefault(),e.stopPropagation(),lt(!1);const t=Array.from(e.dataTransfer.files||[]);t.length>0&&(le(!1),yield we(t))}))},{children:[Ge&&n("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[s("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(z=te.accent)&&void 0!==z?z:"#ff0000"}}),s("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:te.text+"90"}},{children:"Listening..."}))]})),!he&&xe.length>0&&s(R,{className:"p-4 pb-0",isDisabled:he}),s(L,Object.assign({ref:Me,className:H(ct.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!_e.trim()&&!_e.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap",ie?"text-right":"text-left",gt&&"mb-12",Ge&&"text-transparent"),value:_e,placeholder:null!==(M=null==Z?void 0:Z.placeholdertext)&&void 0!==M?M:ie?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(He(e),$){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void $(0);if(t>=11)return;let s=0;t>1&&(s=50),$(24*(t-1)+s)}},onKeyDown:e=>{ne||Xe||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Oe||he||bt()))},onPaste:e=>t(void 0,void 0,void 0,(function*(){const t=Array.from(e.clipboardData.files||[]);t.length>0&&(e.preventDefault(),le(!1),yield we(t))}))},F&&{onFocus:F},P&&{onBlur:P},{dir:ie?"rtl":"ltr"})),s("div",Object.assign({ref:Ue,className:H("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",gt?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!gt&&dt.backgroundColor&&{backgroundColor:dt.backgroundColor}),{borderTopRightRadius:ee.cornerRadius+"px",borderBottomRightRadius:ee.cornerRadius+"px"})},{children:he?s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{ze.current&&(ze.current.cancel(),ze.current=null),be("idle")},style:{backgroundColor:te.accent,color:te.accentText}},{children:s(T,{className:"h-4 w-4 shrink-0"})})):Ge?s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:u.stopListening,style:{backgroundColor:te.accent,color:te.accentText}},{children:s(T,{className:"h-4 w-4 shrink-0"})})):n(o,{children:[ut&&n("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:st?te.accent+"10":void 0,color:st?te.accent:te.accent+"80"},disabled:Oe||he,onClick:()=>{var e;return null===(e=Be.current)||void 0===e?void 0:e.click()}},nt,{children:[s("input",{id:"file-upload",ref:Be,type:"file",accept:[...S,...N,...C].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){le(!1),yield we(Array.from(e.target.files||[])),e.target.value=""}))}),s(A,{className:"h-6 w-6 shrink-0"})]})),mt&&s("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Ge?te.accent:it?te.accent+"10":void 0,color:Ge?te.accentText:it?te.accent:te.accent+"80"},disabled:Oe||he,onClick:()=>{Ge?u.stopListening():(Ve.current=_e,Ke(),u.startListening({continuous:!0,interimResults:!0,language:se||"en-US"}))}},rt,{children:s(E,{className:"h-5 w-5 shrink-0"})})),s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Ze||vt?te.accent:te.accent+"10",color:Ze||vt?te.accentText:te.accent+"80"},disabled:!vt,onClick:()=>bt()},et,{children:s(D,{className:H("h-6 w-6 shrink-0",ie&&"scale-x-[-1] transform")})}))]})}))]})),ke&&s(W,{error:ke,className:"mt-3"})]}))}))}));F.displayName="Input";export{F as default};
1
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as n,Fragment as o}from"react/jsx-runtime";import{forwardRef as i,useState as r,useRef as a,useMemo as l,useImperativeHandle as c,useEffect as d}from"react";import"../../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js";import u,{useSpeechRecognition as m}from"react-speech-recognition";import{usePickaxeContext as p}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as f}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as g}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as h}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as v}from"../../../hooks/pickaxe/useConversation.js";import{useDimensionContext as b}from"../../../hooks/pickaxe/useDimensionContext.js";import{useAuthContext as y}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as j}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as x}from"../Addons/Document/hooks/useDocument.js";import{useScroll as O}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as k}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as w}from"../../../hooks/core/useHover.js";import{useMediaQuery as S}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as N,allowedImageMimeTypes as C,additionalAllowedFileExtensions as I}from"../../../common/documents.js";import{createParser as A}from"eventsource-parser";import D from"../../Icons/attach-vertical.svg.js";import E from"../../Icons/arrow-right.svg.js";import R from"../../Icons/microphone.svg.js";import T from"../../Icons/stop.svg.js";import L from"../Addons/Document/List.js";import W from"../../Core/Textarea.js";import H from"../../Core/ErrorAlert.js";import _ from"../../../common/error.js";import $ from"../../../common/cn.js";const F=i((({resubmitPrompt:i,onFocus:F,onBlur:P,onInputHeightChange:J,initSmitheryAuthData:z},B)=>{var V,M,U;const{origin:q,pickaxeId:G,sessionId:K,sender:Q,senderType:Y,deploymentId:X,deploymentType:Z,pickaxe:ee,styles:te,colors:se,locale:ne,forceMobile:oe,isNewChat:ie,isRtl:re,isEmailLogin:ae,isShowFeedbackMessage:le,setIsNewChat:ce,setIsShowIceBreaker:de,onGenerateComplete:ue}=p(),{token:me,isLoggedOut:pe,isSent:fe}=y(),{messages:ge,limits:he,isGenerating:ve,setMessages:be,setStatus:ye,setLimitData:je,setError:xe}=f(),{documents:Oe,isUploading:ke,documentError:we,onFileUpload:Se,setDocuments:Ne,setDocumentError:Ce}=x(),{scrollStartSession:Ie,scrollEndSession:Ae,scrollToBottom:De}=O({auto:!0}),{artifacts:Ee,currentPopupType:Re,setArtifacts:Te,setCurrentArtifact:Le}=k(),{height:We}=b(),He=v(),_e=j(),[$e,Fe]=r(""),[Pe,Je]=r(!1),[ze,Be]=r(!1),Ve=a(null),Me=a(""),Ue=a(null),qe=a(null),Ge=a(null),Ke=a(null),Qe=Math.max(.2*We,100),{transcript:Ye,listening:Xe,resetTranscript:Ze,browserSupportsSpeechRecognition:et}=m(),[tt]=S("(max-width: 480px)"),st=w(),{isHover:nt}=st,ot=e(st,["isHover"]),it=w(),{isHover:rt}=it,at=e(it,["isHover"]),lt=w(),{isHover:ct}=lt,dt=e(lt,["isHover"]),[ut,mt]=r(!1),pt=h(),ft=g(),gt=null===(V=null==ee?void 0:ee.documentuploadtype)||void 0===V?void 0:V.startsWith("enduserupload"),ht=et&&(null==ee?void 0:ee.enablevoicetotext),vt="chat-input"===Z&&ie&&!fe,bt="chat-input"===Z&&ae&&pe&&fe,yt=Pe||ze,jt=l((()=>{var e,t,s;return!!ie&&(!!ee&&(!He.isLoading&&(!((null!==(t=null===(e=He.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=ee.icebreakers)||void 0===s?void 0:s.length)&&(!le&&!vt)))))}),[ee,ie,le,vt,He.data,He.isLoading]),xt=l((()=>{if(ve||ke)return!1;const e=Oe.length>0&&Oe.every((e=>"finished"===e.status));return!(!$e.trim()&&!e)&&Oe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[ve,ke,$e,Oe]);c(B,(()=>({onSubmit:Ot}))),d((()=>{de(jt)}),[jt]),d((()=>{var e;if(i){const t=Array.from(ge),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Ot(s,!0)}}),[i]),d((()=>{if(!Ke.current||!J)return;const e=new ResizeObserver((e=>{for(const t of e)J(t.contentRect.height)}));return e.observe(Ke.current),()=>{e.disconnect()}}),[J]),d((()=>{if(!Xe)return;const e=Me.current?`${Me.current} `:"";Fe(`${e}${Ye}`)}),[Ye,Xe]),d((()=>{if(!qe.current)return;(()=>{if(!qe.current)return;let e=qe.current.scrollHeight>52;$e.includes("\n")||Oe.length?e=!0:$e.trim()||(e=!1),Je(e)})()}),[$e,Oe]),d((()=>{const e=qe.current,t=Ge.current;if(!e||!t||Pe||$e.includes("\n"))return void Be(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=$e,document.body.appendChild(o);const i=o.offsetWidth;o.remove();const r=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;Be(i>l)}),[$e,Pe]);const Ot=(e,s=!1)=>t(void 0,void 0,void 0,(function*(){var t,n;try{if(ve||ke)return;const o=Oe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),i=o.length>0,r=null!=e?e:$e;if(!r&&!i)return;xe(""),Ce(""),je(null),Fe(""),ce(!1),ye("fetching"),Ie(),De();const a=null!==(n=null===(t=null==ee?void 0:ee.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==n&&n&&o.length>0,l=[...s?Array.from(ge.slice(0,ge.length-1)):Array.from(ge),...s?[]:[{id:ge.length+1,role:"user",parts:[{type:"text",content:r,isVisible:!0}],documentIds:a?o:[]}],{id:ge.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];be(l),De(),a&&Ne([]);const c=(yield _e.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({origin:q,pickaxeId:G,sessionId:K,senderType:Y,value:r},a&&{documentIds:o}),Q&&{sender:Q}),me&&{studioSessionToken:me}),X&&{deploymentId:X}))).body;if(!c)throw new Error("Streaming error");const d=l.length-1,u=new TextDecoder;Ue.current=c.getReader();const m=[];let p="",f=!0,g=!1,h=[...null!=Ee?Ee:[]];const v=A({onEvent:e=>{var t,s;if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&z){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);t&&t[1]&&s&&s[1]&&n&&n[1]&&(f=!1,z({smitheryId:t[1],serverId:s[1],name:n[1]}))}}else if("object"==typeof e&&null!==e){const t=e;"unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name&&(f=!1,z({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}))}}else if("text-start"===n.type)p="",m.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t}),be([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:ge.length+1,role:"assistant",parts:m})]);else if("text-delta"===n.type)p+=n.delta,m[m.length-1].content=p,be([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:ge.length+1,role:"assistant",parts:m})]);else if("text-end"===n.type)p="";else if("reasoning-start"===n.type)p="",m.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s}),be([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:ge.length+1,role:"assistant",parts:m})]);else if("reasoning-delta"===n.type)p+=n.delta,m[m.length-1].content=p,be([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:ge.length+1,role:"assistant",parts:m})]);else if("reasoning-end"===n.type)p="";else if(n.type.startsWith("data-")){const e=n;m.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0}),be([...l.slice(0,d),Object.assign(Object.assign({},l[l.length-1]),{id:ge.length+1,role:"assistant",parts:m})])}}else if("artifact_created"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(h),Re.startsWith("inline")||Le({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Te(h),Re.startsWith("inline")||Le({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);h=h.filter((e=>!(e.id===t.id&&e.version===t.version))),h.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(h),Re.startsWith("inline")||Le({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");h=h.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Te(h)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Te(h.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);xe(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(f=!1)}});for(;f&&Ue.current;){const{value:e,done:t}=yield Ue.current.read();if(t){f=!1;break}const s=u.decode(e);s&&(g||(ye("streaming"),g=!0),v.feed(s))}null==ue||ue(K)}catch(e){if("AbortError"===e.name)return;let t=_(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(he).find((([e])=>t.includes(e)));s?je(s[1]):xe(t)}finally{De(),ye("idle"),Ae(),Ue.current=null}}));return bt?null:s("div",Object.assign({className:$("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!vt&&"px-4 pb-8"),dir:re?"rtl":"ltr"},{children:n("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[n("div",Object.assign({ref:Ke,className:$("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===te.formFieldStyle&&"shadow"),style:Object.assign(Object.assign(Object.assign({},ft),ut&&{backgroundColor:"#EEEEEE"}),{maxHeight:`${Qe}px`,overflowY:"auto"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),mt(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),mt(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),mt(!0)},onDrop:e=>t(void 0,void 0,void 0,(function*(){e.preventDefault(),e.stopPropagation(),mt(!1);const t=Array.from(e.dataTransfer.files||[]);t.length>0&&(ce(!1),yield Se(t))}))},{children:[Xe&&n("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[s("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(M=se.accent)&&void 0!==M?M:"#ff0000"}}),s("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:se.text+"90"}},{children:"Listening..."}))]})),!ve&&Oe.length>0&&s(L,{className:"p-4 pb-0",isDisabled:ve}),s(W,Object.assign({ref:qe,className:$(pt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!$e.trim()&&!$e.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",re?"text-right":"text-left",yt&&"mb-12",Xe&&"text-transparent"),value:$e,placeholder:null!==(U=null==ee?void 0:ee.placeholdertext)&&void 0!==U?U:re?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Fe(e),J){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void J(0);if(t>=11)return;let s=0;t>1&&(s=50),J(24*(t-1)+s)}},onKeyDown:e=>{oe||tt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ke||ve||Ot()))},onPaste:e=>t(void 0,void 0,void 0,(function*(){const t=Array.from(e.clipboardData.files||[]);t.length>0&&(e.preventDefault(),ce(!1),yield Se(t))}))},F&&{onFocus:F},P&&{onBlur:P},{dir:re?"rtl":"ltr"})),s("div",Object.assign({ref:Ge,className:$("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",yt?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!yt&&ft.backgroundColor&&{backgroundColor:ft.backgroundColor}),{borderTopRightRadius:te.cornerRadius+"px",borderBottomRightRadius:te.cornerRadius+"px"})},{children:ve?s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{Ue.current&&(Ue.current.cancel(),Ue.current=null),ye("idle")},style:{backgroundColor:se.accent,color:se.accentText}},{children:s(T,{className:"h-4 w-4 shrink-0"})})):Xe?s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:u.stopListening,style:{backgroundColor:se.accent,color:se.accentText}},{children:s(T,{className:"h-4 w-4 shrink-0"})})):n(o,{children:[gt&&n("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:rt?se.accent+"10":void 0,color:rt?se.accent:se.accent+"80"},disabled:ke||ve,onClick:()=>{var e;return null===(e=Ve.current)||void 0===e?void 0:e.click()}},at,{children:[s("input",{id:"file-upload",ref:Ve,type:"file",accept:[...N,...C,...I].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){ce(!1),yield Se(Array.from(e.target.files||[])),e.target.value=""}))}),s(D,{className:"h-6 w-6 shrink-0"})]})),ht&&s("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Xe?se.accent:ct?se.accent+"10":void 0,color:Xe?se.accentText:ct?se.accent:se.accent+"80"},disabled:ke||ve,onClick:()=>{Xe?u.stopListening():(Me.current=$e,Ze(),u.startListening({continuous:!0,interimResults:!0,language:ne||"en-US"}))}},dt,{children:s(R,{className:"h-5 w-5 shrink-0"})})),s("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:nt||xt?se.accent:se.accent+"10",color:nt||xt?se.accentText:se.accent+"80"},disabled:!xt,onClick:()=>Ot()},ot,{children:s(E,{className:$("h-6 w-6 shrink-0",re&&"scale-x-[-1] transform")})}))]})}))]})),we&&s(H,{error:we,className:"mt-3"})]}))}))}));F.displayName="Input";export{F as default};
@@ -1 +1 @@
1
- import{jsxs as o,jsx as i}from"react/jsx-runtime";import{useMemo as t}from"react";import{usePickaxeContext as e}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as s}from"../Addons/Auth/hooks/useAuthContext.js";import{useStyleFontSize as r}from"../../../hooks/studio/useStyleFontSize.js";import n from"./PickaxeIcon.js";import l from"./PickaxeHistoryButton.js";import c from"./PickaxeLogoutButton.js";import a from"../../../common/cn.js";const m=({className:m,iconClassName:p,historyBtnTip:u,showHistory:d,onIconClick:f,onHistoryClick:h})=>{const{deploymentType:x,pickaxe:g,misc:k,colors:j,translations:y}=e(),{isLoggedIn:b}=s(),v=r(),C=t((()=>({title:(null==g?void 0:g.formtitle)||"",description:(null==g?void 0:g.formdescription)||""})),[g]);return k.isTitle||k.isDescription||!k.isWhiteLabel?o("div",Object.assign({className:a("flex min-h-[56px] items-center justify-between gap-4 px-4",m),style:{backgroundColor:j.secondary,color:j.secondaryText}},{children:[o("div",Object.assign({className:"flex items-center gap-4"},{children:[k.isProfileImage&&i(n,Object.assign({src:null==g?void 0:g.coverphoto,alt:`${null==g?void 0:g.formtitle}'s Profile Picture`,width:32,height:32,className:a("h-[32px] w-[32px] shrink-0 rounded-full",p,!!f&&"cursor-pointer")},f&&{onClick:f})),k.isTitle&&i("p",Object.assign({className:a(v.b1)},{children:C.title}))]})),!!h&&o("div",Object.assign({className:a("popup"===x&&"pr-12","flex")},{children:[i(l,{tip:u,onClick:h}),b&&d&&i(c,{tip:(null==y?void 0:y["log-out"])||"Log Out"})]}))]})):null};export{m as default};
1
+ import{jsxs as o,jsx as i}from"react/jsx-runtime";import{useMemo as t}from"react";import{usePickaxeContext as e}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as s}from"../Addons/Auth/hooks/useAuthContext.js";import{useStyleFontSize as r}from"../../../hooks/studio/useStyleFontSize.js";import n from"./PickaxeIcon.js";import l from"./PickaxeHistoryButton.js";import c from"./PickaxeLogoutButton.js";import a from"../../../common/cn.js";const m=({className:m,iconClassName:p,historyBtnTip:u,onIconClick:d,onHistoryClick:f})=>{const{deploymentType:h,pickaxe:x,misc:g,colors:k,translations:j}=e(),{isLoggedIn:y}=s(),b=r(),v=t((()=>({title:(null==x?void 0:x.formtitle)||"",description:(null==x?void 0:x.formdescription)||""})),[x]);return g.isTitle||g.isDescription||!g.isWhiteLabel?o("div",Object.assign({className:a("flex min-h-[56px] items-center justify-between gap-4 px-4",m),style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[o("div",Object.assign({className:"flex items-center gap-4"},{children:[g.isProfileImage&&i(n,Object.assign({src:null==x?void 0:x.coverphoto,alt:`${null==x?void 0:x.formtitle}'s Profile Picture`,width:32,height:32,className:a("h-[32px] w-[32px] shrink-0 rounded-full",p,!!d&&"cursor-pointer")},d&&{onClick:d})),g.isTitle&&i("p",Object.assign({className:a(b.b1)},{children:v.title}))]})),!!f&&o("div",Object.assign({className:a("popup"===h&&"pr-12","flex")},{children:[i(l,{tip:u,onClick:f}),y&&i(c,{tip:(null==j?void 0:j["log-out"])||"Log Out"})]}))]})):null};export{m as default};
@@ -2,9 +2,8 @@ interface PickaxeEmbedHeadProps {
2
2
  className?: string;
3
3
  iconClassName?: string;
4
4
  historyBtnTip?: string;
5
- showHistory?: boolean;
6
5
  onIconClick?: () => void;
7
6
  onHistoryClick?: () => void;
8
7
  }
9
- declare const PickaxeEmbedHead: ({ className, iconClassName, historyBtnTip, showHistory, onIconClick, onHistoryClick, }: PickaxeEmbedHeadProps) => import("react/jsx-runtime").JSX.Element | null;
8
+ declare const PickaxeEmbedHead: ({ className, iconClassName, historyBtnTip, onIconClick, onHistoryClick, }: PickaxeEmbedHeadProps) => import("react/jsx-runtime").JSX.Element | null;
10
9
  export default PickaxeEmbedHead;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "4.5.2",
3
+ "version": "4.5.4",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",