@pickaxeproject/react 6.6.2 → 6.6.3

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.
Files changed (31) hide show
  1. package/dist/cjs/common/utils.js +1 -1
  2. package/dist/cjs/common/validation.js +1 -1
  3. package/dist/cjs/components/Core/Menu/List.js +1 -1
  4. package/dist/cjs/components/Core/Menu/Overflow.js +1 -1
  5. package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
  6. package/dist/cjs/components/Pickaxe/Form/Questions/Checkbox.js +1 -1
  7. package/dist/cjs/components/Pickaxe/Form/Questions/Dropdown.js +1 -1
  8. package/dist/cjs/components/Pickaxe/Form/Questions/Option.js +1 -1
  9. package/dist/cjs/components/Pickaxe/Form/Questions/Submit.js +1 -1
  10. package/dist/cjs/components/Pickaxe/common/PickaxeUpgradeCard.js +1 -1
  11. package/dist/cjs/components/Pickaxe/index.js +1 -1
  12. package/dist/cjs/src/common/validation.d.ts +2 -0
  13. package/dist/cjs/src/components/Pickaxe/Form/Questions/Dropdown.d.ts +1 -0
  14. package/dist/cjs/src/components/Pickaxe/Provider.d.ts +6 -0
  15. package/dist/cjs/src/types/response.d.ts +1 -0
  16. package/dist/esm/common/utils.js +1 -1
  17. package/dist/esm/common/validation.js +1 -1
  18. package/dist/esm/components/Core/Menu/List.js +1 -1
  19. package/dist/esm/components/Core/Menu/Overflow.js +1 -1
  20. package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
  21. package/dist/esm/components/Pickaxe/Form/Questions/Checkbox.js +1 -1
  22. package/dist/esm/components/Pickaxe/Form/Questions/Dropdown.js +1 -1
  23. package/dist/esm/components/Pickaxe/Form/Questions/Option.js +1 -1
  24. package/dist/esm/components/Pickaxe/Form/Questions/Submit.js +1 -1
  25. package/dist/esm/components/Pickaxe/common/PickaxeUpgradeCard.js +1 -1
  26. package/dist/esm/components/Pickaxe/index.js +1 -1
  27. package/dist/esm/src/common/validation.d.ts +2 -0
  28. package/dist/esm/src/components/Pickaxe/Form/Questions/Dropdown.d.ts +1 -0
  29. package/dist/esm/src/components/Pickaxe/Provider.d.ts +6 -0
  30. package/dist/esm/src/types/response.d.ts +1 -0
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tldts");const t="PXE-uid",r=(e,t=!1)=>{let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";t&&(r=r.replace(/[0-9]/g,""));let o="";for(let t=0;t<e;t++)o+=r.charAt(Math.floor(Math.random()*r.length));return o},o=e=>{try{const t=document.cookie.split("; ");for(const r of t){const[t,o]=r.split("=");if(t===e)return o}return null}catch(e){return console.error("[pxe] failed to get cookie",e),null}};exports.COOKIE_USER_ID=t,exports.buildUpgradeUrl=({baseUrl:e,redirectUrl:t,accessGroupId:r,currentUrl:o})=>{if(!e)return null;const n=null!=o?o:"undefined"!=typeof window?window.location.href:null;if(!n)return null;try{const o=new URL(e,n);if(r){const e=encodeURIComponent(r),t=o.pathname.replace(/\/+$/,"");t.endsWith(`/${e}`)||(o.pathname=`${t}/${e}`)}return t&&o.searchParams.set("redirectUrl",t),o.toString()}catch(e){return console.error("[pxe] failed to build upgrade url",e),null}},exports.deleteAuthToken=e=>{try{if("undefined"==typeof window)return;localStorage.removeItem(e)}catch(e){console.error("[pxe] failed to delete auth token",e)}},exports.deleteCookie=e=>{document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"},exports.extractUrlsFromText=e=>{const t=e.match(/(https?:\/\/[^\s]+)/g)||[];return Array.from(new Set(t))},exports.formatBytes=(e,t=2)=>{if(!+e)return"0 Bytes";const r=t<0?0:t,o=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,o)).toFixed(r))} ${["Bytes","KB","MB","PB","EB"][o]}`},exports.generateId=(e,t="",r="")=>{let o="";for(let t=0;t<e;t++){o+="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())]}return t+o+r},exports.getAuthToken=e=>{try{if("undefined"==typeof window)return null;let t=null;return t=new URLSearchParams(window.location.search).get("pxtoken"),t||(t=localStorage.getItem(`PXE-token-${e}`)),t||(t=o(`PXE-token-${e}`)),t||(t=o(`__Secure-PS-${e}.session-token`)),t?decodeURIComponent(t):null}catch(e){return null}},exports.getCookie=o,exports.initializeEmbedUserId=()=>{try{const n=o(t);if(!n){const o=r(28),n=new Date;n.setFullYear(n.getFullYear()+1);let l=window.location.hostname;const s=e.parse(l).domain;if(s)l=`.${s}`;else{const e=l.split(":")[0],t=e.split(".");l=e,t.length>=2&&(l=`.${t.slice(-2).join(".")}`)}return document.cookie=`${t}=${o};Path=/; Domain=${l}; Expires=${n.toUTCString()}`,o}return n}catch(e){return console.error("[pxe-embed] failed to initialized embed user id",e),r(28)}},exports.isInIframe=()=>{if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch(e){return!0}},exports.mergeRefs=function(...e){return t=>{for(const r of e)r&&("function"==typeof r?r(t):r.current=t)}},exports.randomStr=r,exports.safeJSONParse=e=>{try{return JSON.parse(e)}catch(e){return null}},exports.setAuthToken=(e,t)=>{try{if("undefined"==typeof window)return;localStorage.setItem(e,t)}catch(e){console.error("[pxe] failed to set auth token",e)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tldts");const t="PXE-uid",r=(e,t=!1)=>{let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";t&&(r=r.replace(/[0-9]/g,""));let o="";for(let t=0;t<e;t++)o+=r.charAt(Math.floor(Math.random()*r.length));return o},o=e=>{try{const t=document.cookie.split("; ");for(const r of t){const[t,o]=r.split("=");if(t===e)return o}return null}catch(e){return console.error("[pxe] failed to get cookie",e),null}};exports.COOKIE_USER_ID=t,exports.buildUpgradeUrl=({baseUrl:e,redirectUrl:t,accessGroupId:r,currentUrl:o})=>{if(!e)return null;const n=null!=o?o:"undefined"!=typeof window?window.location.href:null;if(!n)return null;try{const o=new URL(e,n);if(r){const e=encodeURIComponent(r),t=o.pathname.replace(/\/+$/,""),n="/ag-pricing",l=t.indexOf(n);if(l>=0){const r=t.slice(0,l+n.length);o.pathname=`${r}/${e}`}else t.endsWith(`/${e}`)||(o.pathname=`${t}/${e}`)}return t&&o.searchParams.set("redirectUrl",t),o.toString()}catch(e){return console.error("[pxe] failed to build upgrade url",e),null}},exports.deleteAuthToken=e=>{try{if("undefined"==typeof window)return;localStorage.removeItem(e)}catch(e){console.error("[pxe] failed to delete auth token",e)}},exports.deleteCookie=e=>{document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"},exports.extractUrlsFromText=e=>{const t=e.match(/(https?:\/\/[^\s]+)/g)||[];return Array.from(new Set(t))},exports.formatBytes=(e,t=2)=>{if(!+e)return"0 Bytes";const r=t<0?0:t,o=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,o)).toFixed(r))} ${["Bytes","KB","MB","PB","EB"][o]}`},exports.generateId=(e,t="",r="")=>{let o="";for(let t=0;t<e;t++){o+="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())]}return t+o+r},exports.getAuthToken=e=>{try{if("undefined"==typeof window)return null;let t=null;return t=new URLSearchParams(window.location.search).get("pxtoken"),t||(t=localStorage.getItem(`PXE-token-${e}`)),t||(t=o(`PXE-token-${e}`)),t||(t=o(`__Secure-PS-${e}.session-token`)),t?decodeURIComponent(t):null}catch(e){return null}},exports.getCookie=o,exports.initializeEmbedUserId=()=>{try{const n=o(t);if(!n){const o=r(28),n=new Date;n.setFullYear(n.getFullYear()+1);let l=window.location.hostname;const s=e.parse(l).domain;if(s)l=`.${s}`;else{const e=l.split(":")[0],t=e.split(".");l=e,t.length>=2&&(l=`.${t.slice(-2).join(".")}`)}return document.cookie=`${t}=${o};Path=/; Domain=${l}; Expires=${n.toUTCString()}`,o}return n}catch(e){return console.error("[pxe-embed] failed to initialized embed user id",e),r(28)}},exports.isInIframe=()=>{if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch(e){return!0}},exports.mergeRefs=function(...e){return t=>{for(const r of e)r&&("function"==typeof r?r(t):r.current=t)}},exports.randomStr=r,exports.safeJSONParse=e=>{try{return JSON.parse(e)}catch(e){return null}},exports.setAuthToken=(e,t)=>{try{if("undefined"==typeof window)return;localStorage.setItem(e,t)}catch(e){console.error("[pxe] failed to set auth token",e)}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const r={"login required":"login_required","upgrade required":"upgrade_required","access denied":"access_denied"},e=e=>{var u;if("string"!=typeof e)return null;const t=e.trim().toLowerCase().replace(/[.!]+$/g,"");return null!==(u=r[t])&&void 0!==u?u:null};exports.getValidationFailure=r=>{var u;if("string"==typeof r){const u=e(r);return u?{status:u,upgradeGroups:[],upgradeUrl:null}:null}if(!r||"object"!=typeof r)return null;const t=r,l=null!==(u=e(t.message))&&void 0!==u?u:e(t.error);return l?{status:l,upgradeGroups:Array.isArray(t.upgradeGroups)?t.upgradeGroups:[],upgradeUrl:"string"==typeof t.upgradeUrl?t.upgradeUrl:null}:null};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const r={"login required":"login_required","upgrade required":"upgrade_required","access denied":"access_denied"},e=e=>{var u;if("string"!=typeof e)return null;const s=e.trim().toLowerCase().replace(/[.!]+$/g,"");return null!==(u=r[s])&&void 0!==u?u:null};exports.getValidationFailure=r=>{var u;if("string"==typeof r){const u=e(r);return u?{status:u,accessGroup:null,upgradeGroups:[],upgradeUrl:null}:null}if(!r||"object"!=typeof r)return null;const s=r,l=null!==(u=e(s.message))&&void 0!==u?u:e(s.error);return l?{status:l,accessGroup:(t=s.accessGroup,t&&"object"==typeof t?t:null),upgradeGroups:Array.isArray(s.upgradeGroups)?s.upgradeGroups:[],upgradeUrl:"string"==typeof s.upgradeUrl?s.upgradeUrl:null}:null;var t};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),i=require("react"),l=require("./index.js"),r=require("react-tooltip"),s=require("../../../common/cn.js");const a=i.forwardRef(((a,n)=>{var{children:o,width:c="200px",fixedWidth:d,maxHeight:u,align:x="bottom-start",style:h,className:b}=a,p=e.__rest(a,["children","width","fixedWidth","maxHeight","align","style","className"]);const{id:m,isOpen:f,closeOnSelect:g,openOnClick:j,setIsOpen:O,onChange:w}=i.useContext(l.MenuContext);return t.jsx("div",{children:t.jsx(r.Tooltip,Object.assign({ref:n,anchorSelect:`#${m}`,place:x,style:Object.assign(Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black"},"auto"!==c&&{width:"100%",maxWidth:c}),d&&{width:d,maxWidth:"inherit"}),{borderRadius:"4px"}),h),clickable:!0,noArrow:!0,border:"1px solid rgba(0,0,0,.8)",opacity:1,isOpen:f,setIsOpen:w,openOnClick:j},p,{children:t.jsx("div",Object.assign({className:s.default("flex w-full select-none flex-col overflow-y-auto text-base shadow-lg scrollbar scrollbar-thumb-black/50 scrollbar-thumb-rounded-full scrollbar-w-[4px] scrollbar-h-[4px]",b),style:{maxHeight:u}},g&&{onClick:()=>O(!1)},{children:o}))}))})}));a.displayName="MenuList",exports.default=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),i=require("react"),r=require("./index.js"),l=require("react-tooltip"),s=require("../../../common/cn.js");const a=e=>`min(${e}, calc(100vw - 48px))`,o=i.forwardRef(((o,n)=>{var{children:c,width:d="200px",fixedWidth:x,maxHeight:b,align:u="bottom-start",style:h,className:p}=o,g=e.__rest(o,["children","width","fixedWidth","maxHeight","align","style","className"]);const{id:m,isOpen:f,closeOnSelect:j,openOnClick:O,setIsOpen:w,onChange:y}=i.useContext(r.MenuContext);return t.jsx("div",{children:t.jsx(l.Tooltip,Object.assign({ref:n,anchorSelect:`#${m}`,place:u,positionStrategy:"fixed",style:Object.assign(Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black",boxSizing:"border-box"},"auto"!==d&&{width:"100%",maxWidth:a(d)}),x&&{width:x,maxWidth:a(x)}),{borderRadius:"4px"}),h),clickable:!0,noArrow:!0,border:"1px solid rgba(0,0,0,.8)",opacity:1,isOpen:f,setIsOpen:y,openOnClick:O},g,{children:t.jsx("div",Object.assign({className:s.default("flex w-full select-none flex-col overflow-y-auto text-base shadow-lg scrollbar scrollbar-thumb-black/50 scrollbar-thumb-rounded-full scrollbar-w-[4px] scrollbar-h-[4px]",p),style:{maxHeight:b}},j&&{onClick:()=>w(!1)},{children:c}))}))})}));o.displayName="MenuList",exports.default=o;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),r=require("react-tooltip");exports.default=i=>{var{selector:l=".menuOverflow",align:a="bottom-start",width:c="200px",style:o,children:s,clickable:n=!1}=i,d=e.__rest(i,["selector","align","width","style","children","clickable"]);return t.jsx(r.Tooltip,Object.assign({anchorSelect:l,place:a,style:Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black"},"auto"!==c&&{width:"100%",maxWidth:c}),{borderRadius:"4px"}),o),clickable:n,noArrow:!0,opacity:1},d,{children:s}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),i=require("react-tooltip");const r=e=>`min(${e}, calc(100vw - 48px))`;exports.default=l=>{var{selector:o=".menuOverflow",align:c="bottom-start",width:a="200px",style:s,children:n,clickable:d=!1}=l,b=e.__rest(l,["selector","align","width","style","children","clickable"]);return t.jsx(i.Tooltip,Object.assign({anchorSelect:o,place:c,positionStrategy:"fixed",style:Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black",boxSizing:"border-box"},"auto"!==a&&{width:"100%",maxWidth:r(a)}),{borderRadius:"4px"}),s),clickable:d,noArrow:!0,opacity:1},b,{children:n}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),c=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),f=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),h=require("eventsource-parser"),v=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),I=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),x=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),O=require("../../Core/ErrorAlert.js"),N=require("../../../common/error.js"),S=require("../../../common/api/pickaxe.js"),w=require("../../../common/validation.js"),_=require("../../../common/cn.js"),k=require("../../../common/utils.js"),E=require("../../../common/pickaxeConfig.js"),U=require("../../../common/deploymentWebhooks.js"),C=require("../../../hooks/studio/useStudio.js"),T=require("../../../hooks/pickaxe/useSpeech.js"),A=require("../common/PickaxeCommon.js");const D=e=>"string"==typeof e&&e.trim().length>0,P=e=>e.map((e=>Object.assign({},e))),L=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),R=(e,t)=>{if(e&&"object"==typeof e)return e[t]},q=(e,t)=>{const s=R(e,t);return D(s)?s:null},M=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},F=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(R(e,"uses"))?R(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>D(e)?{type:"deployment",id:e}:D(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!o)return{scope:o,record:null};const a=null!==(i=null!==(n=r.find((e=>e.id===o.id&&e.type===o.type)))&&void 0!==n?n:r.find((e=>e.id===o.id)))&&void 0!==i?i:null;return{scope:o,record:a}},V=s.forwardRef((({resubmitPrompt:R,onFocus:V,onBlur:$,onInputHeightChange:B,initSmitheryAuthData:X},H)=>{var K,W,Y,J,z,G,Q,Z,ee,te;const{origin:se,pickaxeId:ne,sessionId:ie,sender:re,senderType:oe,portalId:ae,deploymentId:le,deploymentType:ce,pickaxe:de,styles:ue,colors:pe,translations:me,locale:fe,forceMobile:ge,isNewChat:he,isRtl:ve,isShowFeedbackMessage:be,accessGroup:Ie,setIsNewChat:ye,setIsShowIceBreaker:xe,setValidationStatus:je,setValidationUpgradeGroups:Oe,setValidationUpgradeUrl:Ne,onGenerateComplete:Se}=n.usePickaxeContext(),{token:we,isLoggedOut:_e,isSent:ke,isPricingAuth:Ee}=c.useAuthContext(),{messages:Ue,isGenerating:Ce,setMessages:Te,setStatus:Ae,setLimitData:De,setError:Pe}=i.useResponseContext(),{documents:Le,isUploading:Re,documentError:qe,onFileUpload:Me,setDocuments:Fe,setDocumentError:Ve}=d.useDocument(),{studio:$e}=C.useStudio(),{scrollStartSession:Be,scrollEndSession:Xe,scrollToBottom:He}=u.useScroll({auto:!0}),{artifacts:Ke,currentPopupType:We,setArtifacts:Ye,setCurrentArtifact:Je}=p.useArtifactContext(),{height:ze}=l.useDimensionContext(),Ge=a.useConversation(),[Qe,Ze]=s.useState(""),[et,tt]=s.useState(!1),[st,nt]=s.useState(!1),[it,rt]=s.useState(null),[ot,at]=s.useState(null),[lt,ct]=s.useState(!1),[dt,ut]=s.useState(!1),[pt,mt]=s.useState(0),ft=s.useRef(null),gt=s.useRef(""),ht=s.useRef(null),vt=s.useRef(null),bt=s.useRef(null),It=s.useRef([]),yt=s.useRef(null),xt=s.useRef(null),jt=s.useRef(null),Ot=s.useRef(null),Nt=s.useRef(new Set),St=s.useRef(null),wt=Math.max(.4*ze,100),{speechTranscript:_t,isSpeechListening:kt,isSpeechProcessing:Et,isSpeechSupported:Ut,onStartListening:Ct,onStopListening:Tt}=T.useSpeech(),[At]=f.useMediaQuery("(max-width: 480px)"),Dt=m.useHover(),{isHover:Pt}=Dt,Lt=e.__rest(Dt,["isHover"]),Rt=m.useHover(),{isHover:qt}=Rt,Mt=e.__rest(Rt,["isHover"]),Ft=m.useHover(),{isHover:Vt}=Ft,$t=e.__rest(Ft,["isHover"]),Bt=o.useStyleFontSize(),Xt=r.useStyleInput(),Ht="undefined"!=typeof window?window.location.hostname:"",Kt="undefined"!=typeof window?window.location.href:"",Wt="undefined"!=typeof window&&window.self!==window.top,Yt=Ht.includes("pickaxe.co")&&!Kt.includes("https://studio.pickaxe.co/_embed")&&!Wt,Jt=null!==(W=null===(K=null==de?void 0:de.documentuploadtype)||void 0===K?void 0:K.startsWith("enduserupload"))&&void 0!==W&&W,zt=Ut&&(null==de?void 0:de.enablevoicetotext),Gt=D(le),Qt="chat-input"===ce&&he&&!ke,Zt="chat-input"===ce&&Ee&&_e&&ke,es=s.useCallback((e=>{const t=w.getValidationFailure(e);return!!t&&(Pe(""),De(null),je(t.status),Oe(t.upgradeGroups),Ne(t.upgradeUrl),!0)}),[Pe,De,je,Oe,Ne]),ts=null!==(Y=null==de?void 0:de.placeholdertext)&&void 0!==Y?Y:ve?"بماذا تريد أن تتحدث؟":(null==me?void 0:me["what-do-you-want-to-talk-about"])||"What do you want to talk about?",ss=et||st,ns=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){ct(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==de?void 0:de.studioid},we?{studioSessionToken:we}:re?{sender:re}:{sender:k.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),Yt&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(rt(t.studioUser),at(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{ct(!0)}}))),[Yt,null==de?void 0:de.studioid,re,we]);s.useEffect((()=>{ns()}),[ns]);const is=Number(null!==(J=null==Ie?void 0:Ie.limit)&&void 0!==J?J:0),rs="string"==typeof(null==Ie?void 0:Ie.limitInterval)?Ie.limitInterval:null,os=!!(null==$e?void 0:$e.data.usage)&&$e.data.usage.isCredits,as=s.useMemo((()=>F({studioUser:it,deploymentId:le,portalId:ae})),[le,ae,it]);s.useEffect((()=>{Gt&&he&&ie&&Nt.current.add(ie)}),[he,ie,Gt]);const ls=s.useCallback((()=>{var e,t,s;return{studioId:null==de?void 0:de.studioid,userEmail:q(it,"email"),userId:null!==(e=q(it,"userId"))&&void 0!==e?e:q(it,"userid"),sessionId:ie,deploymentId:le,deploymentType:ce,portalId:ae,accessGroupId:null!==(t=null==Ie?void 0:Ie.accessGroupId)&&void 0!==t?t:null,pickaxeId:ne,sender:re,senderType:oe,origin:se,metadata:null!==(s=E.getPickaxeConfigMetadata(le))&&void 0!==s?s:null}}),[null==Ie?void 0:Ie.accessGroupId,le,ce,se,null==de?void 0:de.studioid,ne,ae,re,oe,ie,it]),cs=s.useCallback((()=>!!(Gt&&lt&&ie)&&(!!Nt.current.has(ie)&&(U.fireDeploymentSessionInitializedWebhook(ls()),Nt.current.delete(ie),!0))),[ls,lt,ie,Gt]);s.useEffect((()=>{if(!lt||!ie)return;cs();const e=St.current;(null==e?void 0:e.sessionId)===ie&&(U.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),ls()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),St.current=null)}),[cs,ls,lt,ie]);const ds={currentUses:M(null==it?void 0:it.currentUses),extraUses:M(null==it?void 0:it.extraUses)},us=as.scope?{currentUses:null!==(G=M(null===(z=as.record)||void 0===z?void 0:z.currentUses))&&void 0!==G?G:0,extraUses:null!==(Z=M(null===(Q=as.record)||void 0===Q?void 0:Q.extraUses))&&void 0!==Z?Z:0}:{currentUses:0,extraUses:0},ps=q(it,"type"),ms="guest"===ps||!ps&&_e?us:ds;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(os&&(null===(e=null==$e?void 0:$e.data)||void 0===e?void 0:e.workspaceId))try{const e=yield S.default.get(`/cost_per_run?workspaceId=${$e.data.workspaceId}`,{withCredentials:!1});t&&mt(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&mt(0)}else t&&mt(0)})),()=>{t=!1}}),[os,null===(ee=null==$e?void 0:$e.data)||void 0===ee?void 0:ee.workspaceId]);const fs=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),r=Number(null!=t?t:0);return s===A.STUDIO_INFINITY_VALUE||r===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,r-i):(console.log("Calculating remaining balance with limit:",s,"currentUses:",i,"extraUses:",r),Math.max(0,s-i)+r)})({currentUses:ms.currentUses,extraUses:ms.extraUses,limit:is,limitInterval:rs}),gs=fs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(fs)),hs=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===A.STUDIO_INFINITY_VALUE||n===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:ms.extraUses,limit:is,limitInterval:rs}),vs=hs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.ceil(.05*hs),bs=os?Math.ceil(5*pt):5,Is=vs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(vs,bs),ys=s.useMemo((()=>!!it&&(!dt&&(gs!==A.STUDIO_INFINITY_VALUE&&gs<=Is))),[dt,Is,gs,it]),xs=s.useMemo((()=>{var e,t,s;return!!he&&(!!de&&(!Ge.isLoading&&(!((null!==(t=null===(e=Ge.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=de.icebreakers)||void 0===s?void 0:s.length)&&(!be&&!Qt)))))}),[de,he,be,Qt,Ge.data,Ge.isLoading]),js=s.useMemo((()=>{if(Ce||Re)return!1;const e=Jt&&Le.length>0&&Le.every((e=>"finished"===e.status));return!(!Qe.trim()&&!e)&&Le.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Jt,Ce,Re,Qe,Le]);s.useImperativeHandle(H,(()=>({onSubmit:Os}))),s.useEffect((()=>{xe(xs)}),[xs]),s.useEffect((()=>{var e;if(R){const t=Array.from(Ue),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Os(s,!0)}}),[R]),s.useEffect((()=>{if(!jt.current||!B)return;const e=new ResizeObserver((e=>{for(const t of e)B(t.contentRect.height)}));return e.observe(jt.current),()=>{e.disconnect()}}),[B]),s.useEffect((()=>{if(!kt)return;const e=gt.current?`${gt.current} `:"";Ze(`${e}${_t}`)}),[_t,kt]),s.useEffect((()=>{if(!yt.current)return;(()=>{if(!yt.current)return;let e=yt.current.scrollHeight>52;Qe.includes("\n")||Le.length?e=!0:Qe.trim()||(e=!1),tt(e)})()}),[Qe,Le]),s.useEffect((()=>{const e=yt.current,t=xt.current;if(!e||!t||et||Qe.includes("\n"))return void nt(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=Qe||ts,document.body.appendChild(i);const r=i.offsetWidth;i.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;nt(r>l)}),[Qe,et,ts]);const Os=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i,r;let o=null;try{if(Ce||Re)return;const a=Le.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),l=a.map((e=>e.documentId)).filter(Boolean),c=a.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),d=null!=t?t:Qe,u=null!==(n=null===(e=null==de?void 0:de.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&l.length>0;if(!d&&!u)return;Pe(""),Ve(""),De(null),Ze(""),ye(!1),Ae("fetching"),Be(),He();const p=[...s?Array.from(Ue.slice(0,Ue.length-1)):Array.from(Ue),...s?[]:[{id:Ue.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:u?l:[]}],{id:Ue.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];Te(p),He(),u&&Fe([]);const m=E.getPickaxeConfigMetadata(le),f="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;o=f,vt.current=f,bt.current=null,It.current=[];const g=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:se,pickaxeId:ne,sessionId:ie,submissionId:f,senderType:oe,value:d},u&&{documentIds:l}),re&&{sender:re}),we&&{studioSessionToken:we}),!we&&!re&&{sender:k.initializeEmbedUserId()}),ae&&{portalId:ae}),le&&{deploymentId:le}),m&&{metadata:m}),u&&c.length>0?{uploadedModelImages:c}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},Yt&&{credentials:"include"})),v=yield g.json();if(!v.success){if(es(v))return;const e=new Error(v.error||v.message||(null==me?void 0:me["failed-to-start-generation"])||"Failed to start generation");throw v.limitData&&(e.limitData=v.limitData),e}const b=null!==(i=v.submissionId)&&void 0!==i?i:f;o=b,vt.current=b;const I=()=>bt.current===b;if(I())return;Gt&&he&&ie&&Nt.current.add(ie);const y=Object.assign(Object.assign({},ls()),{message:d,documentIds:u?l:[],uploadedModelImages:u?c:[],hasUploadedDocuments:u,isHidden:s,metadata:null!=m?m:null});lt?(cs(),U.fireDeploymentFirstMessageSubmittedWebhook(y)):St.current=y,Ae("streaming"),Ot.current=new AbortController;const x=p.length-1,j=[];let O=[...null!=Ke?Ke:[]],N=0,S=!1,w="";for(;!S;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${N}`,{signal:null===(r=Ot.current)||void 0===r?void 0:r.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();ht.current=t;const s=new TextDecoder,n=h.createParser({onEvent:e=>{var t,s;if(I())S=!0;else if(e.event&&"ping"!==e.event&&N++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==me?void 0:me["something-went-wrong"])||"Something went wrong.";return es(t)||Pe(s),void(S=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&X){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw S=!0,X({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw S=!0,X({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)w="",j.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)w+=n.delta,j[j.length-1].content=w;else if("text-end"===n.type)w="";else if("reasoning-start"===n.type)w="",j.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)w+=n.delta,j[j.length-1].content=w;else if("reasoning-end"===n.type)w="";else if(n.type.startsWith("data-")){const e=n;j.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}It.current=P(j),Te([...p.slice(0,x),Object.assign(Object.assign({},p[p.length-1]),{id:Ue.length+1,role:"assistant",parts:j})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ye([...O]),We.startsWith("inline")||Je({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Ye(O),We.startsWith("inline")||Je({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Ye(O),We.startsWith("inline")||Je({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");O=O.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Ye(O)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Ye(O.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==me?void 0:me["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(es(t))return void(S=!0);Pe(s)}else"stop"===e.event&&(S=!0)}else S=!0}});for(;;){if(I()){S=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(I()){S=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}S||I()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||L(e)||I())return void(S=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==Se||Se(ie)}catch(e){if(L(e))return;if(e.limitData)De(e.limitData),Pe("");else{let t=N.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==me?void 0:me["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),es(t)||Pe(t)}}finally{const e=!o||vt.current===o;He(),e&&(Ae("idle"),Xe(),ht.current=null),o&&e&&(vt.current=null,It.current=[]),yield ns()}}));return Zt?null:t.jsx("div",Object.assign({className:_.default("flex w-full flex-shrink-0 flex-col items-center",!Qt&&"px-4 pb-8"),dir:ve?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:jt,className:_.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===ue.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Xt),{maxHeight:`${wt}px`,overflowY:"auto"})},{children:[ys&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Xt.backgroundColor?`${Xt.backgroundColor}E6`:void 0,borderColor:pe.text+"20",color:pe.text,borderTopRightRadius:ue.cornerRadius+"px",borderTopLeftRadius:ue.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[gs.toLocaleString()," ",os?(null==me?void 0:me.credits)||"Credits":(null==me?void 0:me.uses)||"Uses"," ",(null==me?void 0:me.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:pe.accent,color:pe.accentText},onClick:e=>{e.preventDefault(),e.stopPropagation();const t=k.buildUpgradeUrl({baseUrl:ot,accessGroupId:null==Ie?void 0:Ie.accessGroupId});t&&(k.isInIframe()?window.open(t):location.href=t)}},{children:(null==me?void 0:me["pricing.upgrade"])||(null==me?void 0:me.upgrade)||"Upgrade"})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>ut(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Ce&&Le.length>0&&t.jsx(x.default,{className:"p-4 pb-0",isDisabled:Ce}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[kt&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(te=pe.accent)&&void 0!==te?te:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:pe.text+"90"}},{children:(null==me?void 0:me.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:yt,className:_.default(Bt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Qe.trim()&&!Qe.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",ve?"text-right":"text-left",ss&&"mb-12",kt&&"text-transparent"),value:Qe,placeholder:ts,onChange:e=>{Ze(e)},onKeyDown:e=>{ge||At||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Re||Ce||Os()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Jt)return;t.preventDefault(),ye(!1),yield Me(e)}}))},V&&{onFocus:V},$&&{onBlur:$},{dir:ve?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:xt,className:_.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",ss?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!ss&&Xt.backgroundColor&&{backgroundColor:Xt.backgroundColor}),{borderTopRightRadius:ue.cornerRadius+"px",borderBottomRightRadius:ue.cornerRadius+"px"})},{children:Ce?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const t=vt.current;t&&(bt.current=t,(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:vt.current))return;const e=P(It.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/cancel/${t}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:e})},Yt&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(t)),Ot.current&&(Ot.current.abort(),Ot.current=null),ht.current&&(ht.current.cancel().catch((()=>{})),ht.current=null),Ae("idle")},style:{backgroundColor:pe.accent,color:pe.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):kt?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Tt,style:{backgroundColor:pe.accent,color:pe.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Jt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:qt?pe.accent+"10":void 0,color:qt?pe.accent:pe.accent+"80"},disabled:Re||Ce,onClick:()=>{var e;return null===(e=ft.current)||void 0===e?void 0:e.click()}},Mt,{children:[t.jsx("input",{id:"file-upload",ref:ft,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){ye(!1),yield Me(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),zt&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:kt?pe.accent:Vt?pe.accent+"10":void 0,color:kt?pe.accentText:Vt?pe.accent:pe.accent+"80"},disabled:Re||Ce||Et,onClick:()=>{kt?Tt():(gt.current=Qe,Ct(fe||"en-US"))}},$t,{children:t.jsx(I.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Pt||js?pe.accent:pe.accent+"10",color:Pt||js?pe.accentText:pe.accent+"80"},disabled:!js,onClick:()=>Os()},Lt,{children:t.jsx(b.default,{className:_.default("h-6 w-6 shrink-0",ve&&"scale-x-[-1] transform")})}))]})}))]}))]})),qe&&t.jsx(O.default,{error:qe,className:"mt-3"})]}))}))}));V.displayName="Input",exports.default=V;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../hooks/pickaxe/useResponseContext.js"),r=require("../../../hooks/studio/useStyleInput.js"),o=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),c=require("../Addons/Auth/hooks/useAuthContext.js"),d=require("../Addons/Document/hooks/useDocument.js"),u=require("../Addons/Scroll/hooks/useScroll.js"),p=require("../Addons/Artifact/hooks/useArtifactContext.js"),m=require("../../../hooks/core/useHover.js"),f=require("../../../hooks/core/useMediaQuery.js"),g=require("../../../common/documents.js"),h=require("eventsource-parser"),v=require("../../Icons/attach-vertical.svg.js"),b=require("../../Icons/arrow-right.svg.js"),y=require("../../Icons/microphone.svg.js"),I=require("../../Icons/stop.svg.js"),x=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),O=require("../../Core/ErrorAlert.js"),w=require("../../../common/error.js"),N=require("../../../common/api/pickaxe.js"),S=require("../../../common/validation.js"),_=require("../../../common/cn.js"),k=require("../../../common/utils.js"),E=require("../../../common/pickaxeConfig.js"),C=require("../../../common/deploymentWebhooks.js"),U=require("../../../hooks/studio/useStudio.js"),T=require("../../../hooks/pickaxe/useSpeech.js"),A=require("../common/PickaxeCommon.js");const D=e=>"string"==typeof e&&e.trim().length>0,P=e=>e.map((e=>Object.assign({},e))),L=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),R=(e,t)=>{if(e&&"object"==typeof e)return e[t]},q=(e,t)=>{const s=R(e,t);return D(s)?s:null},M=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},F=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(R(e,"uses"))?R(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>D(e)?{type:"deployment",id:e}:D(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!o)return{scope:o,record:null};const a=null!==(i=null!==(n=r.find((e=>e.id===o.id&&e.type===o.type)))&&void 0!==n?n:r.find((e=>e.id===o.id)))&&void 0!==i?i:null;return{scope:o,record:a}},V=s.forwardRef((({resubmitPrompt:R,onFocus:V,onBlur:$,onInputHeightChange:B,initSmitheryAuthData:X},H)=>{var K,W,Y,G,J,z,Q,Z,ee,te,se,ne;const{origin:ie,pickaxeId:re,sessionId:oe,sender:ae,senderType:le,portalId:ce,deploymentId:de,deploymentType:ue,pickaxe:pe,styles:me,colors:fe,translations:ge,locale:he,forceMobile:ve,isNewChat:be,isRtl:ye,isShowFeedbackMessage:Ie,accessGroup:xe,setIsNewChat:je,setIsShowIceBreaker:Oe,setValidationStatus:we,setValidationUpgradeGroups:Ne,setValidationUpgradeUrl:Se,setAccessGroup:_e,onGenerateComplete:ke}=n.usePickaxeContext(),{token:Ee,isLoggedOut:Ce,isSent:Ue,isPricingAuth:Te}=c.useAuthContext(),{messages:Ae,isGenerating:De,setMessages:Pe,setStatus:Le,setLimitData:Re,setError:qe}=i.useResponseContext(),{documents:Me,isUploading:Fe,documentError:Ve,onFileUpload:$e,setDocuments:Be,setDocumentError:Xe}=d.useDocument(),{studio:He}=U.useStudio(),{scrollStartSession:Ke,scrollEndSession:We,scrollToBottom:Ye}=u.useScroll({auto:!0}),{artifacts:Ge,currentPopupType:Je,setArtifacts:ze,setCurrentArtifact:Qe}=p.useArtifactContext(),{height:Ze}=l.useDimensionContext(),et=a.useConversation(),[tt,st]=s.useState(""),[nt,it]=s.useState(!1),[rt,ot]=s.useState(!1),[at,lt]=s.useState(null),[ct,dt]=s.useState(null),[ut,pt]=s.useState(!1),[mt,ft]=s.useState(!1),[gt,ht]=s.useState(0),vt=s.useRef(null),bt=s.useRef(""),yt=s.useRef(null),It=s.useRef(null),xt=s.useRef(null),jt=s.useRef([]),Ot=s.useRef(null),wt=s.useRef(null),Nt=s.useRef(null),St=s.useRef(null),_t=s.useRef(new Set),kt=s.useRef(null),Et=Math.max(.4*Ze,100),{speechTranscript:Ct,isSpeechListening:Ut,isSpeechProcessing:Tt,isSpeechSupported:At,onStartListening:Dt,onStopListening:Pt}=T.useSpeech(),[Lt]=f.useMediaQuery("(max-width: 480px)"),Rt=m.useHover(),{isHover:qt}=Rt,Mt=e.__rest(Rt,["isHover"]),Ft=m.useHover(),{isHover:Vt}=Ft,$t=e.__rest(Ft,["isHover"]),Bt=m.useHover(),{isHover:Xt}=Bt,Ht=e.__rest(Bt,["isHover"]),Kt=o.useStyleFontSize(),Wt=r.useStyleInput(),Yt="undefined"!=typeof window?window.location.hostname:"",Gt="undefined"!=typeof window?window.location.href:"",Jt="undefined"!=typeof window&&window.self!==window.top,zt=Yt.includes("pickaxe.co")&&!Gt.includes("https://studio.pickaxe.co/_embed")&&!Jt,Qt=null!==(W=null===(K=null==pe?void 0:pe.documentuploadtype)||void 0===K?void 0:K.startsWith("enduserupload"))&&void 0!==W&&W,Zt=At&&(null==pe?void 0:pe.enablevoicetotext),es=D(de),ts="chat-input"===ue&&be&&!Ue,ss="chat-input"===ue&&Te&&Ce&&Ue,ns=s.useCallback((e=>{const t=S.getValidationFailure(e);return!!t&&(qe(""),Re(null),we(t.status),_e(t.accessGroup),Ne(t.upgradeGroups),Se(t.upgradeUrl),!0)}),[qe,Re,we,Ne,Se,_e]),is=null!==(Y=null==pe?void 0:pe.placeholdertext)&&void 0!==Y?Y:ye?"بماذا تريد أن تتحدث؟":(null==ge?void 0:ge["what-do-you-want-to-talk-about"])||"What do you want to talk about?",rs=nt||rt,os=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){pt(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==pe?void 0:pe.studioid},Ee?{studioSessionToken:Ee}:ae?{sender:ae}:{sender:k.initializeEmbedUserId()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),zt&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(lt(t.studioUser),dt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{pt(!0)}}))),[zt,null==pe?void 0:pe.studioid,ae,Ee]);s.useEffect((()=>{os()}),[os]);const as=Number(null!==(G=null==xe?void 0:xe.limit)&&void 0!==G?G:0),ls="string"==typeof(null==xe?void 0:xe.limitInterval)?xe.limitInterval:null,cs=!!(null==He?void 0:He.data.usage)&&He.data.usage.isCredits,ds=s.useMemo((()=>F({studioUser:at,deploymentId:de,portalId:ce})),[de,ce,at]);s.useEffect((()=>{es&&be&&oe&&_t.current.add(oe)}),[be,oe,es]);const us=s.useCallback((()=>{var e,t,s;return{studioId:null==pe?void 0:pe.studioid,userEmail:q(at,"email"),userId:null!==(e=q(at,"userId"))&&void 0!==e?e:q(at,"userid"),sessionId:oe,deploymentId:de,deploymentType:ue,portalId:ce,accessGroupId:null!==(t=null==xe?void 0:xe.accessGroupId)&&void 0!==t?t:null,pickaxeId:re,sender:ae,senderType:le,origin:ie,metadata:null!==(s=E.getPickaxeConfigMetadata(de))&&void 0!==s?s:null}}),[null==xe?void 0:xe.accessGroupId,de,ue,ie,null==pe?void 0:pe.studioid,re,ce,ae,le,oe,at]),ps=s.useCallback((()=>!!(es&&ut&&oe)&&(!!_t.current.has(oe)&&(C.fireDeploymentSessionInitializedWebhook(us()),_t.current.delete(oe),!0))),[us,ut,oe,es]);s.useEffect((()=>{if(!ut||!oe)return;ps();const e=kt.current;(null==e?void 0:e.sessionId)===oe&&(C.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),us()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),kt.current=null)}),[ps,us,ut,oe]);const ms={currentUses:M(null==at?void 0:at.currentUses),extraUses:M(null==at?void 0:at.extraUses)},fs=ds.scope?{currentUses:null!==(z=M(null===(J=ds.record)||void 0===J?void 0:J.currentUses))&&void 0!==z?z:0,extraUses:null!==(Z=M(null===(Q=ds.record)||void 0===Q?void 0:Q.extraUses))&&void 0!==Z?Z:0}:{currentUses:0,extraUses:0},gs=q(at,"type"),hs="guest"===gs||!gs&&Ce?fs:ms;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(cs&&(null===(e=null==He?void 0:He.data)||void 0===e?void 0:e.workspaceId))try{const e=yield N.default.get(`/cost_per_run?workspaceId=${He.data.workspaceId}`,{withCredentials:!1});t&&ht(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&ht(0)}else t&&ht(0)})),()=>{t=!1}}),[cs,null===(ee=null==He?void 0:He.data)||void 0===ee?void 0:ee.workspaceId]);const vs=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),r=Number(null!=t?t:0);return s===A.STUDIO_INFINITY_VALUE||r===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,r-i):(console.log("Calculating remaining balance with limit:",s,"currentUses:",i,"extraUses:",r),Math.max(0,s-i)+r)})({currentUses:hs.currentUses,extraUses:hs.extraUses,limit:as,limitInterval:ls}),bs=vs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(vs)),ys=(({extraUses:e,limit:t,limitInterval:s})=>{const n=Number(null!=e?e:0);return t===A.STUDIO_INFINITY_VALUE||n===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===s?Math.max(0,n):Math.max(0,t)+Math.max(0,n)})({extraUses:hs.extraUses,limit:as,limitInterval:ls}),Is=ys===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.ceil(.05*ys),xs=cs?Math.ceil(5*gt):5,js=Is===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(Is,xs),Os=s.useMemo((()=>!!at&&(!mt&&(bs!==A.STUDIO_INFINITY_VALUE&&bs<=js))),[mt,js,bs,at]),ws=(null===(te=null==xe?void 0:xe.upgrade)||void 0===te?void 0:te.isLinkToCustomURL)&&"string"==typeof xe.upgrade.limitLink&&xe.upgrade.limitLink.trim().length>0?xe.upgrade.limitLink.trim():null,Ns=ws&&"string"==typeof(null===(se=null==xe?void 0:xe.upgrade)||void 0===se?void 0:se.limitCTA)&&xe.upgrade.limitCTA.trim().length>0?xe.upgrade.limitCTA:(null==ge?void 0:ge["pricing.upgrade"])||(null==ge?void 0:ge.upgrade)||"Upgrade",Ss=s.useMemo((()=>{var e,t,s;return!!be&&(!!pe&&(!et.isLoading&&(!((null!==(t=null===(e=et.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=pe.icebreakers)||void 0===s?void 0:s.length)&&(!Ie&&!ts)))))}),[pe,be,Ie,ts,et.data,et.isLoading]),_s=s.useMemo((()=>{if(De||Fe)return!1;const e=Qt&&Me.length>0&&Me.every((e=>"finished"===e.status));return!(!tt.trim()&&!e)&&Me.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Qt,De,Fe,tt,Me]);s.useImperativeHandle(H,(()=>({onSubmit:ks}))),s.useEffect((()=>{Oe(Ss)}),[Ss]),s.useEffect((()=>{var e;if(R){const t=Array.from(Ae),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;ks(s,!0)}}),[R]),s.useEffect((()=>{if(!Nt.current||!B)return;const e=new ResizeObserver((e=>{for(const t of e)B(t.contentRect.height)}));return e.observe(Nt.current),()=>{e.disconnect()}}),[B]),s.useEffect((()=>{if(!Ut)return;const e=bt.current?`${bt.current} `:"";st(`${e}${Ct}`)}),[Ct,Ut]),s.useEffect((()=>{if(!Ot.current)return;(()=>{if(!Ot.current)return;let e=Ot.current.scrollHeight>52;tt.includes("\n")||Me.length?e=!0:tt.trim()||(e=!1),it(e)})()}),[tt,Me]),s.useEffect((()=>{const e=Ot.current,t=wt.current;if(!e||!t||nt||tt.includes("\n"))return void ot(!1);const s=window.getComputedStyle(e),n=`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${s.fontSize} / ${s.lineHeight} ${s.fontFamily}`,i=document.createElement("span");Object.assign(i.style,{font:n,letterSpacing:s.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),i.textContent=tt||is,document.body.appendChild(i);const r=i.offsetWidth;i.remove();const o=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-o-a-t.offsetWidth;ot(r>l)}),[tt,nt,is]);const ks=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i,r;let o=null;try{if(De||Fe)return;const a=Me.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),l=a.map((e=>e.documentId)).filter(Boolean),c=a.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),d=null!=t?t:tt,u=null!==(n=null===(e=null==pe?void 0:pe.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&l.length>0;if(!d&&!u)return;qe(""),Xe(""),Re(null),st(""),je(!1),Le("fetching"),Ke(),Ye();const p=[...s?Array.from(Ae.slice(0,Ae.length-1)):Array.from(Ae),...s?[]:[{id:Ae.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:u?l:[]}],{id:Ae.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];Pe(p),Ye(),u&&Be([]);const m=E.getPickaxeConfigMetadata(de),f="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;o=f,It.current=f,xt.current=null,jt.current=[];const g=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:ie,pickaxeId:re,sessionId:oe,submissionId:f,senderType:le,value:d},u&&{documentIds:l}),ae&&{sender:ae}),Ee&&{studioSessionToken:Ee}),!Ee&&!ae&&{sender:k.initializeEmbedUserId()}),ce&&{portalId:ce}),de&&{deploymentId:de}),m&&{metadata:m}),u&&c.length>0?{uploadedModelImages:c}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},zt&&{credentials:"include"})),v=yield g.json();if(!v.success){if(v.limitData){const e=new Error(v.error||v.message||(null==ge?void 0:ge["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=v.limitData,e}if(ns(v))return;throw new Error(v.error||v.message||(null==ge?void 0:ge["failed-to-start-generation"])||"Failed to start generation")}const b=null!==(i=v.submissionId)&&void 0!==i?i:f;o=b,It.current=b;const y=()=>xt.current===b;if(y())return;es&&be&&oe&&_t.current.add(oe);const I=Object.assign(Object.assign({},us()),{message:d,documentIds:u?l:[],uploadedModelImages:u?c:[],hasUploadedDocuments:u,isHidden:s,metadata:null!=m?m:null});ut?(ps(),C.fireDeploymentFirstMessageSubmittedWebhook(I)):kt.current=I,Le("streaming"),St.current=new AbortController;const x=p.length-1,j=[];let O=[...null!=Ge?Ge:[]],w=0,N=!1,S="";for(;!N;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${w}`,{signal:null===(r=St.current)||void 0===r?void 0:r.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();yt.current=t;const s=new TextDecoder,n=h.createParser({onEvent:e=>{var t,s;if(y())N=!0;else if(e.event&&"ping"!==e.event&&w++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(N=!0);const s=t.error||t.message||(null==ge?void 0:ge["something-went-wrong"])||"Something went wrong.";return ns(t)||qe(s),void(N=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&X){const e=n.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&s&&s[1]&&n&&n[1])throw N=!0,X({smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw N=!0,X({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)S="",j.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)S+=n.delta,j[j.length-1].content=S;else if("text-end"===n.type)S="";else if("reasoning-start"===n.type)S="",j.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)S+=n.delta,j[j.length-1].content=S;else if("reasoning-end"===n.type)S="";else if(n.type.startsWith("data-")){const e=n;j.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}jt.current=P(j),Pe([...p.slice(0,x),Object.assign(Object.assign({},p[p.length-1]),{id:Ae.length+1,role:"assistant",parts:j})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ze([...O]),Je.startsWith("inline")||Qe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),ze(O),Je.startsWith("inline")||Qe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);O=O.filter((e=>!(e.id===t.id&&e.version===t.version))),O.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ze(O),Je.startsWith("inline")||Qe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");O=O.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),ze(O)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);ze(O.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return Re(t.limitData),qe(""),void(N=!0);const s=t.error||t.message||(null==ge?void 0:ge["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(ns(t))return void(N=!0);qe(s)}else"stop"===e.event&&(N=!0)}else N=!0}});for(;;){if(y()){N=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(y()){N=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}N||y()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||L(e)||y())return void(N=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==ke||ke(oe)}catch(e){if(L(e))return;if(e.limitData)Re(e.limitData),qe("");else{let t=w.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==ge?void 0:ge["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),ns(t)||qe(t)}}finally{const e=!o||It.current===o;Ye(),e&&(Le("idle"),We(),yt.current=null),o&&e&&(It.current=null,jt.current=[]),yield os()}}));return ss?null:t.jsx("div",Object.assign({className:_.default("flex w-full flex-shrink-0 flex-col items-center",!ts&&"px-4 pb-8"),dir:ye?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:Nt,className:_.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===me.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Wt),{maxHeight:`${Et}px`,overflowY:"auto"})},{children:[Os&&t.jsxs("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:Wt.backgroundColor?`${Wt.backgroundColor}E6`:void 0,borderColor:fe.text+"20",color:fe.text,borderTopRightRadius:me.cornerRadius+"px",borderTopLeftRadius:me.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[bs.toLocaleString()," ",cs?(null==ge?void 0:ge.credits)||"Credits":(null==ge?void 0:ge.uses)||"Uses"," ",(null==ge?void 0:ge.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:fe.accent,color:fe.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),ws)return void window.open(ws,"_blank","noopener,noreferrer");const t=k.buildUpgradeUrl({baseUrl:ct,accessGroupId:null==xe?void 0:xe.accessGroupId});t&&(k.isInIframe()?window.open(t):location.href=t)}},{children:Ns})),t.jsx("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>ft(!0)},{children:t.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!De&&Me.length>0&&t.jsx(x.default,{className:"p-4 pb-0",isDisabled:De}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[Ut&&t.jsxs("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(ne=fe.accent)&&void 0!==ne?ne:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:fe.text+"90"}},{children:(null==ge?void 0:ge.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:Ot,className:_.default(Kt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!tt.trim()&&!tt.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",ye?"text-right":"text-left",rs&&"mb-12",Ut&&"text-transparent"),value:tt,placeholder:is,onChange:e=>{st(e)},onKeyDown:e=>{ve||Lt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Fe||De||ks()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Qt)return;t.preventDefault(),je(!1),yield $e(e)}}))},V&&{onFocus:V},$&&{onBlur:$},{dir:ye?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:wt,className:_.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",rs?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!rs&&Wt.backgroundColor&&{backgroundColor:Wt.backgroundColor}),{borderTopRightRadius:me.cornerRadius+"px",borderBottomRightRadius:me.cornerRadius+"px"})},{children:De?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const t=It.current;t&&(xt.current=t,(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:It.current))return;const e=P(jt.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/cancel/${t}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:e})},zt&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(t)),St.current&&(St.current.abort(),St.current=null),yt.current&&(yt.current.cancel().catch((()=>{})),yt.current=null),Le("idle")},style:{backgroundColor:fe.accent,color:fe.accentText}},{children:t.jsx(I.default,{className:"h-4 w-4 shrink-0"})})):Ut?t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Pt,style:{backgroundColor:fe.accent,color:fe.accentText}},{children:t.jsx(I.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Qt&&t.jsxs("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Vt?fe.accent+"10":void 0,color:Vt?fe.accent:fe.accent+"80"},disabled:Fe||De,onClick:()=>{var e;return null===(e=vt.current)||void 0===e?void 0:e.click()}},$t,{children:[t.jsx("input",{id:"file-upload",ref:vt,type:"file",accept:[...g.allowedFileMimeTypes,...g.allowedImageMimeTypes,...g.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){je(!1),yield $e(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),Zt&&t.jsx("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Ut?fe.accent:Xt?fe.accent+"10":void 0,color:Ut?fe.accentText:Xt?fe.accent:fe.accent+"80"},disabled:Fe||De||Tt,onClick:()=>{Ut?Pt():(bt.current=tt,Dt(he||"en-US"))}},Ht,{children:t.jsx(y.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:qt||_s?fe.accent:fe.accent+"10",color:qt||_s?fe.accentText:fe.accent+"80"},disabled:!_s,onClick:()=>ks()},Mt,{children:t.jsx(b.default,{className:_.default("h-6 w-6 shrink-0",ye&&"scale-x-[-1] transform")})}))]})}))]}))]})),Ve&&t.jsx(O.default,{error:Ve,className:"mt-3"})]}))}))}));V.displayName="Input",exports.default=V;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/studio/useStyleFontSize.js"),r=require("../../../Icons/check.svg.js"),a=require("./Dropdown.js"),c=require("../../../../common/cn.js");exports.default=({field:l,update:o})=>{const{colors:u,isRtl:d,translations:p}=t.usePickaxeContext(),{setError:x}=i.useResponseContext(),j=n.useStyleFontSize(),m=s.useRef(null),f=s.useMemo((()=>l.example.split("S3P32X")),[l.example]),b=s.useMemo((()=>l.input?l.input.split("&#44;"):[]),[l.input]),[h,g]=s.useState((()=>{const e=f.includes(l.input);return l.allowOther&&l.input&&!e?l.input:""}));return e.jsxs("div",Object.assign({className:"flex flex-col gap-y-3",dir:d?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:c.default(j.b3,"font-semibold opacity-70")},{children:l.main})),l.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:u.error}},{children:"*"}))]})),e.jsx(a.default,Object.assign({id:l.id.replace(/[^A-Za-z]+/g,""),value:l.input.replace(/&#44;/g,", "),placeholder:(null==p?void 0:p["select-options"])||"Select option(s)",closeOnSelect:!1,maxToken:l.maxLength,isDropdown:l.isDropdown},{children:e.jsxs("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[f.map(((s,t)=>e.jsxs("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{x("");const s=b.includes(e),t=l.input?l.input.split("&#44;"):[],i=new Set(t);s&&i.has(e)?i.delete(e):s||i.has(e)||i.add(e);const n=Array.from(i).filter((e=>""!==e.trim()));o(Object.assign(Object.assign({},l),{input:n.join("&#44;")}))})(s)},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:b.includes(s)?u.accent:u.accent+"80"},b.includes(s)&&{backgroundColor:u.accent})},{children:e.jsx(r.default,{className:c.default("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",b.includes(s)&&"opacity-100"),style:{color:u.accentText}})})),e.jsx("p",Object.assign({className:c.default(j.b2,"select-none")},{children:s}))]}),t))),l.allowOther&&e.jsxs("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{x("");const e=b.includes(h.trim()),s=l.input?l.input.split("&#44;"):[],t=Array.from(new Set(s)).filter((e=>""!==e.trim()&&f.includes(e)));e||t.push(h.trim()),o(Object.assign(Object.assign({},l),{input:t.join("&#44;")})),setTimeout((()=>{var e;return null===(e=m.current)||void 0===e?void 0:e.focus()}),0)}},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:b.includes(h)?u.accent:u.accent+"80"},b.includes(h)&&{backgroundColor:u.accent})},{children:e.jsx(r.default,{className:c.default("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",b.includes(h)&&"opacity-100"),style:{color:u.accentText}})})),e.jsxs("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e.jsxs("p",Object.assign({className:c.default(j.b2,"select-none opacity-80 min-w-fit")},{children:[(null==p?void 0:p.other)||"Other",":"]})),e.jsx("input",{ref:m,type:"text",className:c.default(j.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:b.includes(h)?u.accent:"rgba(0,0,0,0.2)"},value:h,onChange:e=>(e=>{x(""),g(e);const s=b.includes(e.trim()),t=l.input?l.input.split("&#44;"):[],i=new Set(t.filter((e=>f.includes(e))));s?i.delete(e.trim()):i.add(e.trim());const n=Array.from(i).filter((e=>""!==e.trim()));o(Object.assign(Object.assign({},l),{input:n.join("&#44;")}))})(e.target.value),placeholder:(null==p?void 0:p["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("react"),t=require("../../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../../../../hooks/pickaxe/useResponseContext.js"),i=require("../../../../hooks/studio/useStyleFontSize.js"),r=require("../../../Icons/check.svg.js"),o=require("./Dropdown.js"),a=require("../../../../common/cn.js");exports.default=({field:l,update:c})=>{const{colors:u,isRtl:d,translations:p}=t.usePickaxeContext(),{setError:x}=n.useResponseContext(),m=i.useStyleFontSize(),j=s.useRef(null),f=s.useMemo((()=>l.example.split("S3P32X")),[l.example]),b=s.useMemo((()=>l.input?l.input.split("&#44;"):[]),[l.input]),[h,g]=s.useState((()=>{const e=f.includes(l.input);return l.allowOther&&l.input&&!e?l.input:""}));return e.jsxs("div",Object.assign({className:"flex flex-col gap-y-3",dir:d?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:a.default(m.b3,"font-semibold opacity-70")},{children:l.main})),l.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:u.error}},{children:"*"}))]})),e.jsx(o.default,Object.assign({id:o.getDropdownMenuId(l.id),value:l.input.replace(/&#44;/g,", "),placeholder:(null==p?void 0:p["select-options"])||"Select option(s)",closeOnSelect:!1,maxToken:l.maxLength,isDropdown:l.isDropdown},{children:e.jsxs("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[f.map(((s,t)=>e.jsxs("div",Object.assign({className:"flex min-w-0 items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{x("");const s=b.includes(e),t=l.input?l.input.split("&#44;"):[],n=new Set(t);s&&n.has(e)?n.delete(e):s||n.has(e)||n.add(e);const i=Array.from(n).filter((e=>""!==e.trim()));c(Object.assign(Object.assign({},l),{input:i.join("&#44;")}))})(s)},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:b.includes(s)?u.accent:u.accent+"80"},b.includes(s)&&{backgroundColor:u.accent})},{children:e.jsx(r.default,{className:a.default("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",b.includes(s)&&"opacity-100"),style:{color:u.accentText}})})),e.jsx("p",Object.assign({className:a.default(m.b2,"min-w-0 select-none break-words"),style:{overflowWrap:"anywhere"}},{children:s}))]}),t))),l.allowOther&&e.jsxs("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{x("");const e=b.includes(h.trim()),s=l.input?l.input.split("&#44;"):[],t=Array.from(new Set(s)).filter((e=>""!==e.trim()&&f.includes(e)));e||t.push(h.trim()),c(Object.assign(Object.assign({},l),{input:t.join("&#44;")})),setTimeout((()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()}),0)}},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:b.includes(h)?u.accent:u.accent+"80"},b.includes(h)&&{backgroundColor:u.accent})},{children:e.jsx(r.default,{className:a.default("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",b.includes(h)&&"opacity-100"),style:{color:u.accentText}})})),e.jsxs("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e.jsxs("p",Object.assign({className:a.default(m.b2,"select-none opacity-80 min-w-fit")},{children:[(null==p?void 0:p.other)||"Other",":"]})),e.jsx("input",{ref:j,type:"text",className:a.default(m.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:b.includes(h)?u.accent:"rgba(0,0,0,0.2)"},value:h,onChange:e=>(e=>{x(""),g(e);const s=b.includes(e.trim()),t=l.input?l.input.split("&#44;"):[],n=new Set(t.filter((e=>f.includes(e))));s?n.delete(e.trim()):n.add(e.trim());const i=Array.from(n).filter((e=>""!==e.trim()));c(Object.assign(Object.assign({},l),{input:i.join("&#44;")}))})(e.target.value),placeholder:(null==p?void 0:p["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),r=require("../../../../hooks/studio/useStyleInput.js"),t=require("../../../Core/Menu/index.js"),a=require("../../../Core/Menu/Button.js"),n=require("../../../Core/Menu/List.js"),i=require("../../../../common/cn.js");exports.default=({id:o,children:l,placeholder:c,value:d,className:u,style:x,closeOnSelect:j=!0,maxToken:p=50,isDropdown:b=!1})=>{const{styles:m,colors:f}=s.usePickaxeContext(),h=r.useStyleInput();return b?e.jsxs(t.default,Object.assign({id:o,closeOnSelect:j,className:"relative"},{children:[e.jsx(a.default,Object.assign({variant:"anchor",className:i.default("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",u,p<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},h),x)},{children:e.jsx("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=d?d:"")||c}))})),e.jsx(n.default,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===f.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:p<=50?"400px":"100%",maxHeight:"200px",style:Object.assign(Object.assign(Object.assign({},h),{borderRadius:m.cornerRadius}),x)},{children:l}))]})):e.jsx("div",{children:l})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../../../hooks/studio/useStyleInput.js"),t=require("../../../Core/Menu/index.js"),a=require("../../../Core/Menu/Button.js"),n=require("../../../Core/Menu/List.js"),o=require("../../../../common/cn.js");exports.default=({id:i,children:l,placeholder:c,value:d,className:u,style:p,closeOnSelect:x=!0,maxToken:j=50,isDropdown:b=!1})=>{const{styles:g,colors:m}=r.usePickaxeContext(),f=s.useStyleInput(),h=Object.assign(Object.assign(Object.assign({},f),{borderRadius:g.cornerRadius}),p);return h.backgroundColor&&"transparent"!==h.backgroundColor||(h.backgroundColor=m.primary),b?e.jsxs(t.default,Object.assign({id:i,closeOnSelect:x,className:"relative"},{children:[e.jsx(a.default,Object.assign({variant:"anchor",className:o.default("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",u,j<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},f),p)},{children:e.jsx("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=d?d:"")||c}))})),e.jsx(n.default,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===m.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:j<=50?"400px":"100%",maxHeight:"200px",style:h},{children:l}))]})):e.jsx("div",{children:l})},exports.getDropdownMenuId=e=>{const r=e.trim().replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");let s=0;for(let r=0;r<e.length;r+=1)s=31*s+e.charCodeAt(r)>>>0;return`pxe-dropdown-${r||"field"}-${s.toString(36)}`};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/studio/useStyleFontSize.js"),i=require("react"),r=require("./Dropdown.js"),a=require("../../../../common/cn.js");exports.default=({field:l,update:o})=>{const{colors:c,isRtl:u,translations:d}=s.usePickaxeContext(),{setError:p}=t.useResponseContext(),x=n.useStyleFontSize(),j=i.useRef(null),b=i.useMemo((()=>l.example.split("S3P32X")),[l.example]),[g,m]=i.useState((()=>{const e=b.includes(l.input);return l.allowOther&&l.input&&!e?l.input:""})),f=i.useMemo((()=>!!l.allowOther&&(!b.includes(l.input)&&""!==l.input)),[l.allowOther,l.input,b]);return e.jsxs("div",Object.assign({className:"flex flex-col gap-y-3",dir:u?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:a.default(x.b3,"font-semibold opacity-70")},{children:l.main})),l.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:c.error}},{children:"*"}))]})),e.jsx(r.default,Object.assign({id:l.id.replace(/[^A-Za-z]+/g,""),value:l.input,placeholder:(null==d?void 0:d["select-an-option"])||"Select an option",closeOnSelect:!1,maxToken:l.maxLength,isDropdown:l.isDropdown},{children:e.jsxs("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[b.map(((s,t)=>e.jsxs("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{p(""),o(Object.assign(Object.assign({},l),{input:e}))})(s)},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:l.input===s?c.accent:c.accent+"80"},l.input===s&&{backgroundColor:c.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",l.input===s&&"opacity-100"),style:{backgroundColor:c.accentText}})})),e.jsx("p",Object.assign({className:a.default(x.b2,"select-none")},{children:s}))]}),t))),l.allowOther&&e.jsxs("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{p(""),o(Object.assign(Object.assign({},l),{input:g})),setTimeout((()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()}),0)}},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:f?c.accent:c.accent+"80"},f&&{backgroundColor:c.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",f&&"opacity-100"),style:{backgroundColor:c.accentText}})})),e.jsxs("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e.jsxs("p",Object.assign({className:a.default(x.b2,"select-none opacity-80 min-w-fit")},{children:[(null==d?void 0:d.other)||"Other",":"]})),e.jsx("input",{ref:j,type:"text",className:a.default(x.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:f?c.accent:"rgba(0,0,0,0.2)"},value:g,onChange:e=>{return s=e.target.value,p(""),m(s),void o(Object.assign(Object.assign({},l),{input:s}));var s},onFocus:()=>{f||o(Object.assign(Object.assign({},l),{input:g}))},placeholder:(null==d?void 0:d["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("../../../../hooks/pickaxe/useResponseContext.js"),n=require("../../../../hooks/studio/useStyleFontSize.js"),i=require("react"),r=require("./Dropdown.js"),a=require("../../../../common/cn.js");exports.default=({field:o,update:l})=>{const{colors:c,isRtl:u,translations:d}=s.usePickaxeContext(),{setError:p}=t.useResponseContext(),x=n.useStyleFontSize(),j=i.useRef(null),b=i.useMemo((()=>o.example.split("S3P32X")),[o.example]),[g,m]=i.useState((()=>{const e=b.includes(o.input);return o.allowOther&&o.input&&!e?o.input:""})),f=i.useMemo((()=>!!o.allowOther&&(!b.includes(o.input)&&""!==o.input)),[o.allowOther,o.input,b]);return e.jsxs("div",Object.assign({className:"flex flex-col gap-y-3",dir:u?"rtl":"ltr"},{children:[e.jsxs("div",Object.assign({className:"flex items-center gap-1"},{children:[e.jsx("p",Object.assign({className:a.default(x.b3,"font-semibold opacity-70")},{children:o.main})),o.isRequired&&e.jsx("span",Object.assign({className:"select-none font-semibold",style:{color:c.error}},{children:"*"}))]})),e.jsx(r.default,Object.assign({id:r.getDropdownMenuId(o.id),value:o.input,placeholder:(null==d?void 0:d["select-an-option"])||"Select an option",closeOnSelect:!1,maxToken:o.maxLength,isDropdown:o.isDropdown},{children:e.jsxs("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[b.map(((s,t)=>e.jsxs("div",Object.assign({className:"flex min-w-0 items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{p(""),l(Object.assign(Object.assign({},o),{input:e}))})(s)},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:o.input===s?c.accent:c.accent+"80"},o.input===s&&{backgroundColor:c.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",o.input===s&&"opacity-100"),style:{backgroundColor:c.accentText}})})),e.jsx("p",Object.assign({className:a.default(x.b2,"min-w-0 select-none break-words"),style:{overflowWrap:"anywhere"}},{children:s}))]}),t))),o.allowOther&&e.jsxs("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{p(""),l(Object.assign(Object.assign({},o),{input:g})),setTimeout((()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()}),0)}},{children:[e.jsx("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:f?c.accent:c.accent+"80"},f&&{backgroundColor:c.accent})},{children:e.jsx("div",{className:a.default("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",f&&"opacity-100"),style:{backgroundColor:c.accentText}})})),e.jsxs("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e.jsxs("p",Object.assign({className:a.default(x.b2,"select-none opacity-80 min-w-fit")},{children:[(null==d?void 0:d.other)||"Other",":"]})),e.jsx("input",{ref:j,type:"text",className:a.default(x.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:f?c.accent:"rgba(0,0,0,0.2)"},value:g,onChange:e=>{return s=e.target.value,p(""),m(s),void l(Object.assign(Object.assign({},o),{input:s}));var s},onFocus:()=>{f||l(Object.assign(Object.assign({},o),{input:g}))},placeholder:(null==d?void 0:d["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../Addons/Document/hooks/useDocument.js"),a=require("../../Addons/Scroll/hooks/useScroll.js"),l=require("../../Addons/Artifact/hooks/useArtifactContext.js"),d=require("../../../../common/utils.js"),u=require("@nem035/gpt-3-encoder"),c=require("eventsource-parser"),p=require("../../common/PickaxeBranding.js"),g=require("../../common/PickaxeButton.js"),m=require("../../../../common/error.js"),f=require("../../../../common/validation.js");exports.default=({questions:v,resetQuestions:h})=>{var b;const{origin:x,pickaxeId:j,sender:y,senderType:O,portalId:w,deploymentId:S,pickaxe:C,misc:I,translations:k,isRtl:q,setSessionId:_,setIsNewChat:P,setValidationStatus:A,setValidationUpgradeGroups:E,setValidationUpgradeUrl:N,onGenerateComplete:T}=n.usePickaxeContext(),{token:U}=i.useAuthContext(),{isGenerating:D,setResponse:L,setMessages:R,setStatus:J,setLimitData:V,setError:B,setIsSwitchedToChat:K}=o.useResponseContext(),{documents:W,websiteLink:X,isUploading:F,onWebsiteUpload:G,setDocuments:M,setDocumentError:$}=r.useDocument(),{scrollStartSession:z,scrollEndSession:Q,scrollToTarget:Y}=a.useScroll({auto:!(null==C?void 0:C.enablechatresponses)}),{artifacts:H,currentPopupType:Z,setArtifacts:ee,setCurrentArtifact:te}=l.useArtifactContext(),[se,ne]=s.useState(!1),ie=s.useRef(null),oe=e=>{const t=f.getValidationFailure(e);return!!t&&(B(""),V(null),A(t.status),E(t.upgradeGroups),N(t.upgradeUrl),!0)},re=s.useMemo((()=>v.some((e=>("Short Answer"===e.type||"Long Answer"===e.type||"long"===e.type||"short"===e.type||"Checkbox"===e.type||"Knowledge Upload"===e.type||e.id.includes("documentupload"))&&e.input.length>0))),[v]);return t.jsxs("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:q?"rtl":"ltr"},{children:[t.jsxs("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[t.jsx(g.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:F||D||se,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,t,s;try{if(D||F||se)return;B(""),$(""),V(null),L(null);const n=["Multiple Choice","Checkbox"];for(const e of v){if(u.encode(e.input).length>e.maxLength&&!n.includes(e.type))throw new Error((null==k?void 0:k["response-too-long"])||"One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error((null==k?void 0:k["required-fields-missing"])||"You must fill out all required fields.")}const i=W.filter((e=>"finished"===e.status)),o=W.map((e=>e.name)),r=null!==(t=null===(e=null==C?void 0:C.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,a=v.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),l=d.extractUrlsFromText(X).filter((e=>!o.includes(e)));if(l.length){const e=l[l.length-1];ne(!0);const t=yield G(e);t&&(i.push(t),yield new Promise((e=>setTimeout(e,5e3)))),ne(!1)}else if(a&&r&&!i.length)return void $((null==k?void 0:k["document-upload-required"])||"Please paste a valid website/video link or drag a file to add to the knowledge base.");const p=i.map((e=>e.documentId||"")).filter(Boolean),g=r&&p.length>0,m={};v.forEach((e=>{m[e.id]="Knowledge Upload"===e.type||e.id.includes("documentupload")?i.map((e=>e.name)).join(",")||"":e.input})),J("fetching"),z(),Y();const f=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,{method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:x,pickaxeId:j,senderType:O,valueObj:m},g&&{documentIds:p}),y&&{sender:y}),U&&{studioSessionToken:U}),!U&&!y&&{sender:d.initializeEmbedUserId()}),w&&{portalId:w}),S&&{deploymentId:S}))}),h=yield f.json();if(!h.success){if(oe(h))return;const e=new Error(h.error||h.message||(null==k?void 0:k["failed-to-start-generation"])||"Failed to start generation");throw h.limitData&&(e.limitData=h.limitData),e}if(!h.submissionId||!h.sessionId)throw new Error((null==k?void 0:k["failed-to-start-generation"])||"Failed to start generation");const b=h.submissionId,I=h.sessionId,q={sessionId:I,documentIds:g?p:[],question:{inputs:v.map((e=>({id:e.id,question:e.main,answer:e.input}))),responseParts:[]},messageCount:0,sentAt:new Date};L(q),(null==C?void 0:C.enablechatresponses)&&(_(I),P(!1),K(!0),R([{id:0,role:"assistant",parts:[],documentIds:[]}])),g&&M([]),J("streaming"),ie.current=new AbortController;const A=[];let E=[...null!=H?H:[]],N=0,Q=!1,re="";for(;!Q;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${N}`,{signal:null===(s=ie.current)||void 0===s?void 0:s.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader(),n=new TextDecoder,i=c.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&N++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==k?void 0:k["something-went-wrong"])||"Something went wrong.";return oe(t)||B(s),void(Q=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("text-start"===n.type)re="",A.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)re+=n.delta,A[A.length-1].content=re;else if("text-end"===n.type)re="";else if("reasoning-start"===n.type)re="",A.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)re+=n.delta,A[A.length-1].content=re;else if("reasoning-end"===n.type)re="";else if(n.type.startsWith("data-")){const e=n;A.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}const i=Object.assign(Object.assign({},q),{question:Object.assign(Object.assign({},q.question),{responseParts:[...A]})});L(i),(null==C?void 0:C.enablechatresponses)&&R([{id:0,role:"assistant",parts:[...A],documentIds:[]}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);E=E.filter((e=>!(e.id===t.id&&e.version===t.version))),E.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ee([...E]),Z.startsWith("inline")||te({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);E=E.filter((e=>!(e.id===t.id&&e.version===t.version))),E.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),ee([...E]),Z.startsWith("inline")||te({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);E=E.filter((e=>!(e.id===t.id&&e.version===t.version))),E.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ee([...E]),Z.startsWith("inline")||te({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");E=E.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),ee([...E])}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);ee(E.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}}else Q=!0}});for(;;){const{value:e,done:s}=yield t.read();if(s)break;i.feed(n.decode(e))}Q||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("AbortError"===e.name)return void(Q=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==T||T(I)}catch(e){let t=m.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==k?void 0:k["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),oe(t)||B(t),Y()}finally{J("idle"),ne(!1),Q()}}))},{children:se?(null==k?void 0:k.processing)||"Processing...":F?(null==k?void 0:k.uploading)||"Uploading...":D?(null==k?void 0:k.loading)||"Loading...":null!==(b=null==C?void 0:C.submittext)&&void 0!==b?b:"Submit"})),re&&t.jsx(g.default,Object.assign({variant:"transparent-text",className:"min-h-[42px] px-5",isDisabled:F||D||se,onClick:h},{children:(null==k?void 0:k["form.clear-form"])||(null==k?void 0:k["clear-form"])||"Clear form"}))]})),!I.isWhiteLabel&&t.jsx(p.default,{containerClassName:"justify-end"})]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("react"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../../Addons/Auth/hooks/useAuthContext.js"),o=require("../../../../hooks/pickaxe/useResponseContext.js"),r=require("../../Addons/Document/hooks/useDocument.js"),a=require("../../Addons/Scroll/hooks/useScroll.js"),l=require("../../Addons/Artifact/hooks/useArtifactContext.js"),d=require("../../../../common/utils.js"),u=require("@nem035/gpt-3-encoder"),c=require("eventsource-parser"),p=require("../../common/PickaxeBranding.js"),g=require("../../common/PickaxeButton.js"),m=require("../../../../common/error.js"),f=require("../../../../common/validation.js");exports.default=({questions:v,resetQuestions:h})=>{var b;const{origin:x,pickaxeId:j,sender:y,senderType:O,portalId:w,deploymentId:S,pickaxe:C,misc:I,translations:k,isRtl:q,setSessionId:_,setIsNewChat:E,setValidationStatus:P,setValidationUpgradeGroups:A,setValidationUpgradeUrl:N,setAccessGroup:T,onGenerateComplete:D}=i.usePickaxeContext(),{token:U}=n.useAuthContext(),{isGenerating:L,setResponse:R,setMessages:B,setStatus:J,setLimitData:V,setError:K,setIsSwitchedToChat:W}=o.useResponseContext(),{documents:X,websiteLink:G,isUploading:F,onWebsiteUpload:M,setDocuments:$,setDocumentError:z}=r.useDocument(),{scrollStartSession:Q,scrollEndSession:Y,scrollToTarget:H}=a.useScroll({auto:!(null==C?void 0:C.enablechatresponses)}),{artifacts:Z,currentPopupType:ee,setArtifacts:te,setCurrentArtifact:se}=l.useArtifactContext(),[ie,ne]=s.useState(!1),oe=s.useRef(null),re=e=>{const t=f.getValidationFailure(e);return!!t&&(K(""),V(null),P(t.status),T(t.accessGroup),A(t.upgradeGroups),N(t.upgradeUrl),!0)},ae=s.useMemo((()=>v.some((e=>("Short Answer"===e.type||"Long Answer"===e.type||"long"===e.type||"short"===e.type||"Checkbox"===e.type||"Knowledge Upload"===e.type||e.id.includes("documentupload"))&&e.input.length>0))),[v]);return t.jsxs("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:q?"rtl":"ltr"},{children:[t.jsxs("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[t.jsx(g.default,Object.assign({className:"px-5 min-h-[42px]",isDisabled:F||L||ie,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,t,s;try{if(L||F||ie)return;K(""),z(""),V(null),R(null);const i=["Multiple Choice","Checkbox"];for(const e of v){if(u.encode(e.input).length>e.maxLength&&!i.includes(e.type))throw new Error((null==k?void 0:k["response-too-long"])||"One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error((null==k?void 0:k["required-fields-missing"])||"You must fill out all required fields.")}const n=X.filter((e=>"finished"===e.status)),o=X.map((e=>e.name)),r=null!==(t=null===(e=null==C?void 0:C.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,a=v.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),l=d.extractUrlsFromText(G).filter((e=>!o.includes(e)));if(l.length){const e=l[l.length-1];ne(!0);const t=yield M(e);t&&(n.push(t),yield new Promise((e=>setTimeout(e,5e3)))),ne(!1)}else if(a&&r&&!n.length)return void z((null==k?void 0:k["document-upload-required"])||"Please paste a valid website/video link or drag a file to add to the knowledge base.");const p=n.map((e=>e.documentId||"")).filter(Boolean),g=r&&p.length>0,m={};v.forEach((e=>{m[e.id]="Knowledge Upload"===e.type||e.id.includes("documentupload")?n.map((e=>e.name)).join(",")||"":e.input})),J("fetching"),Q(),H();const f=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,{method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:x,pickaxeId:j,senderType:O,valueObj:m},g&&{documentIds:p}),y&&{sender:y}),U&&{studioSessionToken:U}),!U&&!y&&{sender:d.initializeEmbedUserId()}),w&&{portalId:w}),S&&{deploymentId:S}))}),h=yield f.json();if(!h.success){const e=new Error(h.error||h.message||(null==k?void 0:k["failed-to-start-generation"])||"Failed to start generation");if(h.limitData)throw e.limitData=h.limitData,e;if(re(h))return;throw e}if(!h.submissionId||!h.sessionId)throw new Error((null==k?void 0:k["failed-to-start-generation"])||"Failed to start generation");const b=h.submissionId,I=h.sessionId,q={sessionId:I,documentIds:g?p:[],question:{inputs:v.map((e=>({id:e.id,question:e.main,answer:e.input}))),responseParts:[]},messageCount:0,sentAt:new Date};R(q),(null==C?void 0:C.enablechatresponses)&&(_(I),E(!1),W(!0),B([{id:0,role:"assistant",parts:[],documentIds:[]}])),g&&$([]),J("streaming"),oe.current=new AbortController;const P=[];let A=[...null!=Z?Z:[]],N=0,T=!1,Y="";for(;!T;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${N}`,{signal:null===(s=oe.current)||void 0===s?void 0:s.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader(),i=new TextDecoder,n=c.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&N++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return V(t.limitData),K(""),void(T=!0);const s=t.error||t.message||(null==k?void 0:k["something-went-wrong"])||"Something went wrong.";return re(t)||K(s),void(T=!0)}if("delta"===e.event){const i=JSON.parse(e.data);if("text-start"===i.type)Y="",P.push({type:"text",content:"",isVisible:null===(t=i.isVisible)||void 0===t||t});else if("text-delta"===i.type)Y+=i.delta,P[P.length-1].content=Y;else if("text-end"===i.type)Y="";else if("reasoning-start"===i.type)Y="",P.push({type:"reasoning",content:"",isVisible:null===(s=i.isVisible)||void 0===s||s});else if("reasoning-delta"===i.type)Y+=i.delta,P[P.length-1].content=Y;else if("reasoning-end"===i.type)Y="";else if(i.type.startsWith("data-")){const e=i;P.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}const n=Object.assign(Object.assign({},q),{question:Object.assign(Object.assign({},q.question),{responseParts:[...P]})});R(n),(null==C?void 0:C.enablechatresponses)&&B([{id:0,role:"assistant",parts:[...P],documentIds:[]}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),te([...A]),ee.startsWith("inline")||se({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),te([...A]),ee.startsWith("inline")||se({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),te([...A]),ee.startsWith("inline")||se({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");A=A.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),te([...A])}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);te(A.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}}else T=!0}});for(;;){const{value:e,done:s}=yield t.read();if(s)break;n.feed(i.decode(e))}T||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if(e instanceof Error&&"AbortError"===e.name)return void(T=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==D||D(I)}catch(e){if((e=>e instanceof Error&&Boolean(e.limitData))(e))return V(e.limitData),K(""),void H();let t=m.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==k?void 0:k["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),re(t)||K(t),H()}finally{J("idle"),ne(!1),Y()}}))},{children:ie?(null==k?void 0:k.processing)||"Processing...":F?(null==k?void 0:k.uploading)||"Uploading...":L?(null==k?void 0:k.loading)||"Loading...":null!==(b=null==C?void 0:C.submittext)&&void 0!==b?b:"Submit"})),ae&&t.jsx(g.default,Object.assign({variant:"transparent-text",className:"min-h-[42px] px-5",isDisabled:F||L||ie,onClick:h},{children:(null==k?void 0:k["form.clear-form"])||(null==k?void 0:k["clear-form"])||"Clear form"}))]})),!I.isWhiteLabel&&t.jsx(p.default,{containerClassName:"justify-end"})]}))};
@@ -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("framer-motion"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),l=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../common/utils.js"),n=require("../../Icons/circle-exclamation.svg.js"),c=require("../../Core/SpringTransition.js"),d=require("../../Core/HtmlRenderer.js"),u=require("./PickaxeButton.js"),p=require("../../../common/cn.js"),x=require("../../../common/api/pickaxe.js"),m=require("../Addons/Auth/hooks/useAuthContext.js"),v=require("./AccessGroupCardPreview.js"),f=require("../../../hooks/studio/useStudio.js"),b=require("./PickaxeCurrency.js");const g=({price:e,uses:t,isCredits:i,isSelected:r,costPerRun:o,onClick:l,colors:a,currencySymbol:n})=>{const c=`${n}${e}`,d={backgroundColor:a.secondary,color:a.secondaryText,borderColor:r?a.secondaryText:"rgba(0,0,0,0.1)"},u=i&&o?Math.ceil(t/o):0;return i?s.jsxs("button",Object.assign({onClick:l,className:p.default("flex min-w-[200px] shrink-0 cursor-pointer flex-col rounded-[16px] px-6 py-5 text-left transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:d},{children:[s.jsxs("div",Object.assign({className:"mb-4 flex items-center gap-2"},{children:[s.jsx("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:c})),s.jsxs("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," credits"]}))]})),s.jsx("div",{className:"mb-4 h-[1px] w-full",style:{backgroundColor:a.secondaryText,opacity:.15}}),s.jsxs("span",Object.assign({className:"text-[14px] italic opacity-70"},{children:["~ ",void 0!==u&&u>0?u.toLocaleString():"..."," ","runs"]}))]})):s.jsxs("button",Object.assign({onClick:l,className:p.default("flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-[16px] px-5 py-3 transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:d},{children:[s.jsx("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:c})),s.jsxs("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," uses"]}))]}))},j=(e,s)=>{var t,i;const r=Number(s?null!==(t=e.credits)&&void 0!==t?t:e.uses:null!==(i=e.uses)&&void 0!==i?i:e.credits);return Number.isFinite(r)?r:0},h=e=>{const s=Number(e.price);return Number.isFinite(s)?s:0};exports.default=({className:y,iconClassName:k,htmlClassName:w})=>{var C,N,O;const{colors:S,pickaxe:_,sender:q,translations:U,setValidationStatus:I,setClientSecret:A,setStripeAccountId:P}=r.usePickaxeContext(),{token:R,setRedirectUrl:L}=m.useAuthContext(),{limitData:G}=o.useResponseContext(),{studio:T}=f.useStudio(),F=l.useStyleFontSize(),[B,M]=t.useState(0),[E,$]=t.useState(null),z=null==T?void 0:T.data,D=null==z?void 0:z.usage,H=Boolean(null==D?void 0:D.isCredits),V=null!==(N=null===(C=b.currencyOptions.find((e=>e.id===(null==z?void 0:z.currency))))||void 0===C?void 0:C.symbol)&&void 0!==N?N:b.currencyOptions[0].symbol,J=t.useMemo((()=>{const e=H?null==D?void 0:D.availableCredits:null==D?void 0:D.availableUses;if(Array.isArray(e)&&e.length>0)return e;const s=null==G?void 0:G.buyUses;return Array.isArray(s)?s:[]}),[H,null==G?void 0:G.buyUses,null==D?void 0:D.availableCredits,null==D?void 0:D.availableUses]);t.useEffect((()=>{M(0)}),[J]);const K=J.length>0,Q=K?J[B]:void 0,W=Q?j(Q,H):0,X=Q?h(Q):0;t.useEffect((()=>{let s=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){if(null==z?void 0:z.workspaceId)try{const e=yield x.default.get(`/cost_per_run?workspaceId=${z.workspaceId}`,{withCredentials:!1});if(s){const s=1e4*e.data.costPerRun||0;$(s)}}catch(e){console.error("Failed to fetch cost per run:",e),s&&$(0)}else $(0)})),()=>{s=!1}}),[null==z?void 0:z.workspaceId,$]);const Y=null==G?void 0:G.customLink,Z=null==G?void 0:G.limitCTA,ee=Array.isArray(null==G?void 0:G.upgradeGroups)&&(null==G?void 0:G.upgradeGroups)&&(null==G?void 0:G.upgradeGroups.length)>0;return G?s.jsx(i.AnimatePresence,{children:s.jsxs(c.default,Object.assign({className:p.default("flex flex-col gap-5 w-full",y)},{children:[s.jsxs("div",Object.assign({className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between rounded-lg p-3 bg-opacity-5",style:{backgroundColor:S.secondary}},{children:[s.jsxs("div",Object.assign({className:"flex gap-3 items-start"},{children:[s.jsx(n.default,{className:p.default("h-5 w-5 shrink-0 mt-0.5",k),style:{color:S.accent}}),s.jsx(d.default,{className:p.default(F.b2,"font-semibold leading-relaxed text-sm",w),style:{color:S.text},html:G.limitMessage||""})]})),Y&&s.jsx(u.default,Object.assign({variant:"primary",className:"whitespace-nowrap min-h-[32px] w-full sm:w-auto text-sm",onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(a.isInIframe()){if(!R)return L(Y||null),void I("login_required");window.open(Y)}else{const e=a.buildUpgradeUrl({baseUrl:Y,redirectUrl:document.URL});e&&(window.location.href=e)}}))},{children:Z}))]})),ee&&s.jsxs("div",Object.assign({className:"flex flex-col gap-2"},{children:[s.jsx("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:S.text}},{children:(null==U?void 0:U["available-plans"])||"Available Plans"})),s.jsx("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-4 pt-1 snap-x scrollbar-thin"},{children:null===(O=G.upgradeGroups)||void 0===O?void 0:O.map(((e,t)=>s.jsx(v.default,{data:e},e.accessGroupId||t)))}))]})),K&&Q&&s.jsxs("div",Object.assign({className:"flex flex-col gap-3"},{children:[s.jsxs("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:S.text}},{children:[(null==U?void 0:U.buy)||"Buy"," ",H?(null==U?void 0:U.credits)||"Credits":(null==U?void 0:U.uses)||"Uses"]})),s.jsx("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-2 pt-1 snap-x scrollbar-thin"},{children:J.map(((e,t)=>s.jsx(g,{price:h(e),uses:j(e,H),isCredits:H,costPerRun:E||void 0,isSelected:t===B,onClick:()=>M(t),colors:S,currencySymbol:V},t)))})),s.jsxs(u.default,Object.assign({variant:"primary",className:"w-full py-3 text-sm font-bold shadow-md",onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(R){var s,t;s=W,t=X,e.__awaiter(void 0,void 0,void 0,(function*(){try{const e=yield x.default.post("/get_extra_usage_payment_link",{data:{sender:q||void 0,studioSessionToken:R,studioId:null==_?void 0:_.studioid,cost:t,isEmbed:a.isInIframe(),extraUses:s,successUrl:document.URL}}),{success:i,url:r,clientSecret:o,stripeAccountId:l,error:n}=e.data;i?a.isInIframe()?o&&l?(P(l),A(o),I("stripe_checkout")):r&&window.open(r,"_blank"):r&&(window.location.href=r):alert(n)}catch(e){alert(e)}}))}else{const e=G.limitLink||Y;if(a.isInIframe())L(e||null),I("login_required");else{const s=a.buildUpgradeUrl({baseUrl:e,redirectUrl:document.URL});s&&(window.location.href=s)}}}))},{children:[(null==U?void 0:U.buy)||"Buy"," ",W.toLocaleString()," ",H?(null==U?void 0:U.credits)||"Credits":(null==U?void 0:U.uses)||"Uses"," ","for ",V,X]}))]}))]}))}):null};
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("framer-motion"),r=require("../../../hooks/pickaxe/usePickaxeContext.js"),o=require("../../../hooks/pickaxe/useResponseContext.js"),l=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../common/utils.js"),n=require("../../Icons/circle-exclamation.svg.js"),c=require("../../Core/SpringTransition.js"),d=require("../../Core/HtmlRenderer.js"),u=require("./PickaxeButton.js"),p=require("../../../common/cn.js"),x=require("../../../common/api/pickaxe.js"),m=require("../Addons/Auth/hooks/useAuthContext.js"),v=require("./AccessGroupCardPreview.js"),f=require("../../../hooks/studio/useStudio.js"),b=require("./PickaxeCurrency.js");const g=({price:e,uses:t,isCredits:i,isSelected:r,costPerRun:o,onClick:l,colors:a,currencySymbol:n})=>{const c=`${n}${e}`,d={backgroundColor:a.secondary,color:a.secondaryText,borderColor:r?a.secondaryText:"rgba(0,0,0,0.1)"},u=i&&o?Math.ceil(t/o):0;return i?s.jsxs("button",Object.assign({onClick:l,className:p.default("flex min-w-[200px] shrink-0 cursor-pointer flex-col rounded-[16px] px-6 py-5 text-left transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:d},{children:[s.jsxs("div",Object.assign({className:"mb-4 flex items-center gap-2"},{children:[s.jsx("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:c})),s.jsxs("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," credits"]}))]})),s.jsx("div",{className:"mb-4 h-[1px] w-full",style:{backgroundColor:a.secondaryText,opacity:.15}}),s.jsxs("span",Object.assign({className:"text-[14px] italic opacity-70"},{children:["~ ",void 0!==u&&u>0?u.toLocaleString():"..."," ","runs"]}))]})):s.jsxs("button",Object.assign({onClick:l,className:p.default("flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-[16px] px-5 py-3 transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:d},{children:[s.jsx("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:c})),s.jsxs("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," uses"]}))]}))},j=(e,s)=>{var t,i;const r=Number(s?null!==(t=e.credits)&&void 0!==t?t:e.uses:null!==(i=e.uses)&&void 0!==i?i:e.credits);return Number.isFinite(r)?r:0},y=e=>{const s=Number(e.price);return Number.isFinite(s)?s:0};exports.default=({className:h,iconClassName:k,htmlClassName:w})=>{var C,N,O,S;const{colors:_,pickaxe:q,sender:A,translations:U,setValidationStatus:I,setClientSecret:P,setStripeAccountId:L}=r.usePickaxeContext(),{token:R,setRedirectUrl:G}=m.useAuthContext(),{limitData:T}=o.useResponseContext(),{studio:F}=f.useStudio(),B=l.useStyleFontSize(),[M,E]=t.useState(0),[$,z]=t.useState(null),D=null==F?void 0:F.data,H=null==D?void 0:D.usage,V=Boolean(null==H?void 0:H.isCredits),J=null!==(N=null===(C=b.currencyOptions.find((e=>e.id===(null==D?void 0:D.currency))))||void 0===C?void 0:C.symbol)&&void 0!==N?N:b.currencyOptions[0].symbol,K="string"==typeof(null==T?void 0:T.customLink)?T.customLink.trim():"",Q=t.useMemo((()=>{if(K)return[];const e=V?null==H?void 0:H.availableCredits:null==H?void 0:H.availableUses;if(Array.isArray(e)&&e.length>0)return e;const s=null==T?void 0:T.buyUses;return Array.isArray(s)?s:[]}),[K,V,null==T?void 0:T.buyUses,null==H?void 0:H.availableCredits,null==H?void 0:H.availableUses]);t.useEffect((()=>{E(0)}),[Q]);const W=Q.length>0,X=W?Q[M]:void 0,Y=X?j(X,V):0,Z=X?y(X):0;t.useEffect((()=>{let s=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){if(K)z(null);else if(null==D?void 0:D.workspaceId)try{const e=yield x.default.get(`/cost_per_run?workspaceId=${D.workspaceId}`,{withCredentials:!1});if(s){const s=1e4*e.data.costPerRun||0;z(s)}}catch(e){console.error("Failed to fetch cost per run:",e),s&&z(0)}else z(0)})),()=>{s=!1}}),[K,null==D?void 0:D.workspaceId,z]);const ee=K,se=(null===(O=null==T?void 0:T.limitCTA)||void 0===O?void 0:O.trim())||(null==U?void 0:U["pricing.upgrade"])||(null==U?void 0:U.upgrade)||"Upgrade",te=!K&&Array.isArray(null==T?void 0:T.upgradeGroups)&&(null==T?void 0:T.upgradeGroups)&&(null==T?void 0:T.upgradeGroups.length)>0;return T?s.jsx(i.AnimatePresence,{children:s.jsxs(c.default,Object.assign({className:p.default("flex flex-col gap-5 w-full",h)},{children:[s.jsxs("div",Object.assign({className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between rounded-lg p-3 bg-opacity-5",style:{backgroundColor:_.secondary}},{children:[s.jsxs("div",Object.assign({className:"flex gap-3 items-start"},{children:[s.jsx(n.default,{className:p.default("h-5 w-5 shrink-0 mt-0.5",k),style:{color:_.accent}}),s.jsx(d.default,{className:p.default(B.b2,"font-semibold leading-relaxed text-sm",w),style:{color:_.text},html:T.limitMessage||""})]})),ee&&s.jsx(u.default,Object.assign({variant:"primary",className:"whitespace-nowrap min-h-[32px] w-full sm:w-auto text-sm",onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){window.open(ee,"_blank","noopener,noreferrer")}))},{children:se}))]})),te&&s.jsxs("div",Object.assign({className:"flex flex-col gap-2"},{children:[s.jsx("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:_.text}},{children:(null==U?void 0:U["available-plans"])||"Available Plans"})),s.jsx("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-4 pt-1 snap-x scrollbar-thin"},{children:null===(S=T.upgradeGroups)||void 0===S?void 0:S.map(((e,t)=>s.jsx(v.default,{data:e},e.accessGroupId||t)))}))]})),W&&X&&s.jsxs("div",Object.assign({className:"flex flex-col gap-3"},{children:[s.jsxs("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:_.text}},{children:[(null==U?void 0:U.buy)||"Buy"," ",V?(null==U?void 0:U.credits)||"Credits":(null==U?void 0:U.uses)||"Uses"]})),s.jsx("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-2 pt-1 snap-x scrollbar-thin"},{children:Q.map(((e,t)=>s.jsx(g,{price:y(e),uses:j(e,V),isCredits:V,costPerRun:$||void 0,isSelected:t===M,onClick:()=>E(t),colors:_,currencySymbol:J},t)))})),s.jsxs(u.default,Object.assign({variant:"primary",className:"w-full py-3 text-sm font-bold shadow-md",onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(R){var s,t;s=Y,t=Z,e.__awaiter(void 0,void 0,void 0,(function*(){try{const e=yield x.default.post("/get_extra_usage_payment_link",{data:{sender:A||void 0,studioSessionToken:R,studioId:null==q?void 0:q.studioid,cost:t,isEmbed:a.isInIframe(),extraUses:s,successUrl:document.URL}}),{success:i,url:r,clientSecret:o,stripeAccountId:l,error:n}=e.data;i?a.isInIframe()?o&&l?(L(l),P(o),I("stripe_checkout")):r&&window.open(r,"_blank"):r&&(window.location.href=r):alert(n)}catch(e){alert(e)}}))}else{const e=T.limitLink||ee;if(a.isInIframe())G(e||null),I("login_required");else{const s=a.buildUpgradeUrl({baseUrl:e,redirectUrl:document.URL});s&&(window.location.href=s)}}}))},{children:[(null==U?void 0:U.buy)||"Buy"," ",Y.toLocaleString()," ",V?(null==U?void 0:U.credits)||"Credits":(null==U?void 0:U.uses)||"Uses"," ","for ",J,Z]}))]}))]}))}):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("../../hooks/pickaxe/usePickaxe.js"),a=require("react"),i=require("../../hooks/pickaxe/usePickaxeContext.js"),r=require("./Addons/Auth/hooks/useAuthContext.js"),o=require("./Addons/Auth/hooks/useAuthBootstrap.js"),l=require("../../hooks/pickaxe/useResponseContext.js"),c=require("./Addons/Document/hooks/useDocumentContext.js"),n=require("./Addons/Artifact/hooks/useArtifactContext.js"),d=require("uuid"),u=require("./Addons/Scroll/Provider.js"),x=require("./common/PickaxeSkeleton.js"),p=require("./Chat/index.js"),m=require("./Form/index.js"),f=require("./Addons/Auth/index.js"),j=require("../../common/cn.js"),h=require("../../common/api/pickaxe.js"),v=require("../../common/validation.js"),g=require("./common/AccessGroupCardPreview.js"),b=require("./common/PickaxeAvatar.js"),k=require("../Icons/lock.svg.js"),w=require("../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js"),y=require("../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js");const N=({className:e})=>s.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s.jsx("polyline",{points:"15 18 9 12 15 6"})}));exports.Pickaxe=({pickaxeId:q,className:O})=>{const{sessionId:_,styles:A,colors:C,responsiveBy:I,deploymentType:S,isNewChat:P,isEmbed:E,opacity:U,deploymentId:G,sender:R,portalId:T,validationStatus:L,validationUpgradeGroups:B,validationUpgradeUrl:D,stripeAccountId:F,clientSecret:M,translations:V,preventInitialSessionId:$,setClientSecret:W,setStripeAccountId:z,setValidationStatus:H,setValidationUpgradeGroups:J,setValidationUpgradeUrl:K,setContextId:X,setPickaxeId:Y,setSessionId:Q,setPickaxe:Z,setAccessGroup:ee}=i.usePickaxeContext(),{isSent:se,token:te,isAuthBootstrapComplete:ae}=r.useAuthContext(),{setMessages:ie,setResponse:re,setError:oe,setLimitData:le,setIsSwitchedToChat:ce}=l.useResponseContext(),{setDocumentError:ne}=c.useDocumentContext(),{setCurrentArtifact:de}=n.useArtifactContext(),[ue,xe]=a.useState(!1),pe=t.usePickaxe();o.useAuthBootstrap();const me="chat-input"===S&&P&&!se,fe=a.useMemo((()=>F?y.loadStripe(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:F}):null),[F]);a.useEffect((()=>{Y(q)}),[q]);a.useEffect((()=>{if(!G&&!T||!pe.data)return;if(!ae)return;if("stripe_checkout"===L)return;e.__awaiter(void 0,void 0,void 0,(function*(){var e;H("loading");try{const s=yield h.default.post("/validate_studio_deployment",{data:{deploymentId:G,sender:R||void 0,studioSessionToken:te,portalId:T,studioId:null===(e=pe.data)||void 0===e?void 0:e.studioid}});if(s.data.success)H("success"),J([]),K(null),ee(s.data.accessGroup);else{const e=v.getValidationFailure(s.data);if(!e)return H("login_required"),J([]),void K(null);H(e.status),J(e.upgradeGroups),K(e.upgradeUrl),xe(!0)}}catch(e){console.error("Failed to validate deployment:",e),H("success")}}))}),[G,ae,R,te,T,pe.data]),a.useEffect((()=>{if(!pe.data)return;const e=pe.data.chatflag;$||Q(e?d.v4():""),X(d.v4()),e?ie([]):re(null),oe(""),ne(""),le(null),de(null),ce(!1),Z(pe.data),xe(!0)}),[pe.data]),a.useEffect((()=>{oe(""),ne(""),le(null),ie([]),re(null),de(null)}),[_]);const je=a.useMemo((()=>{const e=null!=U?U:1;if(!C.primary||!C.primary.startsWith("#")||e<0||e>1)return C.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${C.primary}${s}`}),[C.primary,U]);if(!pe.data)return null;return s.jsx("div",Object.assign({className:j.default("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===A.theme&&"dark",O),style:Object.assign({backgroundColor:me?"transparent":je,color:C.text},A.font&&"Real Head Pro"!==A.font&&{fontFamily:A.font})},{children:(()=>{var t,a;if("stripe_checkout"===L&&M&&fe)return s.jsxs("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:C.secondary||"#ffffff",color:C.secondaryText||"#000000"}},{children:[s.jsx("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:s.jsxs("button",Object.assign({onClick:()=>{W&&W(null),z&&z(null),H("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:C.text}},{children:[s.jsx(N,{className:"w-5 h-5"}),s.jsx("span",{children:(null==V?void 0:V.back)||"Back"})]}))})),s.jsx("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s.jsx(w.EmbeddedCheckoutProvider,Object.assign({stripe:fe,options:{clientSecret:M}},{children:s.jsx(w.EmbeddedCheckout,{})}))}))]}));if(pe.isLoading||!ue||"loading"===L)return s.jsx("div",Object.assign({className:j.default("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===I?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:s.jsxs("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s.jsx(x.default,{className:"w-[72px] h-[72px]"}),s.jsx(x.default,{className:"h-[20px] mt-6 w-full"}),s.jsx(x.default,{className:"h-[20px] mt-2 w-full"}),s.jsx(x.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s.jsx("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s.jsx(x.default,{className:j.default("w-full min-h-[48px]","viewport"===I?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===L){const e=B.length>0;return s.jsx("div",Object.assign({className:"flex h-full min-h-0 w-full items-start justify-center overflow-y-auto p-4"},{children:e?s.jsxs("div",Object.assign({className:"flex w-full max-w-4xl flex-col items-center gap-6 py-6"},{children:[s.jsxs("div",Object.assign({className:"max-w-[640px] text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2 break-words"},{children:(null==V?void 0:V["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"break-words opacity-80"},{children:(null==V?void 0:V["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s.jsx("div",Object.assign({className:"flex w-full flex-wrap justify-center gap-4"},{children:B.map(((e,t)=>s.jsx(g.default,{data:e,upgradeUrl:D},e.accessGroupId||e.id||t)))}))]})):s.jsxs("div",Object.assign({className:"m-auto text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==V?void 0:V["access-locked"])||"Access Locked"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==V?void 0:V["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===L&&E?s.jsx(f.default,{}):"login_required"!==L||E?"access_denied"===L?s.jsxs("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[s.jsxs(b.Avatar,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s.jsx(b.AvatarImage,{src:null===(t=pe.data)||void 0===t?void 0:t.coverphoto,alt:`${null===(a=pe.data)||void 0===a?void 0:a.formtitle} Logo`}),s.jsx(b.AvatarFallback,{})]})),s.jsxs("div",Object.assign({className:"text-center mb-6"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==V?void 0:V["access-denied"])||"Access Denied"})),s.jsxs("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s.jsx(k.default,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s.jsx("p",Object.assign({className:"ml-1"},{children:(null==V?void 0:V["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s.jsx("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:C.accent,color:C.accentText,borderRadius:A.cornerRadius},onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;const t=B.map((e=>e.accessGroupId));try{const a=yield h.default.post("/request_access",{data:{sender:R||void 0,studioSessionToken:te,studioId:null===(e=pe.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=pe.data)||void 0===s?void 0:s.formid,deploymentId:G,accessGroupIds:t})}});a.data.success?alert((null==V?void 0:V["access-requested-successfully"])||"Successfully requested access!"):alert(a.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==V?void 0:V["request-access"])||"Request Access"})),s.jsx("span",Object.assign({className:"mt-4 mb-2"},{children:(null==V?void 0:V.or)||"or"})),s.jsx("span",Object.assign({className:"font-medium text-lg"},{children:(null==V?void 0:V["sign-in-with-different-account"])||"Sign in with a different account"}))]})):_?s.jsx(u.ScrollProvider,{children:s.jsx(p.default,{})}):s.jsx(u.ScrollProvider,{children:s.jsx(m.default,{})}):s.jsx("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:s.jsxs("div",Object.assign({className:"text-center mb-8"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==V?void 0:V["access-denied"])||"Access Denied"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==V?void 0:V["login-is-required"])||"Login is required."}))]}))}))})()}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("../../hooks/pickaxe/usePickaxe.js"),i=require("react"),a=require("../../hooks/pickaxe/usePickaxeContext.js"),l=require("./Addons/Auth/hooks/useAuthContext.js"),r=require("./Addons/Auth/hooks/useAuthBootstrap.js"),o=require("../../hooks/pickaxe/useResponseContext.js"),n=require("./Addons/Document/hooks/useDocumentContext.js"),c=require("./Addons/Artifact/hooks/useArtifactContext.js"),d=require("uuid"),u=require("./Addons/Scroll/Provider.js"),p=require("./common/PickaxeSkeleton.js"),x=require("./Chat/index.js"),m=require("./Form/index.js"),f=require("./Addons/Auth/index.js"),j=require("../../common/cn.js"),g=require("../../common/api/pickaxe.js"),h=require("../../common/validation.js"),v=require("./common/AccessGroupCardPreview.js"),b=require("./common/PickaxeButton.js"),k=require("./common/PickaxeAvatar.js"),y=require("../Icons/lock.svg.js"),w=require("../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js"),N=require("../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js");const q=({className:e})=>s.jsx("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s.jsx("polyline",{points:"15 18 9 12 15 6"})}));exports.Pickaxe=({pickaxeId:O,className:A})=>{const{sessionId:C,styles:_,colors:I,responsiveBy:S,deploymentType:P,isNewChat:E,isEmbed:L,opacity:T,deploymentId:U,sender:G,portalId:R,validationStatus:B,validationUpgradeGroups:M,validationUpgradeUrl:D,accessGroup:F,stripeAccountId:V,clientSecret:$,translations:W,preventInitialSessionId:z,setClientSecret:H,setStripeAccountId:J,setValidationStatus:K,setValidationUpgradeGroups:X,setValidationUpgradeUrl:Y,setContextId:Q,setPickaxeId:Z,setSessionId:ee,setPickaxe:se,setAccessGroup:te}=a.usePickaxeContext(),{isSent:ie,token:ae,isAuthBootstrapComplete:le}=l.useAuthContext(),{setMessages:re,setResponse:oe,setError:ne,setLimitData:ce,setIsSwitchedToChat:de}=o.useResponseContext(),{setDocumentError:ue}=n.useDocumentContext(),{setCurrentArtifact:pe}=c.useArtifactContext(),[xe,me]=i.useState(!1),fe=t.usePickaxe();r.useAuthBootstrap();const je="chat-input"===P&&E&&!ie,ge=i.useMemo((()=>V?N.loadStripe(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:V}):null),[V]);i.useEffect((()=>{Z(O)}),[O]);i.useEffect((()=>{if(!U&&!R||!fe.data)return;if(!le)return;if("stripe_checkout"===B)return;e.__awaiter(void 0,void 0,void 0,(function*(){var e;K("loading");try{const s=yield g.default.post("/validate_studio_deployment",{data:{deploymentId:U,sender:G||void 0,studioSessionToken:ae,portalId:R,studioId:null===(e=fe.data)||void 0===e?void 0:e.studioid}});if(s.data.success)K("success"),X([]),Y(null),te(s.data.accessGroup);else{const e=h.getValidationFailure(s.data);if(!e)return K("login_required"),X([]),void Y(null);K(e.status),te(e.accessGroup),X(e.upgradeGroups),Y(e.upgradeUrl),me(!0)}}catch(e){console.error("Failed to validate deployment:",e),K("success")}}))}),[U,le,G,ae,R,fe.data]),i.useEffect((()=>{if(!fe.data)return;const e=fe.data.chatflag;z||ee(e?d.v4():""),Q(d.v4()),e?re([]):oe(null),ne(""),ue(""),ce(null),pe(null),de(!1),se(fe.data),me(!0)}),[fe.data]),i.useEffect((()=>{ne(""),ue(""),ce(null),re([]),oe(null),pe(null)}),[C]);const he=i.useMemo((()=>{const e=null!=T?T:1;if(!I.primary||!I.primary.startsWith("#")||e<0||e>1)return I.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${I.primary}${s}`}),[I.primary,T]);if(!fe.data)return null;return s.jsx("div",Object.assign({className:j.default("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===_.theme&&"dark",A),style:Object.assign({backgroundColor:je?"transparent":he,color:I.text},_.font&&"Real Head Pro"!==_.font&&{fontFamily:_.font})},{children:(()=>{var t,i,a,l,r;if("stripe_checkout"===B&&$&&ge)return s.jsxs("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:I.secondary||"#ffffff",color:I.secondaryText||"#000000"}},{children:[s.jsx("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:s.jsxs("button",Object.assign({onClick:()=>{H&&H(null),J&&J(null),K("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:I.text}},{children:[s.jsx(q,{className:"w-5 h-5"}),s.jsx("span",{children:(null==W?void 0:W.back)||"Back"})]}))})),s.jsx("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s.jsx(w.EmbeddedCheckoutProvider,Object.assign({stripe:ge,options:{clientSecret:$}},{children:s.jsx(w.EmbeddedCheckout,{})}))}))]}));if(fe.isLoading||!xe||"loading"===B)return s.jsx("div",Object.assign({className:j.default("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===S?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:s.jsxs("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s.jsx(p.default,{className:"w-[72px] h-[72px]"}),s.jsx(p.default,{className:"h-[20px] mt-6 w-full"}),s.jsx(p.default,{className:"h-[20px] mt-2 w-full"}),s.jsx(p.default,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s.jsx("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s.jsx(p.default,{className:j.default("w-full min-h-[48px]","viewport"===S?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===B){const e=M.length>0,l=(null===(t=null==F?void 0:F.upgrade)||void 0===t?void 0:t.isLinkToCustomURL)&&"string"==typeof F.upgrade.limitLink&&F.upgrade.limitLink.trim().length>0?F.upgrade.limitLink.trim():null,r="string"==typeof(null===(i=null==F?void 0:F.upgrade)||void 0===i?void 0:i.limitMessage)&&F.upgrade.limitMessage.trim().length>0?F.upgrade.limitMessage:(null==W?void 0:W["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool.",o="string"==typeof(null===(a=null==F?void 0:F.upgrade)||void 0===a?void 0:a.limitCTA)&&F.upgrade.limitCTA.trim().length>0?F.upgrade.limitCTA:(null==W?void 0:W["pricing.upgrade"])||(null==W?void 0:W.upgrade)||"Upgrade";return s.jsx("div",Object.assign({className:"flex h-full min-h-0 w-full items-start justify-center overflow-y-auto p-4"},{children:l?s.jsxs("div",Object.assign({className:"m-auto flex max-w-[640px] flex-col items-center gap-4 text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==W?void 0:W["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:r})),s.jsx(b.default,Object.assign({variant:"primary",className:"min-h-[40px] px-5 text-sm",onClick:()=>{window.open(l,"_blank","noopener,noreferrer")}},{children:o}))]})):e?s.jsxs("div",Object.assign({className:"flex w-full max-w-4xl flex-col items-center gap-6 py-6"},{children:[s.jsxs("div",Object.assign({className:"max-w-[640px] text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2 break-words"},{children:(null==W?void 0:W["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"break-words opacity-80"},{children:(null==W?void 0:W["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s.jsx("div",Object.assign({className:"flex w-full flex-wrap justify-center gap-4"},{children:M.map(((e,t)=>s.jsx(v.default,{data:e,upgradeUrl:D},e.accessGroupId||e.id||t)))}))]})):s.jsxs("div",Object.assign({className:"m-auto flex max-w-[640px] flex-col items-center gap-4 text-center"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==W?void 0:W["access-locked"])||"Access Locked"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==W?void 0:W["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===B&&L?s.jsx(f.default,{}):"login_required"!==B||L?"access_denied"===B?s.jsxs("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[s.jsxs(k.Avatar,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s.jsx(k.AvatarImage,{src:null===(l=fe.data)||void 0===l?void 0:l.coverphoto,alt:`${null===(r=fe.data)||void 0===r?void 0:r.formtitle} Logo`}),s.jsx(k.AvatarFallback,{})]})),s.jsxs("div",Object.assign({className:"text-center mb-6"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==W?void 0:W["access-denied"])||"Access Denied"})),s.jsxs("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s.jsx(y.default,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s.jsx("p",Object.assign({className:"ml-1"},{children:(null==W?void 0:W["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s.jsx("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:I.accent,color:I.accentText,borderRadius:_.cornerRadius},onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;const t=M.map((e=>e.accessGroupId));try{const i=yield g.default.post("/request_access",{data:{sender:G||void 0,studioSessionToken:ae,studioId:null===(e=fe.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=fe.data)||void 0===s?void 0:s.formid,deploymentId:U,accessGroupIds:t})}});i.data.success?alert((null==W?void 0:W["access-requested-successfully"])||"Successfully requested access!"):alert(i.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==W?void 0:W["request-access"])||"Request Access"})),s.jsx("span",Object.assign({className:"mt-4 mb-2"},{children:(null==W?void 0:W.or)||"or"})),s.jsx("span",Object.assign({className:"font-medium text-lg"},{children:(null==W?void 0:W["sign-in-with-different-account"])||"Sign in with a different account"}))]})):C?s.jsx(u.ScrollProvider,{children:s.jsx(x.default,{})}):s.jsx(u.ScrollProvider,{children:s.jsx(m.default,{})}):s.jsx("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:s.jsxs("div",Object.assign({className:"text-center mb-8"},{children:[s.jsx("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==W?void 0:W["access-denied"])||"Access Denied"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==W?void 0:W["login-is-required"])||"Login is required."}))]}))}))})()}))};
@@ -1,6 +1,8 @@
1
+ import type { AccessGroup } from "../components/Pickaxe/Provider";
1
2
  export type PickaxeValidationFailureStatus = "login_required" | "upgrade_required" | "access_denied";
2
3
  export type PickaxeValidationFailure = {
3
4
  status: PickaxeValidationFailureStatus;
5
+ accessGroup: AccessGroup | null;
4
6
  upgradeGroups: any[];
5
7
  upgradeUrl: string | null;
6
8
  };
@@ -10,5 +10,6 @@ interface DropdownProps {
10
10
  maxToken?: number;
11
11
  isDropdown?: boolean;
12
12
  }
13
+ export declare const getDropdownMenuId: (fieldId: string) => string;
13
14
  declare const Dropdown: ({ id, children, placeholder, value, className, style, closeOnSelect, maxToken, isDropdown, }: DropdownProps) => import("react/jsx-runtime").JSX.Element;
14
15
  export default Dropdown;
@@ -59,6 +59,12 @@ export type AccessGroup = {
59
59
  limit: number;
60
60
  accessGroupId: string;
61
61
  limitInterval?: string | null;
62
+ upgrade?: {
63
+ limitMessage?: string | null;
64
+ limitCTA?: string | null;
65
+ limitLink?: string | null;
66
+ isLinkToCustomURL?: boolean;
67
+ } | null;
62
68
  };
63
69
  type PickaxeContextType = {
64
70
  origin: PickaxeHistoryOriginType;
@@ -14,6 +14,7 @@ export interface LimitData {
14
14
  buyUses?: any[];
15
15
  upgradeGroups?: any[];
16
16
  limitLink?: string;
17
+ customLink?: string;
17
18
  accessGroupId?: string;
18
19
  limitCTA?: string;
19
20
  }
@@ -1 +1 @@
1
- import{parse as e}from"tldts";const t="PXE-uid",r=(e,t="",r="")=>{let n="";for(let t=0;t<e;t++){n+="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())]}return t+n+r},n=(e,t=!1)=>{let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";t&&(r=r.replace(/[0-9]/g,""));let n="";for(let t=0;t<e;t++)n+=r.charAt(Math.floor(Math.random()*r.length));return n},o=e=>{const t=e.match(/(https?:\/\/[^\s]+)/g)||[];return Array.from(new Set(t))},l=({baseUrl:e,redirectUrl:t,accessGroupId:r,currentUrl:n})=>{if(!e)return null;const o=null!=n?n:"undefined"!=typeof window?window.location.href:null;if(!o)return null;try{const n=new URL(e,o);if(r){const e=encodeURIComponent(r),t=n.pathname.replace(/\/+$/,"");t.endsWith(`/${e}`)||(n.pathname=`${t}/${e}`)}return t&&n.searchParams.set("redirectUrl",t),n.toString()}catch(e){return console.error("[pxe] failed to build upgrade url",e),null}},c=(e,t=2)=>{if(!+e)return"0 Bytes";const r=t<0?0:t,n=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,n)).toFixed(r))} ${["Bytes","KB","MB","PB","EB"][n]}`},a=e=>{try{const t=document.cookie.split("; ");for(const r of t){const[t,n]=r.split("=");if(t===e)return n}return null}catch(e){return console.error("[pxe] failed to get cookie",e),null}},i=e=>{document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"},u=()=>{try{const r=a(t);if(!r){const r=n(28),o=new Date;o.setFullYear(o.getFullYear()+1);let l=window.location.hostname;const c=e(l).domain;if(c)l=`.${c}`;else{const e=l.split(":")[0],t=e.split(".");l=e,t.length>=2&&(l=`.${t.slice(-2).join(".")}`)}return document.cookie=`${t}=${r};Path=/; Domain=${l}; Expires=${o.toUTCString()}`,r}return r}catch(e){return console.error("[pxe-embed] failed to initialized embed user id",e),n(28)}},s=e=>{try{if("undefined"==typeof window)return null;let t=null;return t=new URLSearchParams(window.location.search).get("pxtoken"),t||(t=localStorage.getItem(`PXE-token-${e}`)),t||(t=a(`PXE-token-${e}`)),t||(t=a(`__Secure-PS-${e}.session-token`)),t?decodeURIComponent(t):null}catch(e){return null}},d=(e,t)=>{try{if("undefined"==typeof window)return;localStorage.setItem(e,t)}catch(e){console.error("[pxe] failed to set auth token",e)}},f=e=>{try{if("undefined"==typeof window)return;localStorage.removeItem(e)}catch(e){console.error("[pxe] failed to delete auth token",e)}};function h(...e){return t=>{for(const r of e)r&&("function"==typeof r?r(t):r.current=t)}}const p=()=>{if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch(e){return!0}},w=e=>{try{return JSON.parse(e)}catch(e){return null}};export{t as COOKIE_USER_ID,l as buildUpgradeUrl,f as deleteAuthToken,i as deleteCookie,o as extractUrlsFromText,c as formatBytes,r as generateId,s as getAuthToken,a as getCookie,u as initializeEmbedUserId,p as isInIframe,h as mergeRefs,n as randomStr,w as safeJSONParse,d as setAuthToken};
1
+ import{parse as e}from"tldts";const t="PXE-uid",r=(e,t="",r="")=>{let n="";for(let t=0;t<e;t++){n+="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())]}return t+n+r},n=(e,t=!1)=>{let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";t&&(r=r.replace(/[0-9]/g,""));let n="";for(let t=0;t<e;t++)n+=r.charAt(Math.floor(Math.random()*r.length));return n},o=e=>{const t=e.match(/(https?:\/\/[^\s]+)/g)||[];return Array.from(new Set(t))},l=({baseUrl:e,redirectUrl:t,accessGroupId:r,currentUrl:n})=>{if(!e)return null;const o=null!=n?n:"undefined"!=typeof window?window.location.href:null;if(!o)return null;try{const n=new URL(e,o);if(r){const e=encodeURIComponent(r),t=n.pathname.replace(/\/+$/,""),o="/ag-pricing",l=t.indexOf(o);if(l>=0){const r=t.slice(0,l+o.length);n.pathname=`${r}/${e}`}else t.endsWith(`/${e}`)||(n.pathname=`${t}/${e}`)}return t&&n.searchParams.set("redirectUrl",t),n.toString()}catch(e){return console.error("[pxe] failed to build upgrade url",e),null}},c=(e,t=2)=>{if(!+e)return"0 Bytes";const r=t<0?0:t,n=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,n)).toFixed(r))} ${["Bytes","KB","MB","PB","EB"][n]}`},i=e=>{try{const t=document.cookie.split("; ");for(const r of t){const[t,n]=r.split("=");if(t===e)return n}return null}catch(e){return console.error("[pxe] failed to get cookie",e),null}},a=e=>{document.cookie=e+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"},u=()=>{try{const r=i(t);if(!r){const r=n(28),o=new Date;o.setFullYear(o.getFullYear()+1);let l=window.location.hostname;const c=e(l).domain;if(c)l=`.${c}`;else{const e=l.split(":")[0],t=e.split(".");l=e,t.length>=2&&(l=`.${t.slice(-2).join(".")}`)}return document.cookie=`${t}=${r};Path=/; Domain=${l}; Expires=${o.toUTCString()}`,r}return r}catch(e){return console.error("[pxe-embed] failed to initialized embed user id",e),n(28)}},s=e=>{try{if("undefined"==typeof window)return null;let t=null;return t=new URLSearchParams(window.location.search).get("pxtoken"),t||(t=localStorage.getItem(`PXE-token-${e}`)),t||(t=i(`PXE-token-${e}`)),t||(t=i(`__Secure-PS-${e}.session-token`)),t?decodeURIComponent(t):null}catch(e){return null}},d=(e,t)=>{try{if("undefined"==typeof window)return;localStorage.setItem(e,t)}catch(e){console.error("[pxe] failed to set auth token",e)}},f=e=>{try{if("undefined"==typeof window)return;localStorage.removeItem(e)}catch(e){console.error("[pxe] failed to delete auth token",e)}};function h(...e){return t=>{for(const r of e)r&&("function"==typeof r?r(t):r.current=t)}}const p=()=>{if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch(e){return!0}},m=e=>{try{return JSON.parse(e)}catch(e){return null}};export{t as COOKIE_USER_ID,l as buildUpgradeUrl,f as deleteAuthToken,a as deleteCookie,o as extractUrlsFromText,c as formatBytes,r as generateId,s as getAuthToken,i as getCookie,u as initializeEmbedUserId,p as isInIframe,h as mergeRefs,n as randomStr,m as safeJSONParse,d as setAuthToken};
@@ -1 +1 @@
1
- const r={"login required":"login_required","upgrade required":"upgrade_required","access denied":"access_denied"},e=e=>{var u;if("string"!=typeof e)return null;const l=e.trim().toLowerCase().replace(/[.!]+$/g,"");return null!==(u=r[l])&&void 0!==u?u:null},u=r=>{var u;if("string"==typeof r){const u=e(r);return u?{status:u,upgradeGroups:[],upgradeUrl:null}:null}if(!r||"object"!=typeof r)return null;const l=r,n=null!==(u=e(l.message))&&void 0!==u?u:e(l.error);return n?{status:n,upgradeGroups:Array.isArray(l.upgradeGroups)?l.upgradeGroups:[],upgradeUrl:"string"==typeof l.upgradeUrl?l.upgradeUrl:null}:null};export{u as getValidationFailure};
1
+ const r={"login required":"login_required","upgrade required":"upgrade_required","access denied":"access_denied"},e=e=>{var u;if("string"!=typeof e)return null;const l=e.trim().toLowerCase().replace(/[.!]+$/g,"");return null!==(u=r[l])&&void 0!==u?u:null},u=r=>{var u;if("string"==typeof r){const u=e(r);return u?{status:u,accessGroup:null,upgradeGroups:[],upgradeUrl:null}:null}if(!r||"object"!=typeof r)return null;const l=r,s=null!==(u=e(l.message))&&void 0!==u?u:e(l.error);return s?{status:s,accessGroup:(n=l.accessGroup,n&&"object"==typeof n?n:null),upgradeGroups:Array.isArray(l.upgradeGroups)?l.upgradeGroups:[],upgradeUrl:"string"==typeof l.upgradeUrl?l.upgradeUrl:null}:null;var n};export{u as getValidationFailure};
@@ -1 +1 @@
1
- import{__rest as e}from"../../../_virtual/_tslib.js";import{jsx as t}from"react/jsx-runtime";import{forwardRef as i,useContext as l}from"react";import{MenuContext as o}from"./index.js";import{Tooltip as r}from"react-tooltip";import a from"../../../common/cn.js";const s=i(((i,s)=>{var{children:n,width:c="200px",fixedWidth:d,maxHeight:m,align:h="bottom-start",style:p,className:b}=i,x=e(i,["children","width","fixedWidth","maxHeight","align","style","className"]);const{id:f,isOpen:g,closeOnSelect:u,openOnClick:O,setIsOpen:j,onChange:w}=l(o);return t("div",{children:t(r,Object.assign({ref:s,anchorSelect:`#${f}`,place:h,style:Object.assign(Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black"},"auto"!==c&&{width:"100%",maxWidth:c}),d&&{width:d,maxWidth:"inherit"}),{borderRadius:"4px"}),p),clickable:!0,noArrow:!0,border:"1px solid rgba(0,0,0,.8)",opacity:1,isOpen:g,setIsOpen:w,openOnClick:O},x,{children:t("div",Object.assign({className:a("flex w-full select-none flex-col overflow-y-auto text-base shadow-lg scrollbar scrollbar-thumb-black/50 scrollbar-thumb-rounded-full scrollbar-w-[4px] scrollbar-h-[4px]",b),style:{maxHeight:m}},u&&{onClick:()=>j(!1)},{children:n}))}))})}));s.displayName="MenuList";export{s as default};
1
+ import{__rest as e}from"../../../_virtual/_tslib.js";import{jsx as i}from"react/jsx-runtime";import{forwardRef as t,useContext as l}from"react";import{MenuContext as o}from"./index.js";import{Tooltip as r}from"react-tooltip";import a from"../../../common/cn.js";const s=e=>`min(${e}, calc(100vw - 48px))`,n=t(((t,n)=>{var{children:c,width:d="200px",fixedWidth:m,maxHeight:b,align:p="bottom-start",style:x,className:h}=t,f=e(t,["children","width","fixedWidth","maxHeight","align","style","className"]);const{id:g,isOpen:u,closeOnSelect:O,openOnClick:w,setIsOpen:j,onChange:y}=l(o);return i("div",{children:i(r,Object.assign({ref:n,anchorSelect:`#${g}`,place:p,positionStrategy:"fixed",style:Object.assign(Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black",boxSizing:"border-box"},"auto"!==d&&{width:"100%",maxWidth:s(d)}),m&&{width:m,maxWidth:s(m)}),{borderRadius:"4px"}),x),clickable:!0,noArrow:!0,border:"1px solid rgba(0,0,0,.8)",opacity:1,isOpen:u,setIsOpen:y,openOnClick:w},f,{children:i("div",Object.assign({className:a("flex w-full select-none flex-col overflow-y-auto text-base shadow-lg scrollbar scrollbar-thumb-black/50 scrollbar-thumb-rounded-full scrollbar-w-[4px] scrollbar-h-[4px]",h),style:{maxHeight:b}},O&&{onClick:()=>j(!1)},{children:c}))}))})}));n.displayName="MenuList";export{n as default};
@@ -1 +1 @@
1
- import{__rest as t}from"../../../_virtual/_tslib.js";import{jsx as e}from"react/jsx-runtime";import{Tooltip as i}from"react-tooltip";const l=l=>{var{selector:r=".menuOverflow",align:o="bottom-start",width:a="200px",style:c,children:n,clickable:s=!1}=l,d=t(l,["selector","align","width","style","children","clickable"]);return e(i,Object.assign({anchorSelect:r,place:o,style:Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black"},"auto"!==a&&{width:"100%",maxWidth:a}),{borderRadius:"4px"}),c),clickable:s,noArrow:!0,opacity:1},d,{children:n}))};export{l as default};
1
+ import{__rest as t}from"../../../_virtual/_tslib.js";import{jsx as i}from"react/jsx-runtime";import{Tooltip as e}from"react-tooltip";const o=t=>`min(${t}, calc(100vw - 48px))`,r=r=>{var{selector:l=".menuOverflow",align:a="bottom-start",width:c="200px",style:n,children:s,clickable:d=!1}=r,b=t(r,["selector","align","width","style","children","clickable"]);return i(e,Object.assign({anchorSelect:l,place:a,positionStrategy:"fixed",style:Object.assign(Object.assign(Object.assign({fontFamily:"inherit",zIndex:1337,display:"flex",flexDirection:"column",padding:"0",backgroundColor:"white",color:"black",boxSizing:"border-box"},"auto"!==c&&{width:"100%",maxWidth:o(c)}),{borderRadius:"4px"}),n),clickable:d,noArrow:!0,opacity:1},b,{children:s}))};export{r as default};
@@ -1 +1 @@
1
- import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as n,jsxs as s,Fragment as o}from"react/jsx-runtime";import{forwardRef as i,useState as r,useRef as a,useCallback as l,useEffect as c,useMemo as d,useImperativeHandle as u}from"react";import{usePickaxeContext as m}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as p}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as f}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as g}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as h}from"../../../hooks/pickaxe/useConversation.js";import{useDimensionContext as v}from"../../../hooks/pickaxe/useDimensionContext.js";import{useAuthContext as b}from"../Addons/Auth/hooks/useAuthContext.js";import{useDocument as y}from"../Addons/Document/hooks/useDocument.js";import{useScroll as x}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as j}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as I}from"../../../hooks/core/useHover.js";import{useMediaQuery as O}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as w,allowedImageMimeTypes as k,additionalAllowedFileExtensions as N}from"../../../common/documents.js";import{createParser as S}from"eventsource-parser";import C from"../../Icons/attach-vertical.svg.js";import _ from"../../Icons/arrow-right.svg.js";import E from"../../Icons/microphone.svg.js";import U from"../../Icons/stop.svg.js";import T from"../Addons/Document/List.js";import A from"../../Core/Textarea.js";import P from"../../Core/ErrorAlert.js";import D from"../../../common/error.js";import L from"../../../common/api/pickaxe.js";import{getValidationFailure as R}from"../../../common/validation.js";import M from"../../../common/cn.js";import{buildUpgradeUrl as $,isInIframe as B,initializeEmbedUserId as X}from"../../../common/utils.js";import{getPickaxeConfigMetadata as K}from"../../../common/pickaxeConfig.js";import{fireDeploymentSessionInitializedWebhook as V,fireDeploymentFirstMessageSubmittedWebhook as F}from"../../../common/deploymentWebhooks.js";import{useStudio as H}from"../../../hooks/studio/useStudio.js";import{useSpeech as W}from"../../../hooks/pickaxe/useSpeech.js";import{STUDIO_INFINITY_VALUE as J}from"../common/PickaxeCommon.js";const G=e=>"string"==typeof e&&e.trim().length>0,z=e=>e.map((e=>Object.assign({},e))),q=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),Q=(e,t)=>{if(e&&"object"==typeof e)return e[t]},Y=(e,t)=>{const n=Q(e,t);return G(n)?n:null},Z=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},ee=({studioUser:e,deploymentId:t,portalId:n})=>{var s,o;const i=Array.isArray(Q(e,"uses"))?Q(e,"uses"):[],r=(({deploymentId:e,portalId:t})=>G(e)?{type:"deployment",id:e}:G(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:n});if(!r)return{scope:r,record:null};const a=null!==(o=null!==(s=i.find((e=>e.id===r.id&&e.type===r.type)))&&void 0!==s?s:i.find((e=>e.id===r.id)))&&void 0!==o?o:null;return{scope:r,record:a}},te=i((({resubmitPrompt:i,onFocus:Q,onBlur:te,onInputHeightChange:ne,initSmitheryAuthData:se},oe)=>{var ie,re,ae,le,ce,de,ue,me,pe,fe;const{origin:ge,pickaxeId:he,sessionId:ve,sender:be,senderType:ye,portalId:xe,deploymentId:je,deploymentType:Ie,pickaxe:Oe,styles:we,colors:ke,translations:Ne,locale:Se,forceMobile:Ce,isNewChat:_e,isRtl:Ee,isShowFeedbackMessage:Ue,accessGroup:Te,setIsNewChat:Ae,setIsShowIceBreaker:Pe,setValidationStatus:De,setValidationUpgradeGroups:Le,setValidationUpgradeUrl:Re,onGenerateComplete:Me}=m(),{token:$e,isLoggedOut:Be,isSent:Xe,isPricingAuth:Ke}=b(),{messages:Ve,isGenerating:Fe,setMessages:He,setStatus:We,setLimitData:Je,setError:Ge}=p(),{documents:ze,isUploading:qe,documentError:Qe,onFileUpload:Ye,setDocuments:Ze,setDocumentError:et}=y(),{studio:tt}=H(),{scrollStartSession:nt,scrollEndSession:st,scrollToBottom:ot}=x({auto:!0}),{artifacts:it,currentPopupType:rt,setArtifacts:at,setCurrentArtifact:lt}=j(),{height:ct}=v(),dt=h(),[ut,mt]=r(""),[pt,ft]=r(!1),[gt,ht]=r(!1),[vt,bt]=r(null),[yt,xt]=r(null),[jt,It]=r(!1),[Ot,wt]=r(!1),[kt,Nt]=r(0),St=a(null),Ct=a(""),_t=a(null),Et=a(null),Ut=a(null),Tt=a([]),At=a(null),Pt=a(null),Dt=a(null),Lt=a(null),Rt=a(new Set),Mt=a(null),$t=Math.max(.4*ct,100),{speechTranscript:Bt,isSpeechListening:Xt,isSpeechProcessing:Kt,isSpeechSupported:Vt,onStartListening:Ft,onStopListening:Ht}=W(),[Wt]=O("(max-width: 480px)"),Jt=I(),{isHover:Gt}=Jt,zt=e(Jt,["isHover"]),qt=I(),{isHover:Qt}=qt,Yt=e(qt,["isHover"]),Zt=I(),{isHover:en}=Zt,tn=e(Zt,["isHover"]),nn=g(),sn=f(),on="undefined"!=typeof window?window.location.hostname:"",rn="undefined"!=typeof window?window.location.href:"",an="undefined"!=typeof window&&window.self!==window.top,ln=on.includes("pickaxe.co")&&!rn.includes("https://studio.pickaxe.co/_embed")&&!an,cn=null!==(re=null===(ie=null==Oe?void 0:Oe.documentuploadtype)||void 0===ie?void 0:ie.startsWith("enduserupload"))&&void 0!==re&&re,dn=Vt&&(null==Oe?void 0:Oe.enablevoicetotext),un=G(je),mn="chat-input"===Ie&&_e&&!Xe,pn="chat-input"===Ie&&Ke&&Be&&Xe,fn=l((e=>{const t=R(e);return!!t&&(Ge(""),Je(null),De(t.status),Le(t.upgradeGroups),Re(t.upgradeUrl),!0)}),[Ge,Je,De,Le,Re]),gn=null!==(ae=null==Oe?void 0:Oe.placeholdertext)&&void 0!==ae?ae:Ee?"بماذا تريد أن تتحدث؟":(null==Ne?void 0:Ne["what-do-you-want-to-talk-about"])||"What do you want to talk about?",hn=pt||gt,vn=l((()=>t(void 0,void 0,void 0,(function*(){It(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==Oe?void 0:Oe.studioid},$e?{studioSessionToken:$e}:be?{sender:be}:{sender:X()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),ln&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(bt(t.studioUser),xt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{It(!0)}}))),[ln,null==Oe?void 0:Oe.studioid,be,$e]);c((()=>{vn()}),[vn]);const bn=Number(null!==(le=null==Te?void 0:Te.limit)&&void 0!==le?le:0),yn="string"==typeof(null==Te?void 0:Te.limitInterval)?Te.limitInterval:null,xn=!!(null==tt?void 0:tt.data.usage)&&tt.data.usage.isCredits,jn=d((()=>ee({studioUser:vt,deploymentId:je,portalId:xe})),[je,xe,vt]);c((()=>{un&&_e&&ve&&Rt.current.add(ve)}),[_e,ve,un]);const In=l((()=>{var e,t,n;return{studioId:null==Oe?void 0:Oe.studioid,userEmail:Y(vt,"email"),userId:null!==(e=Y(vt,"userId"))&&void 0!==e?e:Y(vt,"userid"),sessionId:ve,deploymentId:je,deploymentType:Ie,portalId:xe,accessGroupId:null!==(t=null==Te?void 0:Te.accessGroupId)&&void 0!==t?t:null,pickaxeId:he,sender:be,senderType:ye,origin:ge,metadata:null!==(n=K(je))&&void 0!==n?n:null}}),[null==Te?void 0:Te.accessGroupId,je,Ie,ge,null==Oe?void 0:Oe.studioid,he,xe,be,ye,ve,vt]),On=l((()=>!!(un&&jt&&ve)&&(!!Rt.current.has(ve)&&(V(In()),Rt.current.delete(ve),!0))),[In,jt,ve,un]);c((()=>{if(!jt||!ve)return;On();const e=Mt.current;(null==e?void 0:e.sessionId)===ve&&(F(Object.assign(Object.assign(Object.assign({},e),In()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),Mt.current=null)}),[On,In,jt,ve]);const wn={currentUses:Z(null==vt?void 0:vt.currentUses),extraUses:Z(null==vt?void 0:vt.extraUses)},kn=jn.scope?{currentUses:null!==(de=Z(null===(ce=jn.record)||void 0===ce?void 0:ce.currentUses))&&void 0!==de?de:0,extraUses:null!==(me=Z(null===(ue=jn.record)||void 0===ue?void 0:ue.extraUses))&&void 0!==me?me:0}:{currentUses:0,extraUses:0},Nn=Y(vt,"type"),Sn="guest"===Nn||!Nn&&Be?kn:wn;c((()=>{let e=!0;return t(void 0,void 0,void 0,(function*(){var t;if(xn&&(null===(t=null==tt?void 0:tt.data)||void 0===t?void 0:t.workspaceId))try{const t=yield L.get(`/cost_per_run?workspaceId=${tt.data.workspaceId}`,{withCredentials:!1});e&&Nt(1e4*(Number(t.data.costPerRun)||0))}catch(t){console.error("Failed to fetch average cost per run:",t),e&&Nt(0)}else e&&Nt(0)})),()=>{e=!1}}),[xn,null===(pe=null==tt?void 0:tt.data)||void 0===pe?void 0:pe.workspaceId]);const Cn=(({currentUses:e,extraUses:t,limit:n,limitInterval:s})=>{const o=Number(null!=e?e:0),i=Number(null!=t?t:0);return n===J||i===J?J:"one_time"===s?Math.max(0,i-o):(console.log("Calculating remaining balance with limit:",n,"currentUses:",o,"extraUses:",i),Math.max(0,n-o)+i)})({currentUses:Sn.currentUses,extraUses:Sn.extraUses,limit:bn,limitInterval:yn}),_n=Cn===J?J:Math.max(0,Math.ceil(Cn)),En=(({extraUses:e,limit:t,limitInterval:n})=>{const s=Number(null!=e?e:0);return t===J||s===J?J:"one_time"===n?Math.max(0,s):Math.max(0,t)+Math.max(0,s)})({extraUses:Sn.extraUses,limit:bn,limitInterval:yn}),Un=En===J?J:Math.ceil(.05*En),Tn=xn?Math.ceil(5*kt):5,An=Un===J?J:Math.max(Un,Tn),Pn=d((()=>!!vt&&(!Ot&&(_n!==J&&_n<=An))),[Ot,An,_n,vt]),Dn=d((()=>{var e,t,n;return!!_e&&(!!Oe&&(!dt.isLoading&&(!((null!==(t=null===(e=dt.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(n=Oe.icebreakers)||void 0===n?void 0:n.length)&&(!Ue&&!mn)))))}),[Oe,_e,Ue,mn,dt.data,dt.isLoading]),Ln=d((()=>{if(Fe||qe)return!1;const e=cn&&ze.length>0&&ze.every((e=>"finished"===e.status));return!(!ut.trim()&&!e)&&ze.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[cn,Fe,qe,ut,ze]);u(oe,(()=>({onSubmit:Rn}))),c((()=>{Pe(Dn)}),[Dn]),c((()=>{var e;if(i){const t=Array.from(Ve),n=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Rn(n,!0)}}),[i]),c((()=>{if(!Dt.current||!ne)return;const e=new ResizeObserver((e=>{for(const t of e)ne(t.contentRect.height)}));return e.observe(Dt.current),()=>{e.disconnect()}}),[ne]),c((()=>{if(!Xt)return;const e=Ct.current?`${Ct.current} `:"";mt(`${e}${Bt}`)}),[Bt,Xt]),c((()=>{if(!At.current)return;(()=>{if(!At.current)return;let e=At.current.scrollHeight>52;ut.includes("\n")||ze.length?e=!0:ut.trim()||(e=!1),ft(e)})()}),[ut,ze]),c((()=>{const e=At.current,t=Pt.current;if(!e||!t||pt||ut.includes("\n"))return void ht(!1);const n=window.getComputedStyle(e),s=`${n.fontStyle} ${n.fontVariant} ${n.fontWeight} ${n.fontSize} / ${n.lineHeight} ${n.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:s,letterSpacing:n.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=ut||gn,document.body.appendChild(o);const i=o.offsetWidth;o.remove();const r=parseFloat(n.paddingLeft)||0,a=parseFloat(n.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;ht(i>l)}),[ut,pt,gn]);const Rn=(e,n=!1)=>t(void 0,void 0,void 0,(function*(){var t,s,o,i;let r=null;try{if(Fe||qe)return;const a=ze.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),l=a.map((e=>e.documentId)).filter(Boolean),c=a.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),d=null!=e?e:ut,u=null!==(s=null===(t=null==Oe?void 0:Oe.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&l.length>0;if(!d&&!u)return;Ge(""),et(""),Je(null),mt(""),Ae(!1),We("fetching"),nt(),ot();const m=[...n?Array.from(Ve.slice(0,Ve.length-1)):Array.from(Ve),...n?[]:[{id:Ve.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:u?l:[]}],{id:Ve.length+(n?0:2),role:"assistant",parts:[],documentIds:[]}];He(m),ot(),u&&Ze([]);const p=K(je),f="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;r=f,Et.current=f,Ut.current=null,Tt.current=[];const g=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:ge,pickaxeId:he,sessionId:ve,submissionId:f,senderType:ye,value:d},u&&{documentIds:l}),be&&{sender:be}),$e&&{studioSessionToken:$e}),!$e&&!be&&{sender:X()}),xe&&{portalId:xe}),je&&{deploymentId:je}),p&&{metadata:p}),u&&c.length>0?{uploadedModelImages:c}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},ln&&{credentials:"include"})),h=yield g.json();if(!h.success){if(fn(h))return;const e=new Error(h.error||h.message||(null==Ne?void 0:Ne["failed-to-start-generation"])||"Failed to start generation");throw h.limitData&&(e.limitData=h.limitData),e}const v=null!==(o=h.submissionId)&&void 0!==o?o:f;r=v,Et.current=v;const b=()=>Ut.current===v;if(b())return;un&&_e&&ve&&Rt.current.add(ve);const y=Object.assign(Object.assign({},In()),{message:d,documentIds:u?l:[],uploadedModelImages:u?c:[],hasUploadedDocuments:u,isHidden:n,metadata:null!=p?p:null});jt?(On(),F(y)):Mt.current=y,We("streaming"),Lt.current=new AbortController;const x=m.length-1,j=[];let I=[...null!=it?it:[]],O=0,w=!1,k="";for(;!w;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${v}?index=${O}`,{signal:null===(i=Lt.current)||void 0===i?void 0:i.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();_t.current=t;const n=new TextDecoder,s=S({onEvent:e=>{var t,n;if(b())w=!0;else if(e.event&&"ping"!==e.event&&O++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),n=t.error||t.message||(null==Ne?void 0:Ne["something-went-wrong"])||"Something went wrong.";return fn(t)||Ge(n),void(w=!0)}if("delta"===e.event){const s=JSON.parse(e.data);if("data-error"===s.type&&se){const e=s.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&n&&n[1]&&s&&s[1])throw w=!0,se({smitheryId:t[1],serverId:n[1],name:s[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw w=!0,se({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===s.type)k="",j.push({type:"text",content:"",isVisible:null===(t=s.isVisible)||void 0===t||t});else if("text-delta"===s.type)k+=s.delta,j[j.length-1].content=k;else if("text-end"===s.type)k="";else if("reasoning-start"===s.type)k="",j.push({type:"reasoning",content:"",isVisible:null===(n=s.isVisible)||void 0===n||n});else if("reasoning-delta"===s.type)k+=s.delta,j[j.length-1].content=k;else if("reasoning-end"===s.type)k="";else if(s.type.startsWith("data-")){const e=s;j.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Tt.current=z(j),He([...m.slice(0,x),Object.assign(Object.assign({},m[m.length-1]),{id:Ve.length+1,role:"assistant",parts:j})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),at([...I]),rt.startsWith("inline")||lt({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),at(I),rt.startsWith("inline")||lt({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),at(I),rt.startsWith("inline")||lt({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),n=t.token.replace(/\u200B/g,"");I=I.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+n,status:"streaming"}):e)),at(I)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);at(I.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data),n=t.error||t.message||(null==Ne?void 0:Ne["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(fn(t))return void(w=!0);Ge(n)}else"stop"===e.event&&(w=!0)}else w=!0}});for(;;){if(b()){w=!0,t.cancel().catch((()=>{}));break}const{value:e,done:o}=yield t.read();if(b()){w=!0,t.cancel().catch((()=>{}));break}if(o)break;s.feed(n.decode(e))}w||b()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||q(e)||b())return void(w=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==Me||Me(ve)}catch(e){if(q(e))return;if(e.limitData)Je(e.limitData),Ge("");else{let t=D(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==Ne?void 0:Ne["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),fn(t)||Ge(t)}}finally{const e=!r||Et.current===r;ot(),e&&(We("idle"),st(),_t.current=null),r&&e&&(Et.current=null,Tt.current=[]),yield vn()}}));return pn?null:n("div",Object.assign({className:M("flex w-full flex-shrink-0 flex-col items-center",!mn&&"px-4 pb-8"),dir:Ee?"rtl":"ltr"},{children:s("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[s("div",Object.assign({ref:Dt,className:M("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===we.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},sn),{maxHeight:`${$t}px`,overflowY:"auto"})},{children:[Pn&&s("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:sn.backgroundColor?`${sn.backgroundColor}E6`:void 0,borderColor:ke.text+"20",color:ke.text,borderTopRightRadius:we.cornerRadius+"px",borderTopLeftRadius:we.cornerRadius+"px"}},{children:[n("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:s("span",{children:[_n.toLocaleString()," ",xn?(null==Ne?void 0:Ne.credits)||"Credits":(null==Ne?void 0:Ne.uses)||"Uses"," ",(null==Ne?void 0:Ne.remaining)||"remaining"]})})),s("div",Object.assign({className:"flex items-center gap-3"},{children:[n("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:ke.accent,color:ke.accentText},onClick:e=>{e.preventDefault(),e.stopPropagation();const t=$({baseUrl:yt,accessGroupId:null==Te?void 0:Te.accessGroupId});t&&(B()?window.open(t):location.href=t)}},{children:(null==Ne?void 0:Ne["pricing.upgrade"])||(null==Ne?void 0:Ne.upgrade)||"Upgrade"})),n("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>wt(!0)},{children:n("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:n("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Fe&&ze.length>0&&n(T,{className:"p-4 pb-0",isDisabled:Fe}),s("div",Object.assign({className:"relative flex w-full flex-col"},{children:[Xt&&s("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[n("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(fe=ke.accent)&&void 0!==fe?fe:"#ff0000"}}),n("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:ke.text+"90"}},{children:(null==Ne?void 0:Ne.listening)||"Listening..."}))]})),n(A,Object.assign({ref:At,className:M(nn.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!ut.trim()&&!ut.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",Ee?"text-right":"text-left",hn&&"mb-12",Xt&&"text-transparent"),value:ut,placeholder:gn,onChange:e=>{mt(e)},onKeyDown:e=>{Ce||Wt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),qe||Fe||Rn()))},onPaste:e=>t(void 0,void 0,void 0,(function*(){const t=Array.from(e.clipboardData.files||[]);if(t.length>0){if(!cn)return;e.preventDefault(),Ae(!1),yield Ye(t)}}))},Q&&{onFocus:Q},te&&{onBlur:te},{dir:Ee?"rtl":"ltr"})),n("div",Object.assign({ref:Pt,className:M("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",hn?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!hn&&sn.backgroundColor&&{backgroundColor:sn.backgroundColor}),{borderTopRightRadius:we.cornerRadius+"px",borderBottomRightRadius:we.cornerRadius+"px"})},{children:Fe?n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const e=Et.current;e&&(Ut.current=e,(e=>{t(void 0,void 0,void 0,(function*(){if(!(e=null!=e?e:Et.current))return;const t=z(Tt.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/cancel/${e}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:t})},ln&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(e)),Lt.current&&(Lt.current.abort(),Lt.current=null),_t.current&&(_t.current.cancel().catch((()=>{})),_t.current=null),We("idle")},style:{backgroundColor:ke.accent,color:ke.accentText}},{children:n(U,{className:"h-4 w-4 shrink-0"})})):Xt?n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Ht,style:{backgroundColor:ke.accent,color:ke.accentText}},{children:n(U,{className:"h-4 w-4 shrink-0"})})):s(o,{children:[cn&&s("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Qt?ke.accent+"10":void 0,color:Qt?ke.accent:ke.accent+"80"},disabled:qe||Fe,onClick:()=>{var e;return null===(e=St.current)||void 0===e?void 0:e.click()}},Yt,{children:[n("input",{id:"file-upload",ref:St,type:"file",accept:[...w,...k,...N].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){Ae(!1),yield Ye(Array.from(e.target.files||[])),e.target.value=""}))}),n(C,{className:"h-6 w-6 shrink-0"})]})),dn&&n("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Xt?ke.accent:en?ke.accent+"10":void 0,color:Xt?ke.accentText:en?ke.accent:ke.accent+"80"},disabled:qe||Fe||Kt,onClick:()=>{Xt?Ht():(Ct.current=ut,Ft(Se||"en-US"))}},tn,{children:n(E,{className:"h-5 w-5 shrink-0"})})),n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Gt||Ln?ke.accent:ke.accent+"10",color:Gt||Ln?ke.accentText:ke.accent+"80"},disabled:!Ln,onClick:()=>Rn()},zt,{children:n(_,{className:M("h-6 w-6 shrink-0",Ee&&"scale-x-[-1] transform")})}))]})}))]}))]})),Qe&&n(P,{error:Qe,className:"mt-3"})]}))}))}));te.displayName="Input";export{te as default};
1
+ import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{jsx as n,jsxs as s,Fragment as o}from"react/jsx-runtime";import{forwardRef as i,useState as r,useRef as a,useCallback as l,useEffect as c,useMemo as d,useImperativeHandle as u}from"react";import{usePickaxeContext as m}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as p}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleInput as f}from"../../../hooks/studio/useStyleInput.js";import{useStyleFontSize as g}from"../../../hooks/studio/useStyleFontSize.js";import{useConversation as h}from"../../../hooks/pickaxe/useConversation.js";import{useDimensionContext as v}from"../../../hooks/pickaxe/useDimensionContext.js";import{useAuthContext as b}from"../Addons/Auth/hooks/useAuthContext.js";import{useDocument as y}from"../Addons/Document/hooks/useDocument.js";import{useScroll as x}from"../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as j}from"../Addons/Artifact/hooks/useArtifactContext.js";import{useHover as I}from"../../../hooks/core/useHover.js";import{useMediaQuery as w}from"../../../hooks/core/useMediaQuery.js";import{allowedFileMimeTypes as O,allowedImageMimeTypes as k,additionalAllowedFileExtensions as N}from"../../../common/documents.js";import{createParser as S}from"eventsource-parser";import C from"../../Icons/attach-vertical.svg.js";import _ from"../../Icons/arrow-right.svg.js";import E from"../../Icons/microphone.svg.js";import U from"../../Icons/stop.svg.js";import T from"../Addons/Document/List.js";import A from"../../Core/Textarea.js";import P from"../../Core/ErrorAlert.js";import D from"../../../common/error.js";import L from"../../../common/api/pickaxe.js";import{getValidationFailure as R}from"../../../common/validation.js";import M from"../../../common/cn.js";import{buildUpgradeUrl as $,isInIframe as B,initializeEmbedUserId as X}from"../../../common/utils.js";import{getPickaxeConfigMetadata as K}from"../../../common/pickaxeConfig.js";import{fireDeploymentSessionInitializedWebhook as V,fireDeploymentFirstMessageSubmittedWebhook as F}from"../../../common/deploymentWebhooks.js";import{useStudio as H}from"../../../hooks/studio/useStudio.js";import{useSpeech as W}from"../../../hooks/pickaxe/useSpeech.js";import{STUDIO_INFINITY_VALUE as G}from"../common/PickaxeCommon.js";const J=e=>"string"==typeof e&&e.trim().length>0,z=e=>e.map((e=>Object.assign({},e))),q=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),Q=(e,t)=>{if(e&&"object"==typeof e)return e[t]},Y=(e,t)=>{const n=Q(e,t);return J(n)?n:null},Z=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},ee=({studioUser:e,deploymentId:t,portalId:n})=>{var s,o;const i=Array.isArray(Q(e,"uses"))?Q(e,"uses"):[],r=(({deploymentId:e,portalId:t})=>J(e)?{type:"deployment",id:e}:J(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:n});if(!r)return{scope:r,record:null};const a=null!==(o=null!==(s=i.find((e=>e.id===r.id&&e.type===r.type)))&&void 0!==s?s:i.find((e=>e.id===r.id)))&&void 0!==o?o:null;return{scope:r,record:a}},te=i((({resubmitPrompt:i,onFocus:Q,onBlur:te,onInputHeightChange:ne,initSmitheryAuthData:se},oe)=>{var ie,re,ae,le,ce,de,ue,me,pe,fe,ge,he;const{origin:ve,pickaxeId:be,sessionId:ye,sender:xe,senderType:je,portalId:Ie,deploymentId:we,deploymentType:Oe,pickaxe:ke,styles:Ne,colors:Se,translations:Ce,locale:_e,forceMobile:Ee,isNewChat:Ue,isRtl:Te,isShowFeedbackMessage:Ae,accessGroup:Pe,setIsNewChat:De,setIsShowIceBreaker:Le,setValidationStatus:Re,setValidationUpgradeGroups:Me,setValidationUpgradeUrl:$e,setAccessGroup:Be,onGenerateComplete:Xe}=m(),{token:Ke,isLoggedOut:Ve,isSent:Fe,isPricingAuth:He}=b(),{messages:We,isGenerating:Ge,setMessages:Je,setStatus:ze,setLimitData:qe,setError:Qe}=p(),{documents:Ye,isUploading:Ze,documentError:et,onFileUpload:tt,setDocuments:nt,setDocumentError:st}=y(),{studio:ot}=H(),{scrollStartSession:it,scrollEndSession:rt,scrollToBottom:at}=x({auto:!0}),{artifacts:lt,currentPopupType:ct,setArtifacts:dt,setCurrentArtifact:ut}=j(),{height:mt}=v(),pt=h(),[ft,gt]=r(""),[ht,vt]=r(!1),[bt,yt]=r(!1),[xt,jt]=r(null),[It,wt]=r(null),[Ot,kt]=r(!1),[Nt,St]=r(!1),[Ct,_t]=r(0),Et=a(null),Ut=a(""),Tt=a(null),At=a(null),Pt=a(null),Dt=a([]),Lt=a(null),Rt=a(null),Mt=a(null),$t=a(null),Bt=a(new Set),Xt=a(null),Kt=Math.max(.4*mt,100),{speechTranscript:Vt,isSpeechListening:Ft,isSpeechProcessing:Ht,isSpeechSupported:Wt,onStartListening:Gt,onStopListening:Jt}=W(),[zt]=w("(max-width: 480px)"),qt=I(),{isHover:Qt}=qt,Yt=e(qt,["isHover"]),Zt=I(),{isHover:en}=Zt,tn=e(Zt,["isHover"]),nn=I(),{isHover:sn}=nn,on=e(nn,["isHover"]),rn=g(),an=f(),ln="undefined"!=typeof window?window.location.hostname:"",cn="undefined"!=typeof window?window.location.href:"",dn="undefined"!=typeof window&&window.self!==window.top,un=ln.includes("pickaxe.co")&&!cn.includes("https://studio.pickaxe.co/_embed")&&!dn,mn=null!==(re=null===(ie=null==ke?void 0:ke.documentuploadtype)||void 0===ie?void 0:ie.startsWith("enduserupload"))&&void 0!==re&&re,pn=Wt&&(null==ke?void 0:ke.enablevoicetotext),fn=J(we),gn="chat-input"===Oe&&Ue&&!Fe,hn="chat-input"===Oe&&He&&Ve&&Fe,vn=l((e=>{const t=R(e);return!!t&&(Qe(""),qe(null),Re(t.status),Be(t.accessGroup),Me(t.upgradeGroups),$e(t.upgradeUrl),!0)}),[Qe,qe,Re,Me,$e,Be]),bn=null!==(ae=null==ke?void 0:ke.placeholdertext)&&void 0!==ae?ae:Te?"بماذا تريد أن تتحدث؟":(null==Ce?void 0:Ce["what-do-you-want-to-talk-about"])||"What do you want to talk about?",yn=ht||bt,xn=l((()=>t(void 0,void 0,void 0,(function*(){kt(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/get_user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==ke?void 0:ke.studioid},Ke?{studioSessionToken:Ke}:xe?{sender:xe}:{sender:X()}))},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{headers:{"Content-Type":"application/json","x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}})),un&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(jt(t.studioUser),wt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{kt(!0)}}))),[un,null==ke?void 0:ke.studioid,xe,Ke]);c((()=>{xn()}),[xn]);const jn=Number(null!==(le=null==Pe?void 0:Pe.limit)&&void 0!==le?le:0),In="string"==typeof(null==Pe?void 0:Pe.limitInterval)?Pe.limitInterval:null,wn=!!(null==ot?void 0:ot.data.usage)&&ot.data.usage.isCredits,On=d((()=>ee({studioUser:xt,deploymentId:we,portalId:Ie})),[we,Ie,xt]);c((()=>{fn&&Ue&&ye&&Bt.current.add(ye)}),[Ue,ye,fn]);const kn=l((()=>{var e,t,n;return{studioId:null==ke?void 0:ke.studioid,userEmail:Y(xt,"email"),userId:null!==(e=Y(xt,"userId"))&&void 0!==e?e:Y(xt,"userid"),sessionId:ye,deploymentId:we,deploymentType:Oe,portalId:Ie,accessGroupId:null!==(t=null==Pe?void 0:Pe.accessGroupId)&&void 0!==t?t:null,pickaxeId:be,sender:xe,senderType:je,origin:ve,metadata:null!==(n=K(we))&&void 0!==n?n:null}}),[null==Pe?void 0:Pe.accessGroupId,we,Oe,ve,null==ke?void 0:ke.studioid,be,Ie,xe,je,ye,xt]),Nn=l((()=>!!(fn&&Ot&&ye)&&(!!Bt.current.has(ye)&&(V(kn()),Bt.current.delete(ye),!0))),[kn,Ot,ye,fn]);c((()=>{if(!Ot||!ye)return;Nn();const e=Xt.current;(null==e?void 0:e.sessionId)===ye&&(F(Object.assign(Object.assign(Object.assign({},e),kn()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),Xt.current=null)}),[Nn,kn,Ot,ye]);const Sn={currentUses:Z(null==xt?void 0:xt.currentUses),extraUses:Z(null==xt?void 0:xt.extraUses)},Cn=On.scope?{currentUses:null!==(de=Z(null===(ce=On.record)||void 0===ce?void 0:ce.currentUses))&&void 0!==de?de:0,extraUses:null!==(me=Z(null===(ue=On.record)||void 0===ue?void 0:ue.extraUses))&&void 0!==me?me:0}:{currentUses:0,extraUses:0},_n=Y(xt,"type"),En="guest"===_n||!_n&&Ve?Cn:Sn;c((()=>{let e=!0;return t(void 0,void 0,void 0,(function*(){var t;if(wn&&(null===(t=null==ot?void 0:ot.data)||void 0===t?void 0:t.workspaceId))try{const t=yield L.get(`/cost_per_run?workspaceId=${ot.data.workspaceId}`,{withCredentials:!1});e&&_t(1e4*(Number(t.data.costPerRun)||0))}catch(t){console.error("Failed to fetch average cost per run:",t),e&&_t(0)}else e&&_t(0)})),()=>{e=!1}}),[wn,null===(pe=null==ot?void 0:ot.data)||void 0===pe?void 0:pe.workspaceId]);const Un=(({currentUses:e,extraUses:t,limit:n,limitInterval:s})=>{const o=Number(null!=e?e:0),i=Number(null!=t?t:0);return n===G||i===G?G:"one_time"===s?Math.max(0,i-o):(console.log("Calculating remaining balance with limit:",n,"currentUses:",o,"extraUses:",i),Math.max(0,n-o)+i)})({currentUses:En.currentUses,extraUses:En.extraUses,limit:jn,limitInterval:In}),Tn=Un===G?G:Math.max(0,Math.ceil(Un)),An=(({extraUses:e,limit:t,limitInterval:n})=>{const s=Number(null!=e?e:0);return t===G||s===G?G:"one_time"===n?Math.max(0,s):Math.max(0,t)+Math.max(0,s)})({extraUses:En.extraUses,limit:jn,limitInterval:In}),Pn=An===G?G:Math.ceil(.05*An),Dn=wn?Math.ceil(5*Ct):5,Ln=Pn===G?G:Math.max(Pn,Dn),Rn=d((()=>!!xt&&(!Nt&&(Tn!==G&&Tn<=Ln))),[Nt,Ln,Tn,xt]),Mn=(null===(fe=null==Pe?void 0:Pe.upgrade)||void 0===fe?void 0:fe.isLinkToCustomURL)&&"string"==typeof Pe.upgrade.limitLink&&Pe.upgrade.limitLink.trim().length>0?Pe.upgrade.limitLink.trim():null,$n=Mn&&"string"==typeof(null===(ge=null==Pe?void 0:Pe.upgrade)||void 0===ge?void 0:ge.limitCTA)&&Pe.upgrade.limitCTA.trim().length>0?Pe.upgrade.limitCTA:(null==Ce?void 0:Ce["pricing.upgrade"])||(null==Ce?void 0:Ce.upgrade)||"Upgrade",Bn=d((()=>{var e,t,n;return!!Ue&&(!!ke&&(!pt.isLoading&&(!((null!==(t=null===(e=pt.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(n=ke.icebreakers)||void 0===n?void 0:n.length)&&(!Ae&&!gn)))))}),[ke,Ue,Ae,gn,pt.data,pt.isLoading]),Xn=d((()=>{if(Ge||Ze)return!1;const e=mn&&Ye.length>0&&Ye.every((e=>"finished"===e.status));return!(!ft.trim()&&!e)&&Ye.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[mn,Ge,Ze,ft,Ye]);u(oe,(()=>({onSubmit:Kn}))),c((()=>{Le(Bn)}),[Bn]),c((()=>{var e;if(i){const t=Array.from(We),n=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;Kn(n,!0)}}),[i]),c((()=>{if(!Mt.current||!ne)return;const e=new ResizeObserver((e=>{for(const t of e)ne(t.contentRect.height)}));return e.observe(Mt.current),()=>{e.disconnect()}}),[ne]),c((()=>{if(!Ft)return;const e=Ut.current?`${Ut.current} `:"";gt(`${e}${Vt}`)}),[Vt,Ft]),c((()=>{if(!Lt.current)return;(()=>{if(!Lt.current)return;let e=Lt.current.scrollHeight>52;ft.includes("\n")||Ye.length?e=!0:ft.trim()||(e=!1),vt(e)})()}),[ft,Ye]),c((()=>{const e=Lt.current,t=Rt.current;if(!e||!t||ht||ft.includes("\n"))return void yt(!1);const n=window.getComputedStyle(e),s=`${n.fontStyle} ${n.fontVariant} ${n.fontWeight} ${n.fontSize} / ${n.lineHeight} ${n.fontFamily}`,o=document.createElement("span");Object.assign(o.style,{font:s,letterSpacing:n.letterSpacing,position:"absolute",visibility:"hidden",whiteSpace:"nowrap",top:"0",left:"0"}),o.textContent=ft||bn,document.body.appendChild(o);const i=o.offsetWidth;o.remove();const r=parseFloat(n.paddingLeft)||0,a=parseFloat(n.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;yt(i>l)}),[ft,ht,bn]);const Kn=(e,n=!1)=>t(void 0,void 0,void 0,(function*(){var t,s,o,i;let r=null;try{if(Ge||Ze)return;const a=Ye.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),l=a.map((e=>e.documentId)).filter(Boolean),c=a.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),d=null!=e?e:ft,u=null!==(s=null===(t=null==ke?void 0:ke.documentuploadtype)||void 0===t?void 0:t.startsWith("enduserupload"))&&void 0!==s&&s&&l.length>0;if(!d&&!u)return;Qe(""),st(""),qe(null),gt(""),De(!1),ze("fetching"),it(),at();const m=[...n?Array.from(We.slice(0,We.length-1)):Array.from(We),...n?[]:[{id:We.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:u?l:[]}],{id:We.length+(n?0:2),role:"assistant",parts:[],documentIds:[]}];Je(m),at(),u&&nt([]);const p=K(we),f="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`;r=f,At.current=f,Pt.current=null,Dt.current=[];const g=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:ve,pickaxeId:be,sessionId:ye,submissionId:f,senderType:je,value:d},u&&{documentIds:l}),xe&&{sender:xe}),Ke&&{studioSessionToken:Ke}),!Ke&&!xe&&{sender:X()}),Ie&&{portalId:Ie}),we&&{deploymentId:we}),p&&{metadata:p}),u&&c.length>0?{uploadedModelImages:c}:{})),headers:Object.assign(Object.assign({},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()})},un&&{credentials:"include"})),h=yield g.json();if(!h.success){if(h.limitData){const e=new Error(h.error||h.message||(null==Ce?void 0:Ce["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=h.limitData,e}if(vn(h))return;throw new Error(h.error||h.message||(null==Ce?void 0:Ce["failed-to-start-generation"])||"Failed to start generation")}const v=null!==(o=h.submissionId)&&void 0!==o?o:f;r=v,At.current=v;const b=()=>Pt.current===v;if(b())return;fn&&Ue&&ye&&Bt.current.add(ye);const y=Object.assign(Object.assign({},kn()),{message:d,documentIds:u?l:[],uploadedModelImages:u?c:[],hasUploadedDocuments:u,isHidden:n,metadata:null!=p?p:null});Ot?(Nn(),F(y)):Xt.current=y,ze("streaming"),$t.current=new AbortController;const x=m.length-1,j=[];let I=[...null!=lt?lt:[]],w=0,O=!1,k="";for(;!O;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${v}?index=${w}`,{signal:null===(i=$t.current)||void 0===i?void 0:i.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();Tt.current=t;const n=new TextDecoder,s=S({onEvent:e=>{var t,n;if(b())O=!0;else if(e.event&&"ping"!==e.event&&w++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return qe(t.limitData),Qe(""),void(O=!0);const n=t.error||t.message||(null==Ce?void 0:Ce["something-went-wrong"])||"Something went wrong.";return vn(t)||Qe(n),void(O=!0)}if("delta"===e.event){const s=JSON.parse(e.data);if("data-error"===s.type&&se){const e=s.data.error;if("string"==typeof e){if(/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e)){const t=e.match(/['"]qualifiedName['"]\s*:\s*['"]([^'"]+)['"]/),n=e.match(/['"]serverId['"]\s*:\s*['"]([^'"]+)['"]/),s=e.match(/['"]name['"]\s*:\s*['"]([^'"]+)['"]/);if(t&&t[1]&&n&&n[1]&&s&&s[1])throw O=!0,se({smitheryId:t[1],serverId:n[1],name:s[1]}),new Error("STOP_STREAM")}}else if("object"==typeof e&&null!==e){const t=e;if("unauthorized_smithery"===t.type&&t.qualifiedName&&t.serverId&&t.name)throw O=!0,se({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===s.type)k="",j.push({type:"text",content:"",isVisible:null===(t=s.isVisible)||void 0===t||t});else if("text-delta"===s.type)k+=s.delta,j[j.length-1].content=k;else if("text-end"===s.type)k="";else if("reasoning-start"===s.type)k="",j.push({type:"reasoning",content:"",isVisible:null===(n=s.isVisible)||void 0===n||n});else if("reasoning-delta"===s.type)k+=s.delta,j[j.length-1].content=k;else if("reasoning-end"===s.type)k="";else if(s.type.startsWith("data-")){const e=s;j.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Dt.current=z(j),Je([...m.slice(0,x),Object.assign(Object.assign({},m[m.length-1]),{id:We.length+1,role:"assistant",parts:j})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),dt([...I]),ct.startsWith("inline")||ut({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),dt(I),ct.startsWith("inline")||ut({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);I=I.filter((e=>!(e.id===t.id&&e.version===t.version))),I.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),dt(I),ct.startsWith("inline")||ut({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),n=t.token.replace(/\u200B/g,"");I=I.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+n,status:"streaming"}):e)),dt(I)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);dt(I.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return qe(t.limitData),Qe(""),void(O=!0);const n=t.error||t.message||(null==Ce?void 0:Ce["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(vn(t))return void(O=!0);Qe(n)}else"stop"===e.event&&(O=!0)}else O=!0}});for(;;){if(b()){O=!0,t.cancel().catch((()=>{}));break}const{value:e,done:o}=yield t.read();if(b()){O=!0,t.cancel().catch((()=>{}));break}if(o)break;s.feed(n.decode(e))}O||b()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||q(e)||b())return void(O=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==Xe||Xe(ye)}catch(e){if(q(e))return;if(e.limitData)qe(e.limitData),Qe("");else{let t=D(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==Ce?void 0:Ce["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),vn(t)||Qe(t)}}finally{const e=!r||At.current===r;at(),e&&(ze("idle"),rt(),Tt.current=null),r&&e&&(At.current=null,Dt.current=[]),yield xn()}}));return hn?null:n("div",Object.assign({className:M("flex w-full flex-shrink-0 flex-col items-center",!gn&&"px-4 pb-8"),dir:Te?"rtl":"ltr"},{children:s("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[s("div",Object.assign({ref:Mt,className:M("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===Ne.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},an),{maxHeight:`${Kt}px`,overflowY:"auto"})},{children:[Rn&&s("div",Object.assign({className:"sticky top-0 z-10 flex w-full items-center justify-between border-b px-4 py-2.5 shadow-sm backdrop-blur-md",style:{backgroundColor:an.backgroundColor?`${an.backgroundColor}E6`:void 0,borderColor:Se.text+"20",color:Se.text,borderTopRightRadius:Ne.cornerRadius+"px",borderTopLeftRadius:Ne.cornerRadius+"px"}},{children:[n("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:s("span",{children:[Tn.toLocaleString()," ",wn?(null==Ce?void 0:Ce.credits)||"Credits":(null==Ce?void 0:Ce.uses)||"Uses"," ",(null==Ce?void 0:Ce.remaining)||"remaining"]})})),s("div",Object.assign({className:"flex items-center gap-3"},{children:[n("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:Se.accent,color:Se.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),Mn)return void window.open(Mn,"_blank","noopener,noreferrer");const t=$({baseUrl:It,accessGroupId:null==Pe?void 0:Pe.accessGroupId});t&&(B()?window.open(t):location.href=t)}},{children:$n})),n("button",Object.assign({className:"flex h-6 w-6 items-center justify-center rounded-full opacity-60 transition-opacity hover:opacity-100",onClick:()=>St(!0)},{children:n("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",className:"h-4 w-4"},{children:n("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}))}))]}))]})),!Ge&&Ye.length>0&&n(T,{className:"p-4 pb-0",isDisabled:Ge}),s("div",Object.assign({className:"relative flex w-full flex-col"},{children:[Ft&&s("div",Object.assign({className:"absolute left-4 top-1/2 flex -translate-y-1/2 select-none items-center gap-x-2"},{children:[n("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(he=Se.accent)&&void 0!==he?he:"#ff0000"}}),n("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:Se.text+"90"}},{children:(null==Ce?void 0:Ce.listening)||"Listening..."}))]})),n(A,Object.assign({ref:Lt,className:M(rn.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!ft.trim()&&!ft.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",Te?"text-right":"text-left",yn&&"mb-12",Ft&&"text-transparent"),value:ft,placeholder:bn,onChange:e=>{gt(e)},onKeyDown:e=>{Ee||zt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),Ze||Ge||Kn()))},onPaste:e=>t(void 0,void 0,void 0,(function*(){const t=Array.from(e.clipboardData.files||[]);if(t.length>0){if(!mn)return;e.preventDefault(),De(!1),yield tt(t)}}))},Q&&{onFocus:Q},te&&{onBlur:te},{dir:Te?"rtl":"ltr"})),n("div",Object.assign({ref:Rt,className:M("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",yn?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!yn&&an.backgroundColor&&{backgroundColor:an.backgroundColor}),{borderTopRightRadius:Ne.cornerRadius+"px",borderBottomRightRadius:Ne.cornerRadius+"px"})},{children:Ge?n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const e=At.current;e&&(Pt.current=e,(e=>{t(void 0,void 0,void 0,(function*(){if(!(e=null!=e?e:At.current))return;const t=z(Dt.current);try{yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/cancel/${e}`,Object.assign({method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},(!process.env.NODE_ENV||"development"===process.env.NODE_ENV)&&Object.assign({},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN})),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify({outputMessageParts:t})},un&&{credentials:"include"}))}catch(e){console.warn("Failed to cancel submission",e)}}))})(e)),$t.current&&($t.current.abort(),$t.current=null),Tt.current&&(Tt.current.cancel().catch((()=>{})),Tt.current=null),ze("idle")},style:{backgroundColor:Se.accent,color:Se.accentText}},{children:n(U,{className:"h-4 w-4 shrink-0"})})):Ft?n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:Jt,style:{backgroundColor:Se.accent,color:Se.accentText}},{children:n(U,{className:"h-4 w-4 shrink-0"})})):s(o,{children:[mn&&s("button",Object.assign({className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:en?Se.accent+"10":void 0,color:en?Se.accent:Se.accent+"80"},disabled:Ze||Ge,onClick:()=>{var e;return null===(e=Et.current)||void 0===e?void 0:e.click()}},tn,{children:[n("input",{id:"file-upload",ref:Et,type:"file",accept:[...O,...k,...N].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:e=>t(void 0,void 0,void 0,(function*(){De(!1),yield tt(Array.from(e.target.files||[])),e.target.value=""}))}),n(C,{className:"h-6 w-6 shrink-0"})]})),pn&&n("button",Object.assign({className:"disabled:cursor-default flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",style:{backgroundColor:Ft?Se.accent:sn?Se.accent+"10":void 0,color:Ft?Se.accentText:sn?Se.accent:Se.accent+"80"},disabled:Ze||Ge||Ht,onClick:()=>{Ft?Jt():(Ut.current=ft,Gt(_e||"en-US"))}},on,{children:n(E,{className:"h-5 w-5 shrink-0"})})),n("button",Object.assign({className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out disabled:cursor-default",style:{backgroundColor:Qt||Xn?Se.accent:Se.accent+"10",color:Qt||Xn?Se.accentText:Se.accent+"80"},disabled:!Xn,onClick:()=>Kn()},Yt,{children:n(_,{className:M("h-6 w-6 shrink-0",Te&&"scale-x-[-1] transform")})}))]})}))]}))]})),et&&n(P,{error:et,className:"mt-3"})]}))}))}));te.displayName="Input";export{te as default};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as s,useMemo as i,useState as n}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as o}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as c}from"../../../../hooks/studio/useStyleFontSize.js";import a from"../../../Icons/check.svg.js";import l from"./Dropdown.js";import d from"../../../../common/cn.js";const p=({field:p,update:u})=>{const{colors:m,isRtl:b,translations:f}=r(),{setError:h}=o(),g=c(),j=s(null),x=i((()=>p.example.split("S3P32X")),[p.example]),y=i((()=>p.input?p.input.split("&#44;"):[]),[p.input]),[O,v]=n((()=>{const e=x.includes(p.input);return p.allowOther&&p.input&&!e?p.input:""}));return e("div",Object.assign({className:"flex flex-col gap-y-3",dir:b?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[t("p",Object.assign({className:d(g.b3,"font-semibold opacity-70")},{children:p.main})),p.isRequired&&t("span",Object.assign({className:"select-none font-semibold",style:{color:m.error}},{children:"*"}))]})),t(l,Object.assign({id:p.id.replace(/[^A-Za-z]+/g,""),value:p.input.replace(/&#44;/g,", "),placeholder:(null==f?void 0:f["select-options"])||"Select option(s)",closeOnSelect:!1,maxToken:p.maxLength,isDropdown:p.isDropdown},{children:e("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[x.map(((s,i)=>e("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{h("");const t=y.includes(e),s=p.input?p.input.split("&#44;"):[],i=new Set(s);t&&i.has(e)?i.delete(e):t||i.has(e)||i.add(e);const n=Array.from(i).filter((e=>""!==e.trim()));u(Object.assign(Object.assign({},p),{input:n.join("&#44;")}))})(s)},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:y.includes(s)?m.accent:m.accent+"80"},y.includes(s)&&{backgroundColor:m.accent})},{children:t(a,{className:d("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",y.includes(s)&&"opacity-100"),style:{color:m.accentText}})})),t("p",Object.assign({className:d(g.b2,"select-none")},{children:s}))]}),i))),p.allowOther&&e("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{h("");const e=y.includes(O.trim()),t=p.input?p.input.split("&#44;"):[],s=Array.from(new Set(t)).filter((e=>""!==e.trim()&&x.includes(e)));e||s.push(O.trim()),u(Object.assign(Object.assign({},p),{input:s.join("&#44;")})),setTimeout((()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()}),0)}},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:y.includes(O)?m.accent:m.accent+"80"},y.includes(O)&&{backgroundColor:m.accent})},{children:t(a,{className:d("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",y.includes(O)&&"opacity-100"),style:{color:m.accentText}})})),e("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e("p",Object.assign({className:d(g.b2,"select-none opacity-80 min-w-fit")},{children:[(null==f?void 0:f.other)||"Other",":"]})),t("input",{ref:j,type:"text",className:d(g.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:y.includes(O)?m.accent:"rgba(0,0,0,0.2)"},value:O,onChange:e=>(e=>{h(""),v(e);const t=y.includes(e.trim()),s=p.input?p.input.split("&#44;"):[],i=new Set(s.filter((e=>x.includes(e))));t?i.delete(e.trim()):i.add(e.trim());const n=Array.from(i).filter((e=>""!==e.trim()));u(Object.assign(Object.assign({},p),{input:n.join("&#44;")}))})(e.target.value),placeholder:(null==f?void 0:f["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};export{p as default};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as s,useMemo as i,useState as n}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as o}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as c}from"../../../../hooks/studio/useStyleFontSize.js";import a from"../../../Icons/check.svg.js";import l,{getDropdownMenuId as d}from"./Dropdown.js";import p from"../../../../common/cn.js";const u=({field:u,update:m})=>{const{colors:b,isRtl:f,translations:h}=r(),{setError:g}=o(),j=c(),x=s(null),y=i((()=>u.example.split("S3P32X")),[u.example]),O=i((()=>u.input?u.input.split("&#44;"):[]),[u.input]),[w,v]=n((()=>{const e=y.includes(u.input);return u.allowOther&&u.input&&!e?u.input:""}));return e("div",Object.assign({className:"flex flex-col gap-y-3",dir:f?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[t("p",Object.assign({className:p(j.b3,"font-semibold opacity-70")},{children:u.main})),u.isRequired&&t("span",Object.assign({className:"select-none font-semibold",style:{color:b.error}},{children:"*"}))]})),t(l,Object.assign({id:d(u.id),value:u.input.replace(/&#44;/g,", "),placeholder:(null==h?void 0:h["select-options"])||"Select option(s)",closeOnSelect:!1,maxToken:u.maxLength,isDropdown:u.isDropdown},{children:e("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[y.map(((s,i)=>e("div",Object.assign({className:"flex min-w-0 items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{g("");const t=O.includes(e),s=u.input?u.input.split("&#44;"):[],i=new Set(s);t&&i.has(e)?i.delete(e):t||i.has(e)||i.add(e);const n=Array.from(i).filter((e=>""!==e.trim()));m(Object.assign(Object.assign({},u),{input:n.join("&#44;")}))})(s)},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:O.includes(s)?b.accent:b.accent+"80"},O.includes(s)&&{backgroundColor:b.accent})},{children:t(a,{className:p("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",O.includes(s)&&"opacity-100"),style:{color:b.accentText}})})),t("p",Object.assign({className:p(j.b2,"min-w-0 select-none break-words"),style:{overflowWrap:"anywhere"}},{children:s}))]}),i))),u.allowOther&&e("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{g("");const e=O.includes(w.trim()),t=u.input?u.input.split("&#44;"):[],s=Array.from(new Set(t)).filter((e=>""!==e.trim()&&y.includes(e)));e||s.push(w.trim()),m(Object.assign(Object.assign({},u),{input:s.join("&#44;")})),setTimeout((()=>{var e;return null===(e=x.current)||void 0===e?void 0:e.focus()}),0)}},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center border-2 rounded-sm transition-colors ease-in-out duration-200",style:Object.assign({borderColor:O.includes(w)?b.accent:b.accent+"80"},O.includes(w)&&{backgroundColor:b.accent})},{children:t(a,{className:p("h-3 w-3 shrink-0 transition-opacity opacity-0 ease-in-out duration-200",O.includes(w)&&"opacity-100"),style:{color:b.accentText}})})),e("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e("p",Object.assign({className:p(j.b2,"select-none opacity-80 min-w-fit")},{children:[(null==h?void 0:h.other)||"Other",":"]})),t("input",{ref:x,type:"text",className:p(j.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:O.includes(w)?b.accent:"rgba(0,0,0,0.2)"},value:w,onChange:e=>(e=>{g(""),v(e);const t=O.includes(e.trim()),s=u.input?u.input.split("&#44;"):[],i=new Set(s.filter((e=>y.includes(e))));t?i.delete(e.trim()):i.add(e.trim());const n=Array.from(i).filter((e=>""!==e.trim()));m(Object.assign(Object.assign({},u),{input:n.join("&#44;")}))})(e.target.value),placeholder:(null==h?void 0:h["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};export{u as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as s}from"react/jsx-runtime";import{usePickaxeContext as o}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleInput as r}from"../../../../hooks/studio/useStyleInput.js";import t from"../../../Core/Menu/index.js";import n from"../../../Core/Menu/Button.js";import a from"../../../Core/Menu/List.js";import i from"../../../../common/cn.js";const c=({id:c,children:l,placeholder:d,value:m,className:p,style:u,closeOnSelect:b=!0,maxToken:j=50,isDropdown:f=!1})=>{const{styles:x,colors:h}=o(),g=r();return f?s(t,Object.assign({id:c,closeOnSelect:b,className:"relative"},{children:[e(n,Object.assign({variant:"anchor",className:i("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",p,j<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},g),u)},{children:e("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=m?m:"")||d}))})),e(a,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===h.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:j<=50?"400px":"100%",maxHeight:"200px",style:Object.assign(Object.assign(Object.assign({},g),{borderRadius:x.cornerRadius}),u)},{children:l}))]})):e("div",{children:l})};export{c as default};
1
+ import{jsx as e,jsxs as r}from"react/jsx-runtime";import{usePickaxeContext as o}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useStyleInput as s}from"../../../../hooks/studio/useStyleInput.js";import t from"../../../Core/Menu/index.js";import n from"../../../Core/Menu/Button.js";import a from"../../../Core/Menu/List.js";import i from"../../../../common/cn.js";const c=e=>{const r=e.trim().replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");let o=0;for(let r=0;r<e.length;r+=1)o=31*o+e.charCodeAt(r)>>>0;return`pxe-dropdown-${r||"field"}-${o.toString(36)}`},l=({id:c,children:l,placeholder:d,value:m,className:p,style:u,closeOnSelect:b=!0,maxToken:g=50,isDropdown:f=!1})=>{const{styles:j,colors:x}=o(),h=s(),O=Object.assign(Object.assign(Object.assign({},h),{borderRadius:j.cornerRadius}),u);return O.backgroundColor&&"transparent"!==O.backgroundColor||(O.backgroundColor=x.primary),f?r(t,Object.assign({id:c,closeOnSelect:b,className:"relative"},{children:[e(n,Object.assign({variant:"anchor",className:i("flex items-center justify-between rounded-sm border border-transparent py-3 pl-4 pr-3 shadow duration-300",p,g<=50&&"max-w-[400px]"),style:Object.assign(Object.assign({},h),u)},{children:e("p",Object.assign({className:"line-clamp-1 select-none"},{children:(null!=m?m:"")||d}))})),e(a,Object.assign({className:"p-3 shadow-md",border:"#ffffff"===x.secondaryText.toLowerCase()?"1px solid rgba(255,255,255,0.7)":"1px solid rgba(0,0,0,0.7)",align:"bottom-end",width:g<=50?"400px":"100%",maxHeight:"200px",style:O},{children:l}))]})):e("div",{children:l})};export{l as default,c as getDropdownMenuId};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import{usePickaxeContext as n}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as s}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useRef as o,useMemo as r,useState as a}from"react";import c from"./Dropdown.js";import l from"../../../../common/cn.js";const p=({field:p,update:u})=>{const{colors:d,isRtl:m,translations:b}=n(),{setError:g}=s(),h=i(),f=o(null),x=r((()=>p.example.split("S3P32X")),[p.example]),[j,O]=a((()=>{const e=x.includes(p.input);return p.allowOther&&p.input&&!e?p.input:""})),y=r((()=>!!p.allowOther&&(!x.includes(p.input)&&""!==p.input)),[p.allowOther,p.input,x]);return e("div",Object.assign({className:"flex flex-col gap-y-3",dir:m?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[t("p",Object.assign({className:l(h.b3,"font-semibold opacity-70")},{children:p.main})),p.isRequired&&t("span",Object.assign({className:"select-none font-semibold",style:{color:d.error}},{children:"*"}))]})),t(c,Object.assign({id:p.id.replace(/[^A-Za-z]+/g,""),value:p.input,placeholder:(null==b?void 0:b["select-an-option"])||"Select an option",closeOnSelect:!1,maxToken:p.maxLength,isDropdown:p.isDropdown},{children:e("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[x.map(((n,s)=>e("div",Object.assign({className:"flex items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{g(""),u(Object.assign(Object.assign({},p),{input:e}))})(n)},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:p.input===n?d.accent:d.accent+"80"},p.input===n&&{backgroundColor:d.accent})},{children:t("div",{className:l("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",p.input===n&&"opacity-100"),style:{backgroundColor:d.accentText}})})),t("p",Object.assign({className:l(h.b2,"select-none")},{children:n}))]}),s))),p.allowOther&&e("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{g(""),u(Object.assign(Object.assign({},p),{input:j})),setTimeout((()=>{var e;return null===(e=f.current)||void 0===e?void 0:e.focus()}),0)}},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:y?d.accent:d.accent+"80"},y&&{backgroundColor:d.accent})},{children:t("div",{className:l("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",y&&"opacity-100"),style:{backgroundColor:d.accentText}})})),e("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e("p",Object.assign({className:l(h.b2,"select-none opacity-80 min-w-fit")},{children:[(null==b?void 0:b.other)||"Other",":"]})),t("input",{ref:f,type:"text",className:l(h.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:y?d.accent:"rgba(0,0,0,0.2)"},value:j,onChange:e=>{return t=e.target.value,g(""),O(t),void u(Object.assign(Object.assign({},p),{input:t}));var t},onFocus:()=>{y||u(Object.assign(Object.assign({},p),{input:j}))},placeholder:(null==b?void 0:b["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};export{p as default};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{usePickaxeContext as n}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as s}from"../../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as i}from"../../../../hooks/studio/useStyleFontSize.js";import{useRef as o,useMemo as r,useState as a}from"react";import c,{getDropdownMenuId as l}from"./Dropdown.js";import d from"../../../../common/cn.js";const p=({field:p,update:u})=>{const{colors:m,isRtl:b,translations:g}=n(),{setError:h}=s(),f=i(),x=o(null),j=r((()=>p.example.split("S3P32X")),[p.example]),[O,y]=a((()=>{const e=j.includes(p.input);return p.allowOther&&p.input&&!e?p.input:""})),v=r((()=>!!p.allowOther&&(!j.includes(p.input)&&""!==p.input)),[p.allowOther,p.input,j]);return e("div",Object.assign({className:"flex flex-col gap-y-3",dir:b?"rtl":"ltr"},{children:[e("div",Object.assign({className:"flex items-center gap-1"},{children:[t("p",Object.assign({className:d(f.b3,"font-semibold opacity-70")},{children:p.main})),p.isRequired&&t("span",Object.assign({className:"select-none font-semibold",style:{color:m.error}},{children:"*"}))]})),t(c,Object.assign({id:l(p.id),value:p.input,placeholder:(null==g?void 0:g["select-an-option"])||"Select an option",closeOnSelect:!1,maxToken:p.maxLength,isDropdown:p.isDropdown},{children:e("div",Object.assign({className:"flex flex-col items-start gap-y-3"},{children:[j.map(((n,s)=>e("div",Object.assign({className:"flex min-w-0 items-center gap-x-3 hover:cursor-pointer",onClick:()=>(e=>{h(""),u(Object.assign(Object.assign({},p),{input:e}))})(n)},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:p.input===n?m.accent:m.accent+"80"},p.input===n&&{backgroundColor:m.accent})},{children:t("div",{className:d("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",p.input===n&&"opacity-100"),style:{backgroundColor:m.accentText}})})),t("p",Object.assign({className:d(f.b2,"min-w-0 select-none break-words"),style:{overflowWrap:"anywhere"}},{children:n}))]}),s))),p.allowOther&&e("div",Object.assign({className:"flex w-full items-center gap-x-3 hover:cursor-pointer",onClick:()=>{h(""),u(Object.assign(Object.assign({},p),{input:O})),setTimeout((()=>{var e;return null===(e=x.current)||void 0===e?void 0:e.focus()}),0)}},{children:[t("div",Object.assign({className:"flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-full border-2",style:Object.assign({borderColor:v?m.accent:m.accent+"80"},v&&{backgroundColor:m.accent})},{children:t("div",{className:d("h-2 w-2 shrink-0 transition-opacity opacity-0 ease-in-out duration-200 rounded-full",v&&"opacity-100"),style:{backgroundColor:m.accentText}})})),e("div",Object.assign({className:"flex flex-1 items-center gap-2"},{children:[e("p",Object.assign({className:d(f.b2,"select-none opacity-80 min-w-fit")},{children:[(null==g?void 0:g.other)||"Other",":"]})),t("input",{ref:x,type:"text",className:d(f.b2,"flex-1 bg-transparent border-b outline-none w-full pb-0.5 transition-colors duration-200","cursor-text"),style:{borderColor:v?m.accent:"rgba(0,0,0,0.2)"},value:O,onChange:e=>{return t=e.target.value,h(""),y(t),void u(Object.assign(Object.assign({},p),{input:t}));var t},onFocus:()=>{v||u(Object.assign(Object.assign({},p),{input:O}))},placeholder:(null==g?void 0:g["type-your-answer"])||"Type your answer..."})]}))]}))]}))}))]}))};export{p as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as s}from"react/jsx-runtime";import{useState as n,useRef as i,useMemo as o}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as a}from"../../Addons/Auth/hooks/useAuthContext.js";import{useResponseContext as l}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as c}from"../../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as u}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{extractUrlsFromText as p,initializeEmbedUserId as m}from"../../../../common/utils.js";import{encode as g}from"@nem035/gpt-3-encoder";import{createParser as f}from"eventsource-parser";import h from"../../common/PickaxeBranding.js";import v from"../../common/PickaxeButton.js";import b from"../../../../common/error.js";import{getValidationFailure as y}from"../../../../common/validation.js";const j=({questions:j,resetQuestions:O})=>{var x;const{origin:w,pickaxeId:I,sender:S,senderType:k,portalId:C,deploymentId:N,pickaxe:E,misc:P,translations:_,isRtl:A,setSessionId:T,setIsNewChat:U,setValidationStatus:D,setValidationUpgradeGroups:L,setValidationUpgradeUrl:q,onGenerateComplete:J}=r(),{token:B}=a(),{isGenerating:K,setResponse:R,setMessages:V,setStatus:W,setLimitData:X,setError:G,setIsSwitchedToChat:$}=l(),{documents:F,websiteLink:M,isUploading:Q,onWebsiteUpload:Y,setDocuments:z,setDocumentError:H}=d(),{scrollStartSession:Z,scrollEndSession:ee,scrollToTarget:te}=c({auto:!(null==E?void 0:E.enablechatresponses)}),{artifacts:se,currentPopupType:ne,setArtifacts:ie,setCurrentArtifact:oe}=u(),[re,ae]=n(!1),le=i(null),de=e=>{const t=y(e);return!!t&&(G(""),X(null),D(t.status),L(t.upgradeGroups),q(t.upgradeUrl),!0)},ce=o((()=>j.some((e=>("Short Answer"===e.type||"Long Answer"===e.type||"long"===e.type||"short"===e.type||"Checkbox"===e.type||"Knowledge Upload"===e.type||e.id.includes("documentupload"))&&e.input.length>0))),[j]);return t("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:A?"rtl":"ltr"},{children:[t("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[s(v,Object.assign({className:"px-5 min-h-[42px]",isDisabled:Q||K||re,onClick:()=>e(void 0,void 0,void 0,(function*(){var e,t,s;try{if(K||Q||re)return;G(""),H(""),X(null),R(null);const n=["Multiple Choice","Checkbox"];for(const e of j){if(g(e.input).length>e.maxLength&&!n.includes(e.type))throw new Error((null==_?void 0:_["response-too-long"])||"One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error((null==_?void 0:_["required-fields-missing"])||"You must fill out all required fields.")}const i=F.filter((e=>"finished"===e.status)),o=F.map((e=>e.name)),r=null!==(t=null===(e=null==E?void 0:E.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,a=j.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),l=p(M).filter((e=>!o.includes(e)));if(l.length){const e=l[l.length-1];ae(!0);const t=yield Y(e);t&&(i.push(t),yield new Promise((e=>setTimeout(e,5e3)))),ae(!1)}else if(a&&r&&!i.length)return void H((null==_?void 0:_["document-upload-required"])||"Please paste a valid website/video link or drag a file to add to the knowledge base.");const d=i.map((e=>e.documentId||"")).filter(Boolean),c=r&&d.length>0,u={};j.forEach((e=>{u[e.id]="Knowledge Upload"===e.type||e.id.includes("documentupload")?i.map((e=>e.name)).join(",")||"":e.input})),W("fetching"),Z(),te();const h=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,{method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:w,pickaxeId:I,senderType:k,valueObj:u},c&&{documentIds:d}),S&&{sender:S}),B&&{studioSessionToken:B}),!B&&!S&&{sender:m()}),C&&{portalId:C}),N&&{deploymentId:N}))}),v=yield h.json();if(!v.success){if(de(v))return;const e=new Error(v.error||v.message||(null==_?void 0:_["failed-to-start-generation"])||"Failed to start generation");throw v.limitData&&(e.limitData=v.limitData),e}if(!v.submissionId||!v.sessionId)throw new Error((null==_?void 0:_["failed-to-start-generation"])||"Failed to start generation");const b=v.submissionId,y=v.sessionId,O={sessionId:y,documentIds:c?d:[],question:{inputs:j.map((e=>({id:e.id,question:e.main,answer:e.input}))),responseParts:[]},messageCount:0,sentAt:new Date};R(O),(null==E?void 0:E.enablechatresponses)&&(T(y),U(!1),$(!0),V([{id:0,role:"assistant",parts:[],documentIds:[]}])),c&&z([]),W("streaming"),le.current=new AbortController;const x=[];let P=[...null!=se?se:[]],A=0,D=!1,L="";for(;!D;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${A}`,{signal:null===(s=le.current)||void 0===s?void 0:s.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader(),n=new TextDecoder,i=f({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&A++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==_?void 0:_["something-went-wrong"])||"Something went wrong.";return de(t)||G(s),void(D=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("text-start"===n.type)L="",x.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)L+=n.delta,x[x.length-1].content=L;else if("text-end"===n.type)L="";else if("reasoning-start"===n.type)L="",x.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)L+=n.delta,x[x.length-1].content=L;else if("reasoning-end"===n.type)L="";else if(n.type.startsWith("data-")){const e=n;x.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}const i=Object.assign(Object.assign({},O),{question:Object.assign(Object.assign({},O.question),{responseParts:[...x]})});R(i),(null==E?void 0:E.enablechatresponses)&&V([{id:0,role:"assistant",parts:[...x],documentIds:[]}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);P=P.filter((e=>!(e.id===t.id&&e.version===t.version))),P.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ie([...P]),ne.startsWith("inline")||oe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);P=P.filter((e=>!(e.id===t.id&&e.version===t.version))),P.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),ie([...P]),ne.startsWith("inline")||oe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);P=P.filter((e=>!(e.id===t.id&&e.version===t.version))),P.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),ie([...P]),ne.startsWith("inline")||oe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");P=P.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),ie([...P])}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);ie(P.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}}else D=!0}});for(;;){const{value:e,done:s}=yield t.read();if(s)break;i.feed(n.decode(e))}D||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("AbortError"===e.name)return void(D=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==J||J(y)}catch(e){let t=b(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==_?void 0:_["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),de(t)||G(t),te()}finally{W("idle"),ae(!1),ee()}}))},{children:re?(null==_?void 0:_.processing)||"Processing...":Q?(null==_?void 0:_.uploading)||"Uploading...":K?(null==_?void 0:_.loading)||"Loading...":null!==(x=null==E?void 0:E.submittext)&&void 0!==x?x:"Submit"})),ce&&s(v,Object.assign({variant:"transparent-text",className:"min-h-[42px] px-5",isDisabled:Q||K||re,onClick:O},{children:(null==_?void 0:_["form.clear-form"])||(null==_?void 0:_["clear-form"])||"Clear form"}))]})),!P.isWhiteLabel&&s(h,{containerClassName:"justify-end"})]}))};export{j as default};
1
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as t,jsx as s}from"react/jsx-runtime";import{useState as n,useRef as i,useMemo as o}from"react";import{usePickaxeContext as r}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as a}from"../../Addons/Auth/hooks/useAuthContext.js";import{useResponseContext as l}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{useScroll as c}from"../../Addons/Scroll/hooks/useScroll.js";import{useArtifactContext as u}from"../../Addons/Artifact/hooks/useArtifactContext.js";import{extractUrlsFromText as p,initializeEmbedUserId as m}from"../../../../common/utils.js";import{encode as f}from"@nem035/gpt-3-encoder";import{createParser as g}from"eventsource-parser";import v from"../../common/PickaxeBranding.js";import h from"../../common/PickaxeButton.js";import b from"../../../../common/error.js";import{getValidationFailure as y}from"../../../../common/validation.js";const j=({questions:j,resetQuestions:O})=>{var x;const{origin:w,pickaxeId:I,sender:S,senderType:k,portalId:C,deploymentId:E,pickaxe:N,misc:A,translations:P,isRtl:_,setSessionId:T,setIsNewChat:D,setValidationStatus:U,setValidationUpgradeGroups:L,setValidationUpgradeUrl:q,setAccessGroup:B,onGenerateComplete:J}=r(),{token:K}=a(),{isGenerating:R,setResponse:V,setMessages:W,setStatus:X,setLimitData:G,setError:$,setIsSwitchedToChat:F}=l(),{documents:M,websiteLink:Q,isUploading:Y,onWebsiteUpload:z,setDocuments:H,setDocumentError:Z}=d(),{scrollStartSession:ee,scrollEndSession:te,scrollToTarget:se}=c({auto:!(null==N?void 0:N.enablechatresponses)}),{artifacts:ne,currentPopupType:ie,setArtifacts:oe,setCurrentArtifact:re}=u(),[ae,le]=n(!1),de=i(null),ce=e=>{const t=y(e);return!!t&&($(""),G(null),U(t.status),B(t.accessGroup),L(t.upgradeGroups),q(t.upgradeUrl),!0)},ue=o((()=>j.some((e=>("Short Answer"===e.type||"Long Answer"===e.type||"long"===e.type||"short"===e.type||"Checkbox"===e.type||"Knowledge Upload"===e.type||e.id.includes("documentupload"))&&e.input.length>0))),[j]);return t("div",Object.assign({className:"mt-4 flex flex-wrap justify-between gap-4 items-center",dir:_?"rtl":"ltr"},{children:[t("div",Object.assign({className:"flex items-center flex-grow flex-wrap gap-2"},{children:[s(h,Object.assign({className:"px-5 min-h-[42px]",isDisabled:Y||R||ae,onClick:()=>e(void 0,void 0,void 0,(function*(){var e,t,s;try{if(R||Y||ae)return;$(""),Z(""),G(null),V(null);const n=["Multiple Choice","Checkbox"];for(const e of j){if(f(e.input).length>e.maxLength&&!n.includes(e.type))throw new Error((null==P?void 0:P["response-too-long"])||"One or more of your responses is too long!");if(e.isRequired&&!e.input.trim()&&"userinput:documentupload"!==e.id)throw new Error((null==P?void 0:P["required-fields-missing"])||"You must fill out all required fields.")}const i=M.filter((e=>"finished"===e.status)),o=M.map((e=>e.name)),r=null!==(t=null===(e=null==N?void 0:N.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==t&&t,a=j.some((e=>"userinput:documentupload"===e.id&&e.isRequired)),l=p(Q).filter((e=>!o.includes(e)));if(l.length){const e=l[l.length-1];le(!0);const t=yield z(e);t&&(i.push(t),yield new Promise((e=>setTimeout(e,5e3)))),le(!1)}else if(a&&r&&!i.length)return void Z((null==P?void 0:P["document-upload-required"])||"Please paste a valid website/video link or drag a file to add to the knowledge base.");const d=i.map((e=>e.documentId||"")).filter(Boolean),c=r&&d.length>0,u={};j.forEach((e=>{u[e.id]="Knowledge Upload"===e.type||e.id.includes("documentupload")?i.map((e=>e.name)).join(",")||"":e.input})),X("fetching"),ee(),se();const v=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/submit`,{method:"POST",headers:Object.assign(Object.assign({"Content-Type":"application/json"},process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN&&{"x-pickaxe-session-token":process.env.NEXT_PUBLIC_PICKAXE_SESSION_TOKEN}),{"x-request-sent-at":(new Date).toISOString()}),body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:w,pickaxeId:I,senderType:k,valueObj:u},c&&{documentIds:d}),S&&{sender:S}),K&&{studioSessionToken:K}),!K&&!S&&{sender:m()}),C&&{portalId:C}),E&&{deploymentId:E}))}),h=yield v.json();if(!h.success){const e=new Error(h.error||h.message||(null==P?void 0:P["failed-to-start-generation"])||"Failed to start generation");if(h.limitData)throw e.limitData=h.limitData,e;if(ce(h))return;throw e}if(!h.submissionId||!h.sessionId)throw new Error((null==P?void 0:P["failed-to-start-generation"])||"Failed to start generation");const b=h.submissionId,y=h.sessionId,O={sessionId:y,documentIds:c?d:[],question:{inputs:j.map((e=>({id:e.id,question:e.main,answer:e.input}))),responseParts:[]},messageCount:0,sentAt:new Date};V(O),(null==N?void 0:N.enablechatresponses)&&(T(y),D(!1),F(!0),W([{id:0,role:"assistant",parts:[],documentIds:[]}])),c&&H([]),X("streaming"),de.current=new AbortController;const x=[];let A=[...null!=ne?ne:[]],_=0,U=!1,L="";for(;!U;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${b}?index=${_}`,{signal:null===(s=de.current)||void 0===s?void 0:s.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader(),n=new TextDecoder,i=g({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&_++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return G(t.limitData),$(""),void(U=!0);const s=t.error||t.message||(null==P?void 0:P["something-went-wrong"])||"Something went wrong.";return ce(t)||$(s),void(U=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("text-start"===n.type)L="",x.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)L+=n.delta,x[x.length-1].content=L;else if("text-end"===n.type)L="";else if("reasoning-start"===n.type)L="",x.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)L+=n.delta,x[x.length-1].content=L;else if("reasoning-end"===n.type)L="";else if(n.type.startsWith("data-")){const e=n;x.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}const i=Object.assign(Object.assign({},O),{question:Object.assign(Object.assign({},O.question),{responseParts:[...x]})});V(i),(null==N?void 0:N.enablechatresponses)&&W([{id:0,role:"assistant",parts:[...x],documentIds:[]}])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),oe([...A]),ie.startsWith("inline")||re({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),oe([...A]),ie.startsWith("inline")||re({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);A=A.filter((e=>!(e.id===t.id&&e.version===t.version))),A.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),oe([...A]),ie.startsWith("inline")||re({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");A=A.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),oe([...A])}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);oe(A.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}}else U=!0}});for(;;){const{value:e,done:s}=yield t.read();if(s)break;i.feed(n.decode(e))}U||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if(e instanceof Error&&"AbortError"===e.name)return void(U=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==J||J(y)}catch(e){if((e=>e instanceof Error&&Boolean(e.limitData))(e))return G(e.limitData),$(""),void se();let t=b(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==P?void 0:P["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),ce(t)||$(t),se()}finally{X("idle"),le(!1),te()}}))},{children:ae?(null==P?void 0:P.processing)||"Processing...":Y?(null==P?void 0:P.uploading)||"Uploading...":R?(null==P?void 0:P.loading)||"Loading...":null!==(x=null==N?void 0:N.submittext)&&void 0!==x?x:"Submit"})),ue&&s(h,Object.assign({variant:"transparent-text",className:"min-h-[42px] px-5",isDisabled:Y||R||ae,onClick:O},{children:(null==P?void 0:P["form.clear-form"])||(null==P?void 0:P["clear-form"])||"Clear form"}))]})),!A.isWhiteLabel&&s(v,{containerClassName:"justify-end"})]}))};export{j as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsx as s,jsxs as o}from"react/jsx-runtime";import{useState as t,useMemo as i,useEffect as r}from"react";import{AnimatePresence as l}from"framer-motion";import{usePickaxeContext as n}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as a}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as c}from"../../../hooks/studio/useStyleFontSize.js";import{isInIframe as d,buildUpgradeUrl as u}from"../../../common/utils.js";import m from"../../Icons/circle-exclamation.svg.js";import p from"../../Core/SpringTransition.js";import v from"../../Core/HtmlRenderer.js";import f from"./PickaxeButton.js";import x from"../../../common/cn.js";import b from"../../../common/api/pickaxe.js";import{useAuthContext as g}from"../Addons/Auth/hooks/useAuthContext.js";import h from"./AccessGroupCardPreview.js";import{useStudio as y}from"../../../hooks/studio/useStudio.js";import{currencyOptions as j}from"./PickaxeCurrency.js";const k=({price:e,uses:t,isCredits:i,isSelected:r,costPerRun:l,onClick:n,colors:a,currencySymbol:c})=>{const d=`${c}${e}`,u={backgroundColor:a.secondary,color:a.secondaryText,borderColor:r?a.secondaryText:"rgba(0,0,0,0.1)"},m=i&&l?Math.ceil(t/l):0;return o("button",i?Object.assign({onClick:n,className:x("flex min-w-[200px] shrink-0 cursor-pointer flex-col rounded-[16px] px-6 py-5 text-left transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:u},{children:[o("div",Object.assign({className:"mb-4 flex items-center gap-2"},{children:[s("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:d})),o("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," credits"]}))]})),s("div",{className:"mb-4 h-[1px] w-full",style:{backgroundColor:a.secondaryText,opacity:.15}}),o("span",Object.assign({className:"text-[14px] italic opacity-70"},{children:["~ ",void 0!==m&&m>0?m.toLocaleString():"..."," ","runs"]}))]}):Object.assign({onClick:n,className:x("flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-[16px] px-5 py-3 transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:u},{children:[s("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:d})),o("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",t.toLocaleString()," uses"]}))]}))},w=(e,s)=>{var o,t;const i=Number(s?null!==(o=e.credits)&&void 0!==o?o:e.uses:null!==(t=e.uses)&&void 0!==t?t:e.credits);return Number.isFinite(i)?i:0},C=e=>{const s=Number(e.price);return Number.isFinite(s)?s:0},N=({className:N,iconClassName:O,htmlClassName:S})=>{var U,A,_;const{colors:I,pickaxe:L,sender:R,translations:P,setValidationStatus:G,setClientSecret:T,setStripeAccountId:B}=n(),{token:F,setRedirectUrl:$}=g(),{limitData:q}=a(),{studio:M}=y(),z=c(),[D,E]=t(0),[H,V]=t(null),J=null==M?void 0:M.data,K=null==J?void 0:J.usage,Q=Boolean(null==K?void 0:K.isCredits),W=null!==(A=null===(U=j.find((e=>e.id===(null==J?void 0:J.currency))))||void 0===U?void 0:U.symbol)&&void 0!==A?A:j[0].symbol,X=i((()=>{const e=Q?null==K?void 0:K.availableCredits:null==K?void 0:K.availableUses;if(Array.isArray(e)&&e.length>0)return e;const s=null==q?void 0:q.buyUses;return Array.isArray(s)?s:[]}),[Q,null==q?void 0:q.buyUses,null==K?void 0:K.availableCredits,null==K?void 0:K.availableUses]);r((()=>{E(0)}),[X]);const Y=X.length>0,Z=Y?X[D]:void 0,ee=Z?w(Z,Q):0,se=Z?C(Z):0;r((()=>{let s=!0;return e(void 0,void 0,void 0,(function*(){if(null==J?void 0:J.workspaceId)try{const e=yield b.get(`/cost_per_run?workspaceId=${J.workspaceId}`,{withCredentials:!1});if(s){const s=1e4*e.data.costPerRun||0;V(s)}}catch(e){console.error("Failed to fetch cost per run:",e),s&&V(0)}else V(0)})),()=>{s=!1}}),[null==J?void 0:J.workspaceId,V]);const oe=null==q?void 0:q.customLink,te=null==q?void 0:q.limitCTA,ie=Array.isArray(null==q?void 0:q.upgradeGroups)&&(null==q?void 0:q.upgradeGroups)&&(null==q?void 0:q.upgradeGroups.length)>0;return q?s(l,{children:o(p,Object.assign({className:x("flex flex-col gap-5 w-full",N)},{children:[o("div",Object.assign({className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between rounded-lg p-3 bg-opacity-5",style:{backgroundColor:I.secondary}},{children:[o("div",Object.assign({className:"flex gap-3 items-start"},{children:[s(m,{className:x("h-5 w-5 shrink-0 mt-0.5",O),style:{color:I.accent}}),s(v,{className:x(z.b2,"font-semibold leading-relaxed text-sm",S),style:{color:I.text},html:q.limitMessage||""})]})),oe&&s(f,Object.assign({variant:"primary",className:"whitespace-nowrap min-h-[32px] w-full sm:w-auto text-sm",onClick:()=>e(void 0,void 0,void 0,(function*(){if(d()){if(!F)return $(oe||null),void G("login_required");window.open(oe)}else{const e=u({baseUrl:oe,redirectUrl:document.URL});e&&(window.location.href=e)}}))},{children:te}))]})),ie&&o("div",Object.assign({className:"flex flex-col gap-2"},{children:[s("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:I.text}},{children:(null==P?void 0:P["available-plans"])||"Available Plans"})),s("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-4 pt-1 snap-x scrollbar-thin"},{children:null===(_=q.upgradeGroups)||void 0===_?void 0:_.map(((e,o)=>s(h,{data:e},e.accessGroupId||o)))}))]})),Y&&Z&&o("div",Object.assign({className:"flex flex-col gap-3"},{children:[o("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:I.text}},{children:[(null==P?void 0:P.buy)||"Buy"," ",Q?(null==P?void 0:P.credits)||"Credits":(null==P?void 0:P.uses)||"Uses"]})),s("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-2 pt-1 snap-x scrollbar-thin"},{children:X.map(((e,o)=>s(k,{price:C(e),uses:w(e,Q),isCredits:Q,costPerRun:H||void 0,isSelected:o===D,onClick:()=>E(o),colors:I,currencySymbol:W},o)))})),o(f,Object.assign({variant:"primary",className:"w-full py-3 text-sm font-bold shadow-md",onClick:()=>e(void 0,void 0,void 0,(function*(){if(F){var s,o;s=ee,o=se,e(void 0,void 0,void 0,(function*(){try{const e=yield b.post("/get_extra_usage_payment_link",{data:{sender:R||void 0,studioSessionToken:F,studioId:null==L?void 0:L.studioid,cost:o,isEmbed:d(),extraUses:s,successUrl:document.URL}}),{success:t,url:i,clientSecret:r,stripeAccountId:l,error:n}=e.data;t?d()?r&&l?(B(l),T(r),G("stripe_checkout")):i&&window.open(i,"_blank"):i&&(window.location.href=i):alert(n)}catch(e){alert(e)}}))}else{const e=q.limitLink||oe;if(d())$(e||null),G("login_required");else{const s=u({baseUrl:e,redirectUrl:document.URL});s&&(window.location.href=s)}}}))},{children:[(null==P?void 0:P.buy)||"Buy"," ",ee.toLocaleString()," ",Q?(null==P?void 0:P.credits)||"Credits":(null==P?void 0:P.uses)||"Uses"," ","for ",W,se]}))]}))]}))}):null};export{N as default};
1
+ import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsx as o,jsxs as s}from"react/jsx-runtime";import{useState as i,useMemo as t,useEffect as r}from"react";import{AnimatePresence as l}from"framer-motion";import{usePickaxeContext as n}from"../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as a}from"../../../hooks/pickaxe/useResponseContext.js";import{useStyleFontSize as c}from"../../../hooks/studio/useStyleFontSize.js";import{isInIframe as d,buildUpgradeUrl as u}from"../../../common/utils.js";import m from"../../Icons/circle-exclamation.svg.js";import p from"../../Core/SpringTransition.js";import v from"../../Core/HtmlRenderer.js";import f from"./PickaxeButton.js";import x from"../../../common/cn.js";import b from"../../../common/api/pickaxe.js";import{useAuthContext as g}from"../Addons/Auth/hooks/useAuthContext.js";import h from"./AccessGroupCardPreview.js";import{useStudio as y}from"../../../hooks/studio/useStudio.js";import{currencyOptions as k}from"./PickaxeCurrency.js";const j=({price:e,uses:i,isCredits:t,isSelected:r,costPerRun:l,onClick:n,colors:a,currencySymbol:c})=>{const d=`${c}${e}`,u={backgroundColor:a.secondary,color:a.secondaryText,borderColor:r?a.secondaryText:"rgba(0,0,0,0.1)"},m=t&&l?Math.ceil(i/l):0;return s("button",t?Object.assign({onClick:n,className:x("flex min-w-[200px] shrink-0 cursor-pointer flex-col rounded-[16px] px-6 py-5 text-left transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:u},{children:[s("div",Object.assign({className:"mb-4 flex items-center gap-2"},{children:[o("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:d})),s("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",i.toLocaleString()," credits"]}))]})),o("div",{className:"mb-4 h-[1px] w-full",style:{backgroundColor:a.secondaryText,opacity:.15}}),s("span",Object.assign({className:"text-[14px] italic opacity-70"},{children:["~ ",void 0!==m&&m>0?m.toLocaleString():"..."," ","runs"]}))]}):Object.assign({onClick:n,className:x("flex shrink-0 cursor-pointer items-center justify-center gap-2 rounded-[16px] px-5 py-3 transition-all duration-200",r?"border-2 shadow-sm":"border opacity-80 hover:opacity-100"),style:u},{children:[o("span",Object.assign({className:"text-[24px] font-semibold tracking-tight"},{children:d})),s("span",Object.assign({className:"text-[14px] font-light opacity-80"},{children:["/",i.toLocaleString()," uses"]}))]}))},w=(e,o)=>{var s,i;const t=Number(o?null!==(s=e.credits)&&void 0!==s?s:e.uses:null!==(i=e.uses)&&void 0!==i?i:e.credits);return Number.isFinite(t)?t:0},C=e=>{const o=Number(e.price);return Number.isFinite(o)?o:0},N=({className:N,iconClassName:O,htmlClassName:S})=>{var A,U,_,I;const{colors:L,pickaxe:P,sender:R,translations:G,setValidationStatus:T,setClientSecret:B,setStripeAccountId:F}=n(),{token:$,setRedirectUrl:M}=g(),{limitData:q}=a(),{studio:z}=y(),D=c(),[E,H]=i(0),[V,J]=i(null),K=null==z?void 0:z.data,Q=null==K?void 0:K.usage,W=Boolean(null==Q?void 0:Q.isCredits),X=null!==(U=null===(A=k.find((e=>e.id===(null==K?void 0:K.currency))))||void 0===A?void 0:A.symbol)&&void 0!==U?U:k[0].symbol,Y="string"==typeof(null==q?void 0:q.customLink)?q.customLink.trim():"",Z=t((()=>{if(Y)return[];const e=W?null==Q?void 0:Q.availableCredits:null==Q?void 0:Q.availableUses;if(Array.isArray(e)&&e.length>0)return e;const o=null==q?void 0:q.buyUses;return Array.isArray(o)?o:[]}),[Y,W,null==q?void 0:q.buyUses,null==Q?void 0:Q.availableCredits,null==Q?void 0:Q.availableUses]);r((()=>{H(0)}),[Z]);const ee=Z.length>0,oe=ee?Z[E]:void 0,se=oe?w(oe,W):0,ie=oe?C(oe):0;r((()=>{let o=!0;return e(void 0,void 0,void 0,(function*(){if(Y)J(null);else if(null==K?void 0:K.workspaceId)try{const e=yield b.get(`/cost_per_run?workspaceId=${K.workspaceId}`,{withCredentials:!1});if(o){const o=1e4*e.data.costPerRun||0;J(o)}}catch(e){console.error("Failed to fetch cost per run:",e),o&&J(0)}else J(0)})),()=>{o=!1}}),[Y,null==K?void 0:K.workspaceId,J]);const te=Y,re=(null===(_=null==q?void 0:q.limitCTA)||void 0===_?void 0:_.trim())||(null==G?void 0:G["pricing.upgrade"])||(null==G?void 0:G.upgrade)||"Upgrade",le=!Y&&Array.isArray(null==q?void 0:q.upgradeGroups)&&(null==q?void 0:q.upgradeGroups)&&(null==q?void 0:q.upgradeGroups.length)>0;return q?o(l,{children:s(p,Object.assign({className:x("flex flex-col gap-5 w-full",N)},{children:[s("div",Object.assign({className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between rounded-lg p-3 bg-opacity-5",style:{backgroundColor:L.secondary}},{children:[s("div",Object.assign({className:"flex gap-3 items-start"},{children:[o(m,{className:x("h-5 w-5 shrink-0 mt-0.5",O),style:{color:L.accent}}),o(v,{className:x(D.b2,"font-semibold leading-relaxed text-sm",S),style:{color:L.text},html:q.limitMessage||""})]})),te&&o(f,Object.assign({variant:"primary",className:"whitespace-nowrap min-h-[32px] w-full sm:w-auto text-sm",onClick:()=>e(void 0,void 0,void 0,(function*(){window.open(te,"_blank","noopener,noreferrer")}))},{children:re}))]})),le&&s("div",Object.assign({className:"flex flex-col gap-2"},{children:[o("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:L.text}},{children:(null==G?void 0:G["available-plans"])||"Available Plans"})),o("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-4 pt-1 snap-x scrollbar-thin"},{children:null===(I=q.upgradeGroups)||void 0===I?void 0:I.map(((e,s)=>o(h,{data:e},e.accessGroupId||s)))}))]})),ee&&oe&&s("div",Object.assign({className:"flex flex-col gap-3"},{children:[s("h3",Object.assign({className:"text-xs font-bold opacity-70 uppercase px-1",style:{color:L.text}},{children:[(null==G?void 0:G.buy)||"Buy"," ",W?(null==G?void 0:G.credits)||"Credits":(null==G?void 0:G.uses)||"Uses"]})),o("div",Object.assign({className:"flex flex-row gap-3 overflow-x-auto pb-2 pt-1 snap-x scrollbar-thin"},{children:Z.map(((e,s)=>o(j,{price:C(e),uses:w(e,W),isCredits:W,costPerRun:V||void 0,isSelected:s===E,onClick:()=>H(s),colors:L,currencySymbol:X},s)))})),s(f,Object.assign({variant:"primary",className:"w-full py-3 text-sm font-bold shadow-md",onClick:()=>e(void 0,void 0,void 0,(function*(){if($){var o,s;o=se,s=ie,e(void 0,void 0,void 0,(function*(){try{const e=yield b.post("/get_extra_usage_payment_link",{data:{sender:R||void 0,studioSessionToken:$,studioId:null==P?void 0:P.studioid,cost:s,isEmbed:d(),extraUses:o,successUrl:document.URL}}),{success:i,url:t,clientSecret:r,stripeAccountId:l,error:n}=e.data;i?d()?r&&l?(F(l),B(r),T("stripe_checkout")):t&&window.open(t,"_blank"):t&&(window.location.href=t):alert(n)}catch(e){alert(e)}}))}else{const e=q.limitLink||te;if(d())M(e||null),T("login_required");else{const o=u({baseUrl:e,redirectUrl:document.URL});o&&(window.location.href=o)}}}))},{children:[(null==G?void 0:G.buy)||"Buy"," ",se.toLocaleString()," ",W?(null==G?void 0:G.credits)||"Credits":(null==G?void 0:G.uses)||"Uses"," ","for ",X,ie]}))]}))]}))}):null};export{N as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../_virtual/_tslib.js";import{jsx as s,jsxs as t}from"react/jsx-runtime";import{usePickaxe as o}from"../../hooks/pickaxe/usePickaxe.js";import{useState as i,useMemo as r,useEffect as a}from"react";import{usePickaxeContext as l}from"../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as n}from"./Addons/Auth/hooks/useAuthContext.js";import{useAuthBootstrap as c}from"./Addons/Auth/hooks/useAuthBootstrap.js";import{useResponseContext as d}from"../../hooks/pickaxe/useResponseContext.js";import{useDocumentContext as u}from"./Addons/Document/hooks/useDocumentContext.js";import{useArtifactContext as m}from"./Addons/Artifact/hooks/useArtifactContext.js";import{v4 as p}from"uuid";import{ScrollProvider as f}from"./Addons/Scroll/Provider.js";import x from"./common/PickaxeSkeleton.js";import h from"./Chat/index.js";import v from"./Form/index.js";import g from"./Addons/Auth/index.js";import j from"../../common/cn.js";import b from"../../common/api/pickaxe.js";import{getValidationFailure as k}from"../../common/validation.js";import y from"./common/AccessGroupCardPreview.js";import{Avatar as w,AvatarImage as N,AvatarFallback as O}from"./common/PickaxeAvatar.js";import _ from"../Icons/lock.svg.js";import{EmbeddedCheckoutProvider as A,EmbeddedCheckout as I}from"../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js";import{loadStripe as C}from"../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js";const S=({className:e})=>s("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s("polyline",{points:"15 18 9 12 15 6"})})),q=({pickaxeId:q,className:P})=>{const{sessionId:U,styles:G,colors:T,responsiveBy:L,deploymentType:R,isNewChat:E,isEmbed:B,opacity:D,deploymentId:$,sender:F,portalId:V,validationStatus:M,validationUpgradeGroups:W,validationUpgradeUrl:z,stripeAccountId:H,clientSecret:J,translations:K,preventInitialSessionId:X,setClientSecret:Y,setStripeAccountId:Q,setValidationStatus:Z,setValidationUpgradeGroups:ee,setValidationUpgradeUrl:se,setContextId:te,setPickaxeId:oe,setSessionId:ie,setPickaxe:re,setAccessGroup:ae}=l(),{isSent:le,token:ne,isAuthBootstrapComplete:ce}=n(),{setMessages:de,setResponse:ue,setError:me,setLimitData:pe,setIsSwitchedToChat:fe}=d(),{setDocumentError:xe}=u(),{setCurrentArtifact:he}=m(),[ve,ge]=i(!1),je=o();c();const be="chat-input"===R&&E&&!le,ke=r((()=>H?C(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:H}):null),[H]);a((()=>{oe(q)}),[q]);a((()=>{if(!$&&!V||!je.data)return;if(!ce)return;if("stripe_checkout"===M)return;e(void 0,void 0,void 0,(function*(){var e;Z("loading");try{const s=yield b.post("/validate_studio_deployment",{data:{deploymentId:$,sender:F||void 0,studioSessionToken:ne,portalId:V,studioId:null===(e=je.data)||void 0===e?void 0:e.studioid}});if(s.data.success)Z("success"),ee([]),se(null),ae(s.data.accessGroup);else{const e=k(s.data);if(!e)return Z("login_required"),ee([]),void se(null);Z(e.status),ee(e.upgradeGroups),se(e.upgradeUrl),ge(!0)}}catch(e){console.error("Failed to validate deployment:",e),Z("success")}}))}),[$,ce,F,ne,V,je.data]),a((()=>{if(!je.data)return;const e=je.data.chatflag;X||ie(e?p():""),te(p()),e?de([]):ue(null),me(""),xe(""),pe(null),he(null),fe(!1),re(je.data),ge(!0)}),[je.data]),a((()=>{me(""),xe(""),pe(null),de([]),ue(null),he(null)}),[U]);const ye=r((()=>{const e=null!=D?D:1;if(!T.primary||!T.primary.startsWith("#")||e<0||e>1)return T.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${T.primary}${s}`}),[T.primary,D]);if(!je.data)return null;return s("div",Object.assign({className:j("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===G.theme&&"dark",P),style:Object.assign({backgroundColor:be?"transparent":ye,color:T.text},G.font&&"Real Head Pro"!==G.font&&{fontFamily:G.font})},{children:(()=>{var o,i;if("stripe_checkout"===M&&J&&ke)return t("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:T.secondary||"#ffffff",color:T.secondaryText||"#000000"}},{children:[s("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:t("button",Object.assign({onClick:()=>{Y&&Y(null),Q&&Q(null),Z("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:T.text}},{children:[s(S,{className:"w-5 h-5"}),s("span",{children:(null==K?void 0:K.back)||"Back"})]}))})),s("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s(A,Object.assign({stripe:ke,options:{clientSecret:J}},{children:s(I,{})}))}))]}));if(je.isLoading||!ve||"loading"===M)return s("div",Object.assign({className:j("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===L?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:t("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s(x,{className:"w-[72px] h-[72px]"}),s(x,{className:"h-[20px] mt-6 w-full"}),s(x,{className:"h-[20px] mt-2 w-full"}),s(x,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s(x,{className:j("w-full min-h-[48px]","viewport"===L?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===M){const e=W.length>0;return s("div",Object.assign({className:"flex h-full min-h-0 w-full items-start justify-center overflow-y-auto p-4"},{children:t("div",e?Object.assign({className:"flex w-full max-w-4xl flex-col items-center gap-6 py-6"},{children:[t("div",Object.assign({className:"max-w-[640px] text-center"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2 break-words"},{children:(null==K?void 0:K["upgrade-required"])||"Upgrade Required"})),s("p",Object.assign({className:"break-words opacity-80"},{children:(null==K?void 0:K["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s("div",Object.assign({className:"flex w-full flex-wrap justify-center gap-4"},{children:W.map(((e,t)=>s(y,{data:e,upgradeUrl:z},e.accessGroupId||e.id||t)))}))]}):Object.assign({className:"m-auto text-center"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==K?void 0:K["access-locked"])||"Access Locked"})),s("p",Object.assign({className:"opacity-80"},{children:(null==K?void 0:K["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===M&&B?s(g,{}):"login_required"!==M||B?"access_denied"===M?t("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[t(w,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s(N,{src:null===(o=je.data)||void 0===o?void 0:o.coverphoto,alt:`${null===(i=je.data)||void 0===i?void 0:i.formtitle} Logo`}),s(O,{})]})),t("div",Object.assign({className:"text-center mb-6"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==K?void 0:K["access-denied"])||"Access Denied"})),t("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s(_,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s("p",Object.assign({className:"ml-1"},{children:(null==K?void 0:K["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:T.accent,color:T.accentText,borderRadius:G.cornerRadius},onClick:()=>{e(void 0,void 0,void 0,(function*(){var e,s;const t=W.map((e=>e.accessGroupId));try{const o=yield b.post("/request_access",{data:{sender:F||void 0,studioSessionToken:ne,studioId:null===(e=je.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=je.data)||void 0===s?void 0:s.formid,deploymentId:$,accessGroupIds:t})}});o.data.success?alert((null==K?void 0:K["access-requested-successfully"])||"Successfully requested access!"):alert(o.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==K?void 0:K["request-access"])||"Request Access"})),s("span",Object.assign({className:"mt-4 mb-2"},{children:(null==K?void 0:K.or)||"or"})),s("span",Object.assign({className:"font-medium text-lg"},{children:(null==K?void 0:K["sign-in-with-different-account"])||"Sign in with a different account"}))]})):s(f,U?{children:s(h,{})}:{children:s(v,{})}):s("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:t("div",Object.assign({className:"text-center mb-8"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==K?void 0:K["access-denied"])||"Access Denied"})),s("p",Object.assign({className:"opacity-80"},{children:(null==K?void 0:K["login-is-required"])||"Login is required."}))]}))}))})()}))};export{q as Pickaxe};
1
+ import{__awaiter as e}from"../../_virtual/_tslib.js";import{jsx as s,jsxs as t}from"react/jsx-runtime";import{usePickaxe as i}from"../../hooks/pickaxe/usePickaxe.js";import{useState as o,useMemo as r,useEffect as a}from"react";import{usePickaxeContext as l}from"../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as n}from"./Addons/Auth/hooks/useAuthContext.js";import{useAuthBootstrap as c}from"./Addons/Auth/hooks/useAuthBootstrap.js";import{useResponseContext as d}from"../../hooks/pickaxe/useResponseContext.js";import{useDocumentContext as u}from"./Addons/Document/hooks/useDocumentContext.js";import{useArtifactContext as m}from"./Addons/Artifact/hooks/useArtifactContext.js";import{v4 as p}from"uuid";import{ScrollProvider as f}from"./Addons/Scroll/Provider.js";import x from"./common/PickaxeSkeleton.js";import g from"./Chat/index.js";import h from"./Form/index.js";import v from"./Addons/Auth/index.js";import j from"../../common/cn.js";import b from"../../common/api/pickaxe.js";import{getValidationFailure as k}from"../../common/validation.js";import y from"./common/AccessGroupCardPreview.js";import w from"./common/PickaxeButton.js";import{Avatar as N,AvatarImage as O,AvatarFallback as A}from"./common/PickaxeAvatar.js";import _ from"../Icons/lock.svg.js";import{EmbeddedCheckoutProvider as C,EmbeddedCheckout as I}from"../../node_modules/.pnpm/@stripe_react-stripe-js@4.0.2_@stripe_stripe-js@7.9.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@stripe/react-stripe-js/dist/react-stripe.esm.mjs.js";import{loadStripe as S}from"../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js";const q=({className:e})=>s("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e},{children:s("polyline",{points:"15 18 9 12 15 6"})})),P=({pickaxeId:P,className:L})=>{const{sessionId:T,styles:U,colors:G,responsiveBy:R,deploymentType:B,isNewChat:E,isEmbed:D,opacity:M,deploymentId:$,sender:F,portalId:V,validationStatus:W,validationUpgradeGroups:z,validationUpgradeUrl:H,accessGroup:J,stripeAccountId:K,clientSecret:X,translations:Y,preventInitialSessionId:Q,setClientSecret:Z,setStripeAccountId:ee,setValidationStatus:se,setValidationUpgradeGroups:te,setValidationUpgradeUrl:ie,setContextId:oe,setPickaxeId:re,setSessionId:ae,setPickaxe:le,setAccessGroup:ne}=l(),{isSent:ce,token:de,isAuthBootstrapComplete:ue}=n(),{setMessages:me,setResponse:pe,setError:fe,setLimitData:xe,setIsSwitchedToChat:ge}=d(),{setDocumentError:he}=u(),{setCurrentArtifact:ve}=m(),[je,be]=o(!1),ke=i();c();const ye="chat-input"===B&&E&&!ce,we=r((()=>K?S(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:K}):null),[K]);a((()=>{re(P)}),[P]);a((()=>{if(!$&&!V||!ke.data)return;if(!ue)return;if("stripe_checkout"===W)return;e(void 0,void 0,void 0,(function*(){var e;se("loading");try{const s=yield b.post("/validate_studio_deployment",{data:{deploymentId:$,sender:F||void 0,studioSessionToken:de,portalId:V,studioId:null===(e=ke.data)||void 0===e?void 0:e.studioid}});if(s.data.success)se("success"),te([]),ie(null),ne(s.data.accessGroup);else{const e=k(s.data);if(!e)return se("login_required"),te([]),void ie(null);se(e.status),ne(e.accessGroup),te(e.upgradeGroups),ie(e.upgradeUrl),be(!0)}}catch(e){console.error("Failed to validate deployment:",e),se("success")}}))}),[$,ue,F,de,V,ke.data]),a((()=>{if(!ke.data)return;const e=ke.data.chatflag;Q||ae(e?p():""),oe(p()),e?me([]):pe(null),fe(""),he(""),xe(null),ve(null),ge(!1),le(ke.data),be(!0)}),[ke.data]),a((()=>{fe(""),he(""),xe(null),me([]),pe(null),ve(null)}),[T]);const Ne=r((()=>{const e=null!=M?M:1;if(!G.primary||!G.primary.startsWith("#")||e<0||e>1)return G.primary;const s=Math.round(255*e).toString(16).padStart(2,"0");return`${G.primary}${s}`}),[G.primary,M]);if(!ke.data)return null;return s("div",Object.assign({className:j("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===U.theme&&"dark",L),style:Object.assign({backgroundColor:ye?"transparent":Ne,color:G.text},U.font&&"Real Head Pro"!==U.font&&{fontFamily:U.font})},{children:(()=>{var i,o,r,a,l;if("stripe_checkout"===W&&X&&we)return t("div",Object.assign({className:"absolute inset-0 z-[999] flex flex-col w-full h-full overflow-hidden",style:{backgroundColor:G.secondary||"#ffffff",color:G.secondaryText||"#000000"}},{children:[s("div",Object.assign({className:"flex items-center p-4 border-b border-gray-100 shrink-0"},{children:t("button",Object.assign({onClick:()=>{Z&&Z(null),ee&&ee(null),se("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:G.text}},{children:[s(q,{className:"w-5 h-5"}),s("span",{children:(null==Y?void 0:Y.back)||"Back"})]}))})),s("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s(C,Object.assign({stripe:we,options:{clientSecret:X}},{children:s(I,{})}))}))]}));if(ke.isLoading||!je||"loading"===W)return s("div",Object.assign({className:j("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===R?"min-[767px]:pb-40":"@[767px]/pickaxe-root:pb-40")},{children:t("div",Object.assign({className:"flex w-full items-center max-w-[700px] flex-col"},{children:[s(x,{className:"w-[72px] h-[72px]"}),s(x,{className:"h-[20px] mt-6 w-full"}),s(x,{className:"h-[20px] mt-2 w-full"}),s(x,{className:"h-[20px] mt-2 w-full max-w-[400px]"}),s("div",Object.assign({className:"flex flex-col gap-y-8 w-full mt-6"},{children:s(x,{className:j("w-full min-h-[48px]","viewport"===R?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===W){const e=z.length>0,a=(null===(i=null==J?void 0:J.upgrade)||void 0===i?void 0:i.isLinkToCustomURL)&&"string"==typeof J.upgrade.limitLink&&J.upgrade.limitLink.trim().length>0?J.upgrade.limitLink.trim():null,l="string"==typeof(null===(o=null==J?void 0:J.upgrade)||void 0===o?void 0:o.limitMessage)&&J.upgrade.limitMessage.trim().length>0?J.upgrade.limitMessage:(null==Y?void 0:Y["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool.",n="string"==typeof(null===(r=null==J?void 0:J.upgrade)||void 0===r?void 0:r.limitCTA)&&J.upgrade.limitCTA.trim().length>0?J.upgrade.limitCTA:(null==Y?void 0:Y["pricing.upgrade"])||(null==Y?void 0:Y.upgrade)||"Upgrade";return s("div",Object.assign({className:"flex h-full min-h-0 w-full items-start justify-center overflow-y-auto p-4"},{children:t("div",a?Object.assign({className:"m-auto flex max-w-[640px] flex-col items-center gap-4 text-center"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==Y?void 0:Y["upgrade-required"])||"Upgrade Required"})),s("p",Object.assign({className:"opacity-80"},{children:l})),s(w,Object.assign({variant:"primary",className:"min-h-[40px] px-5 text-sm",onClick:()=>{window.open(a,"_blank","noopener,noreferrer")}},{children:n}))]}):e?Object.assign({className:"flex w-full max-w-4xl flex-col items-center gap-6 py-6"},{children:[t("div",Object.assign({className:"max-w-[640px] text-center"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2 break-words"},{children:(null==Y?void 0:Y["upgrade-required"])||"Upgrade Required"})),s("p",Object.assign({className:"break-words opacity-80"},{children:(null==Y?void 0:Y["please-upgrade-to-continue-using-this-tool"])||"Please upgrade to continue using this tool."}))]})),s("div",Object.assign({className:"flex w-full flex-wrap justify-center gap-4"},{children:z.map(((e,t)=>s(y,{data:e,upgradeUrl:H},e.accessGroupId||e.id||t)))}))]}):Object.assign({className:"m-auto flex max-w-[640px] flex-col items-center gap-4 text-center"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==Y?void 0:Y["access-locked"])||"Access Locked"})),s("p",Object.assign({className:"opacity-80"},{children:(null==Y?void 0:Y["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===W&&D?s(v,{}):"login_required"!==W||D?"access_denied"===W?t("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[t(N,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s(O,{src:null===(a=ke.data)||void 0===a?void 0:a.coverphoto,alt:`${null===(l=ke.data)||void 0===l?void 0:l.formtitle} Logo`}),s(A,{})]})),t("div",Object.assign({className:"text-center mb-6"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==Y?void 0:Y["access-denied"])||"Access Denied"})),t("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s(_,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s("p",Object.assign({className:"ml-1"},{children:(null==Y?void 0:Y["no-access-request-access"])||"It looks like you don't have access to these resources. Please request access to continue."}))]}))]})),s("button",Object.assign({className:"px-6 py-2 font-medium rounded-md transition-colors",style:{backgroundColor:G.accent,color:G.accentText,borderRadius:U.cornerRadius},onClick:()=>{e(void 0,void 0,void 0,(function*(){var e,s;const t=z.map((e=>e.accessGroupId));try{const i=yield b.post("/request_access",{data:{sender:F||void 0,studioSessionToken:de,studioId:null===(e=ke.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=ke.data)||void 0===s?void 0:s.formid,deploymentId:$,accessGroupIds:t})}});i.data.success?alert((null==Y?void 0:Y["access-requested-successfully"])||"Successfully requested access!"):alert(i.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==Y?void 0:Y["request-access"])||"Request Access"})),s("span",Object.assign({className:"mt-4 mb-2"},{children:(null==Y?void 0:Y.or)||"or"})),s("span",Object.assign({className:"font-medium text-lg"},{children:(null==Y?void 0:Y["sign-in-with-different-account"])||"Sign in with a different account"}))]})):s(f,T?{children:s(g,{})}:{children:s(h,{})}):s("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:t("div",Object.assign({className:"text-center mb-8"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==Y?void 0:Y["access-denied"])||"Access Denied"})),s("p",Object.assign({className:"opacity-80"},{children:(null==Y?void 0:Y["login-is-required"])||"Login is required."}))]}))}))})()}))};export{P as Pickaxe};
@@ -1,6 +1,8 @@
1
+ import type { AccessGroup } from "../components/Pickaxe/Provider";
1
2
  export type PickaxeValidationFailureStatus = "login_required" | "upgrade_required" | "access_denied";
2
3
  export type PickaxeValidationFailure = {
3
4
  status: PickaxeValidationFailureStatus;
5
+ accessGroup: AccessGroup | null;
4
6
  upgradeGroups: any[];
5
7
  upgradeUrl: string | null;
6
8
  };
@@ -10,5 +10,6 @@ interface DropdownProps {
10
10
  maxToken?: number;
11
11
  isDropdown?: boolean;
12
12
  }
13
+ export declare const getDropdownMenuId: (fieldId: string) => string;
13
14
  declare const Dropdown: ({ id, children, placeholder, value, className, style, closeOnSelect, maxToken, isDropdown, }: DropdownProps) => import("react/jsx-runtime").JSX.Element;
14
15
  export default Dropdown;
@@ -59,6 +59,12 @@ export type AccessGroup = {
59
59
  limit: number;
60
60
  accessGroupId: string;
61
61
  limitInterval?: string | null;
62
+ upgrade?: {
63
+ limitMessage?: string | null;
64
+ limitCTA?: string | null;
65
+ limitLink?: string | null;
66
+ isLinkToCustomURL?: boolean;
67
+ } | null;
62
68
  };
63
69
  type PickaxeContextType = {
64
70
  origin: PickaxeHistoryOriginType;
@@ -14,6 +14,7 @@ export interface LimitData {
14
14
  buyUses?: any[];
15
15
  upgradeGroups?: any[];
16
16
  limitLink?: string;
17
+ customLink?: string;
17
18
  accessGroupId?: string;
18
19
  limitCTA?: string;
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "6.6.2",
3
+ "version": "6.6.3",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",