@pickaxeproject/react 2.7.0 → 2.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"),s=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),o=require("./useDocumentContext.js"),n=require("../../../../../common/documents.js"),r=require("../../../../../common/error.js"),u=require("uuid");const a=["gpt-4o","gpt-4o-mini","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","o1"];exports.useDocument=({onQuestionChange:d}={})=>{const{formId:l,chatId:c,sessionId:m,pickaxe:p}=s.usePickaxeContext(),f=o.useDocumentContext(),g=i.useSubmitDocument(),w=t.useMemo((()=>{var e;return a.includes(null!==(e=null==p?void 0:p.model)&&void 0!==e?e:"gpt-3.5-turbo")}),[p]),h=e=>{const t=[...n.allowedFileMimeTypes,...w?n.allowedImageMimeTypes:[]];if(e.some((e=>!t.includes(e.type)))){const e=new Error(w?"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, PNG, JPEG, WEBP, or GIF files. Please try again.":"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, or PPTX files. Please try again."),t=r.default(e);return f.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},f),{isImageUploadAllowed:w,onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(f.setDocumentError(""),!t.length)return null;if(h(t))return null;f.setIsUploading(!0),f.setIsShowList(!0);const s=t.map((e=>({file:e,id:u.v4()})));s.forEach((({file:e,id:t})=>{f.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e.__awaiter(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,error:o}=yield g.document({formId:l,responseId:c,file:t,sessionId:m});if(!e)throw new Error(null!=o?o:"Document processing failed");null==d||d({input:t.name,documentId:i});const n=i.startsWith("IMAGE-");return f.editDocument({id:s,type:n?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i}),{name:t.name,documentId:i}}catch(e){const i=r.default(e);return f.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}})))),o=yield Promise.allSettled(i),n=new Set;for(const e of o)"fulfilled"===e.status&&"error"in e.value&&n.add(e.value.error);n.size>0&&f.setDocumentError([...n].join(", ")),f.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){f.setDocumentError("");let e=t.trim();if(!e)return null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error("Please paste a valid website URL or Youtube video link to add to the knowledge base.");f.setIsUploading(!0),f.setIsShowList(!0),f.setWebsiteLink(""),f.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield g.website({formId:l,responseId:c,website:e}),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");f.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:i}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:i}}catch(t){const s=r.default(t);if(console.log("[onWebsiteUpload] Error",s),s.includes("Please paste a valid website URL"))return f.setDocumentError(s),null;f.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:s});return{type:"website",id:e,size:0,name:e,status:"failed",error:s}}finally{f.setIsUploading(!1)}}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("react"),s=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),o=require("./useDocumentContext.js"),n=require("../../../../../common/documents.js"),r=require("../../../../../common/error.js"),a=require("uuid");const u=["gpt-4o","gpt-4o-mini","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","o1"];exports.useDocument=({onQuestionChange:d}={})=>{const{formId:l,chatId:c,sessionId:m,pickaxe:p}=s.usePickaxeContext(),f=o.useDocumentContext(),w=i.useSubmitDocument(),g=t.useMemo((()=>{var e;return u.includes(null!==(e=null==p?void 0:p.model)&&void 0!==e?e:"gpt-3.5-turbo")}),[p]),I=e=>{const t=[...n.allowedFileMimeTypes,...g?n.allowedImageMimeTypes:[]];if(e.some((e=>!t.includes(e.type)))){const e=new Error(g?"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, PNG, JPEG, WEBP, or GIF files. Please try again.":"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, or PPTX files. Please try again."),t=r.default(e);return f.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},f),{isImageUploadAllowed:g,onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(f.setDocumentError(""),!t.length)return null;if(I(t))return null;f.setIsUploading(!0),f.setIsShowList(!0);const s=t.map((e=>({file:e,id:a.v4()})));s.forEach((({file:e,id:t})=>{f.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e.__awaiter(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,error:o}=yield w.document(Object.assign({formId:l,responseId:c,file:t,sessionId:m},(null==p?void 0:p.workspaceid)&&{workspaceId:p.workspaceid}));if(!e)throw new Error(null!=o?o:"Document processing failed");null==d||d({input:t.name,documentId:i});const n=i.startsWith("IMAGE-");return f.editDocument({id:s,type:n?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i}),{name:t.name,documentId:i}}catch(e){const i=r.default(e);return f.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}})))),o=yield Promise.allSettled(i),n=new Set;for(const e of o)"fulfilled"===e.status&&"error"in e.value&&n.add(e.value.error);n.size>0&&f.setDocumentError([...n].join(", ")),f.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){f.setDocumentError("");let e=t.trim();if(!e)return null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error("Please paste a valid website URL or Youtube video link to add to the knowledge base.");f.setIsUploading(!0),f.setIsShowList(!0),f.setWebsiteLink(""),f.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield w.website(Object.assign({formId:l,responseId:c,website:e},(null==p?void 0:p.workspaceid)&&{workspaceId:p.workspaceid})),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");f.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:i}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:i}}catch(t){const s=r.default(t);if(console.log("[onWebsiteUpload] Error",s),s.includes("Please paste a valid website URL"))return f.setDocumentError(s),null;f.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:s});return{type:"website",id:e,size:0,name:e,status:"failed",error:s}}finally{f.setIsUploading(!1)}}))})};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),l=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),i=require("../../../hooks/pickaxe/useConversation.js"),n=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../Addons/Document/hooks/useDocument.js"),c=require("../Addons/Scroll/hooks/useScroll.js"),u=require("../../../hooks/core/useHover.js"),m=require("../../../common/utils.js"),f=require("../../../common/documents.js"),x=require("eventsource-parser"),p=require("../../Icons/attach-vertical.svg.js"),h=require("../../Icons/spinner-lines.svg.js"),g=require("../../Icons/file.svg.js"),j=require("../../Icons/x.svg.js"),b=require("../../Icons/arrow-right.svg.js"),v=require("../Addons/IceBreaker/index.js"),y=require("../../Core/Textarea.js"),k=require("../../Core/ErrorAlert.js"),w=require("../../../common/error.js"),N=require("../../../common/cn.js");exports.default=({isFocused:I,onFocus:O,onBlur:C})=>{var q;const{formId:S,chatId:R,userId:T,studioUserId:_,embedUserId:A,deploymentId:D,deploymentType:B,pickaxe:E,styles:F,colors:U,responsiveBy:H,isNewChat:z,isRtl:M,setIsNewChat:P,setIsShowIceBreaker:L,onGenerateComplete:$}=r.usePickaxeContext(),{messages:G,status:J,limits:K,isGenerating:W,setMessages:Q,setStatus:V,setLimitData:X,setError:Y}=o.useResponseContext(),{documents:Z,isUploading:ee,isImageUploadAllowed:se,documentError:te,onFileUpload:re,setDocuments:oe,setDocumentError:le,removeDocument:ae}=d.useDocument(),{scrollStartSession:ie,scrollEndSession:ne,scrollToBottom:de}=c.useScroll({auto:!0}),ce=i.useConversation(),ue=n.useSubmit(),[me,fe]=t.useState(""),xe=t.useRef(null),pe=u.useHover(),{isHover:he}=pe,ge=e.__rest(pe,["isHover"]),je=u.useHover(),{isHover:be}=je,ve=e.__rest(je,["isHover"]),ye=a.useStyleFontSize(),ke=l.useStyleInput(),we=t.useMemo((()=>{var e,s,t;return!!z&&(!!E&&(!ce.isLoading&&(!((null!==(s=null===(e=ce.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=E.icebreakers)||void 0===t?void 0:t.length))))}),[E,z,ce.data,ce.isLoading]),Ne=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==J||ee)return;const e=null!=s?s:me;if(!e)return;Y(""),le(""),X(null),fe(""),P(!1),V("fetching"),ie(),de();const t=Z.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),r="enduserupload"===(null==E?void 0:E.documentuploadtype)&&t.length>0,o=[...Array.from(G),Object.assign({id:G.length+1,role:"user",content:e},r&&{documentIds:t})];Q(o),de(),r&&oe([]);const l=(yield ue.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:S,responseId:R,value:e},r&&{documentIds:t}),T&&{userId:T}),_&&{studioUserId:_}),A&&{embedUserId:A}),D&&{deploymentId:D}))).body;if(!l)throw new Error("Streaming error");const a=o.length,i=new TextDecoder,n=l.getReader();let d="",c=!0,u=!1;const m=x.createParser({onEvent:e=>{if("delta"===e.event){const s=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=s,Q([...o.slice(0,a),{id:G.length+1,role:"assistant",content:d}])}else if("error"===e.event){const s=JSON.parse(e.data);Y(s.error||"Something went wrong, please try again.")}else"stop"===e.event&&(c=!1)}});for(;c;){const{value:e,done:s}=yield n.read();if(s){c=!1;break}const t=i.decode(e);t&&(u||(V("streaming"),u=!0),m.feed(t))}null==$||$(R)}catch(e){let s=w.default(e)||"";s&&!s.includes("Unexpected token 'A',")||(s="Oops! We're experiencing high traffic at the moment. Please try again later.");const t=Object.entries(K).find((([e])=>s.includes(e)));t?X(t[1]):Y(s)}finally{de(),V("idle"),ne()}}));return t.useEffect((()=>{L(we)}),[we]),s.jsx("div",Object.assign({className:N.default("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!("chat-input"===B&&z)&&"px-4 pb-4"),dir:M?"rtl":"ltr"},{children:s.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!("chat-input"===B&&z)&&s.jsx("div",Object.assign({className:N.default("absolute bottom-full",M?"left-0":"right-0")},{children:s.jsx("div",Object.assign({className:N.default("flex flex-col gap-2 pb-4 px-2",M?"justify-start":"justify-end","viewport"===H?M?"min-[767px]:items-start":"min-[767px]:items-end":M?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:we&&!I&&s.jsx(v.default,{data:(null==E?void 0:E.icebreakers)||[],onSend:Ne})}))})),s.jsxs("div",Object.assign({className:N.default("flex flex-col gap-y-2 px-4 py-3","block"===F.formFieldStyle&&"shadow"),style:ke},{children:["idle"===J&&Z.length>0&&s.jsx("div",Object.assign({className:N.default("grid grid-cols-1","viewport"===H?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:s.jsx("div",Object.assign({className:"flex flex-row gap-x-2"},{children:Z.filter((e=>"failed"!==e.status)).map((e=>{var r,o,l;return s.jsx(t.Fragment,{children:"document"===e.type?s.jsxs("div",Object.assign({className:N.default("relative gap-x-[10px] flex items-center px-2 h-[56px] border",M&&"flex-row-reverse"),style:{borderRadius:ke.borderRadius,borderColor:U.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:U.accent,borderRadius:ke.borderRadius}},{children:ee?s.jsx(h.default,{className:"w-5 h-5 animate-spin",style:{color:U.accentText}}):s.jsx(g.default,{className:"w-5 h-5",style:{color:U.accentText}})})),s.jsxs("div",Object.assign({className:N.default("flex flex-col justify-center truncate",M?"text-right items-end":"text-left items-start")},{children:[s.jsx("p",Object.assign({className:(N.default(ye.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:N.default(ye.b4,"opacity-80 truncate")},{children:m.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",className:N.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",M?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:U.accent,borderColor:ke.backgroundColor},disabled:ee||"idle"!==J,onClick:()=>ae(e.id)},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:U.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:ke.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:ke.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[2]}/${null===(o=e.documentId)||void 0===o?void 0:o.split("-")[1]}.${null===(l=e.documentId)||void 0===l?void 0:l.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ke.borderRadius,backgroundColor:U.secondary}}),s.jsx("button",Object.assign({type:"button",className:N.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",M?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:U.accent,borderColor:ke.backgroundColor},disabled:ee||"idle"!==J,onClick:()=>ae(e.id)},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:U.accentText}})}))]})):null},e.id)}))}))})),s.jsxs("div",Object.assign({className:N.default("flex items-end gap-x-2",M&&"flex-row-reverse")},{children:[s.jsx(y.default,Object.assign({className:N.default(ye.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!me.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",M?"text-right":"text-left"),value:me,placeholder:M?"بماذا تريد أن تتحدث؟":null!==(q=null==E?void 0:E.placeholdertext)&&void 0!==q?q:"What do you want to talk about?",onChange:e=>fe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ee||"idle"!==J||Ne()))}},O&&{onFocus:O},C&&{onBlur:C},{dir:M?"rtl":"ltr"})),s.jsxs("div",Object.assign({className:N.default("flex items-center gap-x-2")},{children:["enduserupload"===(null==E?void 0:E.documentuploadtype)&&s.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:be?U.accent+"10":void 0},disabled:ee||"idle"!==J,onClick:()=>{var e;return null===(e=xe.current)||void 0===e?void 0:e.click()}},ve,{children:[s.jsx("input",{id:"file-upload",ref:xe,type:"file",accept:[...f.allowedFileMimeTypes,...se?f.allowedImageMimeTypes:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){P(!1),yield re(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(p.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:be?U.accent:U.accent+"80"}})]})),s.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:(he||me.length||Z.length&&Z.every((e=>"finished"===e.status)))&&!W?U.accent:U.accent+"10"},disabled:ee||"idle"!==J,onClick:()=>Ne()},ge,{children:s.jsx(b.default,{className:N.default("h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",M&&"transform scale-x-[-1]"),style:{color:(he||me.length||Z.length&&Z.every((e=>"finished"===e.status)))&&!W?U.accentText:U.accent+"80"}})}))]}))]}))]})),te&&s.jsx(k.default,{error:te,className:"mt-3"})]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),l=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),i=require("../../../hooks/pickaxe/useConversation.js"),n=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../Addons/Document/hooks/useDocument.js"),c=require("../Addons/Scroll/hooks/useScroll.js"),u=require("../../../hooks/core/useHover.js"),m=require("../../../common/utils.js"),f=require("../../../common/documents.js"),x=require("eventsource-parser"),p=require("../../Icons/attach-vertical.svg.js"),h=require("../../Icons/spinner-lines.svg.js"),g=require("../../Icons/file.svg.js"),j=require("../../Icons/x.svg.js"),b=require("../../Icons/arrow-right.svg.js"),v=require("../Addons/IceBreaker/index.js"),y=require("../../Core/Textarea.js"),w=require("../../Core/ErrorAlert.js"),k=require("../../../common/error.js"),N=require("../../../common/cn.js");exports.default=({isFocused:I,onFocus:O,onBlur:C})=>{var q;const{formId:S,chatId:R,userId:T,studioUserId:_,embedUserId:A,deploymentId:D,deploymentType:B,pickaxe:E,styles:F,colors:U,responsiveBy:H,isNewChat:z,isRtl:M,setIsNewChat:P,setIsShowIceBreaker:L,onGenerateComplete:$}=r.usePickaxeContext(),{messages:G,status:J,limits:K,isGenerating:W,setMessages:Q,setStatus:V,setLimitData:X,setError:Y}=o.useResponseContext(),{documents:Z,isUploading:ee,isImageUploadAllowed:se,documentError:te,onFileUpload:re,setDocuments:oe,setDocumentError:le,removeDocument:ae}=d.useDocument(),{scrollStartSession:ie,scrollEndSession:ne,scrollToBottom:de}=c.useScroll({auto:!0}),ce=i.useConversation(),ue=n.useSubmit(),[me,fe]=t.useState(""),xe=t.useRef(null),pe=u.useHover(),{isHover:he}=pe,ge=e.__rest(pe,["isHover"]),je=u.useHover(),{isHover:be}=je,ve=e.__rest(je,["isHover"]),ye=a.useStyleFontSize(),we=l.useStyleInput(),ke=t.useMemo((()=>{var e,s,t;return!!z&&(!!E&&(!ce.isLoading&&(!((null!==(s=null===(e=ce.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=E.icebreakers)||void 0===t?void 0:t.length))))}),[E,z,ce.data,ce.isLoading]),Ne=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==J||ee)return;const e=null!=s?s:me;if(!e)return;Y(""),le(""),X(null),fe(""),P(!1),V("fetching"),ie(),de();const t=Z.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),r="enduserupload"===(null==E?void 0:E.documentuploadtype)&&t.length>0,o=[...Array.from(G),Object.assign({id:G.length+1,role:"user",content:e},r&&{documentIds:t})];Q(o),de(),r&&oe([]);const l=(yield ue.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:S,responseId:R,value:e},r&&{documentIds:t}),T&&{userId:T}),_&&{studioUserId:_}),A&&{embedUserId:A}),D&&{deploymentId:D}))).body;if(!l)throw new Error("Streaming error");const a=o.length,i=new TextDecoder,n=l.getReader();let d="",c=!0,u=!1;const m=x.createParser({onEvent:e=>{if("delta"===e.event){const s=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=s,Q([...o.slice(0,a),{id:G.length+1,role:"assistant",content:d}])}else if("error"===e.event){const s=JSON.parse(e.data);Y(s.error||"Something went wrong, please try again.")}else"stop"===e.event&&(c=!1)}});for(;c;){const{value:e,done:s}=yield n.read();if(s){c=!1;break}const t=i.decode(e);t&&(u||(V("streaming"),u=!0),m.feed(t))}null==$||$(R)}catch(e){let s=k.default(e)||"";s&&!s.includes("Unexpected token 'A',")||(s="Oops! We're experiencing high traffic at the moment. Please try again later.");const t=Object.entries(K).find((([e])=>s.includes(e)));t?X(t[1]):Y(s)}finally{de(),V("idle"),ne()}}));return t.useEffect((()=>{L(ke)}),[ke]),s.jsx("div",Object.assign({className:N.default("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!("chat-input"===B&&z)&&"px-4 pb-4"),dir:M?"rtl":"ltr"},{children:s.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!("chat-input"===B&&z)&&s.jsx("div",Object.assign({className:N.default("absolute bottom-full",M?"left-0":"right-0")},{children:s.jsx("div",Object.assign({className:N.default("flex flex-col gap-2 pb-4 px-2",M?"justify-start":"justify-end","viewport"===H?M?"min-[767px]:items-start":"min-[767px]:items-end":M?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:ke&&!I&&s.jsx(v.default,{data:(null==E?void 0:E.icebreakers)||[],onSend:Ne})}))})),s.jsxs("div",Object.assign({className:N.default("flex flex-col gap-y-2 px-4 py-3","block"===F.formFieldStyle&&"shadow"),style:we},{children:["idle"===J&&Z.length>0&&s.jsx("div",Object.assign({className:"flex flex-row gap-2 flex-wrap"},{children:Z.filter((e=>"failed"!==e.status)).map((e=>{var r,o,l;return s.jsx(t.Fragment,{children:"document"===e.type?s.jsxs("div",Object.assign({className:N.default("relative gap-x-[10px] flex items-center px-2 h-[56px] border",M&&"flex-row-reverse"),style:{borderRadius:we.borderRadius,borderColor:U.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:U.accent,borderRadius:we.borderRadius}},{children:ee?s.jsx(h.default,{className:"w-5 h-5 animate-spin",style:{color:U.accentText}}):s.jsx(g.default,{className:"w-5 h-5",style:{color:U.accentText}})})),s.jsxs("div",Object.assign({className:N.default("flex flex-col justify-center truncate",M?"text-right items-end":"text-left items-start")},{children:[s.jsx("p",Object.assign({className:(N.default(ye.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:N.default(ye.b4,"opacity-80 truncate")},{children:m.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",className:N.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",M?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:U.accent,borderColor:we.backgroundColor},disabled:ee||"idle"!==J,onClick:()=>ae(e.id)},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:U.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:we.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:we.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[2]}/${null===(o=e.documentId)||void 0===o?void 0:o.split("-")[1]}.${null===(l=e.documentId)||void 0===l?void 0:l.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:we.borderRadius,backgroundColor:U.secondary}}),s.jsx("button",Object.assign({type:"button",className:N.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",M?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:U.accent,borderColor:we.backgroundColor},disabled:ee||"idle"!==J,onClick:()=>ae(e.id)},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:U.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:N.default("flex items-end gap-x-2",M&&"flex-row-reverse")},{children:[s.jsx(y.default,Object.assign({className:N.default(ye.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!me.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",M?"text-right":"text-left"),value:me,placeholder:M?"بماذا تريد أن تتحدث؟":null!==(q=null==E?void 0:E.placeholdertext)&&void 0!==q?q:"What do you want to talk about?",onChange:e=>fe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ee||"idle"!==J||Ne()))}},O&&{onFocus:O},C&&{onBlur:C},{dir:M?"rtl":"ltr"})),s.jsxs("div",Object.assign({className:N.default("flex items-center gap-x-2")},{children:["enduserupload"===(null==E?void 0:E.documentuploadtype)&&s.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:be?U.accent+"10":void 0},disabled:ee||"idle"!==J,onClick:()=>{var e;return null===(e=xe.current)||void 0===e?void 0:e.click()}},ve,{children:[s.jsx("input",{id:"file-upload",ref:xe,type:"file",accept:[...f.allowedFileMimeTypes,...se?f.allowedImageMimeTypes:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){P(!1),yield re(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(p.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:be?U.accent:U.accent+"80"}})]})),s.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:(he||me.length||Z.length&&Z.every((e=>"finished"===e.status)))&&!W?U.accent:U.accent+"10"},disabled:ee||"idle"!==J,onClick:()=>Ne()},ge,{children:s.jsx(b.default,{className:N.default("h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",M&&"transform scale-x-[-1]"),style:{color:(he||me.length||Z.length&&Z.every((e=>"finished"===e.status)))&&!W?U.accentText:U.accent+"80"}})}))]}))]}))]})),te&&s.jsx(w.default,{error:te,className:"mt-3"})]}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("../../common/utils.js");exports.useSubmitDocument=()=>({document:({formId:s,workspaceId:o,responseId:i,file:t,isKnowledge:n,isBlocking:r,sessionId:c})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,d;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const a=t.name.split(".").pop(),_=t.type,l={formid:s,mimetype:_,extension:a,responseid:i,workspaceid:o,sessionid:c},p=new URLSearchParams(Object.entries(l).filter((e=>void 0!==e[1]))),u=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${p.toString()}`,O=yield fetch(u),g=yield O.json();if(!g.success)throw new Error(null!==(e=g.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const f=new FormData;Object.entries(Object.assign(Object.assign({},g.fields),{file:t})).forEach((([e,s])=>{f.append(e,s)}));const m=yield fetch(g.url,{method:"POST",body:f});if(!m.ok)throw new Error(m.statusText);const w=`${g.url}${g.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",w),_.startsWith("image"))return{success:!0,documentId:`IMAGE-${g.documentId}-${g.folder}`};const I=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},o&&{workspaceId:o}),{documentId:g.documentId}),i&&{responseId:i}),{fileName:t.name,fileSize:t.size}),n&&{isKnowledge:n}),r&&{isBlocking:r})),headers:{"Content-Type":"application/json"}}),b=yield I.json();if(!b.success)throw new Error(null!==(d=b.error)&&void 0!==d?d:"Failed processing document, try again or contact support.");return b})),website:({formId:o,workspaceId:i,responseId:t,website:n,isKnowledge:r,isBlocking:c})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const d=s.generateId(20),a=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o},i&&{workspaceId:i}),{documentId:d}),t&&{responseId:t}),{website:n}),r&&{isKnowledge:r}),c&&{isBlocking:c})),headers:{"Content-Type":"application/json"}}),_=yield a.json();if(!_.success)throw new Error(null!==(e=_.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return _}))});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("../../common/utils.js");exports.useSubmitDocument=()=>({document:({formId:s,workspaceId:o,responseId:i,file:n,isKnowledge:t,isBlocking:r,sessionId:c})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,d;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const a=n.name.split(".").pop(),l=n.type,_={formid:s,mimetype:l,extension:a,responseid:i,workspaceid:o,sessionid:c},p=new URLSearchParams(Object.entries(_).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),u=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${p.toString()}`,O=yield fetch(u),g=yield O.json();if(!g.success)throw new Error(null!==(e=g.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const f=new FormData;Object.entries(Object.assign(Object.assign({},g.fields),{file:n})).forEach((([e,s])=>{f.append(e,s)}));const m=yield fetch(g.url,{method:"POST",body:f});if(!m.ok)throw new Error(m.statusText);const w=`${g.url}${g.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",w),l.startsWith("image"))return{success:!0,documentId:`IMAGE-${g.documentId}-${g.folder}`};const I=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},o&&{workspaceId:o}),{documentId:g.documentId}),i&&{responseId:i}),{fileName:n.name,fileSize:n.size}),t&&{isKnowledge:t}),r&&{isBlocking:r})),headers:{"Content-Type":"application/json"}}),b=yield I.json();if(!b.success)throw new Error(null!==(d=b.error)&&void 0!==d?d:"Failed processing document, try again or contact support.");return b})),website:({formId:o,workspaceId:i,responseId:n,website:t,isKnowledge:r,isBlocking:c})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const d=s.generateId(20),a=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o},i&&{workspaceId:i}),{documentId:d}),n&&{responseId:n}),{website:t}),r&&{isKnowledge:r}),c&&{isBlocking:c})),headers:{"Content-Type":"application/json"}}),l=yield a.json();if(!l.success)throw new Error(null!==(e=l.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return l}))});
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{useMemo as t}from"react";import{usePickaxeContext as o}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useSubmitDocument as s}from"../../../../../hooks/pickaxe/useSubmitDocument.js";import{useDocumentContext as i}from"./useDocumentContext.js";import{allowedFileMimeTypes as n,allowedImageMimeTypes as r}from"../../../../../common/documents.js";import d from"../../../../../common/error.js";import{v4 as a}from"uuid";const u=["gpt-4o","gpt-4o-mini","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","o1"],l=({onQuestionChange:l}={})=>{const{formId:m,chatId:c,sessionId:p,pickaxe:f}=o(),g=i(),h=s(),I=t((()=>{var e;return u.includes(null!==(e=null==f?void 0:f.model)&&void 0!==e?e:"gpt-3.5-turbo")}),[f]),w=e=>{const t=[...n,...I?r:[]];if(e.some((e=>!t.includes(e.type)))){const e=new Error(I?"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, PNG, JPEG, WEBP, or GIF files. Please try again.":"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, or PPTX files. Please try again."),t=d(e);return g.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},g),{isImageUploadAllowed:I,onFileUpload:t=>e(void 0,void 0,void 0,(function*(){if(g.setDocumentError(""),!t.length)return null;if(w(t))return null;g.setIsUploading(!0),g.setIsShowList(!0);const o=t.map((e=>({file:e,id:a()})));o.forEach((({file:e,id:t})=>{g.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const s=o.map((({file:t,id:o})=>e(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:s,error:i}=yield h.document({formId:m,responseId:c,file:t,sessionId:p});if(!e)throw new Error(null!=i?i:"Document processing failed");null==l||l({input:t.name,documentId:s});const n=s.startsWith("IMAGE-");return g.editDocument({id:o,type:n?"image":"document",name:t.name,size:t.size,status:"finished",documentId:s}),{name:t.name,documentId:s}}catch(e){const s=d(e);return g.editDocument({id:o,name:t.name,size:t.size,status:"failed",error:s}),{error:s}}})))),i=yield Promise.allSettled(s),n=new Set;for(const e of i)"fulfilled"===e.status&&"error"in e.value&&n.add(e.value.error);n.size>0&&g.setDocumentError([...n].join(", ")),g.setIsUploading(!1)})),onWebsiteUpload:t=>e(void 0,void 0,void 0,(function*(){g.setDocumentError("");let e=t.trim();if(!e)return null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error("Please paste a valid website URL or Youtube video link to add to the knowledge base.");g.setIsUploading(!0),g.setIsShowList(!0),g.setWebsiteLink(""),g.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield h.website({formId:m,responseId:c,website:e}),{success:o,documentId:s}=t;if(!o)throw new Error("Website processing failed, please try again.");g.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:s}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:s}}catch(t){const o=d(t);if(console.log("[onWebsiteUpload] Error",o),o.includes("Please paste a valid website URL"))return g.setDocumentError(o),null;g.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:o});return{type:"website",id:e,size:0,name:e,status:"failed",error:o}}finally{g.setIsUploading(!1)}}))})};export{l as useDocument};
1
+ import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{useMemo as t}from"react";import{usePickaxeContext as o}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useSubmitDocument as s}from"../../../../../hooks/pickaxe/useSubmitDocument.js";import{useDocumentContext as i}from"./useDocumentContext.js";import{allowedFileMimeTypes as n,allowedImageMimeTypes as r}from"../../../../../common/documents.js";import d from"../../../../../common/error.js";import{v4 as a}from"uuid";const u=["gpt-4o","gpt-4o-mini","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","o1"],l=({onQuestionChange:l}={})=>{const{formId:c,chatId:m,sessionId:p,pickaxe:f}=o(),g=i(),w=s(),I=t((()=>{var e;return u.includes(null!==(e=null==f?void 0:f.model)&&void 0!==e?e:"gpt-3.5-turbo")}),[f]),h=e=>{const t=[...n,...I?r:[]];if(e.some((e=>!t.includes(e.type)))){const e=new Error(I?"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, PNG, JPEG, WEBP, or GIF files. Please try again.":"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, or PPTX files. Please try again."),t=d(e);return g.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},g),{isImageUploadAllowed:I,onFileUpload:t=>e(void 0,void 0,void 0,(function*(){if(g.setDocumentError(""),!t.length)return null;if(h(t))return null;g.setIsUploading(!0),g.setIsShowList(!0);const o=t.map((e=>({file:e,id:a()})));o.forEach((({file:e,id:t})=>{g.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const s=o.map((({file:t,id:o})=>e(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:s,error:i}=yield w.document(Object.assign({formId:c,responseId:m,file:t,sessionId:p},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}));if(!e)throw new Error(null!=i?i:"Document processing failed");null==l||l({input:t.name,documentId:s});const n=s.startsWith("IMAGE-");return g.editDocument({id:o,type:n?"image":"document",name:t.name,size:t.size,status:"finished",documentId:s}),{name:t.name,documentId:s}}catch(e){const s=d(e);return g.editDocument({id:o,name:t.name,size:t.size,status:"failed",error:s}),{error:s}}})))),i=yield Promise.allSettled(s),n=new Set;for(const e of i)"fulfilled"===e.status&&"error"in e.value&&n.add(e.value.error);n.size>0&&g.setDocumentError([...n].join(", ")),g.setIsUploading(!1)})),onWebsiteUpload:t=>e(void 0,void 0,void 0,(function*(){g.setDocumentError("");let e=t.trim();if(!e)return null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error("Please paste a valid website URL or Youtube video link to add to the knowledge base.");g.setIsUploading(!0),g.setIsShowList(!0),g.setWebsiteLink(""),g.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield w.website(Object.assign({formId:c,responseId:m,website:e},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid})),{success:o,documentId:s}=t;if(!o)throw new Error("Website processing failed, please try again.");g.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:s}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:s}}catch(t){const o=d(t);if(console.log("[onWebsiteUpload] Error",o),o.includes("Please paste a valid website URL"))return g.setDocumentError(o),null;g.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:o});return{type:"website",id:e,size:0,name:e,status:"failed",error:o}}finally{g.setIsUploading(!1)}}))})};export{l as useDocument};
@@ -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 r,useRef as i,useMemo as n,useEffect as l,Fragment as a}from"react";import{usePickaxeContext as c}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as h}from"../Addons/Document/hooks/useDocument.js";import{useScroll as g}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as b}from"../../../hooks/core/useHover.js";import{formatBytes as v}from"../../../common/utils.js";import{allowedFileMimeTypes as x,allowedImageMimeTypes as y}from"../../../common/documents.js";import{createParser as j}from"eventsource-parser";import k from"../../Icons/attach-vertical.svg.js";import w from"../../Icons/spinner-lines.svg.js";import N from"../../Icons/file.svg.js";import I from"../../Icons/x.svg.js";import O from"../../Icons/arrow-right.svg.js";import C from"../Addons/IceBreaker/index.js";import S from"../../Core/Textarea.js";import R from"../../Core/ErrorAlert.js";import A from"../../../common/error.js";import T from"../../../common/cn.js";const D=({isFocused:D,onFocus:B,onBlur:E})=>{var U;const{formId:F,chatId:H,userId:z,studioUserId:L,embedUserId:$,deploymentId:G,deploymentType:J,pickaxe:K,styles:P,colors:W,responsiveBy:_,isNewChat:M,isRtl:q,setIsNewChat:Q,setIsShowIceBreaker:V,onGenerateComplete:X}=c(),{messages:Y,status:Z,limits:ee,isGenerating:te,setMessages:se,setStatus:oe,setLimitData:re,setError:ie}=d(),{documents:ne,isUploading:le,isImageUploadAllowed:ae,documentError:ce,onFileUpload:de,setDocuments:ue,setDocumentError:me,removeDocument:pe}=h(),{scrollStartSession:fe,scrollEndSession:he,scrollToBottom:ge}=g({auto:!0}),be=p(),ve=f(),[xe,ye]=r(""),je=i(null),ke=b(),{isHover:we}=ke,Ne=e(ke,["isHover"]),Ie=b(),{isHover:Oe}=Ie,Ce=e(Ie,["isHover"]),Se=m(),Re=u(),Ae=n((()=>{var e,t,s;return!!M&&(!!K&&(!be.isLoading&&(!((null!==(t=null===(e=be.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=K.icebreakers)||void 0===s?void 0:s.length))))}),[K,M,be.data,be.isLoading]),Te=e=>t(void 0,void 0,void 0,(function*(){try{if("idle"!==Z||le)return;const t=null!=e?e:xe;if(!t)return;ie(""),me(""),re(null),ye(""),Q(!1),oe("fetching"),fe(),ge();const s=ne.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),o="enduserupload"===(null==K?void 0:K.documentuploadtype)&&s.length>0,r=[...Array.from(Y),Object.assign({id:Y.length+1,role:"user",content:t},o&&{documentIds:s})];se(r),ge(),o&&ue([]);const i=(yield ve.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,value:t},o&&{documentIds:s}),z&&{userId:z}),L&&{studioUserId:L}),$&&{embedUserId:$}),G&&{deploymentId:G}))).body;if(!i)throw new Error("Streaming error");const n=r.length,l=new TextDecoder,a=i.getReader();let c="",d=!0,u=!1;const m=j({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");c+=t,se([...r.slice(0,n),{id:Y.length+1,role:"assistant",content:c}])}else if("error"===e.event){const t=JSON.parse(e.data);ie(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(d=!1)}});for(;d;){const{value:e,done:t}=yield a.read();if(t){d=!1;break}const s=l.decode(e);s&&(u||(oe("streaming"),u=!0),m.feed(s))}null==X||X(H)}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(ee).find((([e])=>t.includes(e)));s?re(s[1]):ie(t)}finally{ge(),oe("idle"),he()}}));return l((()=>{V(Ae)}),[Ae]),s("div",Object.assign({className:T("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!("chat-input"===J&&M)&&"px-4 pb-4"),dir:q?"rtl":"ltr"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!("chat-input"===J&&M)&&s("div",Object.assign({className:T("absolute bottom-full",q?"left-0":"right-0")},{children:s("div",Object.assign({className:T("flex flex-col gap-2 pb-4 px-2",q?"justify-start":"justify-end","viewport"===_?q?"min-[767px]:items-start":"min-[767px]:items-end":q?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:Ae&&!D&&s(C,{data:(null==K?void 0:K.icebreakers)||[],onSend:Te})}))})),o("div",Object.assign({className:T("flex flex-col gap-y-2 px-4 py-3","block"===P.formFieldStyle&&"shadow"),style:Re},{children:["idle"===Z&&ne.length>0&&s("div",Object.assign({className:T("grid grid-cols-1","viewport"===_?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:s("div",Object.assign({className:"flex flex-row gap-x-2"},{children:ne.filter((e=>"failed"!==e.status)).map((e=>{var t,r,i;return s(a,{children:"document"===e.type?o("div",Object.assign({className:T("relative gap-x-[10px] flex items-center px-2 h-[56px] border",q&&"flex-row-reverse"),style:{borderRadius:Re.borderRadius,borderColor:W.secondaryText+"50"}},{children:[s("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:W.accent,borderRadius:Re.borderRadius}},{children:le?s(w,{className:"w-5 h-5 animate-spin",style:{color:W.accentText}}):s(N,{className:"w-5 h-5",style:{color:W.accentText}})})),o("div",Object.assign({className:T("flex flex-col justify-center truncate",q?"text-right items-end":"text-left items-start")},{children:[s("p",Object.assign({className:(T(Se.b3),"font-medium truncate")},{children:e.name})),s("p",Object.assign({className:T(Se.b4,"opacity-80 truncate")},{children:v(e.size)}))]})),s("button",Object.assign({type:"button",className:T("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",q?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:W.accent,borderColor:Re.backgroundColor},disabled:le||"idle"!==Z,onClick:()=>pe(e.id)},{children:s(I,{className:"w-4 h-4",style:{color:W.accentText}})}))]})):"image"===e.type?o("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:Re.borderRadius}},{children:["finished"===e.status?s("img",{style:{borderRadius:Re.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(t=e.documentId)||void 0===t?void 0:t.split("-")[2]}/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[1]}.${null===(i=e.documentId)||void 0===i?void 0:i.split("-")[2]}`,alt:""}):s("div",{className:"h-full w-full animate-pulse",style:{borderRadius:Re.borderRadius,backgroundColor:W.secondary}}),s("button",Object.assign({type:"button",className:T("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",q?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:W.accent,borderColor:Re.backgroundColor},disabled:le||"idle"!==Z,onClick:()=>pe(e.id)},{children:s(I,{className:"w-4 h-4",style:{color:W.accentText}})}))]})):null},e.id)}))}))})),o("div",Object.assign({className:T("flex items-end gap-x-2",q&&"flex-row-reverse")},{children:[s(S,Object.assign({className:T(Se.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!xe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",q?"text-right":"text-left"),value:xe,placeholder:q?"بماذا تريد أن تتحدث؟":null!==(U=null==K?void 0:K.placeholdertext)&&void 0!==U?U:"What do you want to talk about?",onChange:e=>ye(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),le||"idle"!==Z||Te()))}},B&&{onFocus:B},E&&{onBlur:E},{dir:q?"rtl":"ltr"})),o("div",Object.assign({className:T("flex items-center gap-x-2")},{children:["enduserupload"===(null==K?void 0:K.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:Oe?W.accent+"10":void 0},disabled:le||"idle"!==Z,onClick:()=>{var e;return null===(e=je.current)||void 0===e?void 0:e.click()}},Ce,{children:[s("input",{id:"file-upload",ref:je,type:"file",accept:[...x,...ae?y:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){Q(!1),yield de(Array.from(e.target.files||[])),e.target.value=""}))}),s(k,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Oe?W.accent:W.accent+"80"}})]})),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:(we||xe.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!te?W.accent:W.accent+"10"},disabled:le||"idle"!==Z,onClick:()=>Te()},Ne,{children:s(O,{className:T("h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",q&&"transform scale-x-[-1]"),style:{color:(we||xe.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!te?W.accentText:W.accent+"80"}})}))]}))]}))]})),ce&&s(R,{error:ce,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 r,useRef as i,useMemo as n,useEffect as l,Fragment as a}from"react";import{usePickaxeContext as c}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as h}from"../Addons/Document/hooks/useDocument.js";import{useScroll as g}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as b}from"../../../hooks/core/useHover.js";import{formatBytes as v}from"../../../common/utils.js";import{allowedFileMimeTypes as x,allowedImageMimeTypes as y}from"../../../common/documents.js";import{createParser as j}from"eventsource-parser";import k from"../../Icons/attach-vertical.svg.js";import w from"../../Icons/spinner-lines.svg.js";import N from"../../Icons/file.svg.js";import I from"../../Icons/x.svg.js";import O from"../../Icons/arrow-right.svg.js";import C from"../Addons/IceBreaker/index.js";import S from"../../Core/Textarea.js";import R from"../../Core/ErrorAlert.js";import A from"../../../common/error.js";import T from"../../../common/cn.js";const D=({isFocused:D,onFocus:B,onBlur:E})=>{var U;const{formId:F,chatId:H,userId:z,studioUserId:L,embedUserId:$,deploymentId:G,deploymentType:J,pickaxe:K,styles:P,colors:W,responsiveBy:_,isNewChat:M,isRtl:q,setIsNewChat:Q,setIsShowIceBreaker:V,onGenerateComplete:X}=c(),{messages:Y,status:Z,limits:ee,isGenerating:te,setMessages:se,setStatus:oe,setLimitData:re,setError:ie}=d(),{documents:ne,isUploading:le,isImageUploadAllowed:ae,documentError:ce,onFileUpload:de,setDocuments:ue,setDocumentError:me,removeDocument:pe}=h(),{scrollStartSession:fe,scrollEndSession:he,scrollToBottom:ge}=g({auto:!0}),be=p(),ve=f(),[xe,ye]=r(""),je=i(null),ke=b(),{isHover:we}=ke,Ne=e(ke,["isHover"]),Ie=b(),{isHover:Oe}=Ie,Ce=e(Ie,["isHover"]),Se=m(),Re=u(),Ae=n((()=>{var e,t,s;return!!M&&(!!K&&(!be.isLoading&&(!((null!==(t=null===(e=be.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=K.icebreakers)||void 0===s?void 0:s.length))))}),[K,M,be.data,be.isLoading]),Te=e=>t(void 0,void 0,void 0,(function*(){try{if("idle"!==Z||le)return;const t=null!=e?e:xe;if(!t)return;ie(""),me(""),re(null),ye(""),Q(!1),oe("fetching"),fe(),ge();const s=ne.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)).map((e=>e.documentId)).filter(Boolean),o="enduserupload"===(null==K?void 0:K.documentuploadtype)&&s.length>0,r=[...Array.from(Y),Object.assign({id:Y.length+1,role:"user",content:t},o&&{documentIds:s})];se(r),ge(),o&&ue([]);const i=(yield ve.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,value:t},o&&{documentIds:s}),z&&{userId:z}),L&&{studioUserId:L}),$&&{embedUserId:$}),G&&{deploymentId:G}))).body;if(!i)throw new Error("Streaming error");const n=r.length,l=new TextDecoder,a=i.getReader();let c="",d=!0,u=!1;const m=j({onEvent:e=>{if("delta"===e.event){const t=JSON.parse(e.data).token.replace(/\u200B/g,"");c+=t,se([...r.slice(0,n),{id:Y.length+1,role:"assistant",content:c}])}else if("error"===e.event){const t=JSON.parse(e.data);ie(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(d=!1)}});for(;d;){const{value:e,done:t}=yield a.read();if(t){d=!1;break}const s=l.decode(e);s&&(u||(oe("streaming"),u=!0),m.feed(s))}null==X||X(H)}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(ee).find((([e])=>t.includes(e)));s?re(s[1]):ie(t)}finally{ge(),oe("idle"),he()}}));return l((()=>{V(Ae)}),[Ae]),s("div",Object.assign({className:T("w-full flex flex-col items-center absolute bottom-0 left-0 z-1",!("chat-input"===J&&M)&&"px-4 pb-4"),dir:q?"rtl":"ltr"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[!("chat-input"===J&&M)&&s("div",Object.assign({className:T("absolute bottom-full",q?"left-0":"right-0")},{children:s("div",Object.assign({className:T("flex flex-col gap-2 pb-4 px-2",q?"justify-start":"justify-end","viewport"===_?q?"min-[767px]:items-start":"min-[767px]:items-end":q?"@[767px]/pickaxe-root:items-start":"@[767px]/pickaxe-root:items-end")},{children:Ae&&!D&&s(C,{data:(null==K?void 0:K.icebreakers)||[],onSend:Te})}))})),o("div",Object.assign({className:T("flex flex-col gap-y-2 px-4 py-3","block"===P.formFieldStyle&&"shadow"),style:Re},{children:["idle"===Z&&ne.length>0&&s("div",Object.assign({className:"flex flex-row gap-2 flex-wrap"},{children:ne.filter((e=>"failed"!==e.status)).map((e=>{var t,r,i;return s(a,{children:"document"===e.type?o("div",Object.assign({className:T("relative gap-x-[10px] flex items-center px-2 h-[56px] border",q&&"flex-row-reverse"),style:{borderRadius:Re.borderRadius,borderColor:W.secondaryText+"50"}},{children:[s("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:W.accent,borderRadius:Re.borderRadius}},{children:le?s(w,{className:"w-5 h-5 animate-spin",style:{color:W.accentText}}):s(N,{className:"w-5 h-5",style:{color:W.accentText}})})),o("div",Object.assign({className:T("flex flex-col justify-center truncate",q?"text-right items-end":"text-left items-start")},{children:[s("p",Object.assign({className:(T(Se.b3),"font-medium truncate")},{children:e.name})),s("p",Object.assign({className:T(Se.b4,"opacity-80 truncate")},{children:v(e.size)}))]})),s("button",Object.assign({type:"button",className:T("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",q?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:W.accent,borderColor:Re.backgroundColor},disabled:le||"idle"!==Z,onClick:()=>pe(e.id)},{children:s(I,{className:"w-4 h-4",style:{color:W.accentText}})}))]})):"image"===e.type?o("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:Re.borderRadius}},{children:["finished"===e.status?s("img",{style:{borderRadius:Re.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(t=e.documentId)||void 0===t?void 0:t.split("-")[2]}/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[1]}.${null===(i=e.documentId)||void 0===i?void 0:i.split("-")[2]}`,alt:""}):s("div",{className:"h-full w-full animate-pulse",style:{borderRadius:Re.borderRadius,backgroundColor:W.secondary}}),s("button",Object.assign({type:"button",className:T("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center border outline-none disabled:cursor-default",q?"-left-2 right-auto":"-right-2 left-auto"),style:{backgroundColor:W.accent,borderColor:Re.backgroundColor},disabled:le||"idle"!==Z,onClick:()=>pe(e.id)},{children:s(I,{className:"w-4 h-4",style:{color:W.accentText}})}))]})):null},e.id)}))})),o("div",Object.assign({className:T("flex items-end gap-x-2",q&&"flex-row-reverse")},{children:[s(S,Object.assign({className:T(Se.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!xe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap",q?"text-right":"text-left"),value:xe,placeholder:q?"بماذا تريد أن تتحدث؟":null!==(U=null==K?void 0:K.placeholdertext)&&void 0!==U?U:"What do you want to talk about?",onChange:e=>ye(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),le||"idle"!==Z||Te()))}},B&&{onFocus:B},E&&{onBlur:E},{dir:q?"rtl":"ltr"})),o("div",Object.assign({className:T("flex items-center gap-x-2")},{children:["enduserupload"===(null==K?void 0:K.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:Oe?W.accent+"10":void 0},disabled:le||"idle"!==Z,onClick:()=>{var e;return null===(e=je.current)||void 0===e?void 0:e.click()}},Ce,{children:[s("input",{id:"file-upload",ref:je,type:"file",accept:[...x,...ae?y:[]].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){Q(!1),yield de(Array.from(e.target.files||[])),e.target.value=""}))}),s(k,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Oe?W.accent:W.accent+"80"}})]})),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:(we||xe.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!te?W.accent:W.accent+"10"},disabled:le||"idle"!==Z,onClick:()=>Te()},Ne,{children:s(O,{className:T("h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",q&&"transform scale-x-[-1]"),style:{color:(we||xe.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!te?W.accentText:W.accent+"80"}})}))]}))]}))]})),ce&&s(R,{error:ce,className:"mt-3"})]}))}))};export{D as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{generateId as s}from"../../common/utils.js";const o=()=>({document:({formId:s,workspaceId:o,responseId:n,file:i,isKnowledge:t,isBlocking:r,sessionId:c})=>e(void 0,void 0,void 0,(function*(){var e,d;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const a=i.name.split(".").pop(),l=i.type,p={formid:s,mimetype:l,extension:a,responseid:n,workspaceid:o,sessionid:c},_=new URLSearchParams(Object.entries(p).filter((e=>void 0!==e[1]))),O=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${_.toString()}`,g=yield fetch(O),f=yield g.json();if(!f.success)throw new Error(null!==(e=f.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const m=new FormData;Object.entries(Object.assign(Object.assign({},f.fields),{file:i})).forEach((([e,s])=>{m.append(e,s)}));const u=yield fetch(f.url,{method:"POST",body:m});if(!u.ok)throw new Error(u.statusText);const w=`${f.url}${f.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",w),l.startsWith("image"))return{success:!0,documentId:`IMAGE-${f.documentId}-${f.folder}`};const I=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},o&&{workspaceId:o}),{documentId:f.documentId}),n&&{responseId:n}),{fileName:i.name,fileSize:i.size}),t&&{isKnowledge:t}),r&&{isBlocking:r})),headers:{"Content-Type":"application/json"}}),P=yield I.json();if(!P.success)throw new Error(null!==(d=P.error)&&void 0!==d?d:"Failed processing document, try again or contact support.");return P})),website:({formId:o,workspaceId:n,responseId:i,website:t,isKnowledge:r,isBlocking:c})=>e(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const d=s(20),a=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o},n&&{workspaceId:n}),{documentId:d}),i&&{responseId:i}),{website:t}),r&&{isKnowledge:r}),c&&{isBlocking:c})),headers:{"Content-Type":"application/json"}}),l=yield a.json();if(!l.success)throw new Error(null!==(e=l.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return l}))});export{o as useSubmitDocument};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{generateId as s}from"../../common/utils.js";const o=()=>({document:({formId:s,workspaceId:o,responseId:n,file:i,isKnowledge:t,isBlocking:r,sessionId:c})=>e(void 0,void 0,void 0,(function*(){var e,d;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const a=i.name.split(".").pop(),l=i.type,p={formid:s,mimetype:l,extension:a,responseid:n,workspaceid:o,sessionid:c},_=new URLSearchParams(Object.entries(p).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),O=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${_.toString()}`,g=yield fetch(O),f=yield g.json();if(!f.success)throw new Error(null!==(e=f.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const m=new FormData;Object.entries(Object.assign(Object.assign({},f.fields),{file:i})).forEach((([e,s])=>{m.append(e,s)}));const u=yield fetch(f.url,{method:"POST",body:m});if(!u.ok)throw new Error(u.statusText);const w=`${f.url}${f.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",w),l.startsWith("image"))return{success:!0,documentId:`IMAGE-${f.documentId}-${f.folder}`};const I=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},o&&{workspaceId:o}),{documentId:f.documentId}),n&&{responseId:n}),{fileName:i.name,fileSize:i.size}),t&&{isKnowledge:t}),r&&{isBlocking:r})),headers:{"Content-Type":"application/json"}}),P=yield I.json();if(!P.success)throw new Error(null!==(d=P.error)&&void 0!==d?d:"Failed processing document, try again or contact support.");return P})),website:({formId:o,workspaceId:n,responseId:i,website:t,isKnowledge:r,isBlocking:c})=>e(void 0,void 0,void 0,(function*(){var e;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const d=s(20),a=yield fetch(`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/process_document`,{method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:o},n&&{workspaceId:n}),{documentId:d}),i&&{responseId:i}),{website:t}),r&&{isKnowledge:r}),c&&{isBlocking:c})),headers:{"Content-Type":"application/json"}}),l=yield a.json();if(!l.success)throw new Error(null!==(e=l.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return l}))});export{o as useSubmitDocument};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",