@pickaxeproject/react 2.0.2 → 2.1.0

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"),l=require("../../../hooks/studio/useStyleInput.js"),i=require("../../../hooks/studio/useStyleFontSize.js"),n=require("../../../hooks/pickaxe/useConversation.js"),a=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../../../common/documents.js"),c=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),m=require("../../../hooks/core/useHover.js"),x=require("../../../common/utils.js"),f=require("../../Icons/attach-vertical.svg.js"),h=require("../../Icons/spinner-lines.svg.js"),b=require("../../Icons/file.svg.js"),g=require("../../Icons/x.svg.js"),p=require("../../Icons/arrow-right.svg.js"),j=require("../Addons/IceBreaker/index.js"),v=require("../../Core/Textarea.js"),y=require("../../../common/error.js"),k=require("../../../common/cn.js");exports.default=({isFocused:w,onFocus:I,onBlur:N})=>{var O;const{formId:C,chatId:q,userId:S,studioUserId:R,embedUserId:_,deploymentId:T,pickaxe:A,styles:D,colors:F,responsiveBy:B,isNewChat:U,setIsNewChat:H,setIsShowIceBreaker:E,onGenerateComplete:z}=o.usePickaxeContext(),{messages:M,status:P,limits:L,isGenerating:$,setMessages:G,setStatus:K,setLimitData:W,setError:J}=r.useResponseContext(),{documents:Q,isUploading:V,isImageUploadAllowed:X,setDocuments:Y,onFileUpload:Z}=c.useDocument(),{scrollStartSession:ee,scrollEndSession:se,scrollToBottom:te}=u.useScroll({auto:!0}),oe=n.useConversation(),re=a.useSubmit(),[le,ie]=t.useState(""),ne=t.useRef(null),ae=m.useHover(),{isHover:de}=ae,ce=e.__rest(ae,["isHover"]),ue=m.useHover(),{isHover:me}=ue,xe=e.__rest(ue,["isHover"]),fe=i.useStyleFontSize(),he=l.useStyleInput(),be=t.useMemo((()=>{var e,s,t;return!!U&&(!!A&&(!oe.isLoading&&(!((null!==(s=null===(e=oe.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=A.icebreakers)||void 0===t?void 0:t.length))))}),[A,U,oe.data,oe.isLoading]),ge=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==P||V)return;const e=null!=s?s:le;if(!e)return;J(""),W(null),ie(""),H(!1),K("fetching"),ee(),te();const t=Q.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=t.length?t[t.length-1].documentId:"",r="enduserupload"===(null==A?void 0:A.documentuploadtype)&&o,l=[...Array.from(M),Object.assign({id:M.length+1,role:"user",content:e},r&&{documentIds:[o]})];G(l),te(),r&&Y([]);const i=(yield re.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:C,responseId:q,value:e},r&&{documentId:o}),S&&{userId:S}),R&&{studioUserId:R}),_&&{embedUserId:_}),T&&{deploymentId:T}))).body;if(!i)throw new Error("Streaming error");const n=l.length,a=new TextDecoder,d=i.getReader();let c="",u=!0,m=!1;for(;u;){const{value:e,done:s}=yield d.read();if(s){u=!1;break}const t=a.decode(e,{stream:!0}).replace(/\u200B/g,"");if("[DONE]"===t){u=!1;break}c+=t,c&&(m||(K("streaming"),m=!0),G([...l.slice(0,n),{id:M.length+1,role:"assistant",content:c}]))}null==z||z(q)}catch(e){let s=y.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(L).find((([e])=>s.includes(e)));t?W(t[1]):J(s)}finally{te(),K("idle"),se()}}));return t.useEffect((()=>{E(be)}),[be]),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:be&&!w&&s.jsx(j.default,{data:(null==A?void 0:A.icebreakers)||[],onSend:ge})}))})),s.jsxs("div",Object.assign({className:k.default("flex flex-col gap-y-2 px-4 py-3","block"===D.formFieldStyle&&"shadow"),style:he},{children:["idle"===P&&Q.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:Q.map((e=>{var o,r,l;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:he.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:he.borderRadius}},{children:V?s.jsx(h.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(fe.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:k.default(fe.b4,"opacity-80 truncate")},{children:x.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:he.backgroundColor},disabled:V||"idle"!==P,onClick:()=>Y([])},{children:s.jsx(g.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:he.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:he.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===(l=e.documentId)||void 0===l?void 0:l.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:he.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:he.backgroundColor},disabled:V||"idle"!==P,onClick:()=>Y([])},{children:s.jsx(g.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(v.default,{className:k.default(fe.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!le.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:le,placeholder:null!==(O=null==A?void 0:A.placeholdertext)&&void 0!==O?O:"What do you want to talk about?",onChange:e=>ie(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),V||"idle"!==P||ge()))},onFocus:I,onBlur:N}),s.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==A?void 0:A.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:me?F.accent+"10":void 0},disabled:V||"idle"!==P,onClick:()=>{var e;return null===(e=ne.current)||void 0===e?void 0:e.click()}},xe,{children:[s.jsx("input",{id:"file-upload",ref:ne,type:"file",accept:[...d.allowedFileMimeTypes,...X?d.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield Z(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:me?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:(de||le.length||Q.length&&Q.every((e=>"finished"===e.status)))&&!$?F.accent:F.accent+"10"},disabled:V||"idle"!==P,onClick:()=>ge()},ce,{children:s.jsx(p.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(de||le.length||Q.length&&Q.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"),o=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),l=require("../../../hooks/studio/useStyleInput.js"),n=require("../../../hooks/studio/useStyleFontSize.js"),i=require("../../../hooks/pickaxe/useConversation.js"),a=require("../../../hooks/pickaxe/useSubmit.js"),d=require("../Addons/Document/hooks/useDocument.js"),c=require("../Addons/Scroll/hooks/useScroll.js"),u=require("../../../hooks/core/useHover.js"),m=require("../../../common/utils.js"),x=require("../../../common/documents.js"),f=require("eventsource-parser"),h=require("../../Icons/attach-vertical.svg.js"),p=require("../../Icons/spinner-lines.svg.js"),g=require("../../Icons/file.svg.js"),b=require("../../Icons/x.svg.js"),j=require("../../Icons/arrow-right.svg.js"),v=require("../Addons/IceBreaker/index.js"),y=require("../../Core/Textarea.js"),k=require("../../../common/error.js"),w=require("../../../common/cn.js");exports.default=({isFocused:I,onFocus:N,onBlur:O})=>{var C;const{formId:q,chatId:S,userId:R,studioUserId:_,embedUserId:T,deploymentId:A,pickaxe:F,styles:B,colors:D,responsiveBy:U,isNewChat:H,setIsNewChat:E,setIsShowIceBreaker:z,onGenerateComplete:M}=o.usePickaxeContext(),{messages:P,status:L,limits:$,isGenerating:G,setMessages:K,setStatus:W,setLimitData:J,setError:Q}=r.useResponseContext(),{documents:V,isUploading:X,isImageUploadAllowed:Y,setDocuments:Z,onFileUpload:ee}=d.useDocument(),{scrollStartSession:se,scrollEndSession:te,scrollToBottom:oe}=c.useScroll({auto:!0}),re=i.useConversation(),le=a.useSubmit(),[ne,ie]=t.useState(""),ae=t.useRef(null),de=u.useHover(),{isHover:ce}=de,ue=e.__rest(de,["isHover"]),me=u.useHover(),{isHover:xe}=me,fe=e.__rest(me,["isHover"]),he=n.useStyleFontSize(),pe=l.useStyleInput(),ge=t.useMemo((()=>{var e,s,t;return!!H&&(!!F&&(!re.isLoading&&(!((null!==(s=null===(e=re.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=F.icebreakers)||void 0===t?void 0:t.length))))}),[F,H,re.data,re.isLoading]),be=s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==L||X)return;const e=null!=s?s:ne;if(!e)return;Q(""),J(null),ie(""),E(!1),W("fetching"),se(),oe();const t=V.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=t.length?t[t.length-1].documentId:"",r="enduserupload"===(null==F?void 0:F.documentuploadtype)&&o,l=[...Array.from(P),Object.assign({id:P.length+1,role:"user",content:e},r&&{documentIds:[o]})];K(l),oe(),r&&Z([]);const n=(yield le.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:q,responseId:S,value:e},r&&{documentId:o}),R&&{userId:R}),_&&{studioUserId:_}),T&&{embedUserId:T}),A&&{deploymentId:A}))).body;if(!n)throw new Error("Streaming error");const i=l.length,a=new TextDecoder,d=n.getReader();let c="",u=!0,m=!1;const x=f.createParser({onEvent:e=>{if("delta"===e.event){const s=JSON.parse(e.data).token.replace(/\u200B/g,"");c+=s,K([...l.slice(0,i),{id:P.length+1,role:"assistant",content:c}])}else"stop"===e.event&&(u=!1)}});for(;u;){const{value:e,done:s}=yield d.read();if(s){u=!1;break}const t=a.decode(e);t&&(m||(W("streaming"),m=!0),x.feed(t))}null==M||M(S)}catch(e){let s=k.default(e)||"";s&&!s.includes("Unexpected token 'A',")||(s="Oops! We're experiencing high traffic at the moment. Please try again later.");const t=Object.entries($).find((([e])=>s.includes(e)));t?J(t[1]):Q(s)}finally{oe(),W("idle"),te()}}));return t.useEffect((()=>{z(ge)}),[ge]),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:w.default("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===U?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:ge&&!I&&s.jsx(v.default,{data:(null==F?void 0:F.icebreakers)||[],onSend:be})}))})),s.jsxs("div",Object.assign({className:w.default("flex flex-col gap-y-2 px-4 py-3","block"===B.formFieldStyle&&"shadow"),style:pe},{children:["idle"===L&&V.length>0&&s.jsx("div",Object.assign({className:w.default("grid grid-cols-1","viewport"===U?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:V.map((e=>{var o,r,l;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:pe.borderRadius,borderColor:D.secondaryText+"50"}},{children:[s.jsx("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:D.accent,borderRadius:pe.borderRadius}},{children:X?s.jsx(p.default,{className:"w-5 h-5 animate-spin",style:{color:D.accentText}}):s.jsx(g.default,{className:"w-5 h-5",style:{color:D.accentText}})})),s.jsxs("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s.jsx("p",Object.assign({className:(w.default(he.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:w.default(he.b4,"opacity-80 truncate")},{children:m.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:D.accent,borderColor:pe.backgroundColor},disabled:X||"idle"!==L,onClick:()=>Z([])},{children:s.jsx(b.default,{className:"w-4 h-4",style:{color:D.accentText}})}))]})):"image"===e.type?s.jsxs("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:pe.borderRadius}},{children:["finished"===e.status?s.jsx("img",{style:{borderRadius:pe.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===(l=e.documentId)||void 0===l?void 0:l.split("-")[2]}`,alt:""}):s.jsx("div",{className:"h-full w-full animate-pulse",style:{borderRadius:pe.borderRadius,backgroundColor:D.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:D.accent,borderColor:pe.backgroundColor},disabled:X||"idle"!==L,onClick:()=>Z([])},{children:s.jsx(b.default,{className:"w-4 h-4",style:{color:D.accentText}})}))]})):null},e.id)}))})),s.jsxs("div",Object.assign({className:"flex items-end gap-x-2"},{children:[s.jsx(y.default,{className:w.default(he.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!ne.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:ne,placeholder:null!==(C=null==F?void 0:F.placeholdertext)&&void 0!==C?C:"What do you want to talk about?",onChange:e=>ie(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),X||"idle"!==L||be()))},onFocus:N,onBlur:O}),s.jsxs("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==F?void 0:F.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:xe?D.accent+"10":void 0},disabled:X||"idle"!==L,onClick:()=>{var e;return null===(e=ae.current)||void 0===e?void 0:e.click()}},fe,{children:[s.jsx("input",{id:"file-upload",ref:ae,type:"file",accept:[...x.allowedFileMimeTypes,...Y?x.allowedImageMimeTypes:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:s=>e.__awaiter(void 0,void 0,void 0,(function*(){yield ee(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:xe?D.accent:D.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:(ce||ne.length||V.length&&V.every((e=>"finished"===e.status)))&&!G?D.accent:D.accent+"10"},disabled:X||"idle"!==L,onClick:()=>be()},ue,{children:s.jsx(j.default,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(ce||ne.length||V.length&&V.every((e=>"finished"===e.status)))&&!G?D.accentText:D.accent+"80"}})}))]}))]}))]}))]}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),o=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../Addons/Scroll/hooks/useScrollContext.js"),l=require("../../../../hooks/studio/useStyleFontSize.js"),n=require("../../common/PickaxeMarkdown/index.js"),a=require("../../common/PickaxeMarkdown/Renderer.js"),i=require("date-fns"),c=require("../../../Icons/visitor.svg.js"),d=require("../../common/PickaxeIcon.js"),u=require("../../common/PickaxeCopyButton.js"),x=require("../../Addons/Scroll/ScrollLockView.js"),p=require("../../../../common/cn.js");exports.default=()=>{var h;const{pickaxe:m,styles:j,colors:f,misc:b,translations:g}=o.usePickaxeContext(),{response:k}=t.useResponseContext(),{scrollTargetRef:v}=r.useScrollContext(),y=l.useStyleFontSize(),w=s.useMemo((()=>k?i.format(k.sentAt,"hh:mm a MMM dd, yy"):i.format(new Date,"hh:mm a MMM dd, yy")),[k]),q=s.useMemo((()=>{var e;if(!k)return"";return(null!==(e=k.questions)&&void 0!==e?e:[]).map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 500;">${e.question}</p>\n <p>${e.answer||"n/a"}</p>\n</div>`)).join("")}),[k]);return k?e.jsxs("div",Object.assign({ref:v,className:"flex flex-col shadow-black transition duration-300 hover:shadow"},{children:[e.jsxs("div",Object.assign({className:"flex gap-x-3 overflow-hidden px-4 py-5",style:{backgroundColor:f.primary,color:f.text}},{children:[e.jsx("div",Object.assign({className:"shrink-0 pt-1"},{children:e.jsx(c.default,{className:"h-6 w-6"})})),e.jsxs("div",Object.assign({className:"flex flex-col gap-y-1 overflow-x-auto pb-[6px] scrollbar scrollbar-thin"},{children:[e.jsx("input",{id:`${k.responseId}-input`,type:"checkbox",className:"peer hidden",defaultChecked:q.length<280}),e.jsx("div",{className:"danger-html hidden flex-col opacity-50 peer-checked:flex",dangerouslySetInnerHTML:{__html:q}}),e.jsx("label",Object.assign({htmlFor:`${k.responseId}-input`,className:p.default(y.b3,"mt-1 flex shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:hidden hover:cursor-pointer"),style:{color:f.accent}},{children:(null==g?void 0:g["see-input"])||"See input"})),e.jsx("label",Object.assign({htmlFor:`${k.responseId}-input`,className:p.default(y.b3,"hidden shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:flex hover:cursor-pointer"),style:{color:f.accent}},{children:(null==g?void 0:g["hide-input"])||"Hide input"}))]}))]})),e.jsxs("div",Object.assign({className:"flex gap-x-3 px-4 py-5",style:{backgroundColor:f.secondary,color:f.secondaryText}},{children:[b.isChatImage&&e.jsx(d.default,{src:null==m?void 0:m.chaticon,alt:`${null==m?void 0:m.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6 pt-1",textColor:f.secondaryText}),e.jsxs("div",Object.assign({className:"flex w-full flex-col gap-y-2 overflow-hidden"},{children:[e.jsx(n.PickaxeMarkdown,Object.assign({theme:j.theme,accentColor:f.accent,actions:!0},{children:e.jsx(a.PickaxeMarkdownRenderer,{className:"overflow-x-auto pb-2 font-semilight opacity-90 scrollbar scrollbar-thin",value:k.questionResponse})})),e.jsxs("div",Object.assign({className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1"},{children:[e.jsx("div",Object.assign({className:"flex items-center gap-3"},{children:e.jsx(u.default,{color:f.accent,text:null!==(h=k.questionResponse)&&void 0!==h?h:""})})),e.jsx("div",Object.assign({className:"flex shrink-0 grow justify-end"},{children:e.jsx("p",Object.assign({className:p.default(y.b3,"font-semibold uppercase opacity-30")},{children:w}))}))]}))]}))]})),e.jsx(x.default,{className:"w-full"})]})):null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),o=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../Addons/Scroll/hooks/useScrollContext.js"),r=require("../../../../hooks/studio/useStyleFontSize.js"),a=require("../../Addons/Document/hooks/useDocument.js"),l=require("../../common/PickaxeMarkdown/index.js"),i=require("../../common/PickaxeMarkdown/Renderer.js"),c=require("date-fns"),d=require("../../../Icons/message-square-notes.svg.js"),u=require("../../../Icons/visitor.svg.js"),x=require("../../common/PickaxeIcon.js"),p=require("../../common/PickaxeCopyButton.js"),h=require("../../common/PickaxeSimpleButton.js"),m=require("../../Addons/Scroll/ScrollLockView.js"),j=require("../../../../common/cn.js");exports.default=()=>{var f;const{pickaxe:b,styles:g,colors:k,misc:v,translations:y,setChatId:w,setIsNewChat:q}=o.usePickaxeContext(),{response:N}=t.useResponseContext(),{scrollTargetRef:C}=n.useScrollContext(),{setDocuments:O}=a.useDocument(),M=r.useStyleFontSize(),I=s.useMemo((()=>N?c.format(N.sentAt,"hh:mm a MMM dd, yy"):c.format(new Date,"hh:mm a MMM dd, yy")),[N]),S=s.useMemo((()=>{var e;if(!N)return"";return(null!==(e=N.questions)&&void 0!==e?e:[]).map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 500;">${e.question}</p>\n <p>${e.answer||"n/a"}</p>\n</div>`)).join("")}),[N]);return N?e.jsxs("div",Object.assign({ref:C,className:"flex flex-col shadow-black transition duration-300 hover:shadow"},{children:[e.jsxs("div",Object.assign({className:"flex gap-x-3 overflow-hidden px-4 py-5",style:{backgroundColor:k.primary,color:k.text}},{children:[e.jsx("div",Object.assign({className:"shrink-0 pt-1"},{children:e.jsx(u.default,{className:"h-6 w-6"})})),e.jsxs("div",Object.assign({className:"flex flex-col gap-y-1 overflow-x-auto pb-[6px] scrollbar scrollbar-thin"},{children:[e.jsx("input",{id:`${N.responseId}-input`,type:"checkbox",className:"peer hidden",defaultChecked:S.length<280}),e.jsx("div",{className:"danger-html hidden flex-col opacity-50 peer-checked:flex",dangerouslySetInnerHTML:{__html:S}}),e.jsx("label",Object.assign({htmlFor:`${N.responseId}-input`,className:j.default(M.b3,"mt-1 flex shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:hidden hover:cursor-pointer"),style:{color:k.accent}},{children:(null==y?void 0:y["see-input"])||"See input"})),e.jsx("label",Object.assign({htmlFor:`${N.responseId}-input`,className:j.default(M.b3,"hidden shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:flex hover:cursor-pointer"),style:{color:k.accent}},{children:(null==y?void 0:y["hide-input"])||"Hide input"}))]}))]})),e.jsxs("div",Object.assign({className:"flex gap-x-3 px-4 py-5",style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[v.isChatImage&&e.jsx(x.default,{src:null==b?void 0:b.chaticon,alt:`${null==b?void 0:b.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6 pt-1",textColor:k.secondaryText}),e.jsxs("div",Object.assign({className:"flex w-full flex-col gap-y-2 overflow-hidden"},{children:[e.jsx(l.PickaxeMarkdown,Object.assign({theme:g.theme,accentColor:k.accent,actions:!0},{children:e.jsx(i.PickaxeMarkdownRenderer,{className:"overflow-x-auto pb-2 font-semilight opacity-90 scrollbar scrollbar-thin",value:N.questionResponse})})),e.jsxs("div",Object.assign({className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[(null==b?void 0:b.enablechatresponses)&&e.jsxs(h.default,Object.assign({color:k.accent,onClick:()=>{return e=N.responseId,O([]),q(!1),void w(e);var e}},{children:[e.jsx(d.default,{className:"pxe-h-4 pxe-w-4 pxe-shrink-0"}),e.jsx("p",Object.assign({className:j.default(M.b3,"pxe-font-semibold")},{children:N.messageCount+1}))]})),e.jsx(p.default,{color:k.accent,text:null!==(f=N.questionResponse)&&void 0!==f?f:""})]})),e.jsx("div",Object.assign({className:"flex shrink-0 grow justify-end"},{children:e.jsx("p",Object.assign({className:j.default(M.b3,"font-semibold uppercase opacity-30")},{children:I}))}))]}))]}))]})),e.jsx(m.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"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../../hooks/pickaxe/useSubmit.js"),r=require("../../Addons/Document/hooks/useDocument.js"),l=require("../../Addons/Scroll/hooks/useScroll.js"),a=require("../../../../common/utils.js"),d=require("@nem035/gpt-3-encoder"),u=require("../../common/PickaxeBranding.js"),c=require("../../common/PickaxeButton.js"),m=require("../../../../common/error.js"),p=require("../../../../common/cn.js");exports.default=({questions:f})=>{var g;const{formId:h,userId:x,studioUserId:b,embedUserId:j,deploymentId:v,pickaxe:w,misc:k,translations:y,responsiveBy:I,isShowHistory:q,setChatId:O,setIsShowHistory:S,setIsNewChat:C,onGenerateComplete:D}=i.usePickaxeContext(),{status:P,limits:U,isGenerating:E,setResponse:R,setMessages:N,setStatus:_,setLimitData:A,setError:L}=n.useResponseContext(),{documents:T,websiteLink:B,isUploading:H,onWebsiteUpload:M,setDocumentError:W}=r.useDocument(),{scrollStartSession:G,scrollEndSession:F,scrollToTarget:K}=l.useScroll({auto:!(null==w?void 0:w.enablechatresponses)}),X=o.useSubmit(),[Y,z]=t.useState(!1);return s.jsxs("div",Object.assign({className:p.default("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===I?"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(c.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:H||"idle"!==P||E||Y,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==P||H||Y)return;L(""),A(null),W(""),R(null);const e=["Multiple Choice","Checkbox"];for(const s of f){if(d.encode(s.input).length>s.maxLength&&!e.includes(s.type))throw new Error("One or more of your responses is too long!");if(s.isRequired&&!s.input.trim()&&"userinput:documentupload"!==s.id)throw new Error("You must fill out all required fields.")}const s=T.filter((e=>"finished"===e.status)),t=T.map((e=>e.name)),i="enduserupload"===(null==w?void 0:w.documentuploadtype),n=f.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),o=a.extractUrlsFromText(B).filter((e=>!t.includes(e)));if(o.length){const e=o[o.length-1];z(!0);const t=yield M(e);t&&(s.push(t),yield new Promise((e=>setTimeout(e,5e3)))),z(!1)}else if(n&&i&&!s.length)return void W("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=s.length?s[s.length-1]:null,l=i&&r&&"finished"===r.status;let u={};f.forEach((e=>u=Object.assign(Object.assign({},u),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==r?void 0:r.name)||"":e.input}))),_("fetching"),G(),K();const c=yield X.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:h,valueObj:u},l&&{documentId:r.documentId}),x&&{userId:x}),b&&{studioUserId:b}),j&&{embedUserId:j}),v&&{deploymentId:v})),m=c.body;if(!m)throw new Error("Streaming error");const p=c.headers.get("X-Pickaxe-Response-Id");if(!p)throw new Error("Response ID not found");const g=new TextDecoder,k=m.getReader();let y="",I=!0,q=!1;for(;I;){const{value:e,done:s}=yield k.read();if(s){I=!1;break}const t=g.decode(e,{stream:!0}).replace(/\u200B/g,"");if("[DONE]"===t){I=!1;break}y+=t,y&&(q||(_("streaming"),q=!0,(null==w?void 0:w.enablechatresponses)&&(O(p),C(!1))),R({formId:h,responseId:p,documentIds:r&&r.documentId?[r.documentId]:[],questions:f.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:y,sentAt:new Date}),(null==w?void 0:w.enablechatresponses)&&N([{id:0,role:"assistant",content:y}]))}null==D||D(p)}catch(e){let s=m.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(U).find((([e])=>s.includes(e)));t?A(t[1]):L(s),K()}finally{_("idle"),z(!1),F()}}))},{children:Y?(null==y?void 0:y.processing)||"Processing...":H?(null==y?void 0:y.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==y?void 0:y.loading)||"Loading...":null!==(g=null==w?void 0:w.submittext)&&void 0!==g?g:"Submit"})),k.isHistory&&!q&&s.jsx(c.default,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>S(!0)},{children:(null==y?void 0:y["see-history"])||"See history"}))]})),!k.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:s.jsx(u.default,{})}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../../hooks/pickaxe/useSubmit.js"),r=require("../../Addons/Document/hooks/useDocument.js"),l=require("../../Addons/Scroll/hooks/useScroll.js"),a=require("../../../../common/utils.js"),d=require("@nem035/gpt-3-encoder"),u=require("eventsource-parser"),c=require("../../common/PickaxeBranding.js"),m=require("../../common/PickaxeButton.js"),p=require("../../../../common/error.js"),f=require("../../../../common/cn.js");exports.default=({questions:g})=>{var h;const{formId:x,userId:b,studioUserId:j,embedUserId:v,deploymentId:w,pickaxe:k,misc:y,translations:q,responsiveBy:I,isShowHistory:O,setChatId:S,setIsShowHistory:C,setIsNewChat:P,onGenerateComplete:U}=n.usePickaxeContext(),{status:D,limits:E,isGenerating:R,setResponse:N,setMessages:_,setStatus:A,setLimitData:L,setError:T}=o.useResponseContext(),{documents:B,websiteLink:H,isUploading:M,onWebsiteUpload:W,setDocumentError:G}=r.useDocument(),{scrollStartSession:F,scrollEndSession:J,scrollToTarget:K}=l.useScroll({auto:!(null==k?void 0:k.enablechatresponses)}),X=i.useSubmit(),[Y,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"===I?"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(m.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:M||"idle"!==D||R||Y,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if("idle"!==D||M||Y)return;T(""),L(null),G(""),N(null);const e=["Multiple Choice","Checkbox"];for(const s of g){if(d.encode(s.input).length>s.maxLength&&!e.includes(s.type))throw new Error("One or more of your responses is too long!");if(s.isRequired&&!s.input.trim()&&"userinput:documentupload"!==s.id)throw new Error("You must fill out all required fields.")}const s=B.filter((e=>"finished"===e.status)),t=B.map((e=>e.name)),n="enduserupload"===(null==k?void 0:k.documentuploadtype),o=g.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),i=a.extractUrlsFromText(H).filter((e=>!t.includes(e)));if(i.length){const e=i[i.length-1];z(!0);const t=yield W(e);t&&(s.push(t),yield new Promise((e=>setTimeout(e,5e3)))),z(!1)}else if(o&&n&&!s.length)return void G("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=s.length?s[s.length-1]:null,l=n&&r&&"finished"===r.status;let c={};g.forEach((e=>c=Object.assign(Object.assign({},c),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==r?void 0:r.name)||"":e.input}))),A("fetching"),F(),K();const m=yield X.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:x,valueObj:c},l&&{documentId:r.documentId}),b&&{userId:b}),j&&{studioUserId:j}),v&&{embedUserId:v}),w&&{deploymentId:w})),p=m.body;if(!p)throw new Error("Streaming error");const f=m.headers.get("X-Pickaxe-Response-Id");if(!f)throw new Error("Response ID not found");const h=new TextDecoder,y=p.getReader();let q="",I=!0,O=!1;const C=u.createParser({onEvent:e=>{if("delta"===e.event){const s=JSON.parse(e.data).token.replace(/\u200B/g,"");q+=s,N({formId:x,responseId:f,documentIds:r&&r.documentId?[r.documentId]:[],questions:g.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:q,messageCount:0,sentAt:new Date}),(null==k?void 0:k.enablechatresponses)&&_([{id:0,role:"assistant",content:q}])}else"stop"===e.event&&(I=!1)}});for(;I;){const{value:e,done:s}=yield y.read();if(s){I=!1;break}const t=h.decode(e);t&&(O||(A("streaming"),O=!0,(null==k?void 0:k.enablechatresponses)&&(S(f),P(!1))),C.feed(t))}null==U||U(f)}catch(e){let s=p.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(E).find((([e])=>s.includes(e)));t?L(t[1]):T(s),K()}finally{A("idle"),z(!1),J()}}))},{children:Y?(null==q?void 0:q.processing)||"Processing...":M?(null==q?void 0:q.uploading)||"Uploading...":"fetching"===D||"streaming"===D?(null==q?void 0:q.loading)||"Loading...":null!==(h=null==k?void 0:k.submittext)&&void 0!==h?h:"Submit"})),y.isHistory&&!O&&s.jsx(m.default,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>C(!0)},{children:(null==q?void 0:q["see-history"])||"See history"}))]})),!y.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:s.jsx(c.default,{})}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("@tanstack/react-query");exports.useSubmit=()=>s.useMutation({mutationFn:s=>(({formId:s,responseId:t,documentId:r,studioUserId:o,deploymentId:n,embedUserId:i,pickaxe:c,value:a,valueObj:d})=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=yield fetch(`${process.env.NEXT_PUBLIC_API_URL}/pickaxe/sse`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},t&&{responseId:t}),r&&{documentId:r}),o&&{studioUserId:o}),n&&{deploymentId:n}),i&&{embedUserId:i}),c&&{pickaxe:c}),a&&{value:a}),d&&{valueObj:d}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}));if(200!==e.status){const s=yield e.json();throw new Error(s.error||"Unknown error, please contact support")}if("application/json"===e.headers.get("content-type")){const{success:s,error:t}=yield e.json();if(!s)throw new Error(t||"Unknown error, please contact support")}return e})))(s)});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("@tanstack/react-query");exports.useSubmit=()=>s.useMutation({mutationFn:s=>(({formId:s,responseId:t,documentId:r,studioUserId:n,deploymentId:o,embedUserId:a,pickaxe:i,value:c,valueObj:d,metadata:p})=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=yield fetch(`${process.env.NEXT_PUBLIC_API_URL}/pickaxe/sse`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},t&&{responseId:t}),r&&{documentId:r}),n&&{studioUserId:n}),o&&{deploymentId:o}),a&&{embedUserId:a}),i&&{pickaxe:i}),c&&{value:c}),d&&{valueObj:d}),p&&{metadata:p}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}));if(200!==e.status){const s=yield e.json();throw new Error(s.error||"Unknown error, please contact support")}if("application/json"===e.headers.get("content-type")){const{success:s,error:t}=yield e.json();if(!s)throw new Error(t||"Unknown error, please contact support")}return e})))(s)});
@@ -9,6 +9,7 @@ type MutationParams = {
9
9
  pickaxe?: Partial<Pickaxe>;
10
10
  value?: string;
11
11
  valueObj?: Record<string, string>;
12
+ metadata?: Record<string, unknown>;
12
13
  };
13
14
  export declare const useSubmit: () => import("@tanstack/react-query").UseMutationResult<Response, Error, MutationParams, unknown>;
14
15
  export {};
@@ -29,5 +29,6 @@ export type MemoryStoredResponse = {
29
29
  documentIds: string[];
30
30
  questions: PickaxeHistoryQuestion[];
31
31
  questionResponse: string;
32
+ messageCount: number;
32
33
  sentAt: Date;
33
34
  };
@@ -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 i,useMemo as n,useEffect as l,Fragment as a}from"react";import{usePickaxeContext as c}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{allowedFileMimeTypes as h,allowedImageMimeTypes as b}from"../../../common/documents.js";import{useDocument as g}from"../Addons/Document/hooks/useDocument.js";import{useScroll as v}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as x}from"../../../hooks/core/useHover.js";import{formatBytes as y}from"../../../common/utils.js";import j from"../../Icons/attach-vertical.svg.js";import k from"../../Icons/spinner-lines.svg.js";import w from"../../Icons/file.svg.js";import N from"../../Icons/x.svg.js";import I from"../../Icons/arrow-right.svg.js";import O from"../Addons/IceBreaker/index.js";import C from"../../Core/Textarea.js";import S from"../../../common/error.js";import R from"../../../common/cn.js";const A=({isFocused:A,onFocus:T,onBlur:D})=>{var U;const{formId:B,chatId:F,userId:E,studioUserId:H,embedUserId:z,deploymentId:L,pickaxe:$,styles:G,colors:K,responsiveBy:P,isNewChat:W,setIsNewChat:_,setIsShowIceBreaker:M,onGenerateComplete:q}=c(),{messages:J,status:Q,limits:V,isGenerating:X,setMessages:Y,setStatus:Z,setLimitData:ee,setError:se}=d(),{documents:te,isUploading:oe,isImageUploadAllowed:re,setDocuments:ie,onFileUpload:ne}=g(),{scrollStartSession:le,scrollEndSession:ae,scrollToBottom:ce}=v({auto:!0}),de=p(),ue=f(),[me,pe]=r(""),fe=i(null),he=x(),{isHover:be}=he,ge=e(he,["isHover"]),ve=x(),{isHover:xe}=ve,ye=e(ve,["isHover"]),je=m(),ke=u(),we=n((()=>{var e,s,t;return!!W&&(!!$&&(!de.isLoading&&(!((null!==(s=null===(e=de.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))))}),[$,W,de.data,de.isLoading]),Ne=e=>s(void 0,void 0,void 0,(function*(){try{if("idle"!==Q||oe)return;const s=null!=e?e:me;if(!s)return;se(""),ee(null),pe(""),_(!1),Z("fetching"),le(),ce();const t=te.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=t.length?t[t.length-1].documentId:"",r="enduserupload"===(null==$?void 0:$.documentuploadtype)&&o,i=[...Array.from(J),Object.assign({id:J.length+1,role:"user",content:s},r&&{documentIds:[o]})];Y(i),ce(),r&&ie([]);const n=(yield ue.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:B,responseId:F,value:s},r&&{documentId:o}),E&&{userId:E}),H&&{studioUserId:H}),z&&{embedUserId:z}),L&&{deploymentId:L}))).body;if(!n)throw new Error("Streaming error");const l=i.length,a=new TextDecoder,c=n.getReader();let d="",u=!0,m=!1;for(;u;){const{value:e,done:s}=yield c.read();if(s){u=!1;break}const t=a.decode(e,{stream:!0}).replace(/\u200B/g,"");if("[DONE]"===t){u=!1;break}d+=t,d&&(m||(Z("streaming"),m=!0),Y([...i.slice(0,l),{id:J.length+1,role:"assistant",content:d}]))}null==q||q(F)}catch(e){let s=S(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(V).find((([e])=>s.includes(e)));t?ee(t[1]):se(s)}finally{ce(),Z("idle"),ae()}}));return l((()=>{M(we)}),[we]),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:R("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===P?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:we&&!A&&t(O,{data:(null==$?void 0:$.icebreakers)||[],onSend:Ne})}))})),o("div",Object.assign({className:R("flex flex-col gap-y-2 px-4 py-3","block"===G.formFieldStyle&&"shadow"),style:ke},{children:["idle"===Q&&te.length>0&&t("div",Object.assign({className:R("grid grid-cols-1","viewport"===P?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:te.map((e=>{var s,r,i;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:ke.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:ke.borderRadius}},{children:oe?t(k,{className:"w-5 h-5 animate-spin",style:{color:K.accentText}}):t(w,{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:(R(je.b3),"font-medium truncate")},{children:e.name})),t("p",Object.assign({className:R(je.b4,"opacity-80 truncate")},{children:y(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:ke.backgroundColor},disabled:oe||"idle"!==Q,onClick:()=>ie([])},{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:ke.borderRadius}},{children:["finished"===e.status?t("img",{style:{borderRadius:ke.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(s=e.documentId)||void 0===s?void 0:s.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:""}):t("div",{className:"h-full w-full animate-pulse",style:{borderRadius:ke.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:ke.backgroundColor},disabled:oe||"idle"!==Q,onClick:()=>ie([])},{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(C,{className:R(je.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!me.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:me,placeholder:null!==(U=null==$?void 0:$.placeholdertext)&&void 0!==U?U:"What do you want to talk about?",onChange:e=>pe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),oe||"idle"!==Q||Ne()))},onFocus:T,onBlur:D}),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==$?void 0:$.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:xe?K.accent+"10":void 0},disabled:oe||"idle"!==Q,onClick:()=>{var e;return null===(e=fe.current)||void 0===e?void 0:e.click()}},ye,{children:[t("input",{id:"file-upload",ref:fe,type:"file",accept:[...h,...re?b:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>s(void 0,void 0,void 0,(function*(){yield ne(Array.from(e.target.files||[])),e.target.value=""}))}),t(j,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:xe?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:(be||me.length||te.length&&te.every((e=>"finished"===e.status)))&&!X?K.accent:K.accent+"10"},disabled:oe||"idle"!==Q,onClick:()=>Ne()},ge,{children:t(I,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(be||me.length||te.length&&te.every((e=>"finished"===e.status)))&&!X?K.accentText:K.accent+"80"}})}))]}))]}))]}))]}))}))};export{A 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 c}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as d}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as u}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as m}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as p}from"../../../hooks/pickaxe/useConversation.js";import{useSubmit as f}from"../../../hooks/pickaxe/useSubmit.js";import{useDocument as h}from"../Addons/Document/hooks/useDocument.js";import{useScroll as g}from"../Addons/Scroll/hooks/useScroll.js";import{useHover as b}from"../../../hooks/core/useHover.js";import{formatBytes as v}from"../../../common/utils.js";import{allowedFileMimeTypes as x,allowedImageMimeTypes as y}from"../../../common/documents.js";import{createParser as j}from"eventsource-parser";import k from"../../Icons/attach-vertical.svg.js";import w from"../../Icons/spinner-lines.svg.js";import N from"../../Icons/file.svg.js";import I from"../../Icons/x.svg.js";import O from"../../Icons/arrow-right.svg.js";import C from"../Addons/IceBreaker/index.js";import S from"../../Core/Textarea.js";import R from"../../../common/error.js";import A from"../../../common/cn.js";const T=({isFocused:T,onFocus:U,onBlur:B})=>{var D;const{formId:F,chatId:E,userId:H,studioUserId:z,embedUserId:L,deploymentId:$,pickaxe:G,styles:K,colors:P,responsiveBy:W,isNewChat:_,setIsNewChat:J,setIsShowIceBreaker:M,onGenerateComplete:q}=c(),{messages:Q,status:V,limits:X,isGenerating:Y,setMessages:Z,setStatus:ee,setLimitData:se,setError:te}=d(),{documents:oe,isUploading:re,isImageUploadAllowed:ne,setDocuments:ie,onFileUpload:le}=h(),{scrollStartSession:ae,scrollEndSession:ce,scrollToBottom:de}=g({auto:!0}),ue=p(),me=f(),[pe,fe]=r(""),he=n(null),ge=b(),{isHover:be}=ge,ve=e(ge,["isHover"]),xe=b(),{isHover:ye}=xe,je=e(xe,["isHover"]),ke=m(),we=u(),Ne=i((()=>{var e,s,t;return!!_&&(!!G&&(!ue.isLoading&&(!((null!==(s=null===(e=ue.data)||void 0===e?void 0:e.messages.length)&&void 0!==s?s:0)>1)&&!!(null===(t=G.icebreakers)||void 0===t?void 0:t.length))))}),[G,_,ue.data,ue.isLoading]),Ie=e=>s(void 0,void 0,void 0,(function*(){try{if("idle"!==V||re)return;const s=null!=e?e:pe;if(!s)return;te(""),se(null),fe(""),J(!1),ee("fetching"),ae(),de();const t=oe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=t.length?t[t.length-1].documentId:"",r="enduserupload"===(null==G?void 0:G.documentuploadtype)&&o,n=[...Array.from(Q),Object.assign({id:Q.length+1,role:"user",content:s},r&&{documentIds:[o]})];Z(n),de(),r&&ie([]);const i=(yield me.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:F,responseId:E,value:s},r&&{documentId:o}),H&&{userId:H}),z&&{studioUserId:z}),L&&{embedUserId:L}),$&&{deploymentId:$}))).body;if(!i)throw new Error("Streaming error");const l=n.length,a=new TextDecoder,c=i.getReader();let d="",u=!0,m=!1;const p=j({onEvent:e=>{if("delta"===e.event){const s=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=s,Z([...n.slice(0,l),{id:Q.length+1,role:"assistant",content:d}])}else"stop"===e.event&&(u=!1)}});for(;u;){const{value:e,done:s}=yield c.read();if(s){u=!1;break}const t=a.decode(e);t&&(m||(ee("streaming"),m=!0),p.feed(t))}null==q||q(E)}catch(e){let s=R(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(X).find((([e])=>s.includes(e)));t?se(t[1]):te(s)}finally{de(),ee("idle"),ce()}}));return l((()=>{M(Ne)}),[Ne]),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:A("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===W?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:Ne&&!T&&t(C,{data:(null==G?void 0:G.icebreakers)||[],onSend:Ie})}))})),o("div",Object.assign({className:A("flex flex-col gap-y-2 px-4 py-3","block"===K.formFieldStyle&&"shadow"),style:we},{children:["idle"===V&&oe.length>0&&t("div",Object.assign({className:A("grid grid-cols-1","viewport"===W?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:oe.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:we.borderRadius,borderColor:P.secondaryText+"50"}},{children:[t("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:P.accent,borderRadius:we.borderRadius}},{children:re?t(w,{className:"w-5 h-5 animate-spin",style:{color:P.accentText}}):t(N,{className:"w-5 h-5",style:{color:P.accentText}})})),o("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[t("p",Object.assign({className:(A(ke.b3),"font-medium truncate")},{children:e.name})),t("p",Object.assign({className:A(ke.b4,"opacity-80 truncate")},{children:v(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:P.accent,borderColor:we.backgroundColor},disabled:re||"idle"!==V,onClick:()=>ie([])},{children:t(I,{className:"w-4 h-4",style:{color:P.accentText}})}))]})):"image"===e.type?o("div",Object.assign({className:"relative h-[56px] w-[56px] bg-stone-100",style:{borderRadius:we.borderRadius}},{children:["finished"===e.status?t("img",{style:{borderRadius:we.borderRadius},className:"object-cover w-full h-full",src:`https://prod-pickaxe-assets.s3.us-west-2.amazonaws.com/documentinterrogation/${null===(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:we.borderRadius,backgroundColor:P.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:P.accent,borderColor:we.backgroundColor},disabled:re||"idle"!==V,onClick:()=>ie([])},{children:t(I,{className:"w-4 h-4",style:{color:P.accentText}})}))]})):null},e.id)}))})),o("div",Object.assign({className:"flex items-end gap-x-2"},{children:[t(S,{className:A(ke.i1,"max-h-60 min-h-[27px] w-full border-transparent bg-transparent",!pe.length&&"max-h-6 overflow-hidden text-ellipsis whitespace-nowrap"),value:pe,placeholder:null!==(D=null==G?void 0:G.placeholdertext)&&void 0!==D?D:"What do you want to talk about?",onChange:e=>fe(e),onKeyDown:e=>{"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),re||"idle"!==V||Ie()))},onFocus:U,onBlur:B}),o("div",Object.assign({className:"flex items-center gap-x-2"},{children:["enduserupload"===(null==G?void 0:G.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:ye?P.accent+"10":void 0},disabled:re||"idle"!==V,onClick:()=>{var e;return null===(e=he.current)||void 0===e?void 0:e.click()}},je,{children:[t("input",{id:"file-upload",ref:he,type:"file",accept:[...x,...ne?y:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>s(void 0,void 0,void 0,(function*(){yield le(Array.from(e.target.files||[])),e.target.value=""}))}),t(k,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:ye?P.accent:P.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:(be||pe.length||oe.length&&oe.every((e=>"finished"===e.status)))&&!Y?P.accent:P.accent+"10"},disabled:re||"idle"!==V,onClick:()=>Ie()},ve,{children:t(O,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:(be||pe.length||oe.length&&oe.every((e=>"finished"===e.status)))&&!Y?P.accentText:P.accent+"80"}})}))]}))]}))]}))]}))}))};export{T as default};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as o}from"react/jsx-runtime";import{useMemo as s}from"react";import{usePickaxeContext as t}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useScrollContext as i}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as r}from"../../../../hooks/studio/useStyleFontSize.js";import{PickaxeMarkdown as l}from"../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as c}from"../../common/PickaxeMarkdown/Renderer.js";import{format as a}from"date-fns";import d from"../../../Icons/visitor.svg.js";import m from"../../common/PickaxeIcon.js";import p from"../../common/PickaxeCopyButton.js";import h from"../../Addons/Scroll/ScrollLockView.js";import f from"../../../../common/cn.js";const x=()=>{var x;const{pickaxe:u,styles:b,colors:g,misc:v,translations:j}=t(),{response:y}=n(),{scrollTargetRef:k}=i(),w=r(),N=s((()=>a(y?y.sentAt:new Date,"hh:mm a MMM dd, yy")),[y]),O=s((()=>{var e;if(!y)return"";return(null!==(e=y.questions)&&void 0!==e?e:[]).map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 500;">${e.question}</p>\n <p>${e.answer||"n/a"}</p>\n</div>`)).join("")}),[y]);return y?e("div",Object.assign({ref:k,className:"flex flex-col shadow-black transition duration-300 hover:shadow"},{children:[e("div",Object.assign({className:"flex gap-x-3 overflow-hidden px-4 py-5",style:{backgroundColor:g.primary,color:g.text}},{children:[o("div",Object.assign({className:"shrink-0 pt-1"},{children:o(d,{className:"h-6 w-6"})})),e("div",Object.assign({className:"flex flex-col gap-y-1 overflow-x-auto pb-[6px] scrollbar scrollbar-thin"},{children:[o("input",{id:`${y.responseId}-input`,type:"checkbox",className:"peer hidden",defaultChecked:O.length<280}),o("div",{className:"danger-html hidden flex-col opacity-50 peer-checked:flex",dangerouslySetInnerHTML:{__html:O}}),o("label",Object.assign({htmlFor:`${y.responseId}-input`,className:f(w.b3,"mt-1 flex shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:hidden hover:cursor-pointer"),style:{color:g.accent}},{children:(null==j?void 0:j["see-input"])||"See input"})),o("label",Object.assign({htmlFor:`${y.responseId}-input`,className:f(w.b3,"hidden shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:flex hover:cursor-pointer"),style:{color:g.accent}},{children:(null==j?void 0:j["hide-input"])||"Hide input"}))]}))]})),e("div",Object.assign({className:"flex gap-x-3 px-4 py-5",style:{backgroundColor:g.secondary,color:g.secondaryText}},{children:[v.isChatImage&&o(m,{src:null==u?void 0:u.chaticon,alt:`${null==u?void 0:u.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6 pt-1",textColor:g.secondaryText}),e("div",Object.assign({className:"flex w-full flex-col gap-y-2 overflow-hidden"},{children:[o(l,Object.assign({theme:b.theme,accentColor:g.accent,actions:!0},{children:o(c,{className:"overflow-x-auto pb-2 font-semilight opacity-90 scrollbar scrollbar-thin",value:y.questionResponse})})),e("div",Object.assign({className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1"},{children:[o("div",Object.assign({className:"flex items-center gap-3"},{children:o(p,{color:g.accent,text:null!==(x=y.questionResponse)&&void 0!==x?x:""})})),o("div",Object.assign({className:"flex shrink-0 grow justify-end"},{children:o("p",Object.assign({className:f(w.b3,"font-semibold uppercase opacity-30")},{children:N}))}))]}))]}))]})),o(h,{className:"w-full"})]})):null};export{x as default};
1
+ import{jsxs as e,jsx as o}from"react/jsx-runtime";import{useMemo as s}from"react";import{usePickaxeContext as t}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as n}from"../../../../hooks/pickaxe/useResponseContext.js";import{useScrollContext as r}from"../../Addons/Scroll/hooks/useScrollContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useDocument as l}from"../../Addons/Document/hooks/useDocument.js";import{PickaxeMarkdown as c}from"../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as a}from"../../common/PickaxeMarkdown/Renderer.js";import{format as m}from"date-fns";import d from"../../../Icons/message-square-notes.svg.js";import p from"../../../Icons/visitor.svg.js";import h from"../../common/PickaxeIcon.js";import f from"../../common/PickaxeCopyButton.js";import u from"../../common/PickaxeSimpleButton.js";import x from"../../Addons/Scroll/ScrollLockView.js";import b from"../../../../common/cn.js";const g=()=>{var g;const{pickaxe:v,styles:j,colors:k,misc:y,translations:w,setChatId:N,setIsNewChat:C}=t(),{response:O}=n(),{scrollTargetRef:I}=r(),{setDocuments:S}=l(),D=i(),M=s((()=>m(O?O.sentAt:new Date,"hh:mm a MMM dd, yy")),[O]),P=s((()=>{var e;if(!O)return"";return(null!==(e=O.questions)&&void 0!==e?e:[]).map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 500;">${e.question}</p>\n <p>${e.answer||"n/a"}</p>\n</div>`)).join("")}),[O]);return O?e("div",Object.assign({ref:I,className:"flex flex-col shadow-black transition duration-300 hover:shadow"},{children:[e("div",Object.assign({className:"flex gap-x-3 overflow-hidden px-4 py-5",style:{backgroundColor:k.primary,color:k.text}},{children:[o("div",Object.assign({className:"shrink-0 pt-1"},{children:o(p,{className:"h-6 w-6"})})),e("div",Object.assign({className:"flex flex-col gap-y-1 overflow-x-auto pb-[6px] scrollbar scrollbar-thin"},{children:[o("input",{id:`${O.responseId}-input`,type:"checkbox",className:"peer hidden",defaultChecked:P.length<280}),o("div",{className:"danger-html hidden flex-col opacity-50 peer-checked:flex",dangerouslySetInnerHTML:{__html:P}}),o("label",Object.assign({htmlFor:`${O.responseId}-input`,className:b(D.b3,"mt-1 flex shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:hidden hover:cursor-pointer"),style:{color:k.accent}},{children:(null==w?void 0:w["see-input"])||"See input"})),o("label",Object.assign({htmlFor:`${O.responseId}-input`,className:b(D.b3,"hidden shrink-0 whitespace-nowrap font-semibold text-[#228DD7] peer-checked:flex hover:cursor-pointer"),style:{color:k.accent}},{children:(null==w?void 0:w["hide-input"])||"Hide input"}))]}))]})),e("div",Object.assign({className:"flex gap-x-3 px-4 py-5",style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[y.isChatImage&&o(h,{src:null==v?void 0:v.chaticon,alt:`${null==v?void 0:v.formtitle}'s Chat Icon`,width:24,height:24,className:"h-6 w-6 pt-1",textColor:k.secondaryText}),e("div",Object.assign({className:"flex w-full flex-col gap-y-2 overflow-hidden"},{children:[o(c,Object.assign({theme:j.theme,accentColor:k.accent,actions:!0},{children:o(a,{className:"overflow-x-auto pb-2 font-semilight opacity-90 scrollbar scrollbar-thin",value:O.questionResponse})})),e("div",Object.assign({className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1"},{children:[e("div",Object.assign({className:"flex items-center gap-3"},{children:[(null==v?void 0:v.enablechatresponses)&&e(u,Object.assign({color:k.accent,onClick:()=>{return e=O.responseId,S([]),C(!1),void N(e);var e}},{children:[o(d,{className:"pxe-h-4 pxe-w-4 pxe-shrink-0"}),o("p",Object.assign({className:b(D.b3,"pxe-font-semibold")},{children:O.messageCount+1}))]})),o(f,{color:k.accent,text:null!==(g=O.questionResponse)&&void 0!==g?g:""})]})),o("div",Object.assign({className:"flex shrink-0 grow justify-end"},{children:o("p",Object.assign({className:b(D.b3,"font-semibold uppercase opacity-30")},{children:M}))}))]}))]}))]})),o(x,{className:"w-full"})]})):null};export{g as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as o,jsx as s}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{useDocument as l}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as d}from"../../Addons/Scroll/hooks/useScroll.js";import{extractUrlsFromText as a}from"../../../../common/utils.js";import{encode as c}from"@nem035/gpt-3-encoder";import m from"../../common/PickaxeBranding.js";import u from"../../common/PickaxeButton.js";import p from"../../../../common/error.js";import f from"../../../../common/cn.js";const g=({questions:g})=>{var h;const{formId:b,userId:x,studioUserId:j,embedUserId:v,deploymentId:w,pickaxe:k,misc:y,translations:I,responsiveBy:O,isShowHistory:S,setChatId:C,setIsShowHistory:D,setIsNewChat:E,onGenerateComplete:U}=i(),{status:P,limits:R,isGenerating:q,setResponse:N,setMessages:A,setStatus:L,setLimitData:B,setError:T}=n(),{documents:H,websiteLink:W,isUploading:G,onWebsiteUpload:M,setDocumentError:_}=l(),{scrollStartSession:K,scrollEndSession:X,scrollToTarget:Y}=d({auto:!(null==k?void 0:k.enablechatresponses)}),z=r(),[F,J]=t(!1);return o("div",Object.assign({className:f("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===O?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[o("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[s(u,Object.assign({className:"px-5 min-h-[42px]",isDisabled:G||"idle"!==P||q||F,onClick:()=>e(void 0,void 0,void 0,(function*(){try{if("idle"!==P||G||F)return;T(""),B(null),_(""),N(null);const e=["Multiple Choice","Checkbox"];for(const o of g){if(c(o.input).length>o.maxLength&&!e.includes(o.type))throw new Error("One or more of your responses is too long!");if(o.isRequired&&!o.input.trim()&&"userinput:documentupload"!==o.id)throw new Error("You must fill out all required fields.")}const o=H.filter((e=>"finished"===e.status)),s=H.map((e=>e.name)),t="enduserupload"===(null==k?void 0:k.documentuploadtype),i=g.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),n=a(W).filter((e=>!s.includes(e)));if(n.length){const e=n[n.length-1];J(!0);const s=yield M(e);s&&(o.push(s),yield new Promise((e=>setTimeout(e,5e3)))),J(!1)}else if(i&&t&&!o.length)return void _("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=o.length?o[o.length-1]:null,l=t&&r&&"finished"===r.status;let d={};g.forEach((e=>d=Object.assign(Object.assign({},d),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==r?void 0:r.name)||"":e.input}))),L("fetching"),K(),Y();const m=yield z.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:b,valueObj:d},l&&{documentId:r.documentId}),x&&{userId:x}),j&&{studioUserId:j}),v&&{embedUserId:v}),w&&{deploymentId:w})),u=m.body;if(!u)throw new Error("Streaming error");const p=m.headers.get("X-Pickaxe-Response-Id");if(!p)throw new Error("Response ID not found");const f=new TextDecoder,h=u.getReader();let y="",I=!0,O=!1;for(;I;){const{value:e,done:o}=yield h.read();if(o){I=!1;break}const s=f.decode(e,{stream:!0}).replace(/\u200B/g,"");if("[DONE]"===s){I=!1;break}y+=s,y&&(O||(L("streaming"),O=!0,(null==k?void 0:k.enablechatresponses)&&(C(p),E(!1))),N({formId:b,responseId:p,documentIds:r&&r.documentId?[r.documentId]:[],questions:g.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:y,sentAt:new Date}),(null==k?void 0:k.enablechatresponses)&&A([{id:0,role:"assistant",content:y}]))}null==U||U(p)}catch(e){let o=p(e)||"";o&&!o.includes("Unexpected token 'A',")||(o="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(R).find((([e])=>o.includes(e)));s?B(s[1]):T(o),Y()}finally{L("idle"),J(!1),X()}}))},{children:F?(null==I?void 0:I.processing)||"Processing...":G?(null==I?void 0:I.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==I?void 0:I.loading)||"Loading...":null!==(h=null==k?void 0:k.submittext)&&void 0!==h?h:"Submit"})),y.isHistory&&!S&&s(u,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>D(!0)},{children:(null==I?void 0:I["see-history"])||"See history"}))]})),!y.isWhiteLabel&&s("div",Object.assign({className:"flex justify-end pr-3"},{children:s(m,{})}))]}))};export{g as default};
1
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as s}from"react";import{usePickaxeContext as n}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as i}from"../../../../hooks/pickaxe/useResponseContext.js";import{useSubmit as r}from"../../../../hooks/pickaxe/useSubmit.js";import{useDocument as l}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as a}from"../../Addons/Scroll/hooks/useScroll.js";import{extractUrlsFromText as d}from"../../../../common/utils.js";import{encode as c}from"@nem035/gpt-3-encoder";import{createParser as m}from"eventsource-parser";import u from"../../common/PickaxeBranding.js";import p from"../../common/PickaxeButton.js";import f from"../../../../common/error.js";import g from"../../../../common/cn.js";const h=({questions:h})=>{var x;const{formId:b,userId:v,studioUserId:j,embedUserId:w,deploymentId:k,pickaxe:y,misc:I,translations:O,responsiveBy:S,isShowHistory:C,setChatId:E,setIsShowHistory:U,setIsNewChat:D,onGenerateComplete:P}=n(),{status:R,limits:q,isGenerating:N,setResponse:A,setMessages:L,setStatus:B,setLimitData:T,setError:H}=i(),{documents:W,websiteLink:G,isUploading:M,onWebsiteUpload:_,setDocumentError:J}=l(),{scrollStartSession:K,scrollEndSession:X,scrollToTarget:Y}=a({auto:!(null==y?void 0:y.enablechatresponses)}),z=r(),[F,Q]=s(!1);return o("div",Object.assign({className:g("mt-4 flex flex-wrap flex-col justify-between gap-2","viewport"===S?"min-[767px]:flex-row":"@[767px]/pickaxe-root:flex-row")},{children:[o("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[t(p,Object.assign({className:"px-5 min-h-[42px]",isDisabled:M||"idle"!==R||N||F,onClick:()=>e(void 0,void 0,void 0,(function*(){try{if("idle"!==R||M||F)return;H(""),T(null),J(""),A(null);const e=["Multiple Choice","Checkbox"];for(const o of h){if(c(o.input).length>o.maxLength&&!e.includes(o.type))throw new Error("One or more of your responses is too long!");if(o.isRequired&&!o.input.trim()&&"userinput:documentupload"!==o.id)throw new Error("You must fill out all required fields.")}const o=W.filter((e=>"finished"===e.status)),t=W.map((e=>e.name)),s="enduserupload"===(null==y?void 0:y.documentuploadtype),n=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),i=d(G).filter((e=>!t.includes(e)));if(i.length){const e=i[i.length-1];Q(!0);const t=yield _(e);t&&(o.push(t),yield new Promise((e=>setTimeout(e,5e3)))),Q(!1)}else if(n&&s&&!o.length)return void J("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=o.length?o[o.length-1]:null,l=s&&r&&"finished"===r.status;let a={};h.forEach((e=>a=Object.assign(Object.assign({},a),{[e.id]:"Knowledge Upload"===e.type||e.id.includes("documentupload")?(null==r?void 0:r.name)||"":e.input}))),B("fetching"),K(),Y();const u=yield z.mutateAsync(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:b,valueObj:a},l&&{documentId:r.documentId}),v&&{userId:v}),j&&{studioUserId:j}),w&&{embedUserId:w}),k&&{deploymentId:k})),p=u.body;if(!p)throw new Error("Streaming error");const f=u.headers.get("X-Pickaxe-Response-Id");if(!f)throw new Error("Response ID not found");const g=new TextDecoder,x=p.getReader();let I="",O=!0,S=!1;const C=m({onEvent:e=>{if("delta"===e.event){const o=JSON.parse(e.data).token.replace(/\u200B/g,"");I+=o,A({formId:b,responseId:f,documentIds:r&&r.documentId?[r.documentId]:[],questions:h.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:I,messageCount:0,sentAt:new Date}),(null==y?void 0:y.enablechatresponses)&&L([{id:0,role:"assistant",content:I}])}else"stop"===e.event&&(O=!1)}});for(;O;){const{value:e,done:o}=yield x.read();if(o){O=!1;break}const t=g.decode(e);t&&(S||(B("streaming"),S=!0,(null==y?void 0:y.enablechatresponses)&&(E(f),D(!1))),C.feed(t))}null==P||P(f)}catch(e){let o=f(e)||"";o&&!o.includes("Unexpected token 'A',")||(o="Oops! We're experiencing high traffic at the moment. Please try again later.");const t=Object.entries(q).find((([e])=>o.includes(e)));t?T(t[1]):H(o),Y()}finally{B("idle"),Q(!1),X()}}))},{children:F?(null==O?void 0:O.processing)||"Processing...":M?(null==O?void 0:O.uploading)||"Uploading...":"fetching"===R||"streaming"===R?(null==O?void 0:O.loading)||"Loading...":null!==(x=null==y?void 0:y.submittext)&&void 0!==x?x:"Submit"})),I.isHistory&&!C&&t(p,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>U(!0)},{children:(null==O?void 0:O["see-history"])||"See history"}))]})),!I.isWhiteLabel&&t("div",Object.assign({className:"flex justify-end pr-3"},{children:t(u,{})}))]}))};export{h as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{useMutation as s}from"@tanstack/react-query";const o=()=>s({mutationFn:s=>(({formId:s,responseId:o,documentId:t,studioUserId:n,deploymentId:r,embedUserId:c,pickaxe:i,value:a,valueObj:d})=>e(void 0,void 0,void 0,(function*(){const e=yield fetch(`${process.env.NEXT_PUBLIC_API_URL}/pickaxe/sse`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},o&&{responseId:o}),t&&{documentId:t}),n&&{studioUserId:n}),r&&{deploymentId:r}),c&&{embedUserId:c}),i&&{pickaxe:i}),a&&{value:a}),d&&{valueObj:d}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}));if(200!==e.status){const s=yield e.json();throw new Error(s.error||"Unknown error, please contact support")}if("application/json"===e.headers.get("content-type")){const{success:s,error:o}=yield e.json();if(!s)throw new Error(o||"Unknown error, please contact support")}return e})))(s)});export{o as useSubmit};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{useMutation as s}from"@tanstack/react-query";const t=()=>s({mutationFn:s=>(({formId:s,responseId:t,documentId:o,studioUserId:n,deploymentId:r,embedUserId:a,pickaxe:c,value:i,valueObj:d,metadata:p})=>e(void 0,void 0,void 0,(function*(){const e=yield fetch(`${process.env.NEXT_PUBLIC_API_URL}/pickaxe/sse`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({formId:s},t&&{responseId:t}),o&&{documentId:o}),n&&{studioUserId:n}),r&&{deploymentId:r}),a&&{embedUserId:a}),c&&{pickaxe:c}),i&&{value:i}),d&&{valueObj:d}),p&&{metadata:p}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}}));if(200!==e.status){const s=yield e.json();throw new Error(s.error||"Unknown error, please contact support")}if("application/json"===e.headers.get("content-type")){const{success:s,error:t}=yield e.json();if(!s)throw new Error(t||"Unknown error, please contact support")}return e})))(s)});export{t as useSubmit};
@@ -9,6 +9,7 @@ type MutationParams = {
9
9
  pickaxe?: Partial<Pickaxe>;
10
10
  value?: string;
11
11
  valueObj?: Record<string, string>;
12
+ metadata?: Record<string, unknown>;
12
13
  };
13
14
  export declare const useSubmit: () => import("@tanstack/react-query").UseMutationResult<Response, Error, MutationParams, unknown>;
14
15
  export {};
@@ -29,5 +29,6 @@ export type MemoryStoredResponse = {
29
29
  documentIds: string[];
30
30
  questions: PickaxeHistoryQuestion[];
31
31
  questionResponse: string;
32
+ messageCount: number;
32
33
  sentAt: Date;
33
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",
@@ -84,6 +84,7 @@
84
84
  "eslint-plugin-react": "^7.32.0",
85
85
  "eslint-plugin-react-hooks": "^4.6.0",
86
86
  "eslint-plugin-storybook": "^0.11.2",
87
+ "eventsource-parser": "^3.0.2",
87
88
  "framer-motion": "^11.17.0",
88
89
  "husky": "^8.0.3",
89
90
  "isomorphic-dompurify": "^2.20.0",
@@ -133,6 +134,7 @@
133
134
  "clsx": "^2.1.1",
134
135
  "copy-to-clipboard": "^3.3.3",
135
136
  "date-fns": "^3.6.0",
137
+ "eventsource-parser": "^3.0.2",
136
138
  "framer-motion": "^11.17.0",
137
139
  "isomorphic-dompurify": "^2.20.0",
138
140
  "katex": "^0.16.19",