@pickaxeproject/react 4.2.0 → 4.2.2

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";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var s=e(require("axios"));const n=process.env.NEXT_PUBLIC_PICKAXE_API_URL||"";if(!n)throw new Error("[px/react] NEXT_PUBLIC_PICKAXE_API_URL is not defined");const o="undefined"!=typeof window?window.location.hostname:"",t="undefined"!=typeof window?window.location.href:"",i=o.includes("pickaxe.co")&&!t.includes("https://studio.pickaxe.co/_embed"),c=s.default.create(Object.assign(Object.assign({baseURL:n},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),i&&{withCredentials:!0}));exports.default=c;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var n=e(require("axios"));const o=process.env.NEXT_PUBLIC_PICKAXE_API_URL||"";if(!o)throw new Error("[px/react] NEXT_PUBLIC_PICKAXE_API_URL is not defined");const s="undefined"!=typeof window?window.location.hostname:"",t="undefined"!=typeof window?window.location.href:"",i="undefined"!=typeof window&&window.self!==window.top,d=s.includes("pickaxe.co")&&!t.includes("https://studio.pickaxe.co/_embed")&&!i,c=n.default.create(Object.assign(Object.assign({baseURL:o},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),d&&{withCredentials:!0}));exports.default=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/studio/useStyleFontSize.js"),l=require("./hooks/useDocument.js"),r=require("../../../../common/utils.js"),i=require("../../../Icons/spinner-lines.svg.js"),c=require("../../../Icons/file.svg.js"),o=require("../../../Icons/x.svg.js"),n=require("../../../Icons/circle-info.svg.js"),d=require("../../../../common/cn.js");exports.default=({className:u,isDisabled:f})=>{const{styles:h,colors:m,translations:x,isRtl:j}=t.usePickaxeContext(),{documents:b,isUploading:g,removeDocument:p}=l.useDocument(),v=a.useStyleFontSize();return e.jsx("div",Object.assign({className:d.default("flex flex-row gap-3 flex-wrap",u)},{children:b.map(((t,a)=>{var l,u,b,k,y,w,N;return e.jsx(s.Fragment,{children:"document"===t.type?e.jsxs("div",Object.assign({className:d.default("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",j&&"flex-row-reverse"),style:{borderRadius:h.cornerRadius,borderColor:m.secondaryText+"50"}},{children:[e.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:"uploading"===t.status?e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(c.default,{className:"w-5 h-5 shrink-0"})})),e.jsxs("div",Object.assign({className:d.default("flex flex-col justify-center truncate",j?"text-right items-end":"text-left items-start")},{children:[e.jsx("p",Object.assign({className:d.default(v.b3,"font-medium truncate")},{children:t.name})),e.jsx("p",Object.assign({className:d.default(v.b4,"opacity-80 truncate")},{children:"failed"===t.status?(null===(l=t.error)||void 0===l?void 0:l.includes("You have reached the file limit"))?null!==(u=null==x?void 0:x["file-limit-reached"])&&void 0!==u?u:"You have reached the file limit.":t.error:r.formatBytes(t.size)}))]})),!g&&e.jsx("button",Object.assign({type:"button",className:d.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):"image"===t.type?e.jsxs("div",Object.assign({className:"relative h-[56px] flex flex-col items-center justify-center w-[56px]",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:["finished"===t.status?e.jsx("img",{className:"object-cover w-full h-full",style:{borderRadius:h.cornerRadius},src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(b=t.documentId)||void 0===b?void 0:b.split("-")[2]}/${null===(k=t.documentId)||void 0===k?void 0:k.split("-")[1]}.${null===(y=t.documentId)||void 0===y?void 0:y.split("-")[2]}`,alt:""}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}),!g&&e.jsx("button",Object.assign({type:"button",className:d.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):"website"===t.type?e.jsxs("div",Object.assign({className:d.default("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",j&&"flex-row-reverse"),style:{borderRadius:h.cornerRadius,borderColor:m.secondaryText+"50"}},{children:[e.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:"uploading"===t.status?e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(c.default,{className:"w-5 h-5 shrink-0"})})),e.jsxs("div",Object.assign({className:d.default("flex flex-col justify-center truncate",j?"text-right items-end":"text-left items-start")},{children:[e.jsx("p",Object.assign({className:d.default(v.b3,"font-medium truncate")},{children:t.name})),e.jsx("p",Object.assign({className:d.default(v.b4,"opacity-80 truncate")},{children:"failed"===t.status?(null===(w=t.error)||void 0===w?void 0:w.includes("You have reached the file limit"))?null!==(N=null==x?void 0:x["file-limit-reached"])&&void 0!==N?N:"You have reached the file limit.":t.error:"Website "}))]})),!g&&e.jsx("button",Object.assign({type:"button",className:d.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):null},a)}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/studio/useStyleFontSize.js"),r=require("./hooks/useDocument.js"),l=require("../../../../common/utils.js"),i=require("../../../Icons/spinner-lines.svg.js"),c=require("../../../Icons/file.svg.js"),o=require("../../../Icons/x.svg.js"),n=require("../../../Icons/circle-info.svg.js"),u=require("../../../../common/cn.js");exports.default=({className:d,isDisabled:f})=>{const{styles:h,colors:m,translations:x,isRtl:j}=t.usePickaxeContext(),{documents:b,isUploading:g,removeDocument:p}=r.useDocument(),v=a.useStyleFontSize();return e.jsx("div",Object.assign({className:u.default("flex flex-row gap-3 flex-wrap",d)},{children:b.map(((t,a)=>{var r,d,b,k,y,w;return e.jsx(s.Fragment,{children:"document"===t.type?e.jsxs("div",Object.assign({className:u.default("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",j&&"flex-row-reverse"),style:{borderRadius:h.cornerRadius,borderColor:m.secondaryText+"50"}},{children:[e.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:"uploading"===t.status?e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(c.default,{className:"w-5 h-5 shrink-0"})})),e.jsxs("div",Object.assign({className:u.default("flex flex-col justify-center truncate",j?"text-right items-end":"text-left items-start")},{children:[e.jsx("p",Object.assign({className:u.default(v.b3,"font-medium truncate")},{children:t.name})),e.jsx("p",Object.assign({className:u.default(v.b4,"opacity-80 truncate")},{children:"failed"===t.status?(null===(r=t.error)||void 0===r?void 0:r.includes("You have reached the file limit"))?null!==(d=null==x?void 0:x["file-limit-reached"])&&void 0!==d?d:"You have reached the file limit.":t.error:l.formatBytes(t.size)}))]})),!g&&e.jsx("button",Object.assign({type:"button",className:u.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):"image"===t.type?e.jsxs("div",Object.assign({className:"relative h-[56px] flex flex-col items-center justify-center w-[56px]",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:["finished"===t.status?e.jsx("img",{className:"object-cover w-full h-full",style:{borderRadius:h.cornerRadius},src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null!==(b=t.folder)&&void 0!==b?b:"jpg"}/${t.documentId}.${null!==(k=t.folder)&&void 0!==k?k:"jpg"}`,alt:""}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}),!g&&e.jsx("button",Object.assign({type:"button",className:u.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):"website"===t.type?e.jsxs("div",Object.assign({className:u.default("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",j&&"flex-row-reverse"),style:{borderRadius:h.cornerRadius,borderColor:m.secondaryText+"50"}},{children:[e.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:h.cornerRadius,backgroundColor:m.accent,color:m.accentText},"failed"===t.status&&{backgroundColor:m.error,color:"white"})},{children:"uploading"===t.status?e.jsx(i.default,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===t.status?e.jsx(n.default,{className:"w-5 h-5 shrink-0"}):e.jsx(c.default,{className:"w-5 h-5 shrink-0"})})),e.jsxs("div",Object.assign({className:u.default("flex flex-col justify-center truncate",j?"text-right items-end":"text-left items-start")},{children:[e.jsx("p",Object.assign({className:u.default(v.b3,"font-medium truncate")},{children:t.name})),e.jsx("p",Object.assign({className:u.default(v.b4,"opacity-80 truncate")},{children:"failed"===t.status?(null===(y=t.error)||void 0===y?void 0:y.includes("You have reached the file limit"))?null!==(w=null==x?void 0:x["file-limit-reached"])&&void 0!==w?w:"You have reached the file limit.":t.error:"Website "}))]})),!g&&e.jsx("button",Object.assign({type:"button",className:u.default("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",j?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:m.accent,color:m.accentText},disabled:g||f,onClick:()=>p(t.id)},{children:e.jsx(o.default,{className:"w-4 h-4 shrink-0"})}))]})):null},a)}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../Auth/hooks/useAuthContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),n=require("./useDocumentContext.js"),o=require("../../../../../common/documents.js"),r=require("uuid"),d=require("../../../../../common/error.js");exports.useDocument=({onQuestionChange:u}={})=>{const{contextId:a,pickaxeId:c,sessionId:l,sender:m,senderType:p,pickaxe:f}=t.usePickaxeContext(),{token:w}=s.useAuthContext(),I=n.useDocumentContext(),h=i.useSubmitDocument(),b=e=>{const t=[...o.allowedFileMimeTypes,...o.allowedImageMimeTypes];if(e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&o.additionalAllowedFileExtensions.includes(`.${t}`))return!1}return!0}))){const e=new Error("You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again."),t=d.default(e);return I.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},I),{onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(I.setDocumentError(""),!t.length)return null;if(b(t))return null;I.setIsUploading(!0),I.setIsShowList(!0);const s=t.map((e=>({file:e,id:r.v4()})));s.forEach((({file:e,id:t})=>{I.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:n}=yield h.document(Object.assign(Object.assign(Object.assign({contextId:a,pickaxeId:c,sessionId:l,file:t},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),w&&{studioSessionToken:w}));if(!e)throw new Error(null!=n?n:"Document processing failed");null==u||u({input:t.name,documentId:i});const o=i.startsWith("IMAGE-");return I.editDocument({id:s,type:o?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i}),{name:t.name,documentId:i}}catch(e){const i=d.default(e);return I.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),I.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){I.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.");I.setIsUploading(!0),I.setIsShowList(!0),I.setWebsiteLink(""),I.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield h.website(Object.assign(Object.assign(Object.assign({pickaxeId:c,sessionId:l,website:e},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),w&&{studioSessionToken:w})),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");I.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=d.default(t);if(s.includes("Please paste a valid website URL"))return I.setDocumentError(s),null;I.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{I.setIsUploading(!1)}}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../Auth/hooks/useAuthContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),o=require("./useDocumentContext.js"),n=require("../../../../../common/documents.js"),r=require("uuid"),d=require("../../../../../common/error.js");exports.useDocument=({onQuestionChange:a}={})=>{const{contextId:u,pickaxeId:c,sessionId:l,sender:m,senderType:p,pickaxe:f}=t.usePickaxeContext(),{token:w}=s.useAuthContext(),I=o.useDocumentContext(),h=i.useSubmitDocument(),b=e=>{const t=[...n.allowedFileMimeTypes,...n.allowedImageMimeTypes];if(e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&n.additionalAllowedFileExtensions.includes(`.${t}`))return!1}return!0}))){const e=new Error("You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again."),t=d.default(e);return I.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},I),{onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(I.setDocumentError(""),!t.length)return null;if(b(t))return null;I.setIsUploading(!0),I.setIsShowList(!0);const s=t.map((e=>({file:e,id:r.v4()})));s.forEach((({file:e,id:t})=>{I.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,folder:o,error:r}=yield h.document(Object.assign(Object.assign(Object.assign({contextId:u,pickaxeId:c,sessionId:l,file:t},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),w&&{studioSessionToken:w}));if(!e)throw new Error(null!=r?r:"Document processing failed");null==a||a({input:t.name,documentId:i});const d=i.startsWith("IMAGE-")||n.allowedImageMimeTypes.includes(t.type);return I.editDocument(Object.assign({id:s,type:d?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i},d&&o&&{folder:o})),{name:t.name,documentId:i}}catch(e){const i=d.default(e);return I.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),I.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){I.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.");I.setIsUploading(!0),I.setIsShowList(!0),I.setWebsiteLink(""),I.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield h.website(Object.assign(Object.assign(Object.assign({pickaxeId:c,sessionId:l,website:e},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),w&&{studioSessionToken:w})),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");I.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=d.default(t);if(s.includes("Please paste a valid website URL"))return I.setDocumentError(s),null;I.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{I.setIsUploading(!1)}}))})};
@@ -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:({contextId:s,pickaxeId:o,file:i,workspaceId:t,sessionId:n,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,l;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const u=i.name.split(".").pop(),_="md"===u?"md":i.type,p={sessionid:s,formid:o,mimetype:_,extension:u,responseid:n,workspaceid:t},O=new URLSearchParams(Object.entries(p).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),g=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${O.toString()}`,m=yield fetch(g),I=yield m.json();if(!I.success)throw new Error(null!==(e=I.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({},I.fields),{file:i})).forEach((([e,s])=>{f.append(e,s)}));const w=yield fetch(I.url,{method:"POST",body:f});if(!w.ok)throw new Error(w.statusText);const b=`${I.url}${I.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",b),_.startsWith("image"))return{success:!0,documentId:`IMAGE-${I.documentId}-${I.folder}`};const P=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,documentId:I.documentId,fileName:i.name,fileSize:i.size},t&&{workspaceId:t}),n&&{responseId:n}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),j=yield P.json();if(!j.success)throw new Error(null!==(l=j.error)&&void 0!==l?l:"Failed processing document, try again or contact support.");return j})),website:({pickaxeId:o,website:i,workspaceId:t,sessionId:n,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>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 l=s.generateId(20),u=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,documentId:l,website:i},t&&{workspaceId:t}),n&&{responseId:n}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),_=yield u.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:({contextId:s,pickaxeId:o,file:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,l;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const _=i.name.split(".").pop(),p="md"===_?"md":i.type,u={sessionid:s,formid:o,mimetype:p,extension:_,responseid:t,workspaceid:n},O=new URLSearchParams(Object.entries(u).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),g=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${O.toString()}`,f=yield fetch(g),w=yield f.json();if(!w.success)throw new Error(null!==(e=w.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const b=new FormData;Object.entries(Object.assign(Object.assign({},w.fields),{file:i})).forEach((([e,s])=>{b.append(e,s)}));const m=yield fetch(w.url,{method:"POST",body:b});if(!m.ok)throw new Error(m.statusText);const I=`${w.url}${w.fields.key}`;"development"===process.env.NODE_ENV&&console.log("[S3URL]",I);const j=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,documentId:w.documentId,fileName:i.name,fileSize:i.size},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),P=yield j.json();if(!P.success)throw new Error(null!==(l=P.error)&&void 0!==l?l:"Failed processing document, try again or contact support.");return Object.assign(Object.assign({},P),{folder:w.folder})})),website:({pickaxeId:o,website:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>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 l=s.generateId(20),_=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,documentId:l,website:i},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),p=yield _.json();if(!p.success)throw new Error(null!==(e=p.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return p}))});
@@ -13,6 +13,7 @@ export declare const useSubmitDocument: () => {
13
13
  success: boolean;
14
14
  documentId: string;
15
15
  chunkCount?: number;
16
+ folder?: string;
16
17
  error?: string;
17
18
  }>;
18
19
  website: ({ pickaxeId, website, workspaceId, sessionId, studioUserId, studioSessionToken, isKnowledge, isBlocking, }: {
@@ -7,6 +7,7 @@ export type MemoryStoredDocument = {
7
7
  size: number;
8
8
  status: MemoryStoredDocumentStatus;
9
9
  documentId?: string;
10
+ folder?: string;
10
11
  error?: string;
11
12
  isInsertedAsRaw?: boolean;
12
13
  };
@@ -1 +1 @@
1
- import e from"axios";const s=process.env.NEXT_PUBLIC_PICKAXE_API_URL||"";if(!s)throw new Error("[px/react] NEXT_PUBLIC_PICKAXE_API_URL is not defined");const o="undefined"!=typeof window?window.location.hostname:"",n="undefined"!=typeof window?window.location.href:"",i=o.includes("pickaxe.co")&&!n.includes("https://studio.pickaxe.co/_embed"),t=e.create(Object.assign(Object.assign({baseURL:s},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),i&&{withCredentials:!0}));export{t as default};
1
+ import e from"axios";const o=process.env.NEXT_PUBLIC_PICKAXE_API_URL||"";if(!o)throw new Error("[px/react] NEXT_PUBLIC_PICKAXE_API_URL is not defined");const n="undefined"!=typeof window?window.location.hostname:"",s="undefined"!=typeof window?window.location.href:"",i="undefined"!=typeof window&&window.self!==window.top,t=n.includes("pickaxe.co")&&!s.includes("https://studio.pickaxe.co/_embed")&&!i,d=e.create(Object.assign(Object.assign({baseURL:o},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),t&&{withCredentials:!0}));export{d as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Fragment as s}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useDocument as a}from"./hooks/useDocument.js";import{formatBytes as o}from"../../../../common/utils.js";import l from"../../../Icons/spinner-lines.svg.js";import c from"../../../Icons/file.svg.js";import n from"../../../Icons/x.svg.js";import d from"../../../Icons/circle-info.svg.js";import u from"../../../../common/cn.js";const m=({className:m,isDisabled:h})=>{const{styles:f,colors:b,translations:p,isRtl:g}=r(),{documents:x,isUploading:v,removeDocument:j}=a(),k=i();return e("div",Object.assign({className:u("flex flex-row gap-3 flex-wrap",m)},{children:x.map(((r,i)=>{var a,m,x,y,w,N,O;return e(s,{children:"document"===r.type?t("div",Object.assign({className:u("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",g&&"flex-row-reverse"),style:{borderRadius:f.cornerRadius,borderColor:b.secondaryText+"50"}},{children:[e("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:"uploading"===r.status?e(l,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(c,{className:"w-5 h-5 shrink-0"})})),t("div",Object.assign({className:u("flex flex-col justify-center truncate",g?"text-right items-end":"text-left items-start")},{children:[e("p",Object.assign({className:u(k.b3,"font-medium truncate")},{children:r.name})),e("p",Object.assign({className:u(k.b4,"opacity-80 truncate")},{children:"failed"===r.status?(null===(a=r.error)||void 0===a?void 0:a.includes("You have reached the file limit"))?null!==(m=null==p?void 0:p["file-limit-reached"])&&void 0!==m?m:"You have reached the file limit.":r.error:o(r.size)}))]})),!v&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:v||h,onClick:()=>j(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):"image"===r.type?t("div",Object.assign({className:"relative h-[56px] flex flex-col items-center justify-center w-[56px]",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:["finished"===r.status?e("img",{className:"object-cover w-full h-full",style:{borderRadius:f.cornerRadius},src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(x=r.documentId)||void 0===x?void 0:x.split("-")[2]}/${null===(y=r.documentId)||void 0===y?void 0:y.split("-")[1]}.${null===(w=r.documentId)||void 0===w?void 0:w.split("-")[2]}`,alt:""}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(l,{className:"w-5 h-5 animate-spin shrink-0"}),!v&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:v||h,onClick:()=>j(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):"website"===r.type?t("div",Object.assign({className:u("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",g&&"flex-row-reverse"),style:{borderRadius:f.cornerRadius,borderColor:b.secondaryText+"50"}},{children:[e("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:"uploading"===r.status?e(l,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(c,{className:"w-5 h-5 shrink-0"})})),t("div",Object.assign({className:u("flex flex-col justify-center truncate",g?"text-right items-end":"text-left items-start")},{children:[e("p",Object.assign({className:u(k.b3,"font-medium truncate")},{children:r.name})),e("p",Object.assign({className:u(k.b4,"opacity-80 truncate")},{children:"failed"===r.status?(null===(N=r.error)||void 0===N?void 0:N.includes("You have reached the file limit"))?null!==(O=null==p?void 0:p["file-limit-reached"])&&void 0!==O?O:"You have reached the file limit.":r.error:"Website "}))]})),!v&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:v||h,onClick:()=>j(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):null},i)}))}))};export{m as default};
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Fragment as s}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useDocument as a}from"./hooks/useDocument.js";import{formatBytes as o}from"../../../../common/utils.js";import l from"../../../Icons/spinner-lines.svg.js";import c from"../../../Icons/file.svg.js";import n from"../../../Icons/x.svg.js";import d from"../../../Icons/circle-info.svg.js";import u from"../../../../common/cn.js";const m=({className:m,isDisabled:h})=>{const{styles:f,colors:b,translations:p,isRtl:g}=r(),{documents:x,isUploading:j,removeDocument:v}=a(),k=i();return e("div",Object.assign({className:u("flex flex-row gap-3 flex-wrap",m)},{children:x.map(((r,i)=>{var a,m,x,y,w,N;return e(s,{children:"document"===r.type?t("div",Object.assign({className:u("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",g&&"flex-row-reverse"),style:{borderRadius:f.cornerRadius,borderColor:b.secondaryText+"50"}},{children:[e("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:"uploading"===r.status?e(l,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(c,{className:"w-5 h-5 shrink-0"})})),t("div",Object.assign({className:u("flex flex-col justify-center truncate",g?"text-right items-end":"text-left items-start")},{children:[e("p",Object.assign({className:u(k.b3,"font-medium truncate")},{children:r.name})),e("p",Object.assign({className:u(k.b4,"opacity-80 truncate")},{children:"failed"===r.status?(null===(a=r.error)||void 0===a?void 0:a.includes("You have reached the file limit"))?null!==(m=null==p?void 0:p["file-limit-reached"])&&void 0!==m?m:"You have reached the file limit.":r.error:o(r.size)}))]})),!j&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:j||h,onClick:()=>v(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):"image"===r.type?t("div",Object.assign({className:"relative h-[56px] flex flex-col items-center justify-center w-[56px]",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:["finished"===r.status?e("img",{className:"object-cover w-full h-full",style:{borderRadius:f.cornerRadius},src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null!==(x=r.folder)&&void 0!==x?x:"jpg"}/${r.documentId}.${null!==(y=r.folder)&&void 0!==y?y:"jpg"}`,alt:""}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(l,{className:"w-5 h-5 animate-spin shrink-0"}),!j&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:j||h,onClick:()=>v(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):"website"===r.type?t("div",Object.assign({className:u("relative flex items-center gap-x-2.5 pl-2 pr-4 h-[56px] border",g&&"flex-row-reverse"),style:{borderRadius:f.cornerRadius,borderColor:b.secondaryText+"50"}},{children:[e("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:Object.assign({borderRadius:f.cornerRadius,backgroundColor:b.accent,color:b.accentText},"failed"===r.status&&{backgroundColor:b.error,color:"white"})},{children:"uploading"===r.status?e(l,{className:"w-5 h-5 animate-spin shrink-0"}):"failed"===r.status?e(d,{className:"w-5 h-5 shrink-0"}):e(c,{className:"w-5 h-5 shrink-0"})})),t("div",Object.assign({className:u("flex flex-col justify-center truncate",g?"text-right items-end":"text-left items-start")},{children:[e("p",Object.assign({className:u(k.b3,"font-medium truncate")},{children:r.name})),e("p",Object.assign({className:u(k.b4,"opacity-80 truncate")},{children:"failed"===r.status?(null===(w=r.error)||void 0===w?void 0:w.includes("You have reached the file limit"))?null!==(N=null==p?void 0:p["file-limit-reached"])&&void 0!==N?N:"You have reached the file limit.":r.error:"Website "}))]})),!j&&e("button",Object.assign({type:"button",className:u("absolute w-5 h-5 rounded-full -top-2 flex items-center justify-center outline-none disabled:cursor-default",g?"-left-1 right-auto":"-right-1 left-auto"),style:{backgroundColor:b.accent,color:b.accentText},disabled:j||h,onClick:()=>v(r.id)},{children:e(n,{className:"w-4 h-4 shrink-0"})}))]})):null},i)}))}))};export{m as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{usePickaxeContext as t}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as s}from"../../Auth/hooks/useAuthContext.js";import{useSubmitDocument as i}from"../../../../../hooks/pickaxe/useSubmitDocument.js";import{useDocumentContext as o}from"./useDocumentContext.js";import{additionalAllowedFileExtensions as n,allowedFileMimeTypes as r,allowedImageMimeTypes as d}from"../../../../../common/documents.js";import{v4 as a}from"uuid";import u from"../../../../../common/error.js";const c=({onQuestionChange:c}={})=>{const{contextId:m,pickaxeId:l,sessionId:p,sender:f,senderType:I,pickaxe:h}=t(),{token:w}=s(),b=o(),g=i(),k=e=>{const t=[...r,...d];if(e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&n.includes(`.${t}`))return!1}return!0}))){const e=new Error("You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again."),t=u(e);return b.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},b),{onFileUpload:t=>e(void 0,void 0,void 0,(function*(){if(b.setDocumentError(""),!t.length)return null;if(k(t))return null;b.setIsUploading(!0),b.setIsShowList(!0);const s=t.map((e=>({file:e,id:a()})));s.forEach((({file:e,id:t})=>{b.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,error:o}=yield g.document(Object.assign(Object.assign(Object.assign({contextId:m,pickaxeId:l,sessionId:p,file:t},(null==h?void 0:h.workspaceid)&&{workspaceId:h.workspaceid}),"STUDIO_USER"===I&&{studioUserId:f}),w&&{studioSessionToken:w}));if(!e)throw new Error(null!=o?o:"Document processing failed");null==c||c({input:t.name,documentId:i});const n=i.startsWith("IMAGE-");return b.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=u(e);return b.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),b.setIsUploading(!1)})),onWebsiteUpload:t=>e(void 0,void 0,void 0,(function*(){b.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.");b.setIsUploading(!0),b.setIsShowList(!0),b.setWebsiteLink(""),b.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield g.website(Object.assign(Object.assign(Object.assign({pickaxeId:l,sessionId:p,website:e},(null==h?void 0:h.workspaceid)&&{workspaceId:h.workspaceid}),"STUDIO_USER"===I&&{studioUserId:f}),w&&{studioSessionToken:w})),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");b.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=u(t);if(s.includes("Please paste a valid website URL"))return b.setDocumentError(s),null;b.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{b.setIsUploading(!1)}}))})};export{c as useDocument};
1
+ import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{usePickaxeContext as t}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as s}from"../../Auth/hooks/useAuthContext.js";import{useSubmitDocument as i}from"../../../../../hooks/pickaxe/useSubmitDocument.js";import{useDocumentContext as o}from"./useDocumentContext.js";import{allowedImageMimeTypes as n,additionalAllowedFileExtensions as r,allowedFileMimeTypes as d}from"../../../../../common/documents.js";import{v4 as a}from"uuid";import u from"../../../../../common/error.js";const c=({onQuestionChange:c}={})=>{const{contextId:l,pickaxeId:m,sessionId:p,sender:f,senderType:I,pickaxe:h}=t(),{token:w}=s(),b=o(),g=i(),k=e=>{const t=[...d,...n];if(e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&r.includes(`.${t}`))return!1}return!0}))){const e=new Error("You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again."),t=u(e);return b.setDocumentError(t),!0}return!1};return Object.assign(Object.assign({},b),{onFileUpload:t=>e(void 0,void 0,void 0,(function*(){if(b.setDocumentError(""),!t.length)return null;if(k(t))return null;b.setIsUploading(!0),b.setIsShowList(!0);const s=t.map((e=>({file:e,id:a()})));s.forEach((({file:e,id:t})=>{b.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,folder:o,error:r}=yield g.document(Object.assign(Object.assign(Object.assign({contextId:l,pickaxeId:m,sessionId:p,file:t},(null==h?void 0:h.workspaceid)&&{workspaceId:h.workspaceid}),"STUDIO_USER"===I&&{studioUserId:f}),w&&{studioSessionToken:w}));if(!e)throw new Error(null!=r?r:"Document processing failed");null==c||c({input:t.name,documentId:i});const d=i.startsWith("IMAGE-")||n.includes(t.type);return b.editDocument(Object.assign({id:s,type:d?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i},d&&o&&{folder:o})),{name:t.name,documentId:i}}catch(e){const i=u(e);return b.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),b.setIsUploading(!1)})),onWebsiteUpload:t=>e(void 0,void 0,void 0,(function*(){b.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.");b.setIsUploading(!0),b.setIsShowList(!0),b.setWebsiteLink(""),b.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield g.website(Object.assign(Object.assign(Object.assign({pickaxeId:m,sessionId:p,website:e},(null==h?void 0:h.workspaceid)&&{workspaceId:h.workspaceid}),"STUDIO_USER"===I&&{studioUserId:f}),w&&{studioSessionToken:w})),{success:s,documentId:i}=t;if(!s)throw new Error("Website processing failed, please try again.");b.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=u(t);if(s.includes("Please paste a valid website URL"))return b.setDocumentError(s),null;b.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{b.setIsUploading(!1)}}))})};export{c as useDocument};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{generateId as s}from"../../common/utils.js";const o=()=>({document:({contextId:s,pickaxeId:o,file:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e(void 0,void 0,void 0,(function*(){var e,l;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const p=i.name.split(".").pop(),_="md"===p?"md":i.type,u={sessionid:s,formid:o,mimetype:_,extension:p,responseid:t,workspaceid:n},O=new URLSearchParams(Object.entries(u).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),g=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${O.toString()}`,m=yield fetch(g),f=yield m.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 I=new FormData;Object.entries(Object.assign(Object.assign({},f.fields),{file:i})).forEach((([e,s])=>{I.append(e,s)}));const w=yield fetch(f.url,{method:"POST",body:I});if(!w.ok)throw new Error(w.statusText);const P=`${f.url}${f.fields.key}`;if("development"===process.env.NODE_ENV&&console.log("[S3URL]",P),_.startsWith("image"))return{success:!0,documentId:`IMAGE-${f.documentId}-${f.folder}`};const b=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,documentId:f.documentId,fileName:i.name,fileSize:i.size},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),L=yield b.json();if(!L.success)throw new Error(null!==(l=L.error)&&void 0!==l?l:"Failed processing document, try again or contact support.");return L})),website:({pickaxeId:o,website:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>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 l=s(20),p=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,documentId:l,website:i},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),_=yield p.json();if(!_.success)throw new Error(null!==(e=_.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return _}))});export{o as useSubmitDocument};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{generateId as s}from"../../common/utils.js";const o=()=>({document:({contextId:s,pickaxeId:o,file:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>e(void 0,void 0,void 0,(function*(){var e,l;if(!process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL)throw new Error("NEXT_PUBLIC_MODAL_DOC_APP_URL is not defined");const p=i.name.split(".").pop(),_="md"===p?"md":i.type,O={sessionid:s,formid:o,mimetype:_,extension:p,responseid:t,workspaceid:n},u=new URLSearchParams(Object.entries(O).filter((e=>void 0!==e[1]&&null!==e[1]&&""!==e[1]))),g=`${process.env.NEXT_PUBLIC_MODAL_DOC_APP_URL}/get_document_upload_url?${u.toString()}`,f=yield fetch(g),m=yield f.json();if(!m.success)throw new Error(null!==(e=m.error)&&void 0!==e?e:"Failed to get presigned URL, try again or contact support.");const w=new FormData;Object.entries(Object.assign(Object.assign({},m.fields),{file:i})).forEach((([e,s])=>{w.append(e,s)}));const I=yield fetch(m.url,{method:"POST",body:w});if(!I.ok)throw new Error(I.statusText);const b=`${m.url}${m.fields.key}`;"development"===process.env.NODE_ENV&&console.log("[S3URL]",b);const j=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,documentId:m.documentId,fileName:i.name,fileSize:i.size},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),P=yield j.json();if(!P.success)throw new Error(null!==(l=P.error)&&void 0!==l?l:"Failed processing document, try again or contact support.");return Object.assign(Object.assign({},P),{folder:m.folder})})),website:({pickaxeId:o,website:i,workspaceId:n,sessionId:t,studioUserId:r,studioSessionToken:d,isKnowledge:c,isBlocking:a})=>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 l=s(20),p=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,documentId:l,website:i},n&&{workspaceId:n}),t&&{responseId:t}),r&&{studioUserId:r}),d&&{studioSessionToken:d}),c&&{isKnowledge:c}),a&&{isBlocking:a})),headers:{"Content-Type":"application/json"}}),_=yield p.json();if(!_.success)throw new Error(null!==(e=_.error)&&void 0!==e?e:"Failed processing website, try again or contact support.");return _}))});export{o as useSubmitDocument};
@@ -13,6 +13,7 @@ export declare const useSubmitDocument: () => {
13
13
  success: boolean;
14
14
  documentId: string;
15
15
  chunkCount?: number;
16
+ folder?: string;
16
17
  error?: string;
17
18
  }>;
18
19
  website: ({ pickaxeId, website, workspaceId, sessionId, studioUserId, studioSessionToken, isKnowledge, isBlocking, }: {
@@ -7,6 +7,7 @@ export type MemoryStoredDocument = {
7
7
  size: number;
8
8
  status: MemoryStoredDocumentStatus;
9
9
  documentId?: string;
10
+ folder?: string;
10
11
  error?: string;
11
12
  isInsertedAsRaw?: boolean;
12
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",