@pickaxeproject/react 1.3.7 → 1.3.9

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"),s=require("react/jsx-runtime"),t=require("react"),o=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../hooks/pickaxe/useDimensionContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),d=require("../../../hooks/pickaxe/useSubmit.js"),c=require("../../../hooks/pickaxe/useSubmitResult.js"),u=require("../../../common/documents.js"),m=require("../../../common/api/streamer.js"),p=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),x=require("../../../hooks/core/useHover.js"),h=require("../../../common/utils.js"),f=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/spinner-lines.svg.js"),j=require("../../Icons/file.svg.js"),v=require("../../Icons/x.svg.js"),y=require("../../Icons/arrow-right.svg.js"),k=require("../common/PickaxeBranding.js"),w=require("../Addons/IceBreaker/index.js"),I=require("../../Core/Textarea.js"),O=require("../../../common/error.js"),C=require("../../../common/cn.js");exports.default=()=>{var N;const{formId:q,chatId:R,userId:S,studioUserId:D,deploymentId:A,pickaxe:E,styles:_,colors:T,misc:U,responsiveBy:H,forceMobile:B,isNewChat:M,setIsNewChat:P,setIsShowIceBreaker:F,onGenerateComplete:L}=o.usePickaxeContext(),{messages:z,status:W,limits:G,isGenerating:$,setMessages:K,setStatus:X,setLimitData:J,setError:Q,setIsGenerating:V}=r.useResponseContext(),{isMobile:Y}=i.useDimensionContext(),{documents:Z,isUploading:ee,isImageUploadAllowed:se,upsertDocuments:te,onFileUpload:oe}=p.useDocument(),{scrollStartSession:re,scrollEndSession:ie,scrollToBottom:ne}=g.useScroll({auto:!0}),ae=l.useConversation(),le=d.useSubmit(),de=c.useSubmitResult(),ce=a.useStyleFontSize(),ue=n.useStyleInput(),[me,pe]=t.useState(""),ge=t.useRef(null),xe=x.useHover(),{isHover:he}=xe,fe=e.__rest(xe,["isHover"]),be=x.useHover(),{isHover:je}=be,ve=e.__rest(be,["isHover"]),ye=t.useMemo((()=>{var e,s,t;return!!M&&(!!E&&(!ae.isLoading&&(!((null!==(s=null===(e=ae.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,M,ae.data,ae.isLoading]),ke=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(ee||"idle"!==W||$)return;const e=null!=s?s:me;if(!e)return;pe(""),Q(""),J(null),V(!0),P(!1);const t=new Date,o="enduserupload"===(null==E?void 0:E.documentuploadtype),r=Z.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),i=r.length?r[r.length-1].documentId:"";X("fetching"),re(),ne();const n=Array.from(z);let a=[...n,{id:z.length+1,role:"user",content:e}];K(a),ne();const{success:l,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:p,endUserImageId:g,rawUserInput:x,error:h}=yield le.mutateAsync(Object.assign(Object.assign(Object.assign({formId:q,responseId:R,value:e},o&&i&&{documentId:i}),D&&{studioUserId:D}),A&&{deploymentId:A}));if(!l)throw new Error(null!=h?h:"An error occurred, please try again.");const f=[];p&&f.push(p),g&&f.push(g),f.length>0&&(a=[...n,Object.assign({id:z.length+1,role:"user",content:e},f&&{documentIds:f})],K(a),ne()),te([]),ne();const b=(yield m.streamer({formId:q,responseId:R,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const j=b.getReader(),v=new TextDecoder,y=a.length;let k="",w=!0,I=!1;for(;w;){const{value:e,done:s}=yield j.read();w=!s;const t=v.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(k+=t.replace(/\u200B/g,""),k)I||(X("streaming"),I=!0),K([...a.slice(0,y),{id:z.length+1,role:"assistant",content:k}]);else if(!w&&!k)throw new Error("Server error")}const O=new Date;k&&(ne(),yield de.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:q,responseId:R,documentIds:u},S&&{userId:S}),D&&{studioUserId:D}),D&&(null==E?void 0:E.studioid)&&{studioId:E.studioid}),A&&{deploymentId:A}),{messages:[Object.assign(Object.assign({role:"user",message:x},f&&{documentIds:f}),{sentAt:t}),{role:"assistant",message:k,sentAt:O}]})),X("idle"),null==L||L(R))}catch(e){let s=O.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(G).find((([e])=>s.includes(e)));t?J(t[1]):Q(s),ne()}finally{X("idle"),V(!1),ie()}}));return t.useEffect((()=>{F(ye)}),[ye]),s.jsxs("div",Object.assign({className:C.default("fixed flex w-full flex-col bottom-0 left-0","viewport"===H?"min-[767px]:relative min-[767px]:bottom-auto min-[767px]:left-auto":"absolute @[767px]/pickaxe-root:relative @[767px]/pickaxe-root:bottom-auto @[767px]/pickaxe-root:left-auto")},{children:[!U.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3 pb-3 @[767px]/pickaxe-root:pr-0"},{children:s.jsx(k.default,{animateHover:!0})})),ye&&s.jsx(w.default,{data:(null==E?void 0:E.icebreakers)||[],onSend:ke}),s.jsxs("div",Object.assign({style:Object.assign(Object.assign({},ue),(Y||B)&&{paddingLeft:"0.75rem",paddingRight:"0.75rem"}),className:C.default("flex min-h-[56px] flex-col gap-y-2 px-4 py-3 pb-[15px]","block"===_.formFieldStyle&&"shadow")},{children:["idle"===W&&Z.length>0&&s.jsx("div",Object.assign({className:C.default("grid grid-cols-1","viewport"===H?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:Z.map((e=>{var o,r,i;return s.jsx(t.Fragment,{children:"document"===e.type?s.jsxs("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:ue.borderRadius,borderColor:T.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:T.accent,borderRadius:ue.borderRadius}},{children:ee?s.jsx(b.default,{className:"w-5 h-5 animate-spin",style:{color:T.accentText}}):s.jsx(j.default,{className:"w-5 h-5",style:{color:T.accentText}})})),s.jsxs("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s.jsx("p",Object.assign({className:(C.default(ce.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:C.default(ce.b4,"opacity-80 truncate")},{children:h.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",disabled:ee||"idle"!==W,onClick:()=>te([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:T.accent,borderColor:ue.backgroundColor}},{children:s.jsx(v.default,{className:"w-4 h-4",style:{color:T.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:ue.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:ue.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(o=e.documentId)||void 0===o?void 0:o.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.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ue.borderRadius,backgroundColor:T.secondary}}),s.jsx("button",Object.assign({type:"button",disabled:ee||"idle"!==W,onClick:()=>te([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:T.accent,borderColor:ue.backgroundColor}},{children:s.jsx(v.default,{className:"w-4 h-4",style:{color:T.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:"flex items-end gap-x-2 grow"},{children:[s.jsx(I.default,{className:C.default(ce.i1,"max-h-60 mb-[0.2em] w-full border-transparent bg-transparent",!me.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:me,placeholder:null!==(N=null==E?void 0:E.placeholdertext)&&void 0!==N?N:"What do you want to talk about?",onChange:e=>pe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ee||"idle"!==W||ke()))}}),s.jsxs("div",Object.assign({className:"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:je?T.accent+"10":void 0},disabled:ee||"idle"!==W,onClick:()=>{var e;return null===(e=ge.current)||void 0===e?void 0:e.click()}},ve,{children:[s.jsx("input",{id:"file-upload",ref:ge,type:"file",accept:[...u.allowedFileMimeTypes,...se?u.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield oe(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(f.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:je?T.accent:T.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)))&&!$?T.accent:T.accent+"10"},disabled:ee||"idle"!==W,onClick:()=>ke()},fe,{children:s.jsx(y.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(he||me.length||Z.length&&Z.every((e=>"finished"===e.status)))&&!$?T.accentText:T.accent+"80"}})}))]}))]}))]}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),o=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../hooks/pickaxe/useDimensionContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),a=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),d=require("../../../hooks/pickaxe/useSubmit.js"),c=require("../../../hooks/pickaxe/useSubmitResult.js"),u=require("../../../common/documents.js"),m=require("../../../common/api/streamer.js"),p=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),x=require("../../../hooks/core/useHover.js"),b=require("../../../common/utils.js"),h=require("../../Icons/attach-vertical.svg.js"),f=require("../../Icons/spinner-lines.svg.js"),j=require("../../Icons/file.svg.js"),v=require("../../Icons/x.svg.js"),y=require("../../Icons/arrow-right.svg.js"),k=require("../common/PickaxeBranding.js"),w=require("../Addons/IceBreaker/index.js"),I=require("../../Core/Textarea.js"),O=require("../../../common/error.js"),C=require("../../../common/cn.js");exports.default=()=>{var N;const{formId:q,chatId:R,userId:S,studioUserId:D,embedUserId:A,deploymentId:U,pickaxe:E,styles:_,colors:T,misc:H,responsiveBy:B,forceMobile:M,isNewChat:P,setIsNewChat:F,setIsShowIceBreaker:L,onGenerateComplete:z}=o.usePickaxeContext(),{messages:W,status:G,limits:$,isGenerating:K,setMessages:X,setStatus:J,setLimitData:Q,setError:V,setIsGenerating:Y}=r.useResponseContext(),{isMobile:Z}=i.useDimensionContext(),{documents:ee,isUploading:se,isImageUploadAllowed:te,upsertDocuments:oe,onFileUpload:re}=p.useDocument(),{scrollStartSession:ie,scrollEndSession:ne,scrollToBottom:ae}=g.useScroll({auto:!0}),le=l.useConversation(),de=d.useSubmit(),ce=c.useSubmitResult(),ue=a.useStyleFontSize(),me=n.useStyleInput(),[pe,ge]=t.useState(""),xe=t.useRef(null),be=x.useHover(),{isHover:he}=be,fe=e.__rest(be,["isHover"]),je=x.useHover(),{isHover:ve}=je,ye=e.__rest(je,["isHover"]),ke=t.useMemo((()=>{var e,s,t;return!!P&&(!!E&&(!le.isLoading&&(!((null!==(s=null===(e=le.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,P,le.data,le.isLoading]),we=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(se||"idle"!==G||K)return;const e=null!=s?s:pe;if(!e)return;ge(""),V(""),Q(null),Y(!0),F(!1);const t=new Date,o="enduserupload"===(null==E?void 0:E.documentuploadtype),r=ee.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),i=r.length?r[r.length-1].documentId:"";J("fetching"),ie(),ae();const n=Array.from(W);let a=[...n,{id:W.length+1,role:"user",content:e}];X(a),ae();const{success:l,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:p,endUserImageId:g,rawUserInput:x,error:b}=yield de.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:q,responseId:R,value:e},o&&i&&{documentId:i}),D&&{studioUserId:D}),A&&{embedUserId:A}),U&&{deploymentId:U}));if(!l)throw new Error(null!=b?b:"An error occurred, please try again.");const h=[];p&&h.push(p),g&&h.push(g),h.length>0&&(a=[...n,Object.assign({id:W.length+1,role:"user",content:e},h&&{documentIds:h})],X(a),ae()),oe([]),ae();const f=(yield m.streamer({formId:q,responseId:R,data:d,actionData:c})).body;if(!f)throw new Error("Streaming error");const j=f.getReader(),v=new TextDecoder,y=a.length;let k="",w=!0,I=!1;for(;w;){const{value:e,done:s}=yield j.read();w=!s;const t=v.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(k+=t.replace(/\u200B/g,""),k)I||(J("streaming"),I=!0),X([...a.slice(0,y),{id:W.length+1,role:"assistant",content:k}]);else if(!w&&!k)throw new Error("Server error")}const O=new Date;k&&(ae(),yield ce.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:q,responseId:R,documentIds:u},S&&{userId:S}),D&&{studioUserId:D}),D&&(null==E?void 0:E.studioid)&&{studioId:E.studioid}),A&&{embedUserId:A}),U&&{deploymentId:U}),{messages:[Object.assign(Object.assign({role:"user",message:x},h&&{documentIds:h}),{sentAt:t}),{role:"assistant",message:k,sentAt:O}]})),J("idle"),null==z||z(R))}catch(e){let s=O.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($).find((([e])=>s.includes(e)));t?Q(t[1]):V(s),ae()}finally{J("idle"),Y(!1),ne()}}));return t.useEffect((()=>{L(ke)}),[ke]),s.jsxs("div",Object.assign({className:C.default("fixed flex w-full flex-col bottom-0 left-0","viewport"===B?"min-[767px]:relative min-[767px]:bottom-auto min-[767px]:left-auto":"absolute @[767px]/pickaxe-root:relative @[767px]/pickaxe-root:bottom-auto @[767px]/pickaxe-root:left-auto")},{children:[!H.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3 pb-3 @[767px]/pickaxe-root:pr-0"},{children:s.jsx(k.default,{animateHover:!0})})),ke&&s.jsx(w.default,{data:(null==E?void 0:E.icebreakers)||[],onSend:we}),s.jsxs("div",Object.assign({style:Object.assign(Object.assign({},me),(Z||M)&&{paddingLeft:"0.75rem",paddingRight:"0.75rem"}),className:C.default("flex min-h-[56px] flex-col gap-y-2 px-4 py-3 pb-[15px]","block"===_.formFieldStyle&&"shadow")},{children:["idle"===G&&ee.length>0&&s.jsx("div",Object.assign({className:C.default("grid grid-cols-1","viewport"===B?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:ee.map((e=>{var o,r,i;return s.jsx(t.Fragment,{children:"document"===e.type?s.jsxs("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:me.borderRadius,borderColor:T.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:T.accent,borderRadius:me.borderRadius}},{children:se?s.jsx(f.default,{className:"w-5 h-5 animate-spin",style:{color:T.accentText}}):s.jsx(j.default,{className:"w-5 h-5",style:{color:T.accentText}})})),s.jsxs("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s.jsx("p",Object.assign({className:(C.default(ue.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:C.default(ue.b4,"opacity-80 truncate")},{children:b.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",disabled:se||"idle"!==G,onClick:()=>oe([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:T.accent,borderColor:me.backgroundColor}},{children:s.jsx(v.default,{className:"w-4 h-4",style:{color:T.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:me.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:me.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(o=e.documentId)||void 0===o?void 0:o.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.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:me.borderRadius,backgroundColor:T.secondary}}),s.jsx("button",Object.assign({type:"button",disabled:se||"idle"!==G,onClick:()=>oe([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:T.accent,borderColor:me.backgroundColor}},{children:s.jsx(v.default,{className:"w-4 h-4",style:{color:T.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:"flex items-end gap-x-2 grow"},{children:[s.jsx(I.default,{className:C.default(ue.i1,"max-h-60 mb-[0.2em] w-full border-transparent bg-transparent",!pe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:pe,placeholder:null!==(N=null==E?void 0:E.placeholdertext)&&void 0!==N?N:"What do you want to talk about?",onChange:e=>ge(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),se||"idle"!==G||we()))}}),s.jsxs("div",Object.assign({className:"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:ve?T.accent+"10":void 0},disabled:se||"idle"!==G,onClick:()=>{var e;return null===(e=xe.current)||void 0===e?void 0:e.click()}},ye,{children:[s.jsx("input",{id:"file-upload",ref:xe,type:"file",accept:[...u.allowedFileMimeTypes,...te?u.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield re(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(h.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:ve?T.accent:T.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||pe.length||ee.length&&ee.every((e=>"finished"===e.status)))&&!K?T.accent:T.accent+"10"},disabled:se||"idle"!==G,onClick:()=>we()},fe,{children:s.jsx(y.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(he||pe.length||ee.length&&ee.every((e=>"finished"===e.status)))&&!K?T.accentText:T.accent+"80"}})}))]}))]}))]}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),s=require("react"),o=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/core/useHover.js"),t=require("../../../Core/Menu/index.js"),n=require("../../../Core/Menu/Button.js"),c=require("../../../Core/Menu/List.js"),d=require("../../../../common/cn.js");exports.default=({id:i,children:l,placeholder:u,value:F,className:x,style:b,closeOnSelect:j=!0,maxToken:h=50,isDropdown:p=!1})=>{const{styles:m,colors:v}=o.usePickaxeContext(),y=a.useHover(),{isHover:k}=y,g=e.__rest(y,["isHover"]),[q,w]=s.useState(!1);return p?r.jsxs(t.default,Object.assign({id:i,closeOnSelect:j,onChange:w,className:"relative"},{children:[r.jsx(n.default,Object.assign({variant:"anchor",className:d.default("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300 hover:border-black/25",x,q&&"border-black/70 shadow-none hover:border-black/70 dark:border-white/70 dark:hover:border-white/70",h<=50&&"max-w-[400px]"),style:Object.assign({backgroundColor:"#FFFFFF"===v.secondaryText?"#000000":"#FFFFFF",color:v.secondaryText,borderRadius:`${m.cornerRadius}px`,borderColor:q?v.secondaryText+"B3":k?v.secondaryText+(q?"B3":"40"):"transparent"},b)},g,{children:r.jsx("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=F?F:"")||u}))})),r.jsx(c.default,Object.assign({className:"p-3 shadow-md",border:"#FFFFFF"===v.secondaryText?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:h<=50?"400px":"100%",style:Object.assign({backgroundColor:"#FFFFFF"===v.secondaryText?"#000000":"#FFFFFF",color:v.secondaryText},b)},{children:l}))]})):r.jsx("div",{children:l})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../../hooks/studio/useStyleInput.js"),t=require("../../../Core/Menu/index.js"),a=require("../../../Core/Menu/Button.js"),n=require("../../../Core/Menu/List.js"),i=require("../../../../common/cn.js");exports.default=({id:o,children:l,placeholder:c,value:d,className:u,style:j,closeOnSelect:x=!0,maxToken:p=50,isDropdown:b=!1})=>{const{styles:m,colors:f}=s.usePickaxeContext(),h=r.useStyleInput();return b?e.jsxs(t.default,Object.assign({id:o,closeOnSelect:x,className:"relative"},{children:[e.jsx(a.default,Object.assign({variant:"anchor",className:i.default("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",u,p<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},h),j)},{children:e.jsx("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=d?d:"")||c}))})),e.jsx(n.default,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===f.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:p<=50?"400px":"100%",style:Object.assign(Object.assign(Object.assign({},h),{borderRadius:m.cornerRadius}),j)},{children:l}))]})):e.jsx("div",{children:l})};
@@ -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"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/pickaxe/useSubmit.js"),r=require("../../../../hooks/pickaxe/useSubmitResult.js"),l=require("../../Addons/Document/hooks/useDocument.js"),a=require("../../Addons/Scroll/hooks/useScroll.js"),d=require("../../../../common/api/streamer.js"),u=require("../../../../common/utils.js"),c=require("@nem035/gpt-3-encoder"),m=require("../../common/PickaxeBranding.js"),p=require("../../common/PickaxeButton.js"),g=require("../../../../common/error.js"),f=require("../../../../common/cn.js");exports.default=({questions:h})=>{var x;const{formId:j,userId:b,studioUserId:v,deploymentId:w,pickaxe:y,misc:I,translations:q,responsiveBy:k,isShowHistory:O,setChatId:S,setIsShowHistory:R,setIsNewChat:E,onGenerateComplete:P}=i.usePickaxeContext(),{status:C,limits:D,isGenerating:U,setResponse:A,setMessages:N,setStatus:_,setLimitData:L,setError:T,setIsGenerating:B}=o.useResponseContext(),{documents:W,websiteLink:G,isUploading:H,onWebsiteUpload:M,setDocumentError:X}=l.useDocument(),{scrollStartSession:F,scrollEndSession:K,scrollToTarget:Y}=a.useScroll({auto:!(null==y?void 0:y.enablechatresponses)}),z=n.useSubmit(),J=r.useSubmitResult(),[Q,V]=t.useState(!1);return s.jsxs("div",Object.assign({className:f.default("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===k?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[s.jsxs("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[s.jsx(p.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:H||"idle"!==C||U||Q,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{if(H||"idle"!==C||U||Q)return;A(null),L(null),X(""),B(!0);const s="enduserupload"===(null==y?void 0:y.documentuploadtype),t=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),i=W.filter((e=>"finished"===e.status)),o=u.extractUrlsFromText(G),n=W.map((e=>e.name)),r=o.filter((e=>!n.includes(e)));if(r.length){const e=r[r.length-1];V(!0);const s=yield M(e);s&&(i.push(s),yield new Promise((e=>setTimeout(e,5e3)))),V(!1)}else if(t&&s&&!i.length)return void X("Please paste a valid website/video link or drag a file to add to the knowledge base.");T("");const l=["Multiple Choice","Checkbox"];for(const e of h){if(c.encode(e.input).length>e.maxLength&&!l.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const a=i.length?i[i.length-1]:null;let m={};h.forEach((e=>m=Object.assign(Object.assign({},m),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==a?void 0:a.name)||"":e.input}))),_("fetching"),F(),Y();const{success:p,responseId:g,data:f,actionData:x,usedDocumentIds:I,rawUserInput:q,error:k}=yield z.mutateAsync(Object.assign(Object.assign(Object.assign({formId:j,valueObj:m},s&&a&&{documentId:null!==(e=a.documentId)&&void 0!==e?e:""}),v&&{studioUserId:v}),w&&{deploymentId:w}));if(!p)throw new Error(null!=k?k:"An error occurred, please try again.");Y();const O=(yield d.streamer({formId:j,responseId:g,data:f,actionData:x})).body;if(!O)throw new Error("Streaming error");const R=O.getReader(),D=new TextDecoder;let K="",Z=!0,$=!1;Y();const ee=h.map((e=>({id:e.id,question:e.main,answer:e.input})));for(;Z;){const{value:e,done:s}=yield R.read();Z=!s;const t=D.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(K+=t.replace(/\u200B/g,""),K)$||(_("streaming"),$=!0,(null==y?void 0:y.enablechatresponses)&&(S(g),E(!1))),A({formId:j,responseId:g,documentIds:I,messages:[],questions:ee,questionPrompt:q,questionResponse:K,createdAt:new Date}),(null==y?void 0:y.enablechatresponses)&&N([{id:0,role:"assistant",content:K}]);else if(!Z&&!K)throw new Error("Server error")}K&&(Y(),yield J.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,responseId:g,documentIds:I},b&&{userId:b}),v&&{studioUserId:v}),v&&(null==y?void 0:y.studioid)&&{studioId:y.studioid}),w&&{deploymentId:w}),{questions:ee,questionPrompt:q,questionResponse:K})),_("idle"),null==P||P(g))}catch(e){let s=g.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(D).find((([e])=>s.includes(e)));t?L(t[1]):T(s),Y()}finally{_("idle"),B(!1),V(!1),K()}}))},{children:Q?(null==q?void 0:q.processing)||"Processing...":H?(null==q?void 0:q.uploading)||"Uploading...":"fetching"===C||"streaming"===C?(null==q?void 0:q.loading)||"Loading...":null!==(x=null==y?void 0:y.submittext)&&void 0!==x?x:"Submit"})),I.isHistory&&!O&&s.jsx(p.default,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>R(!0)},{children:(null==q?void 0:q["see-history"])||"See history"}))]})),!I.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:s.jsx(m.default,{})}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/pickaxe/useSubmit.js"),r=require("../../../../hooks/pickaxe/useSubmitResult.js"),a=require("../../Addons/Document/hooks/useDocument.js"),l=require("../../Addons/Scroll/hooks/useScroll.js"),d=require("../../../../common/api/streamer.js"),u=require("../../../../common/utils.js"),c=require("@nem035/gpt-3-encoder"),m=require("../../common/PickaxeBranding.js"),p=require("../../common/PickaxeButton.js"),g=require("../../../../common/error.js"),f=require("../../../../common/cn.js");exports.default=({questions:h})=>{var x;const{formId:b,userId:j,studioUserId:v,embedUserId:w,deploymentId:I,pickaxe:y,misc:q,translations:O,responsiveBy:k,isShowHistory:S,setChatId:R,setIsShowHistory:E,setIsNewChat:P,onGenerateComplete:U}=i.usePickaxeContext(),{status:C,limits:D,isGenerating:A,setResponse:N,setMessages:_,setStatus:L,setLimitData:T,setError:B,setIsGenerating:W}=o.useResponseContext(),{documents:G,websiteLink:H,isUploading:M,onWebsiteUpload:X,setDocumentError:F}=a.useDocument(),{scrollStartSession:K,scrollEndSession:Y,scrollToTarget:z}=l.useScroll({auto:!(null==y?void 0:y.enablechatresponses)}),J=n.useSubmit(),Q=r.useSubmitResult(),[V,Z]=t.useState(!1);return s.jsxs("div",Object.assign({className:f.default("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===k?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[s.jsxs("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[s.jsx(p.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:M||"idle"!==C||A||V,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{if(M||"idle"!==C||A||V)return;N(null),T(null),F(""),W(!0);const s="enduserupload"===(null==y?void 0:y.documentuploadtype),t=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),i=G.filter((e=>"finished"===e.status)),o=u.extractUrlsFromText(H),n=G.map((e=>e.name)),r=o.filter((e=>!n.includes(e)));if(r.length){const e=r[r.length-1];Z(!0);const s=yield X(e);s&&(i.push(s),yield new Promise((e=>setTimeout(e,5e3)))),Z(!1)}else if(t&&s&&!i.length)return void F("Please paste a valid website/video link or drag a file to add to the knowledge base.");B("");const a=["Multiple Choice","Checkbox"];for(const e of h){if(c.encode(e.input).length>e.maxLength&&!a.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const l=i.length?i[i.length-1]:null;let m={};h.forEach((e=>m=Object.assign(Object.assign({},m),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==l?void 0:l.name)||"":e.input}))),L("fetching"),K(),z();const{success:p,responseId:g,data:f,actionData:x,usedDocumentIds:q,rawUserInput:O,error:k}=yield J.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:b,valueObj:m},s&&l&&{documentId:null!==(e=l.documentId)&&void 0!==e?e:""}),v&&{studioUserId:v}),w&&{embedUserId:w}),I&&{deploymentId:I}));if(!p)throw new Error(null!=k?k:"An error occurred, please try again.");z();const S=(yield d.streamer({formId:b,responseId:g,data:f,actionData:x})).body;if(!S)throw new Error("Streaming error");const E=S.getReader(),D=new TextDecoder;let Y="",$=!0,ee=!1;z();const se=h.map((e=>({id:e.id,question:e.main,answer:e.input})));for(;$;){const{value:e,done:s}=yield E.read();$=!s;const t=D.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(Y+=t.replace(/\u200B/g,""),Y)ee||(L("streaming"),ee=!0,(null==y?void 0:y.enablechatresponses)&&(R(g),P(!1))),N({formId:b,responseId:g,documentIds:q,messages:[],questions:se,questionPrompt:O,questionResponse:Y,createdAt:new Date}),(null==y?void 0:y.enablechatresponses)&&_([{id:0,role:"assistant",content:Y}]);else if(!$&&!Y)throw new Error("Server error")}Y&&(z(),yield Q.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:b,responseId:g,documentIds:q},j&&{userId:j}),v&&{studioUserId:v}),v&&(null==y?void 0:y.studioid)&&{studioId:y.studioid}),w&&{embedUserId:w}),I&&{deploymentId:I}),{questions:se,questionPrompt:O,questionResponse:Y})),L("idle"),null==U||U(g))}catch(e){let s=g.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(D).find((([e])=>s.includes(e)));t?T(t[1]):B(s),z()}finally{L("idle"),W(!1),Z(!1),Y()}}))},{children:V?(null==O?void 0:O.processing)||"Processing...":M?(null==O?void 0:O.uploading)||"Uploading...":"fetching"===C||"streaming"===C?(null==O?void 0:O.loading)||"Loading...":null!==(x=null==y?void 0:y.submittext)&&void 0!==x?x:"Submit"})),q.isHistory&&!S&&s.jsx(p.default,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>E(!0)},{children:(null==O?void 0:O["see-history"])||"See history"}))]})),!q.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:s.jsx(m.default,{})}))]}))};
@@ -1,4 +1,4 @@
1
- import { type CSSProperties, type ReactNode } from "react";
1
+ import type { CSSProperties, ReactNode } from "react";
2
2
  interface DropdownProps {
3
3
  id: string;
4
4
  children: ReactNode;
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsxs as s,jsx as o}from"react/jsx-runtime";import{useState as r,useRef as i,useMemo as n,useEffect as a,Fragment as l}from"react";import{usePickaxeContext as d}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../hooks/pickaxe/useResponseContext.js";import{useDimensionContext as u}from"../../../hooks/pickaxe/useDimensionContext.js";import{useStyleInput as m}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as p}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as f}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as g}from"../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as h}from"../../../hooks/pickaxe/useSubmitResult.js";import{allowedFileMimeTypes as b,allowedImageMimeTypes as v}from"../../../common/documents.js";import{streamer as x}from"../../../common/api/streamer.js";import{useDocument as j}from"../Addons/Document/hooks/useDocument.js";import{useScroll as y}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as k}from"../../../hooks/core/useHover.js";import{formatBytes as w}from"../../../common/utils.js";import I from"../../Icons/attach-vertical.svg.js";import O from"../../Icons/spinner-lines.svg.js";import N from"../../Icons/file.svg.js";import C from"../../Icons/x.svg.js";import R from"../../Icons/arrow-right.svg.js";import S from"../common/PickaxeBranding.js";import D from"../Addons/IceBreaker/index.js";import A from"../../Core/Textarea.js";import E from"../../../common/error.js";import U from"../../../common/cn.js";const T=()=>{var T;const{formId:B,chatId:H,userId:L,studioUserId:P,deploymentId:W,pickaxe:z,styles:F,colors:G,misc:M,responsiveBy:$,forceMobile:K,isNewChat:X,setIsNewChat:_,setIsShowIceBreaker:q,onGenerateComplete:J}=d(),{messages:Q,status:V,limits:Y,isGenerating:Z,setMessages:ee,setStatus:te,setLimitData:se,setError:oe,setIsGenerating:re}=c(),{isMobile:ie}=u(),{documents:ne,isUploading:ae,isImageUploadAllowed:le,upsertDocuments:de,onFileUpload:ce}=j(),{scrollStartSession:ue,scrollEndSession:me,scrollToBottom:pe}=y({auto:!0}),fe=f(),ge=g(),he=h(),be=p(),ve=m(),[xe,je]=r(""),ye=i(null),ke=k(),{isHover:we}=ke,Ie=e(ke,["isHover"]),Oe=k(),{isHover:Ne}=Oe,Ce=e(Oe,["isHover"]),Re=n((()=>{var e,t,s;return!!X&&(!!z&&(!fe.isLoading&&(!((null!==(t=null===(e=fe.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=z.icebreakers)||void 0===s?void 0:s.length))))}),[z,X,fe.data,fe.isLoading]),Se=e=>t(void 0,void 0,void 0,(function*(){try{if(ae||"idle"!==V||Z)return;const t=null!=e?e:xe;if(!t)return;je(""),oe(""),se(null),re(!0),_(!1);const s=new Date,o="enduserupload"===(null==z?void 0:z.documentuploadtype),r=ne.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),i=r.length?r[r.length-1].documentId:"";te("fetching"),ue(),pe();const n=Array.from(Q);let a=[...n,{id:Q.length+1,role:"user",content:t}];ee(a),pe();const{success:l,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:m,endUserImageId:p,rawUserInput:f,error:g}=yield ge.mutateAsync(Object.assign(Object.assign(Object.assign({formId:B,responseId:H,value:t},o&&i&&{documentId:i}),P&&{studioUserId:P}),W&&{deploymentId:W}));if(!l)throw new Error(null!=g?g:"An error occurred, please try again.");const h=[];m&&h.push(m),p&&h.push(p),h.length>0&&(a=[...n,Object.assign({id:Q.length+1,role:"user",content:t},h&&{documentIds:h})],ee(a),pe()),de([]),pe();const b=(yield x({formId:B,responseId:H,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const v=b.getReader(),j=new TextDecoder,y=a.length;let k="",w=!0,I=!1;for(;w;){const{value:e,done:t}=yield v.read();w=!t;const s=j.decode(e);if(s.startsWith("[PXE-ERROR]"))throw new Error(s.replace("[PXE-ERROR]","").trim());if(k+=s.replace(/\u200B/g,""),k)I||(te("streaming"),I=!0),ee([...a.slice(0,y),{id:Q.length+1,role:"assistant",content:k}]);else if(!w&&!k)throw new Error("Server error")}const O=new Date;k&&(pe(),yield he.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:B,responseId:H,documentIds:u},L&&{userId:L}),P&&{studioUserId:P}),P&&(null==z?void 0:z.studioid)&&{studioId:z.studioid}),W&&{deploymentId:W}),{messages:[Object.assign(Object.assign({role:"user",message:f},h&&{documentIds:h}),{sentAt:s}),{role:"assistant",message:k,sentAt:O}]})),te("idle"),null==J||J(H))}catch(e){let t=E(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(Y).find((([e])=>t.includes(e)));s?se(s[1]):oe(t),pe()}finally{te("idle"),re(!1),me()}}));return a((()=>{q(Re)}),[Re]),s("div",Object.assign({className:U("fixed flex w-full flex-col bottom-0 left-0","viewport"===$?"min-[767px]:relative min-[767px]:bottom-auto min-[767px]:left-auto":"absolute @[767px]/pickaxe-root:relative @[767px]/pickaxe-root:bottom-auto @[767px]/pickaxe-root:left-auto")},{children:[!M.isWhiteLabel&&o("div",Object.assign({className:"flex justify-end pr-3 pb-3 @[767px]/pickaxe-root:pr-0"},{children:o(S,{animateHover:!0})})),Re&&o(D,{data:(null==z?void 0:z.icebreakers)||[],onSend:Se}),s("div",Object.assign({style:Object.assign(Object.assign({},ve),(ie||K)&&{paddingLeft:"0.75rem",paddingRight:"0.75rem"}),className:U("flex min-h-[56px] flex-col gap-y-2 px-4 py-3 pb-[15px]","block"===F.formFieldStyle&&"shadow")},{children:["idle"===V&&ne.length>0&&o("div",Object.assign({className:U("grid grid-cols-1","viewport"===$?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:ne.map((e=>{var t,r,i;return o(l,{children:"document"===e.type?s("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:ve.borderRadius,borderColor:G.secondaryText+"50"}},{children:[o("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:G.accent,borderRadius:ve.borderRadius}},{children:ae?o(O,{className:"w-5 h-5 animate-spin",style:{color:G.accentText}}):o(N,{className:"w-5 h-5",style:{color:G.accentText}})})),s("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[o("p",Object.assign({className:(U(be.b3),"font-medium truncate")},{children:e.name})),o("p",Object.assign({className:U(be.b4,"opacity-80 truncate")},{children:w(e.size)}))]})),o("button",Object.assign({type:"button",disabled:ae||"idle"!==V,onClick:()=>de([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:G.accent,borderColor:ve.backgroundColor}},{children:o(C,{className:"w-4 h-4",style:{color:G.accentText}})}))]})):"image"===e.type?s("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:ve.borderRadius}},{children:["finished"===e.status?o("img",{style:{borderRadius:ve.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:""}):o("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ve.borderRadius,backgroundColor:G.secondary}}),o("button",Object.assign({type:"button",disabled:ae||"idle"!==V,onClick:()=>de([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:G.accent,borderColor:ve.backgroundColor}},{children:o(C,{className:"w-4 h-4",style:{color:G.accentText}})}))]})):null},e.id)}))})),s("div",Object.assign({className:"flex items-end gap-x-2 grow"},{children:[o(A,{className:U(be.i1,"max-h-60 mb-[0.2em] w-full border-transparent bg-transparent",!xe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:xe,placeholder:null!==(T=null==z?void 0:z.placeholdertext)&&void 0!==T?T:"What do you want to talk about?",onChange:e=>je(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ae||"idle"!==V||Se()))}}),s("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==z?void 0:z.documentuploadtype)&&s("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:Ne?G.accent+"10":void 0},disabled:ae||"idle"!==V,onClick:()=>{var e;return null===(e=ye.current)||void 0===e?void 0:e.click()}},Ce,{children:[o("input",{id:"file-upload",ref:ye,type:"file",accept:[...b,...le?v:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){yield ce(Array.from(e.target.files||[])),e.target.value=""}))}),o(I,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Ne?G.accent:G.accent+"80"}})]})),o("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)))&&!Z?G.accent:G.accent+"10"},disabled:ae||"idle"!==V,onClick:()=>Se()},Ie,{children:o(R,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(we||xe.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!Z?G.accentText:G.accent+"80"}})}))]}))]}))]}))]}))};export{T as default};
1
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsxs as s,jsx as o}from"react/jsx-runtime";import{useState as r,useRef as i,useMemo as n,useEffect as a,Fragment as l}from"react";import{usePickaxeContext as d}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../hooks/pickaxe/useResponseContext.js";import{useDimensionContext as u}from"../../../hooks/pickaxe/useDimensionContext.js";import{useStyleInput as m}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as p}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as f}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as g}from"../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as h}from"../../../hooks/pickaxe/useSubmitResult.js";import{allowedFileMimeTypes as b,allowedImageMimeTypes as v}from"../../../common/documents.js";import{streamer as x}from"../../../common/api/streamer.js";import{useDocument as j}from"../Addons/Document/hooks/useDocument.js";import{useScroll as y}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as k}from"../../../hooks/core/useHover.js";import{formatBytes as I}from"../../../common/utils.js";import w from"../../Icons/attach-vertical.svg.js";import O from"../../Icons/spinner-lines.svg.js";import N from"../../Icons/file.svg.js";import C from"../../Icons/x.svg.js";import R from"../../Icons/arrow-right.svg.js";import S from"../common/PickaxeBranding.js";import D from"../Addons/IceBreaker/index.js";import A from"../../Core/Textarea.js";import U from"../../../common/error.js";import E from"../../../common/cn.js";const T=()=>{var T;const{formId:B,chatId:H,userId:L,studioUserId:P,embedUserId:W,deploymentId:z,pickaxe:F,styles:G,colors:M,misc:$,responsiveBy:K,forceMobile:X,isNewChat:_,setIsNewChat:q,setIsShowIceBreaker:J,onGenerateComplete:Q}=d(),{messages:V,status:Y,limits:Z,isGenerating:ee,setMessages:te,setStatus:se,setLimitData:oe,setError:re,setIsGenerating:ie}=c(),{isMobile:ne}=u(),{documents:ae,isUploading:le,isImageUploadAllowed:de,upsertDocuments:ce,onFileUpload:ue}=j(),{scrollStartSession:me,scrollEndSession:pe,scrollToBottom:fe}=y({auto:!0}),ge=f(),he=g(),be=h(),ve=p(),xe=m(),[je,ye]=r(""),ke=i(null),Ie=k(),{isHover:we}=Ie,Oe=e(Ie,["isHover"]),Ne=k(),{isHover:Ce}=Ne,Re=e(Ne,["isHover"]),Se=n((()=>{var e,t,s;return!!_&&(!!F&&(!ge.isLoading&&(!((null!==(t=null===(e=ge.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=F.icebreakers)||void 0===s?void 0:s.length))))}),[F,_,ge.data,ge.isLoading]),De=e=>t(void 0,void 0,void 0,(function*(){try{if(le||"idle"!==Y||ee)return;const t=null!=e?e:je;if(!t)return;ye(""),re(""),oe(null),ie(!0),q(!1);const s=new Date,o="enduserupload"===(null==F?void 0:F.documentuploadtype),r=ae.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),i=r.length?r[r.length-1].documentId:"";se("fetching"),me(),fe();const n=Array.from(V);let a=[...n,{id:V.length+1,role:"user",content:t}];te(a),fe();const{success:l,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:m,endUserImageId:p,rawUserInput:f,error:g}=yield he.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:B,responseId:H,value:t},o&&i&&{documentId:i}),P&&{studioUserId:P}),W&&{embedUserId:W}),z&&{deploymentId:z}));if(!l)throw new Error(null!=g?g:"An error occurred, please try again.");const h=[];m&&h.push(m),p&&h.push(p),h.length>0&&(a=[...n,Object.assign({id:V.length+1,role:"user",content:t},h&&{documentIds:h})],te(a),fe()),ce([]),fe();const b=(yield x({formId:B,responseId:H,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const v=b.getReader(),j=new TextDecoder,y=a.length;let k="",I=!0,w=!1;for(;I;){const{value:e,done:t}=yield v.read();I=!t;const s=j.decode(e);if(s.startsWith("[PXE-ERROR]"))throw new Error(s.replace("[PXE-ERROR]","").trim());if(k+=s.replace(/\u200B/g,""),k)w||(se("streaming"),w=!0),te([...a.slice(0,y),{id:V.length+1,role:"assistant",content:k}]);else if(!I&&!k)throw new Error("Server error")}const O=new Date;k&&(fe(),yield be.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:B,responseId:H,documentIds:u},L&&{userId:L}),P&&{studioUserId:P}),P&&(null==F?void 0:F.studioid)&&{studioId:F.studioid}),W&&{embedUserId:W}),z&&{deploymentId:z}),{messages:[Object.assign(Object.assign({role:"user",message:f},h&&{documentIds:h}),{sentAt:s}),{role:"assistant",message:k,sentAt:O}]})),se("idle"),null==Q||Q(H))}catch(e){let t=U(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(Z).find((([e])=>t.includes(e)));s?oe(s[1]):re(t),fe()}finally{se("idle"),ie(!1),pe()}}));return a((()=>{J(Se)}),[Se]),s("div",Object.assign({className:E("fixed flex w-full flex-col bottom-0 left-0","viewport"===K?"min-[767px]:relative min-[767px]:bottom-auto min-[767px]:left-auto":"absolute @[767px]/pickaxe-root:relative @[767px]/pickaxe-root:bottom-auto @[767px]/pickaxe-root:left-auto")},{children:[!$.isWhiteLabel&&o("div",Object.assign({className:"flex justify-end pr-3 pb-3 @[767px]/pickaxe-root:pr-0"},{children:o(S,{animateHover:!0})})),Se&&o(D,{data:(null==F?void 0:F.icebreakers)||[],onSend:De}),s("div",Object.assign({style:Object.assign(Object.assign({},xe),(ne||X)&&{paddingLeft:"0.75rem",paddingRight:"0.75rem"}),className:E("flex min-h-[56px] flex-col gap-y-2 px-4 py-3 pb-[15px]","block"===G.formFieldStyle&&"shadow")},{children:["idle"===Y&&ae.length>0&&o("div",Object.assign({className:E("grid grid-cols-1","viewport"===K?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:ae.map((e=>{var t,r,i;return o(l,{children:"document"===e.type?s("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:xe.borderRadius,borderColor:M.secondaryText+"50"}},{children:[o("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:M.accent,borderRadius:xe.borderRadius}},{children:le?o(O,{className:"w-5 h-5 animate-spin",style:{color:M.accentText}}):o(N,{className:"w-5 h-5",style:{color:M.accentText}})})),s("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[o("p",Object.assign({className:(E(ve.b3),"font-medium truncate")},{children:e.name})),o("p",Object.assign({className:E(ve.b4,"opacity-80 truncate")},{children:I(e.size)}))]})),o("button",Object.assign({type:"button",disabled:le||"idle"!==Y,onClick:()=>ce([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:M.accent,borderColor:xe.backgroundColor}},{children:o(C,{className:"w-4 h-4",style:{color:M.accentText}})}))]})):"image"===e.type?s("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:xe.borderRadius}},{children:["finished"===e.status?o("img",{style:{borderRadius:xe.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:""}):o("div",{className:"h-full w-full animate-pulse",style:{borderRadius:xe.borderRadius,backgroundColor:M.secondary}}),o("button",Object.assign({type:"button",disabled:le||"idle"!==Y,onClick:()=>ce([]),className:"absolute w-5 h-5 rounded-full -right-2 -top-2 flex items-center justify-center border outline-none disabled:cursor-default",style:{backgroundColor:M.accent,borderColor:xe.backgroundColor}},{children:o(C,{className:"w-4 h-4",style:{color:M.accentText}})}))]})):null},e.id)}))})),s("div",Object.assign({className:"flex items-end gap-x-2 grow"},{children:[o(A,{className:E(ve.i1,"max-h-60 mb-[0.2em] w-full border-transparent bg-transparent",!je.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:je,placeholder:null!==(T=null==F?void 0:F.placeholdertext)&&void 0!==T?T:"What do you want to talk about?",onChange:e=>ye(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),le||"idle"!==Y||De()))}}),s("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==F?void 0:F.documentuploadtype)&&s("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:Ce?M.accent+"10":void 0},disabled:le||"idle"!==Y,onClick:()=>{var e;return null===(e=ke.current)||void 0===e?void 0:e.click()}},Re,{children:[o("input",{id:"file-upload",ref:ke,type:"file",accept:[...b,...de?v:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){yield ue(Array.from(e.target.files||[])),e.target.value=""}))}),o(w,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Ce?M.accent:M.accent+"80"}})]})),o("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||je.length||ae.length&&ae.every((e=>"finished"===e.status)))&&!ee?M.accent:M.accent+"10"},disabled:le||"idle"!==Y,onClick:()=>De()},Oe,{children:o(R,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(we||je.length||ae.length&&ae.every((e=>"finished"===e.status)))&&!ee?M.accentText:M.accent+"80"}})}))]}))]}))]}))]}))};export{T as default};
@@ -1 +1 @@
1
- import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsx as r,jsxs as o}from"react/jsx-runtime";import{useState as s}from"react";import{usePickaxeContext as a}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useHover as t}from"../../../../hooks/core/useHover.js";import n from"../../../Core/Menu/index.js";import c from"../../../Core/Menu/Button.js";import i from"../../../Core/Menu/List.js";import d from"../../../../common/cn.js";const l=({id:l,children:m,placeholder:F,value:b,className:p,style:x,closeOnSelect:h=!0,maxToken:u=50,isDropdown:j=!1})=>{const{styles:y,colors:f}=a(),g=t(),{isHover:k}=g,v=e(g,["isHover"]),[w,C]=s(!1);return j?o(n,Object.assign({id:l,closeOnSelect:h,onChange:C,className:"relative"},{children:[r(c,Object.assign({variant:"anchor",className:d("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300 hover:border-black/25",p,w&&"border-black/70 shadow-none hover:border-black/70 dark:border-white/70 dark:hover:border-white/70",u<=50&&"max-w-[400px]"),style:Object.assign({backgroundColor:"#FFFFFF"===f.secondaryText?"#000000":"#FFFFFF",color:f.secondaryText,borderRadius:`${y.cornerRadius}px`,borderColor:w?f.secondaryText+"B3":k?f.secondaryText+(w?"B3":"40"):"transparent"},x)},v,{children:r("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=b?b:"")||F}))})),r(i,Object.assign({className:"p-3 shadow-md",border:"#FFFFFF"===f.secondaryText?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:u<=50?"400px":"100%",style:Object.assign({backgroundColor:"#FFFFFF"===f.secondaryText?"#000000":"#FFFFFF",color:f.secondaryText},x)},{children:m}))]})):r("div",{children:m})};export{l as default};
1
+ import{jsx as e,jsxs as s}from"react/jsx-runtime";import{usePickaxeContext as o}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleInput as r}from"../../../../hooks/studio/useStyleInput.js";import t from"../../../Core/Menu/index.js";import n from"../../../Core/Menu/Button.js";import a from"../../../Core/Menu/List.js";import i from"../../../../common/cn.js";const c=({id:c,children:l,placeholder:d,value:m,className:p,style:u,closeOnSelect:b=!0,maxToken:j=50,isDropdown:f=!1})=>{const{styles:x,colors:h}=o(),g=r();return f?s(t,Object.assign({id:c,closeOnSelect:b,className:"relative"},{children:[e(n,Object.assign({variant:"anchor",className:i("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",p,j<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},g),u)},{children:e("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=m?m:"")||d}))})),e(a,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===h.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:j<=50?"400px":"100%",style:Object.assign(Object.assign(Object.assign({},g),{borderRadius:x.cornerRadius}),u)},{children:l}))]})):e("div",{children:l})};export{c as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as s,jsx as o}from"react/jsx-runtime";import{useState as t}from"react";import{usePickaxeContext as i}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useSubmit as r}from"../../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as l}from"../../../../hooks/pickaxe/useSubmitResult.js";import{useDocument as a}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as d}from"../../Addons/Scroll/hooks/useScroll.js";import{streamer as c}from"../../../../common/api/streamer.js";import{extractUrlsFromText as u}from"../../../../common/utils.js";import{encode as m}from"@nem035/gpt-3-encoder";import p from"../../common/PickaxeBranding.js";import f from"../../common/PickaxeButton.js";import g from"../../../../common/error.js";import h from"../../../../common/cn.js";const b=({questions:b})=>{var x;const{formId:j,userId:v,studioUserId:w,deploymentId:y,pickaxe:I,misc:k,translations:O,responsiveBy:E,isShowHistory:R,setChatId:S,setIsShowHistory:q,setIsNewChat:P,onGenerateComplete:D}=i(),{status:C,limits:U,isGenerating:A,setResponse:N,setMessages:L,setStatus:B,setLimitData:T,setError:W,setIsGenerating:G}=n(),{documents:H,websiteLink:M,isUploading:X,onWebsiteUpload:_,setDocumentError:K}=a(),{scrollStartSession:Y,scrollEndSession:z,scrollToTarget:F}=d({auto:!(null==I?void 0:I.enablechatresponses)}),J=r(),Q=l(),[V,Z]=t(!1);return s("div",Object.assign({className:h("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===E?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[s("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[o(f,Object.assign({className:"px-5 min-h-[42px]",isDisabled:X||"idle"!==C||A||V,onClick:()=>e(void 0,void 0,void 0,(function*(){var e;try{if(X||"idle"!==C||A||V)return;N(null),T(null),K(""),G(!0);const s="enduserupload"===(null==I?void 0:I.documentuploadtype),o=b.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),t=H.filter((e=>"finished"===e.status)),i=u(M),n=H.map((e=>e.name)),r=i.filter((e=>!n.includes(e)));if(r.length){const e=r[r.length-1];Z(!0);const s=yield _(e);s&&(t.push(s),yield new Promise((e=>setTimeout(e,5e3)))),Z(!1)}else if(o&&s&&!t.length)return void K("Please paste a valid website/video link or drag a file to add to the knowledge base.");W("");const l=["Multiple Choice","Checkbox"];for(const e of b){if(m(e.input).length>e.maxLength&&!l.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const a=t.length?t[t.length-1]:null;let d={};b.forEach((e=>d=Object.assign(Object.assign({},d),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==a?void 0:a.name)||"":e.input}))),B("fetching"),Y(),F();const{success:p,responseId:f,data:g,actionData:h,usedDocumentIds:x,rawUserInput:k,error:O}=yield J.mutateAsync(Object.assign(Object.assign(Object.assign({formId:j,valueObj:d},s&&a&&{documentId:null!==(e=a.documentId)&&void 0!==e?e:""}),w&&{studioUserId:w}),y&&{deploymentId:y}));if(!p)throw new Error(null!=O?O:"An error occurred, please try again.");F();const E=(yield c({formId:j,responseId:f,data:g,actionData:h})).body;if(!E)throw new Error("Streaming error");const R=E.getReader(),q=new TextDecoder;let U="",z=!0,$=!1;F();const ee=b.map((e=>({id:e.id,question:e.main,answer:e.input})));for(;z;){const{value:e,done:s}=yield R.read();z=!s;const o=q.decode(e);if(o.startsWith("[PXE-ERROR]"))throw new Error(o.replace("[PXE-ERROR]","").trim());if(U+=o.replace(/\u200B/g,""),U)$||(B("streaming"),$=!0,(null==I?void 0:I.enablechatresponses)&&(S(f),P(!1))),N({formId:j,responseId:f,documentIds:x,messages:[],questions:ee,questionPrompt:k,questionResponse:U,createdAt:new Date}),(null==I?void 0:I.enablechatresponses)&&L([{id:0,role:"assistant",content:U}]);else if(!z&&!U)throw new Error("Server error")}U&&(F(),yield Q.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:j,responseId:f,documentIds:x},v&&{userId:v}),w&&{studioUserId:w}),w&&(null==I?void 0:I.studioid)&&{studioId:I.studioid}),y&&{deploymentId:y}),{questions:ee,questionPrompt:k,questionResponse:U})),B("idle"),null==D||D(f))}catch(e){let s=g(e)||"";s&&!s.includes("Unexpected token 'A',")||(s="Oops! We're experiencing high traffic at the moment. Please try again later.");const o=Object.entries(U).find((([e])=>s.includes(e)));o?T(o[1]):W(s),F()}finally{B("idle"),G(!1),Z(!1),z()}}))},{children:V?(null==O?void 0:O.processing)||"Processing...":X?(null==O?void 0:O.uploading)||"Uploading...":"fetching"===C||"streaming"===C?(null==O?void 0:O.loading)||"Loading...":null!==(x=null==I?void 0:I.submittext)&&void 0!==x?x:"Submit"})),k.isHistory&&!R&&o(f,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>q(!0)},{children:(null==O?void 0:O["see-history"])||"See history"}))]})),!k.isWhiteLabel&&o("div",Object.assign({className:"flex justify-end pr-3"},{children:o(p,{})}))]}))};export{b as default};
1
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as s,jsx as o}from"react/jsx-runtime";import{useState as t}from"react";import{usePickaxeContext as i}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useSubmit as r}from"../../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as l}from"../../../../hooks/pickaxe/useSubmitResult.js";import{useDocument as a}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as d}from"../../Addons/Scroll/hooks/useScroll.js";import{streamer as c}from"../../../../common/api/streamer.js";import{extractUrlsFromText as u}from"../../../../common/utils.js";import{encode as m}from"@nem035/gpt-3-encoder";import p from"../../common/PickaxeBranding.js";import f from"../../common/PickaxeButton.js";import g from"../../../../common/error.js";import h from"../../../../common/cn.js";const b=({questions:b})=>{var j;const{formId:x,userId:v,studioUserId:w,embedUserId:I,deploymentId:y,pickaxe:O,misc:k,translations:E,responsiveBy:R,isShowHistory:S,setChatId:U,setIsShowHistory:q,setIsNewChat:P,onGenerateComplete:D}=i(),{status:C,limits:A,isGenerating:N,setResponse:L,setMessages:B,setStatus:T,setLimitData:W,setError:G,setIsGenerating:H}=n(),{documents:M,websiteLink:X,isUploading:_,onWebsiteUpload:K,setDocumentError:Y}=a(),{scrollStartSession:z,scrollEndSession:F,scrollToTarget:J}=d({auto:!(null==O?void 0:O.enablechatresponses)}),Q=r(),V=l(),[Z,$]=t(!1);return s("div",Object.assign({className:h("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===R?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[s("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[o(f,Object.assign({className:"px-5 min-h-[42px]",isDisabled:_||"idle"!==C||N||Z,onClick:()=>e(void 0,void 0,void 0,(function*(){var e;try{if(_||"idle"!==C||N||Z)return;L(null),W(null),Y(""),H(!0);const s="enduserupload"===(null==O?void 0:O.documentuploadtype),o=b.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),t=M.filter((e=>"finished"===e.status)),i=u(X),n=M.map((e=>e.name)),r=i.filter((e=>!n.includes(e)));if(r.length){const e=r[r.length-1];$(!0);const s=yield K(e);s&&(t.push(s),yield new Promise((e=>setTimeout(e,5e3)))),$(!1)}else if(o&&s&&!t.length)return void Y("Please paste a valid website/video link or drag a file to add to the knowledge base.");G("");const l=["Multiple Choice","Checkbox"];for(const e of b){if(m(e.input).length>e.maxLength&&!l.includes(e.type))throw new Error("One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error("You must fill out all required fields.")}const a=t.length?t[t.length-1]:null;let d={};b.forEach((e=>d=Object.assign(Object.assign({},d),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==a?void 0:a.name)||"":e.input}))),T("fetching"),z(),J();const{success:p,responseId:f,data:g,actionData:h,usedDocumentIds:j,rawUserInput:k,error:E}=yield Q.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:x,valueObj:d},s&&a&&{documentId:null!==(e=a.documentId)&&void 0!==e?e:""}),w&&{studioUserId:w}),I&&{embedUserId:I}),y&&{deploymentId:y}));if(!p)throw new Error(null!=E?E:"An error occurred, please try again.");J();const R=(yield c({formId:x,responseId:f,data:g,actionData:h})).body;if(!R)throw new Error("Streaming error");const S=R.getReader(),q=new TextDecoder;let A="",F=!0,ee=!1;J();const se=b.map((e=>({id:e.id,question:e.main,answer:e.input})));for(;F;){const{value:e,done:s}=yield S.read();F=!s;const o=q.decode(e);if(o.startsWith("[PXE-ERROR]"))throw new Error(o.replace("[PXE-ERROR]","").trim());if(A+=o.replace(/\u200B/g,""),A)ee||(T("streaming"),ee=!0,(null==O?void 0:O.enablechatresponses)&&(U(f),P(!1))),L({formId:x,responseId:f,documentIds:j,messages:[],questions:se,questionPrompt:k,questionResponse:A,createdAt:new Date}),(null==O?void 0:O.enablechatresponses)&&B([{id:0,role:"assistant",content:A}]);else if(!F&&!A)throw new Error("Server error")}A&&(J(),yield V.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:x,responseId:f,documentIds:j},v&&{userId:v}),w&&{studioUserId:w}),w&&(null==O?void 0:O.studioid)&&{studioId:O.studioid}),I&&{embedUserId:I}),y&&{deploymentId:y}),{questions:se,questionPrompt:k,questionResponse:A})),T("idle"),null==D||D(f))}catch(e){let s=g(e)||"";s&&!s.includes("Unexpected token 'A',")||(s="Oops! We're experiencing high traffic at the moment. Please try again later.");const o=Object.entries(A).find((([e])=>s.includes(e)));o?W(o[1]):G(s),J()}finally{T("idle"),H(!1),$(!1),F()}}))},{children:Z?(null==E?void 0:E.processing)||"Processing...":_?(null==E?void 0:E.uploading)||"Uploading...":"fetching"===C||"streaming"===C?(null==E?void 0:E.loading)||"Loading...":null!==(j=null==O?void 0:O.submittext)&&void 0!==j?j:"Submit"})),k.isHistory&&!S&&o(f,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>q(!0)},{children:(null==E?void 0:E["see-history"])||"See history"}))]})),!k.isWhiteLabel&&o("div",Object.assign({className:"flex justify-end pr-3"},{children:o(p,{})}))]}))};export{b as default};
@@ -1,4 +1,4 @@
1
- import { type CSSProperties, type ReactNode } from "react";
1
+ import type { CSSProperties, ReactNode } from "react";
2
2
  interface DropdownProps {
3
3
  id: string;
4
4
  children: ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",