@pickaxeproject/react 6.6.0 → 6.6.2

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 (41) hide show
  1. package/dist/cjs/components/Pickaxe/Addons/Auth/Provider.js +1 -1
  2. package/dist/cjs/components/Pickaxe/Addons/Auth/hooks/useAuth.js +1 -1
  3. package/dist/cjs/components/Pickaxe/Addons/Auth/hooks/useAuthBootstrap.js +1 -0
  4. package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
  5. package/dist/cjs/components/Pickaxe/Form/History/Item.js +1 -1
  6. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.js +1 -1
  7. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.js +1 -1
  8. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.js +1 -1
  9. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Renderer.js +1 -1
  10. package/dist/cjs/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  11. package/dist/cjs/components/Pickaxe/index.js +1 -1
  12. package/dist/cjs/src/components/Pickaxe/Addons/Auth/Provider.d.ts +2 -0
  13. package/dist/cjs/src/components/Pickaxe/Addons/Auth/hooks/useAuthBootstrap.d.ts +1 -0
  14. package/dist/cjs/src/components/Pickaxe/Addons/Auth/hooks/useAuthContext.d.ts +2 -0
  15. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.d.ts +6 -0
  16. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.d.ts +3 -2
  17. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.d.ts +6 -1
  18. package/dist/cjs/src/components/Pickaxe/common/PickaxeMarkdown/Renderer.d.ts +3 -2
  19. package/dist/cjs/src/components/Pickaxe/common/PickaxeMessageParts/index.d.ts +2 -0
  20. package/dist/cjs/src/types/history.d.ts +1 -1
  21. package/dist/esm/components/Pickaxe/Addons/Auth/Provider.js +1 -1
  22. package/dist/esm/components/Pickaxe/Addons/Auth/hooks/useAuth.js +1 -1
  23. package/dist/esm/components/Pickaxe/Addons/Auth/hooks/useAuthBootstrap.js +1 -0
  24. package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
  25. package/dist/esm/components/Pickaxe/Form/History/Item.js +1 -1
  26. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.js +1 -1
  27. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.js +1 -1
  28. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.js +1 -1
  29. package/dist/esm/components/Pickaxe/common/PickaxeMarkdown/Renderer.js +1 -1
  30. package/dist/esm/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  31. package/dist/esm/components/Pickaxe/index.js +1 -1
  32. package/dist/esm/src/components/Pickaxe/Addons/Auth/Provider.d.ts +2 -0
  33. package/dist/esm/src/components/Pickaxe/Addons/Auth/hooks/useAuthBootstrap.d.ts +1 -0
  34. package/dist/esm/src/components/Pickaxe/Addons/Auth/hooks/useAuthContext.d.ts +2 -0
  35. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.d.ts +6 -0
  36. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.d.ts +3 -2
  37. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.d.ts +6 -1
  38. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Renderer.d.ts +3 -2
  39. package/dist/esm/src/components/Pickaxe/common/PickaxeMessageParts/index.d.ts +2 -0
  40. package/dist/esm/src/types/history.d.ts +1 -1
  41. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react");const s=t.createContext({});exports.AuthContext=s,exports.default=({children:n})=>{const[i,r]=t.useState(""),[u,a]=t.useState(null),[d,l]=t.useState(null),[o,g]=t.useState(!1),[c,S]=t.useState(!1),[I,x]=t.useState(!1),[p,h]=t.useState(!1),[b,j]=t.useState(!1);return e.jsx(s.Provider,Object.assign({value:{emailInput:i,redirectUrl:d,token:u,isLoggedIn:!!u,isLoggedOut:!u,isLoggingIn:o,isSending:I,isResendDisabled:p,isSent:b,isPricingAuth:c,setIsPricingAuth:S,setRedirectUrl:l,setEmailInput:r,setToken:a,setIsLoggingIn:g,setIsSending:x,setIsResendDisabled:h,setIsSent:j}},{children:n}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react");const s=t.createContext({});exports.AuthContext=s,exports.default=({children:i})=>{const[n,r]=t.useState(""),[u,a]=t.useState(null),[o,l]=t.useState(null),[d,g]=t.useState(!1),[c,S]=t.useState(!1),[I,p]=t.useState(!1),[h,x]=t.useState(!1),[m,A]=t.useState(!1),[b,j]=t.useState(!1);return e.jsx(s.Provider,Object.assign({value:{emailInput:n,redirectUrl:o,token:u,isLoggedIn:!!u,isLoggedOut:!u,isLoggingIn:d,isSending:I,isResendDisabled:h,isSent:m,isPricingAuth:c,isAuthBootstrapComplete:b,setIsPricingAuth:S,setRedirectUrl:l,setEmailInput:r,setToken:a,setIsLoggingIn:g,setIsSending:p,setIsResendDisabled:x,setIsSent:A,setIsAuthBootstrapComplete:j}},{children:i}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("react"),i=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("./useAuthContext.js"),n=require("./useAuthVerify.js"),r=require("../../../../../common/utils.js"),o=require("../../../../../common/api/pickaxe.js"),d=require("../../../../../common/error.js"),u=require("../../../../../hooks/pickaxe/useResponseContext.js");exports.useAuth=()=>{const{deploymentId:a,pickaxe:l,translations:c,setSender:f,setSenderType:m}=i.usePickaxeContext(),{emailInput:p,redirectUrl:k,isSending:g,isLoggedOut:h,isPricingAuth:v,setToken:x,setIsLoggingIn:I,setIsSending:w,setIsSent:y,setIsResendDisabled:j,setIsPricingAuth:A}=s.useAuthContext(),P=n.useAuthVerify({token:r.getAuthToken((null==l?void 0:l.studioid)||"")||"",enabled:h,setIsLoggingIn:I}),{setLimitData:q}=u.useResponseContext();t.useEffect((()=>{if("undefined"==typeof window)return;if(!P.data)return;const{success:e,token:t,error:i}=P.data;if(!e||i)return r.deleteAuthToken(`PXE-token-${null==l?void 0:l.studioid}`),void A(!1);e&&t&&(x(t),f(void 0),m("STUDIO_USER"),v&&(A(!1),q(null)))}),[P.data,null==l?void 0:l.studioid]);return{onSend:t=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(!l)return;if(g)return;const e=p.trim().toLowerCase();if(!e)throw new Error((null==c?void 0:c["email-address-cannot-be-empty"])||"Email address cannot be empty.");if(!e.includes("@")||!e.includes("."))throw new Error((null==c?void 0:c["please-enter-valid-email-address"])||"Please enter a valid email address.");if(!l.studioid)throw new Error(`Studio ID is missing for ${l.formid}. Please contact support.`);w(!0),t&&j(!0);const i=(yield o.default.post("/auth/email",Object.assign(Object.assign({pickaxeId:l.formid,studioId:l.studioid,email:e},a&&{deploymentId:a}),{redirectUrl:k}))).data;if(!i.success)throw new Error(i.error||(null==c?void 0:c["failed-to-send-sign-in-link"])||"Failed to send sign-in link.");w(!1),y(!0),t&&(yield new Promise((e=>setTimeout(e,3e4))),j(!1)),r.setAuthToken(`PXE-token-${l.studioid}`,i.token),A(!0)}catch(e){const t=d.default(e);alert(t)}finally{w(!1)}}))}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),i=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),t=require("./useAuthContext.js"),s=require("../../../../../common/utils.js"),r=require("../../../../../common/api/pickaxe.js"),n=require("../../../../../common/error.js");exports.useAuth=()=>{const{deploymentId:o,pickaxe:d,translations:a}=i.usePickaxeContext(),{emailInput:l,redirectUrl:u,isSending:c,setIsSending:m,setIsSent:p,setIsResendDisabled:f,setIsPricingAuth:h}=t.useAuthContext();return{onSend:i=>e.__awaiter(void 0,void 0,void 0,(function*(){try{if(!d)return;if(c)return;const e=l.trim().toLowerCase();if(!e)throw new Error((null==a?void 0:a["email-address-cannot-be-empty"])||"Email address cannot be empty.");if(!e.includes("@")||!e.includes("."))throw new Error((null==a?void 0:a["please-enter-valid-email-address"])||"Please enter a valid email address.");if(!d.studioid)throw new Error(`Studio ID is missing for ${d.formid}. Please contact support.`);m(!0),i&&f(!0);const t=(yield r.default.post("/auth/email",Object.assign(Object.assign({pickaxeId:d.formid,studioId:d.studioid,email:e},o&&{deploymentId:o}),{redirectUrl:u}))).data;if(!t.success)throw new Error(t.error||(null==a?void 0:a["failed-to-send-sign-in-link"])||"Failed to send sign-in link.");m(!1),p(!0),i&&(yield new Promise((e=>setTimeout(e,3e4))),f(!1)),s.setAuthToken(`PXE-token-${d.studioid}`,t.token),h(!0)}catch(e){const i=n.default(e);alert(i)}finally{m(!1)}}))}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../../../../common/utils.js"),i=require("./useAuthContext.js"),u=require("./useAuthVerify.js");exports.useAuthBootstrap=()=>{const{pickaxe:r,setSender:n,setSenderType:a}=t.usePickaxeContext(),{setLimitData:c}=s.useResponseContext(),{token:d,isLoggedOut:k,isPricingAuth:g,setToken:h,setIsLoggingIn:l,setIsPricingAuth:x,setIsAuthBootstrapComplete:f}=i.useAuthContext(),p=(null==r?void 0:r.studioid)||"",A=p?`PXE-token-${p}`:"",v=o.getAuthToken(p)||"",C=u.useAuthVerify({token:v,enabled:k&&!!v,setIsLoggingIn:l});e.useEffect((()=>{p&&f(!1)}),[f,p]);const E=e.useCallback((e=>{o.setAuthToken(A,e),h(e),n(void 0),a("STUDIO_USER"),g&&(x(!1),c(null))}),[A,g,x,c,n,a,h]);e.useEffect((()=>{if(!A)return;if(!C.data)return;const{success:e,token:t,error:s}=C.data;if(!e||s)return o.deleteAuthToken(A),x(!1),void f(!0);t&&(E(t),f(!0))}),[E,A,C.data,f,x]),e.useEffect((()=>{var e;p&&(d?f(!0):v?C.isLoading||C.isFetching||(C.isError||C.isSuccess&&!(null===(e=C.data)||void 0===e?void 0:e.token))&&f(!0):f(!0))}),[C.data,C.isError,C.isFetching,C.isLoading,C.isSuccess,f,v,p,d])};
@@ -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(Object.assign(Object.assign({studioId:null==de?void 0:de.studioid},re&&{sender:re}),we&&{studioSessionToken:we}),!we&&!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)}}))),[se,ne,ie,oe,re,we,ae,le,Yt]);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=_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 ms=(({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):Math.max(0,s-i)+r})({currentUses:ps.currentUses,extraUses:ps.extraUses,limit:is,limitInterval:rs}),fs=ms===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(ms)),gs=(({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:ps.extraUses,limit:is,limitInterval:rs}),hs=gs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.ceil(.05*gs),vs=os?Math.ceil(5*pt):5,bs=hs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(hs,vs);console.log("Usage and Limits Debug:",{remaining:fs,notificationThreshold:bs,studioUser:it});const Is=s.useMemo((()=>!!it&&(!dt&&(fs!==A.STUDIO_INFINITY_VALUE&&(!(fs<=0)&&fs<=bs)))),[dt,bs,fs,it]),ys=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]),xs=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:js}))),s.useEffect((()=>{xe(ys)}),[ys]),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;js(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 js=(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:[Is&&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:[fs.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||js()))},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||xs?pe.accent:pe.accent+"10",color:Pt||xs?pe.accentText:pe.accent+"80"},disabled:!xs,onClick:()=>js()},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"),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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../Addons/Document/hooks/useDocument.js"),i=require("date-fns"),r=require("../../../../common/api/pickaxe.js"),l=require("lucide-react"),c=require("../../../Icons/trash-2.svg.js"),d=require("../../../Icons/chat.svg.js"),u=require("../../../Icons/copy.svg.js"),m=require("../../../Icons/copied.svg.js"),p=require("../../../Icons/expand.svg.js"),x=require("../../../Icons/collapse.svg.js"),h=require("../../common/PickaxeMarkdown/index.js"),b=require("../../common/PickaxeMarkdown/Renderer.js"),f=require("../../../../common/cn.js");exports.default=({item:g,onDelete:j})=>{const{pickaxe:v,sender:y,colors:k,translations:w,styles:N,isRtl:_,disableCss:C,disableHtml:O,disableJs:q,setSessionId:P,setIsNewChat:M}=n.usePickaxeContext(),{setMessages:I}=a.useResponseContext(),{setDocuments:R}=o.useDocument(),[S,E]=t.useState(!1),[D,F]=t.useState(!1),[T,H]=t.useState(!1),[$,z]=t.useState(!1),[A,J]=t.useState(!1),L=t.useRef(null),[B,K]=t.useState(g.shortSummary||g.summary||(null==w?void 0:w["conversation-name"])||"Conversation name"),[X,G]=t.useState("");t.useEffect((()=>{K(g.shortSummary||g.summary||(null==w?void 0:w["conversation-name"])||"Conversation name")}),[g.shortSummary,g.summary,w]),t.useEffect((()=>{const e=e=>{L.current&&!L.current.contains(e.target)&&E(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const Q=t.useMemo((()=>g?"FORM"===g.pickaxeType&&0===g.messages.length?g.question.responseParts?g.question.responseParts.length:0:g.messages.length:0),[g]),U=t.useMemo((()=>i.format(new Date(g.updatedAt),"MMM dd, yyy hh:mm a")),[g]),V=t.useMemo((()=>{var e;const s=(null==w?void 0:w["not-available"])||"n/a";if("FORM"===g.pickaxeType){if(g.messages&&0!==g.messages.length){const e=g.messages.find((e=>"user"===e.role));return e?e.parts[0].content:""}const t=null!==(e=g.question.inputs)&&void 0!==e?e:[];return A?t.map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 600; opacity: 0.9;">${e.question}</p>\n <p style="opacity: 0.8;">${e.answer||s}</p>\n</div>`)).join(""):t.map((e=>`${e.question}: ${e.answer||s}`)).join(" | ")}const t=g.messages.find((e=>"user"===e.role));return t?t.parts[0].content:""}),[g,A,w]),W=t.useMemo((()=>{if("FORM"===g.pickaxeType){if(g.messages&&0!==g.messages.length){const e=g.messages.find((e=>"assistant"===e.role));return e?e.parts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" "):""}return g.question.responseParts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" ")}const e=g.messages.find((e=>"assistant"===e.role));return e?e.parts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" "):""}),[g]),Y=()=>{F(!1),G("")},Z=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(X.trim()){H(!0);try{yield r.default.post("/edit_conversation_name",{sessionId:g.sessionId,name:X,userId:y}),K(X),F(!1)}catch(e){console.error("Error updating conversation name:",e),alert((null==w?void 0:w["failed-update-name"])||"Failed to update name.")}finally{H(!1)}}}));return s.jsxs("div",Object.assign({className:"flex flex-col overflow-hidden transition duration-300 hover:shadow w-full shrink-0 border",style:{borderColor:k.secondary,borderRadius:N.cornerRadius}},{children:[s.jsx("div",Object.assign({className:"flex items-center justify-between px-4 py-3 h-[44px]",style:{backgroundColor:k.primary,color:k.text}},{children:D?s.jsxs("div",Object.assign({className:"flex items-center w-full gap-2",onClick:e=>e.stopPropagation()},{children:[s.jsx("input",{autoFocus:!0,type:"text",value:X,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key&&Z(),"Escape"===e.key&&Y()},className:"flex-1 text-inherit px-2 py-1 rounded border focus:outline-none focus:ring-0 text-sm",style:{backgroundColor:k.primary,borderColor:k.secondary}}),s.jsx("button",Object.assign({onClick:Z,disabled:T,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==w?void 0:w.save)||"Save"},{children:s.jsx(l.Check,{className:"h-4 w-4"})})),s.jsx("button",Object.assign({onClick:Y,disabled:T,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==w?void 0:w.cancel)||"Cancel"},{children:s.jsx(l.X,{className:"h-4 w-4"})}))]})):s.jsxs(s.Fragment,{children:[s.jsx("h3",Object.assign({className:"font-bold text-lg truncate pr-2 flex-1 min-w-0 select-none"},{children:B})),s.jsxs("div",Object.assign({className:"flex items-center gap-1 shrink-0"},{children:[s.jsx("button",Object.assign({onClick:e=>{e.stopPropagation(),J(!A)},className:"p-1 rounded-full transition-colors hover:bg-black/10",title:A?(null==w?void 0:w.collapse)||"Collapse":(null==w?void 0:w.expand)||"Expand"},{children:A?s.jsx(x.default,{className:"h-4 w-4"}):s.jsx(p.default,{className:"h-4 w-4"})})),s.jsxs("div",Object.assign({className:"relative"},{children:[s.jsx("button",Object.assign({onClick:e=>{e.stopPropagation(),E(!S)},className:"p-1 rounded-full transition-colors hover:bg-black/10"},{children:s.jsx(l.MoreHorizontal,{className:"h-6 w-6"})})),S&&s.jsxs("div",Object.assign({ref:L,className:"absolute right-0 top-8 w-48 rounded-xl shadow-xl z-40 border overflow-hidden animate-in fade-in zoom-in-95 duration-100",style:{backgroundColor:k.secondary,color:k.secondaryText,borderColor:k.primary}},{children:[s.jsxs("button",Object.assign({onClick:e=>{e.stopPropagation(),G(B),F(!0),E(!1)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95 border-b",style:{borderBottomColor:k.primary}},{children:[s.jsx(l.Pencil,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"font-medium text-sm"},{children:(null==w?void 0:w["rename-chat"])||"Rename chat"}))]})),s.jsxs("button",Object.assign({onClick:s=>{s.stopPropagation(),e.__awaiter(void 0,void 0,void 0,(function*(){if(window.confirm((null==w?void 0:w["delete-confirm"])||"Are you sure you want to delete this conversation?")){E(!1);try{yield r.default.post("/delete_pickaxe_conversation",{sessionId:g.sessionId,userId:y}),j&&j(g.sessionId)}catch(e){console.error("Error deleting conversation:",e),alert((null==w?void 0:w["failed-delete-conversation"])||"Failed to delete conversation.")}}}))},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95"},{children:[s.jsx(c.default,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"font-medium text-sm"},{children:(null==w?void 0:w["delete-chat"])||"Delete chat"}))]}))]}))]}))]}))]})})),s.jsxs("div",Object.assign({className:f.default("px-4 py-5 flex flex-col justify-between transition-all duration-200 ease-in-out",A?"h-auto min-h-[130px]":"h-[130px]"),style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[s.jsxs("div",Object.assign({className:"flex flex-col"},{children:[s.jsx("div",Object.assign({className:f.default("w-full",A?"mb-0":"mb-2")},{children:s.jsx(h.PickaxeMarkdown,Object.assign({theme:N.theme,colors:k},_&&{rtl:!0},O&&{disableHtml:!0},q&&{disableJs:!0},C&&{disableCss:!0},{children:s.jsx(b.PickaxeMarkdownRenderer,{style:{display:"block"},className:f.default("w-full",!A&&["[&_*]:!font-semibold mb-0.5 h-5 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],A&&"[&_*]:!text-sm [&_*]:!font-semibold mb-0.5 [&_p]:!m-0"),value:V})}))})),s.jsx("div",Object.assign({className:"w-full"},{children:s.jsx(h.PickaxeMarkdown,Object.assign({theme:N.theme,colors:k},_&&{rtl:!0},O&&{disableHtml:!0},q&&{disableJs:!0},C&&{disableCss:!0},{children:s.jsx(b.PickaxeMarkdownRenderer,{style:{display:"block"},className:f.default("w-full text-sm",!A&&["font-normal h-5 opacity-80 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],A&&"font-normal opacity-90 mt-2 border-t pt-2 border-dashed"),value:W})}))}))]})),s.jsxs("div",Object.assign({className:"flex items-center justify-between mt-4 pt-2 border-t border-transparent"},{children:[s.jsxs("div",Object.assign({className:"flex items-center gap-4"},{children:[((null==v?void 0:v.chatflag)||!(null==v?void 0:v.chatflag)&&(null==v?void 0:v.enablechatresponses))&&s.jsxs("div",Object.assign({className:"flex items-center gap-1.5 opacity-70 hover:opacity-100 cursor-pointer transition-opacity",onClick:e=>{var s;e.stopPropagation(),s=g.sessionId,R([]),I([]),M(!1),P(s)},title:(null==w?void 0:w["open-chat"])||"Open Chat"},{children:[s.jsx(d.default,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"text-sm font-medium"},{children:Q}))]})),s.jsx("button",Object.assign({className:"transition-colors "+($?"opacity-100":"opacity-70 hover:opacity-100"),onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(W),z(!0),setTimeout((()=>{z(!1)}),2e3)},title:$?(null==w?void 0:w.copied)||"Copied!":(null==w?void 0:w["copy-assistant-message"])||"Copy assistant message"},{children:$?s.jsx(m.default,{className:"h-4 w-4",style:{color:k.accent},fill:k.accent}):s.jsx(u.default,{className:"h-4 w-4"})}))]})),s.jsx("span",Object.assign({className:"text-xs font-semibold uppercase opacity-30 whitespace-nowrap"},{children:U}))]}))]}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),s=require("react/jsx-runtime"),t=require("react"),n=require("../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../hooks/pickaxe/useResponseContext.js"),o=require("../../Addons/Document/hooks/useDocument.js"),i=require("date-fns"),r=require("../../../../common/api/pickaxe.js"),l=require("lucide-react"),c=require("../../../Icons/trash-2.svg.js"),d=require("../../../Icons/chat.svg.js"),u=require("../../../Icons/copy.svg.js"),m=require("../../../Icons/copied.svg.js"),p=require("../../../Icons/expand.svg.js"),x=require("../../../Icons/collapse.svg.js"),h=require("../../common/PickaxeMarkdown/index.js"),b=require("../../common/PickaxeMarkdown/Renderer.js"),g=require("../../common/PickaxeMessageParts/index.js"),v=require("../../../../common/cn.js");exports.default=({item:j,onDelete:f})=>{const{pickaxe:y,sender:w,colors:k,translations:N,styles:_,isRtl:C,disableCss:O,disableHtml:q,disableJs:P,setSessionId:M,setIsNewChat:I}=n.usePickaxeContext(),{setMessages:R}=a.useResponseContext(),{setDocuments:S}=o.useDocument(),[E,D]=t.useState(!1),[F,T]=t.useState(!1),[H,$]=t.useState(!1),[z,A]=t.useState(!1),[J,L]=t.useState(!1),U=t.useRef(null),[B,K]=t.useState(j.shortSummary||j.summary||(null==N?void 0:N["conversation-name"])||"Conversation name"),[X,G]=t.useState("");t.useEffect((()=>{K(j.shortSummary||j.summary||(null==N?void 0:N["conversation-name"])||"Conversation name")}),[j.shortSummary,j.summary,N]),t.useEffect((()=>{const e=e=>{U.current&&!U.current.contains(e.target)&&D(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const Q=t.useMemo((()=>j?"FORM"===j.pickaxeType&&0===j.messages.length?j.question.responseParts?j.question.responseParts.length:0:j.messages.length:0),[j]),V=t.useMemo((()=>i.format(new Date(j.updatedAt),"MMM dd, yyy hh:mm a")),[j]),W=t.useMemo((()=>{var e;const s=(null==N?void 0:N["not-available"])||"n/a";if("FORM"===j.pickaxeType){if(j.messages&&0!==j.messages.length){const e=j.messages.find((e=>"user"===e.role));return e?e.parts[0].content:""}const t=null!==(e=j.question.inputs)&&void 0!==e?e:[];return J?t.map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 600; opacity: 0.9;">${e.question}</p>\n <p style="opacity: 0.8;">${e.answer||s}</p>\n</div>`)).join(""):t.map((e=>`${e.question}: ${e.answer||s}`)).join(" | ")}const t=j.messages.find((e=>"user"===e.role));return t?t.parts[0].content:""}),[j,J,N]),Y=t.useMemo((()=>{var e,s,t,n;return"FORM"===j.pickaxeType?j.messages&&0!==j.messages.length?null!==(s=null===(e=j.messages.find((e=>"assistant"===e.role)))||void 0===e?void 0:e.parts)&&void 0!==s?s:[]:j.question.responseParts:null!==(n=null===(t=j.messages.find((e=>"assistant"===e.role)))||void 0===t?void 0:t.parts)&&void 0!==n?n:[]}),[j]),Z=t.useMemo((()=>Y.filter((e=>"text"===e.type)).map((e=>e.content)).join(" ")),[Y]),ee=t.useMemo((()=>g.getSuppressedRichPreviewUrls(Y)),[Y]),se=()=>{T(!1),G("")},te=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(X.trim()){$(!0);try{yield r.default.post("/edit_conversation_name",{sessionId:j.sessionId,name:X,userId:w}),K(X),T(!1)}catch(e){console.error("Error updating conversation name:",e),alert((null==N?void 0:N["failed-update-name"])||"Failed to update name.")}finally{$(!1)}}}));return s.jsxs("div",Object.assign({className:"flex flex-col overflow-hidden transition duration-300 hover:shadow w-full shrink-0 border",style:{borderColor:k.secondary,borderRadius:_.cornerRadius}},{children:[s.jsx("div",Object.assign({className:"flex items-center justify-between px-4 py-3 h-[44px]",style:{backgroundColor:k.primary,color:k.text}},{children:F?s.jsxs("div",Object.assign({className:"flex items-center w-full gap-2",onClick:e=>e.stopPropagation()},{children:[s.jsx("input",{autoFocus:!0,type:"text",value:X,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"===e.key&&te(),"Escape"===e.key&&se()},className:"flex-1 text-inherit px-2 py-1 rounded border focus:outline-none focus:ring-0 text-sm",style:{backgroundColor:k.primary,borderColor:k.secondary}}),s.jsx("button",Object.assign({onClick:te,disabled:H,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==N?void 0:N.save)||"Save"},{children:s.jsx(l.Check,{className:"h-4 w-4"})})),s.jsx("button",Object.assign({onClick:se,disabled:H,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==N?void 0:N.cancel)||"Cancel"},{children:s.jsx(l.X,{className:"h-4 w-4"})}))]})):s.jsxs(s.Fragment,{children:[s.jsx("h3",Object.assign({className:"font-bold text-lg truncate pr-2 flex-1 min-w-0 select-none"},{children:B})),s.jsxs("div",Object.assign({className:"flex items-center gap-1 shrink-0"},{children:[s.jsx("button",Object.assign({onClick:e=>{e.stopPropagation(),L(!J)},className:"p-1 rounded-full transition-colors hover:bg-black/10",title:J?(null==N?void 0:N.collapse)||"Collapse":(null==N?void 0:N.expand)||"Expand"},{children:J?s.jsx(x.default,{className:"h-4 w-4"}):s.jsx(p.default,{className:"h-4 w-4"})})),s.jsxs("div",Object.assign({className:"relative"},{children:[s.jsx("button",Object.assign({onClick:e=>{e.stopPropagation(),D(!E)},className:"p-1 rounded-full transition-colors hover:bg-black/10"},{children:s.jsx(l.MoreHorizontal,{className:"h-6 w-6"})})),E&&s.jsxs("div",Object.assign({ref:U,className:"absolute right-0 top-8 w-48 rounded-xl shadow-xl z-40 border overflow-hidden animate-in fade-in zoom-in-95 duration-100",style:{backgroundColor:k.secondary,color:k.secondaryText,borderColor:k.primary}},{children:[s.jsxs("button",Object.assign({onClick:e=>{e.stopPropagation(),G(B),T(!0),D(!1)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95 border-b",style:{borderBottomColor:k.primary}},{children:[s.jsx(l.Pencil,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"font-medium text-sm"},{children:(null==N?void 0:N["rename-chat"])||"Rename chat"}))]})),s.jsxs("button",Object.assign({onClick:s=>{s.stopPropagation(),e.__awaiter(void 0,void 0,void 0,(function*(){if(window.confirm((null==N?void 0:N["delete-confirm"])||"Are you sure you want to delete this conversation?")){D(!1);try{yield r.default.post("/delete_pickaxe_conversation",{sessionId:j.sessionId,userId:w}),f&&f(j.sessionId)}catch(e){console.error("Error deleting conversation:",e),alert((null==N?void 0:N["failed-delete-conversation"])||"Failed to delete conversation.")}}}))},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95"},{children:[s.jsx(c.default,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"font-medium text-sm"},{children:(null==N?void 0:N["delete-chat"])||"Delete chat"}))]}))]}))]}))]}))]})})),s.jsxs("div",Object.assign({className:v.default("px-4 py-5 flex flex-col justify-between transition-all duration-200 ease-in-out",J?"h-auto min-h-[130px]":"h-[130px]"),style:{backgroundColor:k.secondary,color:k.secondaryText}},{children:[s.jsxs("div",Object.assign({className:"flex flex-col"},{children:[s.jsx("div",Object.assign({className:v.default("w-full",J?"mb-0":"mb-2")},{children:s.jsx(h.PickaxeMarkdown,Object.assign({theme:_.theme,colors:k},C&&{rtl:!0},q&&{disableHtml:!0},P&&{disableJs:!0},O&&{disableCss:!0},{children:s.jsx(b.PickaxeMarkdownRenderer,{style:{display:"block"},className:v.default("w-full",!J&&["[&_*]:!font-semibold mb-0.5 h-5 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],J&&"[&_*]:!text-sm [&_*]:!font-semibold mb-0.5 [&_p]:!m-0"),value:W})}))})),s.jsx("div",Object.assign({className:"w-full"},{children:s.jsx(h.PickaxeMarkdown,Object.assign({theme:_.theme,colors:k},C&&{rtl:!0},q&&{disableHtml:!0},P&&{disableJs:!0},O&&{disableCss:!0},{children:s.jsx(b.PickaxeMarkdownRenderer,{style:{display:"block"},className:v.default("w-full text-sm",!J&&["font-normal h-5 opacity-80 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],J&&"font-normal opacity-90 mt-2 border-t pt-2 border-dashed"),value:Z,suppressedRichPreviewUrls:ee})}))}))]})),s.jsxs("div",Object.assign({className:"flex items-center justify-between mt-4 pt-2 border-t border-transparent"},{children:[s.jsxs("div",Object.assign({className:"flex items-center gap-4"},{children:[((null==y?void 0:y.chatflag)||!(null==y?void 0:y.chatflag)&&(null==y?void 0:y.enablechatresponses))&&s.jsxs("div",Object.assign({className:"flex items-center gap-1.5 opacity-70 hover:opacity-100 cursor-pointer transition-opacity",onClick:e=>{var s;e.stopPropagation(),s=j.sessionId,S([]),R([]),I(!1),M(s)},title:(null==N?void 0:N["open-chat"])||"Open Chat"},{children:[s.jsx(d.default,{className:"h-4 w-4"}),s.jsx("span",Object.assign({className:"text-sm font-medium"},{children:Q}))]})),s.jsx("button",Object.assign({className:"transition-colors "+(z?"opacity-100":"opacity-70 hover:opacity-100"),onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(Z),A(!0),setTimeout((()=>{A(!1)}),2e3)},title:z?(null==N?void 0:N.copied)||"Copied!":(null==N?void 0:N["copy-assistant-message"])||"Copy assistant message"},{children:z?s.jsx(m.default,{className:"h-4 w-4",style:{color:k.accent},fill:k.accent}):s.jsx(u.default,{className:"h-4 w-4"})}))]})),s.jsx("span",Object.assign({className:"text-xs font-semibold uppercase opacity-30 whitespace-nowrap"},{children:V}))]}))]}))]}))};
@@ -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"),o=require("../../../../../../hooks/pickaxe/usePickaxeContext.js"),a=require("../../../../Addons/Auth/hooks/useAuthContext.js"),i=require("../../../../../../hooks/pickaxe/useSubmitDocument.js"),l=require("../../hooks/usePickaxeMarkdownContext.js"),n=require("../../../../../Icons/download.svg.js"),r=require("../../../../../Icons/copy.svg.js"),c=require("../../../../../Icons/copied.svg.js"),d=require("../../../../../Icons/file.svg.js"),u=require("../../../../../Icons/upload-cloud.svg.js"),p=require("copy-to-clipboard"),m=require("../../../../../../common/error.js");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=f(p);const b=new Set(["jpeg","jpg","gif","bmp","webp","svg","tiff","avif","png","jfif","pjpeg","pjp"]),g=new Set(["mp3","wav","ogg","flac","aac","wma","alac","m4a","aiff","ape","au","mid","midi","opus"]),v=new Set(["mp4","webm","mov","avi","mkv","m4v"]),h=new Set(["csv","tsv","txt","json","xml","md","log","yaml","yml"]),w=new Set(["doc","docx","xls","xlsx","ppt","pptx"]),j=e=>b.has(e)?"image":g.has(e)?"audio":v.has(e)?"video":"pdf"===e?"pdf":"html"===e||"htm"===e?"html":h.has(e)?"text":w.has(e)?"office":"file",k=e=>{const t=(e=>{let t=e.trim();for(;/[),.;!?]$/.test(t);)t=t.slice(0,-1);return t})(e);return t.startsWith("http://")?`https://${t.slice(7)}`:t.startsWith("www.")?`https://${t}`:t};exports.default=({fileInfo:p,displayName:f})=>{const{theme:b,colors:g,disableHtml:v,disableJs:h}=l.usePickaxeMarkdownContext(),{contextId:w,pickaxeId:j,pickaxe:k,translations:y}=o.usePickaxeContext(),{isLoggedIn:N,token:C}=a.useAuthContext(),O=i.useSubmitDocument(),[S,I]=s.useState(!1),[q,F]=s.useState(!1),[D,$]=s.useState(!1),_=(e,t)=>{var s;return null!==(s=null==y?void 0:y[e])&&void 0!==s?s:t},P="dark"===b?"#30363D":"#D0D7DE",R="dark"===b?"#0D1117":"#F6F8FA",T="dark"===b?"#161B22":"#FFFFFF",U=(null==f?void 0:f.trim())||p.fileName,A=U!==p.fileName,B={display:"inline-flex",width:32,height:32,alignItems:"center",justifyContent:"center",borderRadius:4,color:g.accentText,backgroundColor:g.accent,opacity:.88,flexShrink:0},E=(e,s,o)=>t.jsx("div",Object.assign({className:"flex w-full p-4"},{children:t.jsxs("div",Object.assign({className:"relative w-full overflow-hidden rounded-md shadow-sm",style:{aspectRatio:"8.5 / 11",backgroundColor:T,border:`1px solid ${P}`}},{children:[t.jsx("iframe",Object.assign({src:e,title:s},o,{className:"h-full w-full",scrolling:"no",tabIndex:-1,style:{border:"none",pointerEvents:"none"}})),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-10",style:{background:"dark"===b?"linear-gradient(to top, rgba(22,27,34,0.95), rgba(22,27,34,0))":"linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0))"}})]}))}));return t.jsxs("div",Object.assign({className:"my-2 w-full overflow-hidden rounded-lg",style:{border:`1px solid ${P}`,backgroundColor:R,color:g.secondaryText}},{children:[t.jsxs("div",Object.assign({className:"flex items-center justify-between gap-3 border-b px-3 py-2",style:{borderColor:P}},{children:[t.jsx("a",Object.assign({href:p.url,target:"_blank",rel:"noopener noreferrer",className:"min-w-0 flex-1 truncate text-sm font-semibold hover:underline",style:{color:g.secondaryText},title:A?`${U} (${p.fileName})`:U},{children:U})),t.jsxs("div",Object.assign({className:"flex shrink-0 items-center gap-1.5"},{children:[t.jsx("button",Object.assign({type:"button",onClick:()=>{const e=document.createElement("a");e.href=p.url,e.download=p.fileName,e.target="_blank",e.rel="noopener noreferrer",e.click()},title:_("download","Download"),"aria-label":_("download","Download"),style:B},{children:t.jsx(n.default,{className:"h-[18px] w-[18px]"})})),t.jsx("button",Object.assign({type:"button",onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){try{I(!0),x.default(p.url),yield new Promise((e=>setTimeout(e,1500)))}finally{I(!1)}}))},title:S?_("copied","Copied"):_("copy-link","Copy link"),"aria-label":S?_("copied","Copied"):_("copy-link","Copy link"),style:Object.assign(Object.assign({},B),{opacity:S?1:B.opacity})},{children:S?t.jsx(c.default,{className:"h-[18px] w-[18px]"}):t.jsx(r.default,{className:"h-[18px] w-[18px]"})})),N&&C&&t.jsx("button",Object.assign({type:"button",disabled:q||D,onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(C&&!q){F(!0),$(!1);try{const e=yield fetch(p.url);if(!e.ok)throw new Error("Failed to download generated file.");const t=yield e.blob(),s=new File([t],p.fileName,{type:t.type||"application/octet-stream"});yield O.document(Object.assign(Object.assign({contextId:w,pickaxeId:j,file:s},(null==k?void 0:k.workspaceid)&&{workspaceId:k.workspaceid}),{studioSessionToken:C,isUserDocument:!0})),$(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(m.default(e))}finally{F(!1),$(!1)}}}))},title:q?_("saving","Saving..."):D?_("saved","Saved"):_("save-to-knowledge-base","Save to Knowledge Base"),"aria-label":q?_("saving","Saving..."):D?_("saved","Saved"):_("save-to-knowledge-base","Save to Knowledge Base"),style:Object.assign(Object.assign({},B),{opacity:q||D?.55:B.opacity,cursor:q||D?"not-allowed":"pointer"})},{children:t.jsx(u.default,{className:"h-[18px] w-[18px]"})}))]}))]})),t.jsx("div",{children:(()=>{if("image"===p.kind)return t.jsx("img",{src:p.url,alt:p.fileName,className:"block max-h-[420px] w-full object-contain"});if("audio"===p.kind)return t.jsx("div",Object.assign({className:"flex min-h-[72px] items-center p-4"},{children:t.jsx("audio",{className:"w-full",controls:!0,src:p.url})}));if("video"===p.kind)return t.jsx("video",{className:"block max-h-[420px] w-full bg-black",controls:!0,preload:"metadata",src:p.url});if("pdf"===p.kind||"text"===p.kind){const e="pdf"===p.kind?`${p.url}#page=1&toolbar=0&navpanes=0&scrollbar=0&view=FitH`:p.url;return E(e,p.fileName)}if("html"===p.kind&&!v){const e=["allow-same-origin","allow-forms","allow-popups","allow-downloads","allow-modals",h?"":"allow-scripts"].filter(Boolean).join(" ");return E(p.url,p.fileName,{sandbox:e})}return"office"===p.kind?E(`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(p.url)}`,p.fileName):t.jsxs("div",Object.assign({className:"flex min-h-[120px] items-center justify-center gap-3 p-6 text-sm"},{children:[t.jsx(d.default,{className:"h-8 w-8 shrink-0"}),t.jsx("span",Object.assign({className:"break-all"},{children:p.extension.toUpperCase()}))]}))})()})]}))},exports.getFilePreviewInfo=e=>{var t,s;try{const o=k(e),a=new URL(o);if("https:"!==a.protocol&&"http:"!==a.protocol)return null;const i=a.pathname.split("/").filter(Boolean).pop();if(!i)return null;const l=decodeURIComponent(i),n=null===(s=null===(t=l.match(/\.([a-z0-9]{1,10})$/i))||void 0===t?void 0:t[1])||void 0===s?void 0:s.toLowerCase();return n?{url:o,fileName:l,extension:n,kind:j(n)}:null}catch(e){return null}},exports.normalizeMarkdownUrl=k,exports.shouldRenderFilePreview=(e,t)=>!!e&&(!t||!t.current.has(e.url)&&(t.current.add(e.url),!0));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),s=require("../../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../../../Addons/Auth/hooks/useAuthContext.js"),r=require("../../../../../../hooks/pickaxe/useSubmitDocument.js"),l=require("../../hooks/usePickaxeMarkdownContext.js"),n=require("../../../../../Icons/download.svg.js"),a=require("../../../../../Icons/copy.svg.js"),c=require("../../../../../Icons/copied.svg.js"),d=require("../../../../../Icons/file.svg.js"),u=require("../../../../../Icons/upload-cloud.svg.js"),p=require("copy-to-clipboard"),m=require("../../../../../../common/error.js");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=f(p);const h=/(?:https?:\/\/|www\.)[^\s<>"']+/gi,v=new Set(["jpeg","jpg","gif","bmp","webp","svg","tiff","avif","png","jfif","pjpeg","pjp"]),w=new Set(["mp3","wav","ogg","flac","aac","wma","alac","m4a","aiff","ape","au","mid","midi","opus"]),b=new Set(["mp4","webm","mov","avi","mkv","m4v"]),g=new Set(["csv","tsv","txt","json","xml","md","log","yaml","yml"]),j=new Set(["doc","docx","xls","xlsx","ppt","pptx"]),k=new Set(["pdf","html","htm",...g,...j]),y=e=>v.has(e)?"image":w.has(e)?"audio":b.has(e)?"video":"pdf"===e?"pdf":"html"===e||"htm"===e?"html":g.has(e)?"text":j.has(e)?"office":"file",N=e=>{const t=(e=>{let t=e.trim();for(;/[),.;!?]$/.test(t);)t=t.slice(0,-1);return t})(e);return t.startsWith("http://")?`https://${t.slice(7)}`:t.startsWith("www.")?`https://${t}`:t},C=e=>{try{return new URL(N(e)).pathname.includes("/action_generated_files/")}catch(e){return!1}},S=e=>{try{return new URL(N(e)).pathname.includes("/documentinterrogation/")}catch(e){return!1}},O=e=>{const t=N(e);if(C(t))return!1;if(S(t))return!0;if((e=>{const t=N(e);return/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i.test(t)||/loom\.com\/(?:share|embed)\/([\w-]+)/i.test(t)||/vimeo\.com\/(?:video\/)?(\d+)/i.test(t)||/streamable\.com\/([\w-]+)/i.test(t)})(t))return!0;const o=(e=>{var t,o,s,i;try{const r=new URL(N(e));return"https:"!==r.protocol&&"http:"!==r.protocol?null:null!==(i=null===(s=null===(o=null===(t=r.pathname.split("/").filter(Boolean).pop())||void 0===t?void 0:t.match(/\.([a-z0-9]{1,10})$/i))||void 0===o?void 0:o[1])||void 0===s?void 0:s.toLowerCase())&&void 0!==i?i:null}catch(e){return null}})(t);return!!o&&k.has(o)},I=(e,t)=>{const o=N(e);return O(o)||(null==t?void 0:t.has(o))};exports.default=({fileInfo:p,displayName:f})=>{const{theme:h,colors:v,disableHtml:w,disableJs:b}=l.usePickaxeMarkdownContext(),{contextId:g,pickaxeId:j,pickaxe:k,translations:y}=s.usePickaxeContext(),{isLoggedIn:N,token:C}=i.useAuthContext(),S=r.useSubmitDocument(),[O,I]=o.useState(!1),[F,q]=o.useState(!1),[U,P]=o.useState(!1),R=(e,t)=>{var o;return null!==(o=null==y?void 0:y[e])&&void 0!==o?o:t},_="dark"===h?"#30363D":"#D0D7DE",D="dark"===h?"#0D1117":"#F6F8FA",$="dark"===h?"#161B22":"#FFFFFF",L=(null==f?void 0:f.trim())||p.fileName,T=L!==p.fileName,A={display:"inline-flex",width:32,height:32,alignItems:"center",justifyContent:"center",borderRadius:4,color:v.accentText,backgroundColor:v.accent,opacity:.88,flexShrink:0},B=(e,o,s)=>t.jsx("div",Object.assign({className:"flex w-full p-4"},{children:t.jsxs("div",Object.assign({className:"relative w-full overflow-hidden rounded-md shadow-sm",style:{aspectRatio:"8.5 / 11",backgroundColor:$,border:`1px solid ${_}`}},{children:[t.jsx("iframe",Object.assign({src:e,title:o},s,{className:"h-full w-full",scrolling:"no",tabIndex:-1,style:{border:"none",pointerEvents:"none"}})),t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-10",style:{background:"dark"===h?"linear-gradient(to top, rgba(22,27,34,0.95), rgba(22,27,34,0))":"linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0))"}})]}))}));return t.jsxs("div",Object.assign({className:"my-2 w-full overflow-hidden rounded-lg",style:{border:`1px solid ${_}`,backgroundColor:D,color:v.secondaryText}},{children:[t.jsxs("div",Object.assign({className:"flex items-center justify-between gap-3 border-b px-3 py-2",style:{borderColor:_}},{children:[t.jsx("a",Object.assign({href:p.url,target:"_blank",rel:"noopener noreferrer",className:"min-w-0 flex-1 truncate text-sm font-semibold hover:underline",style:{color:v.secondaryText},title:T?`${L} (${p.fileName})`:L},{children:L})),t.jsxs("div",Object.assign({className:"flex shrink-0 items-center gap-1.5"},{children:[t.jsx("button",Object.assign({type:"button",onClick:()=>{const e=document.createElement("a");e.href=p.url,e.download=p.fileName,e.target="_blank",e.rel="noopener noreferrer",e.click()},title:R("download","Download"),"aria-label":R("download","Download"),style:A},{children:t.jsx(n.default,{className:"h-[18px] w-[18px]"})})),t.jsx("button",Object.assign({type:"button",onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){try{I(!0),x.default(p.url),yield new Promise((e=>setTimeout(e,1500)))}finally{I(!1)}}))},title:O?R("copied","Copied"):R("copy-link","Copy link"),"aria-label":O?R("copied","Copied"):R("copy-link","Copy link"),style:Object.assign(Object.assign({},A),{opacity:O?1:A.opacity})},{children:O?t.jsx(c.default,{className:"h-[18px] w-[18px]"}):t.jsx(a.default,{className:"h-[18px] w-[18px]"})})),N&&C&&t.jsx("button",Object.assign({type:"button",disabled:F||U,onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){if(C&&!F){q(!0),P(!1);try{const e=yield fetch(p.url);if(!e.ok)throw new Error("Failed to download generated file.");const t=yield e.blob(),o=new File([t],p.fileName,{type:t.type||"application/octet-stream"});yield S.document(Object.assign(Object.assign({contextId:g,pickaxeId:j,file:o},(null==k?void 0:k.workspaceid)&&{workspaceId:k.workspaceid}),{studioSessionToken:C,isUserDocument:!0})),P(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(m.default(e))}finally{q(!1),P(!1)}}}))},title:F?R("saving","Saving..."):U?R("saved","Saved"):R("save-to-knowledge-base","Save to Knowledge Base"),"aria-label":F?R("saving","Saving..."):U?R("saved","Saved"):R("save-to-knowledge-base","Save to Knowledge Base"),style:Object.assign(Object.assign({},A),{opacity:F||U?.55:A.opacity,cursor:F||U?"not-allowed":"pointer"})},{children:t.jsx(u.default,{className:"h-[18px] w-[18px]"})}))]}))]})),t.jsx("div",{children:(()=>{if("image"===p.kind)return t.jsx("img",{src:p.url,alt:p.fileName,className:"block max-h-[420px] w-full object-contain"});if("audio"===p.kind)return t.jsx("div",Object.assign({className:"flex min-h-[72px] items-center p-4"},{children:t.jsx("audio",{className:"w-full",controls:!0,src:p.url})}));if("video"===p.kind)return t.jsx("video",{className:"block max-h-[420px] w-full bg-black",controls:!0,preload:"metadata",src:p.url});if("pdf"===p.kind||"text"===p.kind){const e="pdf"===p.kind?`${p.url}#page=1&toolbar=0&navpanes=0&scrollbar=0&view=FitH`:p.url;return B(e,p.fileName)}if("html"===p.kind&&!w){const e=["allow-same-origin","allow-forms","allow-popups","allow-downloads","allow-modals",b?"":"allow-scripts"].filter(Boolean).join(" ");return B(p.url,p.fileName,{sandbox:e})}return"office"===p.kind?B(`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(p.url)}`,p.fileName):t.jsxs("div",Object.assign({className:"flex min-h-[120px] items-center justify-center gap-3 p-6 text-sm"},{children:[t.jsx(d.default,{className:"h-8 w-8 shrink-0"}),t.jsx("span",Object.assign({className:"break-all"},{children:p.extension.toUpperCase()}))]}))})()})]}))},exports.getFilePreviewInfo=e=>{var t,o;try{const s=N(e),i=new URL(s);if("https:"!==i.protocol&&"http:"!==i.protocol)return null;const r=i.pathname.split("/").filter(Boolean).pop();if(!r)return null;const l=decodeURIComponent(r),n=null===(o=null===(t=l.match(/\.([a-z0-9]{1,10})$/i))||void 0===t?void 0:t[1])||void 0===o?void 0:o.toLowerCase();return n?{url:s,fileName:l,extension:n,kind:y(n)}:null}catch(e){return null}},exports.isDocumentSourceUrl=S,exports.isGeneratedFileUrl=C,exports.isSourceLikeRichPreviewUrl=O,exports.normalizeMarkdownUrl=N,exports.shouldRenderFilePreview=(e,t)=>!!e&&(!t||!t.current.has(e.url)&&(t.current.add(e.url),!0)),exports.shouldSuppressRichPreviewForUrl=I,exports.shouldSuppressRichPreviewInText=(e,t)=>{for(const o of e.matchAll(h))if(I(o[0],t))return!0;return!1};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("../../hooks/usePickaxeMarkdownContext.js"),o=require("../common/IframeVideo.js"),i=require("./FilePreview.js");const s=e=>{let t="";return r.Children.forEach(e,(e=>{"string"!=typeof e&&"number"!=typeof e?r.isValidElement(e)&&(t+=s(e.props.children)):t+=e})),t.trim().replace(/\s+/g," ")};exports.A=({href:l="",children:n,filePreviewSeenRef:c})=>{const{colors:m}=t.usePickaxeMarkdownContext(),a=r.useMemo((()=>l?i.normalizeMarkdownUrl(l):""),[l]),u=r.useMemo((()=>i.getFilePreviewInfo(a)),[a]),d=r.useMemo((()=>((e,r)=>{const t=s(e);if(t&&t!==r&&i.normalizeMarkdownUrl(t)!==r)return t})(n,a)),[n,a]),f=r.useMemo((()=>{if(u)return null;const e=a.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const r=a.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(r)return{title:"loom-embed",src:`https://www.loom.com/embed/${r[1]}`};const t=a.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(t)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${t[1]}`};const o=a.match(/streamable\.com\/([\w-]+)/i);return o?{title:"streamable-embed",src:`https://streamable.com/e/${o[1]}`}:null}),[u,a]);return f?e.jsx(o.default,{title:f.title,src:f.src}):u&&i.shouldRenderFilePreview(u,c)?e.jsx(i.default,{fileInfo:u,displayName:d}):e.jsx("a",Object.assign({href:a,target:"_blank",rel:"noopener noreferrer",style:{color:m.accent}},{children:n}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("../../hooks/usePickaxeMarkdownContext.js"),o=require("../common/IframeVideo.js"),s=require("./FilePreview.js");const i=e=>{let t="";return r.Children.forEach(e,(e=>{"string"!=typeof e&&"number"!=typeof e?r.isValidElement(e)&&(t+=i(e.props.children)):t+=e})),t.trim().replace(/\s+/g," ")};exports.A=({href:l="",children:n,filePreviewSeenRef:c,suppressedRichPreviewUrls:m})=>{const{colors:u}=t.usePickaxeMarkdownContext(),a=r.useMemo((()=>l?s.normalizeMarkdownUrl(l):""),[l]),d=r.useMemo((()=>s.shouldSuppressRichPreviewForUrl(a,m)),[a,m]),h=r.useMemo((()=>s.getFilePreviewInfo(a)),[a]),f=r.useMemo((()=>((e,r)=>{const t=i(e);if(t&&t!==r&&s.normalizeMarkdownUrl(t)!==r)return t})(n,a)),[n,a]),w=r.useMemo((()=>{if(d)return null;if(h)return null;const e=a.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const r=a.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(r)return{title:"loom-embed",src:`https://www.loom.com/embed/${r[1]}`};const t=a.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(t)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${t[1]}`};const o=a.match(/streamable\.com\/([\w-]+)/i);return o?{title:"streamable-embed",src:`https://streamable.com/e/${o[1]}`}:null}),[h,a,d]);return w?e.jsx(o.default,{title:w.title,src:w.src}):h&&!d&&s.shouldRenderFilePreview(h,c)?e.jsx(s.default,{fileInfo:h,displayName:f}):e.jsx("a",Object.assign({href:a,target:"_blank",rel:"noopener noreferrer",style:{color:u.accent}},{children:n}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../common/IframeVideo.js");exports.P=({children:o})=>{const m=t.useMemo((()=>{if("string"!=typeof o)return null;const e=o.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=o.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const r=o.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(r)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${r[1]}`};const m=o.match(/streamable\.com\/([\w-]+)/i);return m?{title:"streamable-embed",src:`https://streamable.com/e/${m[1]}`}:null}),[o]);return m?e.jsx(r.default,{title:m.title,src:m.src}):e.jsx("p",{children:o})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../common/IframeVideo.js"),o=require("../A/FilePreview.js");exports.P=({children:s,suppressedRichPreviewUrls:i})=>{const c=t.useMemo((()=>{if("string"!=typeof s)return null;if(o.shouldSuppressRichPreviewInText(s,i))return null;const e=s.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=s.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const r=s.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(r)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${r[1]}`};const c=s.match(/streamable\.com\/([\w-]+)/i);return c?{title:"streamable-embed",src:`https://streamable.com/e/${c[1]}`}:null}),[s,i]);return c?e.jsx(r.default,{title:c.title,src:c.src}):e.jsx("p",{children:s})};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),n=require("react"),t=require("./hooks/usePickaxeMarkdownContext.js"),i=require("./utils/custom-plugins.js"),s=require("react-markdown"),a=require("remark-gfm"),o=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/A/FilePreview.js"),p=require("./Components/P/index.js"),f=require("./Components/Img/index.js"),h=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),x=require("./Components/Headings/index.js"),g=require("./Components/List/index.js"),j=require("./Components/Table/index.js"),b=require("./Components/Others/index.js"),k=require("./Components/Action/index.js"),q=require("./Components/Artifact/index.js"),C=require("./Components/Others/Think.js"),w=require("../../../../common/cn.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=v(s),O=v(a),$=v(o),P=v(l),S=v(c);exports.PickaxeMarkdownRenderer=({className:s,style:a,children:o,value:l,maxLines:c,maxChars:v,multiLineBreaks:A,onExpandClick:H,filePreviewSeenRef:T})=>{const{colors:M,rtl:R,disableHtml:I,disableJs:_,disableCss:N}=t.usePickaxeMarkdownContext(),[E,L]=n.useState({width:0,height:0}),[B,F]=n.useState(null),z=n.useRef(null),J=n.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),A&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,A]);n.useEffect((()=>{if(v)return void F(J.length>v?J.slice(0,v)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void F(null);if(!z.current||!J||B)return;const e=z.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=c*r;if(!(E.height>n))return;const t=Math.floor(E.width/8),i=Math.floor(t*c);F(J.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[J,c,v,E,B]);const W=n.useRef(new Set);T||(W.current=new Set);const D=null!=T?T:W,Q={h1:x.H1,h2:x.H2,h3:x.H3,h4:x.H4,h5:x.H5,p:p.P,a:e=>r.jsx(u.A,Object.assign({},e,{filePreviewSeenRef:D})),img:e=>{const n="string"==typeof e.src?e.src:"",t=d.getFilePreviewInfo(n);return t?d.shouldRenderFilePreview(t,D)?r.jsx(d.default,{fileInfo:t,displayName:"string"==typeof e.alt?e.alt:void 0}):r.jsx("a",Object.assign({href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:M.accent}},{children:e.alt||t.fileName})):r.jsx(f.Img,Object.assign({},e))},iframe:h.Iframe,code:m.Code,ol:g.Ol,ul:g.Ul,li:g.Li,table:j.Table,th:j.Th,tr:j.Tr,td:j.Td,hr:b.Hr,br:b.Br,blockquote:b.Blockquote,span:n=>{var{children:t}=n,i=e.__rest(n,["children"]);return"pxe-expand-btn"===i.className?r.jsx("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:M.accent,marginLeft:".25rem",userSelect:"none"},H&&{cursor:"pointer"})},H&&{onClick:H},{children:t})):r.jsx("span",Object.assign({},i,{children:t}))},"action-caption":k.ActionCaption,"action-finished":k.ActionFinished,"action-error":k.ActionError,artifact:q.Artifact,"artifact-error":q.ArtifactError,think:C.Think};n.useEffect((()=>{if(!z.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;L({width:e,height:n})}}));return e.observe(z.current),()=>{e.disconnect()}}),[]);const U=B||J;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:z,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},a)},R&&{dir:"rtl"},{children:[r.jsx(y.default,Object.assign({className:w.default("pxe-prose",s),components:Q,remarkPlugins:[O.default,[$.default,{singleDollarTextMath:!1}],i.remarkSmartQuotes],rehypePlugins:[i.rehypeCode,P.default,...I?[]:[S.default],[i.rehypeSanitize,{disableJs:_,disableCss:N}]]},{children:U})),o]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),n=require("react"),t=require("./hooks/usePickaxeMarkdownContext.js"),s=require("./utils/custom-plugins.js"),i=require("react-markdown"),a=require("remark-gfm"),o=require("remark-math"),l=require("rehype-katex"),c=require("rehype-raw"),u=require("./Components/A/index.js"),d=require("./Components/A/FilePreview.js"),p=require("./Components/P/index.js"),h=require("./Components/Img/index.js"),f=require("./Components/Iframe/index.js"),m=require("./Components/Code/index.js"),x=require("./Components/Headings/index.js"),g=require("./Components/List/index.js"),j=require("./Components/Table/index.js"),b=require("./Components/Others/index.js"),w=require("./Components/Action/index.js"),k=require("./Components/Artifact/index.js"),q=require("./Components/Others/Think.js"),C=require("../../../../common/cn.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var y=v(i),P=v(a),O=v(o),$=v(l),S=v(c);exports.PickaxeMarkdownRenderer=({className:i,style:a,children:o,value:l,maxLines:c,maxChars:v,multiLineBreaks:R,onExpandClick:A,filePreviewSeenRef:H,suppressedRichPreviewUrls:T})=>{const{colors:M,rtl:I,disableHtml:_,disableJs:N,disableCss:E}=t.usePickaxeMarkdownContext(),[F,L]=n.useState({width:0,height:0}),[U,B]=n.useState(null),z=n.useRef(null),J=n.useMemo((()=>{if(!l)return"";let e=l.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),R&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[l,R]);n.useEffect((()=>{if(v)return void B(J.length>v?J.slice(0,v)+'<span class="pxe-expand-btn">...</span>':null);if(!c)return void B(null);if(!z.current||!J||U)return;const e=z.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),n=c*r;if(!(F.height>n))return;const t=Math.floor(F.width/8),s=Math.floor(t*c);B(J.slice(0,s)+'<span class="pxe-expand-btn">...</span>')}),[J,c,v,F,U]);const W=n.useRef(new Set);H||(W.current=new Set);const D=null!=H?H:W,Q={h1:x.H1,h2:x.H2,h3:x.H3,h4:x.H4,h5:x.H5,p:e=>r.jsx(p.P,Object.assign({},e,{suppressedRichPreviewUrls:T})),a:e=>r.jsx(u.A,Object.assign({},e,{filePreviewSeenRef:D,suppressedRichPreviewUrls:T})),img:e=>{const n="string"==typeof e.src?e.src:"",t=d.getFilePreviewInfo(n);return t&&!d.shouldSuppressRichPreviewForUrl(t.url,T)?d.shouldRenderFilePreview(t,D)?r.jsx(d.default,{fileInfo:t,displayName:"string"==typeof e.alt?e.alt:void 0}):r.jsx("a",Object.assign({href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:M.accent}},{children:e.alt||t.fileName})):r.jsx(h.Img,Object.assign({},e))},iframe:f.Iframe,code:m.Code,ol:g.Ol,ul:g.Ul,li:g.Li,table:j.Table,th:j.Th,tr:j.Tr,td:j.Td,hr:b.Hr,br:b.Br,blockquote:b.Blockquote,span:n=>{var{children:t}=n,s=e.__rest(n,["children"]);return"pxe-expand-btn"===s.className?r.jsx("span",Object.assign({},s,{style:Object.assign({display:"inline",fontWeight:500,color:M.accent,marginLeft:".25rem",userSelect:"none"},A&&{cursor:"pointer"})},A&&{onClick:A},{children:t})):r.jsx("span",Object.assign({},s,{children:t}))},"action-caption":w.ActionCaption,"action-finished":w.ActionFinished,"action-error":w.ActionError,artifact:k.Artifact,"artifact-error":k.ArtifactError,think:q.Think};n.useEffect((()=>{if(!z.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:n}=r.contentRect;L({width:e,height:n})}}));return e.observe(z.current),()=>{e.disconnect()}}),[]);const G=U||J;return r.jsxs("div",Object.assign({className:"pxe-markdown",ref:z,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},a)},I&&{dir:"rtl"},{children:[r.jsx(y.default,Object.assign({className:C.default("pxe-prose",i),components:Q,remarkPlugins:[P.default,[O.default,{singleDollarTextMath:!1}],s.remarkSmartQuotes],rehypePlugins:[s.rehypeCode,$.default,..._?[]:[S.default],[s.rehypeSanitize,{disableJs:N,disableCss:E}]]},{children:G})),o]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("react"),r=require("../PickaxeMarkdown/Renderer.js"),t=require("../PickaxeMarkdown/Components/A/FilePreview.js"),i=require("../../../../common/utils.js"),s=require("../../../../common/cn.js");const a=n.lazy((()=>Promise.resolve().then((function(){return require("./TextPart/index.js")})))),o=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningPart/index.js")})))),l=n.lazy((()=>Promise.resolve().then((function(){return require("./ActionToolCaptionPart/index.js")})))),u=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningCaptionPart/index.js")})))),c=/(!?)\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|www\.[^\s)]+)\)/g;exports.default=({className:d,parts:p})=>{const f=n.useRef(new Set);return f.current=new Set,e.jsx("div",Object.assign({className:s.default("flex flex-col gap-2",d)},{children:e.jsx(n.Suspense,Object.assign({fallback:e.jsx("div",{})},{children:p.map(((n,s)=>{if(!n.isVisible)return null;if("text"===n.type){const i=((e,n)=>{var r,i;const s=[];let a=0;for(const o of e.matchAll(c)){const l=null!==(r=o.index)&&void 0!==r?r:0,u=o[0],c="!"===o[1],d=null===(i=o[2])||void 0===i?void 0:i.trim(),p=o[3],f=t.getFilePreviewInfo(p);if(!f)continue;l>a&&s.push({type:"markdown",value:e.slice(a,l)});const v=d&&t.normalizeMarkdownUrl(d)!==f.url?d:void 0;t.shouldRenderFilePreview(f,n)?s.push({type:"preview",key:`${f.url}-${l}`,fileInfo:f,displayName:v}):s.push({type:"markdown",value:c?u:`[${d||f.fileName}](${f.url})`}),a=l+u.length}return a<e.length&&s.push({type:"markdown",value:e.slice(a)}),s.length?s:[{type:"markdown",value:e}]})(n.content,f);return e.jsx(a,{children:i.map(((n,i)=>"preview"===n.type?e.jsx(t.default,{fileInfo:n.fileInfo,displayName:n.displayName},n.key):n.value?e.jsx(r.PickaxeMarkdownRenderer,{value:n.value,filePreviewSeenRef:f},i):null))},s)}if("reasoning"===n.type)return e.jsx(o,Object.assign({isReasoning:s===p.length-1},{children:e.jsx(r.PickaxeMarkdownRenderer,{value:n.content})}),s);if("data-action-tool-caption"===n.type){const r=i.safeJSONParse(n.content);return e.jsx(l,Object.assign({},r&&r,{isLoading:s===p.length-1}),s)}if("data-reasoning-caption"===n.type){const r=i.safeJSONParse(n.content);return e.jsx(u,Object.assign({},r&&r,{isLoading:s===p.length-1}),s)}return null}))}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("react"),r=require("../PickaxeMarkdown/Renderer.js"),s=require("../PickaxeMarkdown/Components/A/FilePreview.js"),t=require("../../../../common/utils.js"),i=require("../../../../common/cn.js");const a=n.lazy((()=>Promise.resolve().then((function(){return require("./TextPart/index.js")})))),o=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningPart/index.js")})))),l=n.lazy((()=>Promise.resolve().then((function(){return require("./ActionToolCaptionPart/index.js")})))),u=n.lazy((()=>Promise.resolve().then((function(){return require("./ReasoningCaptionPart/index.js")})))),c=/(!?)\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|www\.[^\s)]+)\)/g,d=e=>{const n=new Set;for(const r of e){if("data-tool-assets"!==r.type)continue;const e=t.safeJSONParse(r.content);if(null==e?void 0:e.assets)for(const r of e.assets)r.value&&!s.isGeneratedFileUrl(r.value)&&n.add(s.normalizeMarkdownUrl(r.value))}return n};exports.default=({className:p,parts:f})=>{const v=n.useRef(new Set);v.current=new Set;const x=d(f);return e.jsx("div",Object.assign({className:i.default("flex flex-col gap-2",p)},{children:e.jsx(n.Suspense,Object.assign({fallback:e.jsx("div",{})},{children:f.map(((n,i)=>{if(!n.isVisible)return null;if("text"===n.type){const t=((e,n,r)=>{var t,i;const a=[];let o=0;for(const l of e.matchAll(c)){const u=null!==(t=l.index)&&void 0!==t?t:0,c=l[0],d="!"===l[1],p=null===(i=l[2])||void 0===i?void 0:i.trim(),f=l[3],v=s.getFilePreviewInfo(f);if(!v)continue;if(s.shouldSuppressRichPreviewForUrl(v.url,r))continue;u>o&&a.push({type:"markdown",value:e.slice(o,u)});const x=p&&s.normalizeMarkdownUrl(p)!==v.url?p:void 0;s.shouldRenderFilePreview(v,n)?a.push({type:"preview",key:`${v.url}-${u}`,fileInfo:v,displayName:x}):a.push({type:"markdown",value:d?c:`[${p||v.fileName}](${v.url})`}),o=u+c.length}return o<e.length&&a.push({type:"markdown",value:e.slice(o)}),a.length?a:[{type:"markdown",value:e}]})(n.content,v,x);return e.jsx(a,{children:t.map(((n,t)=>"preview"===n.type?e.jsx(s.default,{fileInfo:n.fileInfo,displayName:n.displayName},n.key):n.value?e.jsx(r.PickaxeMarkdownRenderer,{value:n.value,filePreviewSeenRef:v,suppressedRichPreviewUrls:x},t):null))},i)}if("reasoning"===n.type)return e.jsx(o,Object.assign({isReasoning:i===f.length-1},{children:e.jsx(r.PickaxeMarkdownRenderer,{value:n.content,suppressedRichPreviewUrls:x})}),i);if("data-action-tool-caption"===n.type){const r=t.safeJSONParse(n.content);return e.jsx(l,Object.assign({},r&&r,{isLoading:i===f.length-1}),i)}if("data-reasoning-caption"===n.type){const r=t.safeJSONParse(n.content);return e.jsx(u,Object.assign({},r&&r,{isLoading:i===f.length-1}),i)}return null}))}))}))},exports.getSuppressedRichPreviewUrls=d;
@@ -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"),l=require("../../hooks/pickaxe/useResponseContext.js"),o=require("./Addons/Document/hooks/useDocumentContext.js"),c=require("./Addons/Artifact/hooks/useArtifactContext.js"),n=require("uuid"),d=require("./Addons/Scroll/Provider.js"),u=require("./common/PickaxeSkeleton.js"),x=require("./Chat/index.js"),p=require("./Form/index.js"),m=require("./Addons/Auth/index.js"),f=require("../../common/cn.js"),j=require("../../common/api/pickaxe.js"),h=require("../../common/validation.js"),v=require("./common/AccessGroupCardPreview.js"),g=require("./common/PickaxeAvatar.js"),b=require("../Icons/lock.svg.js"),k=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"),w=require("../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js");const y=({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:N,className:q})=>{const{sessionId:O,styles:_,colors:C,responsiveBy:A,deploymentType:I,isNewChat:S,isEmbed:P,opacity:E,deploymentId:U,sender:G,portalId:R,validationStatus:T,validationUpgradeGroups:L,validationUpgradeUrl:D,stripeAccountId:F,clientSecret:M,translations:B,preventInitialSessionId:V,setClientSecret:$,setStripeAccountId:W,setValidationStatus:z,setValidationUpgradeGroups:H,setValidationUpgradeUrl:J,setContextId:K,setPickaxeId:X,setSessionId:Y,setPickaxe:Q,setAccessGroup:Z}=i.usePickaxeContext(),{isSent:ee,token:se}=r.useAuthContext(),{setMessages:te,setResponse:ae,setError:ie,setLimitData:re,setIsSwitchedToChat:le}=l.useResponseContext(),{setDocumentError:oe}=o.useDocumentContext(),{setCurrentArtifact:ce}=c.useArtifactContext(),[ne,de]=a.useState(!1),ue=t.usePickaxe(),xe="chat-input"===I&&S&&!ee,pe=a.useMemo((()=>F?w.loadStripe(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:F}):null),[F]);a.useEffect((()=>{X(N)}),[N]);a.useEffect((()=>{if(!U&&!R||!ue.data)return;if("stripe_checkout"===T)return;e.__awaiter(void 0,void 0,void 0,(function*(){var e;z("loading");try{const s=yield j.default.post("/validate_studio_deployment",{data:{deploymentId:U,sender:G||void 0,studioSessionToken:se,portalId:R,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid}});if(s.data.success)z("success"),H([]),J(null),Z(s.data.accessGroup);else{const e=h.getValidationFailure(s.data);if(!e)return z("login_required"),H([]),void J(null);z(e.status),H(e.upgradeGroups),J(e.upgradeUrl),de(!0)}}catch(e){console.error("Failed to validate deployment:",e),z("success")}}))}),[U,G,se,R,ue.data]),a.useEffect((()=>{if(!ue.data)return;const e=ue.data.chatflag;V||Y(e?n.v4():""),K(n.v4()),e?te([]):ae(null),ie(""),oe(""),re(null),ce(null),le(!1),Q(ue.data),de(!0)}),[ue.data]),a.useEffect((()=>{ie(""),oe(""),re(null),te([]),ae(null),ce(null)}),[O]);const me=a.useMemo((()=>{const e=null!=E?E: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,E]);if(!ue.data)return null;return s.jsx("div",Object.assign({className:f.default("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===_.theme&&"dark",q),style:Object.assign({backgroundColor:xe?"transparent":me,color:C.text},_.font&&"Real Head Pro"!==_.font&&{fontFamily:_.font})},{children:(()=>{var t,a;if("stripe_checkout"===T&&M&&pe)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:()=>{$&&$(null),W&&W(null),z("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(y,{className:"w-5 h-5"}),s.jsx("span",{children:(null==B?void 0:B.back)||"Back"})]}))})),s.jsx("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s.jsx(k.EmbeddedCheckoutProvider,Object.assign({stripe:pe,options:{clientSecret:M}},{children:s.jsx(k.EmbeddedCheckout,{})}))}))]}));if(ue.isLoading||!ne||"loading"===T)return s.jsx("div",Object.assign({className:f.default("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===A?"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(u.default,{className:"w-[72px] h-[72px]"}),s.jsx(u.default,{className:"h-[20px] mt-6 w-full"}),s.jsx(u.default,{className:"h-[20px] mt-2 w-full"}),s.jsx(u.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(u.default,{className:f.default("w-full min-h-[48px]","viewport"===A?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===T){const e=L.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==B?void 0:B["upgrade-required"])||"Upgrade Required"})),s.jsx("p",Object.assign({className:"break-words opacity-80"},{children:(null==B?void 0:B["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:L.map(((e,t)=>s.jsx(v.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==B?void 0:B["access-locked"])||"Access Locked"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===T&&P?s.jsx(m.default,{}):"login_required"!==T||P?"access_denied"===T?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(g.Avatar,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s.jsx(g.AvatarImage,{src:null===(t=ue.data)||void 0===t?void 0:t.coverphoto,alt:`${null===(a=ue.data)||void 0===a?void 0:a.formtitle} Logo`}),s.jsx(g.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==B?void 0:B["access-denied"])||"Access Denied"})),s.jsxs("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s.jsx(b.default,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s.jsx("p",Object.assign({className:"ml-1"},{children:(null==B?void 0:B["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:_.cornerRadius},onClick:()=>{e.__awaiter(void 0,void 0,void 0,(function*(){var e,s;const t=L.map((e=>e.accessGroupId));try{const a=yield j.default.post("/request_access",{data:{sender:G||void 0,studioSessionToken:se,studioId:null===(e=ue.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=ue.data)||void 0===s?void 0:s.formid,deploymentId:U,accessGroupIds:t})}});a.data.success?alert((null==B?void 0:B["access-requested-successfully"])||"Successfully requested access!"):alert(a.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==B?void 0:B["request-access"])||"Request Access"})),s.jsx("span",Object.assign({className:"mt-4 mb-2"},{children:(null==B?void 0:B.or)||"or"})),s.jsx("span",Object.assign({className:"font-medium text-lg"},{children:(null==B?void 0:B["sign-in-with-different-account"])||"Sign in with a different account"}))]})):O?s.jsx(d.ScrollProvider,{children:s.jsx(x.default,{})}):s.jsx(d.ScrollProvider,{children:s.jsx(p.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==B?void 0:B["access-denied"])||"Access Denied"})),s.jsx("p",Object.assign({className:"opacity-80"},{children:(null==B?void 0:B["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"),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."}))]}))}))})()}))};
@@ -11,6 +11,7 @@ type AuthContextType = {
11
11
  isResendDisabled: boolean;
12
12
  isSent: boolean;
13
13
  isPricingAuth: boolean;
14
+ isAuthBootstrapComplete: boolean;
14
15
  setEmailInput: SetState<string>;
15
16
  setToken: SetState<string | null>;
16
17
  setIsLoggingIn: SetState<boolean>;
@@ -19,6 +20,7 @@ type AuthContextType = {
19
20
  setIsSent: SetState<boolean>;
20
21
  setIsPricingAuth: SetState<boolean>;
21
22
  setRedirectUrl: SetState<string | null>;
23
+ setIsAuthBootstrapComplete: SetState<boolean>;
22
24
  };
23
25
  export interface IAuthProviderProps {
24
26
  children: ReactNode;
@@ -0,0 +1 @@
1
+ export declare const useAuthBootstrap: () => void;
@@ -9,6 +9,7 @@ export declare const useAuthContext: () => {
9
9
  isResendDisabled: boolean;
10
10
  isSent: boolean;
11
11
  isPricingAuth: boolean;
12
+ isAuthBootstrapComplete: boolean;
12
13
  setEmailInput: import("../../../../../types/common").SetState<string>;
13
14
  setToken: import("../../../../../types/common").SetState<string | null>;
14
15
  setIsLoggingIn: import("../../../../../types/common").SetState<boolean>;
@@ -17,4 +18,5 @@ export declare const useAuthContext: () => {
17
18
  setIsSent: import("../../../../../types/common").SetState<boolean>;
18
19
  setIsPricingAuth: import("../../../../../types/common").SetState<boolean>;
19
20
  setRedirectUrl: import("../../../../../types/common").SetState<string | null>;
21
+ setIsAuthBootstrapComplete: import("../../../../../types/common").SetState<boolean>;
20
22
  };
@@ -7,7 +7,13 @@ export type FilePreviewInfo = {
7
7
  kind: FilePreviewKind;
8
8
  };
9
9
  export type FilePreviewSeenRef = MutableRefObject<Set<string>>;
10
+ export type SuppressedRichPreviewUrls = Set<string>;
10
11
  export declare const normalizeMarkdownUrl: (href: string) => string;
12
+ export declare const isGeneratedFileUrl: (href: string) => boolean;
13
+ export declare const isDocumentSourceUrl: (href: string) => boolean;
14
+ export declare const isSourceLikeRichPreviewUrl: (href: string) => boolean;
15
+ export declare const shouldSuppressRichPreviewForUrl: (href: string, suppressedRichPreviewUrls?: SuppressedRichPreviewUrls) => boolean | undefined;
16
+ export declare const shouldSuppressRichPreviewInText: (value: string, suppressedRichPreviewUrls?: SuppressedRichPreviewUrls) => boolean;
11
17
  export declare const getFilePreviewInfo: (href: string) => FilePreviewInfo | null;
12
18
  export declare const shouldRenderFilePreview: (fileInfo: FilePreviewInfo | null, seenRef?: FilePreviewSeenRef) => boolean;
13
19
  interface FilePreviewProps {
@@ -1,7 +1,8 @@
1
1
  import type { MarkdownComponent } from "../..";
2
- import type { FilePreviewSeenRef } from "./FilePreview";
2
+ import type { FilePreviewSeenRef, SuppressedRichPreviewUrls } from "./FilePreview";
3
3
  type AProps = Parameters<MarkdownComponent<"a">>[0] & {
4
4
  filePreviewSeenRef?: FilePreviewSeenRef;
5
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
5
6
  };
6
- export declare const A: ({ href, children, filePreviewSeenRef }: AProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const A: ({ href, children, filePreviewSeenRef, suppressedRichPreviewUrls, }: AProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -1,2 +1,7 @@
1
1
  import type { MarkdownComponent } from "../..";
2
- export declare const P: MarkdownComponent<"p">;
2
+ import type { SuppressedRichPreviewUrls } from "../A/FilePreview";
3
+ type PProps = Parameters<MarkdownComponent<"p">>[0] & {
4
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
5
+ };
6
+ export declare const P: ({ children, suppressedRichPreviewUrls }: PProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode, type CSSProperties } from "react";
2
- import { type FilePreviewSeenRef } from "./Components/A/FilePreview";
2
+ import { type FilePreviewSeenRef, type SuppressedRichPreviewUrls } from "./Components/A/FilePreview";
3
3
  export interface PickaxeMarkdownRendererProps {
4
4
  className?: string;
5
5
  style?: CSSProperties;
@@ -10,5 +10,6 @@ export interface PickaxeMarkdownRendererProps {
10
10
  multiLineBreaks?: boolean;
11
11
  onExpandClick?: () => void;
12
12
  filePreviewSeenRef?: FilePreviewSeenRef;
13
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
13
14
  }
14
- export declare const PickaxeMarkdownRenderer: ({ className, style, children: _children, value, maxLines, maxChars, multiLineBreaks, onExpandClick, filePreviewSeenRef, }: PickaxeMarkdownRendererProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const PickaxeMarkdownRenderer: ({ className, style, children: _children, value, maxLines, maxChars, multiLineBreaks, onExpandClick, filePreviewSeenRef, suppressedRichPreviewUrls, }: PickaxeMarkdownRendererProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,9 @@
1
1
  import type { PickaxeHistoryMessagePart } from "../../../../types/history";
2
+ import { type SuppressedRichPreviewUrls } from "../PickaxeMarkdown/Components/A/FilePreview";
2
3
  interface PickaxeMessagePartsProps {
3
4
  className?: string;
4
5
  parts: PickaxeHistoryMessagePart[];
5
6
  }
7
+ export declare const getSuppressedRichPreviewUrls: (parts: PickaxeHistoryMessagePart[]) => SuppressedRichPreviewUrls;
6
8
  declare const PickaxeMessageParts: ({ className, parts, }: PickaxeMessagePartsProps) => import("react/jsx-runtime").JSX.Element;
7
9
  export default PickaxeMessageParts;
@@ -35,7 +35,7 @@ export type PickaxeHistoryMessage = {
35
35
  createdAt: string;
36
36
  area?: PickaxeHistoryMessageArea;
37
37
  };
38
- export type PickaxeHistoryMessagePartsType = "text" | "reasoning" | "data-action-tool-caption" | "data-reasoning-caption";
38
+ export type PickaxeHistoryMessagePartsType = "text" | "reasoning" | "data-action-tool-caption" | "data-reasoning-caption" | "data-tool-assets";
39
39
  export type PickaxeHistoryMessagePart = {
40
40
  type: PickaxeHistoryMessagePartsType;
41
41
  content: string;
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useState as s,createContext as t}from"react";const i=t({}),n=({children:t})=>{const[n,r]=s(""),[g,d]=s(null),[l,o]=s(null),[c,u]=s(!1),[a,I]=s(!1),[m,p]=s(!1),[h,L]=s(!1),[S,b]=s(!1);return e(i.Provider,Object.assign({value:{emailInput:n,redirectUrl:l,token:g,isLoggedIn:!!g,isLoggedOut:!g,isLoggingIn:c,isSending:m,isResendDisabled:h,isSent:S,isPricingAuth:a,setIsPricingAuth:I,setRedirectUrl:o,setEmailInput:r,setToken:d,setIsLoggingIn:u,setIsSending:p,setIsResendDisabled:L,setIsSent:b}},{children:t}))};export{i as AuthContext,n as default};
1
+ import{jsx as e}from"react/jsx-runtime";import{useState as t,createContext as s}from"react";const i=s({}),n=({children:s})=>{const[n,r]=t(""),[o,l]=t(null),[g,d]=t(null),[u,a]=t(!1),[c,I]=t(!1),[m,p]=t(!1),[h,A]=t(!1),[L,S]=t(!1),[b,f]=t(!1);return e(i.Provider,Object.assign({value:{emailInput:n,redirectUrl:g,token:o,isLoggedIn:!!o,isLoggedOut:!o,isLoggingIn:u,isSending:m,isResendDisabled:h,isSent:L,isPricingAuth:c,isAuthBootstrapComplete:b,setIsPricingAuth:I,setRedirectUrl:d,setEmailInput:r,setToken:l,setIsLoggingIn:a,setIsSending:p,setIsResendDisabled:A,setIsSent:S,setIsAuthBootstrapComplete:f}},{children:s}))};export{i as AuthContext,n as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{useEffect as i}from"react";import{usePickaxeContext as t}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as o}from"./useAuthContext.js";import{useAuthVerify as s}from"./useAuthVerify.js";import{getAuthToken as n,deleteAuthToken as r,setAuthToken as d}from"../../../../../common/utils.js";import a from"../../../../../common/api/pickaxe.js";import l from"../../../../../common/error.js";import{useResponseContext as m}from"../../../../../hooks/pickaxe/useResponseContext.js";const u=()=>{const{deploymentId:u,pickaxe:c,translations:p,setSender:f,setSenderType:g}=t(),{emailInput:k,redirectUrl:I,isSending:v,isLoggedOut:h,isPricingAuth:w,setToken:y,setIsLoggingIn:j,setIsSending:x,setIsSent:S,setIsResendDisabled:E,setIsPricingAuth:P}=o(),b=s({token:n((null==c?void 0:c.studioid)||"")||"",enabled:h,setIsLoggingIn:j}),{setLimitData:L}=m();i((()=>{if("undefined"==typeof window)return;if(!b.data)return;const{success:e,token:i,error:t}=b.data;if(!e||t)return r(`PXE-token-${null==c?void 0:c.studioid}`),void P(!1);e&&i&&(y(i),f(void 0),g("STUDIO_USER"),w&&(P(!1),L(null)))}),[b.data,null==c?void 0:c.studioid]);return{onSend:i=>e(void 0,void 0,void 0,(function*(){try{if(!c)return;if(v)return;const e=k.trim().toLowerCase();if(!e)throw new Error((null==p?void 0:p["email-address-cannot-be-empty"])||"Email address cannot be empty.");if(!e.includes("@")||!e.includes("."))throw new Error((null==p?void 0:p["please-enter-valid-email-address"])||"Please enter a valid email address.");if(!c.studioid)throw new Error(`Studio ID is missing for ${c.formid}. Please contact support.`);x(!0),i&&E(!0);const t=(yield a.post("/auth/email",Object.assign(Object.assign({pickaxeId:c.formid,studioId:c.studioid,email:e},u&&{deploymentId:u}),{redirectUrl:I}))).data;if(!t.success)throw new Error(t.error||(null==p?void 0:p["failed-to-send-sign-in-link"])||"Failed to send sign-in link.");x(!1),S(!0),i&&(yield new Promise((e=>setTimeout(e,3e4))),E(!1)),d(`PXE-token-${c.studioid}`,t.token),P(!0)}catch(e){const i=l(e);alert(i)}finally{x(!1)}}))}};export{u as useAuth};
1
+ import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{usePickaxeContext as i}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as t}from"./useAuthContext.js";import{setAuthToken as o}from"../../../../../common/utils.js";import r from"../../../../../common/api/pickaxe.js";import s from"../../../../../common/error.js";const n=()=>{const{deploymentId:n,pickaxe:d,translations:a}=i(),{emailInput:l,redirectUrl:m,isSending:c,setIsSending:u,setIsSent:p,setIsResendDisabled:f,setIsPricingAuth:k}=t();return{onSend:i=>e(void 0,void 0,void 0,(function*(){try{if(!d)return;if(c)return;const e=l.trim().toLowerCase();if(!e)throw new Error((null==a?void 0:a["email-address-cannot-be-empty"])||"Email address cannot be empty.");if(!e.includes("@")||!e.includes("."))throw new Error((null==a?void 0:a["please-enter-valid-email-address"])||"Please enter a valid email address.");if(!d.studioid)throw new Error(`Studio ID is missing for ${d.formid}. Please contact support.`);u(!0),i&&f(!0);const t=(yield r.post("/auth/email",Object.assign(Object.assign({pickaxeId:d.formid,studioId:d.studioid,email:e},n&&{deploymentId:n}),{redirectUrl:m}))).data;if(!t.success)throw new Error(t.error||(null==a?void 0:a["failed-to-send-sign-in-link"])||"Failed to send sign-in link.");u(!1),p(!0),i&&(yield new Promise((e=>setTimeout(e,3e4))),f(!1)),o(`PXE-token-${d.studioid}`,t.token),k(!0)}catch(e){const i=s(e);alert(i)}finally{u(!1)}}))}};export{n as useAuth};
@@ -0,0 +1 @@
1
+ import{useEffect as t,useCallback as o}from"react";import{usePickaxeContext as e}from"../../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as s}from"../../../../../hooks/pickaxe/useResponseContext.js";import{getAuthToken as i,setAuthToken as r,deleteAuthToken as n}from"../../../../../common/utils.js";import{useAuthContext as a}from"./useAuthContext.js";import{useAuthVerify as u}from"./useAuthVerify.js";const c=()=>{const{pickaxe:c,setSender:d,setSenderType:m}=e(),{setLimitData:g}=s(),{token:p,isLoggedOut:k,isPricingAuth:f,setToken:h,setIsLoggingIn:l,setIsPricingAuth:x,setIsAuthBootstrapComplete:I}=a(),v=(null==c?void 0:c.studioid)||"",L=v?`PXE-token-${v}`:"",S=i(v)||"",j=u({token:S,enabled:k&&!!S,setIsLoggingIn:l});t((()=>{v&&I(!1)}),[I,v]);const A=o((t=>{r(L,t),h(t),d(void 0),m("STUDIO_USER"),f&&(x(!1),g(null))}),[L,f,x,g,d,m,h]);t((()=>{if(!L)return;if(!j.data)return;const{success:t,token:o,error:e}=j.data;if(!t||e)return n(L),x(!1),void I(!0);o&&(A(o),I(!0))}),[A,L,j.data,I,x]),t((()=>{var t;v&&(p?I(!0):S?j.isLoading||j.isFetching||(j.isError||j.isSuccess&&!(null===(t=j.data)||void 0===t?void 0:t.token))&&I(!0):I(!0))}),[j.data,j.isError,j.isFetching,j.isLoading,j.isSuccess,I,S,v,p])};export{c as useAuthBootstrap};
@@ -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(Object.assign(Object.assign({studioId:null==Oe?void 0:Oe.studioid},be&&{sender:be}),$e&&{studioSessionToken:$e}),!$e&&!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)}}))),[ge,he,ve,ye,be,$e,xe,je,ln]);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=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 Sn=(({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):Math.max(0,n-o)+i})({currentUses:Nn.currentUses,extraUses:Nn.extraUses,limit:bn,limitInterval:yn}),Cn=Sn===J?J:Math.max(0,Math.ceil(Sn)),_n=(({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:Nn.extraUses,limit:bn,limitInterval:yn}),En=_n===J?J:Math.ceil(.05*_n),Un=xn?Math.ceil(5*kt):5,Tn=En===J?J:Math.max(En,Un);console.log("Usage and Limits Debug:",{remaining:Cn,notificationThreshold:Tn,studioUser:vt});const An=d((()=>!!vt&&(!Ot&&(Cn!==J&&(!(Cn<=0)&&Cn<=Tn)))),[Ot,Tn,Cn,vt]),Pn=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]),Dn=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:Ln}))),c((()=>{Pe(Pn)}),[Pn]),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;Ln(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 Ln=(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:[An&&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:[Cn.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||Ln()))},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||Dn?ke.accent:ke.accent+"10",color:Gt||Dn?ke.accentText:ke.accent+"80"},disabled:!Dn,onClick:()=>Ln()},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 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 +1 @@
1
- import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as s,jsx as t,Fragment as o}from"react/jsx-runtime";import{useState as n,useRef as a,useEffect as i,useMemo as r}from"react";import{usePickaxeContext as l}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{format as m}from"date-fns";import p from"../../../../common/api/pickaxe.js";import{Check as u,X as h,MoreHorizontal as b,Pencil as f}from"lucide-react";import g from"../../../Icons/trash-2.svg.js";import v from"../../../Icons/chat.svg.js";import y from"../../../Icons/copy.svg.js";import x from"../../../Icons/copied.svg.js";import j from"../../../Icons/expand.svg.js";import w from"../../../Icons/collapse.svg.js";import{PickaxeMarkdown as k}from"../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as N}from"../../common/PickaxeMarkdown/Renderer.js";import C from"../../../../common/cn.js";const O=({item:O,onDelete:_})=>{const{pickaxe:I,sender:P,colors:M,translations:R,styles:D,isRtl:E,disableCss:T,disableHtml:q,disableJs:F,setSessionId:S,setIsNewChat:$}=l(),{setMessages:A}=c(),{setDocuments:H}=d(),[J,z]=n(!1),[L,B]=n(!1),[K,G]=n(!1),[Q,U]=n(!1),[V,W]=n(!1),X=a(null),[Y,Z]=n(O.shortSummary||O.summary||(null==R?void 0:R["conversation-name"])||"Conversation name"),[ee,se]=n("");i((()=>{Z(O.shortSummary||O.summary||(null==R?void 0:R["conversation-name"])||"Conversation name")}),[O.shortSummary,O.summary,R]),i((()=>{const e=e=>{X.current&&!X.current.contains(e.target)&&z(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const te=r((()=>O?"FORM"===O.pickaxeType&&0===O.messages.length?O.question.responseParts?O.question.responseParts.length:0:O.messages.length:0),[O]),oe=r((()=>m(new Date(O.updatedAt),"MMM dd, yyy hh:mm a")),[O]),ne=r((()=>{var e;const s=(null==R?void 0:R["not-available"])||"n/a";if("FORM"===O.pickaxeType){if(O.messages&&0!==O.messages.length){const e=O.messages.find((e=>"user"===e.role));return e?e.parts[0].content:""}const t=null!==(e=O.question.inputs)&&void 0!==e?e:[];return V?t.map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 600; opacity: 0.9;">${e.question}</p>\n <p style="opacity: 0.8;">${e.answer||s}</p>\n</div>`)).join(""):t.map((e=>`${e.question}: ${e.answer||s}`)).join(" | ")}const t=O.messages.find((e=>"user"===e.role));return t?t.parts[0].content:""}),[O,V,R]),ae=r((()=>{if("FORM"===O.pickaxeType){if(O.messages&&0!==O.messages.length){const e=O.messages.find((e=>"assistant"===e.role));return e?e.parts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" "):""}return O.question.responseParts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" ")}const e=O.messages.find((e=>"assistant"===e.role));return e?e.parts.filter((e=>"text"===e.type)).map((e=>e.content)).join(" "):""}),[O]),ie=()=>{B(!1),se("")},re=()=>e(void 0,void 0,void 0,(function*(){if(ee.trim()){G(!0);try{yield p.post("/edit_conversation_name",{sessionId:O.sessionId,name:ee,userId:P}),Z(ee),B(!1)}catch(e){console.error("Error updating conversation name:",e),alert((null==R?void 0:R["failed-update-name"])||"Failed to update name.")}finally{G(!1)}}}));return s("div",Object.assign({className:"flex flex-col overflow-hidden transition duration-300 hover:shadow w-full shrink-0 border",style:{borderColor:M.secondary,borderRadius:D.cornerRadius}},{children:[t("div",Object.assign({className:"flex items-center justify-between px-4 py-3 h-[44px]",style:{backgroundColor:M.primary,color:M.text}},{children:L?s("div",Object.assign({className:"flex items-center w-full gap-2",onClick:e=>e.stopPropagation()},{children:[t("input",{autoFocus:!0,type:"text",value:ee,onChange:e=>se(e.target.value),onKeyDown:e=>{"Enter"===e.key&&re(),"Escape"===e.key&&ie()},className:"flex-1 text-inherit px-2 py-1 rounded border focus:outline-none focus:ring-0 text-sm",style:{backgroundColor:M.primary,borderColor:M.secondary}}),t("button",Object.assign({onClick:re,disabled:K,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==R?void 0:R.save)||"Save"},{children:t(u,{className:"h-4 w-4"})})),t("button",Object.assign({onClick:ie,disabled:K,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==R?void 0:R.cancel)||"Cancel"},{children:t(h,{className:"h-4 w-4"})}))]})):s(o,{children:[t("h3",Object.assign({className:"font-bold text-lg truncate pr-2 flex-1 min-w-0 select-none"},{children:Y})),s("div",Object.assign({className:"flex items-center gap-1 shrink-0"},{children:[t("button",Object.assign({onClick:e=>{e.stopPropagation(),W(!V)},className:"p-1 rounded-full transition-colors hover:bg-black/10",title:V?(null==R?void 0:R.collapse)||"Collapse":(null==R?void 0:R.expand)||"Expand"},{children:t(V?w:j,{className:"h-4 w-4"})})),s("div",Object.assign({className:"relative"},{children:[t("button",Object.assign({onClick:e=>{e.stopPropagation(),z(!J)},className:"p-1 rounded-full transition-colors hover:bg-black/10"},{children:t(b,{className:"h-6 w-6"})})),J&&s("div",Object.assign({ref:X,className:"absolute right-0 top-8 w-48 rounded-xl shadow-xl z-40 border overflow-hidden animate-in fade-in zoom-in-95 duration-100",style:{backgroundColor:M.secondary,color:M.secondaryText,borderColor:M.primary}},{children:[s("button",Object.assign({onClick:e=>{e.stopPropagation(),se(Y),B(!0),z(!1)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95 border-b",style:{borderBottomColor:M.primary}},{children:[t(f,{className:"h-4 w-4"}),t("span",Object.assign({className:"font-medium text-sm"},{children:(null==R?void 0:R["rename-chat"])||"Rename chat"}))]})),s("button",Object.assign({onClick:s=>{s.stopPropagation(),e(void 0,void 0,void 0,(function*(){if(window.confirm((null==R?void 0:R["delete-confirm"])||"Are you sure you want to delete this conversation?")){z(!1);try{yield p.post("/delete_pickaxe_conversation",{sessionId:O.sessionId,userId:P}),_&&_(O.sessionId)}catch(e){console.error("Error deleting conversation:",e),alert((null==R?void 0:R["failed-delete-conversation"])||"Failed to delete conversation.")}}}))},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95"},{children:[t(g,{className:"h-4 w-4"}),t("span",Object.assign({className:"font-medium text-sm"},{children:(null==R?void 0:R["delete-chat"])||"Delete chat"}))]}))]}))]}))]}))]})})),s("div",Object.assign({className:C("px-4 py-5 flex flex-col justify-between transition-all duration-200 ease-in-out",V?"h-auto min-h-[130px]":"h-[130px]"),style:{backgroundColor:M.secondary,color:M.secondaryText}},{children:[s("div",Object.assign({className:"flex flex-col"},{children:[t("div",Object.assign({className:C("w-full",V?"mb-0":"mb-2")},{children:t(k,Object.assign({theme:D.theme,colors:M},E&&{rtl:!0},q&&{disableHtml:!0},F&&{disableJs:!0},T&&{disableCss:!0},{children:t(N,{style:{display:"block"},className:C("w-full",!V&&["[&_*]:!font-semibold mb-0.5 h-5 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],V&&"[&_*]:!text-sm [&_*]:!font-semibold mb-0.5 [&_p]:!m-0"),value:ne})}))})),t("div",Object.assign({className:"w-full"},{children:t(k,Object.assign({theme:D.theme,colors:M},E&&{rtl:!0},q&&{disableHtml:!0},F&&{disableJs:!0},T&&{disableCss:!0},{children:t(N,{style:{display:"block"},className:C("w-full text-sm",!V&&["font-normal h-5 opacity-80 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],V&&"font-normal opacity-90 mt-2 border-t pt-2 border-dashed"),value:ae})}))}))]})),s("div",Object.assign({className:"flex items-center justify-between mt-4 pt-2 border-t border-transparent"},{children:[s("div",Object.assign({className:"flex items-center gap-4"},{children:[((null==I?void 0:I.chatflag)||!(null==I?void 0:I.chatflag)&&(null==I?void 0:I.enablechatresponses))&&s("div",Object.assign({className:"flex items-center gap-1.5 opacity-70 hover:opacity-100 cursor-pointer transition-opacity",onClick:e=>{var s;e.stopPropagation(),s=O.sessionId,H([]),A([]),$(!1),S(s)},title:(null==R?void 0:R["open-chat"])||"Open Chat"},{children:[t(v,{className:"h-4 w-4"}),t("span",Object.assign({className:"text-sm font-medium"},{children:te}))]})),t("button",Object.assign({className:"transition-colors "+(Q?"opacity-100":"opacity-70 hover:opacity-100"),onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(ae),U(!0),setTimeout((()=>{U(!1)}),2e3)},title:Q?(null==R?void 0:R.copied)||"Copied!":(null==R?void 0:R["copy-assistant-message"])||"Copy assistant message"},{children:Q?t(x,{className:"h-4 w-4",style:{color:M.accent},fill:M.accent}):t(y,{className:"h-4 w-4"})}))]})),t("span",Object.assign({className:"text-xs font-semibold uppercase opacity-30 whitespace-nowrap"},{children:oe}))]}))]}))]}))};export{O as default};
1
+ import{__awaiter as e}from"../../../../_virtual/_tslib.js";import{jsxs as s,jsx as o,Fragment as t}from"react/jsx-runtime";import{useState as n,useRef as a,useEffect as i,useMemo as r}from"react";import{usePickaxeContext as l}from"../../../../hooks/pickaxe/usePickaxeContext.js";import{useResponseContext as c}from"../../../../hooks/pickaxe/useResponseContext.js";import{useDocument as d}from"../../Addons/Document/hooks/useDocument.js";import{format as m}from"date-fns";import p from"../../../../common/api/pickaxe.js";import{Check as u,X as h,MoreHorizontal as b,Pencil as g}from"lucide-react";import v from"../../../Icons/trash-2.svg.js";import f from"../../../Icons/chat.svg.js";import y from"../../../Icons/copy.svg.js";import x from"../../../Icons/copied.svg.js";import j from"../../../Icons/expand.svg.js";import w from"../../../Icons/collapse.svg.js";import{PickaxeMarkdown as k}from"../../common/PickaxeMarkdown/index.js";import{PickaxeMarkdownRenderer as N}from"../../common/PickaxeMarkdown/Renderer.js";import{getSuppressedRichPreviewUrls as C}from"../../common/PickaxeMessageParts/index.js";import O from"../../../../common/cn.js";const _=({item:_,onDelete:I})=>{const{pickaxe:P,sender:M,colors:R,translations:D,styles:E,isRtl:T,disableCss:q,disableHtml:F,disableJs:S,setSessionId:$,setIsNewChat:A}=l(),{setMessages:H}=c(),{setDocuments:J}=d(),[z,L]=n(!1),[B,K]=n(!1),[U,G]=n(!1),[Q,V]=n(!1),[W,X]=n(!1),Y=a(null),[Z,ee]=n(_.shortSummary||_.summary||(null==D?void 0:D["conversation-name"])||"Conversation name"),[se,oe]=n("");i((()=>{ee(_.shortSummary||_.summary||(null==D?void 0:D["conversation-name"])||"Conversation name")}),[_.shortSummary,_.summary,D]),i((()=>{const e=e=>{Y.current&&!Y.current.contains(e.target)&&L(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[]);const te=r((()=>_?"FORM"===_.pickaxeType&&0===_.messages.length?_.question.responseParts?_.question.responseParts.length:0:_.messages.length:0),[_]),ne=r((()=>m(new Date(_.updatedAt),"MMM dd, yyy hh:mm a")),[_]),ae=r((()=>{var e;const s=(null==D?void 0:D["not-available"])||"n/a";if("FORM"===_.pickaxeType){if(_.messages&&0!==_.messages.length){const e=_.messages.find((e=>"user"===e.role));return e?e.parts[0].content:""}const o=null!==(e=_.question.inputs)&&void 0!==e?e:[];return W?o.map((e=>`<div style="display: flex; flex-direction: column; margin-bottom: 1em;">\n <p style="font-weight: 600; opacity: 0.9;">${e.question}</p>\n <p style="opacity: 0.8;">${e.answer||s}</p>\n</div>`)).join(""):o.map((e=>`${e.question}: ${e.answer||s}`)).join(" | ")}const o=_.messages.find((e=>"user"===e.role));return o?o.parts[0].content:""}),[_,W,D]),ie=r((()=>{var e,s,o,t;return"FORM"===_.pickaxeType?_.messages&&0!==_.messages.length?null!==(s=null===(e=_.messages.find((e=>"assistant"===e.role)))||void 0===e?void 0:e.parts)&&void 0!==s?s:[]:_.question.responseParts:null!==(t=null===(o=_.messages.find((e=>"assistant"===e.role)))||void 0===o?void 0:o.parts)&&void 0!==t?t:[]}),[_]),re=r((()=>ie.filter((e=>"text"===e.type)).map((e=>e.content)).join(" ")),[ie]),le=r((()=>C(ie)),[ie]),ce=()=>{K(!1),oe("")},de=()=>e(void 0,void 0,void 0,(function*(){if(se.trim()){G(!0);try{yield p.post("/edit_conversation_name",{sessionId:_.sessionId,name:se,userId:M}),ee(se),K(!1)}catch(e){console.error("Error updating conversation name:",e),alert((null==D?void 0:D["failed-update-name"])||"Failed to update name.")}finally{G(!1)}}}));return s("div",Object.assign({className:"flex flex-col overflow-hidden transition duration-300 hover:shadow w-full shrink-0 border",style:{borderColor:R.secondary,borderRadius:E.cornerRadius}},{children:[o("div",Object.assign({className:"flex items-center justify-between px-4 py-3 h-[44px]",style:{backgroundColor:R.primary,color:R.text}},{children:B?s("div",Object.assign({className:"flex items-center w-full gap-2",onClick:e=>e.stopPropagation()},{children:[o("input",{autoFocus:!0,type:"text",value:se,onChange:e=>oe(e.target.value),onKeyDown:e=>{"Enter"===e.key&&de(),"Escape"===e.key&&ce()},className:"flex-1 text-inherit px-2 py-1 rounded border focus:outline-none focus:ring-0 text-sm",style:{backgroundColor:R.primary,borderColor:R.secondary}}),o("button",Object.assign({onClick:de,disabled:U,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==D?void 0:D.save)||"Save"},{children:o(u,{className:"h-4 w-4"})})),o("button",Object.assign({onClick:ce,disabled:U,className:"p-1 rounded hover:bg-black/20 transition-colors",title:(null==D?void 0:D.cancel)||"Cancel"},{children:o(h,{className:"h-4 w-4"})}))]})):s(t,{children:[o("h3",Object.assign({className:"font-bold text-lg truncate pr-2 flex-1 min-w-0 select-none"},{children:Z})),s("div",Object.assign({className:"flex items-center gap-1 shrink-0"},{children:[o("button",Object.assign({onClick:e=>{e.stopPropagation(),X(!W)},className:"p-1 rounded-full transition-colors hover:bg-black/10",title:W?(null==D?void 0:D.collapse)||"Collapse":(null==D?void 0:D.expand)||"Expand"},{children:o(W?w:j,{className:"h-4 w-4"})})),s("div",Object.assign({className:"relative"},{children:[o("button",Object.assign({onClick:e=>{e.stopPropagation(),L(!z)},className:"p-1 rounded-full transition-colors hover:bg-black/10"},{children:o(b,{className:"h-6 w-6"})})),z&&s("div",Object.assign({ref:Y,className:"absolute right-0 top-8 w-48 rounded-xl shadow-xl z-40 border overflow-hidden animate-in fade-in zoom-in-95 duration-100",style:{backgroundColor:R.secondary,color:R.secondaryText,borderColor:R.primary}},{children:[s("button",Object.assign({onClick:e=>{e.stopPropagation(),oe(Z),K(!0),L(!1)},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95 border-b",style:{borderBottomColor:R.primary}},{children:[o(g,{className:"h-4 w-4"}),o("span",Object.assign({className:"font-medium text-sm"},{children:(null==D?void 0:D["rename-chat"])||"Rename chat"}))]})),s("button",Object.assign({onClick:s=>{s.stopPropagation(),e(void 0,void 0,void 0,(function*(){if(window.confirm((null==D?void 0:D["delete-confirm"])||"Are you sure you want to delete this conversation?")){L(!1);try{yield p.post("/delete_pickaxe_conversation",{sessionId:_.sessionId,userId:M}),I&&I(_.sessionId)}catch(e){console.error("Error deleting conversation:",e),alert((null==D?void 0:D["failed-delete-conversation"])||"Failed to delete conversation.")}}}))},className:"w-full text-left px-4 py-3 flex items-center gap-3 transition-all hover:brightness-95"},{children:[o(v,{className:"h-4 w-4"}),o("span",Object.assign({className:"font-medium text-sm"},{children:(null==D?void 0:D["delete-chat"])||"Delete chat"}))]}))]}))]}))]}))]})})),s("div",Object.assign({className:O("px-4 py-5 flex flex-col justify-between transition-all duration-200 ease-in-out",W?"h-auto min-h-[130px]":"h-[130px]"),style:{backgroundColor:R.secondary,color:R.secondaryText}},{children:[s("div",Object.assign({className:"flex flex-col"},{children:[o("div",Object.assign({className:O("w-full",W?"mb-0":"mb-2")},{children:o(k,Object.assign({theme:E.theme,colors:R},T&&{rtl:!0},F&&{disableHtml:!0},S&&{disableJs:!0},q&&{disableCss:!0},{children:o(N,{style:{display:"block"},className:O("w-full",!W&&["[&_*]:!font-semibold mb-0.5 h-5 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],W&&"[&_*]:!text-sm [&_*]:!font-semibold mb-0.5 [&_p]:!m-0"),value:ae})}))})),o("div",Object.assign({className:"w-full"},{children:o(k,Object.assign({theme:E.theme,colors:R},T&&{rtl:!0},F&&{disableHtml:!0},S&&{disableJs:!0},q&&{disableCss:!0},{children:o(N,{style:{display:"block"},className:O("w-full text-sm",!W&&["font-normal h-5 opacity-80 truncate [&_p]:inline [&_p]:m-0","[&_*]:!inline","[&_*]:!m-0 [&_*]:!p-0","[&_*]:!text-sm","[&_*]:!leading-none","[&_img]:hidden [&_hr]:hidden [&_br]:hidden"],W&&"font-normal opacity-90 mt-2 border-t pt-2 border-dashed"),value:re,suppressedRichPreviewUrls:le})}))}))]})),s("div",Object.assign({className:"flex items-center justify-between mt-4 pt-2 border-t border-transparent"},{children:[s("div",Object.assign({className:"flex items-center gap-4"},{children:[((null==P?void 0:P.chatflag)||!(null==P?void 0:P.chatflag)&&(null==P?void 0:P.enablechatresponses))&&s("div",Object.assign({className:"flex items-center gap-1.5 opacity-70 hover:opacity-100 cursor-pointer transition-opacity",onClick:e=>{var s;e.stopPropagation(),s=_.sessionId,J([]),H([]),A(!1),$(s)},title:(null==D?void 0:D["open-chat"])||"Open Chat"},{children:[o(f,{className:"h-4 w-4"}),o("span",Object.assign({className:"text-sm font-medium"},{children:te}))]})),o("button",Object.assign({className:"transition-colors "+(Q?"opacity-100":"opacity-70 hover:opacity-100"),onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(re),V(!0),setTimeout((()=>{V(!1)}),2e3)},title:Q?(null==D?void 0:D.copied)||"Copied!":(null==D?void 0:D["copy-assistant-message"])||"Copy assistant message"},{children:Q?o(x,{className:"h-4 w-4",style:{color:R.accent},fill:R.accent}):o(y,{className:"h-4 w-4"})}))]})),o("span",Object.assign({className:"text-xs font-semibold uppercase opacity-30 whitespace-nowrap"},{children:ne}))]}))]}))]}))};export{_ as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../../../../_virtual/_tslib.js";import{jsxs as o,jsx as t}from"react/jsx-runtime";import{useState as i}from"react";import{usePickaxeContext as l}from"../../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as a}from"../../../../Addons/Auth/hooks/useAuthContext.js";import{useSubmitDocument as n}from"../../../../../../hooks/pickaxe/useSubmitDocument.js";import{usePickaxeMarkdownContext as s}from"../../hooks/usePickaxeMarkdownContext.js";import r from"../../../../../Icons/download.svg.js";import c from"../../../../../Icons/copy.svg.js";import d from"../../../../../Icons/copied.svg.js";import p from"../../../../../Icons/file.svg.js";import m from"../../../../../Icons/upload-cloud.svg.js";import f from"copy-to-clipboard";import u from"../../../../../../common/error.js";const b=new Set(["jpeg","jpg","gif","bmp","webp","svg","tiff","avif","png","jfif","pjpeg","pjp"]),g=new Set(["mp3","wav","ogg","flac","aac","wma","alac","m4a","aiff","ape","au","mid","midi","opus"]),h=new Set(["mp4","webm","mov","avi","mkv","m4v"]),v=new Set(["csv","tsv","txt","json","xml","md","log","yaml","yml"]),w=new Set(["doc","docx","xls","xlsx","ppt","pptx"]),x=e=>b.has(e)?"image":g.has(e)?"audio":h.has(e)?"video":"pdf"===e?"pdf":"html"===e||"htm"===e?"html":v.has(e)?"text":w.has(e)?"office":"file",k=e=>{const o=(e=>{let o=e.trim();for(;/[),.;!?]$/.test(o);)o=o.slice(0,-1);return o})(e);return o.startsWith("http://")?`https://${o.slice(7)}`:o.startsWith("www.")?`https://${o}`:o},y=e=>{var o,t;try{const i=k(e),l=new URL(i);if("https:"!==l.protocol&&"http:"!==l.protocol)return null;const a=l.pathname.split("/").filter(Boolean).pop();if(!a)return null;const n=decodeURIComponent(a),s=null===(t=null===(o=n.match(/\.([a-z0-9]{1,10})$/i))||void 0===o?void 0:o[1])||void 0===t?void 0:t.toLowerCase();return s?{url:i,fileName:n,extension:s,kind:x(s)}:null}catch(e){return null}},j=(e,o)=>!!e&&(!o||!o.current.has(e.url)&&(o.current.add(e.url),!0)),N=({fileInfo:b,displayName:g})=>{const{theme:h,colors:v,disableHtml:w,disableJs:x}=s(),{contextId:k,pickaxeId:y,pickaxe:j,translations:N}=l(),{isLoggedIn:C,token:O}=a(),I=n(),[S,F]=i(!1),[$,D]=i(!1),[T,B]=i(!1),R=(e,o)=>{var t;return null!==(t=null==N?void 0:N[e])&&void 0!==t?t:o},U="dark"===h?"#30363D":"#D0D7DE",A="dark"===h?"#0D1117":"#F6F8FA",E="dark"===h?"#161B22":"#FFFFFF",P=(null==g?void 0:g.trim())||b.fileName,_=P!==b.fileName,L={display:"inline-flex",width:32,height:32,alignItems:"center",justifyContent:"center",borderRadius:4,color:v.accentText,backgroundColor:v.accent,opacity:.88,flexShrink:0},H=(e,i,l)=>t("div",Object.assign({className:"flex w-full p-4"},{children:o("div",Object.assign({className:"relative w-full overflow-hidden rounded-md shadow-sm",style:{aspectRatio:"8.5 / 11",backgroundColor:E,border:`1px solid ${U}`}},{children:[t("iframe",Object.assign({src:e,title:i},l,{className:"h-full w-full",scrolling:"no",tabIndex:-1,style:{border:"none",pointerEvents:"none"}})),t("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-10",style:{background:"dark"===h?"linear-gradient(to top, rgba(22,27,34,0.95), rgba(22,27,34,0))":"linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0))"}})]}))}));return o("div",Object.assign({className:"my-2 w-full overflow-hidden rounded-lg",style:{border:`1px solid ${U}`,backgroundColor:A,color:v.secondaryText}},{children:[o("div",Object.assign({className:"flex items-center justify-between gap-3 border-b px-3 py-2",style:{borderColor:U}},{children:[t("a",Object.assign({href:b.url,target:"_blank",rel:"noopener noreferrer",className:"min-w-0 flex-1 truncate text-sm font-semibold hover:underline",style:{color:v.secondaryText},title:_?`${P} (${b.fileName})`:P},{children:P})),o("div",Object.assign({className:"flex shrink-0 items-center gap-1.5"},{children:[t("button",Object.assign({type:"button",onClick:()=>{const e=document.createElement("a");e.href=b.url,e.download=b.fileName,e.target="_blank",e.rel="noopener noreferrer",e.click()},title:R("download","Download"),"aria-label":R("download","Download"),style:L},{children:t(r,{className:"h-[18px] w-[18px]"})})),t("button",Object.assign({type:"button",onClick:()=>{e(void 0,void 0,void 0,(function*(){try{F(!0),f(b.url),yield new Promise((e=>setTimeout(e,1500)))}finally{F(!1)}}))},title:S?R("copied","Copied"):R("copy-link","Copy link"),"aria-label":S?R("copied","Copied"):R("copy-link","Copy link"),style:Object.assign(Object.assign({},L),{opacity:S?1:L.opacity})},{children:t(S?d:c,{className:"h-[18px] w-[18px]"})})),C&&O&&t("button",Object.assign({type:"button",disabled:$||T,onClick:()=>{e(void 0,void 0,void 0,(function*(){if(O&&!$){D(!0),B(!1);try{const e=yield fetch(b.url);if(!e.ok)throw new Error("Failed to download generated file.");const o=yield e.blob(),t=new File([o],b.fileName,{type:o.type||"application/octet-stream"});yield I.document(Object.assign(Object.assign({contextId:k,pickaxeId:y,file:t},(null==j?void 0:j.workspaceid)&&{workspaceId:j.workspaceid}),{studioSessionToken:O,isUserDocument:!0})),B(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(u(e))}finally{D(!1),B(!1)}}}))},title:$?R("saving","Saving..."):T?R("saved","Saved"):R("save-to-knowledge-base","Save to Knowledge Base"),"aria-label":$?R("saving","Saving..."):T?R("saved","Saved"):R("save-to-knowledge-base","Save to Knowledge Base"),style:Object.assign(Object.assign({},L),{opacity:$||T?.55:L.opacity,cursor:$||T?"not-allowed":"pointer"})},{children:t(m,{className:"h-[18px] w-[18px]"})}))]}))]})),t("div",{children:(()=>{if("image"===b.kind)return t("img",{src:b.url,alt:b.fileName,className:"block max-h-[420px] w-full object-contain"});if("audio"===b.kind)return t("div",Object.assign({className:"flex min-h-[72px] items-center p-4"},{children:t("audio",{className:"w-full",controls:!0,src:b.url})}));if("video"===b.kind)return t("video",{className:"block max-h-[420px] w-full bg-black",controls:!0,preload:"metadata",src:b.url});if("pdf"===b.kind||"text"===b.kind){const e="pdf"===b.kind?`${b.url}#page=1&toolbar=0&navpanes=0&scrollbar=0&view=FitH`:b.url;return H(e,b.fileName)}if("html"===b.kind&&!w){const e=["allow-same-origin","allow-forms","allow-popups","allow-downloads","allow-modals",x?"":"allow-scripts"].filter(Boolean).join(" ");return H(b.url,b.fileName,{sandbox:e})}return"office"===b.kind?H(`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(b.url)}`,b.fileName):o("div",Object.assign({className:"flex min-h-[120px] items-center justify-center gap-3 p-6 text-sm"},{children:[t(p,{className:"h-8 w-8 shrink-0"}),t("span",Object.assign({className:"break-all"},{children:b.extension.toUpperCase()}))]}))})()})]}))};export{N as default,y as getFilePreviewInfo,k as normalizeMarkdownUrl,j as shouldRenderFilePreview};
1
+ import{__awaiter as e}from"../../../../../../_virtual/_tslib.js";import{jsxs as t,jsx as o}from"react/jsx-runtime";import{useState as n}from"react";import{usePickaxeContext as i}from"../../../../../../hooks/pickaxe/usePickaxeContext.js";import{useAuthContext as l}from"../../../../Addons/Auth/hooks/useAuthContext.js";import{useSubmitDocument as a}from"../../../../../../hooks/pickaxe/useSubmitDocument.js";import{usePickaxeMarkdownContext as r}from"../../hooks/usePickaxeMarkdownContext.js";import s from"../../../../../Icons/download.svg.js";import c from"../../../../../Icons/copy.svg.js";import d from"../../../../../Icons/copied.svg.js";import m from"../../../../../Icons/file.svg.js";import p from"../../../../../Icons/upload-cloud.svg.js";import u from"copy-to-clipboard";import f from"../../../../../../common/error.js";const h=/(?:https?:\/\/|www\.)[^\s<>"']+/gi,b=new Set(["jpeg","jpg","gif","bmp","webp","svg","tiff","avif","png","jfif","pjpeg","pjp"]),v=new Set(["mp3","wav","ogg","flac","aac","wma","alac","m4a","aiff","ape","au","mid","midi","opus"]),w=new Set(["mp4","webm","mov","avi","mkv","m4v"]),g=new Set(["csv","tsv","txt","json","xml","md","log","yaml","yml"]),x=new Set(["doc","docx","xls","xlsx","ppt","pptx"]),k=new Set(["pdf","html","htm",...g,...x]),y=e=>b.has(e)?"image":v.has(e)?"audio":w.has(e)?"video":"pdf"===e?"pdf":"html"===e||"htm"===e?"html":g.has(e)?"text":x.has(e)?"office":"file",j=e=>{const t=(e=>{let t=e.trim();for(;/[),.;!?]$/.test(t);)t=t.slice(0,-1);return t})(e);return t.startsWith("http://")?`https://${t.slice(7)}`:t.startsWith("www.")?`https://${t}`:t},N=e=>{try{return new URL(j(e)).pathname.includes("/action_generated_files/")}catch(e){return!1}},C=e=>{try{return new URL(j(e)).pathname.includes("/documentinterrogation/")}catch(e){return!1}},O=e=>{const t=j(e);if(N(t))return!1;if(C(t))return!0;if((e=>{const t=j(e);return/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i.test(t)||/loom\.com\/(?:share|embed)\/([\w-]+)/i.test(t)||/vimeo\.com\/(?:video\/)?(\d+)/i.test(t)||/streamable\.com\/([\w-]+)/i.test(t)})(t))return!0;const o=(e=>{var t,o,n,i;try{const l=new URL(j(e));return"https:"!==l.protocol&&"http:"!==l.protocol?null:null!==(i=null===(n=null===(o=null===(t=l.pathname.split("/").filter(Boolean).pop())||void 0===t?void 0:t.match(/\.([a-z0-9]{1,10})$/i))||void 0===o?void 0:o[1])||void 0===n?void 0:n.toLowerCase())&&void 0!==i?i:null}catch(e){return null}})(t);return!!o&&k.has(o)},I=(e,t)=>{const o=j(e);return O(o)||(null==t?void 0:t.has(o))},S=(e,t)=>{for(const o of e.matchAll(h))if(I(o[0],t))return!0;return!1},F=e=>{var t,o;try{const n=j(e),i=new URL(n);if("https:"!==i.protocol&&"http:"!==i.protocol)return null;const l=i.pathname.split("/").filter(Boolean).pop();if(!l)return null;const a=decodeURIComponent(l),r=null===(o=null===(t=a.match(/\.([a-z0-9]{1,10})$/i))||void 0===t?void 0:t[1])||void 0===o?void 0:o.toLowerCase();return r?{url:n,fileName:a,extension:r,kind:y(r)}:null}catch(e){return null}},$=(e,t)=>!!e&&(!t||!t.current.has(e.url)&&(t.current.add(e.url),!0)),D=({fileInfo:h,displayName:b})=>{const{theme:v,colors:w,disableHtml:g,disableJs:x}=r(),{contextId:k,pickaxeId:y,pickaxe:j,translations:N}=i(),{isLoggedIn:C,token:O}=l(),I=a(),[S,F]=n(!1),[$,D]=n(!1),[R,U]=n(!1),L=(e,t)=>{var o;return null!==(o=null==N?void 0:N[e])&&void 0!==o?o:t},B="dark"===v?"#30363D":"#D0D7DE",T="dark"===v?"#0D1117":"#F6F8FA",_="dark"===v?"#161B22":"#FFFFFF",A=(null==b?void 0:b.trim())||h.fileName,E=A!==h.fileName,P={display:"inline-flex",width:32,height:32,alignItems:"center",justifyContent:"center",borderRadius:4,color:w.accentText,backgroundColor:w.accent,opacity:.88,flexShrink:0},z=(e,n,i)=>o("div",Object.assign({className:"flex w-full p-4"},{children:t("div",Object.assign({className:"relative w-full overflow-hidden rounded-md shadow-sm",style:{aspectRatio:"8.5 / 11",backgroundColor:_,border:`1px solid ${B}`}},{children:[o("iframe",Object.assign({src:e,title:n},i,{className:"h-full w-full",scrolling:"no",tabIndex:-1,style:{border:"none",pointerEvents:"none"}})),o("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-10",style:{background:"dark"===v?"linear-gradient(to top, rgba(22,27,34,0.95), rgba(22,27,34,0))":"linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0))"}})]}))}));return t("div",Object.assign({className:"my-2 w-full overflow-hidden rounded-lg",style:{border:`1px solid ${B}`,backgroundColor:T,color:w.secondaryText}},{children:[t("div",Object.assign({className:"flex items-center justify-between gap-3 border-b px-3 py-2",style:{borderColor:B}},{children:[o("a",Object.assign({href:h.url,target:"_blank",rel:"noopener noreferrer",className:"min-w-0 flex-1 truncate text-sm font-semibold hover:underline",style:{color:w.secondaryText},title:E?`${A} (${h.fileName})`:A},{children:A})),t("div",Object.assign({className:"flex shrink-0 items-center gap-1.5"},{children:[o("button",Object.assign({type:"button",onClick:()=>{const e=document.createElement("a");e.href=h.url,e.download=h.fileName,e.target="_blank",e.rel="noopener noreferrer",e.click()},title:L("download","Download"),"aria-label":L("download","Download"),style:P},{children:o(s,{className:"h-[18px] w-[18px]"})})),o("button",Object.assign({type:"button",onClick:()=>{e(void 0,void 0,void 0,(function*(){try{F(!0),u(h.url),yield new Promise((e=>setTimeout(e,1500)))}finally{F(!1)}}))},title:S?L("copied","Copied"):L("copy-link","Copy link"),"aria-label":S?L("copied","Copied"):L("copy-link","Copy link"),style:Object.assign(Object.assign({},P),{opacity:S?1:P.opacity})},{children:o(S?d:c,{className:"h-[18px] w-[18px]"})})),C&&O&&o("button",Object.assign({type:"button",disabled:$||R,onClick:()=>{e(void 0,void 0,void 0,(function*(){if(O&&!$){D(!0),U(!1);try{const e=yield fetch(h.url);if(!e.ok)throw new Error("Failed to download generated file.");const t=yield e.blob(),o=new File([t],h.fileName,{type:t.type||"application/octet-stream"});yield I.document(Object.assign(Object.assign({contextId:k,pickaxeId:y,file:o},(null==j?void 0:j.workspaceid)&&{workspaceId:j.workspaceid}),{studioSessionToken:O,isUserDocument:!0})),U(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(f(e))}finally{D(!1),U(!1)}}}))},title:$?L("saving","Saving..."):R?L("saved","Saved"):L("save-to-knowledge-base","Save to Knowledge Base"),"aria-label":$?L("saving","Saving..."):R?L("saved","Saved"):L("save-to-knowledge-base","Save to Knowledge Base"),style:Object.assign(Object.assign({},P),{opacity:$||R?.55:P.opacity,cursor:$||R?"not-allowed":"pointer"})},{children:o(p,{className:"h-[18px] w-[18px]"})}))]}))]})),o("div",{children:(()=>{if("image"===h.kind)return o("img",{src:h.url,alt:h.fileName,className:"block max-h-[420px] w-full object-contain"});if("audio"===h.kind)return o("div",Object.assign({className:"flex min-h-[72px] items-center p-4"},{children:o("audio",{className:"w-full",controls:!0,src:h.url})}));if("video"===h.kind)return o("video",{className:"block max-h-[420px] w-full bg-black",controls:!0,preload:"metadata",src:h.url});if("pdf"===h.kind||"text"===h.kind){const e="pdf"===h.kind?`${h.url}#page=1&toolbar=0&navpanes=0&scrollbar=0&view=FitH`:h.url;return z(e,h.fileName)}if("html"===h.kind&&!g){const e=["allow-same-origin","allow-forms","allow-popups","allow-downloads","allow-modals",x?"":"allow-scripts"].filter(Boolean).join(" ");return z(h.url,h.fileName,{sandbox:e})}return"office"===h.kind?z(`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(h.url)}`,h.fileName):t("div",Object.assign({className:"flex min-h-[120px] items-center justify-center gap-3 p-6 text-sm"},{children:[o(m,{className:"h-8 w-8 shrink-0"}),o("span",Object.assign({className:"break-all"},{children:h.extension.toUpperCase()}))]}))})()})]}))};export{D as default,F as getFilePreviewInfo,C as isDocumentSourceUrl,N as isGeneratedFileUrl,O as isSourceLikeRichPreviewUrl,j as normalizeMarkdownUrl,$ as shouldRenderFilePreview,I as shouldSuppressRichPreviewForUrl,S as shouldSuppressRichPreviewInText};
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useMemo as t,Children as r,isValidElement as o}from"react";import{usePickaxeMarkdownContext as m}from"../../hooks/usePickaxeMarkdownContext.js";import c from"../common/IframeVideo.js";import i,{normalizeMarkdownUrl as s,getFilePreviewInfo as n,shouldRenderFilePreview as l}from"./FilePreview.js";const a=e=>{let t="";return r.forEach(e,(e=>{"string"!=typeof e&&"number"!=typeof e?o(e)&&(t+=a(e.props.children)):t+=e})),t.trim().replace(/\s+/g," ")},f=({href:r="",children:o,filePreviewSeenRef:f})=>{const{colors:u}=m(),p=t((()=>r?s(r):""),[r]),b=t((()=>n(p)),[p]),h=t((()=>((e,t)=>{const r=a(e);if(r&&r!==t&&s(r)!==t)return r})(o,p)),[o,p]),d=t((()=>{if(b)return null;const e=p.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=p.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const r=p.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(r)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${r[1]}`};const o=p.match(/streamable\.com\/([\w-]+)/i);return o?{title:"streamable-embed",src:`https://streamable.com/e/${o[1]}`}:null}),[b,p]);return d?e(c,{title:d.title,src:d.src}):b&&l(b,f)?e(i,{fileInfo:b,displayName:h}):e("a",Object.assign({href:p,target:"_blank",rel:"noopener noreferrer",style:{color:u.accent}},{children:o}))};export{f as A};
1
+ import{jsx as e}from"react/jsx-runtime";import{useMemo as r,Children as t,isValidElement as o}from"react";import{usePickaxeMarkdownContext as m}from"../../hooks/usePickaxeMarkdownContext.js";import i from"../common/IframeVideo.js";import c,{normalizeMarkdownUrl as s,shouldSuppressRichPreviewForUrl as n,getFilePreviewInfo as l,shouldRenderFilePreview as a}from"./FilePreview.js";const u=e=>{let r="";return t.forEach(e,(e=>{"string"!=typeof e&&"number"!=typeof e?o(e)&&(r+=u(e.props.children)):r+=e})),r.trim().replace(/\s+/g," ")},f=({href:t="",children:o,filePreviewSeenRef:f,suppressedRichPreviewUrls:p})=>{const{colors:h}=m(),b=r((()=>t?s(t):""),[t]),d=r((()=>n(b,p)),[b,p]),w=r((()=>l(b)),[b]),v=r((()=>((e,r)=>{const t=u(e);if(t&&t!==r&&s(t)!==r)return t})(o,b)),[o,b]),y=r((()=>{if(d)return null;if(w)return null;const e=b.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const r=b.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(r)return{title:"loom-embed",src:`https://www.loom.com/embed/${r[1]}`};const t=b.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(t)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${t[1]}`};const o=b.match(/streamable\.com\/([\w-]+)/i);return o?{title:"streamable-embed",src:`https://streamable.com/e/${o[1]}`}:null}),[w,b,d]);return y?e(i,{title:y.title,src:y.src}):w&&!d&&a(w,f)?e(c,{fileInfo:w,displayName:v}):e("a",Object.assign({href:b,target:"_blank",rel:"noopener noreferrer",style:{color:h.accent}},{children:o}))};export{f as A};
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useMemo as t}from"react";import o from"../common/IframeVideo.js";const m=({children:m})=>{const r=t((()=>{if("string"!=typeof m)return null;const e=m.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=m.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const o=m.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(o)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${o[1]}`};const r=m.match(/streamable\.com\/([\w-]+)/i);return r?{title:"streamable-embed",src:`https://streamable.com/e/${r[1]}`}:null}),[m]);return r?e(o,{title:r.title,src:r.src}):e("p",{children:m})};export{m as P};
1
+ import{jsx as e}from"react/jsx-runtime";import{useMemo as t}from"react";import r from"../common/IframeVideo.js";import{shouldSuppressRichPreviewInText as o}from"../A/FilePreview.js";const m=({children:m,suppressedRichPreviewUrls:i})=>{const c=t((()=>{if("string"!=typeof m)return null;if(o(m,i))return null;const e=m.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/i);if(e)return{title:"youtube-embed",src:`https://www.youtube.com/embed/${e[1]}`};const t=m.match(/loom\.com\/(?:share|embed)\/([\w-]+)/i);if(t)return{title:"loom-embed",src:`https://www.loom.com/embed/${t[1]}`};const r=m.match(/vimeo\.com\/(?:video\/)?(\d+)/i);if(r)return{title:"vimeo-embed",src:`https://player.vimeo.com/video/${r[1]}`};const c=m.match(/streamable\.com\/([\w-]+)/i);return c?{title:"streamable-embed",src:`https://streamable.com/e/${c[1]}`}:null}),[m,i]);return c?e(r,{title:c.title,src:c.src}):e("p",{children:m})};export{m as P};
@@ -1 +1 @@
1
- import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsxs as r,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as o,useMemo as i,useEffect as s}from"react";import{usePickaxeMarkdownContext as a}from"./hooks/usePickaxeMarkdownContext.js";import{remarkSmartQuotes as m,rehypeCode as l,rehypeSanitize as c}from"./utils/custom-plugins.js";import p from"react-markdown";import f from"remark-gfm";import d from"remark-math";import h from"rehype-katex";import u from"rehype-raw";import{A as g}from"./Components/A/index.js";import x,{getFilePreviewInfo as b,shouldRenderFilePreview as j}from"./Components/A/FilePreview.js";import{P as C}from"./Components/P/index.js";import{Img as k}from"./Components/Img/index.js";import{Iframe as w}from"./Components/Iframe/index.js";import{Code as v}from"./Components/Code/index.js";import{H1 as $,H2 as y,H3 as O,H4 as S,H5 as P}from"./Components/Headings/index.js";import{Ol as N,Ul as A,Li as I}from"./Components/List/index.js";import{Table as L,Th as M,Tr as R,Td as T}from"./Components/Table/index.js";import{Hr as H,Br as _,Blockquote as B}from"./Components/Others/index.js";import{ActionCaption as J,ActionFinished as W,ActionError as q}from"./Components/Action/index.js";import{Artifact as z,ArtifactError as D}from"./Components/Artifact/index.js";import{Think as E}from"./Components/Others/Think.js";import F from"../../../../common/cn.js";const G=({className:G,style:K,children:Q,value:U,maxLines:V,maxChars:X,multiLineBreaks:Y,onExpandClick:Z,filePreviewSeenRef:ee})=>{const{colors:re,rtl:te,disableHtml:ne,disableJs:oe,disableCss:ie}=a(),[se,ae]=n({width:0,height:0}),[me,le]=n(null),ce=o(null),pe=i((()=>{if(!U)return"";let e=U.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),Y&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[U,Y]);s((()=>{if(X)return void le(pe.length>X?pe.slice(0,X)+'<span class="pxe-expand-btn">...</span>':null);if(!V)return void le(null);if(!ce.current||!pe||me)return;const e=ce.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),t=V*r;if(!(se.height>t))return;const n=Math.floor(se.width/8),o=Math.floor(n*V);le(pe.slice(0,o)+'<span class="pxe-expand-btn">...</span>')}),[pe,V,X,se,me]);const fe=o(new Set);ee||(fe.current=new Set);const de=null!=ee?ee:fe,he={h1:$,h2:y,h3:O,h4:S,h5:P,p:C,a:e=>t(g,Object.assign({},e,{filePreviewSeenRef:de})),img:e=>{const r="string"==typeof e.src?e.src:"",n=b(r);return n?j(n,de)?t(x,{fileInfo:n,displayName:"string"==typeof e.alt?e.alt:void 0}):t("a",Object.assign({href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:re.accent}},{children:e.alt||n.fileName})):t(k,Object.assign({},e))},iframe:w,code:v,ol:N,ul:A,li:I,table:L,th:M,tr:R,td:T,hr:H,br:_,blockquote:B,span:r=>{var{children:n}=r,o=e(r,["children"]);return"pxe-expand-btn"===o.className?t("span",Object.assign({},o,{style:Object.assign({display:"inline",fontWeight:500,color:re.accent,marginLeft:".25rem",userSelect:"none"},Z&&{cursor:"pointer"})},Z&&{onClick:Z},{children:n})):t("span",Object.assign({},o,{children:n}))},"action-caption":J,"action-finished":W,"action-error":q,artifact:z,"artifact-error":D,think:E};s((()=>{if(!ce.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:t}=r.contentRect;ae({width:e,height:t})}}));return e.observe(ce.current),()=>{e.disconnect()}}),[]);const ue=me||pe;return r("div",Object.assign({className:"pxe-markdown",ref:ce,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},K)},te&&{dir:"rtl"},{children:[t(p,Object.assign({className:F("pxe-prose",G),components:he,remarkPlugins:[f,[d,{singleDollarTextMath:!1}],m],rehypePlugins:[l,h,...ne?[]:[u],[c,{disableJs:oe,disableCss:ie}]]},{children:ue})),Q]}))};export{G as PickaxeMarkdownRenderer};
1
+ import{__rest as e}from"../../../../_virtual/_tslib.js";import{jsxs as r,jsx as t}from"react/jsx-runtime";import{useState as n,useRef as i,useMemo as o,useEffect as s}from"react";import{usePickaxeMarkdownContext as a}from"./hooks/usePickaxeMarkdownContext.js";import{remarkSmartQuotes as l,rehypeCode as m,rehypeSanitize as p}from"./utils/custom-plugins.js";import c from"react-markdown";import d from"remark-gfm";import f from"remark-math";import h from"rehype-katex";import u from"rehype-raw";import{A as g}from"./Components/A/index.js";import x,{getFilePreviewInfo as b,shouldSuppressRichPreviewForUrl as j,shouldRenderFilePreview as w}from"./Components/A/FilePreview.js";import{P as C}from"./Components/P/index.js";import{Img as k}from"./Components/Img/index.js";import{Iframe as v}from"./Components/Iframe/index.js";import{Code as $}from"./Components/Code/index.js";import{H1 as y,H2 as O,H3 as P,H4 as S,H5 as R}from"./Components/Headings/index.js";import{Ol as N,Ul as A,Li as I}from"./Components/List/index.js";import{Table as L,Th as M,Tr as T,Td as H}from"./Components/Table/index.js";import{Hr as U,Br as _,Blockquote as B}from"./Components/Others/index.js";import{ActionCaption as J,ActionFinished as W,ActionError as q}from"./Components/Action/index.js";import{Artifact as z,ArtifactError as D}from"./Components/Artifact/index.js";import{Think as E}from"./Components/Others/Think.js";import F from"../../../../common/cn.js";const G=({className:G,style:K,children:Q,value:V,maxLines:X,maxChars:Y,multiLineBreaks:Z,onExpandClick:ee,filePreviewSeenRef:re,suppressedRichPreviewUrls:te})=>{const{colors:ne,rtl:ie,disableHtml:oe,disableJs:se,disableCss:ae}=a(),[le,me]=n({width:0,height:0}),[pe,ce]=n(null),de=i(null),fe=o((()=>{if(!V)return"";let e=V.trim();return e=e.replace(/<!--[\s\S]*?-->/g,""),e=e.replace(/\u200B/g,""),e=e.replace(/\\\((.*?)\\\)/g,"$$$ $1 $$$"),e=e.replace(/\\\[(.*?)\\\]/g,"$$$ $1 $$$"),e=e.replace(/<\/think>/g,"\n</think>"),Z&&(e=e.replace(/```[\s\S]*?```|(\n(?=\n))/g,((e,r)=>r?"\n\n<br/>\n":e))),e||""}),[V,Z]);s((()=>{if(Y)return void ce(fe.length>Y?fe.slice(0,Y)+'<span class="pxe-expand-btn">...</span>':null);if(!X)return void ce(null);if(!de.current||!fe||pe)return;const e=de.current,r=parseInt(window.getComputedStyle(e).lineHeight,10),t=X*r;if(!(le.height>t))return;const n=Math.floor(le.width/8),i=Math.floor(n*X);ce(fe.slice(0,i)+'<span class="pxe-expand-btn">...</span>')}),[fe,X,Y,le,pe]);const he=i(new Set);re||(he.current=new Set);const ue=null!=re?re:he,ge={h1:y,h2:O,h3:P,h4:S,h5:R,p:e=>t(C,Object.assign({},e,{suppressedRichPreviewUrls:te})),a:e=>t(g,Object.assign({},e,{filePreviewSeenRef:ue,suppressedRichPreviewUrls:te})),img:e=>{const r="string"==typeof e.src?e.src:"",n=b(r);return n&&!j(n.url,te)?w(n,ue)?t(x,{fileInfo:n,displayName:"string"==typeof e.alt?e.alt:void 0}):t("a",Object.assign({href:n.url,target:"_blank",rel:"noopener noreferrer",style:{color:ne.accent}},{children:e.alt||n.fileName})):t(k,Object.assign({},e))},iframe:v,code:$,ol:N,ul:A,li:I,table:L,th:M,tr:T,td:H,hr:U,br:_,blockquote:B,span:r=>{var{children:n}=r,i=e(r,["children"]);return"pxe-expand-btn"===i.className?t("span",Object.assign({},i,{style:Object.assign({display:"inline",fontWeight:500,color:ne.accent,marginLeft:".25rem",userSelect:"none"},ee&&{cursor:"pointer"})},ee&&{onClick:ee},{children:n})):t("span",Object.assign({},i,{children:n}))},"action-caption":J,"action-finished":W,"action-error":q,artifact:z,"artifact-error":D,think:E};s((()=>{if(!de.current)return;const e=new ResizeObserver((e=>{for(const r of e){const{width:e,height:t}=r.contentRect;me({width:e,height:t})}}));return e.observe(de.current),()=>{e.disconnect()}}),[]);const xe=pe||fe;return r("div",Object.assign({className:"pxe-markdown",ref:de,style:Object.assign({position:"relative",overflowWrap:"break-word",display:"grid",gridTemplateColumns:"repeat(1, minmax(0, 1fr))",gap:".625rem",width:"100%"},K)},ie&&{dir:"rtl"},{children:[t(c,Object.assign({className:F("pxe-prose",G),components:ge,remarkPlugins:[d,[f,{singleDollarTextMath:!1}],l],rehypePlugins:[m,h,...oe?[]:[u],[p,{disableJs:se,disableCss:ae}]]},{children:xe})),Q]}))};export{G as PickaxeMarkdownRenderer};
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useRef as n,Suspense as t,lazy as i}from"react";import{PickaxeMarkdownRenderer as o}from"../PickaxeMarkdown/Renderer.js";import r,{getFilePreviewInfo as a,normalizeMarkdownUrl as s,shouldRenderFilePreview as l}from"../PickaxeMarkdown/Components/A/FilePreview.js";import{safeJSONParse as c}from"../../../../common/utils.js";import p from"../../../../common/cn.js";const m=i((()=>import("./TextPart/index.js"))),u=i((()=>import("./ReasoningPart/index.js"))),d=i((()=>import("./ActionToolCaptionPart/index.js"))),f=i((()=>import("./ReasoningCaptionPart/index.js"))),g=/(!?)\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|www\.[^\s)]+)\)/g,v=({className:i,parts:v})=>{const h=n(new Set);return h.current=new Set,e("div",Object.assign({className:p("flex flex-col gap-2",i)},{children:e(t,Object.assign({fallback:e("div",{})},{children:v.map(((n,t)=>{if(!n.isVisible)return null;if("text"===n.type){const i=((e,n)=>{var t,i;const o=[];let r=0;for(const c of e.matchAll(g)){const p=null!==(t=c.index)&&void 0!==t?t:0,m=c[0],u="!"===c[1],d=null===(i=c[2])||void 0===i?void 0:i.trim(),f=c[3],g=a(f);if(!g)continue;p>r&&o.push({type:"markdown",value:e.slice(r,p)});const v=d&&s(d)!==g.url?d:void 0;l(g,n)?o.push({type:"preview",key:`${g.url}-${p}`,fileInfo:g,displayName:v}):o.push({type:"markdown",value:u?m:`[${d||g.fileName}](${g.url})`}),r=p+m.length}return r<e.length&&o.push({type:"markdown",value:e.slice(r)}),o.length?o:[{type:"markdown",value:e}]})(n.content,h);return e(m,{children:i.map(((n,t)=>"preview"===n.type?e(r,{fileInfo:n.fileInfo,displayName:n.displayName},n.key):n.value?e(o,{value:n.value,filePreviewSeenRef:h},t):null))},t)}if("reasoning"===n.type)return e(u,Object.assign({isReasoning:t===v.length-1},{children:e(o,{value:n.content})}),t);if("data-action-tool-caption"===n.type){const i=c(n.content);return e(d,Object.assign({},i&&i,{isLoading:t===v.length-1}),t)}if("data-reasoning-caption"===n.type){const i=c(n.content);return e(f,Object.assign({},i&&i,{isLoading:t===v.length-1}),t)}return null}))}))}))};export{v as default};
1
+ import{jsx as e}from"react/jsx-runtime";import{useRef as t,Suspense as n,lazy as i}from"react";import{PickaxeMarkdownRenderer as o}from"../PickaxeMarkdown/Renderer.js";import s,{isGeneratedFileUrl as r,normalizeMarkdownUrl as a,getFilePreviewInfo as l,shouldSuppressRichPreviewForUrl as c,shouldRenderFilePreview as p}from"../PickaxeMarkdown/Components/A/FilePreview.js";import{safeJSONParse as u}from"../../../../common/utils.js";import d from"../../../../common/cn.js";const m=i((()=>import("./TextPart/index.js"))),f=i((()=>import("./ReasoningPart/index.js"))),v=i((()=>import("./ActionToolCaptionPart/index.js"))),g=i((()=>import("./ReasoningCaptionPart/index.js"))),h=/(!?)\[([^\]\n]+)\]\((https?:\/\/[^\s)]+|www\.[^\s)]+)\)/g,w=e=>{const t=new Set;for(const n of e){if("data-tool-assets"!==n.type)continue;const e=u(n.content);if(null==e?void 0:e.assets)for(const n of e.assets)n.value&&!r(n.value)&&t.add(a(n.value))}return t},y=({className:i,parts:r})=>{const y=t(new Set);y.current=new Set;const j=w(r);return e("div",Object.assign({className:d("flex flex-col gap-2",i)},{children:e(n,Object.assign({fallback:e("div",{})},{children:r.map(((t,n)=>{if(!t.isVisible)return null;if("text"===t.type){const i=((e,t,n)=>{var i,o;const s=[];let r=0;for(const u of e.matchAll(h)){const d=null!==(i=u.index)&&void 0!==i?i:0,m=u[0],f="!"===u[1],v=null===(o=u[2])||void 0===o?void 0:o.trim(),g=u[3],h=l(g);if(!h)continue;if(c(h.url,n))continue;d>r&&s.push({type:"markdown",value:e.slice(r,d)});const w=v&&a(v)!==h.url?v:void 0;p(h,t)?s.push({type:"preview",key:`${h.url}-${d}`,fileInfo:h,displayName:w}):s.push({type:"markdown",value:f?m:`[${v||h.fileName}](${h.url})`}),r=d+m.length}return r<e.length&&s.push({type:"markdown",value:e.slice(r)}),s.length?s:[{type:"markdown",value:e}]})(t.content,y,j);return e(m,{children:i.map(((t,n)=>"preview"===t.type?e(s,{fileInfo:t.fileInfo,displayName:t.displayName},t.key):t.value?e(o,{value:t.value,filePreviewSeenRef:y,suppressedRichPreviewUrls:j},n):null))},n)}if("reasoning"===t.type)return e(f,Object.assign({isReasoning:n===r.length-1},{children:e(o,{value:t.content,suppressedRichPreviewUrls:j})}),n);if("data-action-tool-caption"===t.type){const i=u(t.content);return e(v,Object.assign({},i&&i,{isLoading:n===r.length-1}),n)}if("data-reasoning-caption"===t.type){const i=u(t.content);return e(g,Object.assign({},i&&i,{isLoading:n===r.length-1}),n)}return null}))}))}))};export{y as default,w as getSuppressedRichPreviewUrls};
@@ -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{useResponseContext as c}from"../../hooks/pickaxe/useResponseContext.js";import{useDocumentContext as d}from"./Addons/Document/hooks/useDocumentContext.js";import{useArtifactContext as u}from"./Addons/Artifact/hooks/useArtifactContext.js";import{v4 as m}from"uuid";import{ScrollProvider as p}from"./Addons/Scroll/Provider.js";import f from"./common/PickaxeSkeleton.js";import x from"./Chat/index.js";import h from"./Form/index.js";import v from"./Addons/Auth/index.js";import g from"../../common/cn.js";import j from"../../common/api/pickaxe.js";import{getValidationFailure as b}from"../../common/validation.js";import k from"./common/AccessGroupCardPreview.js";import{Avatar as y,AvatarImage as w,AvatarFallback as N}from"./common/PickaxeAvatar.js";import O from"../Icons/lock.svg.js";import{EmbeddedCheckoutProvider as _,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 A}from"../../node_modules/.pnpm/@stripe_stripe-js@7.9.0/node_modules/@stripe/stripe-js/dist/index.mjs.js";const C=({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"})})),S=({pickaxeId:S,className:q})=>{const{sessionId:P,styles:U,colors:G,responsiveBy:T,deploymentType:L,isNewChat:R,isEmbed:E,opacity:D,deploymentId:B,sender:$,portalId:F,validationStatus:V,validationUpgradeGroups:M,validationUpgradeUrl:W,stripeAccountId:z,clientSecret:H,translations:J,preventInitialSessionId:K,setClientSecret:X,setStripeAccountId:Y,setValidationStatus:Q,setValidationUpgradeGroups:Z,setValidationUpgradeUrl:ee,setContextId:se,setPickaxeId:te,setSessionId:oe,setPickaxe:ie,setAccessGroup:re}=l(),{isSent:ae,token:le}=n(),{setMessages:ne,setResponse:ce,setError:de,setLimitData:ue,setIsSwitchedToChat:me}=c(),{setDocumentError:pe}=d(),{setCurrentArtifact:fe}=u(),[xe,he]=i(!1),ve=o(),ge="chat-input"===L&&R&&!ae,je=r((()=>z?A(process.env.NEXT_PUBLIC_STRIPE_KEY,{stripeAccount:z}):null),[z]);a((()=>{te(S)}),[S]);a((()=>{if(!B&&!F||!ve.data)return;if("stripe_checkout"===V)return;e(void 0,void 0,void 0,(function*(){var e;Q("loading");try{const s=yield j.post("/validate_studio_deployment",{data:{deploymentId:B,sender:$||void 0,studioSessionToken:le,portalId:F,studioId:null===(e=ve.data)||void 0===e?void 0:e.studioid}});if(s.data.success)Q("success"),Z([]),ee(null),re(s.data.accessGroup);else{const e=b(s.data);if(!e)return Q("login_required"),Z([]),void ee(null);Q(e.status),Z(e.upgradeGroups),ee(e.upgradeUrl),he(!0)}}catch(e){console.error("Failed to validate deployment:",e),Q("success")}}))}),[B,$,le,F,ve.data]),a((()=>{if(!ve.data)return;const e=ve.data.chatflag;K||oe(e?m():""),se(m()),e?ne([]):ce(null),de(""),pe(""),ue(null),fe(null),me(!1),ie(ve.data),he(!0)}),[ve.data]),a((()=>{de(""),pe(""),ue(null),ne([]),ce(null),fe(null)}),[P]);const be=r((()=>{const e=null!=D?D: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,D]);if(!ve.data)return null;return s("div",Object.assign({className:g("relative @container/pickaxe-root flex flex-col flex-grow w-full h-full","dark"===U.theme&&"dark",q),style:Object.assign({backgroundColor:ge?"transparent":be,color:G.text},U.font&&"Real Head Pro"!==U.font&&{fontFamily:U.font})},{children:(()=>{var o,i;if("stripe_checkout"===V&&H&&je)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:()=>{X&&X(null),Y&&Y(null),Q("success")},className:"flex items-center gap-2 text-sm font-semibold opacity-70 hover:opacity-100 transition-opacity",style:{color:G.text}},{children:[s(C,{className:"w-5 h-5"}),s("span",{children:(null==J?void 0:J.back)||"Back"})]}))})),s("div",Object.assign({className:"flex-1 w-full h-full overflow-y-auto [&>div]:h-full"},{children:s(_,Object.assign({stripe:je,options:{clientSecret:H}},{children:s(I,{})}))}))]}));if(ve.isLoading||!xe||"loading"===V)return s("div",Object.assign({className:g("flex items-center flex-col w-full pt-12 px-4 pb-10","viewport"===T?"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(f,{className:"w-[72px] h-[72px]"}),s(f,{className:"h-[20px] mt-6 w-full"}),s(f,{className:"h-[20px] mt-2 w-full"}),s(f,{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(f,{className:g("w-full min-h-[48px]","viewport"===T?"min-[767px]:max-w-[176px]":"@[767px]/pickaxe-root:max-w-[176px]")})}))]}))}));if("upgrade_required"===V){const e=M.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==J?void 0:J["upgrade-required"])||"Upgrade Required"})),s("p",Object.assign({className:"break-words opacity-80"},{children:(null==J?void 0:J["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:M.map(((e,t)=>s(k,{data:e,upgradeUrl:W},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==J?void 0:J["access-locked"])||"Access Locked"})),s("p",Object.assign({className:"opacity-80"},{children:(null==J?void 0:J["this-tool-is-locked-contact-owner"])||"This tool is locked to use. Contact owner for more information."}))]}))}))}return"login_required"===V&&E?s(v,{}):"login_required"!==V||E?"access_denied"===V?t("div",Object.assign({className:"flex flex-col items-center justify-center w-full h-full p-4 overflow-y-auto"},{children:[t(y,Object.assign({className:"h-[68px] w-[68px] mb-4"},{children:[s(w,{src:null===(o=ve.data)||void 0===o?void 0:o.coverphoto,alt:`${null===(i=ve.data)||void 0===i?void 0:i.formtitle} Logo`}),s(N,{})]})),t("div",Object.assign({className:"text-center mb-6"},{children:[s("h2",Object.assign({className:"text-2xl font-bold mb-2"},{children:(null==J?void 0:J["access-denied"])||"Access Denied"})),t("div",Object.assign({className:"w-[400px] text-xl flex justify-center items-start"},{children:[s(O,{className:"h-6 w-6 mr-[-20px] shrink-0"}),s("p",Object.assign({className:"ml-1"},{children:(null==J?void 0:J["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=M.map((e=>e.accessGroupId));try{const o=yield j.post("/request_access",{data:{sender:$||void 0,studioSessionToken:le,studioId:null===(e=ve.data)||void 0===e?void 0:e.studioid,message:JSON.stringify({toolId:null===(s=ve.data)||void 0===s?void 0:s.formid,deploymentId:B,accessGroupIds:t})}});o.data.success?alert((null==J?void 0:J["access-requested-successfully"])||"Successfully requested access!"):alert(o.data.error)}catch(e){alert(`Couldn't request access. Error: ${e}`)}}))}},{children:(null==J?void 0:J["request-access"])||"Request Access"})),s("span",Object.assign({className:"mt-4 mb-2"},{children:(null==J?void 0:J.or)||"or"})),s("span",Object.assign({className:"font-medium text-lg"},{children:(null==J?void 0:J["sign-in-with-different-account"])||"Sign in with a different account"}))]})):s(p,P?{children:s(x,{})}:{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==J?void 0:J["access-denied"])||"Access Denied"})),s("p",Object.assign({className:"opacity-80"},{children:(null==J?void 0:J["login-is-required"])||"Login is required."}))]}))}))})()}))};export{S 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 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};
@@ -11,6 +11,7 @@ type AuthContextType = {
11
11
  isResendDisabled: boolean;
12
12
  isSent: boolean;
13
13
  isPricingAuth: boolean;
14
+ isAuthBootstrapComplete: boolean;
14
15
  setEmailInput: SetState<string>;
15
16
  setToken: SetState<string | null>;
16
17
  setIsLoggingIn: SetState<boolean>;
@@ -19,6 +20,7 @@ type AuthContextType = {
19
20
  setIsSent: SetState<boolean>;
20
21
  setIsPricingAuth: SetState<boolean>;
21
22
  setRedirectUrl: SetState<string | null>;
23
+ setIsAuthBootstrapComplete: SetState<boolean>;
22
24
  };
23
25
  export interface IAuthProviderProps {
24
26
  children: ReactNode;
@@ -0,0 +1 @@
1
+ export declare const useAuthBootstrap: () => void;
@@ -9,6 +9,7 @@ export declare const useAuthContext: () => {
9
9
  isResendDisabled: boolean;
10
10
  isSent: boolean;
11
11
  isPricingAuth: boolean;
12
+ isAuthBootstrapComplete: boolean;
12
13
  setEmailInput: import("../../../../../types/common").SetState<string>;
13
14
  setToken: import("../../../../../types/common").SetState<string | null>;
14
15
  setIsLoggingIn: import("../../../../../types/common").SetState<boolean>;
@@ -17,4 +18,5 @@ export declare const useAuthContext: () => {
17
18
  setIsSent: import("../../../../../types/common").SetState<boolean>;
18
19
  setIsPricingAuth: import("../../../../../types/common").SetState<boolean>;
19
20
  setRedirectUrl: import("../../../../../types/common").SetState<string | null>;
21
+ setIsAuthBootstrapComplete: import("../../../../../types/common").SetState<boolean>;
20
22
  };
@@ -7,7 +7,13 @@ export type FilePreviewInfo = {
7
7
  kind: FilePreviewKind;
8
8
  };
9
9
  export type FilePreviewSeenRef = MutableRefObject<Set<string>>;
10
+ export type SuppressedRichPreviewUrls = Set<string>;
10
11
  export declare const normalizeMarkdownUrl: (href: string) => string;
12
+ export declare const isGeneratedFileUrl: (href: string) => boolean;
13
+ export declare const isDocumentSourceUrl: (href: string) => boolean;
14
+ export declare const isSourceLikeRichPreviewUrl: (href: string) => boolean;
15
+ export declare const shouldSuppressRichPreviewForUrl: (href: string, suppressedRichPreviewUrls?: SuppressedRichPreviewUrls) => boolean | undefined;
16
+ export declare const shouldSuppressRichPreviewInText: (value: string, suppressedRichPreviewUrls?: SuppressedRichPreviewUrls) => boolean;
11
17
  export declare const getFilePreviewInfo: (href: string) => FilePreviewInfo | null;
12
18
  export declare const shouldRenderFilePreview: (fileInfo: FilePreviewInfo | null, seenRef?: FilePreviewSeenRef) => boolean;
13
19
  interface FilePreviewProps {
@@ -1,7 +1,8 @@
1
1
  import type { MarkdownComponent } from "../..";
2
- import type { FilePreviewSeenRef } from "./FilePreview";
2
+ import type { FilePreviewSeenRef, SuppressedRichPreviewUrls } from "./FilePreview";
3
3
  type AProps = Parameters<MarkdownComponent<"a">>[0] & {
4
4
  filePreviewSeenRef?: FilePreviewSeenRef;
5
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
5
6
  };
6
- export declare const A: ({ href, children, filePreviewSeenRef }: AProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const A: ({ href, children, filePreviewSeenRef, suppressedRichPreviewUrls, }: AProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -1,2 +1,7 @@
1
1
  import type { MarkdownComponent } from "../..";
2
- export declare const P: MarkdownComponent<"p">;
2
+ import type { SuppressedRichPreviewUrls } from "../A/FilePreview";
3
+ type PProps = Parameters<MarkdownComponent<"p">>[0] & {
4
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
5
+ };
6
+ export declare const P: ({ children, suppressedRichPreviewUrls }: PProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode, type CSSProperties } from "react";
2
- import { type FilePreviewSeenRef } from "./Components/A/FilePreview";
2
+ import { type FilePreviewSeenRef, type SuppressedRichPreviewUrls } from "./Components/A/FilePreview";
3
3
  export interface PickaxeMarkdownRendererProps {
4
4
  className?: string;
5
5
  style?: CSSProperties;
@@ -10,5 +10,6 @@ export interface PickaxeMarkdownRendererProps {
10
10
  multiLineBreaks?: boolean;
11
11
  onExpandClick?: () => void;
12
12
  filePreviewSeenRef?: FilePreviewSeenRef;
13
+ suppressedRichPreviewUrls?: SuppressedRichPreviewUrls;
13
14
  }
14
- export declare const PickaxeMarkdownRenderer: ({ className, style, children: _children, value, maxLines, maxChars, multiLineBreaks, onExpandClick, filePreviewSeenRef, }: PickaxeMarkdownRendererProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const PickaxeMarkdownRenderer: ({ className, style, children: _children, value, maxLines, maxChars, multiLineBreaks, onExpandClick, filePreviewSeenRef, suppressedRichPreviewUrls, }: PickaxeMarkdownRendererProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,9 @@
1
1
  import type { PickaxeHistoryMessagePart } from "../../../../types/history";
2
+ import { type SuppressedRichPreviewUrls } from "../PickaxeMarkdown/Components/A/FilePreview";
2
3
  interface PickaxeMessagePartsProps {
3
4
  className?: string;
4
5
  parts: PickaxeHistoryMessagePart[];
5
6
  }
7
+ export declare const getSuppressedRichPreviewUrls: (parts: PickaxeHistoryMessagePart[]) => SuppressedRichPreviewUrls;
6
8
  declare const PickaxeMessageParts: ({ className, parts, }: PickaxeMessagePartsProps) => import("react/jsx-runtime").JSX.Element;
7
9
  export default PickaxeMessageParts;
@@ -35,7 +35,7 @@ export type PickaxeHistoryMessage = {
35
35
  createdAt: string;
36
36
  area?: PickaxeHistoryMessageArea;
37
37
  };
38
- export type PickaxeHistoryMessagePartsType = "text" | "reasoning" | "data-action-tool-caption" | "data-reasoning-caption";
38
+ export type PickaxeHistoryMessagePartsType = "text" | "reasoning" | "data-action-tool-caption" | "data-reasoning-caption" | "data-tool-assets";
39
39
  export type PickaxeHistoryMessagePart = {
40
40
  type: PickaxeHistoryMessagePartsType;
41
41
  content: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "6.6.0",
3
+ "version": "6.6.2",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",