@pickaxeproject/react 2.1.8 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),o=require("../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../hooks/pickaxe/useResponseContext.js"),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
+ "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"),p=require("../../Icons/attach-vertical.svg.js"),h=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:J,setStatus:K,setLimitData:W,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"]),pe=n.useStyleFontSize(),he=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(""),W(null),ie(""),E(!1),K("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]})];J(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,J([...l.slice(0,i),{id:P.length+1,role:"assistant",content:c}])}else if("error"===e.event){const s=JSON.parse(e.data);Q(s.error||"Something went wrong, please try again.")}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||(K("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?W(t[1]):Q(s)}finally{oe(),K("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:he},{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:he.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:he.borderRadius}},{children:X?s.jsx(h.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(pe.b3),"font-medium truncate")},{children:e.name})),s.jsx("p",Object.assign({className:w.default(pe.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:he.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: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: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:he.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(pe.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(p.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("../../../../_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
+ "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"),g=require("../../../../common/cn.js");exports.default=({questions:f})=>{var h;const{formId:x,userId:b,studioUserId:j,embedUserId:v,deploymentId:w,pickaxe:y,misc:k,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:J,scrollEndSession:F,scrollToTarget:K}=l.useScroll({auto:!(null==y?void 0:y.enablechatresponses)}),X=i.useSubmit(),[Y,z]=t.useState(!1);return s.jsxs("div",Object.assign({className:g.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 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=B.filter((e=>"finished"===e.status)),t=B.map((e=>e.name)),n="enduserupload"===(null==y?void 0:y.documentuploadtype),o=f.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={};f.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"),J(),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 g=m.headers.get("X-Pickaxe-Response-Id");if(!g)throw new Error("Response ID not found");const h=new TextDecoder,k=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:g,documentIds:r&&r.documentId?[r.documentId]:[],questions:f.map((e=>({id:e.id,question:e.main,answer:e.input}))),questionResponse:q,messageCount:0,sentAt:new Date}),(null==y?void 0:y.enablechatresponses)&&_([{id:0,role:"assistant",content:q}])}else if("error"===e.event){const s=JSON.parse(e.data);T(s.error||"Something went wrong, please try again.")}else"stop"===e.event&&(I=!1)}});for(;I;){const{value:e,done:s}=yield k.read();if(s){I=!1;break}const t=h.decode(e);t&&(O||(A("streaming"),O=!0,(null==y?void 0:y.enablechatresponses)&&(S(g),P(!1))),C.feed(t))}null==U||U(g)}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),F()}}))},{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==y?void 0:y.submittext)&&void 0!==h?h:"Submit"})),k.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"}))]})),!k.isWhiteLabel&&s.jsx("div",Object.assign({className:"flex justify-end pr-3"},{children:s.jsx(c.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 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
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as s,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:J,colors:K,responsiveBy:P,isNewChat:W,setIsNewChat:_,setIsShowIceBreaker:M,onGenerateComplete:q}=c(),{messages:Q,status:V,limits:X,isGenerating:Y,setMessages:Z,setStatus:ee,setLimitData:te,setError:se}=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,t,s;return!!W&&(!!G&&(!ue.isLoading&&(!((null!==(t=null===(e=ue.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&!!(null===(s=G.icebreakers)||void 0===s?void 0:s.length))))}),[G,W,ue.data,ue.isLoading]),Ie=e=>t(void 0,void 0,void 0,(function*(){try{if("idle"!==V||re)return;const t=null!=e?e:pe;if(!t)return;se(""),te(null),fe(""),_(!1),ee("fetching"),ae(),de();const s=oe.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),o=s.length?s[s.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:t},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:t},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 t=JSON.parse(e.data).token.replace(/\u200B/g,"");d+=t,Z([...n.slice(0,l),{id:Q.length+1,role:"assistant",content:d}])}else if("error"===e.event){const t=JSON.parse(e.data);se(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(u=!1)}});for(;u;){const{value:e,done:t}=yield c.read();if(t){u=!1;break}const s=a.decode(e);s&&(m||(ee("streaming"),m=!0),p.feed(s))}null==q||q(E)}catch(e){let t=R(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const s=Object.entries(X).find((([e])=>t.includes(e)));s?te(s[1]):se(t)}finally{de(),ee("idle"),ce()}}));return l((()=>{M(Ne)}),[Ne]),s("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:[s("div",Object.assign({className:"absolute right-0 bottom-full"},{children:s("div",Object.assign({className:A("flex justify-end flex-col gap-2 pb-4 px-2","viewport"===P?"min-[767px]:items-end":"@[767px]/pickaxe-root:items-end")},{children:Ne&&!T&&s(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"===J.formFieldStyle&&"shadow"),style:we},{children:["idle"===V&&oe.length>0&&s("div",Object.assign({className:A("grid grid-cols-1","viewport"===P?"min-[765px]:grid-cols-2":"@[767px]/pickaxe-root:grid-cols-2")},{children:oe.map((e=>{var t,r,n;return s(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:K.secondaryText+"50"}},{children:[s("div",Object.assign({className:"w-10 h-10 flex items-center justify-center shrink-0",style:{backgroundColor:K.accent,borderRadius:we.borderRadius}},{children:re?s(w,{className:"w-5 h-5 animate-spin",style:{color:K.accentText}}):s(N,{className:"w-5 h-5",style:{color:K.accentText}})})),o("div",Object.assign({className:"flex flex-col justify-center truncate"},{children:[s("p",Object.assign({className:(A(ke.b3),"font-medium truncate")},{children:e.name})),s("p",Object.assign({className:A(ke.b4,"opacity-80 truncate")},{children:v(e.size)}))]})),s("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:we.backgroundColor},disabled:re||"idle"!==V,onClick:()=>ie([])},{children:s(I,{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:we.borderRadius}},{children:["finished"===e.status?s("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===(t=e.documentId)||void 0===t?void 0:t.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:""}):s("div",{className:"h-full w-full animate-pulse",style:{borderRadius:we.borderRadius,backgroundColor:K.secondary}}),s("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:we.backgroundColor},disabled:re||"idle"!==V,onClick:()=>ie([])},{children:s(I,{className:"w-4 h-4",style:{color:K.accentText}})}))]})):null},e.id)}))})),o("div",Object.assign({className:"flex items-end gap-x-2"},{children:[s(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?K.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:[s("input",{id:"file-upload",ref:he,type:"file",accept:[...x,...ne?y:[]].join(", "),multiple:!1,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){yield le(Array.from(e.target.files||[])),e.target.value=""}))}),s(k,{className:"h-6 w-6 shrink-0 duration-200 transition-colors ease-in-out",style:{color:ye?K.accent:K.accent+"80"}})]})),s("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?K.accent:K.accent+"10"},disabled:re||"idle"!==V,onClick:()=>Ie()},ve,{children:s(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?K.accentText:K.accent+"80"}})}))]}))]}))]}))]}))}))};export{T as default};
@@ -1 +1 @@
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
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as o}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:y,pickaxe:k,misc:I,translations:O,responsiveBy:S,isShowHistory:C,setChatId:E,setIsShowHistory:U,setIsNewChat:D,onGenerateComplete:N}=n(),{status:P,limits:R,isGenerating:q,setResponse:A,setMessages:L,setStatus:B,setLimitData:T,setError:H}=i(),{documents:W,websiteLink:G,isUploading:J,onWebsiteUpload:M,setDocumentError:_}=l(),{scrollStartSession:K,scrollEndSession:X,scrollToTarget:Y}=a({auto:!(null==k?void 0:k.enablechatresponses)}),z=r(),[F,Q]=s(!1);return t("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:[t("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[o(p,Object.assign({className:"px-5 min-h-[42px]",isDisabled:J||"idle"!==P||q||F,onClick:()=>e(void 0,void 0,void 0,(function*(){try{if("idle"!==P||J||F)return;H(""),T(null),_(""),A(null);const e=["Multiple Choice","Checkbox"];for(const t of h){if(c(t.input).length>t.maxLength&&!e.includes(t.type))throw new Error("One or more of your responses is too long!");if(t.isRequired&&!t.input.trim()&&"userinput:documentupload"!==t.id)throw new Error("You must fill out all required fields.")}const t=W.filter((e=>"finished"===e.status)),o=W.map((e=>e.name)),s="enduserupload"===(null==k?void 0:k.documentuploadtype),n=h.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),i=d(G).filter((e=>!o.includes(e)));if(i.length){const e=i[i.length-1];Q(!0);const o=yield M(e);o&&(t.push(o),yield new Promise((e=>setTimeout(e,5e3)))),Q(!1)}else if(n&&s&&!t.length)return void _("Please paste a valid website/video link or drag a file to add to the knowledge base.");const r=t.length?t[t.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}),y&&{deploymentId:y})),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 t=JSON.parse(e.data).token.replace(/\u200B/g,"");I+=t,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==k?void 0:k.enablechatresponses)&&L([{id:0,role:"assistant",content:I}])}else if("error"===e.event){const t=JSON.parse(e.data);H(t.error||"Something went wrong, please try again.")}else"stop"===e.event&&(O=!1)}});for(;O;){const{value:e,done:t}=yield x.read();if(t){O=!1;break}const o=g.decode(e);o&&(S||(B("streaming"),S=!0,(null==k?void 0:k.enablechatresponses)&&(E(f),D(!1))),C.feed(o))}null==N||N(f)}catch(e){let t=f(e)||"";t&&!t.includes("Unexpected token 'A',")||(t="Oops! We're experiencing high traffic at the moment. Please try again later.");const o=Object.entries(R).find((([e])=>t.includes(e)));o?T(o[1]):H(t),Y()}finally{B("idle"),Q(!1),X()}}))},{children:F?(null==O?void 0:O.processing)||"Processing...":J?(null==O?void 0:O.uploading)||"Uploading...":"fetching"===P||"streaming"===P?(null==O?void 0:O.loading)||"Loading...":null!==(x=null==k?void 0:k.submittext)&&void 0!==x?x:"Submit"})),I.isHistory&&!C&&o(p,Object.assign({variant:"transparent-text",className:"px-4",onClick:()=>U(!0)},{children:(null==O?void 0:O["see-history"])||"See history"}))]})),!I.isWhiteLabel&&o("div",Object.assign({className:"flex justify-end pr-3"},{children:o(u,{})}))]}))};export{h as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",