@pickaxeproject/react 6.5.2 → 6.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/components/Pickaxe/Addons/Document/hooks/useDocument.js +1 -1
  2. package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
  3. package/dist/cjs/components/Pickaxe/Chat/index.js +1 -1
  4. package/dist/cjs/components/Pickaxe/Form/History/Item.js +1 -1
  5. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.js +1 -1
  6. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.js +1 -1
  7. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.js +1 -1
  8. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/Renderer.js +1 -1
  9. package/dist/cjs/components/Pickaxe/common/PickaxeMarkdown/utils/custom-plugins.js +1 -1
  10. package/dist/cjs/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  11. package/dist/cjs/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
  12. package/dist/cjs/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
  13. package/dist/cjs/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
  14. package/dist/cjs/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
  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/PickaxeMarkdown/utils/custom-plugins.d.ts +7 -0
  20. package/dist/cjs/src/components/Pickaxe/common/PickaxeMessageParts/index.d.ts +2 -0
  21. package/dist/cjs/src/types/history.d.ts +1 -1
  22. package/dist/esm/components/Pickaxe/Addons/Document/hooks/useDocument.js +1 -1
  23. package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
  24. package/dist/esm/components/Pickaxe/Chat/index.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/PickaxeMarkdown/utils/custom-plugins.js +1 -1
  31. package/dist/esm/components/Pickaxe/common/PickaxeMessageParts/index.js +1 -1
  32. package/dist/esm/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
  33. package/dist/esm/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
  34. package/dist/esm/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
  35. package/dist/esm/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
  36. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/FilePreview.d.ts +6 -0
  37. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/A/index.d.ts +3 -2
  38. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Components/P/index.d.ts +6 -1
  39. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/Renderer.d.ts +3 -2
  40. package/dist/esm/src/components/Pickaxe/common/PickaxeMarkdown/utils/custom-plugins.d.ts +7 -0
  41. package/dist/esm/src/components/Pickaxe/common/PickaxeMessageParts/index.d.ts +2 -0
  42. package/dist/esm/src/types/history.d.ts +1 -1
  43. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../Auth/hooks/useAuthContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),n=require("./useDocumentContext.js"),o=require("../../../../../common/documents.js"),r=require("uuid"),d=require("../../../../../common/error.js");exports.useDocument=({onQuestionChange:a}={})=>{const{contextId:u,pickaxeId:l,sessionId:c,sender:m,senderType:p,pickaxe:f,translations:w}=t.usePickaxeContext(),{token:b}=s.useAuthContext(),I=n.useDocumentContext(),v=i.useSubmitDocument(),h=e=>{const t=[...o.allowedFileMimeTypes,...o.allowedImageMimeTypes];if(e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&o.additionalAllowedFileExtensions.includes(`.${t}`))return!1}return!0}))){const e=(null==w?void 0:w["invalid-upload-file-types"])||"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again.",t=new Error(e),s=d.default(t);return I.setDocumentError(s),!0}return!1};return Object.assign(Object.assign({},I),{onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(I.setDocumentError(""),!t.length)return null;if(h(t))return null;I.setIsUploading(!0),I.setIsShowList(!0);const s=t.map((e=>({file:e,id:r.v4()})));s.forEach((({file:e,id:t})=>{I.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e.__awaiter(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,folder:n,error:r}=yield v.document(Object.assign(Object.assign(Object.assign({contextId:u,pickaxeId:l,sessionId:c,file:t},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),b&&{studioSessionToken:b}));if(!e)throw new Error(r||(null==w?void 0:w["document-processing-failed"])||"Document processing failed");null==a||a({input:t.name,documentId:i});const d=i.startsWith("IMAGE-")||o.allowedImageMimeTypes.includes(t.type);return I.editDocument(Object.assign({id:s,type:d?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i},d&&n&&{folder:n})),{name:t.name,documentId:i}}catch(e){const i=d.default(e);return I.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),I.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){I.setDocumentError("");let e=t.trim();if(!e)return null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error((null==w?void 0:w["invalid-website-or-youtube-link"])||"Please paste a valid website URL or Youtube video link to add to the knowledge base.");I.setIsUploading(!0),I.setIsShowList(!0),I.setWebsiteLink(""),I.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield v.website(Object.assign(Object.assign(Object.assign({pickaxeId:l,sessionId:c,website:e},(null==f?void 0:f.workspaceid)&&{workspaceId:f.workspaceid}),"STUDIO_USER"===p&&{studioUserId:m}),b&&{studioSessionToken:b})),{success:s,documentId:i}=t;if(!s)throw new Error((null==w?void 0:w["website-processing-failed"])||"Website processing failed, please try again.");I.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:i}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:i}}catch(t){const s=d.default(t);if(s.includes((null==w?void 0:w["invalid-website-url"])||"Please paste a valid website URL"))return I.setDocumentError(s),null;I.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:s});return{type:"website",id:e,size:0,name:e,status:"failed",error:s}}finally{I.setIsUploading(!1)}}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),s=require("../../Auth/hooks/useAuthContext.js"),i=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),o=require("./useDocumentContext.js"),n=require("../../../../../common/documents.js"),r=require("uuid"),d=require("../../../../../common/error.js");exports.useDocument=({onQuestionChange:u}={})=>{var a,l;const{contextId:c,pickaxeId:p,sessionId:m,sender:f,senderType:w,pickaxe:v,translations:b}=t.usePickaxeContext(),{token:I}=s.useAuthContext(),h=o.useDocumentContext(),g=i.useSubmitDocument(),y=null!==(l=null===(a=null==v?void 0:v.documentuploadtype)||void 0===a?void 0:a.startsWith("enduserupload"))&&void 0!==l&&l,k=(null==b?void 0:b["file-upload-disabled"])||"File uploads are disabled for this Pickaxe.",D=e=>{const t=[...n.allowedFileMimeTypes,...n.allowedImageMimeTypes],s=e.some((e=>{var s;if(t.includes(e.type))return!1;if(""===e.type){const t=null===(s=e.name.split(".").pop())||void 0===s?void 0:s.toLowerCase();if(t&&n.additionalAllowedFileExtensions.includes(`.${t}`))return!1}return!0}));if(s){const e=(null==b?void 0:b["invalid-upload-file-types"])||"You can only upload PDF, TXT, DOCX, CSV, XLSX, JSON, PPTX, MD, XML, PNG, JPEG, WEBP, or GIF files. Please try again.",t=new Error(e),s=d.default(t);return h.setDocumentError(s),!0}return!1};return Object.assign(Object.assign({},h),{onFileUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(h.setDocumentError(""),!t.length)return null;if(!y)return h.setDocumentError(k),null;if(D(t))return null;h.setIsUploading(!0),h.setIsShowList(!0);const s=t.map((e=>({file:e,id:r.v4()})));s.forEach((({file:e,id:t})=>{h.addDocument({type:"document",id:t,size:e.size,name:e.name,status:"uploading"})}));const i=s.map((({file:t,id:s})=>e.__awaiter(void 0,void 0,void 0,(function*(){try{const{success:e,documentId:i,folder:o,error:r}=yield g.document(Object.assign(Object.assign(Object.assign({contextId:c,pickaxeId:p,sessionId:m,file:t},(null==v?void 0:v.workspaceid)&&{workspaceId:v.workspaceid}),"STUDIO_USER"===w&&{studioUserId:f}),I&&{studioSessionToken:I}));if(!e)throw new Error(r||(null==b?void 0:b["document-processing-failed"])||"Document processing failed");null==u||u({input:t.name,documentId:i});const d=i.startsWith("IMAGE-")||n.allowedImageMimeTypes.includes(t.type);return h.editDocument(Object.assign({id:s,type:d?"image":"document",name:t.name,size:t.size,status:"finished",documentId:i},d&&o&&{folder:o})),{name:t.name,documentId:i}}catch(e){const i=d.default(e);return h.editDocument({id:s,name:t.name,size:t.size,status:"failed",error:i}),{error:i}}}))));yield Promise.allSettled(i),h.setIsUploading(!1)})),onWebsiteUpload:t=>e.__awaiter(void 0,void 0,void 0,(function*(){h.setDocumentError("");let e=t.trim();if(!e)return null;if(!y)return h.setDocumentError(k),null;e.startsWith("http://")&&(e=e.replace("http://","https://")),e.startsWith("https://")||(e=`https://${e}`);try{if(!e.includes("."))throw new Error((null==b?void 0:b["invalid-website-or-youtube-link"])||"Please paste a valid website URL or Youtube video link to add to the knowledge base.");h.setIsUploading(!0),h.setIsShowList(!0),h.setWebsiteLink(""),h.setDocuments([{type:"website",id:e,size:0,name:e,status:"uploading"}]);const t=yield g.website(Object.assign(Object.assign(Object.assign({pickaxeId:p,sessionId:m,website:e},(null==v?void 0:v.workspaceid)&&{workspaceId:v.workspaceid}),"STUDIO_USER"===w&&{studioUserId:f}),I&&{studioSessionToken:I})),{success:s,documentId:i}=t;if(!s)throw new Error((null==b?void 0:b["website-processing-failed"])||"Website processing failed, please try again.");h.setDocuments([{type:"website",id:e,size:0,name:e,status:"finished",documentId:i}]);return{type:"website",id:e,name:e,size:0,status:"finished",documentId:i}}catch(t){const s=d.default(t);if(s.includes((null==b?void 0:b["invalid-website-url"])||"Please paste a valid website URL"))return h.setDocumentError(s),null;h.editDocument({type:"website",id:e,size:0,name:e,status:"failed",error:s});return{type:"website",id:e,size:0,name:e,status:"failed",error:s}}finally{h.setIsUploading(!1)}}))})};
@@ -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"),o=require("../../../hooks/studio/useStyleInput.js"),r=require("../../../hooks/studio/useStyleFontSize.js"),a=require("../../../hooks/pickaxe/useConversation.js"),l=require("../../../hooks/pickaxe/useDimensionContext.js"),d=require("../Addons/Auth/hooks/useAuthContext.js"),c=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"),x=require("../../Icons/microphone.svg.js"),y=require("../../Icons/stop.svg.js"),I=require("../Addons/Document/List.js"),j=require("../../Core/Textarea.js"),w=require("../../Core/ErrorAlert.js"),O=require("../../../common/error.js"),N=require("../../../common/api/pickaxe.js"),S=require("../../../common/validation.js"),k=require("../../../common/cn.js"),_=require("../../../common/utils.js"),U=require("../../../common/pickaxeConfig.js"),C=require("../../../common/deploymentWebhooks.js"),E=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,L=(e,t)=>{if(e&&"object"==typeof e)return e[t]},P=(e,t)=>{const s=L(e,t);return D(s)?s:null},q=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},R=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const o=Array.isArray(L(e,"uses"))?L(e,"uses"):[],r=(({deploymentId:e,portalId:t})=>D(e)?{type:"deployment",id:e}:D(t)?{type:"portal",id:t}:null)({deploymentId:t,portalId:s});if(!r)return{scope:r,record:null};const a=null!==(i=null!==(n=o.find((e=>e.id===r.id&&e.type===r.type)))&&void 0!==n?n:o.find((e=>e.id===r.id)))&&void 0!==i?i:null;return{scope:r,record:a}},M=s.forwardRef((({resubmitPrompt:L,onFocus:M,onBlur:F,onInputHeightChange:V,initSmitheryAuthData:H},W)=>{var $,B,X,Y,K,z,J,G,Q;const{origin:Z,pickaxeId:ee,sessionId:te,sender:se,senderType:ne,portalId:ie,deploymentId:oe,deploymentType:re,pickaxe:ae,styles:le,colors:de,translations:ce,locale:ue,forceMobile:pe,isNewChat:me,isRtl:fe,isShowFeedbackMessage:ge,accessGroup:he,setIsNewChat:ve,setIsShowIceBreaker:be,setValidationStatus:xe,setValidationUpgradeGroups:ye,setValidationUpgradeUrl:Ie,onGenerateComplete:je}=n.usePickaxeContext(),{token:we,isLoggedOut:Oe,isSent:Ne,isPricingAuth:Se}=d.useAuthContext(),{messages:ke,isGenerating:_e,setMessages:Ue,setStatus:Ce,setLimitData:Ee,setError:Te}=i.useResponseContext(),{documents:Ae,isUploading:De,documentError:Le,onFileUpload:Pe,setDocuments:qe,setDocumentError:Re}=c.useDocument(),{studio:Me}=E.useStudio(),{scrollStartSession:Fe,scrollEndSession:Ve,scrollToBottom:He}=u.useScroll({auto:!0}),{artifacts:We,currentPopupType:$e,setArtifacts:Be,setCurrentArtifact:Xe}=p.useArtifactContext(),{height:Ye}=l.useDimensionContext(),Ke=a.useConversation(),[ze,Je]=s.useState(""),[Ge,Qe]=s.useState(!1),[Ze,et]=s.useState(!1),[tt,st]=s.useState(null),[nt,it]=s.useState(null),[ot,rt]=s.useState(!1),[at,lt]=s.useState(!1),[dt,ct]=s.useState(0),ut=s.useRef(null),pt=s.useRef(""),mt=s.useRef(null),ft=s.useRef(null),gt=s.useRef(null),ht=s.useRef(null),vt=s.useRef(null),bt=s.useRef(new Set),xt=s.useRef(null),yt=Math.max(.4*Ye,100),{speechTranscript:It,isSpeechListening:jt,isSpeechProcessing:wt,isSpeechSupported:Ot,onStartListening:Nt,onStopListening:St}=T.useSpeech(),[kt]=f.useMediaQuery("(max-width: 480px)"),_t=m.useHover(),{isHover:Ut}=_t,Ct=e.__rest(_t,["isHover"]),Et=m.useHover(),{isHover:Tt}=Et,At=e.__rest(Et,["isHover"]),Dt=m.useHover(),{isHover:Lt}=Dt,Pt=e.__rest(Dt,["isHover"]),qt=r.useStyleFontSize(),Rt=o.useStyleInput(),Mt="undefined"!=typeof window?window.location.hostname:"",Ft="undefined"!=typeof window?window.location.href:"",Vt="undefined"!=typeof window&&window.self!==window.top,Ht=Mt.includes("pickaxe.co")&&!Ft.includes("https://studio.pickaxe.co/_embed")&&!Vt,Wt=null===($=null==ae?void 0:ae.documentuploadtype)||void 0===$?void 0:$.startsWith("enduserupload"),$t=Ot&&(null==ae?void 0:ae.enablevoicetotext),Bt=D(oe),Xt="chat-input"===re&&me&&!Ne,Yt="chat-input"===re&&Se&&Oe&&Ne,Kt=s.useCallback((e=>{const t=S.getValidationFailure(e);return!!t&&(Te(""),Ee(null),xe(t.status),ye(t.upgradeGroups),Ie(t.upgradeUrl),!0)}),[Te,Ee,xe,ye,Ie]),zt=null!==(B=null==ae?void 0:ae.placeholdertext)&&void 0!==B?B:fe?"بماذا تريد أن تتحدث؟":(null==ce?void 0:ce["what-do-you-want-to-talk-about"])||"What do you want to talk about?",Jt=Ge||Ze,Gt=s.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){rt(!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==ae?void 0:ae.studioid},se&&{sender:se}),we&&{studioSessionToken:we}),!we&&!se&&{sender:_.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}})),Ht&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(st(t.studioUser),it(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{rt(!0)}}))),[Z,ee,te,ne,se,we,ie,oe,Ht]);s.useEffect((()=>{Gt()}),[Gt]);const Qt=Number(null!==(X=null==he?void 0:he.limit)&&void 0!==X?X:0),Zt="string"==typeof(null==he?void 0:he.limitInterval)?he.limitInterval:null,es=!!(null==Me?void 0:Me.data.usage)&&Me.data.usage.isCredits,ts=s.useMemo((()=>R({studioUser:tt,deploymentId:oe,portalId:ie})),[oe,ie,tt]);s.useEffect((()=>{Bt&&me&&te&&bt.current.add(te)}),[me,te,Bt]);const ss=s.useCallback((()=>{var e,t,s;return{studioId:null==ae?void 0:ae.studioid,userEmail:P(tt,"email"),userId:null!==(e=P(tt,"userId"))&&void 0!==e?e:P(tt,"userid"),sessionId:te,deploymentId:oe,deploymentType:re,portalId:ie,accessGroupId:null!==(t=null==he?void 0:he.accessGroupId)&&void 0!==t?t:null,pickaxeId:ee,sender:se,senderType:ne,origin:Z,metadata:null!==(s=U.getPickaxeConfigMetadata(oe))&&void 0!==s?s:null}}),[null==he?void 0:he.accessGroupId,oe,re,Z,null==ae?void 0:ae.studioid,ee,ie,se,ne,te,tt]),ns=s.useCallback((()=>!!(Bt&&ot&&te)&&(!!bt.current.has(te)&&(C.fireDeploymentSessionInitializedWebhook(ss()),bt.current.delete(te),!0))),[ss,ot,te,Bt]);s.useEffect((()=>{if(!ot||!te)return;ns();const e=xt.current;(null==e?void 0:e.sessionId)===te&&(C.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),ss()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),xt.current=null)}),[ns,ss,ot,te]);const is={currentUses:q(null==tt?void 0:tt.currentUses),extraUses:q(null==tt?void 0:tt.extraUses)},os=ts.scope?{currentUses:null!==(K=q(null===(Y=ts.record)||void 0===Y?void 0:Y.currentUses))&&void 0!==K?K:0,extraUses:null!==(J=q(null===(z=ts.record)||void 0===z?void 0:z.extraUses))&&void 0!==J?J:0}:{currentUses:0,extraUses:0},rs=Oe?os:is;s.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(es&&(null===(e=null==Me?void 0:Me.data)||void 0===e?void 0:e.workspaceId))try{const e=yield N.default.get(`/cost_per_run?workspaceId=${Me.data.workspaceId}`,{withCredentials:!1});t&&ct(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&ct(0)}else t&&ct(0)})),()=>{t=!1}}),[es,null===(G=null==Me?void 0:Me.data)||void 0===G?void 0:G.workspaceId]);const as=(({currentUses:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=e?e:0),o=Number(null!=t?t:0);return s===A.STUDIO_INFINITY_VALUE||o===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,o-i):Math.max(0,s-i)+o})({currentUses:rs.currentUses,extraUses:rs.extraUses,limit:Qt,limitInterval:Zt}),ls=as===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(as)),ds=(({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:rs.extraUses,limit:Qt,limitInterval:Zt}),cs=ds===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.ceil(.05*ds),us=es?Math.ceil(5*dt):5,ps=cs===A.STUDIO_INFINITY_VALUE?A.STUDIO_INFINITY_VALUE:Math.max(cs,us);console.log("Usage and Limits Debug:",{remaining:ls,notificationThreshold:ps,studioUser:tt});const ms=s.useMemo((()=>!!tt&&(!at&&(ls!==A.STUDIO_INFINITY_VALUE&&(!(ls<=0)&&ls<=ps)))),[at,ps,ls,tt]),fs=s.useMemo((()=>{var e,t,s;return!!me&&(!!ae&&(!Ke.isLoading&&(!((null!==(t=null===(e=Ke.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=ae.icebreakers)||void 0===s?void 0:s.length)&&(!ge&&!Xt)))))}),[ae,me,ge,Xt,Ke.data,Ke.isLoading]),gs=s.useMemo((()=>{if(_e||De)return!1;const e=Ae.length>0&&Ae.every((e=>"finished"===e.status));return!(!ze.trim()&&!e)&&Ae.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[_e,De,ze,Ae]);s.useImperativeHandle(W,(()=>({onSubmit:hs}))),s.useEffect((()=>{be(fs)}),[fs]),s.useEffect((()=>{var e;if(L){const t=Array.from(ke),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;hs(s,!0)}}),[L]),s.useEffect((()=>{if(!ht.current||!V)return;const e=new ResizeObserver((e=>{for(const t of e)V(t.contentRect.height)}));return e.observe(ht.current),()=>{e.disconnect()}}),[V]),s.useEffect((()=>{if(!jt)return;const e=pt.current?`${pt.current} `:"";Je(`${e}${It}`)}),[It,jt]),s.useEffect((()=>{if(!ft.current)return;(()=>{if(!ft.current)return;let e=ft.current.scrollHeight>52;ze.includes("\n")||Ae.length?e=!0:ze.trim()||(e=!1),Qe(e)})()}),[ze,Ae]),s.useEffect((()=>{const e=ft.current,t=gt.current;if(!e||!t||Ge||ze.includes("\n"))return void et(!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=ze||zt,document.body.appendChild(i);const o=i.offsetWidth;i.remove();const r=parseFloat(s.paddingLeft)||0,a=parseFloat(s.paddingRight)||0,l=e.clientWidth-r-a-t.offsetWidth;et(o>l)}),[ze,Ge,zt]);const hs=(t,s=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,n,i;try{if(_e||De)return;const o=Ae.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),r=o.map((e=>e.documentId)).filter(Boolean),a=o.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),l=r.length>0,d=null!=t?t:ze;if(!d&&!l)return;Te(""),Re(""),Ee(null),Je(""),ve(!1),Ce("fetching"),Fe(),He();const c=null!==(n=null===(e=null==ae?void 0:ae.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==n&&n&&r.length>0,u=[...s?Array.from(ke.slice(0,ke.length-1)):Array.from(ke),...s?[]:[{id:ke.length+1,role:"user",parts:[{type:"text",content:d,isVisible:!0}],documentIds:c?r:[]}],{id:ke.length+(s?0:2),role:"assistant",parts:[],documentIds:[]}];Ue(u),He(),c&&qe([]);const p=U.getPickaxeConfigMetadata(oe),m=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:Z,pickaxeId:ee,sessionId:te,senderType:ne,value:d},c&&{documentIds:r}),se&&{sender:se}),we&&{studioSessionToken:we}),!we&&!se&&{sender:_.initializeEmbedUserId()}),ie&&{portalId:ie}),oe&&{deploymentId:oe}),p&&{metadata:p}),a.length>0&&{uploadedModelImages:a})),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()})},Ht&&{credentials:"include"})),f=yield m.json();if(!f.success){if(Kt(f))return;const e=new Error(f.error||f.message||(null==ce?void 0:ce["failed-to-start-generation"])||"Failed to start generation");throw f.limitData&&(e.limitData=f.limitData),e}const g=f.submissionId;Bt&&me&&te&&bt.current.add(te);const v=Object.assign(Object.assign({},ss()),{message:d,documentIds:c?r:[],uploadedModelImages:a,hasUploadedDocuments:c,isHidden:s,metadata:null!=p?p:null});ot?(ns(),C.fireDeploymentFirstMessageSubmittedWebhook(v)):xt.current=v,Ce("streaming"),vt.current=new AbortController;const b=u.length-1,x=[];let y=[...null!=We?We:[]],I=0,j=!1,w="";for(;!j;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API_URL}/stream/${g}?index=${I}`,{signal:null===(i=vt.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();mt.current=t;const s=new TextDecoder,n=h.createParser({onEvent:e=>{var t,s;if(e.event&&"ping"!==e.event&&I++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data),s=t.error||t.message||(null==ce?void 0:ce["something-went-wrong"])||"Something went wrong.";return Kt(t)||Te(s),void(j=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("data-error"===n.type&&H){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 j=!0,H({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 j=!0,H({smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)w="",x.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)w+=n.delta,x[x.length-1].content=w;else if("text-end"===n.type)w="";else if("reasoning-start"===n.type)w="",x.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)w+=n.delta,x[x.length-1].content=w;else if("reasoning-end"===n.type)w="";else if(n.type.startsWith("data-")){const e=n;x.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}Ue([...u.slice(0,b),Object.assign(Object.assign({},u[u.length-1]),{id:ke.length+1,role:"assistant",parts:x})])}else if("artifact_created"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Be([...y]),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),Be(y),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);y=y.filter((e=>!(e.id===t.id&&e.version===t.version))),y.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),Be(y),$e.startsWith("inline")||Xe({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");y=y.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),Be(y)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);Be(y.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==ce?void 0:ce["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(Kt(t))return void(j=!0);Te(s)}else"stop"===e.event&&(j=!0)}else j=!0}});for(;;){const{value:e,done:i}=yield t.read();if(i)break;n.feed(s.decode(e))}j||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||"AbortError"===e.name)return void(j=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==je||je(te)}catch(e){if(e.limitData)Ee(e.limitData),Te("");else{let t=O.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==ce?void 0:ce["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),Kt(t)||Te(t)}}finally{He(),Ce("idle"),Ve(),mt.current=null,yield Gt()}}));return Yt?null:t.jsx("div",Object.assign({className:k.default("flex w-full flex-shrink-0 flex-col items-center",!Xt&&"px-4 pb-8"),dir:fe?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[t.jsxs("div",Object.assign({ref:ht,className:k.default("relative flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===le.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Rt),{maxHeight:`${yt}px`,overflowY:"auto"})},{children:[ms&&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:Rt.backgroundColor?`${Rt.backgroundColor}E6`:void 0,borderColor:de.text+"20",color:de.text,borderTopRightRadius:le.cornerRadius+"px",borderTopLeftRadius:le.cornerRadius+"px"}},{children:[t.jsx("div",Object.assign({className:"flex items-center gap-2 text-sm font-medium"},{children:t.jsxs("span",{children:[ls.toLocaleString()," ",es?(null==ce?void 0:ce.credits)||"Credits":(null==ce?void 0:ce.uses)||"Uses"," ",(null==ce?void 0:ce.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:de.accent,color:de.accentText},onClick:e=>{e.preventDefault(),e.stopPropagation();const t=_.buildUpgradeUrl({baseUrl:nt,accessGroupId:null==he?void 0:he.accessGroupId});t&&(_.isInIframe()?window.open(t):location.href=t)}},{children:(null==ce?void 0:ce["pricing.upgrade"])||(null==ce?void 0:ce.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:()=>lt(!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"})}))}))]}))]})),!_e&&Ae.length>0&&t.jsx(I.default,{className:"p-4 pb-0",isDisabled:_e}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[jt&&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!==(Q=de.accent)&&void 0!==Q?Q:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:de.text+"90"}},{children:(null==ce?void 0:ce.listening)||"Listening..."}))]})),t.jsx(j.default,Object.assign({ref:ft,className:k.default(qt.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!ze.trim()&&!ze.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",fe?"text-right":"text-left",Jt&&"mb-12",jt&&"text-transparent"),value:ze,placeholder:zt,onChange:e=>{Je(e)},onKeyDown:e=>{pe||kt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),De||_e||hs()))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);e.length>0&&(t.preventDefault(),ve(!1),yield Pe(e))}))},M&&{onFocus:M},F&&{onBlur:F},{dir:fe?"rtl":"ltr"})),t.jsx("div",Object.assign({ref:gt,className:k.default("flex items-center gap-2 absolute right-0 z-2 transition-all duration-200 ease-in-out",Jt?"bottom-0 mb-2.5":"top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!Jt&&Rt.backgroundColor&&{backgroundColor:Rt.backgroundColor}),{borderTopRightRadius:le.cornerRadius+"px",borderBottomRightRadius:le.cornerRadius+"px"})},{children:_e?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:()=>{vt.current&&(vt.current.abort(),vt.current=null),mt.current&&(mt.current.cancel(),mt.current=null),Ce("idle")},style:{backgroundColor:de.accent,color:de.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):jt?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:St,style:{backgroundColor:de.accent,color:de.accentText}},{children:t.jsx(y.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Wt&&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:Tt?de.accent+"10":void 0,color:Tt?de.accent:de.accent+"80"},disabled:De||_e,onClick:()=>{var e;return null===(e=ut.current)||void 0===e?void 0:e.click()}},At,{children:[t.jsx("input",{id:"file-upload",ref:ut,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*(){ve(!1),yield Pe(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(v.default,{className:"h-6 w-6 shrink-0"})]})),$t&&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:jt?de.accent:Lt?de.accent+"10":void 0,color:jt?de.accentText:Lt?de.accent:de.accent+"80"},disabled:De||_e||wt,onClick:()=>{jt?St():(pt.current=ze,Nt(ue||"en-US"))}},Pt,{children:t.jsx(x.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:Ut||gs?de.accent:de.accent+"10",color:Ut||gs?de.accentText:de.accent+"80"},disabled:!gs,onClick:()=>hs()},Ct,{children:t.jsx(b.default,{className:k.default("h-6 w-6 shrink-0",fe&&"scale-x-[-1] transform")})}))]})}))]}))]})),Le&&t.jsx(w.default,{error:Le,className:"mt-3"})]}))}))}));M.displayName="Input",exports.default=M;
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 +1 @@
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/useDimensionContext.js"),n=require("../Addons/Document/hooks/useDocument.js"),a=require("../Addons/Scroll/hooks/useScrollContext.js"),l=require("../../../hooks/studio/useStyleFontSize.js"),u=require("../../../hooks/core/useScrollToBottomVisibility.js"),c=require("./History/index.js"),d=require("./Input.js"),f=require("../../Icons/attach-vertical.svg.js"),h=require("../../../common/cn.js"),m=require("../../../common/api/pickaxe.js"),p=require("uuid"),v=require("../../Core/StudioTip.js"),x=require("../common/ScrollToBottomButton.js"),j=require("../../../hooks/pickaxe/useResponseContext.js"),g=require("../Addons/Navbar/NavPill.js"),b=require("../../Icons/history.svg.js");exports.default=()=>{const{deploymentType:k,isNewChat:y,setIsNewChat:S,sessionId:w,setSessionId:C,setLastSessionId:q,pickaxeId:I,sender:D,pickaxe:_,styles:N,isEmbed:P,translations:T}=s.usePickaxeContext(),{isSent:A}=i.useAuthContext(),{width:F,height:E,setDimension:O}=r.useDimensionContext(),{setDocuments:R,onFileUpload:H}=n.useDocument(),{scrollContainerRef:z,isLocked:B,setIsLocked:L}=a.useScrollContext(),{isGenerating:G,messages:V}=j.useResponseContext(),M=l.useStyleFontSize(),[U,J]=o.useState(0),[K,Q]=o.useState(!1),[W,X]=o.useState(!1),Y=o.useRef(null),Z=o.useRef(null),$=o.useRef(0),[ee,te]=o.useState(null),[oe,se]=o.useState(!1),ie=(null==T?void 0:T["new-chat"])||"New chat",re="chat-input"===k&&y&&!A,{hasScrollableContent:ne,isNearBottom:ae}=u.default(z);o.useEffect((()=>()=>{R([])}),[]);const le=o.useCallback((()=>{if(!I||!D)return;const t=(o=0)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{const t=yield m.default.post("/get_pickaxe_conversation",{sessionId:w,userId:D});if(t.data&&t.data.success){const e=t.data.title;if(e&&"Conversation Title"!==e)return void ce(e)}else console.error("Failed to load conversation:",null===(e=t.data)||void 0===e?void 0:e.error)}catch(e){console.error("Error fetching conversation:",e)}o<20&&setTimeout((()=>t(o+1)),3e3)}));t()}),[I,D,w]);o.useEffect((()=>{G||y||!w||le()}),[G,y,w,le]),o.useEffect((()=>{if(!Y.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:o}=t.contentRect;O(parseInt(e.toFixed(0)),parseInt(o.toFixed(0)))}}));return e.observe(Y.current),()=>{e.disconnect()}}),[O]);const[ue,ce]=o.useState(ie),de=(null==_?void 0:_.formtitle)||"Pickaxe",fe=(null==_?void 0:_.coverphoto)||void 0,[he,me]=o.useState(!1);o.useEffect((()=>{const e=!re&&!P&&N.portalTheme&&(V.filter((e=>"user"===e.role)).length>0||K||!y);me(null!=e&&e)}),[re,P,K,y,V,N.portalTheme]);const pe=o.useCallback((()=>{z.current&&(L(!0),z.current.scrollTo({top:z.current.scrollHeight,behavior:"smooth"}))}),[z,L]);return t.jsxs("div",Object.assign({ref:Y,className:"relative flex h-full w-full flex-col items-center overflow-hidden",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),$.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&X(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),$.current-=1,0===$.current&&X(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){t.preventDefault(),t.stopPropagation(),X(!1),$.current=0;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(S(!1),yield H(e))}))},{children:[W&&t.jsxs("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[t.jsx("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:t.jsx(f.default,{className:"h-10 w-10"})})),t.jsx("h3",Object.assign({className:h.default(M.h3,"mt-6 font-semibold text-c-primary text-black")},{children:(null==T?void 0:T["drop-files-to-upload"])||"Drop files to upload"})),t.jsx("p",Object.assign({className:h.default(M.b2,"mt-2 opacity-60 text-black")},{children:(null==T?void 0:T["add-anything-to-the-conversation"])||"Add anything to the conversation"}))]})),re?t.jsx(d.default,{}):t.jsxs(t.Fragment,{children:[he&&t.jsxs("div",Object.assign({className:h.default("direct-link"===k?"absolute top-4 left-4 md:top-6 md:left-6 z-40 flex items-center gap-2 animate-in fade-in slide-in-from-top-4 duration-500":"w-full max-w-3xl mt-6 px-4 md:px-0 flex justify-start z-30 mb-4 animate-in fade-in slide-in-from-top-4 duration-500 gap-2","dark"===N.portalTheme?"glass-dark ":"")},{children:[t.jsx(g.NavPill,{text:de,icon:fe}),y||ue===ie?t.jsx(g.NavPill,{text:ue}):t.jsx(g.EditableNavPill,{text:ue,sessionId:w,onRename:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(w)try{yield m.default.post("/edit_conversation_name",{sessionId:w,name:t,userId:D}),ce(t)}catch(e){console.error("Error renaming chat:",e),alert((null==T?void 0:T["failed-rename-chat"])||"Failed to rename chat.")}})),onDelete:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(w&&window.confirm((null==T?void 0:T["delete-confirm"])||"Are you sure you want to delete this conversation?"))try{yield m.default.post("/delete_pickaxe_conversation",{sessionId:w,userId:D}),S(!0),C(p.v4()),ce(ie)}catch(e){console.error("Error deleting chat:",e),alert((null==T?void 0:T["failed-delete-chat"])||"Failed to delete chat.")}})),isDarkGlass:"dark"===N.portalTheme}),t.jsx(v.StudioTip,Object.assign({content:T["chat-history"]||"Chat History",align:"bottom",containerClassName:"inline-flex shrink-0"},{children:t.jsx(g.HistoryPill,{icon:t.jsx(b.default,{}),onClick:()=>{C(""),q(w)}})}))]})),t.jsx(c.default,{additionalScrollHeight:U,isForceHideInfo:E<=545||F<=350||K,isInputFocused:K,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){Z.current&&Z.current.onSubmit(t)})),smitheryAuthData:ee,resubmitPrompt:()=>{te(null),se(!0)}}),t.jsx(x.default,{isVisible:ne&&!B&&!ae,bottom:U+65,onClick:pe}),t.jsx(d.default,{ref:Z,onFocus:()=>Q(!0),onBlur:()=>Q(!1),onInputHeightChange:J,initSmitheryAuthData:e=>te(e),resubmitPrompt:oe})]})]}))};
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/useDimensionContext.js"),n=require("../Addons/Document/hooks/useDocument.js"),a=require("../Addons/Scroll/hooks/useScrollContext.js"),l=require("../../../hooks/studio/useStyleFontSize.js"),u=require("../../../hooks/core/useScrollToBottomVisibility.js"),c=require("./History/index.js"),d=require("./Input.js"),f=require("../../Icons/attach-vertical.svg.js"),h=require("../../../common/cn.js"),m=require("../../../common/api/pickaxe.js"),v=require("uuid"),p=require("../../Core/StudioTip.js"),x=require("../common/ScrollToBottomButton.js"),j=require("../../../hooks/pickaxe/useResponseContext.js"),g=require("../Addons/Navbar/NavPill.js"),b=require("../../Icons/history.svg.js");exports.default=()=>{var k,y;const{deploymentType:S,isNewChat:w,setIsNewChat:C,sessionId:q,setSessionId:I,setLastSessionId:D,pickaxeId:_,sender:N,pickaxe:P,styles:T,isEmbed:A,translations:F}=s.usePickaxeContext(),{isSent:E}=i.useAuthContext(),{width:O,height:R,setDimension:H}=r.useDimensionContext(),{setDocuments:z,onFileUpload:B}=n.useDocument(),{scrollContainerRef:L,isLocked:G,setIsLocked:V}=a.useScrollContext(),{isGenerating:M,messages:U}=j.useResponseContext(),W=l.useStyleFontSize(),[J,K]=o.useState(0),[Q,X]=o.useState(!1),[Y,Z]=o.useState(!1),$=o.useRef(null),ee=o.useRef(null),te=o.useRef(0),[oe,se]=o.useState(null),[ie,re]=o.useState(!1),ne=(null==F?void 0:F["new-chat"])||"New chat",ae="chat-input"===S&&w&&!E,le=null!==(y=null===(k=null==P?void 0:P.documentuploadtype)||void 0===k?void 0:k.startsWith("enduserupload"))&&void 0!==y&&y,{hasScrollableContent:ue,isNearBottom:ce}=u.default(L);o.useEffect((()=>()=>{z([])}),[]);const de=o.useCallback((()=>{if(!_||!N)return;const t=(o=0)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{const t=yield m.default.post("/get_pickaxe_conversation",{sessionId:q,userId:N});if(t.data&&t.data.success){const e=t.data.title;if(e&&"Conversation Title"!==e)return void he(e)}else console.error("Failed to load conversation:",null===(e=t.data)||void 0===e?void 0:e.error)}catch(e){console.error("Error fetching conversation:",e)}o<20&&setTimeout((()=>t(o+1)),3e3)}));t()}),[_,N,q]);o.useEffect((()=>{M||w||!q||de()}),[M,w,q,de]),o.useEffect((()=>{if(!$.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:o}=t.contentRect;H(parseInt(e.toFixed(0)),parseInt(o.toFixed(0)))}}));return e.observe($.current),()=>{e.disconnect()}}),[H]);const[fe,he]=o.useState(ne),me=(null==P?void 0:P.formtitle)||"Pickaxe",ve=(null==P?void 0:P.coverphoto)||void 0,[pe,xe]=o.useState(!1);o.useEffect((()=>{const e=!ae&&!A&&T.portalTheme&&(U.filter((e=>"user"===e.role)).length>0||Q||!w);xe(null!=e&&e)}),[ae,A,Q,w,U,T.portalTheme]);const je=o.useCallback((()=>{L.current&&(V(!0),L.current.scrollTo({top:L.current.scrollHeight,behavior:"smooth"}))}),[L,V]);return t.jsxs("div",Object.assign({ref:$,className:"relative flex h-full w-full flex-col items-center overflow-hidden",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),le&&(te.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&Z(!0))},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),le&&(te.current-=1,0===te.current&&Z(!1))},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(t.preventDefault(),t.stopPropagation(),Z(!1),te.current=0,!le)return;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(C(!1),yield B(e))}))},{children:[Y&&t.jsxs("div",Object.assign({className:"absolute inset-0 z-50 flex flex-col items-center justify-center rounded-lg bg-white/80 backdrop-blur-sm transition-all duration-300"},{children:[t.jsx("div",Object.assign({className:"flex h-24 w-24 items-center justify-center rounded-full bg-white shadow-lg animate-bounce text-black"},{children:t.jsx(f.default,{className:"h-10 w-10"})})),t.jsx("h3",Object.assign({className:h.default(W.h3,"mt-6 font-semibold text-c-primary text-black")},{children:(null==F?void 0:F["drop-files-to-upload"])||"Drop files to upload"})),t.jsx("p",Object.assign({className:h.default(W.b2,"mt-2 opacity-60 text-black")},{children:(null==F?void 0:F["add-anything-to-the-conversation"])||"Add anything to the conversation"}))]})),ae?t.jsx(d.default,{}):t.jsxs(t.Fragment,{children:[pe&&t.jsxs("div",Object.assign({className:h.default("direct-link"===S?"absolute top-4 left-4 md:top-6 md:left-6 z-40 flex items-center gap-2 animate-in fade-in slide-in-from-top-4 duration-500":"w-full max-w-3xl mt-6 px-4 md:px-0 flex justify-start z-30 mb-4 animate-in fade-in slide-in-from-top-4 duration-500 gap-2","dark"===T.portalTheme?"glass-dark ":"")},{children:[t.jsx(g.NavPill,{text:me,icon:ve}),w||fe===ne?t.jsx(g.NavPill,{text:fe}):t.jsx(g.EditableNavPill,{text:fe,sessionId:q,onRename:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(q)try{yield m.default.post("/edit_conversation_name",{sessionId:q,name:t,userId:N}),he(t)}catch(e){console.error("Error renaming chat:",e),alert((null==F?void 0:F["failed-rename-chat"])||"Failed to rename chat.")}})),onDelete:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(q&&window.confirm((null==F?void 0:F["delete-confirm"])||"Are you sure you want to delete this conversation?"))try{yield m.default.post("/delete_pickaxe_conversation",{sessionId:q,userId:N}),C(!0),I(v.v4()),he(ne)}catch(e){console.error("Error deleting chat:",e),alert((null==F?void 0:F["failed-delete-chat"])||"Failed to delete chat.")}})),isDarkGlass:"dark"===T.portalTheme}),t.jsx(p.StudioTip,Object.assign({content:F["chat-history"]||"Chat History",align:"bottom",containerClassName:"inline-flex shrink-0"},{children:t.jsx(g.HistoryPill,{icon:t.jsx(b.default,{}),onClick:()=>{I(""),D(q)}})}))]})),t.jsx(c.default,{additionalScrollHeight:J,isForceHideInfo:R<=545||O<=350||Q,isInputFocused:Q,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){ee.current&&ee.current.onSubmit(t)})),smitheryAuthData:oe,resubmitPrompt:()=>{se(null),re(!0)}}),t.jsx(x.default,{isVisible:ue&&!G&&!ce,bottom:J+65,onClick:je}),t.jsx(d.default,{ref:ee,onFocus:()=>X(!0),onBlur:()=>X(!1),onInputHeightChange:K,initSmitheryAuthData:e=>se(e),resubmitPrompt:ie})]})]}))};
@@ -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"),q=require("./Components/Action/index.js"),C=require("./Components/Artifact/index.js"),k=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,U={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":q.ActionCaption,"action-finished":q.ActionFinished,"action-error":q.ActionError,artifact:C.Artifact,"artifact-error":C.ArtifactError,think:k.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=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:U,remarkPlugins:[O.default,[$.default,{singleDollarTextMath:!1}]],rehypePlugins:[i.rehypeCode,P.default,...I?[]:[S.default],[i.rehypeSanitize,{disableJs:_,disableCss:N}]]},{children:G})),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("unist-util-visit");exports.rehypeCode=()=>r=>{e.visit(r,"code",(e=>{var r;e.lang=null!==(r=e.lang)&&void 0!==r?r:"plaintext"}))},exports.rehypeSanitize=(r={})=>t=>{e.visit(t,"element",((t,i,o)=>{if(r.disableJs){if("script"===t.tagName&&o&&"number"==typeof i)return o.children.splice(i,1),[e.SKIP,i];if(t.properties){["onclick","onload","onerror","onmouseover","onmouseout","onfocus","onblur"].forEach((e=>{t.properties[e]&&delete t.properties[e]})),t.properties.href&&"string"==typeof t.properties.href&&t.properties.href.toLowerCase().startsWith("javascript:")&&delete t.properties.href}}if(r.disableCss&&"style"===t.tagName&&o&&"number"==typeof i)return o.children.splice(i,1),[e.SKIP,i]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("unist-util-visit");const t=new Set(["blockquote","break","delete","footnoteDefinition","heading","html","list","listItem","paragraph","root","table","tableCell","tableRow","thematicBreak","yaml"]),r=new Set(["code","html","inlineCode","inlineMath","math","mdxFlowExpression","mdxJsxFlowElement","mdxJsxTextElement","mdxTextExpression"]),o=/[\s([{<]/,i=/[:;—–-]/,s=(e,l)=>{if(e.type&&r.has(e.type))return;if("text"===e.type&&"string"==typeof e.value)return void(e.value=((e,t)=>{let r="";for(let n=0;n<e.length;n+=1){const a=e[n];if('"'!==a)r+=a,t.previousChar=a;else{const a=(s=t.previousChar,l=e[n+1],!s||o.test(s)||l&&!/\s/.test(l)&&i.test(s)?"“":"”");r+=a,t.previousChar=a}}var s,l;return r})(e.value,l));if(!e.children)return;const n=e.type&&t.has(e.type)?{previousChar:""}:l;e.children.forEach((e=>{s(e,n)}))};exports.rehypeCode=()=>t=>{e.visit(t,"code",(e=>{var t;e.lang=null!==(t=e.lang)&&void 0!==t?t:"plaintext"}))},exports.rehypeSanitize=(t={})=>r=>{e.visit(r,"element",((r,o,i)=>{if(t.disableJs){if("script"===r.tagName&&i&&"number"==typeof o)return i.children.splice(o,1),[e.SKIP,o];if(r.properties){["onclick","onload","onerror","onmouseover","onmouseout","onfocus","onblur"].forEach((e=>{r.properties[e]&&delete r.properties[e]})),r.properties.href&&"string"==typeof r.properties.href&&r.properties.href.toLowerCase().startsWith("javascript:")&&delete r.properties.href}}if(t.disableCss&&"style"===r.tagName&&i&&"number"==typeof o)return i.children.splice(o,1),[e.SKIP,o]}))},exports.remarkSmartQuotes=()=>e=>{s(e,{previousChar:""})};
@@ -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 t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base2.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("../../../../../_virtual/_commonjsHelpers.js"),r=require("../../../../../_virtual/cose-base.js"),i=require("../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js");r.__module.exports,exports.__require=function(){return t||(t=1,o=r.__module,r.__module.exports,e.commonjsGlobal,n=function(t){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(e,r){e.exports=t},function(t,e,r){var i=r(0).FDLayoutConstants;function o(){}for(var n in i)o[n]=i[n];o.DEFAULT_USE_MULTI_LEVEL_SCALING=!1,o.DEFAULT_RADIAL_SEPARATION=i.DEFAULT_EDGE_LENGTH,o.DEFAULT_COMPONENT_SEPERATION=60,o.TILE=!0,o.TILING_PADDING_VERTICAL=10,o.TILING_PADDING_HORIZONTAL=10,o.TREE_REDUCTION_ON_INCREMENTAL=!1,t.exports=o},function(t,e,r){var i=r(0).FDLayoutEdge;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraph;function o(t,e,r){i.call(this,t,e,r)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).LGraphManager;function o(t){i.call(this,t)}for(var n in o.prototype=Object.create(i.prototype),i)o[n]=i[n];t.exports=o},function(t,e,r){var i=r(0).FDLayoutNode,o=r(0).IMath;function n(t,e,r,o){i.call(this,t,e,r,o)}for(var a in n.prototype=Object.create(i.prototype),i)n[a]=i[a];n.prototype.move=function(){var t=this.graphManager.getLayout();this.displacementX=t.coolingFactor*(this.springForceX+this.repulsionForceX+this.gravitationForceX)/this.noOfChildren,this.displacementY=t.coolingFactor*(this.springForceY+this.repulsionForceY+this.gravitationForceY)/this.noOfChildren,Math.abs(this.displacementX)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementX=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementX)),Math.abs(this.displacementY)>t.coolingFactor*t.maxNodeDisplacement&&(this.displacementY=t.coolingFactor*t.maxNodeDisplacement*o.sign(this.displacementY)),null==this.child||0==this.child.getNodes().length?this.moveBy(this.displacementX,this.displacementY):this.propogateDisplacementToChildren(this.displacementX,this.displacementY),t.totalDisplacement+=Math.abs(this.displacementX)+Math.abs(this.displacementY),this.springForceX=0,this.springForceY=0,this.repulsionForceX=0,this.repulsionForceY=0,this.gravitationForceX=0,this.gravitationForceY=0,this.displacementX=0,this.displacementY=0},n.prototype.propogateDisplacementToChildren=function(t,e){for(var r,i=this.getChild().getNodes(),o=0;o<i.length;o++)null==(r=i[o]).getChild()?(r.moveBy(t,e),r.displacementX+=t,r.displacementY+=e):r.propogateDisplacementToChildren(t,e)},n.prototype.setPred1=function(t){this.pred1=t},n.prototype.getPred1=function(){return pred1},n.prototype.getPred2=function(){return pred2},n.prototype.setNext=function(t){this.next=t},n.prototype.getNext=function(){return next},n.prototype.setProcessed=function(t){this.processed=t},n.prototype.isProcessed=function(){return processed},t.exports=n},function(t,e,r){var i=r(0).FDLayout,o=r(4),n=r(3),a=r(5),s=r(2),h=r(1),d=r(0).FDLayoutConstants,g=r(0).LayoutConstants,l=r(0).Point,p=r(0).PointD,c=r(0).Layout,u=r(0).Integer,f=r(0).IGeometry,v=r(0).LGraph,T=r(0).Transform;function E(){i.call(this),this.toBeTiled={}}for(var m in E.prototype=Object.create(i.prototype),i)E[m]=i[m];E.prototype.newGraphManager=function(){var t=new o(this);return this.graphManager=t,t},E.prototype.newGraph=function(t){return new n(null,this.graphManager,t)},E.prototype.newNode=function(t){return new a(this.graphManager,t)},E.prototype.newEdge=function(t){return new s(null,null,t)},E.prototype.initParameters=function(){i.prototype.initParameters.call(this,arguments),this.isSubLayout||(h.DEFAULT_EDGE_LENGTH<10?this.idealEdgeLength=10:this.idealEdgeLength=h.DEFAULT_EDGE_LENGTH,this.useSmartIdealEdgeLengthCalculation=h.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION,this.springConstant=d.DEFAULT_SPRING_STRENGTH,this.repulsionConstant=d.DEFAULT_REPULSION_STRENGTH,this.gravityConstant=d.DEFAULT_GRAVITY_STRENGTH,this.compoundGravityConstant=d.DEFAULT_COMPOUND_GRAVITY_STRENGTH,this.gravityRangeFactor=d.DEFAULT_GRAVITY_RANGE_FACTOR,this.compoundGravityRangeFactor=d.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR,this.prunedNodesAll=[],this.growTreeIterations=0,this.afterGrowthIterations=0,this.isTreeGrowing=!1,this.isGrowthFinished=!1,this.coolingCycle=0,this.maxCoolingCycle=this.maxIterations/d.CONVERGENCE_CHECK_PERIOD,this.finalTemperature=d.CONVERGENCE_CHECK_PERIOD/this.maxIterations,this.coolingAdjuster=1)},E.prototype.layout=function(){return g.DEFAULT_CREATE_BENDS_AS_NEEDED&&(this.createBendpoints(),this.graphManager.resetAllEdges()),this.level=0,this.classicLayout()},E.prototype.classicLayout=function(){if(this.nodesWithGravity=this.calculateNodesToApplyGravitationTo(),this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity),this.calcNoOfChildrenForAllNodes(),this.graphManager.calcLowestCommonAncestors(),this.graphManager.calcInclusionTreeDepths(),this.graphManager.getRoot().calcEstimatedSize(),this.calcIdealEdgeLengths(),this.incremental)h.TREE_REDUCTION_ON_INCREMENTAL&&(this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation(),e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)})),this.graphManager.setAllNodesToApplyGravitation(r));else{var t=this.getFlatForest();if(t.length>0)this.positionNodesRadially(t);else{this.reduceTrees(),this.graphManager.resetAllNodesToApplyGravitation();var e=new Set(this.getAllNodes()),r=this.nodesWithGravity.filter((function(t){return e.has(t)}));this.graphManager.setAllNodesToApplyGravitation(r),this.positionNodesRandomly()}}return this.initSpringEmbedder(),this.runSpringEmbedder(),!0},E.prototype.tick=function(){if(this.totalIterations++,this.totalIterations===this.maxIterations&&!this.isTreeGrowing&&!this.isGrowthFinished){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}if(this.totalIterations%d.CONVERGENCE_CHECK_PERIOD==0&&!this.isTreeGrowing&&!this.isGrowthFinished){if(this.isConverged()){if(!(this.prunedNodesAll.length>0))return!0;this.isTreeGrowing=!0}this.coolingCycle++,0==this.layoutQuality?this.coolingAdjuster=this.coolingCycle:1==this.layoutQuality&&(this.coolingAdjuster=this.coolingCycle/3),this.coolingFactor=Math.max(this.initialCoolingFactor-Math.pow(this.coolingCycle,Math.log(100*(this.initialCoolingFactor-this.finalTemperature))/Math.log(this.maxCoolingCycle))/100*this.coolingAdjuster,this.finalTemperature),this.animationPeriod=Math.ceil(this.initialAnimationPeriod*Math.sqrt(this.coolingFactor))}if(this.isTreeGrowing){if(this.growTreeIterations%10==0)if(this.prunedNodesAll.length>0){this.graphManager.updateBounds(),this.updateGrid(),this.growTree(this.prunedNodesAll),this.graphManager.resetAllNodesToApplyGravitation();var t=new Set(this.getAllNodes()),e=this.nodesWithGravity.filter((function(e){return t.has(e)}));this.graphManager.setAllNodesToApplyGravitation(e),this.graphManager.updateBounds(),this.updateGrid(),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL}else this.isTreeGrowing=!1,this.isGrowthFinished=!0;this.growTreeIterations++}if(this.isGrowthFinished){if(this.isConverged())return!0;this.afterGrowthIterations%10==0&&(this.graphManager.updateBounds(),this.updateGrid()),this.coolingFactor=d.DEFAULT_COOLING_FACTOR_INCREMENTAL*((100-this.afterGrowthIterations)/100),this.afterGrowthIterations++}var r=!this.isTreeGrowing&&!this.isGrowthFinished,i=this.growTreeIterations%10==1&&this.isTreeGrowing||this.afterGrowthIterations%10==1&&this.isGrowthFinished;return this.totalDisplacement=0,this.graphManager.updateBounds(),this.calcSpringForces(),this.calcRepulsionForces(r,i),this.calcGravitationalForces(),this.moveNodes(),this.animate(),!1},E.prototype.getPositionsData=function(){for(var t=this.graphManager.getAllNodes(),e={},r=0;r<t.length;r++){var i=t[r].rect,o=t[r].id;e[o]={id:o,x:i.getCenterX(),y:i.getCenterY(),w:i.width,h:i.height}}return e},E.prototype.runSpringEmbedder=function(){this.initialAnimationPeriod=25,this.animationPeriod=this.initialAnimationPeriod;var t=!1;if("during"===d.ANIMATE)this.emit("layoutstarted");else{for(;!t;)t=this.tick();this.graphManager.updateBounds()}},E.prototype.calculateNodesToApplyGravitationTo=function(){var t,e,r=[],i=this.graphManager.getGraphs(),o=i.length;for(e=0;e<o;e++)(t=i[e]).updateConnected(),t.isConnected||(r=r.concat(t.getNodes()));return r},E.prototype.createBendpoints=function(){var t=[];t=t.concat(this.graphManager.getAllEdges());var e,r=new Set;for(e=0;e<t.length;e++){var i=t[e];if(!r.has(i)){var o=i.getSource(),n=i.getTarget();if(o==n)i.getBendpoints().push(new p),i.getBendpoints().push(new p),this.createDummyNodesForBendpoints(i),r.add(i);else{var a=[];if(a=(a=a.concat(o.getEdgeListToNode(n))).concat(n.getEdgeListToNode(o)),!r.has(a[0])){var s;if(a.length>1)for(s=0;s<a.length;s++){var h=a[s];h.getBendpoints().push(new p),this.createDummyNodesForBendpoints(h)}a.forEach((function(t){r.add(t)}))}}}if(r.size==t.length)break}},E.prototype.positionNodesRadially=function(t){for(var e=new l(0,0),r=Math.ceil(Math.sqrt(t.length)),i=0,o=0,n=0,a=new p(0,0),s=0;s<t.length;s++){s%r==0&&(n=0,o=i,0!=s&&(o+=h.DEFAULT_COMPONENT_SEPERATION),i=0);var d=t[s],u=c.findCenterOfTree(d);e.x=n,e.y=o,(a=E.radialLayout(d,u,e)).y>i&&(i=Math.floor(a.y)),n=Math.floor(a.x+h.DEFAULT_COMPONENT_SEPERATION)}this.transform(new p(g.WORLD_CENTER_X-a.x/2,g.WORLD_CENTER_Y-a.y/2))},E.radialLayout=function(t,e,r){var i=Math.max(this.maxDiagonalInTree(t),h.DEFAULT_RADIAL_SEPARATION);E.branchRadialLayout(e,null,0,359,0,i);var o=v.calculateBounds(t),n=new T;n.setDeviceOrgX(o.getMinX()),n.setDeviceOrgY(o.getMinY()),n.setWorldOrgX(r.x),n.setWorldOrgY(r.y);for(var a=0;a<t.length;a++)t[a].transform(n);var s=new p(o.getMaxX(),o.getMaxY());return n.inverseTransformPoint(s)},E.branchRadialLayout=function(t,e,r,i,o,n){var a=(i-r+1)/2;a<0&&(a+=180);var s=(a+r)%360*f.TWO_PI/360,h=o*Math.cos(s),d=o*Math.sin(s);t.setCenter(h,d);var g=[],l=(g=g.concat(t.getEdges())).length;null!=e&&l--;for(var p,c=0,u=g.length,v=t.getEdgesBetween(e);v.length>1;){var T=v[0];v.splice(0,1);var m=g.indexOf(T);m>=0&&g.splice(m,1),u--,l--}p=null!=e?(g.indexOf(v[0])+1)%u:0;for(var y=Math.abs(i-r)/l,N=p;c!=l;N=++N%u){var w=g[N].getOtherEnd(t);if(w!=e){var A=(r+c*y)%360,C=(A+y)%360;E.branchRadialLayout(w,t,A,C,o+n,n),c++}}},E.maxDiagonalInTree=function(t){for(var e=u.MIN_VALUE,r=0;r<t.length;r++){var i=t[r].getDiagonal();i>e&&(e=i)}return e},E.prototype.calcRepulsionRange=function(){return 2*(this.level+1)*this.idealEdgeLength},E.prototype.groupZeroDegreeMembers=function(){var t=this,e={};this.memberGroups={},this.idToDummyNode={};for(var r=[],i=this.graphManager.getAllNodes(),o=0;o<i.length;o++){var n=(s=i[o]).getParent();0!==this.getNodeDegreeWithChildren(s)||null!=n.id&&this.getToBeTiled(n)||r.push(s)}for(o=0;o<r.length;o++){var s,h=(s=r[o]).getParent().id;void 0===e[h]&&(e[h]=[]),e[h]=e[h].concat(s)}Object.keys(e).forEach((function(r){if(e[r].length>1){var i="DummyCompound_"+r;t.memberGroups[i]=e[r];var o=e[r][0].getParent(),n=new a(t.graphManager);n.id=i,n.paddingLeft=o.paddingLeft||0,n.paddingRight=o.paddingRight||0,n.paddingBottom=o.paddingBottom||0,n.paddingTop=o.paddingTop||0,t.idToDummyNode[i]=n;var s=t.getGraphManager().add(t.newGraph(),n),h=o.getChild();h.add(n);for(var d=0;d<e[r].length;d++){var g=e[r][d];h.remove(g),s.add(g)}}}))},E.prototype.clearCompounds=function(){var t={},e={};this.performDFSOnCompounds();for(var r=0;r<this.compoundOrder.length;r++)e[this.compoundOrder[r].id]=this.compoundOrder[r],t[this.compoundOrder[r].id]=[].concat(this.compoundOrder[r].getChild().getNodes()),this.graphManager.remove(this.compoundOrder[r].getChild()),this.compoundOrder[r].child=null;this.graphManager.resetAllNodes(),this.tileCompoundMembers(t,e)},E.prototype.clearZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack=[];Object.keys(this.memberGroups).forEach((function(r){var i=t.idToDummyNode[r];e[r]=t.tileNodes(t.memberGroups[r],i.paddingLeft+i.paddingRight),i.rect.width=e[r].width,i.rect.height=e[r].height}))},E.prototype.repopulateCompounds=function(){for(var t=this.compoundOrder.length-1;t>=0;t--){var e=this.compoundOrder[t],r=e.id,i=e.paddingLeft,o=e.paddingTop;this.adjustLocations(this.tiledMemberPack[r],e.rect.x,e.rect.y,i,o)}},E.prototype.repopulateZeroDegreeMembers=function(){var t=this,e=this.tiledZeroDegreePack;Object.keys(e).forEach((function(r){var i=t.idToDummyNode[r],o=i.paddingLeft,n=i.paddingTop;t.adjustLocations(e[r],i.rect.x,i.rect.y,o,n)}))},E.prototype.getToBeTiled=function(t){var e=t.id;if(null!=this.toBeTiled[e])return this.toBeTiled[e];var r=t.getChild();if(null==r)return this.toBeTiled[e]=!1,!1;for(var i=r.getNodes(),o=0;o<i.length;o++){var n=i[o];if(this.getNodeDegree(n)>0)return this.toBeTiled[e]=!1,!1;if(null!=n.getChild()){if(!this.getToBeTiled(n))return this.toBeTiled[e]=!1,!1}else this.toBeTiled[n.id]=!1}return this.toBeTiled[e]=!0,!0},E.prototype.getNodeDegree=function(t){t.id;for(var e=t.getEdges(),r=0,i=0;i<e.length;i++){var o=e[i];o.getSource().id!==o.getTarget().id&&(r+=1)}return r},E.prototype.getNodeDegreeWithChildren=function(t){var e=this.getNodeDegree(t);if(null==t.getChild())return e;for(var r=t.getChild().getNodes(),i=0;i<r.length;i++){var o=r[i];e+=this.getNodeDegreeWithChildren(o)}return e},E.prototype.performDFSOnCompounds=function(){this.compoundOrder=[],this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes())},E.prototype.fillCompexOrderByDFS=function(t){for(var e=0;e<t.length;e++){var r=t[e];null!=r.getChild()&&this.fillCompexOrderByDFS(r.getChild().getNodes()),this.getToBeTiled(r)&&this.compoundOrder.push(r)}},E.prototype.adjustLocations=function(t,e,r,i,o){r+=o;for(var n=e+=i,a=0;a<t.rows.length;a++){var s=t.rows[a];e=n;for(var h=0,d=0;d<s.length;d++){var g=s[d];g.rect.x=e,g.rect.y=r,e+=g.rect.width+t.horizontalPadding,g.rect.height>h&&(h=g.rect.height)}r+=h+t.verticalPadding}},E.prototype.tileCompoundMembers=function(t,e){var r=this;this.tiledMemberPack=[],Object.keys(t).forEach((function(i){var o=e[i];r.tiledMemberPack[i]=r.tileNodes(t[i],o.paddingLeft+o.paddingRight),o.rect.width=r.tiledMemberPack[i].width,o.rect.height=r.tiledMemberPack[i].height}))},E.prototype.tileNodes=function(t,e){var r={rows:[],rowWidth:[],rowHeight:[],width:0,height:e,verticalPadding:h.TILING_PADDING_VERTICAL,horizontalPadding:h.TILING_PADDING_HORIZONTAL};t.sort((function(t,e){return t.rect.width*t.rect.height>e.rect.width*e.rect.height?-1:t.rect.width*t.rect.height<e.rect.width*e.rect.height?1:0}));for(var i=0;i<t.length;i++){var o=t[i];0==r.rows.length?this.insertNodeToRow(r,o,0,e):this.canAddHorizontal(r,o.rect.width,o.rect.height)?this.insertNodeToRow(r,o,this.getShortestRowIndex(r),e):this.insertNodeToRow(r,o,r.rows.length,e),this.shiftToLastRow(r)}return r},E.prototype.insertNodeToRow=function(t,e,r,i){var o=i;r==t.rows.length&&(t.rows.push([]),t.rowWidth.push(o),t.rowHeight.push(0));var n=t.rowWidth[r]+e.rect.width;t.rows[r].length>0&&(n+=t.horizontalPadding),t.rowWidth[r]=n,t.width<n&&(t.width=n);var a=e.rect.height;r>0&&(a+=t.verticalPadding);var s=0;a>t.rowHeight[r]&&(s=t.rowHeight[r],t.rowHeight[r]=a,s=t.rowHeight[r]-s),t.height+=s,t.rows[r].push(e)},E.prototype.getShortestRowIndex=function(t){for(var e=-1,r=Number.MAX_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]<r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.getLongestRowIndex=function(t){for(var e=-1,r=Number.MIN_VALUE,i=0;i<t.rows.length;i++)t.rowWidth[i]>r&&(e=i,r=t.rowWidth[i]);return e},E.prototype.canAddHorizontal=function(t,e,r){var i=this.getShortestRowIndex(t);if(i<0)return!0;var o=t.rowWidth[i];if(o+t.horizontalPadding+e<=t.width)return!0;var n,a,s=0;return t.rowHeight[i]<r&&i>0&&(s=r+t.verticalPadding-t.rowHeight[i]),n=t.width-o>=e+t.horizontalPadding?(t.height+s)/(o+e+t.horizontalPadding):(t.height+s)/t.width,s=r+t.verticalPadding,(a=t.width<e?(t.height+s)/e:(t.height+s)/t.width)<1&&(a=1/a),n<1&&(n=1/n),n<a},E.prototype.shiftToLastRow=function(t){var e=this.getLongestRowIndex(t),r=t.rowWidth.length-1,i=t.rows[e],o=i[i.length-1],n=o.width+t.horizontalPadding;if(t.width-t.rowWidth[r]>n&&e!=r){i.splice(-1,1),t.rows[r].push(o),t.rowWidth[e]=t.rowWidth[e]-n,t.rowWidth[r]=t.rowWidth[r]+n,t.width=t.rowWidth[instance.getLongestRowIndex(t)];for(var a=Number.MIN_VALUE,s=0;s<i.length;s++)i[s].height>a&&(a=i[s].height);e>0&&(a+=t.verticalPadding);var h=t.rowHeight[e]+t.rowHeight[r];t.rowHeight[e]=a,t.rowHeight[r]<o.height+t.verticalPadding&&(t.rowHeight[r]=o.height+t.verticalPadding);var d=t.rowHeight[e]+t.rowHeight[r];t.height+=d-h,this.shiftToLastRow(t)}},E.prototype.tilingPreLayout=function(){h.TILE&&(this.groupZeroDegreeMembers(),this.clearCompounds(),this.clearZeroDegreeMembers())},E.prototype.tilingPostLayout=function(){h.TILE&&(this.repopulateZeroDegreeMembers(),this.repopulateCompounds())},E.prototype.reduceTrees=function(){for(var t,e=[],r=!0;r;){var i=this.graphManager.getAllNodes(),o=[];r=!1;for(var n=0;n<i.length;n++)1!=(t=i[n]).getEdges().length||t.getEdges()[0].isInterGraph||null!=t.getChild()||(o.push([t,t.getEdges()[0],t.getOwner()]),r=!0);if(1==r){for(var a=[],s=0;s<o.length;s++)1==o[s][0].getEdges().length&&(a.push(o[s]),o[s][0].getOwner().remove(o[s][0]));e.push(a),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()}}this.prunedNodesAll=e},E.prototype.growTree=function(t){for(var e,r=t[t.length-1],i=0;i<r.length;i++)e=r[i],this.findPlaceforPrunedNode(e),e[2].add(e[0]),e[2].add(e[1],e[1].source,e[1].target);t.splice(t.length-1,1),this.graphManager.resetAllNodes(),this.graphManager.resetAllEdges()},E.prototype.findPlaceforPrunedNode=function(t){var e,r,i=t[0],o=(r=i==t[1].source?t[1].target:t[1].source).startX,n=r.finishX,a=r.startY,s=r.finishY,h=[0,0,0,0];if(a>0)for(var g=o;g<=n;g++)h[0]+=this.grid[g][a-1].length+this.grid[g][a].length-1;if(n<this.grid.length-1)for(g=a;g<=s;g++)h[1]+=this.grid[n+1][g].length+this.grid[n][g].length-1;if(s<this.grid[0].length-1)for(g=o;g<=n;g++)h[2]+=this.grid[g][s+1].length+this.grid[g][s].length-1;if(o>0)for(g=a;g<=s;g++)h[3]+=this.grid[o-1][g].length+this.grid[o][g].length-1;for(var l,p,c=u.MAX_VALUE,f=0;f<h.length;f++)h[f]<c?(c=h[f],l=1,p=f):h[f]==c&&l++;if(3==l&&0==c)0==h[0]&&0==h[1]&&0==h[2]?e=1:0==h[0]&&0==h[1]&&0==h[3]?e=0:0==h[0]&&0==h[2]&&0==h[3]?e=3:0==h[1]&&0==h[2]&&0==h[3]&&(e=2);else if(2==l&&0==c){var v=Math.floor(2*Math.random());e=0==h[0]&&0==h[1]?0==v?0:1:0==h[0]&&0==h[2]?0==v?0:2:0==h[0]&&0==h[3]?0==v?0:3:0==h[1]&&0==h[2]?0==v?1:2:0==h[1]&&0==h[3]?0==v?1:3:0==v?2:3}else e=4==l&&0==c?v=Math.floor(4*Math.random()):p;0==e?i.setCenter(r.getCenterX(),r.getCenterY()-r.getHeight()/2-d.DEFAULT_EDGE_LENGTH-i.getHeight()/2):1==e?i.setCenter(r.getCenterX()+r.getWidth()/2+d.DEFAULT_EDGE_LENGTH+i.getWidth()/2,r.getCenterY()):2==e?i.setCenter(r.getCenterX(),r.getCenterY()+r.getHeight()/2+d.DEFAULT_EDGE_LENGTH+i.getHeight()/2):i.setCenter(r.getCenterX()-r.getWidth()/2-d.DEFAULT_EDGE_LENGTH-i.getWidth()/2,r.getCenterY())},t.exports=E},function(t,e,r){var i={};i.layoutBase=r(0),i.CoSEConstants=r(1),i.CoSEEdge=r(2),i.CoSEGraph=r(3),i.CoSEGraphManager=r(4),i.CoSELayout=r(6),i.CoSENode=r(5),t.exports=i}])},o.exports=n(i.__require())),r.__module.exports;var o,n};