@pickaxeproject/react 3.7.0 → 3.7.1

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"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../../../hooks/pickaxe/useSubmit.js"),c=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),f=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),p=require("../../../common/documents.js"),g=require("eventsource-parser"),v=require("../../Icons/attach-vertical.svg.js"),h=require("../../Icons/arrow-right.svg.js"),x=require("../Addons/IceBreaker/index.js"),j=require("../Addons/Document/List.js"),b=require("../../Core/Textarea.js"),y=require("../../Core/ErrorAlert.js"),k=require("../../../common/error.js"),O=require("../../../common/cn.js");exports.default=({isFocused:w,onFocus:S,onBlur:I})=>{var q;const{formId:N,chatId:A,userId:C,studioUserId:_,embedUserId:D,deploymentId:E,deploymentType:B,pickaxe:T,styles:F,colors:U,responsiveBy:H,isNewChat:J,isRtl:R,isEmailLogin:L,setIsNewChat:M,setIsShowIceBreaker:P,onGenerateComplete:W}=i.usePickaxeContext(),{token:z,isLoggedOut:G,isSent:K}=l.useAuthContext(),{messages:Q,status:V,limits:X,isGenerating:Y,setMessages:Z,setStatus:$,setLimitData:ee,setError:te}=r.useResponseContext(),{documents:se,isUploading:ie,isImageUploadAllowed:re,documentError:ne,onFileUpload:oe,setDocuments:ae,setDocumentError:le}=c.useDocument(),{scrollStartSession:de,scrollEndSession:ce,scrollToBottom:ue}=u.useScroll({auto:!0}),{artifacts:fe,currentPopupType:me,setArtifacts:pe,setCurrentArtifact:ge}=f.useArtifactContext(),ve=a.useConversation(),he=d.useSubmit(),[xe,je]=s.useState(""),be=s.useRef(null),ye=m.useHover(),{isHover:ke}=ye,Oe=e.__rest(ye,["isHover"]),we=m.useHover(),{isHover:Se}=we,Ie=e.__rest(we,["isHover"]),qe=o.useStyleFontSize(),Ne=n.useStyleInput(),Ae="chat-input"===B&&J&&!K,Ce="chat-input"===B&&L&&G&&K,_e=s.useMemo((()=>{var e,t,s;return!!J&&(!!T&&(!ve.isLoading&&(!((null!==(t=null===(e=ve.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=T.icebreakers)||void 0===s?void 0:s.length))))}),[T,J,ve.data,ve.isLoading]),De=s.useMemo((()=>{if(Y||ie)return!1;return!!xe.trim()&&se.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Y,ie,xe,se]),Ee=t=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==V||ie)return;const e=null!=t?t:xe;if(!e)return;te(""),le(""),ee(null),je(""),M(!1),$("fetching"),de(),ue();const s=se.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),i="enduserupload"===(null==T?void 0:T.documentuploadtype)&&s.length>0,r=[...Array.from(Q),Object.assign({id:Q.length+1,role:"user",content:e},i&&{documentIds:s})];Z(r),ue(),i&&ae([]);const n=(yield he.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:N,responseId:A,value:e},i&&{documentIds:s}),C&&{userId:C}),_&&{studioUserId:_}),D&&{embedUserId:D}),z&&{studioSessionToken:z}),E&&{deploymentId:E}))).body;if(!n)throw new Error("Streaming error");const o=r.length,a=new TextDecoder,l=n.getReader();let d="",c=!0,u=!1,f=[...null!=fe?fe:[]];const m=g.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=t,Z([...r.slice(0,o),{id:Q.length+1,role:"assistant",content:d}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),pe(f),me.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),pe(f),me.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),pe(f),me.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");f=f.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),pe(f)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);pe(f.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);te(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(c=!1)}});for(;c;){const{value:e,done:t}=yield l.read();if(t){c=!1;break}const s=a.decode(e);s&&(u||($("streaming"),u=!0),m.feed(s))}null==W||W(A)}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(X).find((([e])=>t.includes(e)));s?ee(s[1]):te(t)}finally{ue(),$("idle"),ce()}}));return s.useEffect((()=>{P(_e)}),[_e]),Ce?null:t.jsx("div",Object.assign({className:O.default("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!Ae&&"px-4 pb-4"),dir:R?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!Ae&&t.jsx("div",Object.assign({className:O.default("absolute bottom-full",R?"left-0":"right-0")},{children:t.jsx("div",Object.assign({className:O.default("flex flex-col gap-2 pb-4 px-2",R?"justify-start":"justify-end","viewport"===H?R?"min-[767px]:items-start":"min-[767px]:items-end":R?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:_e&&!w&&t.jsx(x.default,{data:(null==T?void 0:T.icebreakers)||[],onSend:Ee})}))})),t.jsxs("div",Object.assign({className:O.default("flex flex-col gap-y-3 px-4 py-3","block"===F.formFieldStyle&&"shadow"),style:Ne},{children:["idle"===V&&se.length>0&&t.jsx(j.default,{isDisabled:"idle"!==V}),t.jsxs("div",Object.assign({className:O.default("flex items-end gap-x-2",R&&"flex-row-reverse")},{children:[t.jsx(b.default,Object.assign({className:O.default(qe.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!xe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",R?"text-right":"text-left"),value:xe,placeholder:null!==(q=null==T?void 0:T.placeholdertext)&&void 0!==q?q:R?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>je(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ie||"idle"!==V||Ee()))}},S&&{onFocus:S},I&&{onBlur:I},{dir:R?"rtl":"ltr"})),t.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==T?void 0:T.documentuploadtype)&&t.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Se?U.accent+"10":void 0,color:Se?U.accent:U.accent+"80"},disabled:ie||"idle"!==V,onClick:()=>{var e;return null===(e=be.current)||void 0===e?void 0:e.click()}},Ie,{children:[t.jsx("input",{id:"file-upload",ref:be,type:"file",accept:[...p.allowedFileMimeTypes,...re?p.allowedImageMimeTypes:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){M(!1),yield oe(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),t.jsx("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:ke||De?U.accent:U.accent+"10",color:ke||De?U.accentText:U.accent+"80"},disabled:"idle"!==V||ie,onClick:()=>Ee()},Oe,{children:t.jsx(h.default,{className:O.default("h-6 w-6 shrink-0",R&&"transform scale-x-[-1]")})}))]}))]}))]})),ne&&t.jsx(y.default,{error:ne,className:"mt-3"})]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../../../hooks/pickaxe/useSubmit.js"),u=require("../Addons/Document/hooks/useDocument.js"),c=require("../Addons/Scroll/hooks/useScroll.js"),f=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),p=require("../../../common/documents.js"),v=require("eventsource-parser"),h=require("../../Icons/attach-vertical.svg.js"),g=require("../../Icons/arrow-right.svg.js"),x=require("../Addons/IceBreaker/index.js"),j=require("../Addons/Document/List.js"),b=require("../../Core/Textarea.js"),y=require("../../Core/ErrorAlert.js"),k=require("../../../common/error.js"),O=require("../../../common/cn.js");exports.default=({isFocused:w,onFocus:S,onBlur:I})=>{var q,N,A;const{formId:C,chatId:_,userId:D,studioUserId:E,embedUserId:B,deploymentId:T,deploymentType:F,pickaxe:U,styles:H,colors:J,responsiveBy:R,isNewChat:W,isRtl:L,isEmailLogin:M,setIsNewChat:P,setIsShowIceBreaker:z,onGenerateComplete:G}=i.usePickaxeContext(),{token:K,isLoggedOut:Q,isSent:V}=l.useAuthContext(),{messages:X,status:Y,limits:Z,isGenerating:$,setMessages:ee,setStatus:te,setLimitData:se,setError:ie}=r.useResponseContext(),{documents:re,isUploading:ne,isImageUploadAllowed:oe,documentError:ae,onFileUpload:le,setDocuments:de,setDocumentError:ue}=u.useDocument(),{scrollStartSession:ce,scrollEndSession:fe,scrollToBottom:me}=c.useScroll({auto:!0}),{artifacts:pe,currentPopupType:ve,setArtifacts:he,setCurrentArtifact:ge}=f.useArtifactContext(),xe=a.useConversation(),je=d.useSubmit(),[be,ye]=s.useState(""),ke=s.useRef(null),Oe=m.useHover(),{isHover:we}=Oe,Se=e.__rest(Oe,["isHover"]),Ie=m.useHover(),{isHover:qe}=Ie,Ne=e.__rest(Ie,["isHover"]),Ae=o.useStyleFontSize(),Ce=n.useStyleInput(),_e="chat-input"===F&&W&&!V,De="chat-input"===F&&M&&Q&&V,Ee=s.useMemo((()=>{var e,t,s;return!!W&&(!!U&&(!xe.isLoading&&(!((null!==(t=null===(e=xe.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=U.icebreakers)||void 0===s?void 0:s.length))))}),[U,W,xe.data,xe.isLoading]),Be=s.useMemo((()=>{if($||ne)return!1;return!!be.trim()&&re.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[$,ne,be,re]),Te=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;try{if("idle"!==Y||ne)return;const i=null!=t?t:be;if(!i)return;ie(""),ue(""),se(null),ye(""),P(!1),te("fetching"),ce(),me();const r=re.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),n=null!==(s=null===(e=null==U?void 0:U.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==s&&s&&r.length>0,o=[...Array.from(X),Object.assign({id:X.length+1,role:"user",content:i},n&&{documentIds:r})];ee(o),me(),n&&de([]);const a=(yield je.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:C,responseId:_,value:i},n&&{documentIds:r}),D&&{userId:D}),E&&{studioUserId:E}),B&&{embedUserId:B}),K&&{studioSessionToken:K}),T&&{deploymentId:T}))).body;if(!a)throw new Error("Streaming error");const l=o.length,d=new TextDecoder,u=a.getReader();let c="",f=!0,m=!1,p=[...null!=pe?pe:[]];const h=v.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");c+=t,ee([...o.slice(0,l),{id:X.length+1,role:"assistant",content:c}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),he(p),ve.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),he(p),ve.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);p=p.filter((e=>!(e.id===t.id&&e.version===t.version))),p.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),he(p),ve.startsWith("inline")||ge({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");p=p.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),he(p)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);he(p.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);ie(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(f=!1)}});for(;f;){const{value:e,done:t}=yield u.read();if(t){f=!1;break}const s=d.decode(e);s&&(m||(te("streaming"),m=!0),h.feed(s))}null==G||G(_)}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(Z).find((([e])=>t.includes(e)));s?se(s[1]):ie(t)}finally{me(),te("idle"),fe()}}));return s.useEffect((()=>{z(Ee)}),[Ee]),De?null:t.jsx("div",Object.assign({className:O.default("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!_e&&"px-4 pb-4"),dir:L?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!_e&&t.jsx("div",Object.assign({className:O.default("absolute bottom-full",L?"left-0":"right-0")},{children:t.jsx("div",Object.assign({className:O.default("flex flex-col gap-2 pb-4 px-2",L?"justify-start":"justify-end","viewport"===R?L?"min-[767px]:items-start":"min-[767px]:items-end":L?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:Ee&&!w&&t.jsx(x.default,{data:(null==U?void 0:U.icebreakers)||[],onSend:Te})}))})),t.jsxs("div",Object.assign({className:O.default("flex flex-col gap-y-3 px-4 py-3","block"===H.formFieldStyle&&"shadow"),style:Ce},{children:["idle"===Y&&re.length>0&&t.jsx(j.default,{isDisabled:"idle"!==Y}),t.jsxs("div",Object.assign({className:O.default("flex items-end gap-x-2",L&&"flex-row-reverse")},{children:[t.jsx(b.default,Object.assign({className:O.default(Ae.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!be.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",L?"text-right":"text-left"),value:be,placeholder:null!==(q=null==U?void 0:U.placeholdertext)&&void 0!==q?q:L?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>ye(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ne||"idle"!==Y||Te()))}},S&&{onFocus:S},I&&{onBlur:I},{dir:L?"rtl":"ltr"})),t.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:[null!==(A=null===(N=null==U?void 0:U.documentuploadtype)||void 0===N?void 0:N.startsWith("enduserupload"))&&void 0!==A&&A&&t.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:qe?J.accent+"10":void 0,color:qe?J.accent:J.accent+"80"},disabled:ne||"idle"!==Y,onClick:()=>{var e;return null===(e=ke.current)||void 0===e?void 0:e.click()}},Ne,{children:[t.jsx("input",{id:"file-upload",ref:ke,type:"file",accept:[...p.allowedFileMimeTypes,...oe?p.allowedImageMimeTypes:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){P(!1),yield le(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(h.default,{className:"h-6 w-6 shrink-0"})]})),t.jsx("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:we||Be?J.accent:J.accent+"10",color:we||Be?J.accentText:J.accent+"80"},disabled:"idle"!==Y||ne,onClick:()=>Te()},Se,{children:t.jsx(g.default,{className:O.default("h-6 w-6 shrink-0",L&&"transform scale-x-[-1]")})}))]}))]}))]})),ae&&t.jsx(y.default,{error:ae,className:"mt-3"})]}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../../hooks/pickaxe/useSubmit.js"),a=require("../../Addons/Document/hooks/useDocument.js"),d=require("../../Addons/Scroll/hooks/useScroll.js"),l=require("../../Addons/Artifact/hooks/useArtifactContext.js"),u=require("../../../../common/utils.js"),c=require("@nem035/gpt-3-encoder"),p=require("eventsource-parser"),m=require("../../common/PickaxeBranding.js"),f=require("../../common/PickaxeButton.js"),g=require("../../../../common/error.js");exports.default=({questions:h})=>{var v;const{formId:j,userId:b,studioUserId:x,embedUserId:O,deploymentId:k,pickaxe:w,misc:q,translations:S,isRtl:y,setChatId:I,setIsNewChat:C,onGenerateComplete:A}=n.usePickaxeContext(),{token:N}=i.useAuthContext(),{status:P,limits:_,isGenerating:D,setResponse:R,setMessages:U,setStatus:E,setLimitData:J,setError:T}=o.useResponseContext(),{documents:W,websiteLink:B,isUploading:L,onWebsiteUpload:M,setDocuments:G,setDocumentError:F}=a.useDocument(),{scrollStartSession:K,scrollEndSession:X,scrollToTarget:Y}=d.useScroll({auto:!(null==w?void 0:w.enablechatresponses)}),{artifacts:z,currentPopupType:H,setArtifacts:Q,setCurrentArtifact:V}=l.useArtifactContext(),Z=r.useSubmit(),[$,ee]=s.useState(!1);return t.jsxs("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:y?"rtl":"ltr"},{children:[t.jsx("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:t.jsx(f.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:L||"idle"!==P||D||$,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==P||L||$)return;T(""),F(""),J(null),R(null);const e=["Multiple Choice","Checkbox"];for(const t of h){if(c.encode(t.input).length>t.maxLength&&!e.includes(t.type))throw new Error("One or more of your responses is too long!");if(t.isRequired&&!t.input.trim()&&"userinput:documentupload"!==t.id)throw new Error("You must fill out all required fields.")}const t=W.filter((e=>"finished"===e.status)),s=W.map((e=>e.name)),n="enduserupload"===(null==w?void 0:w.documentuploadtype),i=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),o=u.extractUrlsFromText(B).filter((e=>!s.includes(e)));if(o.length){const e=o[o.length-1];ee(!0);const s=yield M(e);s&&(t.push(s),yield new Promise((e=>setTimeout(e,5e3)))),ee(!1)}else if(i&&n&&!t.length)return void F("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=t.map((e=>e.documentId)).filter(Boolean),a=n&&r.length>0;let d={};h.forEach((e=>d=Object.assign(Object.assign({},d),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?t.map((e=>e.name)).join(",")||"":e.input}))),E("fetching"),K(),Y();const l=yield Z.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,valueObj:d},a&&{documentIds:r}),b&&{userId:b}),x&&{studioUserId:x}),O&&{embedUserId:O}),N&&{studioSessionToken:N}),k&&{deploymentId:k})),m=l.body;if(!m)throw new Error("Streaming error");const f=l.headers.get("X-Pickaxe-Response-Id");if(!f)throw new Error("Response ID not found");const g=new TextDecoder,v=m.getReader();let q="",S=!0,y=!1,_=[...null!=z?z:[]];const D=p.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");q+=t,R({formId:j,responseId:f,documentIds:r,questions:h.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:q,messageCount:0,sentAt:new Date}),(null==w?void 0:w.enablechatresponses)&&U([{id:0,role:"assistant",content:q}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);_=_.filter((e=>!(e.id===t.id&&e.version===t.version))),_.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Q(_),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);_=_.filter((e=>!(e.id===t.id&&e.version===t.version))),_.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Q(_),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);_=_.filter((e=>!(e.id===t.id&&e.version===t.version))),_.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Q(_),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");_=_.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Q(_)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Q(_.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);T(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(S=!1)}});for(;S;){const{value:e,done:t}=yield v.read();if(t){S=!1;break}const s=g.decode(e);s&&(y||(E("streaming"),y=!0,a&&G([]),(null==w?void 0:w.enablechatresponses)&&(I(f),C(!1))),D.feed(s))}null==A||A(f)}catch(e){let t=g.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(_).find((([e])=>t.includes(e)));s?J(s[1]):T(t),Y()}finally{E("idle"),ee(!1),X()}}))},{children:$?(null==S?void 0:S.processing)||"Processing...":L?(null==S?void 0:S.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==S?void 0:S.loading)||"Loading...":null!==(v=null==w?void 0:w.submittext)&&void 0!==v?v:"Submit"}))})),!q.isWhiteLabel&&t.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:t.jsx(m.default,{})}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../../hooks/pickaxe/useSubmit.js"),a=require("../../Addons/Document/hooks/useDocument.js"),d=require("../../Addons/Scroll/hooks/useScroll.js"),l=require("../../Addons/Artifact/hooks/useArtifactContext.js"),u=require("../../../../common/utils.js"),c=require("@nem035/gpt-3-encoder"),p=require("eventsource-parser"),m=require("../../common/PickaxeBranding.js"),f=require("../../common/PickaxeButton.js"),g=require("../../../../common/error.js");exports.default=({questions:h})=>{var v;const{formId:j,userId:b,studioUserId:x,embedUserId:O,deploymentId:k,pickaxe:w,misc:q,translations:S,isRtl:y,setChatId:I,setIsNewChat:C,onGenerateComplete:A}=i.usePickaxeContext(),{token:N}=n.useAuthContext(),{status:P,limits:_,isGenerating:D,setResponse:R,setMessages:U,setStatus:E,setLimitData:J,setError:T}=o.useResponseContext(),{documents:W,websiteLink:B,isUploading:L,onWebsiteUpload:M,setDocuments:G,setDocumentError:F}=a.useDocument(),{scrollStartSession:K,scrollEndSession:X,scrollToTarget:Y}=d.useScroll({auto:!(null==w?void 0:w.enablechatresponses)}),{artifacts:z,currentPopupType:H,setArtifacts:Q,setCurrentArtifact:V}=l.useArtifactContext(),Z=r.useSubmit(),[$,ee]=s.useState(!1);return t.jsxs("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:y?"rtl":"ltr"},{children:[t.jsx("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:t.jsx(f.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:L||"idle"!==P||D||$,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,t;try{if("idle"!==P||L||$)return;T(""),F(""),J(null),R(null);const s=["Multiple Choice","Checkbox"];for(const e of h){if(c.encode(e.input).length>e.maxLength&&!s.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const i=W.filter((e=>"finished"===e.status)),n=W.map((e=>e.name)),o=null!==(t=null===(e=null==w?void 0:w.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,r=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),a=u.extractUrlsFromText(B).filter((e=>!n.includes(e)));if(a.length){const e=a[a.length-1];ee(!0);const t=yield M(e);t&&(i.push(t),yield new Promise((e=>setTimeout(e,5e3)))),ee(!1)}else if(r&&o&&!i.length)return void F("Please paste a valid website/video link or drag a file to add to the knowledge base.");const d=i.map((e=>e.documentId)).filter(Boolean),l=o&&d.length>0;let m={};h.forEach((e=>m=Object.assign(Object.assign({},m),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?i.map((e=>e.name)).join(",")||"":e.input}))),E("fetching"),K(),Y();const f=yield Z.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,valueObj:m},l&&{documentIds:d}),b&&{userId:b}),x&&{studioUserId:x}),O&&{embedUserId:O}),N&&{studioSessionToken:N}),k&&{deploymentId:k})),g=f.body;if(!g)throw new Error("Streaming error");const v=f.headers.get("X-Pickaxe-Response-Id");if(!v)throw new Error("Response ID not found");const q=new TextDecoder,S=g.getReader();let y="",_=!0,D=!1,X=[...null!=z?z:[]];const te=p.createParser({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");y+=t,R({formId:j,responseId:v,documentIds:d,questions:h.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:y,messageCount:0,sentAt:new Date}),(null==w?void 0:w.enablechatresponses)&&U([{id:0,role:"assistant",content:y}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);X=X.filter((e=>!(e.id===t.id&&e.version===t.version))),X.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Q(X),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);X=X.filter((e=>!(e.id===t.id&&e.version===t.version))),X.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Q(X),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);X=X.filter((e=>!(e.id===t.id&&e.version===t.version))),X.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Q(X),H.startsWith("inline")||V({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");X=X.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Q(X)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Q(X.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);T(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(_=!1)}});for(;_;){const{value:e,done:t}=yield S.read();if(t){_=!1;break}const s=q.decode(e);s&&(D||(E("streaming"),D=!0,l&&G([]),(null==w?void 0:w.enablechatresponses)&&(I(v),C(!1))),te.feed(s))}null==A||A(v)}catch(e){let t=g.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(_).find((([e])=>t.includes(e)));s?J(s[1]):T(t),Y()}finally{E("idle"),ee(!1),X()}}))},{children:$?(null==S?void 0:S.processing)||"Processing...":L?(null==S?void 0:S.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==S?void 0:S.loading)||"Loading...":null!==(v=null==w?void 0:w.submittext)&&void 0!==v?v:"Submit"}))})),!q.isWhiteLabel&&t.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:t.jsx(m.default,{})}))]}))};
@@ -2,7 +2,7 @@ import type { PickaxeQuestion } from "./form";
2
2
  export type PickaxeImageOrText = "text" | "image";
3
3
  export type PickaxePrivacySetting = "public" | "unlisted" | "private" | "deleted";
4
4
  export type PickaxeCloneable = "true" | "false";
5
- export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload";
5
+ export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload" | "enduserupload-display";
6
6
  export type PickaxeModel = "gpt-3.5-turbo" | "gpt-4-1106-preview" | "mistral-small" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o-mini" | "gpt-4o" | "gpt-4" | "o3-mini" | "o1" | "deepseek-chat" | "mistral-large-latest" | "claude-3-opus-20240229" | "claude-3-5-sonnet-20240620" | "claude-3-7-sonnet-20250219" | "llama-3-uncensored";
7
7
  export type Pickaxe = {
8
8
  _id: string;
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as o}from"react/jsx-runtime";import{useState as i,useRef as n,useMemo as r,useEffect as a}from"react";import{usePickaxeContext as l}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as c}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as u}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as m}from"../../../hooks/pickaxe/useConversation.js";import{useAuthContext as p}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as g}from"../Addons/Document/hooks/useDocument.js";import{useScroll as h}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as v}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as b}from"../../../hooks/core/useHover.js";import{allowedFileMimeTypes as j,allowedImageMimeTypes as x}from"../../../common/documents.js";import{createParser as k}from"eventsource-parser";import y from"../../Icons/attach-vertical.svg.js";import O from"../../Icons/arrow-right.svg.js";import w from"../Addons/IceBreaker/index.js";import I from"../Addons/Document/List.js";import S from"../../Core/Textarea.js";import N from"../../Core/ErrorAlert.js";import A from"../../../common/error.js";import C from"../../../common/cn.js";const D=({isFocused:D,onFocus:B,onBlur:E})=>{var U;const{formId:J,chatId:T,userId:_,studioUserId:F,embedUserId:L,deploymentId:H,deploymentType:R,pickaxe:W,styles:P,colors:z,responsiveBy:G,isNewChat:K,isRtl:M,isEmailLogin:q,setIsNewChat:Q,setIsShowIceBreaker:V,onGenerateComplete:X}=l(),{token:Y,isLoggedOut:Z,isSent:$}=p(),{messages:ee,status:te,limits:se,isGenerating:oe,setMessages:ie,setStatus:ne,setLimitData:re,setError:ae}=d(),{documents:le,isUploading:de,isImageUploadAllowed:ce,documentError:ue,onFileUpload:me,setDocuments:pe,setDocumentError:fe}=g(),{scrollStartSession:ge,scrollEndSession:he,scrollToBottom:ve}=h({auto:!0}),{artifacts:be,currentPopupType:je,setArtifacts:xe,setCurrentArtifact:ke}=v(),ye=m(),Oe=f(),[we,Ie]=i(""),Se=n(null),Ne=b(),{isHover:Ae}=Ne,Ce=e(Ne,["isHover"]),De=b(),{isHover:Be}=De,Ee=e(De,["isHover"]),Ue=u(),Je=c(),Te="chat-input"===R&&K&&!$,_e="chat-input"===R&&q&&Z&&$,Fe=r((()=>{var e,t,s;return!!K&&(!!W&&(!ye.isLoading&&(!((null!==(t=null===(e=ye.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=W.icebreakers)||void 0===s?void 0:s.length))))}),[W,K,ye.data,ye.isLoading]),Le=r((()=>{if(oe||de)return!1;return!!we.trim()&&le.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[oe,de,we,le]),He=e=>t(void 0,void 0,void 0,(function*(){try{if("idle"!==te||de)return;const t=null!=e?e:we;if(!t)return;ae(""),fe(""),re(null),Ie(""),Q(!1),ne("fetching"),ge(),ve();const s=le.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),o="enduserupload"===(null==W?void 0:W.documentuploadtype)&&s.length>0,i=[...Array.from(ee),Object.assign({id:ee.length+1,role:"user",content:t},o&&{documentIds:s})];ie(i),ve(),o&&pe([]);const n=(yield Oe.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:J,responseId:T,value:t},o&&{documentIds:s}),_&&{userId:_}),F&&{studioUserId:F}),L&&{embedUserId:L}),Y&&{studioSessionToken:Y}),H&&{deploymentId:H}))).body;if(!n)throw new Error("Streaming error");const r=i.length,a=new TextDecoder,l=n.getReader();let d="",c=!0,u=!1,m=[...null!=be?be:[]];const p=k({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=t,ie([...i.slice(0,r),{id:ee.length+1,role:"assistant",content:d}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),xe(m),je.startsWith("inline")||ke({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),xe(m),je.startsWith("inline")||ke({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);m=m.filter((e=>!(e.id===t.id&&e.version===t.version))),m.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),xe(m),je.startsWith("inline")||ke({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");m=m.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),xe(m)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);xe(m.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);ae(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(c=!1)}});for(;c;){const{value:e,done:t}=yield l.read();if(t){c=!1;break}const s=a.decode(e);s&&(u||(ne("streaming"),u=!0),p.feed(s))}null==X||X(T)}catch(e){let t=A(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(se).find((([e])=>t.includes(e)));s?re(s[1]):ae(t)}finally{ve(),ne("idle"),he()}}));return a((()=>{V(Fe)}),[Fe]),_e?null:s("div",Object.assign({className:C("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!Te&&"px-4 pb-4"),dir:M?"rtl":"ltr"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!Te&&s("div",Object.assign({className:C("absolute bottom-full",M?"left-0":"right-0")},{children:s("div",Object.assign({className:C("flex flex-col gap-2 pb-4 px-2",M?"justify-start":"justify-end","viewport"===G?M?"min-[767px]:items-start":"min-[767px]:items-end":M?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:Fe&&!D&&s(w,{data:(null==W?void 0:W.icebreakers)||[],onSend:He})}))})),o("div",Object.assign({className:C("flex flex-col gap-y-3 px-4 py-3","block"===P.formFieldStyle&&"shadow"),style:Je},{children:["idle"===te&&le.length>0&&s(I,{isDisabled:"idle"!==te}),o("div",Object.assign({className:C("flex items-end gap-x-2",M&&"flex-row-reverse")},{children:[s(S,Object.assign({className:C(Ue.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!we.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",M?"text-right":"text-left"),value:we,placeholder:null!==(U=null==W?void 0:W.placeholdertext)&&void 0!==U?U:M?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>Ie(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),de||"idle"!==te||He()))}},B&&{onFocus:B},E&&{onBlur:E},{dir:M?"rtl":"ltr"})),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==W?void 0:W.documentuploadtype)&&o("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Be?z.accent+"10":void 0,color:Be?z.accent:z.accent+"80"},disabled:de||"idle"!==te,onClick:()=>{var e;return null===(e=Se.current)||void 0===e?void 0:e.click()}},Ee,{children:[s("input",{id:"file-upload",ref:Se,type:"file",accept:[...j,...ce?x:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){Q(!1),yield me(Array.from(e.target.files||[])),e.target.value=""}))}),s(y,{className:"h-6 w-6 shrink-0"})]})),s("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:Ae||Le?z.accent:z.accent+"10",color:Ae||Le?z.accentText:z.accent+"80"},disabled:"idle"!==te||de,onClick:()=>He()},Ce,{children:s(O,{className:C("h-6 w-6 shrink-0",M&&"transform scale-x-[-1]")})}))]}))]}))]})),ue&&s(N,{error:ue,className:"mt-3"})]}))}))};export{D as default};
1
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as o}from"react/jsx-runtime";import{useState as i,useRef as n,useMemo as r,useEffect as a}from"react";import{usePickaxeContext as l}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as c}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as u}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as m}from"../../../hooks/pickaxe/useConversation.js";import{useAuthContext as p}from"../Addons/Auth/hooks/useAuthContext.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as v}from"../Addons/Document/hooks/useDocument.js";import{useScroll as h}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as g}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as b}from"../../../hooks/core/useHover.js";import{allowedFileMimeTypes as j,allowedImageMimeTypes as x}from"../../../common/documents.js";import{createParser as k}from"eventsource-parser";import y from"../../Icons/attach-vertical.svg.js";import O from"../../Icons/arrow-right.svg.js";import w from"../Addons/IceBreaker/index.js";import I from"../Addons/Document/List.js";import S from"../../Core/Textarea.js";import N from"../../Core/ErrorAlert.js";import A from"../../../common/error.js";import C from"../../../common/cn.js";const D=({isFocused:D,onFocus:B,onBlur:E})=>{var U,J,T;const{formId:W,chatId:_,userId:F,studioUserId:L,embedUserId:H,deploymentId:R,deploymentType:P,pickaxe:z,styles:G,colors:K,responsiveBy:M,isNewChat:q,isRtl:Q,isEmailLogin:V,setIsNewChat:X,setIsShowIceBreaker:Y,onGenerateComplete:Z}=l(),{token:$,isLoggedOut:ee,isSent:te}=p(),{messages:se,status:oe,limits:ie,isGenerating:ne,setMessages:re,setStatus:ae,setLimitData:le,setError:de}=d(),{documents:ce,isUploading:ue,isImageUploadAllowed:me,documentError:pe,onFileUpload:fe,setDocuments:ve,setDocumentError:he}=v(),{scrollStartSession:ge,scrollEndSession:be,scrollToBottom:je}=h({auto:!0}),{artifacts:xe,currentPopupType:ke,setArtifacts:ye,setCurrentArtifact:Oe}=g(),we=m(),Ie=f(),[Se,Ne]=i(""),Ae=n(null),Ce=b(),{isHover:De}=Ce,Be=e(Ce,["isHover"]),Ee=b(),{isHover:Ue}=Ee,Je=e(Ee,["isHover"]),Te=u(),We=c(),_e="chat-input"===P&&q&&!te,Fe="chat-input"===P&&V&&ee&&te,Le=r((()=>{var e,t,s;return!!q&&(!!z&&(!we.isLoading&&(!((null!==(t=null===(e=we.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=z.icebreakers)||void 0===s?void 0:s.length))))}),[z,q,we.data,we.isLoading]),He=r((()=>{if(ne||ue)return!1;return!!Se.trim()&&ce.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[ne,ue,Se,ce]),Re=e=>t(void 0,void 0,void 0,(function*(){var t,s;try{if("idle"!==oe||ue)return;const o=null!=e?e:Se;if(!o)return;de(""),he(""),le(null),Ne(""),X(!1),ae("fetching"),ge(),je();const i=ce.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),n=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,r=[...Array.from(se),Object.assign({id:se.length+1,role:"user",content:o},n&&{documentIds:i})];re(r),je(),n&&ve([]);const a=(yield Ie.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:W,responseId:_,value:o},n&&{documentIds:i}),F&&{userId:F}),L&&{studioUserId:L}),H&&{embedUserId:H}),$&&{studioSessionToken:$}),R&&{deploymentId:R}))).body;if(!a)throw new Error("Streaming error");const l=r.length,d=new TextDecoder,c=a.getReader();let u="",m=!0,p=!1,f=[...null!=xe?xe:[]];const v=k({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");u+=t,re([...r.slice(0,l),{id:se.length+1,role:"assistant",content:u}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ye(f),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),ye(f),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);f=f.filter((e=>!(e.id===t.id&&e.version===t.version))),f.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ye(f),ke.startsWith("inline")||Oe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");f=f.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),ye(f)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);ye(f.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&&(m=!1)}});for(;m;){const{value:e,done:t}=yield c.read();if(t){m=!1;break}const s=d.decode(e);s&&(p||(ae("streaming"),p=!0),v.feed(s))}null==Z||Z(_)}catch(e){let t=A(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(ie).find((([e])=>t.includes(e)));s?le(s[1]):de(t)}finally{je(),ae("idle"),be()}}));return a((()=>{Y(Le)}),[Le]),Fe?null:s("div",Object.assign({className:C("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!_e&&"px-4 pb-4"),dir:Q?"rtl":"ltr"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!_e&&s("div",Object.assign({className:C("absolute bottom-full",Q?"left-0":"right-0")},{children:s("div",Object.assign({className:C("flex flex-col gap-2 pb-4 px-2",Q?"justify-start":"justify-end","viewport"===M?Q?"min-[767px]:items-start":"min-[767px]:items-end":Q?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:Le&&!D&&s(w,{data:(null==z?void 0:z.icebreakers)||[],onSend:Re})}))})),o("div",Object.assign({className:C("flex flex-col gap-y-3 px-4 py-3","block"===G.formFieldStyle&&"shadow"),style:We},{children:["idle"===oe&&ce.length>0&&s(I,{isDisabled:"idle"!==oe}),o("div",Object.assign({className:C("flex items-end gap-x-2",Q&&"flex-row-reverse")},{children:[s(S,Object.assign({className:C(Te.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!Se.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",Q?"text-right":"text-left"),value:Se,placeholder:null!==(U=null==z?void 0:z.placeholdertext)&&void 0!==U?U:Q?"بماذا تريد أن تتحدث؟":"What do you want to talk about?",onChange:e=>Ne(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ue||"idle"!==oe||Re()))}},B&&{onFocus:B},E&&{onBlur:E},{dir:Q?"rtl":"ltr"})),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:[null!==(T=null===(J=null==z?void 0:z.documentuploadtype)||void 0===J?void 0:J.startsWith("enduserupload"))&&void 0!==T&&T&&o("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Ue?K.accent+"10":void 0,color:Ue?K.accent:K.accent+"80"},disabled:ue||"idle"!==oe,onClick:()=>{var e;return null===(e=Ae.current)||void 0===e?void 0:e.click()}},Je,{children:[s("input",{id:"file-upload",ref:Ae,type:"file",accept:[...j,...me?x:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){X(!1),yield fe(Array.from(e.target.files||[])),e.target.value=""}))}),s(y,{className:"h-6 w-6 shrink-0"})]})),s("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full duration-200 transition-colors ease-in-out",style:{backgroundColor:De||He?K.accent:K.accent+"10",color:De||He?K.accentText:K.accent+"80"},disabled:"idle"!==oe||ue,onClick:()=>Re()},Be,{children:s(O,{className:C("h-6 w-6 shrink-0",Q&&"transform scale-x-[-1]")})}))]}))]}))]})),pe&&s(N,{error:pe,className:"mt-3"})]}))}))};export{D as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as s}from"react/jsx-runtime";import{useState as n}from"react";import{usePickaxeContext as i}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as o}from"../../Addons/Auth/hooks/useAuthContext.js";import{useResponseContext as r}from"../../../../hooks/pickaxe/useResponseContext.js";import{useSubmit as a}from"../../../../hooks/pickaxe/useSubmit.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as l}from"../../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as c}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{extractUrlsFromText as u}from"../../../../common/utils.js";import{encode as m}from"@nem035/gpt-3-encoder";import{createParser as p}from"eventsource-parser";import f from"../../common/PickaxeBranding.js";import g from"../../common/PickaxeButton.js";import h from"../../../../common/error.js";const v=({questions:v})=>{var b;const{formId:j,userId:O,studioUserId:x,embedUserId:k,deploymentId:w,pickaxe:y,misc:I,translations:S,isRtl:A,setChatId:C,setIsNewChat:N,onGenerateComplete:D}=i(),{token:E}=o(),{status:P,limits:R,isGenerating:U,setResponse:q,setMessages:J,setStatus:_,setLimitData:T,setError:W}=r(),{documents:B,websiteLink:L,isUploading:G,onWebsiteUpload:M,setDocuments:K,setDocumentError:X}=d(),{scrollStartSession:Y,scrollEndSession:z,scrollToTarget:F}=l({auto:!(null==y?void 0:y.enablechatresponses)}),{artifacts:H,currentPopupType:Q,setArtifacts:V,setCurrentArtifact:Z}=c(),$=a(),[ee,te]=n(!1);return t("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:A?"rtl":"ltr"},{children:[s("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:s(g,Object.assign({className:"px-5 min-h-[42px]",isDisabled:G||"idle"!==P||U||ee,onClick:()=>e(void 0,void 0,void 0,(function*(){try{if("idle"!==P||G||ee)return;W(""),X(""),T(null),q(null);const e=["Multiple Choice","Checkbox"];for(const t of v){if(m(t.input).length>t.maxLength&&!e.includes(t.type))throw new Error("One or more of your responses is too long!");if(t.isRequired&&!t.input.trim()&&"userinput:documentupload"!==t.id)throw new Error("You must fill out all required fields.")}const t=B.filter((e=>"finished"===e.status)),s=B.map((e=>e.name)),n="enduserupload"===(null==y?void 0:y.documentuploadtype),i=v.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),o=u(L).filter((e=>!s.includes(e)));if(o.length){const e=o[o.length-1];te(!0);const s=yield M(e);s&&(t.push(s),yield new Promise((e=>setTimeout(e,5e3)))),te(!1)}else if(i&&n&&!t.length)return void X("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=t.map((e=>e.documentId)).filter(Boolean),a=n&&r.length>0;let d={};v.forEach((e=>d=Object.assign(Object.assign({},d),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?t.map((e=>e.name)).join(",")||"":e.input}))),_("fetching"),Y(),F();const l=yield $.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,valueObj:d},a&&{documentIds:r}),O&&{userId:O}),x&&{studioUserId:x}),k&&{embedUserId:k}),E&&{studioSessionToken:E}),w&&{deploymentId:w})),c=l.body;if(!c)throw new Error("Streaming error");const f=l.headers.get("X-Pickaxe-Response-Id");if(!f)throw new Error("Response ID not found");const g=new TextDecoder,h=c.getReader();let b="",I=!0,S=!1,A=[...null!=H?H:[]];const R=p({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");b+=t,q({formId:j,responseId:f,documentIds:r,questions:v.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:b,messageCount:0,sentAt:new Date}),(null==y?void 0:y.enablechatresponses)&&J([{id:0,role:"assistant",content:b}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),V(A),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),V(A),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),V(A),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");A=A.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),V(A)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);V(A.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);W(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(I=!1)}});for(;I;){const{value:e,done:t}=yield h.read();if(t){I=!1;break}const s=g.decode(e);s&&(S||(_("streaming"),S=!0,a&&K([]),(null==y?void 0:y.enablechatresponses)&&(C(f),N(!1))),R.feed(s))}null==D||D(f)}catch(e){let t=h(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(R).find((([e])=>t.includes(e)));s?T(s[1]):W(t),F()}finally{_("idle"),te(!1),z()}}))},{children:ee?(null==S?void 0:S.processing)||"Processing...":G?(null==S?void 0:S.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==S?void 0:S.loading)||"Loading...":null!==(b=null==y?void 0:y.submittext)&&void 0!==b?b:"Submit"}))})),!I.isWhiteLabel&&s("div",Object.assign({className:"flex justify-end pr-3"},{children:s(f,{})}))]}))};export{v as default};
1
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as s}from"react/jsx-runtime";import{useState as i}from"react";import{usePickaxeContext as n}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as o}from"../../Addons/Auth/hooks/useAuthContext.js";import{useResponseContext as r}from"../../../../hooks/pickaxe/useResponseContext.js";import{useSubmit as a}from"../../../../hooks/pickaxe/useSubmit.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as l}from"../../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as c}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{extractUrlsFromText as u}from"../../../../common/utils.js";import{encode as m}from"@nem035/gpt-3-encoder";import{createParser as p}from"eventsource-parser";import f from"../../common/PickaxeBranding.js";import g from"../../common/PickaxeButton.js";import h from"../../../../common/error.js";const v=({questions:v})=>{var b;const{formId:j,userId:O,studioUserId:x,embedUserId:k,deploymentId:w,pickaxe:y,misc:I,translations:S,isRtl:A,setChatId:C,setIsNewChat:N,onGenerateComplete:D}=n(),{token:E}=o(),{status:P,limits:R,isGenerating:U,setResponse:q,setMessages:J,setStatus:W,setLimitData:_,setError:T}=r(),{documents:B,websiteLink:L,isUploading:G,onWebsiteUpload:M,setDocuments:K,setDocumentError:X}=d(),{scrollStartSession:Y,scrollEndSession:z,scrollToTarget:F}=l({auto:!(null==y?void 0:y.enablechatresponses)}),{artifacts:H,currentPopupType:Q,setArtifacts:V,setCurrentArtifact:Z}=c(),$=a(),[ee,te]=i(!1);return t("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:A?"rtl":"ltr"},{children:[s("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:s(g,Object.assign({className:"px-5 min-h-[42px]",isDisabled:G||"idle"!==P||U||ee,onClick:()=>e(void 0,void 0,void 0,(function*(){var e,t;try{if("idle"!==P||G||ee)return;T(""),X(""),_(null),q(null);const s=["Multiple Choice","Checkbox"];for(const e of v){if(m(e.input).length>e.maxLength&&!s.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const i=B.filter((e=>"finished"===e.status)),n=B.map((e=>e.name)),o=null!==(t=null===(e=null==y?void 0:y.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,r=v.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),a=u(L).filter((e=>!n.includes(e)));if(a.length){const e=a[a.length-1];te(!0);const t=yield M(e);t&&(i.push(t),yield new Promise((e=>setTimeout(e,5e3)))),te(!1)}else if(r&&o&&!i.length)return void X("Please paste a valid website/video link or drag a file to add to the knowledge base.");const d=i.map((e=>e.documentId)).filter(Boolean),l=o&&d.length>0;let c={};v.forEach((e=>c=Object.assign(Object.assign({},c),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?i.map((e=>e.name)).join(",")||"":e.input}))),W("fetching"),Y(),F();const f=yield $.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,valueObj:c},l&&{documentIds:d}),O&&{userId:O}),x&&{studioUserId:x}),k&&{embedUserId:k}),E&&{studioSessionToken:E}),w&&{deploymentId:w})),g=f.body;if(!g)throw new Error("Streaming error");const h=f.headers.get("X-Pickaxe-Response-Id");if(!h)throw new Error("Response ID not found");const b=new TextDecoder,I=g.getReader();let S="",A=!0,R=!1,U=[...null!=H?H:[]];const z=p({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");S+=t,q({formId:j,responseId:h,documentIds:d,questions:v.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:S,messageCount:0,sentAt:new Date}),(null==y?void 0:y.enablechatresponses)&&J([{id:0,role:"assistant",content:S}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);U=U.filter((e=>!(e.id===t.id&&e.version===t.version))),U.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),V(U),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);U=U.filter((e=>!(e.id===t.id&&e.version===t.version))),U.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),V(U),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);U=U.filter((e=>!(e.id===t.id&&e.version===t.version))),U.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),V(U),Q.startsWith("inline")||Z({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");U=U.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),V(U)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);V(U.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);T(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(A=!1)}});for(;A;){const{value:e,done:t}=yield I.read();if(t){A=!1;break}const s=b.decode(e);s&&(R||(W("streaming"),R=!0,l&&K([]),(null==y?void 0:y.enablechatresponses)&&(C(h),N(!1))),z.feed(s))}null==D||D(h)}catch(e){let t=h(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(R).find((([e])=>t.includes(e)));s?_(s[1]):T(t),F()}finally{W("idle"),te(!1),z()}}))},{children:ee?(null==S?void 0:S.processing)||"Processing...":G?(null==S?void 0:S.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==S?void 0:S.loading)||"Loading...":null!==(b=null==y?void 0:y.submittext)&&void 0!==b?b:"Submit"}))})),!I.isWhiteLabel&&s("div",Object.assign({className:"flex justify-end pr-3"},{children:s(f,{})}))]}))};export{v as default};
@@ -2,7 +2,7 @@ import type { PickaxeQuestion } from "./form";
2
2
  export type PickaxeImageOrText = "text" | "image";
3
3
  export type PickaxePrivacySetting = "public" | "unlisted" | "private" | "deleted";
4
4
  export type PickaxeCloneable = "true" | "false";
5
- export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload";
5
+ export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload" | "enduserupload-display";
6
6
  export type PickaxeModel = "gpt-3.5-turbo" | "gpt-4-1106-preview" | "mistral-small" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o-mini" | "gpt-4o" | "gpt-4" | "o3-mini" | "o1" | "deepseek-chat" | "mistral-large-latest" | "claude-3-opus-20240229" | "claude-3-5-sonnet-20240620" | "claude-3-7-sonnet-20250219" | "llama-3-uncensored";
7
7
  export type Pickaxe = {
8
8
  _id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",