@pickaxeproject/react 3.20.4 → 3.21.0

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("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../Addons/Auth/hooks/useAuthContext.js"),c=require("../../../hooks/pickaxe/useSubmit.js"),u=require("../Addons/Document/hooks/useDocument.js"),d=require("../Addons/Scroll/hooks/useScroll.js"),f=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/pickaxe/useSpeechRecognition.js"),h=require("../../../hooks/core/useHover.js"),g=require("../../../hooks/core/useMediaQuery.js"),v=require("../../../common/documents.js"),p=require("eventsource-parser"),x=require("../../Icons/attach-vertical.svg.js"),j=require("../../Icons/arrow-right.svg.js"),b=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),k=require("../Addons/Document/List.js"),w=require("../../Core/Textarea.js"),O=require("../../Core/ErrorAlert.js"),I=require("../../../common/error.js"),S=require("../../../common/cn.js");const N=({colors:e})=>{var s;return t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(s=e.accent)&&void 0!==s?s:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm",style:{color:e.text+"90"}},{children:"Listening..."}))]}))},C=s.forwardRef((({onFocus:C,onBlur:q,onInputHeightChange:A},_)=>{var E,H,T;const{formId:M,chatId:D,userId:L,studioUserId:R,embedUserId:F,deploymentId:W,deploymentType:U,pickaxe:B,styles:J,colors:P,studioLang:$,forceMobile:G,isNewChat:z,isRtl:K,isEmailLogin:Q,isShowFeedbackMessage:V,setIsNewChat:X,setIsShowIceBreaker:Y,onGenerateComplete:Z}=n.usePickaxeContext(),{token:ee,isLoggedOut:te,isSent:se}=l.useAuthContext(),{messages:ne,status:ie,limits:re,isGenerating:oe,setMessages:ae,setStatus:le,setLimitData:ce,setError:ue}=i.useResponseContext(),{documents:de,isUploading:fe,isImageUploadAllowed:me,documentError:he,onFileUpload:ge,setDocuments:ve,setDocumentError:pe}=u.useDocument(),{scrollStartSession:xe,scrollEndSession:je,scrollToBottom:be}=d.useScroll({auto:!0}),{artifacts:ye,currentPopupType:ke,setArtifacts:we,setCurrentArtifact:Oe}=f.useArtifactContext(),Ie=a.useConversation(),Se=c.useSubmit(),[Ne,Ce]=s.useState(""),qe=s.useRef(null),Ae=s.useRef(""),{isSupported:_e,isListening:Ee,finalTranscript:He,interimTranscript:Te,startListening:Me,stopListening:De}=m.useSpeechRecognition({lang:$||"en"}),[Le]=g.useMediaQuery("(max-width: 899px)"),Re=h.useHover(),{isHover:Fe}=Re,We=e.__rest(Re,["isHover"]),Ue=h.useHover(),{isHover:Be}=Ue,Je=e.__rest(Ue,["isHover"]),Pe=h.useHover(),{isHover:$e}=Pe,Ge=e.__rest(Pe,["isHover"]),ze=h.useHover(),{isHover:Ke}=ze,Qe=e.__rest(ze,["isHover"]),Ve=o.useStyleFontSize(),Xe=r.useStyleInput(),Ye="chat-input"===U&&z&&!se,Ze="chat-input"===U&&Q&&te&&se,et=s.useMemo((()=>{var e,t,s;return!!z&&(!!B&&(!Ie.isLoading&&(!((null!==(t=null===(e=Ie.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)&&(!V&&!Ye)))))}),[B,z,V,Ye,Ie.data,Ie.isLoading]),tt=s.useMemo((()=>{if(oe||fe)return!1;const e=de.length>0&&de.every((e=>{var t;return"finished"===e.status&&(null===(t=e.documentId)||void 0===t?void 0:t.startsWith("IMAGE-"))}));return!(!Ne.trim()&&!e)&&de.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[oe,fe,Ne,de]);s.useEffect((()=>{Y(et)}),[et]),s.useEffect((()=>{if(!Ee)return;const e=`${Ae.current} ${He} ${Te}`.trim();Ce(e)}),[He,Te,Ee]),s.useEffect((()=>{!Ee&&Ae.current&&(Ce(`${Ae.current} ${He}`.trim()),Ae.current="")}),[Ee,He]);const st=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;try{if("idle"!==ie||fe||Ee)return;const n=de.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),i=n.length>0&&n.every((e=>e.startsWith("IMAGE-"))),r=null!=t?t:Ne;if(!r&&!i)return;ue(""),pe(""),ce(null),Ce(""),X(!1),le("fetching"),xe(),be();const o=null!==(s=null===(e=null==B?void 0:B.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==s&&s&&n.length>0,a=[...Array.from(ne),Object.assign({id:ne.length+1,role:"user",content:r},o&&{documentIds:n})];ae(a),be(),o&&ve([]);const l=(yield Se.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:M,responseId:D,value:r},o&&{documentIds:n}),L&&{userId:L}),R&&{studioUserId:R}),F&&{embedUserId:F}),ee&&{studioSessionToken:ee}),W&&{deploymentId:W}))).body;if(!l)throw new Error("Streaming error");const c=a.length,u=new TextDecoder,d=l.getReader();let f="",m=!0,h=!1,g=[...null!=ye?ye:[]];const v=p.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");f+=t,ae([...a.slice(0,c),{id:ne.length+1,role:"assistant",content:f}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);g=g.filter((e=>!(e.id===t.id&&e.version===t.version))),g.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(g),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);g=g.filter((e=>!(e.id===t.id&&e.version===t.version))),g.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),we(g),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);g=g.filter((e=>!(e.id===t.id&&e.version===t.version))),g.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(g),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");g=g.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),we(g)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);we(g.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);ue(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(m=!1)}});for(;m;){const{value:e,done:t}=yield d.read();if(t){m=!1;break}const s=u.decode(e);s&&(h||(le("streaming"),h=!0),v.feed(s))}null==Z||Z(D)}catch(e){let t=I.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(re).find((([e])=>t.includes(e)));s?ce(s[1]):ue(t)}finally{be(),le("idle"),je()}}));return s.useImperativeHandle(_,(()=>({onSubmit:st}))),Ze?null:t.jsx("div",Object.assign({className:S.default("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!Ye&&"px-4 pb-4"),dir:K?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[t.jsxs("div",Object.assign({className:S.default("flex flex-col gap-y-3 px-4 py-3","block"===J.formFieldStyle&&"shadow"),style:Xe},{children:[Ee&&t.jsx(N,{colors:P}),"idle"===ie&&de.length>0&&t.jsx(k.default,{isDisabled:"idle"!==ie}),t.jsxs("div",Object.assign({className:S.default("flex items-end gap-x-2",K&&"flex-row-reverse")},{children:[t.jsx(w.default,Object.assign({className:S.default(Ve.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!Ne.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",K?"text-right":"text-left",Ee&&"text-transparent"),value:Ne,placeholder:null!==(E=null==B?void 0:B.placeholdertext)&&void 0!==E?E:K?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Ce(e),A){const t=(e.match(/\n/g)||[]).length+1;if(t>=11)return;A(24*(t-1))}},onKeyDown:e=>{G||Le||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),fe||"idle"!==ie||st()))}},C&&{onFocus:C},q&&{onBlur:q},{dir:K?"rtl":"ltr"})),t.jsx("div",Object.assign({className:"flex items-center gap-x-2"},{children:Ee?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:De,style:{backgroundColor:Ke?P.accent:P.accent+"10",color:Ke?P.accentText:P.accent}},Qe,{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[null!==(T=null===(H=null==B?void 0:B.documentuploadtype)||void 0===H?void 0:H.startsWith("enduserupload"))&&void 0!==T&&T&&t.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Be?P.accent+"10":void 0,color:Be?P.accent:P.accent+"80"},disabled:fe||"idle"!==ie,onClick:()=>{var e;return null===(e=qe.current)||void 0===e?void 0:e.click()}},Je,{children:[t.jsx("input",{id:"file-upload",ref:qe,type:"file",accept:[...v.allowedFileMimeTypes,...me?v.allowedImageMimeTypes:[],...v.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){X(!1),yield ge(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(x.default,{className:"h-6 w-6 shrink-0"})]})),_e&&(null==B?void 0:B.enablevoicetotext)&&t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center \n justify-center rounded-full\n outline-none transition-colors \n duration-200 ease-in-out\n disabled:cursor-default",style:{backgroundColor:Ee?P.accent:$e?P.accent+"10":void 0,color:Ee?P.accentText:$e?P.accent:P.accent+"80"},disabled:fe||"idle"!==ie,onClick:()=>{Ee?De():(Ae.current=Ne,Me())}},Ge,{children:t.jsx(b.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:Fe||tt?P.accent:P.accent+"10",color:Fe||tt?P.accentText:P.accent+"80"},disabled:"idle"!==ie||fe,onClick:()=>st()},We,{children:t.jsx(j.default,{className:S.default("h-6 w-6 shrink-0",K&&"transform scale-x-[-1]")})}))]})}))]}))]})),he&&t.jsx(O.default,{error:he,className:"mt-3"})]}))}))}));C.displayName="Input",exports.default=C;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../Addons/Auth/hooks/useAuthContext.js"),c=require("../../../hooks/pickaxe/useSubmit.js"),u=require("../Addons/Document/hooks/useDocument.js"),d=require("../Addons/Scroll/hooks/useScroll.js"),f=require("../Addons/Artifact/hooks/useArtifactContext.js"),g=require("../../../hooks/pickaxe/useSpeechRecognition.js"),p=require("../../../hooks/core/useHover.js"),v=require("../../../hooks/core/useMediaQuery.js"),m=require("../../../common/documents.js"),h=require("eventsource-parser"),x=require("../../Icons/attach-vertical.svg.js"),j=require("../../Icons/arrow-right.svg.js"),b=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),k=require("../Addons/Document/List.js"),w=require("../../Core/Textarea.js"),O=require("../../Core/ErrorAlert.js"),S=require("../../../common/error.js"),I=require("../../../common/cn.js");const C=({colors:e})=>{var s,r;const{translations:i}=n.usePickaxeContext();return t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(s=e.accent)&&void 0!==s?s:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm",style:{color:e.text+"90"}},{children:null!==(r=null==i?void 0:i.listening)&&void 0!==r?r:"Listening..."}))]}))},N=s.forwardRef((({onFocus:N,onBlur:q,onInputHeightChange:A},_)=>{var E,D,H;const{formId:T,chatId:L,userId:M,studioUserId:P,embedUserId:R,deploymentId:F,deploymentType:W,pickaxe:U,styles:B,colors:J,studioLang:$,forceMobile:G,isNewChat:z,isRtl:K,isEmailLogin:Q,isShowFeedbackMessage:V,setIsNewChat:X,setIsShowIceBreaker:Y,onGenerateComplete:Z}=n.usePickaxeContext(),{token:ee,isLoggedOut:te,isSent:se}=l.useAuthContext(),{messages:ne,status:re,limits:ie,isGenerating:oe,setMessages:ae,setStatus:le,setLimitData:ce,setError:ue}=r.useResponseContext(),{documents:de,isUploading:fe,isImageUploadAllowed:ge,documentError:pe,onFileUpload:ve,setDocuments:me,setDocumentError:he}=u.useDocument(),{scrollStartSession:xe,scrollEndSession:je,scrollToBottom:be}=d.useScroll({auto:!0}),{artifacts:ye,currentPopupType:ke,setArtifacts:we,setCurrentArtifact:Oe}=f.useArtifactContext(),Se=a.useConversation(),Ie=c.useSubmit(),[Ce,Ne]=s.useState(""),qe=s.useRef(null),Ae=s.useRef(""),_e=s.useRef(null),{isSupported:Ee,isListening:De,finalTranscript:He,interimTranscript:Te,startListening:Le,stopListening:Me}=g.useSpeechRecognition({lang:$||"en"}),[Pe]=v.useMediaQuery("(max-width: 899px)"),Re=p.useHover(),{isHover:Fe}=Re,We=e.__rest(Re,["isHover"]),Ue=p.useHover(),{isHover:Be}=Ue,Je=e.__rest(Ue,["isHover"]),$e=p.useHover(),{isHover:Ge}=$e,ze=e.__rest($e,["isHover"]),Ke=p.useHover(),{isHover:Qe}=Ke,Ve=e.__rest(Ke,["isHover"]),[Xe,Ye]=s.useState(!1),Ze=o.useStyleFontSize(),et=i.useStyleInput(),tt="chat-input"===W&&z&&!se,st="chat-input"===W&&Q&&te&&se,nt=s.useMemo((()=>{var e,t,s;return!!z&&(!!U&&(!Se.isLoading&&(!((null!==(t=null===(e=Se.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=U.icebreakers)||void 0===s?void 0:s.length)&&(!V&&!tt)))))}),[U,z,V,tt,Se.data,Se.isLoading]),rt=s.useMemo((()=>{if(oe||fe)return!1;const e=de.length>0&&de.every((e=>{var t;return"finished"===e.status&&(null===(t=e.documentId)||void 0===t?void 0:t.startsWith("IMAGE-"))}));return!(!Ce.trim()&&!e)&&de.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[oe,fe,Ce,de]);s.useEffect((()=>{Y(nt)}),[nt]),s.useEffect((()=>{if(!De)return;const e=`${Ae.current} ${He} ${Te}`.trim();Ne(e)}),[He,Te,De]),s.useEffect((()=>{!De&&Ae.current&&(Ne(`${Ae.current} ${He}`.trim()),Ae.current="")}),[De,He]);const it=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;try{if("idle"!==re||fe)return;const n=de.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),r=n.length>0&&n.every((e=>e.startsWith("IMAGE-"))),i=null!=t?t:Ce;if(!i&&!r)return;ue(""),he(""),ce(null),Ne(""),X(!1),le("fetching"),xe(),be();const o=null!==(s=null===(e=null==U?void 0:U.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==s&&s&&n.length>0,a=[...Array.from(ne),Object.assign({id:ne.length+1,role:"user",content:i},o&&{documentIds:n})];ae(a),be(),o&&me([]);const l=(yield Ie.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:T,responseId:L,value:i},o&&{documentIds:n}),M&&{userId:M}),P&&{studioUserId:P}),R&&{embedUserId:R}),ee&&{studioSessionToken:ee}),F&&{deploymentId:F}))).body;if(!l)throw new Error("Streaming error");const c=a.length,u=new TextDecoder;_e.current=l.getReader();let d="",f=!0,g=!1,p=[...null!=ye?ye:[]];const v=h.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=t,ae([...a.slice(0,c),{id:ne.length+1,role:"assistant",content:d}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(p),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),we(p),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),we(p),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");p=p.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),we(p)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);we(p.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);ue(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(f=!1)}});for(;f&&_e.current;){const{value:e,done:t}=yield _e.current.read();if(t){f=!1;break}const s=u.decode(e);s&&(g||(le("streaming"),g=!0),v.feed(s))}null==Z||Z(L)}catch(e){if("AbortError"===e.name)return void console.log("Stream stopped by user.");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(ie).find((([e])=>t.includes(e)));s?ce(s[1]):ue(t)}finally{be(),le("idle"),je(),_e.current=null}}));return s.useImperativeHandle(_,(()=>({onSubmit:it}))),st?null:t.jsx("div",Object.assign({className:I.default("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!tt&&"px-4 pb-4"),dir:K?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"relative flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({className:I.default("flex flex-col gap-y-3 px-4 py-3","block"===B.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},et),Xe&&{backgroundColor:"#EEEEEE"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),Ye(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),Ye(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),Ye(!0)},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),Ye(!1);const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(X(!1),yield ve(e))}))},{children:[De&&t.jsx(C,{colors:J}),"idle"===re&&de.length>0&&t.jsx(k.default,{isDisabled:"idle"!==re}),t.jsxs("div",Object.assign({className:I.default("flex items-end gap-x-2",K&&"flex-row-reverse")},{children:[t.jsx(w.default,Object.assign({className:I.default(Ze.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!Ce.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",K?"text-right":"text-left",De&&"text-transparent"),value:Ce,placeholder:null!==(E=null==U?void 0:U.placeholdertext)&&void 0!==E?E:K?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Ne(e),A){const t=(e.match(/\n/g)||[]).length+1;if(t>=11)return;A(24*(t-1))}},onKeyDown:e=>{G||Pe||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),fe||"idle"!==re||it()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),X(!1),yield ve(e))}))},N&&{onFocus:N},q&&{onBlur:q},{dir:K?"rtl":"ltr"})),t.jsx("div",Object.assign({className:"flex items-center gap-x-2"},{children:oe?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{_e.current&&(_e.current.cancel(),_e.current=null),le("idle")},style:{backgroundColor:Qe?J.accent:J.accent+"10",color:Qe?J.accentText:J.accent}},Ve,{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):De?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Me,style:{backgroundColor:Qe?J.accent:J.accent+"10",color:Qe?J.accentText:J.accent}},Ve,{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[null!==(H=null===(D=null==U?void 0:U.documentuploadtype)||void 0===D?void 0:D.startsWith("enduserupload"))&&void 0!==H&&H&&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:Be?J.accent+"10":void 0,color:Be?J.accent:J.accent+"80"},disabled:fe||"idle"!==re,onClick:()=>{var e;return null===(e=qe.current)||void 0===e?void 0:e.click()}},Je,{children:[t.jsx("input",{id:"file-upload",ref:qe,type:"file",accept:[...m.allowedFileMimeTypes,...ge?m.allowedImageMimeTypes:[],...m.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){X(!1),yield ve(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(x.default,{className:"h-6 w-6 shrink-0"})]})),Ee&&(null==U?void 0:U.enablevoicetotext)&&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:De?J.accent:Ge?J.accent+"10":void 0,color:De?J.accentText:Ge?J.accent:J.accent+"80"},disabled:fe||"idle"!==re,onClick:()=>{De?Me():(Ae.current=Ce,Le())}},ze,{children:t.jsx(b.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("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:Fe||rt?J.accent:J.accent+"10",color:Fe||rt?J.accentText:J.accent+"80"},disabled:!rt,onClick:()=>it()},We,{children:t.jsx(j.default,{className:I.default("h-6 w-6 shrink-0",K&&"scale-x-[-1] transform")})}))]})}))]}))]})),pe&&t.jsx(O.default,{error:pe,className:"mt-3"})]}))}))}));N.displayName="Input",exports.default=N;
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as o,Fragment as n}from"react/jsx-runtime";import{forwardRef as i,useState as r,useRef as a,useMemo as l,useEffect as c,useImperativeHandle as d}from"react";import{usePickaxeContext as u}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as m}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as f}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as p}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as h}from"../../../hooks/pickaxe/useConversation.js";import{useAuthContext as g}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as v}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as b}from"../Addons/Document/hooks/useDocument.js";import{useScroll as j}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as x}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useSpeechRecognition as k}from"../../../hooks/pickaxe/useSpeechRecognition.js";import{useHover as y}from"../../../hooks/core/useHover.js";import{useMediaQuery as O}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as w,allowedImageMimeTypes as I,additionalAllowedFileExtensions as N}from"../../../common/documents.js";import{createParser as S}from"eventsource-parser";import C from"../../Icons/attach-vertical.svg.js";import A from"../../Icons/arrow-right.svg.js";import E from"../../Icons/microphone.svg.js";import L from"../../Icons/stop.svg.js";import T from"../Addons/Document/List.js";import D from"../../Core/Textarea.js";import H from"../../Core/ErrorAlert.js";import W from"../../../common/error.js";import U from"../../../common/cn.js";const B=({colors:e})=>{var t;return o("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 items-center gap-x-2"},{children:[s("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(t=e.accent)&&void 0!==t?t:"#ff0000"}}),s("span",Object.assign({className:"text-sm",style:{color:e.text+"90"}},{children:"Listening..."}))]}))},J=i((({onFocus:i,onBlur:J,onInputHeightChange:_},F)=>{var M,R,$;const{formId:G,chatId:P,userId:z,studioUserId:K,embedUserId:Q,deploymentId:q,deploymentType:V,pickaxe:X,styles:Y,colors:Z,studioLang:ee,forceMobile:te,isNewChat:se,isRtl:oe,isEmailLogin:ne,isShowFeedbackMessage:ie,setIsNewChat:re,setIsShowIceBreaker:ae,onGenerateComplete:le}=u(),{token:ce,isLoggedOut:de,isSent:ue}=g(),{messages:me,status:fe,limits:pe,isGenerating:he,setMessages:ge,setStatus:ve,setLimitData:be,setError:je}=m(),{documents:xe,isUploading:ke,isImageUploadAllowed:ye,documentError:Oe,onFileUpload:we,setDocuments:Ie,setDocumentError:Ne}=b(),{scrollStartSession:Se,scrollEndSession:Ce,scrollToBottom:Ae}=j({auto:!0}),{artifacts:Ee,currentPopupType:Le,setArtifacts:Te,setCurrentArtifact:De}=x(),He=h(),We=v(),[Ue,Be]=r(""),Je=a(null),_e=a(""),{isSupported:Fe,isListening:Me,finalTranscript:Re,interimTranscript:$e,startListening:Ge,stopListening:Pe}=k({lang:ee||"en"}),[ze]=O("(max-width: 899px)"),Ke=y(),{isHover:Qe}=Ke,qe=e(Ke,["isHover"]),Ve=y(),{isHover:Xe}=Ve,Ye=e(Ve,["isHover"]),Ze=y(),{isHover:et}=Ze,tt=e(Ze,["isHover"]),st=y(),{isHover:ot}=st,nt=e(st,["isHover"]),it=p(),rt=f(),at="chat-input"===V&&se&&!ue,lt="chat-input"===V&&ne&&de&&ue,ct=l((()=>{var e,t,s;return!!se&&(!!X&&(!He.isLoading&&(!((null!==(t=null===(e=He.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=X.icebreakers)||void 0===s?void 0:s.length)&&(!ie&&!at)))))}),[X,se,ie,at,He.data,He.isLoading]),dt=l((()=>{if(he||ke)return!1;const e=xe.length>0&&xe.every((e=>{var t;return"finished"===e.status&&(null===(t=e.documentId)||void 0===t?void 0:t.startsWith("IMAGE-"))}));return!(!Ue.trim()&&!e)&&xe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[he,ke,Ue,xe]);c((()=>{ae(ct)}),[ct]),c((()=>{if(!Me)return;const e=`${_e.current} ${Re} ${$e}`.trim();Be(e)}),[Re,$e,Me]),c((()=>{!Me&&_e.current&&(Be(`${_e.current} ${Re}`.trim()),_e.current="")}),[Me,Re]);const ut=e=>t(void 0,void 0,void 0,(function*(){var t,s;try{if("idle"!==fe||ke||Me)return;const o=xe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),n=o.length>0&&o.every((e=>e.startsWith("IMAGE-"))),i=null!=e?e:Ue;if(!i&&!n)return;je(""),Ne(""),be(null),Be(""),re(!1),ve("fetching"),Se(),Ae();const r=null!==(s=null===(t=null==X?void 0:X.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&o.length>0,a=[...Array.from(me),Object.assign({id:me.length+1,role:"user",content:i},r&&{documentIds:o})];ge(a),Ae(),r&&Ie([]);const l=(yield We.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:G,responseId:P,value:i},r&&{documentIds:o}),z&&{userId:z}),K&&{studioUserId:K}),Q&&{embedUserId:Q}),ce&&{studioSessionToken:ce}),q&&{deploymentId:q}))).body;if(!l)throw new Error("Streaming error");const c=a.length,d=new TextDecoder,u=l.getReader();let m="",f=!0,p=!1,h=[...null!=Ee?Ee:[]];const g=S({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");m+=t,ge([...a.slice(0,c),{id:me.length+1,role:"assistant",content: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),Le.startsWith("inline")||De({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),Le.startsWith("inline")||De({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),Le.startsWith("inline")||De({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;){const{value:e,done:t}=yield u.read();if(t){f=!1;break}const s=d.decode(e);s&&(p||(ve("streaming"),p=!0),g.feed(s))}null==le||le(P)}catch(e){let t=W(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(pe).find((([e])=>t.includes(e)));s?be(s[1]):je(t)}finally{Ae(),ve("idle"),Ce()}}));return d(F,(()=>({onSubmit:ut}))),lt?null:s("div",Object.assign({className:U("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!at&&"px-4 pb-4"),dir:oe?"rtl":"ltr"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[o("div",Object.assign({className:U("flex flex-col gap-y-3 px-4 py-3","block"===Y.formFieldStyle&&"shadow"),style:rt},{children:[Me&&s(B,{colors:Z}),"idle"===fe&&xe.length>0&&s(T,{isDisabled:"idle"!==fe}),o("div",Object.assign({className:U("flex items-end gap-x-2",oe&&"flex-row-reverse")},{children:[s(D,Object.assign({className:U(it.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!Ue.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",oe?"text-right":"text-left",Me&&"text-transparent"),value:Ue,placeholder:null!==(M=null==X?void 0:X.placeholdertext)&&void 0!==M?M:oe?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Be(e),_){const t=(e.match(/\n/g)||[]).length+1;if(t>=11)return;_(24*(t-1))}},onKeyDown:e=>{te||ze||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ke||"idle"!==fe||ut()))}},i&&{onFocus:i},J&&{onBlur:J},{dir:oe?"rtl":"ltr"})),s("div",Object.assign({className:"flex items-center gap-x-2"},{children:Me?s("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Pe,style:{backgroundColor:ot?Z.accent:Z.accent+"10",color:ot?Z.accentText:Z.accent}},nt,{children:s(L,{className:"h-4 w-4 shrink-0"})})):o(n,{children:[null!==($=null===(R=null==X?void 0:X.documentuploadtype)||void 0===R?void 0:R.startsWith("enduserupload"))&&void 0!==$&&$&&o("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Xe?Z.accent+"10":void 0,color:Xe?Z.accent:Z.accent+"80"},disabled:ke||"idle"!==fe,onClick:()=>{var e;return null===(e=Je.current)||void 0===e?void 0:e.click()}},Ye,{children:[s("input",{id:"file-upload",ref:Je,type:"file",accept:[...w,...ye?I:[],...N].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){re(!1),yield we(Array.from(e.target.files||[])),e.target.value=""}))}),s(C,{className:"h-6 w-6 shrink-0"})]})),Fe&&(null==X?void 0:X.enablevoicetotext)&&s("button",Object.assign({className:"flex h-8 w-8 items-center \n justify-center rounded-full\n outline-none transition-colors \n duration-200 ease-in-out\n disabled:cursor-default",style:{backgroundColor:Me?Z.accent:et?Z.accent+"10":void 0,color:Me?Z.accentText:et?Z.accent:Z.accent+"80"},disabled:ke||"idle"!==fe,onClick:()=>{Me?Pe():(_e.current=Ue,Ge())}},tt,{children:s(E,{className:"h-5 w-5 shrink-0"})})),s("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:Qe||dt?Z.accent:Z.accent+"10",color:Qe||dt?Z.accentText:Z.accent+"80"},disabled:"idle"!==fe||ke,onClick:()=>ut()},qe,{children:s(A,{className:U("h-6 w-6 shrink-0",oe&&"transform scale-x-[-1]")})}))]})}))]}))]})),Oe&&s(H,{error:Oe,className:"mt-3"})]}))}))}));J.displayName="Input";export{J 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 r,useState as i,useRef as a,useMemo as l,useEffect as c,useImperativeHandle as d}from"react";import{usePickaxeContext as u}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as m}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as f}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as p}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as g}from"../../../hooks/pickaxe/useConversation.js";import{useAuthContext as h}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as v}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as b}from"../Addons/Document/hooks/useDocument.js";import{useScroll as j}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as x}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useSpeechRecognition as y}from"../../../hooks/pickaxe/useSpeechRecognition.js";import{useHover as k}from"../../../hooks/core/useHover.js";import{useMediaQuery as O}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as w,allowedImageMimeTypes as I,additionalAllowedFileExtensions as N}from"../../../common/documents.js";import{createParser as S}from"eventsource-parser";import C from"../../Icons/attach-vertical.svg.js";import A from"../../Icons/arrow-right.svg.js";import D from"../../Icons/microphone.svg.js";import E from"../../Icons/stop.svg.js";import T from"../Addons/Document/List.js";import L from"../../Core/Textarea.js";import H from"../../Core/ErrorAlert.js";import W from"../../../common/error.js";import P from"../../../common/cn.js";const U=({colors:e})=>{var t,o;const{translations:r}=u();return n("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 items-center gap-x-2"},{children:[s("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(t=e.accent)&&void 0!==t?t:"#ff0000"}}),s("span",Object.assign({className:"text-sm",style:{color:e.text+"90"}},{children:null!==(o=null==r?void 0:r.listening)&&void 0!==o?o:"Listening..."}))]}))},B=r((({onFocus:r,onBlur:B,onInputHeightChange:J},_)=>{var F,M,R;const{formId:$,chatId:G,userId:z,studioUserId:K,embedUserId:Q,deploymentId:q,deploymentType:V,pickaxe:X,styles:Y,colors:Z,studioLang:ee,forceMobile:te,isNewChat:se,isRtl:ne,isEmailLogin:oe,isShowFeedbackMessage:re,setIsNewChat:ie,setIsShowIceBreaker:ae,onGenerateComplete:le}=u(),{token:ce,isLoggedOut:de,isSent:ue}=h(),{messages:me,status:fe,limits:pe,isGenerating:ge,setMessages:he,setStatus:ve,setLimitData:be,setError:je}=m(),{documents:xe,isUploading:ye,isImageUploadAllowed:ke,documentError:Oe,onFileUpload:we,setDocuments:Ie,setDocumentError:Ne}=b(),{scrollStartSession:Se,scrollEndSession:Ce,scrollToBottom:Ae}=j({auto:!0}),{artifacts:De,currentPopupType:Ee,setArtifacts:Te,setCurrentArtifact:Le}=x(),He=g(),We=v(),[Pe,Ue]=i(""),Be=a(null),Je=a(""),_e=a(null),{isSupported:Fe,isListening:Me,finalTranscript:Re,interimTranscript:$e,startListening:Ge,stopListening:ze}=y({lang:ee||"en"}),[Ke]=O("(max-width: 899px)"),Qe=k(),{isHover:qe}=Qe,Ve=e(Qe,["isHover"]),Xe=k(),{isHover:Ye}=Xe,Ze=e(Xe,["isHover"]),et=k(),{isHover:tt}=et,st=e(et,["isHover"]),nt=k(),{isHover:ot}=nt,rt=e(nt,["isHover"]),[it,at]=i(!1),lt=p(),ct=f(),dt="chat-input"===V&&se&&!ue,ut="chat-input"===V&&oe&&de&&ue,mt=l((()=>{var e,t,s;return!!se&&(!!X&&(!He.isLoading&&(!((null!==(t=null===(e=He.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=X.icebreakers)||void 0===s?void 0:s.length)&&(!re&&!dt)))))}),[X,se,re,dt,He.data,He.isLoading]),ft=l((()=>{if(ge||ye)return!1;const e=xe.length>0&&xe.every((e=>{var t;return"finished"===e.status&&(null===(t=e.documentId)||void 0===t?void 0:t.startsWith("IMAGE-"))}));return!(!Pe.trim()&&!e)&&xe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[ge,ye,Pe,xe]);c((()=>{ae(mt)}),[mt]),c((()=>{if(!Me)return;const e=`${Je.current} ${Re} ${$e}`.trim();Ue(e)}),[Re,$e,Me]),c((()=>{!Me&&Je.current&&(Ue(`${Je.current} ${Re}`.trim()),Je.current="")}),[Me,Re]);const pt=e=>t(void 0,void 0,void 0,(function*(){var t,s;try{if("idle"!==fe||ye)return;const n=xe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),o=n.length>0&&n.every((e=>e.startsWith("IMAGE-"))),r=null!=e?e:Pe;if(!r&&!o)return;je(""),Ne(""),be(null),Ue(""),ie(!1),ve("fetching"),Se(),Ae();const i=null!==(s=null===(t=null==X?void 0:X.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&n.length>0,a=[...Array.from(me),Object.assign({id:me.length+1,role:"user",content:r},i&&{documentIds:n})];he(a),Ae(),i&&Ie([]);const l=(yield We.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:$,responseId:G,value:r},i&&{documentIds:n}),z&&{userId:z}),K&&{studioUserId:K}),Q&&{embedUserId:Q}),ce&&{studioSessionToken:ce}),q&&{deploymentId:q}))).body;if(!l)throw new Error("Streaming error");const c=a.length,d=new TextDecoder;_e.current=l.getReader();let u="",m=!0,f=!1,p=[...null!=De?De:[]];const g=S({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");u+=t,he([...a.slice(0,c),{id:me.length+1,role:"assistant",content:u}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(p),Ee.startsWith("inline")||Le({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Te(p),Ee.startsWith("inline")||Le({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(p),Ee.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,"");p=p.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Te(p)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Te(p.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&&(m=!1)}});for(;m&&_e.current;){const{value:e,done:t}=yield _e.current.read();if(t){m=!1;break}const s=d.decode(e);s&&(f||(ve("streaming"),f=!0),g.feed(s))}null==le||le(G)}catch(e){if("AbortError"===e.name)return void console.log("Stream stopped by user.");let t=W(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(pe).find((([e])=>t.includes(e)));s?be(s[1]):je(t)}finally{Ae(),ve("idle"),Ce(),_e.current=null}}));return d(_,(()=>({onSubmit:pt}))),ut?null:s("div",Object.assign({className:P("z-1 absolute bottom-0 left-0 flex w-full flex-col items-center",!dt&&"px-4 pb-4"),dir:ne?"rtl":"ltr"},{children:n("div",Object.assign({className:"relative flex w-full max-w-[800px] flex-col"},{children:[n("div",Object.assign({className:P("flex flex-col gap-y-3 px-4 py-3","block"===Y.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},ct),it&&{backgroundColor:"#EEEEEE"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),at(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),at(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),at(!0)},onDrop:e=>t(void 0,void 0,void 0,(function*(){e.preventDefault(),e.stopPropagation(),at(!1);const t=Array.from(e.dataTransfer.files||[]);t.length>0&&(ie(!1),yield we(t))}))},{children:[Me&&s(U,{colors:Z}),"idle"===fe&&xe.length>0&&s(T,{isDisabled:"idle"!==fe}),n("div",Object.assign({className:P("flex items-end gap-x-2",ne&&"flex-row-reverse")},{children:[s(L,Object.assign({className:P(lt.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!Pe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",ne?"text-right":"text-left",Me&&"text-transparent"),value:Pe,placeholder:null!==(F=null==X?void 0:X.placeholdertext)&&void 0!==F?F:ne?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>{if(Ue(e),J){const t=(e.match(/\n/g)||[]).length+1;if(t>=11)return;J(24*(t-1))}},onKeyDown:e=>{te||Ke||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ye||"idle"!==fe||pt()))},onPaste:e=>t(void 0,void 0,void 0,(function*(){const t=Array.from(e.clipboardData.files||[]);t.length>0&&(e.preventDefault(),ie(!1),yield we(t))}))},r&&{onFocus:r},B&&{onBlur:B},{dir:ne?"rtl":"ltr"})),s("div",Object.assign({className:"flex items-center gap-x-2"},{children:ge?s("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{_e.current&&(_e.current.cancel(),_e.current=null),ve("idle")},style:{backgroundColor:ot?Z.accent:Z.accent+"10",color:ot?Z.accentText:Z.accent}},rt,{children:s(E,{className:"h-4 w-4 shrink-0"})})):Me?s("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:ze,style:{backgroundColor:ot?Z.accent:Z.accent+"10",color:ot?Z.accentText:Z.accent}},rt,{children:s(E,{className:"h-4 w-4 shrink-0"})})):n(o,{children:[null!==(R=null===(M=null==X?void 0:X.documentuploadtype)||void 0===M?void 0:M.startsWith("enduserupload"))&&void 0!==R&&R&&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:Ye?Z.accent+"10":void 0,color:Ye?Z.accent:Z.accent+"80"},disabled:ye||"idle"!==fe,onClick:()=>{var e;return null===(e=Be.current)||void 0===e?void 0:e.click()}},Ze,{children:[s("input",{id:"file-upload",ref:Be,type:"file",accept:[...w,...ke?I:[],...N].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){ie(!1),yield we(Array.from(e.target.files||[])),e.target.value=""}))}),s(C,{className:"h-6 w-6 shrink-0"})]})),Fe&&(null==X?void 0:X.enablevoicetotext)&&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:Me?Z.accent:tt?Z.accent+"10":void 0,color:Me?Z.accentText:tt?Z.accent:Z.accent+"80"},disabled:ye||"idle"!==fe,onClick:()=>{Me?ze():(Je.current=Pe,Ge())}},st,{children:s(D,{className:"h-5 w-5 shrink-0"})})),s("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:qe||ft?Z.accent:Z.accent+"10",color:qe||ft?Z.accentText:Z.accent+"80"},disabled:!ft,onClick:()=>pt()},Ve,{children:s(A,{className:P("h-6 w-6 shrink-0",ne&&"scale-x-[-1] transform")})}))]})}))]}))]})),Oe&&s(H,{error:Oe,className:"mt-3"})]}))}))}));B.displayName="Input";export{B as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "3.20.4",
3
+ "version": "3.21.0",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",