@pickaxeproject/react 4.2.0 → 4.2.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.
- package/dist/cjs/components/Pickaxe/Addons/Document/List.js +1 -1
- package/dist/cjs/components/Pickaxe/Addons/Document/hooks/useDocument.js +1 -1
- package/dist/cjs/hooks/pickaxe/useSubmitDocument.js +1 -1
- package/dist/cjs/src/hooks/pickaxe/useSubmitDocument.d.ts +1 -0
- package/dist/cjs/src/types/document.d.ts +1 -0
- package/dist/esm/components/Pickaxe/Addons/Document/List.js +1 -1
- package/dist/esm/components/Pickaxe/Addons/Document/hooks/useDocument.js +1 -1
- package/dist/esm/hooks/pickaxe/useSubmitDocument.js +1 -1
- package/dist/esm/src/hooks/pickaxe/useSubmitDocument.d.ts +1 -0
- package/dist/esm/src/types/document.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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"),
|
|
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"),
|
|
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:
|
|
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, }: {
|
|
@@ -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:
|
|
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{
|
|
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,
|
|
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, }: {
|