@pickaxeproject/react 5.3.1 → 5.5.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.
- package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/cjs/components/Pickaxe/Chat/index.js +1 -1
- package/dist/cjs/components/Pickaxe/Form/Questions/Input.js +1 -1
- package/dist/cjs/components/Pickaxe/Form/Questions/Option.js +1 -1
- package/dist/cjs/components/Pickaxe/Form/Questions/index.js +1 -1
- package/dist/cjs/src/components/Pickaxe/Form/Questions/Input.d.ts +1 -0
- package/dist/cjs/src/types/form.d.ts +2 -0
- package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/esm/components/Pickaxe/Chat/index.js +1 -1
- package/dist/esm/components/Pickaxe/Form/Questions/Input.js +1 -1
- package/dist/esm/components/Pickaxe/Form/Questions/Option.js +1 -1
- package/dist/esm/components/Pickaxe/Form/Questions/index.js +1 -1
- package/dist/esm/src/components/Pickaxe/Form/Questions/Input.d.ts +1 -0
- package/dist/esm/src/types/form.d.ts +2 -0
- package/package.json +1 -1
|
@@ -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 _=N(n);const I=s.forwardRef((({resubmitPrompt:N,onFocus:I,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,_e]=s.useState(""),[Ie,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="undefined"!=typeof window?window.location.hostname:"",ot="undefined"!=typeof window?window.location.href:"",at="undefined"!=typeof window&&window.self!==window.top,lt=it.includes("pickaxe.co")&&!ot.includes("https://studio.pickaxe.co/_embed")&&!at,ct=null===(R=null==J?void 0:J.documentuploadtype)||void 0===R?void 0:R.startsWith("enduserupload"),ut=Je&&(null==J?void 0:J.enablevoicetotext),dt="chat-input"===B&&z&&!re,ft="chat-input"===B&&Q&&ne&&re,pt=null!==(P=null==J?void 0:J.placeholdertext)&&void 0!==P?P:G?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",gt=Ie||Ae,ht=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&&!dt)))))}),[J,z,Y,dt,Ce.data,Ce.isLoading]),mt=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:vt}))),s.useEffect((()=>{ee(ht)}),[ht]),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;vt(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} `:"";_e(`${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||Ie||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||pt,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,Ie,pt]);const vt=(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),_e(""),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(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}})),lt&&{credentials:"include"})),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 ft?null:t.jsx("div",Object.assign({className:C.default("flex w-full flex-shrink-0 flex-col items-center",!dt&&"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",gt&&"mb-12",We&&"text-transparent"),value:Ne,placeholder:pt,onChange:e=>{if(_e(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||vt()))},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))}))},I&&{onFocus:I},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",gt?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!gt&&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:_.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:[ct&&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"})]})),ut&&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?_.default.stopListening():(Re.current=Ne,Be(),_.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||mt?V.accent:V.accent+"10",color:Ke||mt?V.accentText:V.accent+"80"},disabled:!mt,onClick:()=>vt()},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"})]}))}))}));I.displayName="Input",exports.default=I;
|
|
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"),
|
|
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"),
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/studio/useStyleFontSize.js"),i=require("react"),r=require("./Dropdown.js"),a=require("../../../../common/cn.js");exports.default=({field:c,update:l})=>{const{colors:o,isRtl:u,translations:d}=s.usePickaxeContext(),{setError:p}=t.useResponseContext(),x=n.useStyleFontSize(),j=i.useRef(null),b=i.useMemo((()=>c.example.split("S3P32X")),[c.example]),[g,m]=i.useState((()=>{const e=b.includes(c.input);return c.allowOther&&c.input&&!e?c.input:""})),f=i.useMemo((()=>!!c.allowOther&&(!b.includes(c.input)&&""!==c.input)),[c.allowOther,c.input,b]);return e.jsxs("div",Object.assign({className:"flex flex-col gap-y-3",dir:u?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:a.default(x.b3,"font-semibold opacity-70")},{children:c.main})),c.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:o.error}},{children:"*"}))]})),e.jsx(r.default,Object.assign({id:c.id.replace(/[^A-Za-z]+/g,""),value:c.input,placeholder:"Select an option",closeOnSelect:!1,maxToken:c.maxLength,isDropdown:c.isDropdown},{children:e.jsxs("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[b.map(((s,t)=>e.jsxs("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{p(""),l(Object.assign(Object.assign({},c),{input:e}))})(s)},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:c.input===s?o.accent:o.accent+"80"},c.input===s&&{backgroundColor:o.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",c.input===s&&"opacity-100"),style:{backgroundColor:o.accentText}})})),e.jsx("p",Object.assign({className:a.default(x.b2,"select-none")},{children:s}))]}),t))),c.allowOther&&e.jsxs("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{p(""),l(Object.assign(Object.assign({},c),{input:g})),setTimeout((()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()}),0)}},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:f?o.accent:o.accent+"80"},f&&{backgroundColor:o.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",f&&"opacity-100"),style:{backgroundColor:o.accentText}})})),e.jsxs("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e.jsxs("p",Object.assign({className:a.default(x.b2,"select-none opacity-80 min-w-fit")},{children:[(null==d?void 0:d.other)||"Other",":"]})),e.jsx("input",{ref:j,type:"text",className:a.default(x.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:f?o.accent:"rgba(0,0,0,0.2)"},value:g,onChange:e=>{return s=e.target.value,p(""),m(s),void l(Object.assign(Object.assign({},c),{input:s}));var s},onFocus:()=>{f||l(Object.assign(Object.assign({},c),{input:g}))},placeholder:"Type your answer..."})]}))]}))]}))}))]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../Core/ErrorAlert.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../Core/ErrorAlert.js"),a=require("../../common/PickaxeUpgradeCard.js"),o=require("./Input.js"),u=require("./Option.js"),n=require("./Document.js"),l=require("./Checkbox.js"),d=require("./Submit.js");exports.default=()=>{const{pickaxe:p,translations:c}=r.usePickaxeContext(),{error:x}=s.useResponseContext(),[m,f]=t.useState([]),[j,h]=t.useState([]),g=e=>{f((t=>t.map((t=>t.id===e.id?e:t))))},q=t.useMemo((()=>j),[j]);return t.useEffect((()=>{if(!p)return;if(!p._questions)return;const e=new Date("2025-10-16T23:10:00Z"),t=!p.updatedAt||new Date(p.updatedAt)<e,r=p._questions.map(((e,r)=>{var s;let i="";const a="string"==typeof e.allowOther?"true"===e.allowOther:!!e.allowOther;if("Knowledge Upload"===e.type||"userinput:documentupload"===e.id)i="";else if("Multiple Choice"===e.type||"multiple"===e.type){const t=e.example.split("S3P32X");t.includes(i)||a||(i=t[0])}let o=e.secondary||"";return t&&(o=e.secondary||("Knowledge Upload"===e.type?null!==(s=null==c?void 0:c["form-doc-placeholder"])&&void 0!==s?s:"Paste a website/video link or drag a file":e.example)||""),Object.assign(Object.assign({order:r+1,id:e.id,type:e.type,main:e.main,example:e.example,input:i,length:0,maxLength:parseInt(e.answerlength),placeholder:o,allowOther:a},e.isRequired&&{isRequired:"string"==typeof e.isRequired?"true"===e.isRequired:e.isRequired}),e.isDropdown&&{isDropdown:"string"==typeof e.isDropdown?"true"===e.isDropdown:e.isDropdown})}));f(r),h(r)}),[p]),e.jsxs("div",Object.assign({className:"mt-8 flex flex-col gap-y-8 max-lg:px-4"},{children:[m.map(((r,s)=>"Multiple Choice"===r.type?e.jsx(t.Fragment,{children:e.jsx(u.default,{field:r,update:g})},s):"Checkbox"===r.type?e.jsx(t.Fragment,{children:e.jsx(l.default,{field:r,update:g})},s):"userinput:documentupload"===r.id?e.jsx(t.Fragment,{children:e.jsx(n.default,{field:r,update:g})},s):e.jsx(t.Fragment,{children:e.jsx(o.default,{field:r,update:g})},s))),e.jsx(i.default,{error:x}),e.jsx(a.default,{}),e.jsx(d.default,{questions:m,update:g,resetQuestions:()=>f(q)})]}))};
|
|
@@ -8,6 +8,7 @@ export type PickaxeQuestion = {
|
|
|
8
8
|
type: PickaxeQuestionType;
|
|
9
9
|
isRequired?: boolean;
|
|
10
10
|
isDropdown?: boolean;
|
|
11
|
+
allowOther?: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type MemoryStoredQuestionField = {
|
|
13
14
|
order: number;
|
|
@@ -22,4 +23,5 @@ export type MemoryStoredQuestionField = {
|
|
|
22
23
|
documentId?: string;
|
|
23
24
|
isRequired?: boolean;
|
|
24
25
|
isDropdown?: boolean;
|
|
26
|
+
allowOther?: boolean;
|
|
25
27
|
};
|
|
@@ -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 p}from"react-speech-recognition";import{usePickaxeContext as m}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 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 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}=m(),{token:ue,isLoggedOut:pe,isSent:me}=y(),{messages:fe,limits:ge,isGenerating:he,setMessages:ve,setStatus:be,setLimitData:ye,setError:xe}=f(),{documents:je,isUploading:we,documentError:Oe,onFileUpload:ke,setDocuments:Se,setDocumentError:Ne}=x(),{scrollStartSession:Ce,scrollEndSession:Ie,scrollToBottom:Ee}=j({auto:!0}),{artifacts:Ae,currentPopupType:_e,setArtifacts:Te,setCurrentArtifact:Pe}=w(),{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}=p(),[et]=k("(max-width: 480px)"),tt=O(),{isHover:nt}=tt,st=e(tt,["isHover"]),ot=O(),{isHover:rt}=ot,it=e(ot,["isHover"]),at=O(),{isHover:lt}=at,ct=e(at,["isHover"]),[dt,ut]=i(!1),pt=h(),mt=g(),ft="undefined"!=typeof window?window.location.hostname:"",gt="undefined"!=typeof window?window.location.href:"",ht="undefined"!=typeof window&&window.self!==window.top,vt=ft.includes("pickaxe.co")&&!gt.includes("https://studio.pickaxe.co/_embed")&&!ht,bt=null===(U=null==Z?void 0:Z.documentuploadtype)||void 0===U?void 0:U.startsWith("enduserupload"),yt=Ze&&(null==Z?void 0:Z.enablevoicetotext),xt="chat-input"===Y&&oe&&!me,jt="chat-input"===Y&&ie&&pe&&me,wt=null!==(M=null==Z?void 0:Z.placeholdertext)&&void 0!==M?M:re?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",Ot=We||He,kt=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&&!xt)))))}),[Z,oe,ae,xt,Re.data,Re.isLoading]),St=l((()=>{if(he||we)return!1;const e=je.length>0&&je.every((e=>"finished"===e.status));return!(!Le.trim()&&!e)&&je.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[he,we,Le,je]);c(J,(()=>({onSubmit:Nt}))),d((()=>{ce(kt)}),[kt]),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;Nt(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")||je.length?e=!0:Le.trim()||(e=!1),Be(e)})()}),[Le,je]),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||wt,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,wt]);const Nt=(e,n=!1)=>t(void 0,void 0,void 0,(function*(){var t,s,o;try{if(he||we)return;const r=je.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;xe(""),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 p=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:i}),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}})),vt&&{credentials:"include"})),m=yield p.json();if(!m.success)throw new Error(m.error||"Failed to start generation");const f=m.submissionId;be("streaming"),ze.current=new AbortController;const g=u.length-1,h=[];let v=[...null!=Ae?Ae:[]],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=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 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="",h.push({type:"text",content:"",isVisible:null===(t=s.isVisible)||void 0===t||t});else if("text-delta"===s.type)x+=s.delta,h[h.length-1].content=x;else if("text-end"===s.type)x="";else if("reasoning-start"===s.type)x="",h.push({type:"reasoning",content:"",isVisible:null===(n=s.isVisible)||void 0===n||n});else if("reasoning-delta"===s.type)x+=s.delta,h[h.length-1].content=x;else if("reasoning-end"===s.type)x="";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);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=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]):xe(t)}finally{Ee(),be("idle"),Ie(),Me.current=null}}));return jt?null:n("div",Object.assign({className:$("flex w-full flex-shrink-0 flex-col items-center",!xt&&"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({},mt),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&&je.length>0&&n(P,{className:"p-4 pb-0",isDisabled:he}),n(D,Object.assign({ref:Ve,className:$(pt.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",Ot&&"mb-12",Qe&&"text-transparent"),value:Le,placeholder:wt,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||he||Nt()))},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",Ot?"mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!Ot&&mt.backgroundColor&&{backgroundColor:mt.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:[bt&&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:we||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"})]})),yt&&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||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||St?te.accent:te.accent+"10",color:nt||St?te.accentText:te.accent+"80"},disabled:!St,onClick:()=>Nt()},st,{children:n(A,{className:$("h-6 w-6 shrink-0",re&&"scale-x-[-1] transform")})}))]})}))]})),Oe&&n(R,{error:Oe,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{
|
|
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
|
|
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 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as
|
|
1
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{usePickaxeContext as s}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useRef as r,useMemo as o,useState as a}from"react";import c from"./Dropdown.js";import l from"../../../../common/cn.js";const p=({field:p,update:d})=>{const{colors:u,isRtl:m,translations:b}=s(),{setError:g}=n(),h=i(),f=r(null),x=o((()=>p.example.split("S3P32X")),[p.example]),[j,O]=a((()=>{const e=x.includes(p.input);return p.allowOther&&p.input&&!e?p.input:""})),y=o((()=>!!p.allowOther&&(!x.includes(p.input)&&""!==p.input)),[p.allowOther,p.input,x]);return e("div",Object.assign({className:"flex flex-col gap-y-3",dir:m?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[t("p",Object.assign({className:l(h.b3,"font-semibold opacity-70")},{children:p.main})),p.isRequired&&t("span",Object.assign({className:"select-none font-semibold",style:{color:u.error}},{children:"*"}))]})),t(c,Object.assign({id:p.id.replace(/[^A-Za-z]+/g,""),value:p.input,placeholder:"Select an option",closeOnSelect:!1,maxToken:p.maxLength,isDropdown:p.isDropdown},{children:e("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[x.map(((s,n)=>e("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{g(""),d(Object.assign(Object.assign({},p),{input:e}))})(s)},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:p.input===s?u.accent:u.accent+"80"},p.input===s&&{backgroundColor:u.accent})},{children:t("div",{className:l("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",p.input===s&&"opacity-100"),style:{backgroundColor:u.accentText}})})),t("p",Object.assign({className:l(h.b2,"select-none")},{children:s}))]}),n))),p.allowOther&&e("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{g(""),d(Object.assign(Object.assign({},p),{input:j})),setTimeout((()=>{var e;return null===(e=f.current)||void 0===e?void 0:e.focus()}),0)}},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:y?u.accent:u.accent+"80"},y&&{backgroundColor:u.accent})},{children:t("div",{className:l("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",y&&"opacity-100"),style:{backgroundColor:u.accentText}})})),e("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e("p",Object.assign({className:l(h.b2,"select-none opacity-80 min-w-fit")},{children:[(null==b?void 0:b.other)||"Other",":"]})),t("input",{ref:f,type:"text",className:l(h.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:y?u.accent:"rgba(0,0,0,0.2)"},value:j,onChange:e=>{return t=e.target.value,g(""),O(t),void d(Object.assign(Object.assign({},p),{input:t}));var t},onFocus:()=>{y||d(Object.assign(Object.assign({},p),{input:j}))},placeholder:"Type your answer..."})]}))]}))]}))}))]}))};export{p as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as o,useMemo as
|
|
1
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as o,useMemo as r,useEffect as i,Fragment as p}from"react";import{usePickaxeContext as s}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import a from"../../../Core/ErrorAlert.js";import l from"../../common/PickaxeUpgradeCard.js";import d from"./Input.js";import u from"./Option.js";import m from"./Document.js";import c from"./Checkbox.js";import f from"./Submit.js";const h=()=>{const{pickaxe:h,translations:x}=s(),{error:g}=n(),[w,y]=o([]),[j,k]=o([]),q=e=>{y((t=>t.map((t=>t.id===e.id?e:t))))},C=r((()=>j),[j]);return i((()=>{if(!h)return;if(!h._questions)return;const e=new Date("2025-10-16T23:10:00Z"),t=!h.updatedAt||new Date(h.updatedAt)<e,o=h._questions.map(((e,o)=>{var r;let i="";const p="string"==typeof e.allowOther?"true"===e.allowOther:!!e.allowOther;if("Knowledge Upload"===e.type||"userinput:documentupload"===e.id)i="";else if("Multiple Choice"===e.type||"multiple"===e.type){const t=e.example.split("S3P32X");t.includes(i)||p||(i=t[0])}let s=e.secondary||"";return t&&(s=e.secondary||("Knowledge Upload"===e.type?null!==(r=null==x?void 0:x["form-doc-placeholder"])&&void 0!==r?r:"Paste a website/video link or drag a file":e.example)||""),Object.assign(Object.assign({order:o+1,id:e.id,type:e.type,main:e.main,example:e.example,input:i,length:0,maxLength:parseInt(e.answerlength),placeholder:s,allowOther:p},e.isRequired&&{isRequired:"string"==typeof e.isRequired?"true"===e.isRequired:e.isRequired}),e.isDropdown&&{isDropdown:"string"==typeof e.isDropdown?"true"===e.isDropdown:e.isDropdown})}));y(o),k(o)}),[h]),e("div",Object.assign({className:"mt-8 flex flex-col gap-y-8 max-lg:px-4"},{children:[w.map(((e,o)=>"Multiple Choice"===e.type?t(p,{children:t(u,{field:e,update:q})},o):"Checkbox"===e.type?t(p,{children:t(c,{field:e,update:q})},o):"userinput:documentupload"===e.id?t(p,{children:t(m,{field:e,update:q})},o):t(p,{children:t(d,{field:e,update:q})},o))),t(a,{error:g}),t(l,{}),t(f,{questions:w,update:q,resetQuestions:()=>y(C)})]}))};export{h as default};
|
|
@@ -8,6 +8,7 @@ export type PickaxeQuestion = {
|
|
|
8
8
|
type: PickaxeQuestionType;
|
|
9
9
|
isRequired?: boolean;
|
|
10
10
|
isDropdown?: boolean;
|
|
11
|
+
allowOther?: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type MemoryStoredQuestionField = {
|
|
13
14
|
order: number;
|
|
@@ -22,4 +23,5 @@ export type MemoryStoredQuestionField = {
|
|
|
22
23
|
documentId?: string;
|
|
23
24
|
isRequired?: boolean;
|
|
24
25
|
isDropdown?: boolean;
|
|
26
|
+
allowOther?: boolean;
|
|
25
27
|
};
|