@pickaxeproject/react 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),a=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../Addons/Scroll/hooks/useScrollContext.js"),l=require("../../../../hooks/studio/useStyleFontSize.js"),o=require("../../../../hooks/pickaxe/useConversation.js"),r=require("../../common/PickaxeIcon.js"),n=require("../../../Core/ErrorAlert.js"),c=require("../../Addons/Scroll/ScrollLockView.js"),d=require("../../common/PickaxeHead.js"),u=require("../../common/PickaxeCompactHead.js"),x=require("../../common/PickaxeUpgradeCard.js"),m=require("./Message.js"),f=require("../../../../common/cn.js"),j=require("../../common/PickaxeBranding.js");exports.default=({hideInfo:h,isInputFocused:g})=>{var p;const v=o.useConversation(),w=l.useStyleFontSize(),{pickaxe:b,colors:k,misc:N,isNewChat:C,isEmbed:y,setChatId:q}=a.usePickaxeContext(),{scrollContainerRef:O}=i.useScrollContext(),{messages:S,status:P,limitData:I,error:E}=t.useResponseContext(),L=s.useMemo((()=>!!v.data&&!(v.data.messages.length<=1)),[v.data]),M=s.useMemo((()=>!h&&v.isSuccess&&C&&!L),[h,v.isSuccess,C,L]),A=s.useMemo((()=>{var e,s;return!!S.length&&!(null!==(s=null===(e=null==S?void 0:S[S.length-1])||void 0===e?void 0:e.content)&&void 0!==s?s:"").trim()}),[S]);return e.jsx("div",Object.assign({ref:O,className:"flex w-full h-[calc(100dvh-74px)] flex-col items-center overflow-y-auto mb-12 pb-8"},{children:e.jsxs("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px] px-4"},{children:[(M||!y)&&!N.isWhiteLabel&&e.jsx(j.default,{className:f.default("absolute top-4 right-4",!M&&!y&&"top-2"),animateHover:!0}),e.jsx(d.default,{className:f.default("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",M&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxLines:2,onIconClick:()=>q("")}),y&&!v.isLoading&&e.jsx(u.default,{className:f.default("opacity-0 transition-all duration-500 ease-in-out h-0 w-full",!M&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",onIconClick:()=>q("")}),e.jsx("div",Object.assign({className:f.default("flex flex-col mt-6 transition-all duration-300 ease-in-out w-full",y&&!v.isLoading&&!M&&"mt-0")},{children:v.isError?e.jsx("div",Object.assign({className:"flex w-full justify-center"},{children:e.jsxs("p",Object.assign({className:f.default(w.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e.jsx("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):v.data?e.jsxs("div",Object.assign({className:"flex flex-col w-full"},{children:[e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[v.data.messages.map(((s,a)=>e.jsx(m.default,Object.assign({index:a,message:s},0===a&&{isIntroExpand:g}),a))),S.map(((s,a)=>e.jsx(m.default,{index:v.data.messages.length+a,message:s},a))),"fetching"===P||A?e.jsxs("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:["NONE"!==(null==b?void 0:b.chaticon)&&e.jsx(r.default,{src:null!==(p=null==b?void 0:b.chaticon)&&void 0!==p?p:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/chaticons/${null==b?void 0:b.formid}.png`,alt:`${null==b?void 0:b.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6",textColor:k.text}),e.jsx("div",Object.assign({className:"flex items-center gap-x-2 rounded px-4 py-4"},{children:Array.from({length:3}).map(((s,a)=>e.jsx("div",{className:f.default("h-1.5 w-1.5 animate-dot rounded-full",1===a&&"animate-dot-down"),style:{backgroundColor:k.secondaryText}},a)))}))]})):I?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(x.default,{})})):E?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(n.default,{error:E})})):null]})),e.jsx(c.default,{className:"w-full"})]})):null}))]}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),a=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../../hooks/pickaxe/useDimensionContext.js"),o=require("../../Addons/Scroll/hooks/useScrollContext.js"),l=require("../../../../hooks/studio/useStyleFontSize.js"),n=require("../../../../hooks/pickaxe/useConversation.js"),r=require("../../common/PickaxeIcon.js"),c=require("../../../Core/ErrorAlert.js"),d=require("../../Addons/Scroll/ScrollLockView.js"),u=require("../../common/PickaxeHead.js"),x=require("../../common/PickaxeCompactHead.js"),m=require("../../common/PickaxeUpgradeCard.js"),f=require("./Message.js"),j=require("../../common/PickaxeBranding.js"),h=require("../../../../common/cn.js");exports.default=({hideInfo:g,isInputFocused:p})=>{var v;const w=n.useConversation(),k=l.useStyleFontSize(),{pickaxe:b,colors:C,misc:N,isNewChat:y,isEmbed:q,setChatId:O}=a.usePickaxeContext(),{scrollContainerRef:S}=o.useScrollContext(),{messages:P,status:I,limitData:E,error:L}=t.useResponseContext(),{height:M}=i.useDimensionContext(),A=s.useMemo((()=>!!w.data&&!(w.data.messages.length<=1)),[w.data]),H=s.useMemo((()=>!g&&w.isSuccess&&y&&!A),[g,w.isSuccess,y,A]),z=s.useMemo((()=>{var e,s;return!!P.length&&!(null!==(s=null===(e=null==P?void 0:P[P.length-1])||void 0===e?void 0:e.content)&&void 0!==s?s:"").trim()}),[P]);return e.jsx("div",Object.assign({ref:S,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-8",style:{height:`calc(${M}px - 74px)`}},{children:e.jsxs("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px] px-4"},{children:[(H||!q)&&!N.isWhiteLabel&&e.jsx(j.default,{className:h.default("absolute top-4 right-4",!H&&!q&&"top-2"),animateHover:!0}),e.jsx(u.default,{className:h.default("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",H&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxLines:2,onIconClick:()=>O("")}),q&&!w.isLoading&&e.jsx(x.default,{className:h.default("opacity-0 transition-all duration-500 ease-in-out h-0 w-full",!H&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",onIconClick:()=>O("")}),e.jsx("div",Object.assign({className:h.default("flex flex-col mt-6 transition-all duration-300 ease-in-out w-full",q&&!w.isLoading&&!H&&"mt-0")},{children:w.isError?e.jsx("div",Object.assign({className:"flex w-full justify-center"},{children:e.jsxs("p",Object.assign({className:h.default(k.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e.jsx("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):w.data?e.jsxs("div",Object.assign({className:"flex flex-col w-full"},{children:[e.jsxs("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[w.data.messages.map(((s,a)=>e.jsx(f.default,Object.assign({index:a,message:s},0===a&&{isIntroExpand:p}),a))),P.map(((s,a)=>e.jsx(f.default,{index:w.data.messages.length+a,message:s},a))),"fetching"===I||z?e.jsxs("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:["NONE"!==(null==b?void 0:b.chaticon)&&e.jsx(r.default,{src:null!==(v=null==b?void 0:b.chaticon)&&void 0!==v?v:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/chaticons/${null==b?void 0:b.formid}.png`,alt:`${null==b?void 0:b.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6",textColor:C.text}),e.jsx("div",Object.assign({className:"flex items-center gap-x-2 rounded px-4 py-4"},{children:Array.from({length:3}).map(((s,a)=>e.jsx("div",{className:h.default("h-1.5 w-1.5 animate-dot rounded-full",1===a&&"animate-dot-down"),style:{backgroundColor:C.secondaryText}},a)))}))]})):E?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(m.default,{})})):L?e.jsx("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e.jsx(c.default,{error:L})})):null]})),e.jsx(d.default,{className:"w-full"})]})):null}))]}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),i=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),a=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../../../hooks/pickaxe/useSubmitResult.js"),c=require("../../../common/documents.js"),u=require("../../../common/api/streamer.js"),m=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),h=require("../../../hooks/core/useHover.js"),p=require("../../../common/utils.js"),x=require("../../Icons/attach-vertical.svg.js"),f=require("../../Icons/spinner-lines.svg.js"),b=require("../../Icons/file.svg.js"),j=require("../../Icons/x.svg.js"),v=require("../../Icons/arrow-right.svg.js"),y=require("../Addons/IceBreaker/index.js"),w=require("../../Core/Textarea.js"),I=require("../../../common/error.js"),k=require("../../../common/cn.js");exports.default=({isFocused:O,onFocus:N,onBlur:C})=>{var q;const{formId:R,chatId:S,userId:D,studioUserId:A,embedUserId:U,deploymentId:E,pickaxe:_,styles:T,colors:F,responsiveBy:B,isNewChat:H,setIsNewChat:P,setIsShowIceBreaker:z,onGenerateComplete:M}=r.usePickaxeContext(),{messages:G,status:L,limits:W,isGenerating:$,setMessages:K,setStatus:X,setLimitData:J,setError:Q,setIsGenerating:V}=o.useResponseContext(),{documents:Y,isUploading:Z,isImageUploadAllowed:ee,upsertDocuments:se,onFileUpload:te}=m.useDocument(),{scrollStartSession:re,scrollEndSession:oe,scrollToBottom:ne}=g.useScroll({auto:!0}),ie=l.useConversation(),le=a.useSubmit(),ae=d.useSubmitResult(),de=i.useStyleFontSize(),ce=n.useStyleInput(),[ue,me]=t.useState(""),ge=t.useRef(null),he=h.useHover(),{isHover:pe}=he,xe=e.__rest(he,["isHover"]),fe=h.useHover(),{isHover:be}=fe,je=e.__rest(fe,["isHover"]),ve=t.useMemo((()=>{var e,s,t;return!!H&&(!!_&&(!ie.isLoading&&(!((null!==(s=null===(e=ie.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=_.icebreakers)||void 0===t?void 0:t.length))))}),[_,H,ie.data,ie.isLoading]),ye=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(Z||"idle"!==L||$)return;const e=null!=s?s:ue;if(!e)return;me(""),Q(""),J(null),V(!0),P(!1);const t=new Date,r="enduserupload"===(null==_?void 0:_.documentuploadtype),o=Y.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),n=o.length?o[o.length-1].documentId:"";X("fetching"),re(),ne();const i=Array.from(G);let l=[...i,{id:G.length+1,role:"user",content:e}];K(l),ne();const{success:a,data:d,actionData:c,usedDocumentIds:m,endUserDocumentId:g,endUserImageId:h,rawUserInput:p,error:x}=yield le.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:R,responseId:S,value:e},r&&n&&{documentId:n}),A&&{studioUserId:A}),U&&{embedUserId:U}),E&&{deploymentId:E}));if(!a)throw new Error(null!=x?x:"An error occurred, please try again.");const f=[];g&&f.push(g),h&&f.push(h),f.length>0&&(l=[...i,Object.assign({id:G.length+1,role:"user",content:e},f&&{documentIds:f})],K(l),ne()),se([]),ne();const b=(yield u.streamer({formId:R,responseId:S,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const j=b.getReader(),v=new TextDecoder,y=l.length;let w="",I=!0,k=!1;for(;I;){const{value:e,done:s}=yield j.read();I=!s;const t=v.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(w+=t.replace(/\u200B/g,""),w)k||(X("streaming"),k=!0),K([...l.slice(0,y),{id:G.length+1,role:"assistant",content:w}]);else if(!I&&!w)throw new Error("Server error")}const O=new Date;w&&(ne(),yield ae.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:R,responseId:S,documentIds:m},D&&{userId:D}),A&&{studioUserId:A}),A&&(null==_?void 0:_.studioid)&&{studioId:_.studioid}),U&&{embedUserId:U}),E&&{deploymentId:E}),{messages:[Object.assign(Object.assign({role:"user",message:p},f&&{documentIds:f}),{sentAt:t}),{role:"assistant",message:w,sentAt:O}]})),X("idle"),null==M||M(S))}catch(e){let s=I.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(W).find((([e])=>s.includes(e)));t?J(t[1]):Q(s),ne()}finally{X("idle"),V(!1),oe()}}));return t.useEffect((()=>{z(ve)}),[ve]),s.jsx("div",Object.assign({className:"px-4 pb-4 w-full flex flex-col items-center fixed bottom-0 left-0 z-1"},{children:s.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[s.jsx("div",Object.assign({className:"absolute right-0 bottom-full"},{children:s.jsx("div",Object.assign({className:k.default("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===B?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:ve&&!O&&s.jsx(y.default,{data:(null==_?void 0:_.icebreakers)||[],onSend:ye})}))})),s.jsxs("div",Object.assign({className:k.default("flex flex-col gap-y-2 px-4 py-3","block"===T.formFieldStyle&&"shadow"),style:ce},{children:["idle"===L&&Y.length>0&&s.jsx("div",Object.assign({className:k.default("grid grid-cols-1","viewport"===B?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:Y.map((e=>{var r,o,n;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:ce.borderRadius,borderColor:F.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:F.accent,borderRadius:ce.borderRadius}},{children:Z?s.jsx(f.default,{className:"w-5 h-5 animate-spin",style:{color:F.accentText}}):s.jsx(b.default,{className:"w-5 h-5",style:{color:F.accentText}})})),s.jsxs("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s.jsx("p",Object.assign({className:(k.default(de.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:k.default(de.b4,"opacity-80 truncate")},{children:p.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",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:F.accent,borderColor:ce.backgroundColor},disabled:Z||"idle"!==L,onClick:()=>se([])},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:F.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:ce.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:ce.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[2]}/${null===(o=e.documentId)||void 0===o?void 0:o.split("-")[1]}.${null===(n=e.documentId)||void 0===n?void 0:n.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ce.borderRadius,backgroundColor:F.secondary}}),s.jsx("button",Object.assign({type:"button",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:F.accent,borderColor:ce.backgroundColor},disabled:Z||"idle"!==L,onClick:()=>se([])},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:F.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:"flex items-end gap-x-2"},{children:[s.jsx(w.default,{className:k.default(de.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!ue.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:ue,placeholder:null!==(q=null==_?void 0:_.placeholdertext)&&void 0!==q?q:"What do you want to talk about?",onChange:e=>me(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Z||"idle"!==L||ye()))},onFocus:N,onBlur:C}),s.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==_?void 0:_.documentuploadtype)&&s.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:be?F.accent+"10":void 0},disabled:Z||"idle"!==L,onClick:()=>{var e;return null===(e=ge.current)||void 0===e?void 0:e.click()}},je,{children:[s.jsx("input",{id:"file-upload",ref:ge,type:"file",accept:[...c.allowedFileMimeTypes,...ee?c.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield te(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(x.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:be?F.accent:F.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:(pe||ue.length||Y.length&&Y.every((e=>"finished"===e.status)))&&!$?F.accent:F.accent+"10"},disabled:Z||"idle"!==L,onClick:()=>ye()},xe,{children:s.jsx(v.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(pe||ue.length||Y.length&&Y.every((e=>"finished"===e.status)))&&!$?F.accentText:F.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"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../hooks/studio/useStyleInput.js"),i=require("../../../hooks/studio/useStyleFontSize.js"),l=require("../../../hooks/pickaxe/useConversation.js"),a=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../../../hooks/pickaxe/useSubmitResult.js"),c=require("../../../common/documents.js"),u=require("../../../common/api/streamer.js"),m=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),h=require("../../../hooks/core/useHover.js"),p=require("../../../common/utils.js"),x=require("../../Icons/attach-vertical.svg.js"),f=require("../../Icons/spinner-lines.svg.js"),b=require("../../Icons/file.svg.js"),j=require("../../Icons/x.svg.js"),v=require("../../Icons/arrow-right.svg.js"),y=require("../Addons/IceBreaker/index.js"),w=require("../../Core/Textarea.js"),I=require("../../../common/error.js"),k=require("../../../common/cn.js");exports.default=({isFocused:O,onFocus:N,onBlur:C})=>{var q;const{formId:R,chatId:S,userId:D,studioUserId:A,embedUserId:U,deploymentId:E,pickaxe:_,styles:T,colors:F,responsiveBy:B,isNewChat:H,setIsNewChat:P,setIsShowIceBreaker:z,onGenerateComplete:M}=r.usePickaxeContext(),{messages:G,status:L,limits:W,isGenerating:$,setMessages:K,setStatus:X,setLimitData:J,setError:Q,setIsGenerating:V}=o.useResponseContext(),{documents:Y,isUploading:Z,isImageUploadAllowed:ee,upsertDocuments:se,onFileUpload:te}=m.useDocument(),{scrollStartSession:re,scrollEndSession:oe,scrollToBottom:ne}=g.useScroll({auto:!0}),ie=l.useConversation(),le=a.useSubmit(),ae=d.useSubmitResult(),de=i.useStyleFontSize(),ce=n.useStyleInput(),[ue,me]=t.useState(""),ge=t.useRef(null),he=h.useHover(),{isHover:pe}=he,xe=e.__rest(he,["isHover"]),fe=h.useHover(),{isHover:be}=fe,je=e.__rest(fe,["isHover"]),ve=t.useMemo((()=>{var e,s,t;return!!H&&(!!_&&(!ie.isLoading&&(!((null!==(s=null===(e=ie.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=_.icebreakers)||void 0===t?void 0:t.length))))}),[_,H,ie.data,ie.isLoading]),ye=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(Z||"idle"!==L||$)return;const e=null!=s?s:ue;if(!e)return;me(""),Q(""),J(null),V(!0),P(!1);const t=new Date,r="enduserupload"===(null==_?void 0:_.documentuploadtype),o=Y.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),n=o.length?o[o.length-1].documentId:"";X("fetching"),re(),ne();const i=Array.from(G);let l=[...i,{id:G.length+1,role:"user",content:e}];K(l),ne();const{success:a,data:d,actionData:c,usedDocumentIds:m,endUserDocumentId:g,endUserImageId:h,rawUserInput:p,error:x}=yield le.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:R,responseId:S,value:e},r&&n&&{documentId:n}),A&&{studioUserId:A}),U&&{embedUserId:U}),E&&{deploymentId:E}));if(!a)throw new Error(null!=x?x:"An error occurred, please try again.");const f=[];g&&f.push(g),h&&f.push(h),f.length>0&&(l=[...i,Object.assign({id:G.length+1,role:"user",content:e},f&&{documentIds:f})],K(l),ne()),se([]),ne();const b=(yield u.streamer({formId:R,responseId:S,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const j=b.getReader(),v=new TextDecoder,y=l.length;let w="",I=!0,k=!1;for(;I;){const{value:e,done:s}=yield j.read();I=!s;const t=v.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(w+=t.replace(/\u200B/g,""),w)k||(X("streaming"),k=!0),K([...l.slice(0,y),{id:G.length+1,role:"assistant",content:w}]);else if(!I&&!w)throw new Error("Server error")}const O=new Date;w&&(ne(),yield ae.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:R,responseId:S,documentIds:m},D&&{userId:D}),A&&{studioUserId:A}),A&&(null==_?void 0:_.studioid)&&{studioId:_.studioid}),U&&{embedUserId:U}),E&&{deploymentId:E}),{messages:[Object.assign(Object.assign({role:"user",message:p},f&&{documentIds:f}),{sentAt:t}),{role:"assistant",message:w,sentAt:O}]})),X("idle"),null==M||M(S))}catch(e){let s=I.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(W).find((([e])=>s.includes(e)));t?J(t[1]):Q(s),ne()}finally{X("idle"),V(!1),oe()}}));return t.useEffect((()=>{z(ve)}),[ve]),s.jsx("div",Object.assign({className:"px-4 pb-4 w-full flex flex-col items-center absolute bottom-0 left-0 z-1"},{children:s.jsxs("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[s.jsx("div",Object.assign({className:"absolute right-0 bottom-full"},{children:s.jsx("div",Object.assign({className:k.default("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===B?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:ve&&!O&&s.jsx(y.default,{data:(null==_?void 0:_.icebreakers)||[],onSend:ye})}))})),s.jsxs("div",Object.assign({className:k.default("flex flex-col gap-y-2 px-4 py-3","block"===T.formFieldStyle&&"shadow"),style:ce},{children:["idle"===L&&Y.length>0&&s.jsx("div",Object.assign({className:k.default("grid grid-cols-1","viewport"===B?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:Y.map((e=>{var r,o,n;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:ce.borderRadius,borderColor:F.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:F.accent,borderRadius:ce.borderRadius}},{children:Z?s.jsx(f.default,{className:"w-5 h-5 animate-spin",style:{color:F.accentText}}):s.jsx(b.default,{className:"w-5 h-5",style:{color:F.accentText}})})),s.jsxs("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s.jsx("p",Object.assign({className:(k.default(de.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:k.default(de.b4,"opacity-80 truncate")},{children:p.formatBytes(e.size)}))]})),s.jsx("button",Object.assign({type:"button",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:F.accent,borderColor:ce.backgroundColor},disabled:Z||"idle"!==L,onClick:()=>se([])},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:F.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:ce.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:ce.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[2]}/${null===(o=e.documentId)||void 0===o?void 0:o.split("-")[1]}.${null===(n=e.documentId)||void 0===n?void 0:n.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ce.borderRadius,backgroundColor:F.secondary}}),s.jsx("button",Object.assign({type:"button",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:F.accent,borderColor:ce.backgroundColor},disabled:Z||"idle"!==L,onClick:()=>se([])},{children:s.jsx(j.default,{className:"w-4 h-4",style:{color:F.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:"flex items-end gap-x-2"},{children:[s.jsx(w.default,{className:k.default(de.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!ue.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:ue,placeholder:null!==(q=null==_?void 0:_.placeholdertext)&&void 0!==q?q:"What do you want to talk about?",onChange:e=>me(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Z||"idle"!==L||ye()))},onFocus:N,onBlur:C}),s.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==_?void 0:_.documentuploadtype)&&s.jsxs("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:be?F.accent+"10":void 0},disabled:Z||"idle"!==L,onClick:()=>{var e;return null===(e=ge.current)||void 0===e?void 0:e.click()}},je,{children:[s.jsx("input",{id:"file-upload",ref:ge,type:"file",accept:[...c.allowedFileMimeTypes,...ee?c.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield te(Array.from(s.target.files||[])),s.target.value=""}))}),s.jsx(x.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:be?F.accent:F.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:(pe||ue.length||Y.length&&Y.every((e=>"finished"===e.status)))&&!$?F.accent:F.accent+"10"},disabled:Z||"idle"!==L,onClick:()=>ye()},xe,{children:s.jsx(v.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(pe||ue.length||Y.length&&Y.every((e=>"finished"===e.status)))&&!$?F.accentText:F.accent+"80"}})}))]}))]}))]}))]}))}))};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useMemo as o}from"react";import{usePickaxeContext as s}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as t}from"../../../../hooks/pickaxe/useResponseContext.js";import{useScrollContext as i}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as l}from"../../../../hooks/studio/useStyleFontSize.js";import{useConversation as r}from"../../../../hooks/pickaxe/useConversation.js";import n from"../../common/PickaxeIcon.js";import c from"../../../Core/ErrorAlert.js";import m from"../../Addons/Scroll/ScrollLockView.js";import d from"../../common/PickaxeHead.js";import p from"../../common/PickaxeCompactHead.js";import x from"../../common/PickaxeUpgradeCard.js";import f from"./Message.js";import u from"../../../../common/cn.js";import h from"../../common/PickaxeBranding.js";const g=({hideInfo:g,isInputFocused:j})=>{var v;const w=r(),b=l(),{pickaxe:k,colors:N,misc:C,isNewChat:y,isEmbed:O,setChatId:S}=s(),{scrollContainerRef:I}=i(),{messages:P,status:E,limitData:L,error:A}=t(),H=o((()=>!!w.data&&!(w.data.messages.length<=1)),[w.data]),z=o((()=>!g&&w.isSuccess&&y&&!H),[g,w.isSuccess,y,H]),F=o((()=>{var e,a;return!!P.length&&!(null!==(a=null===(e=null==P?void 0:P[P.length-1])||void 0===e?void 0:e.content)&&void 0!==a?a:"").trim()}),[P]);return e("div",Object.assign({ref:I,className:"flex w-full h-[calc(100dvh-74px)] flex-col items-center overflow-y-auto mb-12 pb-8"},{children:a("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px] px-4"},{children:[(z||!O)&&!C.isWhiteLabel&&e(h,{className:u("absolute top-4 right-4",!z&&!O&&"top-2"),animateHover:!0}),e(d,{className:u("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",z&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxLines:2,onIconClick:()=>S("")}),O&&!w.isLoading&&e(p,{className:u("opacity-0 transition-all duration-500 ease-in-out h-0 w-full",!z&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",onIconClick:()=>S("")}),e("div",Object.assign({className:u("flex flex-col mt-6 transition-all duration-300 ease-in-out w-full",O&&!w.isLoading&&!z&&"mt-0")},{children:w.isError?e("div",Object.assign({className:"flex w-full justify-center"},{children:a("p",Object.assign({className:u(b.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):w.data?a("div",Object.assign({className:"flex flex-col w-full"},{children:[a("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[w.data.messages.map(((a,o)=>e(f,Object.assign({index:o,message:a},0===o&&{isIntroExpand:j}),o))),P.map(((a,o)=>e(f,{index:w.data.messages.length+o,message:a},o))),"fetching"===E||F?a("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:["NONE"!==(null==k?void 0:k.chaticon)&&e(n,{src:null!==(v=null==k?void 0:k.chaticon)&&void 0!==v?v:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/chaticons/${null==k?void 0:k.formid}.png`,alt:`${null==k?void 0:k.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6",textColor:N.text}),e("div",Object.assign({className:"flex items-center gap-x-2 rounded px-4 py-4"},{children:Array.from({length:3}).map(((a,o)=>e("div",{className:u("h-1.5 w-1.5 animate-dot rounded-full",1===o&&"animate-dot-down"),style:{backgroundColor:N.secondaryText}},o)))}))]})):L?e("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e(x,{})})):A?e("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e(c,{error:A})})):null]})),e(m,{className:"w-full"})]})):null}))]}))}))};export{g as default};
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{useMemo as s}from"react";import{usePickaxeContext as a}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as t}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDimensionContext as i}from"../../../../hooks/pickaxe/useDimensionContext.js";import{useScrollContext as l}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as r}from"../../../../hooks/studio/useStyleFontSize.js";import{useConversation as n}from"../../../../hooks/pickaxe/useConversation.js";import c from"../../common/PickaxeIcon.js";import m from"../../../Core/ErrorAlert.js";import d from"../../Addons/Scroll/ScrollLockView.js";import p from"../../common/PickaxeHead.js";import x from"../../common/PickaxeCompactHead.js";import f from"../../common/PickaxeUpgradeCard.js";import h from"./Message.js";import u from"../../common/PickaxeBranding.js";import g from"../../../../common/cn.js";const j=({hideInfo:j,isInputFocused:v})=>{var w;const k=n(),b=r(),{pickaxe:N,colors:C,misc:y,isNewChat:O,isEmbed:S,setChatId:I}=a(),{scrollContainerRef:P}=l(),{messages:E,status:L,limitData:A,error:H}=t(),{height:$}=i(),z=s((()=>!!k.data&&!(k.data.messages.length<=1)),[k.data]),D=s((()=>!j&&k.isSuccess&&O&&!z),[j,k.isSuccess,O,z]),F=s((()=>{var e,o;return!!E.length&&!(null!==(o=null===(e=null==E?void 0:E[E.length-1])||void 0===e?void 0:e.content)&&void 0!==o?o:"").trim()}),[E]);return e("div",Object.assign({ref:P,className:"flex w-full flex-col items-center overflow-y-auto mb-12 pb-8",style:{height:`calc(${$}px - 74px)`}},{children:o("div",Object.assign({className:"relative flex flex-col items-center flex-grow w-full max-w-[800px] px-4"},{children:[(D||!S)&&!y.isWhiteLabel&&e(u,{className:g("absolute top-4 right-4",!D&&!S&&"top-2"),animateHover:!0}),e(p,{className:g("opacity-0 mt-[0%] transition-all duration-500 ease-in-out max-h-0 overflow-hidden max-w-[500px]",D&&"opacity-100 mt-[10%] max-h-[100%]"),iconClassName:"duration-300 hover:opacity-90",maxLines:2,onIconClick:()=>I("")}),S&&!k.isLoading&&e(x,{className:g("opacity-0 transition-all duration-500 ease-in-out h-0 w-full",!D&&"opacity-100 h-[56px]"),iconClassName:"duration-300 hover:opacity-90",onIconClick:()=>I("")}),e("div",Object.assign({className:g("flex flex-col mt-6 transition-all duration-300 ease-in-out w-full",S&&!k.isLoading&&!D&&"mt-0")},{children:k.isError?e("div",Object.assign({className:"flex w-full justify-center"},{children:o("p",Object.assign({className:g(b.b2,"text-center font-semibold")},{children:["Something went wrong. Please try again, or"," ",e("a",Object.assign({href:"mailto:info@pickaxeproject.com?subject=Help",target:"_blank",rel:"noreferrer"},{children:"contact us"}))," ","for help."]}))})):k.data?o("div",Object.assign({className:"flex flex-col w-full"},{children:[o("div",Object.assign({className:"grid grid-cols-1 gap-y-6 w-full"},{children:[k.data.messages.map(((o,s)=>e(h,Object.assign({index:s,message:o},0===s&&{isIntroExpand:v}),s))),E.map(((o,s)=>e(h,{index:k.data.messages.length+s,message:o},s))),"fetching"===L||F?o("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:["NONE"!==(null==N?void 0:N.chaticon)&&e(c,{src:null!==(w=null==N?void 0:N.chaticon)&&void 0!==w?w:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/chaticons/${null==N?void 0:N.formid}.png`,alt:`${null==N?void 0:N.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6",textColor:C.text}),e("div",Object.assign({className:"flex items-center gap-x-2 rounded px-4 py-4"},{children:Array.from({length:3}).map(((o,s)=>e("div",{className:g("h-1.5 w-1.5 animate-dot rounded-full",1===s&&"animate-dot-down"),style:{backgroundColor:C.secondaryText}},s)))}))]})):A?e("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e(f,{})})):H?e("div",Object.assign({className:"flex max-w-[80%] items-center gap-x-3"},{children:e(m,{error:H})})):null]})),e(d,{className:"w-full"})]})):null}))]}))}))};export{j as default};
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as s}from"../../../_virtual/_tslib.js";import{jsx as t,jsxs as o}from"react/jsx-runtime";import{useState as r,useRef as n,useMemo as i,useEffect as l,Fragment as a}from"react";import{usePickaxeContext as d}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as g}from"../../../hooks/pickaxe/useSubmitResult.js";import{allowedFileMimeTypes as h,allowedImageMimeTypes as b}from"../../../common/documents.js";import{streamer as v}from"../../../common/api/streamer.js";import{useDocument as x}from"../Addons/Document/hooks/useDocument.js";import{useScroll as j}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as y}from"../../../hooks/core/useHover.js";import{formatBytes as w}from"../../../common/utils.js";import I from"../../Icons/attach-vertical.svg.js";import k from"../../Icons/spinner-lines.svg.js";import O from"../../Icons/file.svg.js";import N from"../../Icons/x.svg.js";import C from"../../Icons/arrow-right.svg.js";import R from"../Addons/IceBreaker/index.js";import S from"../../Core/Textarea.js";import A from"../../../common/error.js";import D from"../../../common/cn.js";const U=({isFocused:U,onFocus:E,onBlur:T})=>{var B;const{formId:F,chatId:H,userId:z,studioUserId:P,embedUserId:G,deploymentId:L,pickaxe:W,styles:$,colors:K,responsiveBy:X,isNewChat:_,setIsNewChat:M,setIsShowIceBreaker:q,onGenerateComplete:J}=d(),{messages:Q,status:V,limits:Y,isGenerating:Z,setMessages:ee,setStatus:se,setLimitData:te,setError:oe,setIsGenerating:re}=c(),{documents:ne,isUploading:ie,isImageUploadAllowed:le,upsertDocuments:ae,onFileUpload:de}=x(),{scrollStartSession:ce,scrollEndSession:ue,scrollToBottom:me}=j({auto:!0}),pe=p(),fe=f(),ge=g(),he=m(),be=u(),[ve,xe]=r(""),je=n(null),ye=y(),{isHover:we}=ye,Ie=e(ye,["isHover"]),ke=y(),{isHover:Oe}=ke,Ne=e(ke,["isHover"]),Ce=i((()=>{var e,s,t;return!!_&&(!!W&&(!pe.isLoading&&(!((null!==(s=null===(e=pe.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=W.icebreakers)||void 0===t?void 0:t.length))))}),[W,_,pe.data,pe.isLoading]),Re=e=>s(void 0,void 0,void 0,(function*(){try{if(ie||"idle"!==V||Z)return;const s=null!=e?e:ve;if(!s)return;xe(""),oe(""),te(null),re(!0),M(!1);const t=new Date,o="enduserupload"===(null==W?void 0:W.documentuploadtype),r=ne.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),n=r.length?r[r.length-1].documentId:"";se("fetching"),ce(),me();const i=Array.from(Q);let l=[...i,{id:Q.length+1,role:"user",content:s}];ee(l),me();const{success:a,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:m,endUserImageId:p,rawUserInput:f,error:g}=yield fe.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,value:s},o&&n&&{documentId:n}),P&&{studioUserId:P}),G&&{embedUserId:G}),L&&{deploymentId:L}));if(!a)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&&(l=[...i,Object.assign({id:Q.length+1,role:"user",content:s},h&&{documentIds:h})],ee(l),me()),ae([]),me();const b=(yield v({formId:F,responseId:H,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const x=b.getReader(),j=new TextDecoder,y=l.length;let w="",I=!0,k=!1;for(;I;){const{value:e,done:s}=yield x.read();I=!s;const t=j.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(w+=t.replace(/\u200B/g,""),w)k||(se("streaming"),k=!0),ee([...l.slice(0,y),{id:Q.length+1,role:"assistant",content:w}]);else if(!I&&!w)throw new Error("Server error")}const O=new Date;w&&(me(),yield ge.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,documentIds:u},z&&{userId:z}),P&&{studioUserId:P}),P&&(null==W?void 0:W.studioid)&&{studioId:W.studioid}),G&&{embedUserId:G}),L&&{deploymentId:L}),{messages:[Object.assign(Object.assign({role:"user",message:f},h&&{documentIds:h}),{sentAt:t}),{role:"assistant",message:w,sentAt:O}]})),se("idle"),null==J||J(H))}catch(e){let s=A(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(Y).find((([e])=>s.includes(e)));t?te(t[1]):oe(s),me()}finally{se("idle"),re(!1),ue()}}));return l((()=>{q(Ce)}),[Ce]),t("div",Object.assign({className:"px-4 pb-4 w-full flex flex-col items-center fixed bottom-0 left-0 z-1"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[t("div",Object.assign({className:"absolute right-0 bottom-full"},{children:t("div",Object.assign({className:D("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===X?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:Ce&&!U&&t(R,{data:(null==W?void 0:W.icebreakers)||[],onSend:Re})}))})),o("div",Object.assign({className:D("flex flex-col gap-y-2 px-4 py-3","block"===$.formFieldStyle&&"shadow"),style:be},{children:["idle"===V&&ne.length>0&&t("div",Object.assign({className:D("grid grid-cols-1","viewport"===X?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:ne.map((e=>{var s,r,n;return t(a,{children:"document"===e.type?o("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:be.borderRadius,borderColor:K.secondaryText+"50"}},{children:[t("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:K.accent,borderRadius:be.borderRadius}},{children:ie?t(k,{className:"w-5 h-5 animate-spin",style:{color:K.accentText}}):t(O,{className:"w-5 h-5",style:{color:K.accentText}})})),o("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[t("p",Object.assign({className:(D(he.b3),"font-medium truncate")},{children:e.name})),t("p",Object.assign({className:D(he.b4,"opacity-80 truncate")},{children:w(e.size)}))]})),t("button",Object.assign({type:"button",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:K.accent,borderColor:be.backgroundColor},disabled:ie||"idle"!==V,onClick:()=>ae([])},{children:t(N,{className:"w-4 h-4",style:{color:K.accentText}})}))]})):"image"===e.type?o("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:be.borderRadius}},{children:["finished"===e.status?t("img",{style:{borderRadius:be.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(s=e.documentId)||void 0===s?void 0:s.split("-")[2]}/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[1]}.${null===(n=e.documentId)||void 0===n?void 0:n.split("-")[2]}`,alt:""}):t("div",{className:"h-full w-full animate-pulse",style:{borderRadius:be.borderRadius,backgroundColor:K.secondary}}),t("button",Object.assign({type:"button",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:K.accent,borderColor:be.backgroundColor},disabled:ie||"idle"!==V,onClick:()=>ae([])},{children:t(N,{className:"w-4 h-4",style:{color:K.accentText}})}))]})):null},e.id)}))})),o("div",Object.assign({className:"flex items-end gap-x-2"},{children:[t(S,{className:D(he.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!ve.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:ve,placeholder:null!==(B=null==W?void 0:W.placeholdertext)&&void 0!==B?B:"What do you want to talk about?",onChange:e=>xe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ie||"idle"!==V||Re()))},onFocus:E,onBlur:T}),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==W?void 0:W.documentuploadtype)&&o("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Oe?K.accent+"10":void 0},disabled:ie||"idle"!==V,onClick:()=>{var e;return null===(e=je.current)||void 0===e?void 0:e.click()}},Ne,{children:[t("input",{id:"file-upload",ref:je,type:"file",accept:[...h,...le?b:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>s(void 0,void 0,void 0,(function*(){yield de(Array.from(e.target.files||[])),e.target.value=""}))}),t(I,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Oe?K.accent:K.accent+"80"}})]})),t("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||ve.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!Z?K.accent:K.accent+"10"},disabled:ie||"idle"!==V,onClick:()=>Re()},Ie,{children:t(C,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(we||ve.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!Z?K.accentText:K.accent+"80"}})}))]}))]}))]}))]}))}))};export{U as default};
1
+ import{__rest as e,__awaiter as s}from"../../../_virtual/_tslib.js";import{jsx as t,jsxs as o}from"react/jsx-runtime";import{useState as r,useRef as n,useMemo as i,useEffect as l,Fragment as a}from"react";import{usePickaxeContext as d}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useSubmitResult as g}from"../../../hooks/pickaxe/useSubmitResult.js";import{allowedFileMimeTypes as h,allowedImageMimeTypes as b}from"../../../common/documents.js";import{streamer as v}from"../../../common/api/streamer.js";import{useDocument as x}from"../Addons/Document/hooks/useDocument.js";import{useScroll as j}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as y}from"../../../hooks/core/useHover.js";import{formatBytes as w}from"../../../common/utils.js";import I from"../../Icons/attach-vertical.svg.js";import k from"../../Icons/spinner-lines.svg.js";import O from"../../Icons/file.svg.js";import N from"../../Icons/x.svg.js";import C from"../../Icons/arrow-right.svg.js";import R from"../Addons/IceBreaker/index.js";import S from"../../Core/Textarea.js";import A from"../../../common/error.js";import D from"../../../common/cn.js";const U=({isFocused:U,onFocus:E,onBlur:T})=>{var B;const{formId:F,chatId:H,userId:z,studioUserId:P,embedUserId:G,deploymentId:L,pickaxe:W,styles:$,colors:K,responsiveBy:X,isNewChat:_,setIsNewChat:M,setIsShowIceBreaker:q,onGenerateComplete:J}=d(),{messages:Q,status:V,limits:Y,isGenerating:Z,setMessages:ee,setStatus:se,setLimitData:te,setError:oe,setIsGenerating:re}=c(),{documents:ne,isUploading:ie,isImageUploadAllowed:le,upsertDocuments:ae,onFileUpload:de}=x(),{scrollStartSession:ce,scrollEndSession:ue,scrollToBottom:me}=j({auto:!0}),pe=p(),fe=f(),ge=g(),he=m(),be=u(),[ve,xe]=r(""),je=n(null),ye=y(),{isHover:we}=ye,Ie=e(ye,["isHover"]),ke=y(),{isHover:Oe}=ke,Ne=e(ke,["isHover"]),Ce=i((()=>{var e,s,t;return!!_&&(!!W&&(!pe.isLoading&&(!((null!==(s=null===(e=pe.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=W.icebreakers)||void 0===t?void 0:t.length))))}),[W,_,pe.data,pe.isLoading]),Re=e=>s(void 0,void 0,void 0,(function*(){try{if(ie||"idle"!==V||Z)return;const s=null!=e?e:ve;if(!s)return;xe(""),oe(""),te(null),re(!0),M(!1);const t=new Date,o="enduserupload"===(null==W?void 0:W.documentuploadtype),r=ne.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),n=r.length?r[r.length-1].documentId:"";se("fetching"),ce(),me();const i=Array.from(Q);let l=[...i,{id:Q.length+1,role:"user",content:s}];ee(l),me();const{success:a,data:d,actionData:c,usedDocumentIds:u,endUserDocumentId:m,endUserImageId:p,rawUserInput:f,error:g}=yield fe.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,value:s},o&&n&&{documentId:n}),P&&{studioUserId:P}),G&&{embedUserId:G}),L&&{deploymentId:L}));if(!a)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&&(l=[...i,Object.assign({id:Q.length+1,role:"user",content:s},h&&{documentIds:h})],ee(l),me()),ae([]),me();const b=(yield v({formId:F,responseId:H,data:d,actionData:c})).body;if(!b)throw new Error("Streaming error");const x=b.getReader(),j=new TextDecoder,y=l.length;let w="",I=!0,k=!1;for(;I;){const{value:e,done:s}=yield x.read();I=!s;const t=j.decode(e);if(t.startsWith("[PXE-ERROR]"))throw new Error(t.replace("[PXE-ERROR]","").trim());if(w+=t.replace(/\u200B/g,""),w)k||(se("streaming"),k=!0),ee([...l.slice(0,y),{id:Q.length+1,role:"assistant",content:w}]);else if(!I&&!w)throw new Error("Server error")}const O=new Date;w&&(me(),yield ge.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:H,documentIds:u},z&&{userId:z}),P&&{studioUserId:P}),P&&(null==W?void 0:W.studioid)&&{studioId:W.studioid}),G&&{embedUserId:G}),L&&{deploymentId:L}),{messages:[Object.assign(Object.assign({role:"user",message:f},h&&{documentIds:h}),{sentAt:t}),{role:"assistant",message:w,sentAt:O}]})),se("idle"),null==J||J(H))}catch(e){let s=A(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(Y).find((([e])=>s.includes(e)));t?te(t[1]):oe(s),me()}finally{se("idle"),re(!1),ue()}}));return l((()=>{q(Ce)}),[Ce]),t("div",Object.assign({className:"px-4 pb-4 w-full flex flex-col items-center absolute bottom-0 left-0 z-1"},{children:o("div",Object.assign({className:"relative flex flex-col max-w-[800px] w-full"},{children:[t("div",Object.assign({className:"absolute right-0 bottom-full"},{children:t("div",Object.assign({className:D("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===X?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:Ce&&!U&&t(R,{data:(null==W?void 0:W.icebreakers)||[],onSend:Re})}))})),o("div",Object.assign({className:D("flex flex-col gap-y-2 px-4 py-3","block"===$.formFieldStyle&&"shadow"),style:be},{children:["idle"===V&&ne.length>0&&t("div",Object.assign({className:D("grid grid-cols-1","viewport"===X?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:ne.map((e=>{var s,r,n;return t(a,{children:"document"===e.type?o("div",Object.assign({className:"relative gap-x-[10px] flex items-center px-2 h-[56px] border",style:{borderRadius:be.borderRadius,borderColor:K.secondaryText+"50"}},{children:[t("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:K.accent,borderRadius:be.borderRadius}},{children:ie?t(k,{className:"w-5 h-5 animate-spin",style:{color:K.accentText}}):t(O,{className:"w-5 h-5",style:{color:K.accentText}})})),o("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[t("p",Object.assign({className:(D(he.b3),"font-medium truncate")},{children:e.name})),t("p",Object.assign({className:D(he.b4,"opacity-80 truncate")},{children:w(e.size)}))]})),t("button",Object.assign({type:"button",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:K.accent,borderColor:be.backgroundColor},disabled:ie||"idle"!==V,onClick:()=>ae([])},{children:t(N,{className:"w-4 h-4",style:{color:K.accentText}})}))]})):"image"===e.type?o("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:be.borderRadius}},{children:["finished"===e.status?t("img",{style:{borderRadius:be.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(s=e.documentId)||void 0===s?void 0:s.split("-")[2]}/${null===(r=e.documentId)||void 0===r?void 0:r.split("-")[1]}.${null===(n=e.documentId)||void 0===n?void 0:n.split("-")[2]}`,alt:""}):t("div",{className:"h-full w-full animate-pulse",style:{borderRadius:be.borderRadius,backgroundColor:K.secondary}}),t("button",Object.assign({type:"button",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:K.accent,borderColor:be.backgroundColor},disabled:ie||"idle"!==V,onClick:()=>ae([])},{children:t(N,{className:"w-4 h-4",style:{color:K.accentText}})}))]})):null},e.id)}))})),o("div",Object.assign({className:"flex items-end gap-x-2"},{children:[t(S,{className:D(he.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!ve.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:ve,placeholder:null!==(B=null==W?void 0:W.placeholdertext)&&void 0!==B?B:"What do you want to talk about?",onChange:e=>xe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ie||"idle"!==V||Re()))},onFocus:E,onBlur:T}),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==W?void 0:W.documentuploadtype)&&o("button",Object.assign({className:"outline-none disabled:cursor-default w-8 h-8 flex items-center justify-center rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:Oe?K.accent+"10":void 0},disabled:ie||"idle"!==V,onClick:()=>{var e;return null===(e=je.current)||void 0===e?void 0:e.click()}},Ne,{children:[t("input",{id:"file-upload",ref:je,type:"file",accept:[...h,...le?b:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>s(void 0,void 0,void 0,(function*(){yield de(Array.from(e.target.files||[])),e.target.value=""}))}),t(I,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:Oe?K.accent:K.accent+"80"}})]})),t("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||ve.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!Z?K.accent:K.accent+"10"},disabled:ie||"idle"!==V,onClick:()=>Re()},Ie,{children:t(C,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(we||ve.length||ne.length&&ne.every((e=>"finished"===e.status)))&&!Z?K.accentText:K.accent+"80"}})}))]}))]}))]}))]}))}))};export{U as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",