@pickaxeproject/react 5.3.0 → 5.4.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");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("../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"),y=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),x=require("../../Icons/microphone.svg.js"),j=require("../../Icons/stop.svg.js"),w=require("../Addons/Document/List.js"),O=require("../../Core/Textarea.js"),S=require("../../Core/ErrorAlert.js"),k=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 _=s.forwardRef((({resubmitPrompt:N,onFocus:_,onBlur:E,onInputHeightChange:A,initSmitheryAuthData:T},q)=>{var R,P,D;const{origin:L,pickaxeId:H,sessionId:M,sender:F,senderType:$,deploymentId:W,deploymentType:B,pickaxe:J,styles:U,colors:V,locale:K,forceMobile:X,isNewChat:z,isRtl:G,isEmailLogin:Q,isShowFeedbackMessage:Y,setIsNewChat:Z,setIsShowIceBreaker:ee,onGenerateComplete:te}=r.usePickaxeContext(),{token:se,isLoggedOut:ne,isSent:re}=u.useAuthContext(),{messages:ie,limits:oe,isGenerating:ae,setMessages:le,setStatus:ce,setLimitData:ue,setError:de}=i.useResponseContext(),{documents:fe,isUploading:pe,documentError:ge,onFileUpload:he,setDocuments:me,setDocumentError:ve}=d.useDocument(),{scrollStartSession:ye,scrollEndSession:be,scrollToBottom:xe}=f.useScroll({auto:!0}),{artifacts:je,currentPopupType:we,setArtifacts:Oe,setCurrentArtifact:Se}=p.useArtifactContext(),{height:ke}=c.useDimensionContext(),Ce=l.useConversation(),[Ne,Ie]=s.useState(""),[_e,Ee]=s.useState(!1),[Ae,Te]=s.useState(!1),qe=s.useRef(null),Re=s.useRef(""),Pe=s.useRef(null),De=s.useRef(null),Le=s.useRef(null),He=s.useRef(null),Me=s.useRef(null),Fe=Math.max(.4*ke,100),{transcript:$e,listening:We,resetTranscript:Be,browserSupportsSpeechRecognition:Je}=n.useSpeechRecognition(),[Ue]=h.useMediaQuery("(max-width: 480px)"),Ve=g.useHover(),{isHover:Ke}=Ve,Xe=e.__rest(Ve,["isHover"]),ze=g.useHover(),{isHover:Ge}=ze,Qe=e.__rest(ze,["isHover"]),Ye=g.useHover(),{isHover:Ze}=Ye,et=e.__rest(Ye,["isHover"]),[tt,st]=s.useState(!1),nt=a.useStyleFontSize(),rt=o.useStyleInput(),it=null===(R=null==J?void 0:J.documentuploadtype)||void 0===R?void 0:R.startsWith("enduserupload"),ot=Je&&(null==J?void 0:J.enablevoicetotext),at="chat-input"===B&&z&&!re,lt="chat-input"===B&&Q&&ne&&re,ct=null!==(P=null==J?void 0:J.placeholdertext)&&void 0!==P?P:G?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",ut=_e||Ae,dt=s.useMemo((()=>{var e,t,s;return!!z&&(!!J&&(!Ce.isLoading&&(!((null!==(t=null===(e=Ce.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=J.icebreakers)||void 0===s?void 0:s.length)&&(!Y&&!at)))))}),[J,z,Y,at,Ce.data,Ce.isLoading]),ft=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(q,(()=>({onSubmit:pt}))),s.useEffect((()=>{ee(dt)}),[dt]),s.useEffect((()=>{var e;if(N){const t=Array.from(ie),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;pt(s,!0)}}),[N]),s.useEffect((()=>{if(!He.current||!A)return;const e=new ResizeObserver((e=>{for(const t of e)A(t.contentRect.height)}));return e.observe(He.current),()=>{e.disconnect()}}),[A]),s.useEffect((()=>{if(!We)return;const e=Re.current?`${Re.current} `:"";Ie(`${e}${$e}`)}),[$e,We]),s.useEffect((()=>{if(!De.current)return;(()=>{if(!De.current)return;let e=De.current.scrollHeight>52;Ne.includes("\n")||fe.length?e=!0:Ne.trim()||(e=!1),Ee(e)})()}),[Ne,fe]),s.useEffect((()=>{const e=De.current,t=Le.current;if(!e||!t||_e||Ne.includes("\n"))return void Te(!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=Ne||ct,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;Te(i>l)}),[Ne,_e,ct]);const pt=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,r;try{if(ae||pe)return;const i=fe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=i.map((e=>e.documentId)).filter(Boolean),a=i.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=o.length>0,c=null!=t?t:Ne;if(!c&&!l)return;de(""),ve(""),ue(null),Ie(""),Z(!1),ce("fetching"),ye(),xe();const u=null!==(n=null===(e=null==J?void 0:J.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&o.length>0,d=[...s?Array.from(ie.slice(0,ie.length-1)):Array.from(ie),...s?[]:[{id:ie.length+1,role:"user",parts:[{type:"text",content:c,isVisible:!0}],documentIds:u?o:[]}],{id:ie.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];le(d),xe(),u&&me([]);const f=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:L,pickaxeId:H,sessionId:M,senderType:$,value:c},u&&{documentIds:o}),F&&{sender:F}),se&&{studioSessionToken:se}),W&&{deploymentId:W}),a.length>0&&{uploadedModelImages:a}))},process.env.NODE_ENV&&"development"!==process.env.NODE_ENV?{credentials:"include"}:Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}))),p=yield f.json();if(!p.success)throw new Error(p.error||"Failed to start generation");const g=p.submissionId;ce("streaming"),Me.current=new AbortController;const h=d.length-1,m=[];let y=[...null!=je?je:[]],b=0,x=!1,j="";for(;!x;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${g}?index=${b}`,{signal:null===(r=Me.current)||void 0===r?void 0:r.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();Pe.current=t;const s=new TextDecoder,n=v.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&b++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data).error||"Something went wrong.";return de(t),void(x=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&T){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*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw x=!0,T({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw x=!0,T({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)j="",m.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)j+=n.delta,m[m.length-1].content=j;else if("text-end"===n.type)j="";else if("reasoning-start"===n.type)j="",m.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)j+=n.delta,m[m.length-1].content=j;else if("reasoning-end"===n.type)j="";else if(n.type.startsWith("data-")){const e=n;m.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}le([...d.slice(0,h),Object.assign(Object.assign({},d[d.length-1]),{id:ie.length+1,role:"assistant",parts:m})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Oe([...y]),we.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Oe(y),we.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Oe(y),we.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,"");y=y.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Oe(y)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Oe(y.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&&(x=!0)}else x=!0}});for(;;){const{value:e,done:r}=yield t.read();if(r)break;n.feed(s.decode(e))}x||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(x=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==te||te(M)}catch(e){let t=k.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{xe(),ce("idle"),be(),Pe.current=null}}));return lt?null:t.jsx("div",Object.assign({className:C.default("flex w-full flex-shrink-0 flex-col items-center",!at&&"px-4 pb-8"),dir:G?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:He,className:C.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===U.formFieldStyle&&"shadow"),style:Object.assign(Object.assign(Object.assign({},rt),tt&&{backgroundColor:"#EEEEEE"}),{maxHeight:`${Fe}px`,overflowY:"auto"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),st(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),st(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),st(!0)},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),st(!1);const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(Z(!1),yield he(e))}))},{children:[We&&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!==(D=V.accent)&&void 0!==D?D:"#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(w.default,{className:"p-4 pb-0",isDisabled:ae}),t.jsx(O.default,Object.assign({ref:De,className:C.default(nt.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 placeholder:whitespace-normal placeholder:overflow-visible",G?"text-right":"text-left",ut&&"mb-12",We&&"text-transparent"),value:Ne,placeholder:ct,onChange:e=>{if(Ie(e),A){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void A(0);if(t>=11)return;let s=0;t>1&&(s=50),A(24*(t-1)+s)}},onKeyDown:e=>{X||Ue||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),pe||ae||pt()))},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))}))},_&&{onFocus:_},E&&{onBlur:E},{dir:G?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Le,className:C.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&&rt.backgroundColor&&{backgroundColor:rt.backgroundColor}),{borderTopRightRadius:U.cornerRadius+"px",borderBottomRightRadius:U.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:()=>{Me.current&&(Me.current.abort(),Me.current=null),Pe.current&&(Pe.current.cancel(),Pe.current=null),ce("idle")},style:{backgroundColor:V.accent,color:V.accentText}},{children:t.jsx(j.default,{className:"h-4 w-4 shrink-0"})})):We?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(j.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[it&&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:Ge?V.accent+"10":void 0,color:Ge?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{var e;return null===(e=qe.current)||void 0===e?void 0:e.click()}},Qe,{children:[t.jsx("input",{id:"file-upload",ref:qe,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(y.default,{className:"h-6 w-6 shrink-0"})]})),ot&&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:We?V.accent:Ze?V.accent+"10":void 0,color:We?V.accentText:Ze?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{We?I.default.stopListening():(Re.current=Ne,Be(),I.default.startListening({continuous:!0,interimResults:!0,language:K||"en-US"}))}},et,{children:t.jsx(x.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:Ke||ft?V.accent:V.accent+"10",color:Ke||ft?V.accentText:V.accent+"80"},disabled:!ft,onClick:()=>pt()},Xe,{children:t.jsx(b.default,{className:C.default("h-6 w-6 shrink-0",G&&"scale-x-[-1] transform")})}))]})}))]})),ge&&t.jsx(S.default,{error:ge,className:"mt-3"})]}))}))}));_.displayName="Input",exports.default=_;
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("../Addons/Document/hooks/useDocument.js"),f=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),h=require("../../../hooks/core/useHover.js"),m=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),v=require("eventsource-parser"),y=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),x=require("../../Icons/microphone.svg.js"),j=require("../../Icons/stop.svg.js"),w=require("../Addons/Document/List.js"),O=require("../../Core/Textarea.js"),S=require("../../Core/ErrorAlert.js"),k=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 _=s.forwardRef((({resubmitPrompt:N,onFocus:_,onBlur:E,onInputHeightChange:A,initSmitheryAuthData:q},R)=>{var T,P,D;const{origin:L,pickaxeId:H,sessionId:M,sender:F,senderType:$,deploymentId:W,deploymentType:B,pickaxe:J,styles:U,colors:V,locale:K,forceMobile:X,isNewChat:z,isRtl:G,isEmailLogin:Q,isShowFeedbackMessage:Y,setIsNewChat:Z,setIsShowIceBreaker:ee,onGenerateComplete:te}=r.usePickaxeContext(),{token:se,isLoggedOut:ne,isSent:re}=u.useAuthContext(),{messages:ie,limits:oe,isGenerating:ae,setMessages:le,setStatus:ce,setLimitData:ue,setError:de}=i.useResponseContext(),{documents:fe,isUploading:pe,documentError:he,onFileUpload:me,setDocuments:ge,setDocumentError:ve}=d.useDocument(),{scrollStartSession:ye,scrollEndSession:be,scrollToBottom:xe}=f.useScroll({auto:!0}),{artifacts:je,currentPopupType:we,setArtifacts:Oe,setCurrentArtifact:Se}=p.useArtifactContext(),{height:ke}=c.useDimensionContext(),Ce=l.useConversation(),[Ne,Ie]=s.useState(""),[_e,Ee]=s.useState(!1),[Ae,qe]=s.useState(!1),Re=s.useRef(null),Te=s.useRef(""),Pe=s.useRef(null),De=s.useRef(null),Le=s.useRef(null),He=s.useRef(null),Me=s.useRef(null),Fe=Math.max(.4*ke,100),{transcript:$e,listening:We,resetTranscript:Be,browserSupportsSpeechRecognition:Je}=n.useSpeechRecognition(),[Ue]=m.useMediaQuery("(max-width: 480px)"),Ve=h.useHover(),{isHover:Ke}=Ve,Xe=e.__rest(Ve,["isHover"]),ze=h.useHover(),{isHover:Ge}=ze,Qe=e.__rest(ze,["isHover"]),Ye=h.useHover(),{isHover:Ze}=Ye,et=e.__rest(Ye,["isHover"]),tt=a.useStyleFontSize(),st=o.useStyleInput(),nt="undefined"!=typeof window?window.location.hostname:"",rt="undefined"!=typeof window?window.location.href:"",it="undefined"!=typeof window&&window.self!==window.top,ot=nt.includes("pickaxe.co")&&!rt.includes("https://studio.pickaxe.co/_embed")&&!it,at=null===(T=null==J?void 0:J.documentuploadtype)||void 0===T?void 0:T.startsWith("enduserupload"),lt=Je&&(null==J?void 0:J.enablevoicetotext),ct="chat-input"===B&&z&&!re,ut="chat-input"===B&&Q&&ne&&re,dt=null!==(P=null==J?void 0:J.placeholdertext)&&void 0!==P?P:G?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",ft=_e||Ae,pt=s.useMemo((()=>{var e,t,s;return!!z&&(!!J&&(!Ce.isLoading&&(!((null!==(t=null===(e=Ce.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=J.icebreakers)||void 0===s?void 0:s.length)&&(!Y&&!ct)))))}),[J,z,Y,ct,Ce.data,Ce.isLoading]),ht=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(R,(()=>({onSubmit:mt}))),s.useEffect((()=>{ee(pt)}),[pt]),s.useEffect((()=>{var e;if(N){const t=Array.from(ie),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;mt(s,!0)}}),[N]),s.useEffect((()=>{if(!He.current||!A)return;const e=new ResizeObserver((e=>{for(const t of e)A(t.contentRect.height)}));return e.observe(He.current),()=>{e.disconnect()}}),[A]),s.useEffect((()=>{if(!We)return;const e=Te.current?`${Te.current} `:"";Ie(`${e}${$e}`)}),[$e,We]),s.useEffect((()=>{if(!De.current)return;(()=>{if(!De.current)return;let e=De.current.scrollHeight>52;Ne.includes("\n")||fe.length?e=!0:Ne.trim()||(e=!1),Ee(e)})()}),[Ne,fe]),s.useEffect((()=>{const e=De.current,t=Le.current;if(!e||!t||_e||Ne.includes("\n"))return void qe(!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=Ne||dt,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;qe(i>l)}),[Ne,_e,dt]);const mt=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,r;try{if(ae||pe)return;const i=fe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=i.map((e=>e.documentId)).filter(Boolean),a=i.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=o.length>0,c=null!=t?t:Ne;if(!c&&!l)return;de(""),ve(""),ue(null),Ie(""),Z(!1),ce("fetching"),ye(),xe();const u=null!==(n=null===(e=null==J?void 0:J.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&o.length>0,d=[...s?Array.from(ie.slice(0,ie.length-1)):Array.from(ie),...s?[]:[{id:ie.length+1,role:"user",parts:[{type:"text",content:c,isVisible:!0}],documentIds:u?o:[]}],{id:ie.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];le(d),xe(),u&&ge([]);const f=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign(Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:L,pickaxeId:H,sessionId:M,senderType:$,value:c},u&&{documentIds:o}),F&&{sender:F}),se&&{studioSessionToken:se}),W&&{deploymentId:W}),a.length>0&&{uploadedModelImages:a}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),ot&&{credentials:"include"})),p=yield f.json();if(!p.success)throw new Error(p.error||"Failed to start generation");const h=p.submissionId;ce("streaming"),Me.current=new AbortController;const m=d.length-1,g=[];let y=[...null!=je?je:[]],b=0,x=!1,j="";for(;!x;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${h}?index=${b}`,{signal:null===(r=Me.current)||void 0===r?void 0:r.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();Pe.current=t;const s=new TextDecoder,n=v.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&b++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data).error||"Something went wrong.";return de(t),void(x=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&q){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*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw x=!0,q({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw x=!0,q({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)j="",g.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)j+=n.delta,g[g.length-1].content=j;else if("text-end"===n.type)j="";else if("reasoning-start"===n.type)j="",g.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)j+=n.delta,g[g.length-1].content=j;else if("reasoning-end"===n.type)j="";else if(n.type.startsWith("data-")){const e=n;g.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}le([...d.slice(0,m),Object.assign(Object.assign({},d[d.length-1]),{id:ie.length+1,role:"assistant",parts:g})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Oe([...y]),we.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Oe(y),we.startsWith("inline")||Se({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Oe(y),we.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,"");y=y.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Oe(y)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Oe(y.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&&(x=!0)}else x=!0}});for(;;){const{value:e,done:r}=yield t.read();if(r)break;n.feed(s.decode(e))}x||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(x=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==te||te(M)}catch(e){let t=k.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{xe(),ce("idle"),be(),Pe.current=null}}));return ut?null:t.jsx("div",Object.assign({className:C.default("flex w-full flex-shrink-0 flex-col items-center",!ct&&"px-4 pb-8"),dir:G?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:He,className:C.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===U.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},st),{maxHeight:`${Fe}px`,overflowY:"auto"})},{children:[We&&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!==(D=V.accent)&&void 0!==D?D:"#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(w.default,{className:"p-4 pb-0",isDisabled:ae}),t.jsx(O.default,Object.assign({ref:De,className:C.default(tt.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 placeholder:whitespace-normal placeholder:overflow-visible",G?"text-right":"text-left",ft&&"mb-12",We&&"text-transparent"),value:Ne,placeholder:dt,onChange:e=>{if(Ie(e),A){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void A(0);if(t>=11)return;let s=0;t>1&&(s=50),A(24*(t-1)+s)}},onKeyDown:e=>{X||Ue||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),pe||ae||mt()))},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 me(e))}))},_&&{onFocus:_},E&&{onBlur:E},{dir:G?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:Le,className:C.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",ft?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!ft&&st.backgroundColor&&{backgroundColor:st.backgroundColor}),{borderTopRightRadius:U.cornerRadius+"px",borderBottomRightRadius:U.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:()=>{Me.current&&(Me.current.abort(),Me.current=null),Pe.current&&(Pe.current.cancel(),Pe.current=null),ce("idle")},style:{backgroundColor:V.accent,color:V.accentText}},{children:t.jsx(j.default,{className:"h-4 w-4 shrink-0"})})):We?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(j.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[at&&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:Ge?V.accent+"10":void 0,color:Ge?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{var e;return null===(e=Re.current)||void 0===e?void 0:e.click()}},Qe,{children:[t.jsx("input",{id:"file-upload",ref:Re,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){Z(!1),yield me(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(y.default,{className:"h-6 w-6 shrink-0"})]})),lt&&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:We?V.accent:Ze?V.accent+"10":void 0,color:We?V.accentText:Ze?V.accent:V.accent+"80"},disabled:pe||ae,onClick:()=>{We?I.default.stopListening():(Te.current=Ne,Be(),I.default.startListening({continuous:!0,interimResults:!0,language:K||"en-US"}))}},et,{children:t.jsx(x.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:Ke||ht?V.accent:V.accent+"10",color:Ke||ht?V.accentText:V.accent+"80"},disabled:!ht,onClick:()=>mt()},Xe,{children:t.jsx(b.default,{className:C.default("h-6 w-6 shrink-0",G&&"scale-x-[-1] transform")})}))]})}))]})),he&&t.jsx(S.default,{error:he,className:"mt-3"})]}))}))}));_.displayName="Input",exports.default=_;
@@ -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"),u=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../Addons/Auth/hooks/useAuthContext.js"),n=require("../../../hooks/pickaxe/useDimensionContext.js"),i=require("../Addons/Document/hooks/useDocument.js"),o=require("./History/index.js"),c=require("./Input.js");exports.default=()=>{const{deploymentType:a,isNewChat:l}=u.usePickaxeContext(),{isSent:d}=r.useAuthContext(),{width:h,height:x,setDimension:f}=n.useDimensionContext(),{setDocuments:m}=i.useDocument(),[j,p]=s.useState(0),[v,b]=s.useState(!1),q=s.useRef(null),D=s.useRef(null),[S,k]=s.useState(null),[C,g]=s.useState(!1),A="chat-input"===a&&l&&!d;return s.useEffect((()=>()=>{m([])}),[]),s.useEffect((()=>{if(!q.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:s}=t.contentRect;f(parseInt(e.toFixed(0)),parseInt(s.toFixed(0)))}}));return e.observe(q.current),()=>{e.disconnect()}}),[q.current]),t.jsx("div",Object.assign({ref:q,className:"relative flex h-full w-full flex-col items-center"},{children:A?t.jsx(c.default,{}):t.jsxs(t.Fragment,{children:[t.jsx(o.default,{additionalScrollHeight:j,isForceHideInfo:x<=545||h<=350||v,isInputFocused:v,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){D.current&&D.current.onSubmit(t)})),smitheryAuthData:S,resubmitPrompt:()=>{k(null),g(!0)}}),t.jsx(c.default,{ref:D,onFocus:()=>b(!0),onBlur:()=>b(!1),onInputHeightChange:p,initSmitheryAuthData:e=>k(e),resubmitPrompt:C})]})}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../Addons/Auth/hooks/useAuthContext.js"),i=require("../../../hooks/pickaxe/useDimensionContext.js"),o=require("../Addons/Document/hooks/useDocument.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),u=require("./History/index.js"),c=require("./Input.js"),l=require("../../Icons/attach-vertical.svg.js"),d=require("../../../common/cn.js");exports.default=()=>{const{deploymentType:f,isNewChat:h,setIsNewChat:m}=r.usePickaxeContext(),{isSent:p}=n.useAuthContext(),{width:x,height:j,setDimension:g}=i.useDimensionContext(),{setDocuments:b,onFileUpload:v}=o.useDocument(),D=a.useStyleFontSize(),[y,S]=s.useState(0),[k,w]=s.useState(!1),[q,A]=s.useState(!1),C=s.useRef(null),F=s.useRef(null),P=s.useRef(0),[I,N]=s.useState(null),[O,_]=s.useState(!1),R="chat-input"===f&&h&&!p;s.useEffect((()=>()=>{b([])}),[]),s.useEffect((()=>{if(!C.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:s}=t.contentRect;g(parseInt(e.toFixed(0)),parseInt(s.toFixed(0)))}}));return e.observe(C.current),()=>{e.disconnect()}}),[C.current]);return t.jsxs("div",Object.assign({ref:C,className:"relative flex h-full w-full flex-col items-center",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),P.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&A(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),P.current-=1,0===P.current&&A(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),A(!1),P.current=0;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(m(!1),yield v(e))}))},{children:[q&&t.jsxs("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[t.jsx("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:t.jsx(l.default,{className:"h-10 w-10"})})),t.jsx("h3",Object.assign({className:d.default(D.h3,"mt-6 font-semibold text-c-primary text-black")},{children:"Drop files to upload"})),t.jsx("p",Object.assign({className:d.default(D.b2,"mt-2 opacity-60 text-black")},{children:"Add anything to the conversation"}))]})),R?t.jsx(c.default,{}):t.jsxs(t.Fragment,{children:[t.jsx(u.default,{additionalScrollHeight:y,isForceHideInfo:j<=545||x<=350||k,isInputFocused:k,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){F.current&&F.current.onSubmit(t)})),smitheryAuthData:I,resubmitPrompt:()=>{N(null),_(!0)}}),t.jsx(c.default,{ref:F,onFocus:()=>w(!0),onBlur:()=>w(!1),onInputHeightChange:S,initSmitheryAuthData:e=>N(e),resubmitPrompt:O})]})]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/studio/useStyleInput.js"),r=require("../../../../hooks/studio/useStyleFontSize.js"),a=require("@nem035/gpt-3-encoder"),i=require("../../../Core/Textarea.js"),l=require("../../../../common/cn.js");exports.default=({field:c,update:u})=>{const{styles:d,colors:p,isRtl:x}=s.usePickaxeContext(),{setError:h}=o.useResponseContext(),[g,m]=t.useState(!1),j=r.useStyleFontSize(),b=n.useStyleInput();return e.jsxs("div",Object.assign({className:"group relative flex flex-col gap-y-1",dir:x?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex flex-col gap-y-2"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:l.default(j.b3,"font-semibold opacity-70")},{children:c.main})),c.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:p.accent}},{children:"*"}))]})),e.jsx(i.default,{className:l.default(j.i1,"rounded-sm border border-transparent px-4 py-3 duration-300 ease-in-out transition-all placeholder:font-semilight",c.maxLength<10&&"max-w-[400px]","block"===d.formFieldStyle&&"shadow hover:shadow-none"),style:b,placeholder:c.placeholder,rows:1,value:c.input,tabIndex:c.order,onChange:e=>{h("");const t=a.encode(e).length;u(Object.assign(Object.assign({},c),{input:e,length:t}))},onFocus:()=>m(!0),onBlur:()=>m(!1),onPaste:e=>{if(e.clipboardData.getData("text").length<1e3)return;const t=e.target;setTimeout((()=>{const e=t.getBoundingClientRect().bottom+window.scrollY;window.scrollTo({top:e,behavior:"smooth"})}),250)}})]})),e.jsx("div",Object.assign({className:"pointer-events-none absolute bottom-0 right-0 p-1 px-2"},{children:e.jsxs("p",Object.assign({className:l.default(j.b4,"font-semibold opacity-20 opacity-0 group-hover:opacity-100 group-hover:duration-200",c.length>c.maxLength&&"text-c-red opacity-100",g&&"opacity-100")},{children:[c.length,"/",c.maxLength]}))}))]}))};
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"),o=require("../../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../../hooks/pickaxe/useResponseContext.js"),a=require("../../../../hooks/studio/useStyleInput.js"),i=require("../../../../hooks/studio/useStyleFontSize.js"),l=require("../../../../hooks/core/useHover.js"),c=require("../../../Core/Textarea.js"),u=require("../../../Icons/microphone.svg.js"),d=require("../../../Icons/stop.svg.js"),p=require("../../../../common/cn.js");function g(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=g(n);exports.default=({field:g,update:h})=>{var m;const{styles:j,colors:f,isRtl:b,pickaxe:v,locale:y}=o.usePickaxeContext(),{setError:O}=r.useResponseContext(),[k,N]=s.useState(!1),q=i.useStyleFontSize(),w=a.useStyleInput(),{transcript:S,listening:C,resetTranscript:R,browserSupportsSpeechRecognition:_}=n.useSpeechRecognition(),L=s.useRef(""),I=l.useHover(),{isHover:T}=I,z=e.__rest(I,["isHover"]),F=_&&(null==v?void 0:v.enablevoicetotext),H=e=>{O("");const t=e.length;h(Object.assign(Object.assign({},g),{input:e,length:t}))};s.useEffect((()=>{if(!C)return;const e=L.current?`${L.current} `:"";H(`${e}${S}`)}),[S,C]);return t.jsxs("div",Object.assign({className:"group relative flex flex-col gap-y-1",dir:b?"rtl":"ltr"},{children:[t.jsxs("div",Object.assign({className:"flex flex-col gap-y-2"},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[t.jsx("p",Object.assign({className:p.default(q.b3,"font-semibold opacity-70")},{children:g.main})),g.isRequired&&t.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:f.accent}},{children:"*"}))]})),t.jsxs("div",Object.assign({className:"relative w-full"},{children:[C&&t.jsxs("div",Object.assign({className:p.default("absolute top-3.5 z-10 flex select-none items-center gap-x-2 pointer-events-none",b?"right-4":"left-4")},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(m=f.accent)&&void 0!==m?m:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm font-semilight",style:{color:f.text+"90"}},{children:"Listening..."}))]})),t.jsx(c.default,{className:p.default(q.i1,"rounded-sm border border-transparent py-3 duration-300 ease-in-out transition-all placeholder:font-semilight w-full",b?F?"pl-10 pr-4":"px-4":F?"pl-4 pr-10":"px-4",g.maxLength<10&&"max-w-[400px]","block"===j.formFieldStyle&&"shadow hover:shadow-none",C&&"caret-transparent"),style:Object.assign(Object.assign({},w),C&&{color:"transparent"}),placeholder:C?"":g.placeholder,rows:1,value:g.input,tabIndex:g.order,onChange:H,onFocus:()=>N(!0),onBlur:()=>N(!1),onPaste:e=>{if(e.clipboardData.getData("text").length<1e3)return;const t=e.target;setTimeout((()=>{const e=t.getBoundingClientRect().bottom+window.scrollY;window.scrollTo({top:e,behavior:"smooth"})}),250)}}),F&&t.jsx("div",Object.assign({className:p.default("absolute top-2 z-20",b?"left-2":"right-2")},{children: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",style:{backgroundColor:C?f.accent:T?f.accent+"10":void 0,color:C?f.accentText:T?f.accent:f.accent+"80"},onClick:()=>{C?x.default.stopListening():(L.current=g.input||"",R(),x.default.startListening({continuous:!0,interimResults:!0,language:y||"en-US"}),N(!0))}},z,{type:"button"},{children:C?t.jsx(d.default,{className:"h-4 w-4 shrink-0"}):t.jsx(u.default,{className:"h-5 w-5 shrink-0"})}))}))]}))]})),t.jsx("div",Object.assign({className:"pointer-events-none absolute bottom-0 right-0 p-1 px-2"},{children:t.jsxs("p",Object.assign({className:p.default(q.b4,"font-semibold opacity-20 opacity-0 group-hover:opacity-100 group-hover:duration-200",g.length>g.maxLength&&"text-c-red opacity-100",k&&"opacity-100")},{children:[g.length,"/",g.maxLength]}))}))]}))};
@@ -1,4 +1,5 @@
1
1
  import type { MemoryStoredQuestionField } from "../../../../types/form";
2
+ import "regenerator-runtime/runtime";
2
3
  interface InputProps {
3
4
  field: MemoryStoredQuestionField;
4
5
  update: (questions: MemoryStoredQuestionField) => void;
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as n,jsxs as s,Fragment as o}from"react/jsx-runtime";import{forwardRef as r,useState as i,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{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 w}from"../../../hooks/core/useHover.js";import{useMediaQuery as k}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 E from"../../Icons/attach-vertical.svg.js";import A from"../../Icons/arrow-right.svg.js";import _ from"../../Icons/microphone.svg.js";import T from"../../Icons/stop.svg.js";import P from"../Addons/Document/List.js";import D from"../../Core/Textarea.js";import R from"../../Core/ErrorAlert.js";import L from"../../../common/error.js";import $ from"../../../common/cn.js";const W=r((({resubmitPrompt:r,onFocus:W,onBlur:B,onInputHeightChange:H,initSmitheryAuthData:F},J)=>{var U,M,V;const{origin:K,pickaxeId:X,sessionId:z,sender:q,senderType:G,deploymentId:Q,deploymentType:Y,pickaxe:Z,styles:ee,colors:te,locale:ne,forceMobile:se,isNewChat:oe,isRtl:re,isEmailLogin:ie,isShowFeedbackMessage:ae,setIsNewChat:le,setIsShowIceBreaker:ce,onGenerateComplete:de}=p(),{token:ue,isLoggedOut:me,isSent:pe}=y(),{messages:fe,limits:ge,isGenerating:he,setMessages:ve,setStatus:be,setLimitData:ye,setError:je}=f(),{documents:xe,isUploading:Oe,documentError:we,onFileUpload:ke,setDocuments:Se,setDocumentError:Ne}=j(),{scrollStartSession:Ce,scrollEndSession:Ie,scrollToBottom:Ee}=x({auto:!0}),{artifacts:Ae,currentPopupType:_e,setArtifacts:Te,setCurrentArtifact:Pe}=O(),{height:De}=b(),Re=v(),[Le,$e]=i(""),[We,Be]=i(!1),[He,Fe]=i(!1),Je=a(null),Ue=a(""),Me=a(null),Ve=a(null),Ke=a(null),Xe=a(null),ze=a(null),qe=Math.max(.4*De,100),{transcript:Ge,listening:Qe,resetTranscript:Ye,browserSupportsSpeechRecognition:Ze}=m(),[et]=k("(max-width: 480px)"),tt=w(),{isHover:nt}=tt,st=e(tt,["isHover"]),ot=w(),{isHover:rt}=ot,it=e(ot,["isHover"]),at=w(),{isHover:lt}=at,ct=e(at,["isHover"]),[dt,ut]=i(!1),mt=h(),pt=g(),ft=null===(U=null==Z?void 0:Z.documentuploadtype)||void 0===U?void 0:U.startsWith("enduserupload"),gt=Ze&&(null==Z?void 0:Z.enablevoicetotext),ht="chat-input"===Y&&oe&&!pe,vt="chat-input"===Y&&ie&&me&&pe,bt=null!==(M=null==Z?void 0:Z.placeholdertext)&&void 0!==M?M:re?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",yt=We||He,jt=l((()=>{var e,t,n;return!!oe&&(!!Z&&(!Re.isLoading&&(!((null!==(t=null===(e=Re.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(n=Z.icebreakers)||void 0===n?void 0:n.length)&&(!ae&&!ht)))))}),[Z,oe,ae,ht,Re.data,Re.isLoading]),xt=l((()=>{if(he||Oe)return!1;const e=xe.length>0&&xe.every((e=>"finished"===e.status));return!(!Le.trim()&&!e)&&xe.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[he,Oe,Le,xe]);c(J,(()=>({onSubmit:Ot}))),d((()=>{ce(jt)}),[jt]),d((()=>{var e;if(r){const t=Array.from(fe),n=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Ot(n,!0)}}),[r]),d((()=>{if(!Xe.current||!H)return;const e=new ResizeObserver((e=>{for(const t of e)H(t.contentRect.height)}));return e.observe(Xe.current),()=>{e.disconnect()}}),[H]),d((()=>{if(!Qe)return;const e=Ue.current?`${Ue.current} `:"";$e(`${e}${Ge}`)}),[Ge,Qe]),d((()=>{if(!Ve.current)return;(()=>{if(!Ve.current)return;let e=Ve.current.scrollHeight>52;Le.includes("\n")||xe.length?e=!0:Le.trim()||(e=!1),Be(e)})()}),[Le,xe]),d((()=>{const e=Ve.current,t=Ke.current;if(!e||!t||We||Le.includes("\n"))return void Fe(!1);const n=window.getComputedStyle(e),s=`${n.fontStyle} ${n.fontVariant} ${n.fontWeight} ${n.fontSize} / ${n.lineHeight} ${n.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:s,letterSpacing:n.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=Le||bt,document.body.appendChild(o);const r=o.offsetWidth;o.remove();const i=parseFloat(n.paddingLeft)||0,a=parseFloat(n.paddingRight)||0,l=e.clientWidth-i-a-t.offsetWidth;Fe(r>l)}),[Le,We,bt]);const Ot=(e,n=!1)=>t(void 0,void 0,void 0,(function*(){var t,s,o;try{if(he||Oe)return;const r=xe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),i=r.map((e=>e.documentId)).filter(Boolean),a=r.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=i.length>0,c=null!=e?e:Le;if(!c&&!l)return;je(""),Ne(""),ye(null),$e(""),le(!1),be("fetching"),Ce(),Ee();const d=null!==(s=null===(t=null==Z?void 0:Z.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&i.length>0,u=[...n?Array.from(fe.slice(0,fe.length-1)):Array.from(fe),...n?[]:[{id:fe.length+1,role:"user",parts:[{type:"text",content:c,isVisible:!0}],documentIds:d?i:[]}],{id:fe.length+(n?0:2),role:"assistant",parts:[],documentIds:[]}];ve(u),Ee(),d&&Se([]);const m=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:K,pickaxeId:X,sessionId:z,senderType:G,value:c},d&&{documentIds:i}),q&&{sender:q}),ue&&{studioSessionToken:ue}),Q&&{deploymentId:Q}),a.length>0&&{uploadedModelImages:a}))},process.env.NODE_ENV&&"development"!==process.env.NODE_ENV?{credentials:"include"}:Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}))),p=yield m.json();if(!p.success)throw new Error(p.error||"Failed to start generation");const f=p.submissionId;be("streaming"),ze.current=new AbortController;const g=u.length-1,h=[];let v=[...null!=Ae?Ae:[]],b=0,y=!1,j="";for(;!y;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${f}?index=${b}`,{signal:null===(o=ze.current)||void 0===o?void 0:o.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();Me.current=t;const n=new TextDecoder,s=I({onEvent:e=>{var t,n;if(e.event&&"ping"!==e.event&&b++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data).error||"Something went wrong.";return je(t),void(y=!0)}if("delta"===e.event){const s=JSON.parse(e.data);if("data-error"===s.type&&F){const e=s.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&n&&n[1]&&s&&s[1])throw y=!0,F({smitheryId:t[1],serverId:n[1],name:s[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw y=!0,F({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===s.type)j="",h.push({type:"text",content:"",isVisible:null===(t=s.isVisible)||void 0===t||t});else if("text-delta"===s.type)j+=s.delta,h[h.length-1].content=j;else if("text-end"===s.type)j="";else if("reasoning-start"===s.type)j="",h.push({type:"reasoning",content:"",isVisible:null===(n=s.isVisible)||void 0===n||n});else if("reasoning-delta"===s.type)j+=s.delta,h[h.length-1].content=j;else if("reasoning-end"===s.type)j="";else if(s.type.startsWith("data-")){const e=s;h.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}ve([...u.slice(0,g),Object.assign(Object.assign({},u[u.length-1]),{id:fe.length+1,role:"assistant",parts:h})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te([...v]),_e.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Te(v),_e.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(v),_e.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),n=t.token.replace(/\u200B/g,"");v=v.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+n,status:"streaming"}):e)),Te(v)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Te(v.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&&(y=!0)}else y=!0}});for(;;){const{value:e,done:o}=yield t.read();if(o)break;s.feed(n.decode(e))}y||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(y=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==de||de(z)}catch(e){let t=L(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const n=Object.entries(ge).find((([e])=>t.includes(e)));n?ye(n[1]):je(t)}finally{Ee(),be("idle"),Ie(),Me.current=null}}));return vt?null:n("div",Object.assign({className:$("flex w-full flex-shrink-0 flex-col items-center",!ht&&"px-4 pb-8"),dir:re?"rtl":"ltr"},{children:s("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[s("div",Object.assign({ref:Xe,className:$("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===ee.formFieldStyle&&"shadow"),style:Object.assign(Object.assign(Object.assign({},pt),dt&&{backgroundColor:"#EEEEEE"}),{maxHeight:`${qe}px`,overflowY:"auto"}),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),ut(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),ut(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation(),ut(!0)},onDrop:e=>t(void 0,void 0,void 0,(function*(){e.preventDefault(),e.stopPropagation(),ut(!1);const t=Array.from(e.dataTransfer.files||[]);t.length>0&&(le(!1),yield ke(t))}))},{children:[Qe&&s("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[n("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(V=te.accent)&&void 0!==V?V:"#ff0000"}}),n("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:te.text+"90"}},{children:"Listening..."}))]})),!he&&xe.length>0&&n(P,{className:"p-4 pb-0",isDisabled:he}),n(D,Object.assign({ref:Ve,className:$(mt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Le.trim()&&!Le.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",re?"text-right":"text-left",yt&&"mb-12",Qe&&"text-transparent"),value:Le,placeholder:bt,onChange:e=>{if($e(e),H){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void H(0);if(t>=11)return;let n=0;t>1&&(n=50),H(24*(t-1)+n)}},onKeyDown:e=>{se||et||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Oe||he||Ot()))},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 ke(t))}))},W&&{onFocus:W},B&&{onBlur:B},{dir:re?"rtl":"ltr"})),n("div",Object.assign({ref:Ke,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&&pt.backgroundColor&&{backgroundColor:pt.backgroundColor}),{borderTopRightRadius:ee.cornerRadius+"px",borderBottomRightRadius:ee.cornerRadius+"px"})},{children:he?n("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.abort(),ze.current=null),Me.current&&(Me.current.cancel(),Me.current=null),be("idle")},style:{backgroundColor:te.accent,color:te.accentText}},{children:n(T,{className:"h-4 w-4 shrink-0"})})):Qe?n("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:n(T,{className:"h-4 w-4 shrink-0"})})):s(o,{children:[ft&&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:rt?te.accent+"10":void 0,color:rt?te.accent:te.accent+"80"},disabled:Oe||he,onClick:()=>{var e;return null===(e=Je.current)||void 0===e?void 0:e.click()}},it,{children:[n("input",{id:"file-upload",ref:Je,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 ke(Array.from(e.target.files||[])),e.target.value=""}))}),n(E,{className:"h-6 w-6 shrink-0"})]})),gt&&n("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:Qe?te.accent:lt?te.accent+"10":void 0,color:Qe?te.accentText:lt?te.accent:te.accent+"80"},disabled:Oe||he,onClick:()=>{Qe?u.stopListening():(Ue.current=Le,Ye(),u.startListening({continuous:!0,interimResults:!0,language:ne||"en-US"}))}},ct,{children:n(_,{className:"h-5 w-5 shrink-0"})})),n("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?te.accent:te.accent+"10",color:nt||xt?te.accentText:te.accent+"80"},disabled:!xt,onClick:()=>Ot()},st,{children:n(A,{className:$("h-6 w-6 shrink-0",re&&"scale-x-[-1] transform")})}))]})}))]})),we&&n(R,{error:we,className:"mt-3"})]}))}))}));W.displayName="Input";export{W as default};
1
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as n,jsxs as s,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 h}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as g}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{useDocument as x}from"../Addons/Document/hooks/useDocument.js";import{useScroll as j}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as w}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as O}from"../../../hooks/core/useHover.js";import{useMediaQuery as k}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as S,allowedImageMimeTypes as N,additionalAllowedFileExtensions as I}from"../../../common/documents.js";import{createParser as C}from"eventsource-parser";import E from"../../Icons/attach-vertical.svg.js";import _ from"../../Icons/arrow-right.svg.js";import A from"../../Icons/microphone.svg.js";import T from"../../Icons/stop.svg.js";import P from"../Addons/Document/List.js";import R from"../../Core/Textarea.js";import L from"../../Core/ErrorAlert.js";import D from"../../../common/error.js";import $ from"../../../common/cn.js";const W=i((({resubmitPrompt:i,onFocus:W,onBlur:B,onInputHeightChange:H,initSmitheryAuthData:F},J)=>{var U,M,V;const{origin:K,pickaxeId:X,sessionId:z,sender:q,senderType:G,deploymentId:Q,deploymentType:Y,pickaxe:Z,styles:ee,colors:te,locale:ne,forceMobile:se,isNewChat:oe,isRtl:ie,isEmailLogin:re,isShowFeedbackMessage:ae,setIsNewChat:le,setIsShowIceBreaker:ce,onGenerateComplete:de}=p(),{token:ue,isLoggedOut:me,isSent:pe}=y(),{messages:fe,limits:he,isGenerating:ge,setMessages:ve,setStatus:be,setLimitData:ye,setError:xe}=f(),{documents:je,isUploading:we,documentError:Oe,onFileUpload:ke,setDocuments:Se,setDocumentError:Ne}=x(),{scrollStartSession:Ie,scrollEndSession:Ce,scrollToBottom:Ee}=j({auto:!0}),{artifacts:_e,currentPopupType:Ae,setArtifacts:Te,setCurrentArtifact:Pe}=w(),{height:Re}=b(),Le=v(),[De,$e]=r(""),[We,Be]=r(!1),[He,Fe]=r(!1),Je=a(null),Ue=a(""),Me=a(null),Ve=a(null),Ke=a(null),Xe=a(null),ze=a(null),qe=Math.max(.4*Re,100),{transcript:Ge,listening:Qe,resetTranscript:Ye,browserSupportsSpeechRecognition:Ze}=m(),[et]=k("(max-width: 480px)"),tt=O(),{isHover:nt}=tt,st=e(tt,["isHover"]),ot=O(),{isHover:it}=ot,rt=e(ot,["isHover"]),at=O(),{isHover:lt}=at,ct=e(at,["isHover"]),dt=g(),ut=h(),mt="undefined"!=typeof window?window.location.hostname:"",pt="undefined"!=typeof window?window.location.href:"",ft="undefined"!=typeof window&&window.self!==window.top,ht=mt.includes("pickaxe.co")&&!pt.includes("https://studio.pickaxe.co/_embed")&&!ft,gt=null===(U=null==Z?void 0:Z.documentuploadtype)||void 0===U?void 0:U.startsWith("enduserupload"),vt=Ze&&(null==Z?void 0:Z.enablevoicetotext),bt="chat-input"===Y&&oe&&!pe,yt="chat-input"===Y&&re&&me&&pe,xt=null!==(M=null==Z?void 0:Z.placeholdertext)&&void 0!==M?M:ie?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",jt=We||He,wt=l((()=>{var e,t,n;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===(n=Z.icebreakers)||void 0===n?void 0:n.length)&&(!ae&&!bt)))))}),[Z,oe,ae,bt,Le.data,Le.isLoading]),Ot=l((()=>{if(ge||we)return!1;const e=je.length>0&&je.every((e=>"finished"===e.status));return!(!De.trim()&&!e)&&je.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[ge,we,De,je]);c(J,(()=>({onSubmit:kt}))),d((()=>{ce(wt)}),[wt]),d((()=>{var e;if(i){const t=Array.from(fe),n=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;kt(n,!0)}}),[i]),d((()=>{if(!Xe.current||!H)return;const e=new ResizeObserver((e=>{for(const t of e)H(t.contentRect.height)}));return e.observe(Xe.current),()=>{e.disconnect()}}),[H]),d((()=>{if(!Qe)return;const e=Ue.current?`${Ue.current} `:"";$e(`${e}${Ge}`)}),[Ge,Qe]),d((()=>{if(!Ve.current)return;(()=>{if(!Ve.current)return;let e=Ve.current.scrollHeight>52;De.includes("\n")||je.length?e=!0:De.trim()||(e=!1),Be(e)})()}),[De,je]),d((()=>{const e=Ve.current,t=Ke.current;if(!e||!t||We||De.includes("\n"))return void Fe(!1);const n=window.getComputedStyle(e),s=`${n.fontStyle} ${n.fontVariant} ${n.fontWeight} ${n.fontSize} / ${n.lineHeight} ${n.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:s,letterSpacing:n.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=De||xt,document.body.appendChild(o);const i=o.offsetWidth;o.remove();const r=parseFloat(n.paddingLeft)||0,a=parseFloat(n.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;Fe(i>l)}),[De,We,xt]);const kt=(e,n=!1)=>t(void 0,void 0,void 0,(function*(){var t,s,o;try{if(ge||we)return;const i=je.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),r=i.map((e=>e.documentId)).filter(Boolean),a=i.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=r.length>0,c=null!=e?e:De;if(!c&&!l)return;xe(""),Ne(""),ye(null),$e(""),le(!1),be("fetching"),Ie(),Ee();const d=null!==(s=null===(t=null==Z?void 0:Z.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&r.length>0,u=[...n?Array.from(fe.slice(0,fe.length-1)):Array.from(fe),...n?[]:[{id:fe.length+1,role:"user",parts:[{type:"text",content:c,isVisible:!0}],documentIds:d?r:[]}],{id:fe.length+(n?0:2),role:"assistant",parts:[],documentIds:[]}];ve(u),Ee(),d&&Se([]);const m=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign(Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:K,pickaxeId:X,sessionId:z,senderType:G,value:c},d&&{documentIds:r}),q&&{sender:q}),ue&&{studioSessionToken:ue}),Q&&{deploymentId:Q}),a.length>0&&{uploadedModelImages:a}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),ht&&{credentials:"include"})),p=yield m.json();if(!p.success)throw new Error(p.error||"Failed to start generation");const f=p.submissionId;be("streaming"),ze.current=new AbortController;const h=u.length-1,g=[];let v=[...null!=_e?_e:[]],b=0,y=!1,x="";for(;!y;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${f}?index=${b}`,{signal:null===(o=ze.current)||void 0===o?void 0:o.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();Me.current=t;const n=new TextDecoder,s=C({onEvent:e=>{var t,n;if(e.event&&"ping"!==e.event&&b++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data).error||"Something went wrong.";return xe(t),void(y=!0)}if("delta"===e.event){const s=JSON.parse(e.data);if("data-error"===s.type&&F){const e=s.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&n&&n[1]&&s&&s[1])throw y=!0,F({smitheryId:t[1],serverId:n[1],name:s[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw y=!0,F({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===s.type)x="",g.push({type:"text",content:"",isVisible:null===(t=s.isVisible)||void 0===t||t});else if("text-delta"===s.type)x+=s.delta,g[g.length-1].content=x;else if("text-end"===s.type)x="";else if("reasoning-start"===s.type)x="",g.push({type:"reasoning",content:"",isVisible:null===(n=s.isVisible)||void 0===n||n});else if("reasoning-delta"===s.type)x+=s.delta,g[g.length-1].content=x;else if("reasoning-end"===s.type)x="";else if(s.type.startsWith("data-")){const e=s;g.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}ve([...u.slice(0,h),Object.assign(Object.assign({},u[u.length-1]),{id:fe.length+1,role:"assistant",parts:g})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te([...v]),Ae.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Te(v),Ae.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);v=v.filter((e=>!(e.id===t.id&&e.version===t.version))),v.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Te(v),Ae.startsWith("inline")||Pe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),n=t.token.replace(/\u200B/g,"");v=v.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+n,status:"streaming"}):e)),Te(v)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Te(v.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&&(y=!0)}else y=!0}});for(;;){const{value:e,done:o}=yield t.read();if(o)break;s.feed(n.decode(e))}y||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(y=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==de||de(z)}catch(e){let t=D(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const n=Object.entries(he).find((([e])=>t.includes(e)));n?ye(n[1]):xe(t)}finally{Ee(),be("idle"),Ce(),Me.current=null}}));return yt?null:n("div",Object.assign({className:$("flex w-full flex-shrink-0 flex-col items-center",!bt&&"px-4 pb-8"),dir:ie?"rtl":"ltr"},{children:s("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[s("div",Object.assign({ref:Xe,className:$("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===ee.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},ut),{maxHeight:`${qe}px`,overflowY:"auto"})},{children:[Qe&&s("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[n("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(V=te.accent)&&void 0!==V?V:"#ff0000"}}),n("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:te.text+"90"}},{children:"Listening..."}))]})),!ge&&je.length>0&&n(P,{className:"p-4 pb-0",isDisabled:ge}),n(R,Object.assign({ref:Ve,className:$(dt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!De.trim()&&!De.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",ie?"text-right":"text-left",jt&&"mb-12",Qe&&"text-transparent"),value:De,placeholder:xt,onChange:e=>{if($e(e),H){const t=(e.match(/\n/g)||[]).length+1;if(!e)return void H(0);if(t>=11)return;let n=0;t>1&&(n=50),H(24*(t-1)+n)}},onKeyDown:e=>{se||et||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),we||ge||kt()))},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 ke(t))}))},W&&{onFocus:W},B&&{onBlur:B},{dir:ie?"rtl":"ltr"})),n("div",Object.assign({ref:Ke,className:$("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",jt?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!jt&&ut.backgroundColor&&{backgroundColor:ut.backgroundColor}),{borderTopRightRadius:ee.cornerRadius+"px",borderBottomRightRadius:ee.cornerRadius+"px"})},{children:ge?n("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.abort(),ze.current=null),Me.current&&(Me.current.cancel(),Me.current=null),be("idle")},style:{backgroundColor:te.accent,color:te.accentText}},{children:n(T,{className:"h-4 w-4 shrink-0"})})):Qe?n("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:n(T,{className:"h-4 w-4 shrink-0"})})):s(o,{children:[gt&&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:it?te.accent+"10":void 0,color:it?te.accent:te.accent+"80"},disabled:we||ge,onClick:()=>{var e;return null===(e=Je.current)||void 0===e?void 0:e.click()}},rt,{children:[n("input",{id:"file-upload",ref:Je,type:"file",accept:[...S,...N,...I].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){le(!1),yield ke(Array.from(e.target.files||[])),e.target.value=""}))}),n(E,{className:"h-6 w-6 shrink-0"})]})),vt&&n("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:Qe?te.accent:lt?te.accent+"10":void 0,color:Qe?te.accentText:lt?te.accent:te.accent+"80"},disabled:we||ge,onClick:()=>{Qe?u.stopListening():(Ue.current=De,Ye(),u.startListening({continuous:!0,interimResults:!0,language:ne||"en-US"}))}},ct,{children:n(A,{className:"h-5 w-5 shrink-0"})})),n("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||Ot?te.accent:te.accent+"10",color:nt||Ot?te.accentText:te.accent+"80"},disabled:!Ot,onClick:()=>kt()},st,{children:n(_,{className:$("h-6 w-6 shrink-0",ie&&"scale-x-[-1] transform")})}))]})}))]})),Oe&&n(L,{error:Oe,className:"mt-3"})]}))}))}));W.displayName="Input";export{W as default};
@@ -1 +1 @@
1
- import{__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as e,jsxs as o,Fragment as r}from"react/jsx-runtime";import{useState as n,useRef as i,useEffect as s}from"react";import{usePickaxeContext as u}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as m}from"../Addons/Auth/hooks/useAuthContext.js";import{useDimensionContext as c}from"../../../hooks/pickaxe/useDimensionContext.js";import{useDocument as l}from"../Addons/Document/hooks/useDocument.js";import h from"./History/index.js";import a from"./Input.js";const d=()=>{const{deploymentType:d,isNewChat:p}=u(),{isSent:f}=m(),{width:x,height:j,setDimension:b}=c(),{setDocuments:v}=l(),[k,D]=n(0),[g,A]=n(!1),I=i(null),w=i(null),[y,C]=n(null),[F,S]=n(!1),H="chat-input"===d&&p&&!f;return s((()=>()=>{v([])}),[]),s((()=>{if(!I.current)return;const t=new ResizeObserver((t=>{for(const e of t){const{width:t,height:o}=e.contentRect;b(parseInt(t.toFixed(0)),parseInt(o.toFixed(0)))}}));return t.observe(I.current),()=>{t.disconnect()}}),[I.current]),e("div",Object.assign({ref:I,className:"relative flex h-full w-full flex-col items-center"},{children:H?e(a,{}):o(r,{children:[e(h,{additionalScrollHeight:k,isForceHideInfo:j<=545||x<=350||g,isInputFocused:g,onSubmit:e=>t(void 0,void 0,void 0,(function*(){w.current&&w.current.onSubmit(e)})),smitheryAuthData:y,resubmitPrompt:()=>{C(null),S(!0)}}),e(a,{ref:w,onFocus:()=>A(!0),onBlur:()=>A(!1),onInputHeightChange:D,initSmitheryAuthData:t=>C(t),resubmitPrompt:F})]})}))};export{d as default};
1
+ import{__awaiter as t}from"../../../_virtual/_tslib.js";import{jsxs as e,jsx as o,Fragment as r}from"react/jsx-runtime";import{useState as n,useRef as i,useEffect as s}from"react";import{usePickaxeContext as a}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as c}from"../Addons/Auth/hooks/useAuthContext.js";import{useDimensionContext as l}from"../../../hooks/pickaxe/useDimensionContext.js";import{useDocument as u}from"../Addons/Document/hooks/useDocument.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import d from"./History/index.js";import p from"./Input.js";import f from"../../Icons/attach-vertical.svg.js";import h from"../../../common/cn.js";const g=()=>{const{deploymentType:g,isNewChat:b,setIsNewChat:v}=a(),{isSent:x}=c(),{width:j,height:D,setDimension:y}=l(),{setDocuments:k,onFileUpload:w}=u(),A=m(),[I,N]=n(0),[F,O]=n(!1),[P,S]=n(!1),C=i(null),H=i(null),T=i(0),[z,R]=n(null),[_,B]=n(!1),E="chat-input"===g&&b&&!x;s((()=>()=>{k([])}),[]),s((()=>{if(!C.current)return;const t=new ResizeObserver((t=>{for(const e of t){const{width:t,height:o}=e.contentRect;y(parseInt(t.toFixed(0)),parseInt(o.toFixed(0)))}}));return t.observe(C.current),()=>{t.disconnect()}}),[C.current]);return e("div",Object.assign({ref:C,className:"relative flex h-full w-full flex-col items-center",onDragEnter:t=>{t.preventDefault(),t.stopPropagation(),T.current+=1,t.dataTransfer.items&&t.dataTransfer.items.length>0&&S(!0)},onDragLeave:t=>{t.preventDefault(),t.stopPropagation(),T.current-=1,0===T.current&&S(!1)},onDragOver:t=>{t.preventDefault(),t.stopPropagation()},onDrop:e=>t(void 0,void 0,void 0,(function*(){e.preventDefault(),e.stopPropagation(),S(!1),T.current=0;const t=Array.from(e.dataTransfer.files||[]);t.length>0&&(v(!1),yield w(t))}))},{children:[P&&e("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[o("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:o(f,{className:"h-10 w-10"})})),o("h3",Object.assign({className:h(A.h3,"mt-6 font-semibold text-c-primary text-black")},{children:"Drop files to upload"})),o("p",Object.assign({className:h(A.b2,"mt-2 opacity-60 text-black")},{children:"Add anything to the conversation"}))]})),E?o(p,{}):e(r,{children:[o(d,{additionalScrollHeight:I,isForceHideInfo:D<=545||j<=350||F,isInputFocused:F,onSubmit:e=>t(void 0,void 0,void 0,(function*(){H.current&&H.current.onSubmit(e)})),smitheryAuthData:z,resubmitPrompt:()=>{R(null),B(!0)}}),o(p,{ref:H,onFocus:()=>O(!0),onBlur:()=>O(!1),onInputHeightChange:N,initSmitheryAuthData:t=>R(t),resubmitPrompt:_})]})]}))};export{g as default};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as o}from"react/jsx-runtime";import{useState as t}from"react";import{usePickaxeContext as s}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as r}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as n}from"../../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as a}from"../../../../hooks/studio/useStyleFontSize.js";import{encode as i}from"@nem035/gpt-3-encoder";import l from"../../../Core/Textarea.js";import c from"../../../../common/cn.js";const m=({field:m,update:p})=>{const{styles:d,colors:h,isRtl:g}=s(),{setError:u}=r(),[b,x]=t(!1),f=a(),j=n();return e("div",Object.assign({className:"group relative flex flex-col gap-y-1",dir:g?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex flex-col gap-y-2"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[o("p",Object.assign({className:c(f.b3,"font-semibold opacity-70")},{children:m.main})),m.isRequired&&o("span",Object.assign({className:"select-none font-semibold",style:{color:h.accent}},{children:"*"}))]})),o(l,{className:c(f.i1,"rounded-sm border border-transparent px-4 py-3 duration-300 ease-in-out transition-all placeholder:font-semilight",m.maxLength<10&&"max-w-[400px]","block"===d.formFieldStyle&&"shadow hover:shadow-none"),style:j,placeholder:m.placeholder,rows:1,value:m.input,tabIndex:m.order,onChange:e=>{u("");const o=i(e).length;p(Object.assign(Object.assign({},m),{input:e,length:o}))},onFocus:()=>x(!0),onBlur:()=>x(!1),onPaste:e=>{if(e.clipboardData.getData("text").length<1e3)return;const o=e.target;setTimeout((()=>{const e=o.getBoundingClientRect().bottom+window.scrollY;window.scrollTo({top:e,behavior:"smooth"})}),250)}})]})),o("div",Object.assign({className:"pointer-events-none absolute bottom-0 right-0 p-1 px-2"},{children:e("p",Object.assign({className:c(f.b4,"font-semibold opacity-20 opacity-0 group-hover:opacity-100 group-hover:duration-200",m.length>m.maxLength&&"text-c-red opacity-100",b&&"opacity-100")},{children:[m.length,"/",m.maxLength]}))}))]}))};export{m as default};
1
+ import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as o}from"react/jsx-runtime";import{useState as s,useRef as n,useEffect as r}from"react";import"../../../../node_modules/.pnpm/regenerator-runtime@0.14.1/node_modules/regenerator-runtime/runtime.js";import i,{useSpeechRecognition as a}from"react-speech-recognition";import{usePickaxeContext as c}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as l}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as p}from"../../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../../hooks/studio/useStyleFontSize.js";import{useHover as u}from"../../../../hooks/core/useHover.js";import d from"../../../Core/Textarea.js";import g from"../../../Icons/microphone.svg.js";import h from"../../../Icons/stop.svg.js";import b from"../../../../common/cn.js";const f=({field:f,update:x})=>{var j;const{styles:v,colors:y,isRtl:N,pickaxe:O,locale:k}=c(),{setError:w}=l(),[C,S]=s(!1),L=m(),R=p(),{transcript:T,listening:I,resetTranscript:_,browserSupportsSpeechRecognition:z}=a(),F=n(""),H=u(),{isHover:$}=H,B=e(H,["isHover"]),D=z&&(null==O?void 0:O.enablevoicetotext),P=e=>{w("");const t=e.length;x(Object.assign(Object.assign({},f),{input:e,length:t}))};r((()=>{if(!I)return;const e=F.current?`${F.current} `:"";P(`${e}${T}`)}),[T,I]);return t("div",Object.assign({className:"group relative flex flex-col gap-y-1",dir:N?"rtl":"ltr"},{children:[t("div",Object.assign({className:"flex flex-col gap-y-2"},{children:[t("div",Object.assign({className:"flex items-center gap-1"},{children:[o("p",Object.assign({className:b(L.b3,"font-semibold opacity-70")},{children:f.main})),f.isRequired&&o("span",Object.assign({className:"select-none font-semibold",style:{color:y.accent}},{children:"*"}))]})),t("div",Object.assign({className:"relative w-full"},{children:[I&&t("div",Object.assign({className:b("absolute top-3.5 z-10 flex select-none items-center gap-x-2 pointer-events-none",N?"right-4":"left-4")},{children:[o("span",{className:"h-2 w-2 animate-pulse rounded-full",style:{backgroundColor:null!==(j=y.accent)&&void 0!==j?j:"#ff0000"}}),o("span",Object.assign({className:"text-sm font-semilight",style:{color:y.text+"90"}},{children:"Listening..."}))]})),o(d,{className:b(L.i1,"rounded-sm border border-transparent py-3 duration-300 ease-in-out transition-all placeholder:font-semilight w-full",N?D?"pl-10 pr-4":"px-4":D?"pl-4 pr-10":"px-4",f.maxLength<10&&"max-w-[400px]","block"===v.formFieldStyle&&"shadow hover:shadow-none",I&&"caret-transparent"),style:Object.assign(Object.assign({},R),I&&{color:"transparent"}),placeholder:I?"":f.placeholder,rows:1,value:f.input,tabIndex:f.order,onChange:P,onFocus:()=>S(!0),onBlur:()=>S(!1),onPaste:e=>{if(e.clipboardData.getData("text").length<1e3)return;const t=e.target;setTimeout((()=>{const e=t.getBoundingClientRect().bottom+window.scrollY;window.scrollTo({top:e,behavior:"smooth"})}),250)}}),D&&o("div",Object.assign({className:b("absolute top-2 z-20",N?"left-2":"right-2")},{children:o("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:I?y.accent:$?y.accent+"10":void 0,color:I?y.accentText:$?y.accent:y.accent+"80"},onClick:()=>{I?i.stopListening():(F.current=f.input||"",_(),i.startListening({continuous:!0,interimResults:!0,language:k||"en-US"}),S(!0))}},B,{type:"button"},{children:I?o(h,{className:"h-4 w-4 shrink-0"}):o(g,{className:"h-5 w-5 shrink-0"})}))}))]}))]})),o("div",Object.assign({className:"pointer-events-none absolute bottom-0 right-0 p-1 px-2"},{children:t("p",Object.assign({className:b(L.b4,"font-semibold opacity-20 opacity-0 group-hover:opacity-100 group-hover:duration-200",f.length>f.maxLength&&"text-c-red opacity-100",C&&"opacity-100")},{children:[f.length,"/",f.maxLength]}))}))]}))};export{f as default};
@@ -1,4 +1,5 @@
1
1
  import type { MemoryStoredQuestionField } from "../../../../types/form";
2
+ import "regenerator-runtime/runtime";
2
3
  interface InputProps {
3
4
  field: MemoryStoredQuestionField;
4
5
  update: (questions: MemoryStoredQuestionField) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",