@pickaxeproject/react 6.24.4 → 6.24.6
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.
- package/dist/cjs/common/speechTranscript.js +1 -0
- package/dist/cjs/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/cjs/components/Pickaxe/Addons/Artifact/index.js +1 -1
- package/dist/cjs/components/Pickaxe/Addons/Scroll/Provider.js +1 -1
- package/dist/cjs/components/Pickaxe/Addons/Scroll/hooks/useScroll.js +1 -1
- package/dist/cjs/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/cjs/components/Pickaxe/Chat/index.js +1 -1
- package/dist/cjs/hooks/pickaxe/useSpeechToText.js +1 -1
- package/dist/cjs/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/cjs/src/common/speechTranscript.d.ts +20 -0
- package/dist/cjs/src/components/Pickaxe/Addons/Artifact/Renderer/index.d.ts +1 -1
- package/dist/cjs/src/components/Pickaxe/Addons/Scroll/Provider.d.ts +3 -0
- package/dist/cjs/src/components/Pickaxe/Addons/Scroll/hooks/useScroll.d.ts +2 -1
- package/dist/cjs/src/components/Pickaxe/Addons/Scroll/hooks/useScrollContext.d.ts +4 -0
- package/dist/cjs/src/hooks/pickaxe/useSpeechToText.d.ts +5 -0
- package/dist/esm/common/speechTranscript.js +1 -0
- package/dist/esm/components/Pickaxe/Addons/Artifact/Renderer/index.js +1 -1
- package/dist/esm/components/Pickaxe/Addons/Artifact/index.js +1 -1
- package/dist/esm/components/Pickaxe/Addons/Scroll/Provider.js +1 -1
- package/dist/esm/components/Pickaxe/Addons/Scroll/hooks/useScroll.js +1 -1
- package/dist/esm/components/Pickaxe/Chat/Input.js +1 -1
- package/dist/esm/components/Pickaxe/Chat/index.js +1 -1
- package/dist/esm/hooks/pickaxe/useSpeechToText.js +1 -1
- package/dist/esm/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
- package/dist/esm/src/common/speechTranscript.d.ts +20 -0
- package/dist/esm/src/components/Pickaxe/Addons/Artifact/Renderer/index.d.ts +1 -1
- package/dist/esm/src/components/Pickaxe/Addons/Scroll/Provider.d.ts +3 -0
- package/dist/esm/src/components/Pickaxe/Addons/Scroll/hooks/useScroll.d.ts +2 -1
- package/dist/esm/src/components/Pickaxe/Addons/Scroll/hooks/useScrollContext.d.ts +4 -0
- package/dist/esm/src/hooks/pickaxe/useSpeechToText.d.ts +5 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>t.normalize("NFKC").toLocaleLowerCase().replace(/[^\p{L}\p{N}]/gu,""),e=t=>t.replace(/^[^\p{L}\p{N}]+/u,"").trim(),r=e=>{var r;const n=t(e.text);if(!n)return[];let o="";const l=[];for(const i of null!==(r=e.words)&&void 0!==r?r:[]){if(o+=t(i.text),!n.startsWith(o))return[];if(l.push(i),o===n)return l}return[]},n=(n,o)=>{var l,i,s;if(!(null==o?void 0:o.text))return n.text;const u=t(o.text),f=t(n.text);if(!u)return"";if(f.startsWith(u)){let r=0;for(const o of n.text.matchAll(/[\p{L}\p{N}]/gu))if(r+=t(o[0]).length,r>=u.length)return e(n.text.slice((null!==(l=o.index)&&void 0!==l?l:0)+o[0].length));return""}const c=o.text.split(/\s+/).map(t).filter(Boolean),x=Array.from(n.text.matchAll(/\S+/gu));let a=0,p=0;for(const e of c){for(;a<x.length&&t(x[a][0])!==e;)a+=1;if(a===x.length){p=0;break}const r=x[a++];p=(null!==(i=r.index)&&void 0!==i?i:0)+r[0].length}if(p)return e(n.text.slice(p));if(void 0!==o.cutoff&&(null===(s=n.words)||void 0===s?void 0:s.length)){const t=o.cutoff;return r(n).filter((e=>e.start>=t)).map((t=>t.text)).join(" ").trim()}return""};exports.consumeSpeechTurn=(t,e)=>{if(e&&!n(t,e))return e;const o={text:t.text},l=r(t),i=l[l.length-1];return i&&Number.isFinite(i.end)&&(o.cutoff=i.end),o},exports.getUnconsumedSpeech=n;
|
|
@@ -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"),n=require("../hooks/useArtifactContext.js"),a=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Auth/hooks/useAuthContext.js"),r=require("../../Scroll/hooks/useScroll.js"),l=require("../hooks/useArtifact.js"),s=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),c=require("react-to-print"),d=require("../../../common/PickaxeMarkdown/index.js"),p=require("../../../common/PickaxeMarkdown/Renderer.js"),u=require("react-syntax-highlighter"),m=require("../../../../../common/docx/index.js"),x=require("file-saver"),y=require("../../Scroll/ScrollLockView.js"),v=require("../../../../Icons/expand.svg.js"),f=require("../../../../Icons/shrink.svg.js"),g=require("../../../../Icons/collapse-new.svg.js"),h=require("../../../../Icons/copy-new.svg.js"),b=require("../../../../Icons/download-new.svg.js"),w=require("../../../common/PickaxeCopyButton.js"),j=require("../../../../Core/ScrollArea.js"),k=require("../../../../Core/TipContainer.js"),C=require("../MermaidRenderer.js"),T=require("./SaveMenu.js"),S=require("./ViewOptions.js"),F=require("csv-to-markdown-table"),O=require("copy-to-clipboard"),A=require("../../../../../common/cn.js"),D=require("../../../../../common/error.js");function q(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var E=q(x),N=q(F),B=q(O);const M="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",_=e=>{var t;const o=null==e?void 0:e.trim().toLowerCase();if(!o)return".txt";return null!==(t={javascript:".js",js:".js",typescript:".ts",ts:".ts",python:".py",py:".py",json:".json",html:".html",css:".css",markdown:".md",md:".md",sql:".sql",shell:".sh",bash:".sh",sh:".sh",yaml:".yaml",yml:".yml",xml:".xml"}[o])&&void 0!==t?t:`.${o}`};exports.default=x=>{var F,O,q,P;const{artifacts:$,currentPopupType:R,currentArtifact:z,setCurrentArtifact:L}=n.useArtifactContext(),{onLoadArtifact:I}=l.useArtifact(),{contextId:W,pickaxeId:H,pickaxe:K,styles:V,colors:X,translations:U}=a.usePickaxeContext(),{isLoggedIn:G,token:J}=i.useAuthContext(),Q=s.useSubmitDocument(),[Y,Z]=o.useState("code"),[ee,te]=o.useState(!1),[oe,ne]=o.useState(!1),[ae,ie]=o.useState(!1),re=o.useRef(),le=o.useRef(null),se=o.useRef(null),ce=c.useReactToPrint({contentRef:re}),{scrollContainerRef:de,scrollStartSession:pe,scrollToBottom:ue,scrollEndSession:me}=r.useScroll({auto:"code"===Y}),xe=null!==(O=null===(F=x.styling)||void 0===F?void 0:F.styles)&&void 0!==O?O:V,ye=null!==(P=null===(q=x.styling)||void 0===q?void 0:q.colors)&&void 0!==P?P:X,ve=o.useMemo((()=>{var e,t,o,n,a;if(!x.artifact&&!z)return null;const i=null!==(t=null===(e=x.artifact)||void 0===e?void 0:e.id)&&void 0!==t?t:null==z?void 0:z.id,r=null!==(n=null===(o=x.artifact)||void 0===o?void 0:o.version)&&void 0!==n?n:null==z?void 0:z.version;return null!==(a=$.find((e=>e.id===i&&e.version===r)))&&void 0!==a?a:null}),[z,$,x.artifact]),fe=o.useMemo((()=>ve?"text/csv"===ve.type?N.default(ve.content,",",!0):"text/tab-separated-values"===ve.type?N.default(ve.content,"\t",!0):null:null),[ve]),ge=o.useMemo((()=>(ye.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==ye?void 0:ye.secondaryText]),he=o.useMemo((()=>{const e=x.artifact&&(null==z?void 0:z.id)===x.artifact.id&&(null==z?void 0:z.version)===x.artifact.version;return"inline"===x.type&&("inline-form"===R?!!z:e)}),[z,R,x.type,x.artifact]),be=o.useMemo((()=>ve?(e=>{switch(e.type){case"text/markdown":return{extension:".md",mimeType:"text/markdown",content:e.content};case"text/html":return{extension:".html",mimeType:"text/html",content:e.content};case"text/csv":return{extension:".csv",mimeType:"text/csv",content:e.content};case"text/tab-separated-values":return{extension:".tsv",mimeType:"text/tab-separated-values",content:e.content};case"image/svg+xml":return{extension:".svg",mimeType:"image/svg+xml",content:e.content};case"application/pdf":return e.content.trimStart().startsWith("%PDF")?{extension:".pdf",mimeType:"application/pdf",content:e.content}:{extension:".html",mimeType:"text/html",content:e.content};case"application/vnd.pxe.code":return{extension:_(e.programmingLanguage),mimeType:"text/plain",content:e.content};case"application/vnd.pxe.mermaid":return{extension:".mmd",mimeType:"text/plain",content:e.content};case"application/vnd.pxe.react":return{extension:".tsx",mimeType:"text/typescript",content:e.content};default:return null}})(ve):null),[ve]);o.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===x.type&&x.artifact&&($.some((e=>x.artifact&&e.id===x.artifact.id&&e.version===x.artifact.version))||I({id:x.artifact.id,version:x.artifact.version}))}))}),[$,x.type,x.artifact]),o.useEffect((()=>{if("application/vnd.pxe.code"===(null==ve?void 0:ve.type)&&Z("code"),"finished"!==(null==ve?void 0:ve.status))return Z("code"),pe(),void ue();me(),"application/vnd.pxe.code"!==ve.type&&Z("render")}),[null==ve?void 0:ve.status,null==ve?void 0:ve.type]),o.useEffect((()=>{var e;!se.current||"text/html"!==(null==ve?void 0:ve.type)&&"application/pdf"!==(null==ve?void 0:ve.type)&&"application/vnd.pxe.react"!==(null==ve?void 0:ve.type)||null===(e=se.current.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},M)}),[null==ve?void 0:ve.content,null==ve?void 0:ve.type]);const we=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;if("text/html"===ve.type||"application/pdf"===ve.type){const e=ve.content,t=window.open("","_blank");return void(t&&(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.print()))}const e=Y;"code"===e&&(Z("render"),yield new Promise((e=>setTimeout(e,50)))),ce(),"code"===e&&Z(e)})),je=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;const e=yield m.convertMarkdownToDocx(ve.content);m.downloadDocx(e,`${ve.title}.docx`)})),ke=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!ve)return;let o={mimeType:"text/plain",extension:".txt"};switch(t){case"text/markdown":o={mimeType:"text/markdown",extension:".md"};break;case"text/html":o={mimeType:"text/html",extension:".html"};break;case"text/csv":o={mimeType:"text/csv",extension:".csv"};break;case"text/tab-separated-values":o={mimeType:"text/tab-separated-values",extension:".tsv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":o={mimeType:"image/svg+xml",extension:".svg"};break;case"application/pdf":o={mimeType:"application/pdf",extension:".pdf"};break;case"application/vnd.pxe.code":o={mimeType:`application/${ve.programmingLanguage||"text"};charset=utf-8`,extension:`.${ve.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":o={mimeType:"text/typescript",extension:".tsx"};break;default:o={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ve.type){const t=Y;"code"===t&&(Z("render"),yield new Promise((e=>setTimeout(e,50))));const o=null===(e=le.current)||void 0===e?void 0:e.querySelector("svg");o&&(n=(new XMLSerializer).serializeToString(o)),"code"===t&&Z(t)}const a=new Blob([null!=n?n:ve.content],{type:o.mimeType});E.default(a,`${ve.title}${o.extension}`)})),Ce=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve&&be&&J){ne(!0),ie(!1);try{const t=`${e=ve.title,e.trim().replace(/[\\/:*?"<>|]/g,"-").replace(/\s+/g," ")||"artifact"}${be.extension}`,o=new File([be.content],t,{type:be.mimeType});yield Q.document(Object.assign(Object.assign({contextId:W,pickaxeId:H,file:o},(null==K?void 0:K.workspaceid)&&{workspaceId:K.workspaceid}),{studioSessionToken:J,isUserDocument:!0})),ie(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(D.default(e))}finally{ne(!1),ie(!1)}var e}})),Te=()=>{"inline"!==x.type||!x.artifact||he?L(null):L({id:x.artifact.id,version:x.artifact.version})},Se=he||!R.startsWith("inline");return ve?t.jsxs("div",Object.assign({className:A.default("pxe-artifact-renderer flex flex-col","inline"===x.type&&!he&&"min-h-[320px] mb-6",x.className),style:Object.assign(Object.assign({backgroundColor:ye.secondary,color:ye.secondaryText},"auto"!==R&&{borderRadius:xe.cornerRadius}),x.style)},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-4 justify-between px-4 py-3 shadow-sm"},{children:[t.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex min-w-0 items-center gap-4"},{children:[Se&&t.jsx(S.default,{type:ve.type,view:Y,colors:ye,onChange:Z}),t.jsx("p",Object.assign({className:"w-[220px] max-w-full truncate text-[18px] font-semilight leading-tight",title:ve.title},{children:ve.title}))]})),"inline"===x.type&&!Se&&t.jsx("div",Object.assign({className:"shrink-0"},{children:t.jsx("button",Object.assign({type:"button",style:{color:ye.secondaryText},onClick:Te,title:(null==U?void 0:U.expand)||"Expand","aria-label":(null==U?void 0:U.expand)||"Expand artifact"},{children:he?t.jsx(f.default,{className:"w-6 h-6 shrink-0"}):t.jsx(v.default,{className:"w-6 h-6 shrink-0"})}))}))]})),Se&&t.jsx("div",Object.assign({className:"flex items-center justify-between border-y px-4 py-2.5",style:{borderColor:ye.primary}},{children:t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100",style:{color:ye.secondaryText},onClick:Te,title:"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse":(null==U?void 0:U.close)||"Close","aria-label":"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse artifact":(null==U?void 0:U.close)||"Close artifact"},{children:t.jsx(g.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-50",style:{color:ye.secondaryText},disabled:ee,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve)try{B.default(ve.content),te(!0),yield new Promise((e=>setTimeout(e,1500)))}finally{te(!1)}})),title:(null==U?void 0:U.copy)||"Copy","aria-label":(null==U?void 0:U.copy)||"Copy artifact content"},{children:t.jsx(h.default,{className:"h-[18px] w-[18px] shrink-0"})})),t.jsx(T.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae,className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100"},{children:t.jsx("div",Object.assign({role:"button",className:"cursor-pointer",style:{color:ye.secondaryText},title:(null==U?void 0:U.save)||"Download","aria-label":(null==U?void 0:U.save)||"Download artifact content"},{children:t.jsx(b.default,{className:"h-6 w-6 shrink-0"})}))}))]}))})),t.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:t.jsxs(j.default,Object.assign({ref:de,innerClassName:"flex-grow w-full"},{children:["render"===Y&&"application/vnd.pxe.code"!==ve.type?t.jsx("div",Object.assign({ref:re,className:A.default("p-4 pb-6 flex-grow flex flex-col","text/html"===ve.type&&"p-0","text/csv"===ve.type&&"p-0","application/pdf"===ve.type&&"p-0","application/vnd.pxe.react"===ve.type&&"p-0")},{children:"text/markdown"===ve.type||"text/csv"===ve.type||"text/tab-separated-values"===ve.type||"image/svg+xml"===ve.type?t.jsx(d.PickaxeMarkdown,Object.assign({theme:xe.theme,colors:ye},{children:t.jsx(p.PickaxeMarkdownRenderer,{value:null!=fe?fe:ve.content,className:A.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full",("text/csv"===ve.type||"text/tab-separated-values"===ve.type)&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ve.type?t.jsx(C.default,{ref:le,id:`mermaid-${ve.id}-${ve.version}`,data:ve.content}):"text/html"===ve.type||"application/pdf"===ve.type||"application/vnd.pxe.react"===ve.type?t.jsx("iframe",Object.assign({ref:se,title:ve.title,src:`${M}/${"application/vnd.pxe.react"!==ve.type?"html":"react"}?theme=${ge?"dark":"light"}&bg=${ye.secondary}&accent=${ye.accent}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==ye?void 0:ye.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const t=e.target;setTimeout((()=>{var e;try{null===(e=t.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},M)}catch(e){console.error("Error sending message to iframe:",e)}}),100),ue()}},{children:(null==U?void 0:U["iframe-artifact-fallback"])||"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t.jsx(u.Prism,Object.assign({PreTag:"div",language:"text/markdown"===ve.type?"markdown":"text/html"===ve.type||"image/svg+xml"===ve.type?"xml":"application/vnd.pxe.react"===ve.type?"typescript":ve.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==ye?void 0:ye.secondary}),':not(pre) > code[class*="language-"]':{background:null==ye?void 0:ye.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ge&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:ve.content})),t.jsx(y.default,{})]}))})),"inline"===x.type&&!he&&t.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t.jsx(k.default,Object.assign({id:`artifact-copy-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(w.default,{color:ye.secondaryText,text:ve.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t.jsx(k.default,Object.assign({id:`artifact-save-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(T.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae},{children:t.jsx("button",Object.assign({style:{color:ye.secondaryText}},{children:t.jsx(b.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("react"),n=require("../hooks/useArtifactContext.js"),a=require("../../../../../hooks/pickaxe/usePickaxeContext.js"),i=require("../../Auth/hooks/useAuthContext.js"),r=require("../../Scroll/hooks/useScroll.js"),l=require("../hooks/useArtifact.js"),s=require("../../../../../hooks/pickaxe/useSubmitDocument.js"),c=require("react-to-print"),d=require("../../../common/PickaxeMarkdown/index.js"),p=require("../../../common/PickaxeMarkdown/Renderer.js"),u=require("react-syntax-highlighter"),m=require("../../../../../common/docx/index.js"),x=require("file-saver"),y=require("../../Scroll/Provider.js"),v=require("../../Scroll/ScrollLockView.js"),f=require("../../../../Icons/expand.svg.js"),g=require("../../../../Icons/shrink.svg.js"),h=require("../../../../Icons/collapse-new.svg.js"),b=require("../../../../Icons/copy-new.svg.js"),w=require("../../../../Icons/download-new.svg.js"),j=require("../../../common/PickaxeCopyButton.js"),k=require("../../../../Core/ScrollArea.js"),C=require("../../../../Core/TipContainer.js"),T=require("../MermaidRenderer.js"),S=require("./SaveMenu.js"),F=require("./ViewOptions.js"),O=require("csv-to-markdown-table"),A=require("copy-to-clipboard"),q=require("../../../../../common/cn.js"),D=require("../../../../../common/error.js");function E(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var N=E(x),B=E(O),M=E(A);const _="development"===process.env.NODE_ENV?"http://localhost:3007":"https://user-content.pickaxe.co",P=e=>{var t;const o=null==e?void 0:e.trim().toLowerCase();if(!o)return".txt";return null!==(t={javascript:".js",js:".js",typescript:".ts",ts:".ts",python:".py",py:".py",json:".json",html:".html",css:".css",markdown:".md",md:".md",sql:".sql",shell:".sh",bash:".sh",sh:".sh",yaml:".yaml",yml:".yml",xml:".xml"}[o])&&void 0!==t?t:`.${o}`},$=x=>{var y,O,A,E;const{artifacts:$,currentPopupType:R,currentArtifact:z,setCurrentArtifact:L}=n.useArtifactContext(),{onLoadArtifact:I}=l.useArtifact(),{contextId:W,pickaxeId:H,pickaxe:K,styles:V,colors:X,translations:U}=a.usePickaxeContext(),{isLoggedIn:G,token:J}=i.useAuthContext(),Q=s.useSubmitDocument(),[Y,Z]=o.useState("code"),[ee,te]=o.useState(!1),[oe,ne]=o.useState(!1),[ae,ie]=o.useState(!1),re=o.useRef(),le=o.useRef(null),se=o.useRef(null),ce=c.useReactToPrint({contentRef:re}),{scrollContainerRef:de,scrollStartSession:pe,scrollToBottom:ue,scrollEndSession:me}=r.useScroll({auto:"code"===Y}),xe=null!==(O=null===(y=x.styling)||void 0===y?void 0:y.styles)&&void 0!==O?O:V,ye=null!==(E=null===(A=x.styling)||void 0===A?void 0:A.colors)&&void 0!==E?E:X,ve=o.useMemo((()=>{var e,t,o,n,a;if(!x.artifact&&!z)return null;const i=null!==(t=null===(e=x.artifact)||void 0===e?void 0:e.id)&&void 0!==t?t:null==z?void 0:z.id,r=null!==(n=null===(o=x.artifact)||void 0===o?void 0:o.version)&&void 0!==n?n:null==z?void 0:z.version;return null!==(a=$.find((e=>e.id===i&&e.version===r)))&&void 0!==a?a:null}),[z,$,x.artifact]),fe=o.useMemo((()=>ve?"text/csv"===ve.type?B.default(ve.content,",",!0):"text/tab-separated-values"===ve.type?B.default(ve.content,"\t",!0):null:null),[ve]),ge=o.useMemo((()=>(ye.secondaryText||"").toLowerCase().startsWith("#ffffff")),[null==ye?void 0:ye.secondaryText]),he=o.useMemo((()=>{const e=x.artifact&&(null==z?void 0:z.id)===x.artifact.id&&(null==z?void 0:z.version)===x.artifact.version;return"inline"===x.type&&("inline-form"===R?!!z:e)}),[z,R,x.type,x.artifact]),be=o.useMemo((()=>ve?(e=>{switch(e.type){case"text/markdown":return{extension:".md",mimeType:"text/markdown",content:e.content};case"text/html":return{extension:".html",mimeType:"text/html",content:e.content};case"text/csv":return{extension:".csv",mimeType:"text/csv",content:e.content};case"text/tab-separated-values":return{extension:".tsv",mimeType:"text/tab-separated-values",content:e.content};case"image/svg+xml":return{extension:".svg",mimeType:"image/svg+xml",content:e.content};case"application/pdf":return e.content.trimStart().startsWith("%PDF")?{extension:".pdf",mimeType:"application/pdf",content:e.content}:{extension:".html",mimeType:"text/html",content:e.content};case"application/vnd.pxe.code":return{extension:P(e.programmingLanguage),mimeType:"text/plain",content:e.content};case"application/vnd.pxe.mermaid":return{extension:".mmd",mimeType:"text/plain",content:e.content};case"application/vnd.pxe.react":return{extension:".tsx",mimeType:"text/typescript",content:e.content};default:return null}})(ve):null),[ve]);o.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){"inline"===x.type&&x.artifact&&($.some((e=>x.artifact&&e.id===x.artifact.id&&e.version===x.artifact.version))||I({id:x.artifact.id,version:x.artifact.version}))}))}),[$,x.type,x.artifact]),o.useEffect((()=>{if("application/vnd.pxe.code"===(null==ve?void 0:ve.type)&&Z("code"),"finished"!==(null==ve?void 0:ve.status))return Z("code"),pe(),void ue();me(),"application/vnd.pxe.code"!==ve.type&&Z("render")}),[null==ve?void 0:ve.status,null==ve?void 0:ve.type]),o.useEffect((()=>{var e;!se.current||"text/html"!==(null==ve?void 0:ve.type)&&"application/pdf"!==(null==ve?void 0:ve.type)&&"application/vnd.pxe.react"!==(null==ve?void 0:ve.type)||null===(e=se.current.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},_)}),[null==ve?void 0:ve.content,null==ve?void 0:ve.type]);const we=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;if("text/html"===ve.type||"application/pdf"===ve.type){const e=ve.content,t=window.open("","_blank");return void(t&&(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.print()))}const e=Y;"code"===e&&(Z("render"),yield new Promise((e=>setTimeout(e,50)))),ce(),"code"===e&&Z(e)})),je=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!ve)return;const e=yield m.convertMarkdownToDocx(ve.content);m.downloadDocx(e,`${ve.title}.docx`)})),ke=t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(!ve)return;let o={mimeType:"text/plain",extension:".txt"};switch(t){case"text/markdown":o={mimeType:"text/markdown",extension:".md"};break;case"text/html":o={mimeType:"text/html",extension:".html"};break;case"text/csv":o={mimeType:"text/csv",extension:".csv"};break;case"text/tab-separated-values":o={mimeType:"text/tab-separated-values",extension:".tsv"};break;case"image/svg+xml":case"application/vnd.pxe.mermaid":o={mimeType:"image/svg+xml",extension:".svg"};break;case"application/pdf":o={mimeType:"application/pdf",extension:".pdf"};break;case"application/vnd.pxe.code":o={mimeType:`application/${ve.programmingLanguage||"text"};charset=utf-8`,extension:`.${ve.programmingLanguage||"txt"}`};break;case"application/vnd.pxe.react":o={mimeType:"text/typescript",extension:".tsx"};break;default:o={mimeType:"text/plain",extension:".txt"}}let n=null;if("application/vnd.pxe.mermaid"===ve.type){const t=Y;"code"===t&&(Z("render"),yield new Promise((e=>setTimeout(e,50))));const o=null===(e=le.current)||void 0===e?void 0:e.querySelector("svg");o&&(n=(new XMLSerializer).serializeToString(o)),"code"===t&&Z(t)}const a=new Blob([null!=n?n:ve.content],{type:o.mimeType});N.default(a,`${ve.title}${o.extension}`)})),Ce=()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve&&be&&J){ne(!0),ie(!1);try{const t=`${e=ve.title,e.trim().replace(/[\\/:*?"<>|]/g,"-").replace(/\s+/g," ")||"artifact"}${be.extension}`,o=new File([be.content],t,{type:be.mimeType});yield Q.document(Object.assign(Object.assign({contextId:W,pickaxeId:H,file:o},(null==K?void 0:K.workspaceid)&&{workspaceId:K.workspaceid}),{studioSessionToken:J,isUserDocument:!0})),ie(!0),yield new Promise((e=>setTimeout(e,1500)))}catch(e){alert(D.default(e))}finally{ne(!1),ie(!1)}var e}})),Te=()=>{"inline"!==x.type||!x.artifact||he?L(null):L({id:x.artifact.id,version:x.artifact.version})},Se=he||!R.startsWith("inline");return ve?t.jsxs("div",Object.assign({className:q.default("pxe-artifact-renderer flex flex-col","inline"===x.type&&!he&&"min-h-[320px] mb-6",x.className),style:Object.assign(Object.assign({backgroundColor:ye.secondary,color:ye.secondaryText},"auto"!==R&&{borderRadius:xe.cornerRadius}),x.style)},{children:[t.jsxs("div",Object.assign({className:"flex items-center gap-4 justify-between px-4 py-3 shadow-sm"},{children:[t.jsxs("div",Object.assign({className:"pxe-artifact-create-header flex min-w-0 items-center gap-4"},{children:[Se&&t.jsx(F.default,{type:ve.type,view:Y,colors:ye,onChange:Z}),t.jsx("p",Object.assign({className:"w-[220px] max-w-full truncate text-[18px] font-semilight leading-tight",title:ve.title},{children:ve.title}))]})),"inline"===x.type&&!Se&&t.jsx("div",Object.assign({className:"shrink-0"},{children:t.jsx("button",Object.assign({type:"button",style:{color:ye.secondaryText},onClick:Te,title:(null==U?void 0:U.expand)||"Expand","aria-label":(null==U?void 0:U.expand)||"Expand artifact"},{children:he?t.jsx(g.default,{className:"w-6 h-6 shrink-0"}):t.jsx(f.default,{className:"w-6 h-6 shrink-0"})}))}))]})),Se&&t.jsx("div",Object.assign({className:"flex items-center justify-between border-y px-4 py-2.5",style:{borderColor:ye.primary}},{children:t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100",style:{color:ye.secondaryText},onClick:Te,title:"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse":(null==U?void 0:U.close)||"Close","aria-label":"inline"===x.type?(null==U?void 0:U.collapse)||"Collapse artifact":(null==U?void 0:U.close)||"Close artifact"},{children:t.jsx(h.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({type:"button",className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-50",style:{color:ye.secondaryText},disabled:ee,onClick:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(ve)try{M.default(ve.content),te(!0),yield new Promise((e=>setTimeout(e,1500)))}finally{te(!1)}})),title:(null==U?void 0:U.copy)||"Copy","aria-label":(null==U?void 0:U.copy)||"Copy artifact content"},{children:t.jsx(b.default,{className:"h-[18px] w-[18px] shrink-0"})})),t.jsx(S.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae,className:"opacity-70 transition-opacity duration-300 ease-in-out hover:opacity-100"},{children:t.jsx("div",Object.assign({role:"button",className:"cursor-pointer",style:{color:ye.secondaryText},title:(null==U?void 0:U.save)||"Download","aria-label":(null==U?void 0:U.save)||"Download artifact content"},{children:t.jsx(w.default,{className:"h-6 w-6 shrink-0"})}))}))]}))})),t.jsx("div",Object.assign({className:"flex flex-col flex-grow @container/pickaxe-artifact"},{children:t.jsxs(k.default,Object.assign({ref:de,innerClassName:"flex-grow w-full"},{children:["render"===Y&&"application/vnd.pxe.code"!==ve.type?t.jsx("div",Object.assign({ref:re,className:q.default("p-4 pb-6 flex-grow flex flex-col","text/html"===ve.type&&"p-0","text/csv"===ve.type&&"p-0","application/pdf"===ve.type&&"p-0","application/vnd.pxe.react"===ve.type&&"p-0")},{children:"text/markdown"===ve.type||"text/csv"===ve.type||"text/tab-separated-values"===ve.type||"image/svg+xml"===ve.type?t.jsx(d.PickaxeMarkdown,Object.assign({theme:xe.theme,colors:ye},{children:t.jsx(p.PickaxeMarkdownRenderer,{value:null!=fe?fe:ve.content,className:q.default("px-6 @[767px]/pickaxe-artifact:px-11 mx-auto w-full",("text/csv"===ve.type||"text/tab-separated-values"===ve.type)&&"px-4 @[767px]/pickaxe-artifact:px-4 mx-0"),style:{flex:1}})})):"application/vnd.pxe.mermaid"===ve.type?t.jsx(T.default,{ref:le,id:`mermaid-${ve.id}-${ve.version}`,data:ve.content}):"text/html"===ve.type||"application/pdf"===ve.type||"application/vnd.pxe.react"===ve.type?t.jsx("iframe",Object.assign({ref:se,title:ve.title,src:`${_}/${"application/vnd.pxe.react"!==ve.type?"html":"react"}?theme=${ge?"dark":"light"}&bg=${ye.secondary}&accent=${ye.accent}`,style:{width:"100%",flex:1,border:"none",backgroundColor:null==ye?void 0:ye.secondary},loading:"lazy",allow:"fullscreen; camera; microphone; gyroscope; accelerometer; geolocation; clipboard-write; autoplay",sandbox:"allow-scripts allow-same-origin allow-forms allow-downloads allow-popups-to-escape-sandbox allow-pointer-lock allow-popups allow-modals allow-orientation-lock allow-presentation",onLoad:e=>{const t=e.target;setTimeout((()=>{var e;try{null===(e=t.contentWindow)||void 0===e||e.postMessage({type:"application/vnd.pxe.react"!==ve.type?"HTML_CODE":"REACT_CODE",content:ve.content},_)}catch(e){console.error("Error sending message to iframe:",e)}}),100),ue()}},{children:(null==U?void 0:U["iframe-artifact-fallback"])||"Iframe is not supported, please view this artifact in a browser that supports it."})):null})):t.jsx(u.Prism,Object.assign({PreTag:"div",language:"text/markdown"===ve.type?"markdown":"text/html"===ve.type||"image/svg+xml"===ve.type?"xml":"application/vnd.pxe.react"===ve.type?"typescript":ve.programmingLanguage,showLineNumbers:!0,customStyle:{margin:0,flex:1},style:Object.assign({'code[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"}),'pre[class*="language-"]':Object.assign(Object.assign({color:null==ye?void 0:ye.secondaryText},ge&&{textShadow:"0 1px rgba(0, 0, 0, 0.3)"}),{fontFamily:"Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace",direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",borderRadius:"0.3em",minWidth:0,paddingLeft:"1em",paddingRight:"1em",paddingBottom:"2em",background:null==ye?void 0:ye.secondary}),':not(pre) > code[class*="language-"]':{background:null==ye?void 0:ye.secondary,padding:".1em",borderRadius:".3em"},comment:{color:"#7C7C7C"},prolog:{color:"#7C7C7C"},doctype:{color:"#7C7C7C"},cdata:{color:"#7C7C7C"},punctuation:{color:"#c5c8c6"},".namespace":{opacity:".7"},property:{color:"#96CBFE"},keyword:{color:"#96CBFE"},tag:{color:"#96CBFE"},"class-name":{color:"#FFFFB6"},boolean:{color:"#99CC99"},constant:{color:"#99CC99"},symbol:{color:"#f92672"},deleted:{color:"#f92672"},number:{color:"#FF73FD"},selector:{color:"#A8FF60"},"attr-name":{color:"#A8FF60"},string:{color:"#A8FF60"},char:{color:"#A8FF60"},builtin:{color:"#A8FF60"},inserted:{color:"#A8FF60"},variable:{color:"#C6C5FE"},operator:{color:"#EDEDED"},entity:{color:"#FFFFB6",cursor:"help"},url:{color:"#96CBFE"},".language-css .token.string":{color:"#87C38A"},".style .token.string":{color:"#87C38A"},atrule:{color:"#F9EE98"},"attr-value":{color:"#F9EE98"},function:{color:"#DAD085"},regex:{color:"#E9C062"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}},!ge&&{comment:{color:"#7D8B99"},prolog:{color:"#7D8B99"},doctype:{color:"#7D8B99"},cdata:{color:"#7D8B99"},punctuation:{color:"#4D4D4C"},property:{color:"#4078F2"},keyword:{color:"#8959A8"},tag:{color:"#8959A8"},"class-name":{color:"#D75F00"},boolean:{color:"#0086B3"},constant:{color:"#0086B3"},symbol:{color:"#990055"},deleted:{color:"#990000"},number:{color:"#005CC5"},selector:{color:"#63A35C"},"attr-name":{color:"#63A35C"},string:{color:"#50A14F"},char:{color:"#50A14F"},builtin:{color:"#50A14F"},inserted:{color:"#50A14F"},variable:{color:"#A626A4"},operator:{color:"#4D4D4C"},entity:{color:"#E45649",cursor:"help"},url:{color:"#4078F2"},".language-css .token.string":{color:"#50A14F"},".style .token.string":{color:"#50A14F"},atrule:{color:"#C18401"},"attr-value":{color:"#986801"},function:{color:"#005CC5"},regex:{color:"#D16969"},important:{color:null==ye?void 0:ye.secondaryText,fontWeight:"bold"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"}})},{children:ve.content})),t.jsx(v.default,{})]}))})),"inline"===x.type&&!he&&t.jsxs("div",Object.assign({className:"flex items-center gap-4 p-4 pt-6"},{children:[t.jsx(C.default,Object.assign({id:`artifact-copy-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.copy)||"Copy",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(j.default,{color:ye.secondaryText,text:ve.content,className:"opacity-100",iconClassName:"w-5 h-5"})})),t.jsx(C.default,Object.assign({id:`artifact-save-${ve.id}-${ve.version}`,tip:(null==U?void 0:U.save)||"Save",style:{padding:"0.25rem 0.5rem",backgroundColor:ye.secondary,color:ye.secondaryText,fontSize:"12px"},align:"bottom"},{children:t.jsx(S.default,Object.assign({data:ve,colors:ye,onDownload:ke,onSaveAsPDF:we,onSaveAsDOCX:je,onSaveToKnowledgeBase:Ce,isSaveToKnowledgeBaseEnabled:G&&Boolean(be),isSavingToKnowledgeBase:oe,isSavedToKnowledgeBase:ae},{children:t.jsx("button",Object.assign({style:{color:ye.secondaryText}},{children:t.jsx(w.default,{className:"w-5 h-5 shrink-0"})}))}))}))]}))]})):null};exports.default=e=>t.jsx(y.ScrollProvider,{children:t.jsx($,Object.assign({},e))});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("./hooks/useArtifactContext.js"),i=require("../../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../../../../hooks/core/useMediaQuery.js"),s=require("../../../Core/Modal/index.js"),l=require("../../../Core/Modal/Body.js"),a=require("./Renderer/index.js");exports.PickaxeArtifact=({forcedPopupType:o,panel:u,styling:c})=>{const{popupType:d,currentPopupType:f,currentArtifact:x,setCurrentPopupType:p,setCurrentArtifact:j}=r.useArtifactContext(),{sessionId:h,pickaxe:m,forceMobile:y}=i.usePickaxeContext(),[g]=n.useMediaQuery("(max-width: 899px)");t.useEffect((()=>{const e=!(null==m?void 0:m.chatflag)&&!h||!h;let t=d;"auto"===t&&(e?t="inline-form":(y||g)&&(t="inline")),"inline"===d&&e&&(t="inline-form"),o&&(t=o),p(t)}),[d,y,g,null==m?void 0:m.chatflag,h,o]);const C=e.jsx(a.default,{type:"detached",className:"h-full"});return x&&"inline"!==f?e.jsx(e.Fragment,{children:"auto"===f&&u?u(C):"modal"===f||"inline-form"===f?e.jsx(s.default,Object.assign({isOpen:!0,onChange:e=>{e||j(null)}},{children:e.jsx(l.default,Object.assign({className:"max-w-[90dvw] flex flex-col w-full",style:{minHeight:"90dvh"}},{children:e.jsx(a.default,Object.assign({type:"inline-form"===f?"inline":"detached",className:"flex-grow"},c&&{styling:c}))}))})):null}):null};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react");const s=r.createContext({}),t=({children:t})=>{const[l,o]=r.useState(!0),[c,i]=r.useState(!0),[n,u]=r.useState(!1),[a,S]=r.useState(!0),f=r.useRef(),R=r.useRef(),d=r.useRef(!1),g=r.useRef(!1),x=r.useRef("auto"),m=r.useRef(null);return r.useEffect((()=>{const e=m;return()=>{e.current&&clearTimeout(e.current)}}),[]),e.jsx(s.Provider,Object.assign({value:{scrollContainerRef:f,scrollTargetRef:R,hasScrolledRef:d,isProgrammaticScrollRef:g,programmaticScrollBehaviorRef:x,scrollEndTimerRef:m,isLocked:l,isScrollSession:c,isScrolling:n,isScrollIncreasing:a,setIsLocked:o,setIsScrollSession:i,setIsScrolling:u,setIsScrollIncreasing:S}},{children:t}))};exports.ScrollContext=s,exports.ScrollProvider=t,exports.default=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useScrollContext.js");exports.useScroll=({auto:t=!1,debug:o,smooth:n=!0})=>{const{scrollContainerRef:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useScrollContext.js");exports.useScroll=({auto:t=!1,debug:o,smooth:n=!0,listen:l=!0}={})=>{const{scrollContainerRef:c,scrollTargetRef:s,hasScrolledRef:u,isProgrammaticScrollRef:i,programmaticScrollBehaviorRef:a,scrollEndTimerRef:d,isLocked:v,isScrollIncreasing:h,setIsLocked:f,setIsScrollSession:g,setIsScrolling:m,setIsScrollIncreasing:b}=r.useScrollContext(),w=e.useRef(null),C=e.useRef(0),S=e.useCallback((()=>{d.current&&(clearTimeout(d.current),d.current=null),i.current=!1,m(!1);const e=c.current;if(!e)return;const r=e.scrollHeight-e.scrollTop-e.clientHeight<=32;u.current=!r,f(r)}),[u,i,c,d,f,m]),T=e.useCallback((()=>{null!==w.current&&(cancelAnimationFrame(w.current),w.current=null)}),[]),p=e.useCallback((e=>{d.current&&clearTimeout(d.current),a.current=e,d.current=setTimeout(S,"smooth"===e?400:100)}),[a,d,S]),E=e.useCallback(((e={})=>{var r;if(!e.force&&u.current)return;const t=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",l=c.current,a=s.current;if(l||a){if(i.current=!0,m(!0),e.force&&(u.current=!1,f(!0)),l){const e=Math.max(0,l.scrollHeight-l.clientHeight);l.scrollTo({top:e,behavior:t})}else if(a){const e=a.getBoundingClientRect().bottom+window.scrollY,r=Math.max(0,e-window.innerHeight);window.scrollTo({top:r,behavior:t})}o&&console.log("[useScroll] scrolled to the active bottom"),p(t)}else o&&console.log("[useScroll] no scroll element detected")}),[o,p,u,i,c,s,m,f,n]),R=e.useCallback(((e={})=>{T(),w.current=requestAnimationFrame((()=>{w.current=null,E(e)}))}),[T,E]),k=e.useCallback(((e={})=>{var r;if(!e.force&&u.current)return;const t=s.current;if(!t)return void(o&&console.log("[useScroll] scroll target not detected"));const l=null!==(r=e.behavior)&&void 0!==r?r:n?"smooth":"auto",c=t.getBoundingClientRect().bottom+window.scrollY,a=Math.max(0,c-500);i.current=!0,m(!0),window.scrollTo({top:a,behavior:l}),o&&console.log("[useScroll] scrolled to the form response"),p(l)}),[o,p,u,i,s,m,n]),H=e.useCallback(((e={})=>{T(),w.current=requestAnimationFrame((()=>{w.current=null,k(e)}))}),[T,k]),L=e.useCallback((()=>{u.current=!1,f(!0),g(!0)}),[u,f,g]),x=e.useCallback((()=>{g(!1)}),[g]),M=e.useCallback(((e={})=>R(e)),[R]),B=e.useCallback(((e={})=>H(e)),[H]);return e.useEffect((()=>{if(!t||!v)return;let e=c.current,r=s.current,o=null,n=[];const l=()=>{var t;if(!o)return;const n=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,l=n>C.current;C.current=n,b(l),l&&(e?R({behavior:"auto"}):H({behavior:"auto"}))},u=new ResizeObserver(l);function i(){o&&(n.forEach((e=>u.unobserve(e))),n=[o,...Array.from(o.children)],n.forEach((e=>u.observe(e))))}const a=new MutationObserver((()=>{i(),l()}));let d=null;const h=()=>{var t;e=c.current,r=s.current;const n=null!=e?e:r;return!(!n||n===o)&&(a.disconnect(),u.disconnect(),o=n,C.current=e?Math.max(0,e.scrollHeight-e.clientHeight):null!==(t=null==r?void 0:r.getBoundingClientRect().height)&&void 0!==t?t:0,i(),a.observe(o,{childList:!0,subtree:!0}),e?R({behavior:"auto"}):H({behavior:"auto"}),!0)};return h()||(d=new MutationObserver((()=>{h()&&(null==d||d.disconnect())})),d.observe(document.body,{childList:!0,subtree:!0})),()=>{null==d||d.disconnect(),a.disconnect(),u.disconnect()}}),[t,v,R,H,c,s,b]),e.useEffect((()=>{v&&(u.current=!1)}),[u,v]),e.useEffect((()=>{if(!l)return;const e=c.current,r=null!=e?e:window,t=()=>{if(i.current)return void p(a.current);const r=(()=>{if(e)return e.scrollHeight-e.scrollTop-e.clientHeight<=32;const r=s.current;return!r||r.getBoundingClientRect().bottom-window.innerHeight<=32})();u.current=!r,f(r)},o=()=>{i.current&&S()},n=()=>{i.current&&(i.current=!1,m(!1),d.current&&(clearTimeout(d.current),d.current=null),e?e.scrollTo({top:e.scrollTop,behavior:"auto"}):window.scrollTo({top:window.scrollY,behavior:"auto"}))};return r.addEventListener("scroll",t,{passive:!0}),r.addEventListener("scrollend",o),r.addEventListener("wheel",n,{passive:!0}),r.addEventListener("touchmove",n,{passive:!0}),()=>{r.removeEventListener("scroll",t),r.removeEventListener("scrollend",o),r.removeEventListener("wheel",n),r.removeEventListener("touchmove",n)}}),[p,u,i,l,a,c,d,s,f,m,S]),e.useEffect((()=>()=>{T()}),[T]),{scrollContainerRef:c,scrollTargetRef:s,isScrollIncreasing:h,scrollStartSession:L,scrollEndSession:x,scrollToBottom:M,scrollToTarget:B}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("../../../common/canChat.js"),n=require("../../../hooks/pickaxe/useEndUserModel.js"),i=require("../common/EndUserModelPicker.js"),r=require("../../../common/actionApproval.js"),o=require("react"),a=require("../../../hooks/pickaxe/usePickaxeContext.js"),l=require("../../../hooks/pickaxe/useResponseContext.js"),d=require("../../../hooks/studio/useStyleInput.js"),c=require("../../../hooks/studio/useStyleFontSize.js"),u=require("../../../hooks/pickaxe/useConversation.js"),p=require("../../../hooks/pickaxe/useDimensionContext.js"),m=require("../Addons/Auth/hooks/useAuthContext.js"),f=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),v=require("../Addons/Artifact/hooks/useArtifactContext.js"),h=require("../../../hooks/core/useHover.js"),b=require("../../../hooks/core/useMediaQuery.js"),x=require("../../../common/documents.js"),y=require("eventsource-parser"),I=require("../../Icons/attach-vertical.svg.js"),j=require("../../Icons/arrow-right.svg.js"),S=require("../../Icons/microphone.svg.js"),N=require("../../Icons/message-clock.svg.js"),O=require("../../Icons/stop.svg.js"),w=require("../../Icons/trash.svg.js"),k=require("../../Icons/pencil.svg.js"),_=require("../Addons/Document/List.js"),E=require("../../Core/Textarea.js"),T=require("../../Core/ErrorAlert.js"),C=require("../../Core/Menu/index.js"),U=require("../../Core/Menu/Button.js"),A=require("../../Core/Menu/List.js"),D=require("../../../common/error.js"),P=require("../../../common/api/pickaxe.js"),L=require("../../../common/validation.js"),q=require("../../../common/cn.js"),M=require("../../../common/utils.js"),R=require("../../../common/pickaxeConfig.js"),F=require("../../../common/agentPrefill.js"),V=require("../../../common/deploymentWebhooks.js"),$=require("../../../hooks/studio/useStudio.js"),B=require("../../../hooks/pickaxe/useSpeechToText.js"),X=require("../common/PickaxeCommon.js");const K=(e,t)=>{const s=e.find((e=>e.id===t));return s?e.filter((e=>e.id!==t)).map((e=>e.predecessorSubmissionId===t?Object.assign(Object.assign({},e),{predecessorSubmissionId:s.predecessorSubmissionId}):e)):e},G=e=>"string"==typeof e&&e.trim().length>0,H=()=>"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`,Y=e=>e.map((e=>Object.assign({},e))),W=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),z=(e,t)=>{if(e&&"object"==typeof e)return e[t]},J=(e,t)=>{const s=z(e,t);return G(s)?s:null},Q=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},Z=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(z(e,"uses"))?z(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>G(e)?{type:"deployment",id:e}:G(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}},ee=o.forwardRef((({resubmitPrompt:z,onFocus:ee,onBlur:te,onInputHeightChange:se,initSmitheryAuthData:ne},ie)=>{var re,oe,ae,le,de,ce,ue,pe,me,fe,ge,ve,he,be,xe,ye,Ie,je;const{origin:Se,pickaxeId:Ne,sessionId:Oe,sender:we,senderType:ke,portalId:_e,deploymentId:Ee,deploymentType:Te,pickaxe:Ce,styles:Ue,colors:Ae,translations:De,locale:Pe,forceMobile:Le,isNewChat:qe,isRtl:Me,isEmbed:Re,isShowFeedbackMessage:Fe,accessGroup:Ve,setIsNewChat:$e,setIsShowIceBreaker:Be,setValidationStatus:Xe,setValidationUpgradeGroups:Ke,setValidationUpgradeUrl:Ge,setAccessGroup:He,onUpgrade:Ye,onGenerateComplete:We}=a.usePickaxeContext(),{value:ze,enabled:Je}=n.useEndUserModel(),{token:Qe,isLoggedOut:Ze,isSent:et,isPricingAuth:tt}=m.useAuthContext(),{messages:st,isGenerating:nt,setMessages:it,setStatus:rt,setLimitData:ot,setError:at,setActionApprovalToken:lt}=l.useResponseContext(),{documents:dt,isUploading:ct,documentError:ut,onFileUpload:pt,setDocuments:mt,setDocumentError:ft}=f.useDocument(),{studio:gt}=$.useStudio(),[vt]=b.useMediaQuery("(max-width: 480px)"),{scrollStartSession:ht,scrollEndSession:bt,scrollToBottom:xt}=g.useScroll({auto:!0,smooth:!(Le||vt)}),{artifacts:yt,currentPopupType:It,setArtifacts:jt,setCurrentArtifact:St}=v.useArtifactContext(),{height:Nt}=p.useDimensionContext(),Ot=u.useConversation(),[wt,kt]=o.useState((()=>F.readAgentPrefill([Ee,Ne]).chatInput)),[_t,Et]=o.useState(!1),[Tt,Ct]=o.useState(!1),[Ut,At]=o.useState(!1),[Dt,Pt]=o.useState(!1),[Lt,qt]=o.useState([]),[Mt,Rt]=o.useState(!1),[Ft,Vt]=o.useState(null),[$t,Bt]=o.useState(null),[Xt,Kt]=o.useState(null),[Gt,Ht]=o.useState(null),[Yt,Wt]=o.useState(!1),[zt,Jt]=o.useState(!1),[Qt,Zt]=o.useState(0),es=o.useRef(null),ts=o.useRef(""),ss=o.useRef(null),ns=o.useRef(null),is=o.useRef(null),rs=o.useRef([]),os=o.useRef(null),as=o.useRef(null),ls=o.useRef(null),ds=o.useRef(null),cs=o.useRef(new Set),us=o.useRef(null),ps=Math.max(.4*Nt,100),{speechTranscript:ms,isSpeechListening:fs,isSpeechProcessing:gs,isSpeechSupported:vs,onStartListening:hs,onStopListening:bs}=B.useSpeechToText(),xs=h.useHover(),{isHover:ys}=xs,Is=e.__rest(xs,["isHover"]),js=h.useHover(),{isHover:Ss}=js,Ns=e.__rest(js,["isHover"]),Os=h.useHover(),{isHover:ws}=Os,ks=e.__rest(Os,["isHover"]),_s=c.useStyleFontSize(),Es=d.useStyleInput(),Ts="undefined"!=typeof window?window.location.hostname:"",Cs="undefined"!=typeof window?window.location.href:"",Us="undefined"!=typeof window&&window.self!==window.top,As=Ts.includes("pickaxe.co")&&!Cs.includes("https://studio.pickaxe.co/_embed")&&!Us,Ds=null!==(oe=null===(re=null==Ce?void 0:Ce.documentuploadtype)||void 0===re?void 0:re.startsWith("enduserupload"))&&void 0!==oe&&oe,Ps=vs&&(null==Ce?void 0:Ce.enablevoicetotext),Ls=fs&&!wt.trim(),qs=G(Ee),Ms="chat-input"===Te&&qe&&!et,Rs="chat-input"===Te&&tt&&Ze&&et,Fs=o.useCallback((e=>{const t=L.getValidationFailure(e);return!!t&&(at(""),ot(null),Xe(t.status),He(t.accessGroup),Ke(t.upgradeGroups),Ge(t.upgradeUrl),!0)}),[at,lt,ot,Xe,Ke,Ge,He]),Vs=null!==(ae=null==Ce?void 0:Ce.placeholdertext)&&void 0!==ae?ae:Me?"بماذا تريد أن تتحدث؟":(null==De?void 0:De["what-do-you-want-to-talk-about"])||"What do you want to talk about?",$s=_t||Tt,Bs=o.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){Wt(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==Ce?void 0:Ce.studioid},Qe?{studioSessionToken:Qe}:we?{sender:we}:{sender:M.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}})),As&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(Kt(t.studioUser),Ht(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{Wt(!0)}}))),[As,null==Ce?void 0:Ce.studioid,we,Qe]);o.useEffect((()=>{Bs()}),[Bs]);const Xs=Number(null!==(le=null==Ve?void 0:Ve.limit)&&void 0!==le?le:0),Ks="string"==typeof(null==Ve?void 0:Ve.limitInterval)?Ve.limitInterval:null,Gs=!!(null==gt?void 0:gt.data.usage)&>.data.usage.isCredits,Hs=o.useMemo((()=>{var e,t,s,n,i;return null!==(i=null!==(n=null!==(s=null!==(t=null!==(e=null!=_e?_e:J(Xt,"portalId"))&&void 0!==e?e:J(Xt,"portalid"))&&void 0!==t?t:J(Ve,"portalId"))&&void 0!==s?s:J(Ve,"portalid"))&&void 0!==n?n:J(Ce,"portalId"))&&void 0!==i?i:J(Ce,"portalid")}),[Ve,_e,Ce,Xt]),Ys=o.useMemo((()=>Z({studioUser:Xt,deploymentId:Ee,portalId:Hs})),[Ee,Hs,Xt]);o.useEffect((()=>{qs&&qe&&Oe&&cs.current.add(Oe)}),[qe,Oe,qs]);const Ws=o.useCallback((()=>{var e,t,s;return{studioId:null==Ce?void 0:Ce.studioid,userEmail:J(Xt,"email"),userId:null!==(e=J(Xt,"userId"))&&void 0!==e?e:J(Xt,"userid"),sessionId:Oe,deploymentId:Ee,deploymentType:Te,portalId:Hs,accessGroupId:null!==(t=null==Ve?void 0:Ve.accessGroupId)&&void 0!==t?t:null,pickaxeId:Ne,sender:we,senderType:ke,origin:Se,metadata:null!==(s=R.getPickaxeConfigMetadata(Ee))&&void 0!==s?s:null}}),[null==Ve?void 0:Ve.accessGroupId,Ee,Te,Se,null==Ce?void 0:Ce.studioid,Ne,Hs,we,ke,Oe,Xt]),zs=o.useCallback((()=>!!(qs&&Yt&&Oe)&&(!!cs.current.has(Oe)&&(V.fireDeploymentSessionInitializedWebhook(Ws()),cs.current.delete(Oe),!0))),[Ws,Yt,Oe,qs]);o.useEffect((()=>{if(!Yt||!Oe)return;zs();const e=us.current;(null==e?void 0:e.sessionId)===Oe&&(V.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),Ws()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),us.current=null)}),[zs,Ws,Yt,Oe]);const Js={currentUses:Q(null==Xt?void 0:Xt.currentUses),extraUses:Q(null==Xt?void 0:Xt.extraUses)},Qs=Ys.scope?{currentUses:null!==(ce=Q(null===(de=Ys.record)||void 0===de?void 0:de.currentUses))&&void 0!==ce?ce:0,extraUses:null!==(pe=Q(null===(ue=Ys.record)||void 0===ue?void 0:ue.extraUses))&&void 0!==pe?pe:0}:{currentUses:0,extraUses:0},Zs=J(Xt,"type"),en="guest"===Zs||!Zs&&Ze?Qs:Js;o.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(Gs&&(null===(e=null==gt?void 0:gt.data)||void 0===e?void 0:e.workspaceId))try{const e=yield P.pickaxeApi2.get(`/cost_per_run?workspaceId=${gt.data.workspaceId}`,{withCredentials:!1});t&&Zt(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&Zt(0)}else t&&Zt(0)})),()=>{t=!1}}),[Gs,null===(me=null==gt?void 0:gt.data)||void 0===me?void 0:me.workspaceId]);const tn=(({accessGroupType:e,currentUses:t,extraUses:s,limit:n,limitInterval:i})=>{const r=Number(null!=t?t:0),o=Number(null!=s?s:0);return"public"===e&&"one_time"===i?n===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,n-r):n===X.STUDIO_INFINITY_VALUE||o===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:"one_time"===i?Math.max(0,o):Math.max(0,n-r)+o})({accessGroupType:null==Ve?void 0:Ve.type,currentUses:en.currentUses,extraUses:en.extraUses,limit:Xs,limitInterval:Ks}),sn=tn===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(tn)),nn=(({accessGroupType:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=t?t:0);return"public"===e&&"one_time"===n?s===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,s):s===X.STUDIO_INFINITY_VALUE||i===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,i):Math.max(0,s)+Math.max(0,i)})({accessGroupType:null==Ve?void 0:Ve.type,extraUses:en.extraUses,limit:Xs,limitInterval:Ks}),rn=nn===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.ceil(.05*nn),on=Gs?Math.ceil(5*Qt):5,an=rn===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(rn,on),ln=o.useMemo((()=>!!Xt&&(!zt&&(sn!==X.STUDIO_INFINITY_VALUE&&(!(nn<=0||sn>=nn)&&sn<=an)))),[zt,an,sn,Xt,nn]),dn=Boolean(null==Ve?void 0:Ve.hideUpgradeOptions),cn=Boolean(!dn&&((null===(fe=null==Ve?void 0:Ve.upgrade)||void 0===fe?void 0:fe.isBuyMoreUses)||(null===(ge=null==Ve?void 0:Ve.upgrade)||void 0===ge?void 0:ge.isLinkToCustomURL)||(null===(ve=null==Ve?void 0:Ve.upgrade)||void 0===ve?void 0:ve.isUpgradeToAnotherGroup)&&(null===(he=Ve.upgrade.accessGroupIds)||void 0===he?void 0:he.length))),un=!dn&&(null===(be=null==Ve?void 0:Ve.upgrade)||void 0===be?void 0:be.isLinkToCustomURL)&&"string"==typeof Ve.upgrade.limitLink&&Ve.upgrade.limitLink.trim().length>0?Ve.upgrade.limitLink.trim():null,pn=un&&"string"==typeof(null===(xe=null==Ve?void 0:Ve.upgrade)||void 0===xe?void 0:xe.limitCTA)&&Ve.upgrade.limitCTA.trim().length>0?Ve.upgrade.limitCTA:(null==De?void 0:De["pricing.upgrade"])||(null==De?void 0:De.upgrade)||"Upgrade",mn=o.useMemo((()=>{var e,t,s;return!!qe&&(!!Ce&&(!Ot.isLoading&&(!((null!==(t=null===(e=Ot.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=Ce.icebreakers)||void 0===s?void 0:s.length)&&(!Fe&&!Ms)))))}),[Ce,qe,Fe,Ms,Ot.data,Ot.isLoading]),fn=o.useMemo((()=>{if(ct||Ut)return!1;const e=Ds&&dt.length>0&&dt.every((e=>"finished"===e.status));return!(!wt.trim()&&!e)&&dt.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Ds,ct,Ut,wt,dt]);o.useImperativeHandle(ie,(()=>({onSubmit:xn}))),o.useEffect((()=>{Be(mn)}),[mn]),o.useEffect((()=>{var e;if(z){const t=Array.from(st),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;xn(s,!0)}}),[z]),o.useEffect((()=>{if(!ls.current||!se)return;const e=new ResizeObserver((e=>{for(const t of e)se(t.contentRect.height)}));return e.observe(ls.current),()=>{e.disconnect()}}),[se]),o.useEffect((()=>{if(!fs)return;const e=ts.current?`${ts.current} `:"";kt(`${e}${ms}`)}),[ms,fs]),o.useEffect((()=>{if(!os.current)return;(()=>{if(!os.current)return;let e=os.current.scrollHeight>52;wt.includes("\n")||dt.length?e=!0:wt.trim()||(e=!1),Et(e)})()}),[wt,dt]),o.useEffect((()=>{const e=os.current,t=as.current;if(!e||!t||Je||_t||wt.includes("\n"))return void Ct(!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=wt||Vs,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;Ct(r>l)}),[wt,_t,Vs,Je]);const gn=t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:ns.current))return!1;const e=Y(rs.current);try{return(yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/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})},As&&{credentials:"include"}))).ok}catch(e){return console.warn("Failed to cancel submission",e),!1}})),vn=e=>{is.current=e,ds.current&&(ds.current.abort(),ds.current=null),ss.current&&(ss.current.cancel().catch((()=>{})),ss.current=null)},hn=t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Date.now()+3e4;for(;Date.now()<e;){try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/status/${t}`,Object.assign({headers:Object.assign({"Cache-Control":"no-cache"},(!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}))},As&&{credentials:"include"}));if(e.ok){if((yield e.json()).terminal)return!0}}catch(e){console.warn("Failed to read submission status",e)}yield new Promise((e=>setTimeout(e,250)))}return!1})),bn=()=>{const e=ns.current;e&&!Ut&&!ct&&wt.trim()&&(qt((t=>{var s,n;return[...t,{id:H(),message:wt,predecessorSubmissionId:null!==(n=null===(s=t[t.length-1])||void 0===s?void 0:s.id)&&void 0!==n?n:e}]})),kt(""))},xn=(t,n=!1,i=!1,o,a=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,l,d,c,u;if(!s.canChat(Ce))return;let p=null;try{if(nt&&!i||ct||fs||gs)return;const s=dt.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),m=s.map((e=>e.documentId)).filter(Boolean),f=s.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),g=null!=t?t:wt,v=null!==(l=null===(e=null==Ce?void 0:Ce.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==l&&l&&m.length>0;if(!g&&!v)return;at(""),ft(""),ot(null),kt(""),$e(!1),Pt(!1),rt("fetching"),ht(),xt();const h=n?st.slice(0,st.length-1):st,b=(e=>e.reduce(((e,t)=>Math.max(e,t.id)),0)+1)(h),x=b+(n?0:1),I={id:x,role:"assistant",parts:[],documentIds:[]},j=[...h,...n?[]:[{id:b,role:"user",parts:[{type:"text",content:g,isVisible:!0}],documentIds:v?m:[]}],I];it(j),xt(),v&&mt([]);const S=R.getPickaxeConfigMetadata(Ee),N=null!=o?o:H();p=N,ns.current=N,is.current=null,rs.current=[];const O=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({supportsActionConfirmation:!0,selectedModel:ze||void 0,origin:Se,pickaxeId:Ne,sessionId:Oe,submissionId:N},a&&{interactionType:"steer"}),{senderType:ke,value:g}),v&&{documentIds:m}),we&&{sender:we}),Qe&&{studioSessionToken:Qe}),!Qe&&!we&&{sender:M.initializeEmbedUserId()}),Hs&&{portalId:Hs}),Ee&&{deploymentId:Ee}),S&&{metadata:S}),v&&f.length>0?{uploadedModelImages:f}:{})),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()})},As&&{credentials:"include"})),w=yield O.json();if(!w.success){if(w.limitData){const e=new Error(w.error||w.message||(null==De?void 0:De["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=w.limitData,e}if(Fs(w))return;throw new Error(w.error||w.message||(null==De?void 0:De["failed-to-start-generation"])||"Failed to start generation")}lt(null!==(d=w.actionApprovalToken)&&void 0!==d?d:null);const k=null!==(c=w.submissionId)&&void 0!==c?c:N;p=k,ns.current=k;const _=()=>is.current===k;if(_())return;qs&&qe&&Oe&&cs.current.add(Oe);const E=Object.assign(Object.assign({},Ws()),{message:g,documentIds:v?m:[],uploadedModelImages:v?f:[],hasUploadedDocuments:v,isHidden:n,metadata:null!=S?S:null});Yt?(zs(),V.fireDeploymentFirstMessageSubmittedWebhook(E)):us.current=E,rt("streaming"),ds.current=new AbortController;const T=[];let C=[...null!=yt?yt:[]],U=0,A=!1,D="";for(;!A;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/stream/${k}?index=${U}`,{signal:null===(u=ds.current)||void 0===u?void 0:u.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();ss.current=t;const s=new TextDecoder,n=y.createParser({onEvent:e=>{var t,s;if(_())A=!0;else if(e.event&&"ping"!==e.event&&U++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return ot(t.limitData),at(""),void(A=!0);const s=t.error||t.message||(null==De?void 0:De["something-went-wrong"])||"Something went wrong.";return Fs(t)||at(s),void(A=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("finish"===n.type)return void Pt(!0);if("data-error"===n.type&&ne){const e=n.data.error;if("string"==typeof e){const t=/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e),s=/['"]type['"]\s*:\s*['"]unauthorized_composio['"]/.test(e);if(t){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 A=!0,ne({provider:"smithery",smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}else if(s){const t=e.match(/['"]toolkitSlug['"]\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 A=!0,ne({provider:"composio",toolkitSlug: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 A=!0,ne({provider:"smithery",smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM");if("unauthorized_composio"===t.type&&t.toolkitSlug&&t.serverId&&t.name)throw A=!0,ne({provider:"composio",toolkitSlug:t.toolkitSlug,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)D="",T.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)D+=n.delta,r.updateStreamTextPart(T,"text",D);else if("text-end"===n.type)D="";else if("reasoning-start"===n.type)D="",T.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)D+=n.delta,r.updateStreamTextPart(T,"reasoning",D);else if("reasoning-end"===n.type)D="";else if(n.type.startsWith("data-")){const e=n;"data-action-approval"===e.type?r.upsertActionApprovalPart(T,e.data):T.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}rs.current=Y(T);const i=Y(T);it((e=>{const t=e.findIndex((e=>e.id===x)),s=Object.assign(Object.assign({},I),{parts:i});return-1===t?[...e,s]:e.map(((e,n)=>n===t?s:e))}))}else if("artifact_created"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),jt([...C]),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),jt(C),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),jt(C),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");C=C.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),jt(C)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);jt(C.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return ot(t.limitData),at(""),void(A=!0);const s=t.error||t.message||(null==De?void 0:De["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(Fs(t))return void(A=!0);at(s)}else"stop"===e.event&&(A=!0)}else A=!0}});for(;;){if(_()){A=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(_()){A=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}A||_()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||W(e)||_())return void(A=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==We||We(Oe)}catch(e){if(W(e))return;if(e.limitData)ot(e.limitData),at("");else{let t=D.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==De?void 0:De["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),Fs(t)||at(t)}}finally{const e=!p||ns.current===p;xt(),e&&(rt("idle"),bt(),ss.current=null),p&&e&&(ns.current=null,rs.current=[]),yield Bs()}}));return o.useEffect((()=>{if(nt||Ut||Mt||0===Lt.length)return;const t=Lt[0];Rt(!0),Vt(t.id),e.__awaiter(void 0,void 0,void 0,(function*(){try{if(!(yield hn(t.predecessorSubmissionId)))return void at((null==De?void 0:De["queued-message-waiting"])||"A queued message is waiting for the previous response to finish.");qt((e=>e.filter((e=>e.id!==t.id)))),yield xn(t.message,!1,!0,t.id)}finally{Rt(!1),Vt(null)}}))}),[nt,Mt,Ut,Lt]),Rs?null:t.jsx("div",Object.assign({className:q.default("flex w-full flex-shrink-0 flex-col items-center",!Ms&&"px-4 pb-8"),dir:Me?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[Lt.length>0&&t.jsx("div",Object.assign({className:"mx-3 -mb-3 overflow-hidden border pb-3",style:{borderColor:Ae.text+"18",backgroundColor:null!==(ye=Es.backgroundColor)&&void 0!==ye?ye:Ae.text+"08",color:Ae.text,borderTopLeftRadius:Math.max(Ue.cornerRadius-4,12),borderTopRightRadius:Math.max(Ue.cornerRadius-4,12)}},{children:Lt.map(((s,n)=>{var i;return t.jsxs("div",Object.assign({className:"flex min-h-10 items-center gap-2 px-3 py-2",style:n<Lt.length-1?{borderBottom:`1px solid ${Ae.text}12`}:void 0},{children:[t.jsx(N.default,{className:"h-4 w-4 shrink-0 opacity-50","aria-hidden":"true"}),t.jsx("span",Object.assign({className:"min-w-0 flex-1 truncate text-sm",title:s.message},{children:s.message})),$t===s.id||Ft===s.id?t.jsxs("span",Object.assign({className:"flex shrink-0 items-center gap-1.5 px-2 py-1 text-xs opacity-60","aria-live":"polite"},{children:[t.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border border-current border-r-transparent","aria-hidden":"true"}),$t===s.id?(null==De?void 0:De.steering)||"Steering...":(null==De?void 0:De.starting)||"Starting..."]})):t.jsxs(t.Fragment,{children:[t.jsxs("button",Object.assign({type:"button",className:"shrink-0 rounded-md px-2 py-1 text-xs font-medium opacity-70 transition-opacity hover:opacity-100 disabled:cursor-default disabled:opacity-40",disabled:Ut||!nt,onClick:()=>{(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){const e=ns.current;if(!e||Ut)return;const s=Lt.findIndex((e=>e.id===t.id));if(-1===s)return;At(!0),Bt(t.id),at(""),vn(e);let n=!1;try{if(!(yield gn(e)))throw new Error((null==De?void 0:De["failed-to-interrupt-current-response"])||"Failed to interrupt the current response.");if(!(yield hn(e)))throw new Error((null==De?void 0:De["current-response-still-stopping"])||"The current response is still stopping. Please send your message again in a moment.");rt("idle"),qt((e=>e.filter((e=>e.id!==t.id)))),n=!0,At(!1),Bt(null),yield xn(t.message,!1,!0,t.id,!0)}catch(e){rt("idle"),n&&qt((e=>{if(e.some((e=>e.id===t.id)))return e;const n=[...e];return n.splice(s,0,t),n})),at(D.default(e))}finally{At(!1),Bt(null)}}))})(s)},"aria-label":`${(null==De?void 0:De["steer-with"])||"Steer with"}: ${s.message}`},{children:[t.jsx("span",Object.assign({"aria-hidden":"true"},{children:"↳ "})),(null==De?void 0:De.steer)||"Steer"]})),t.jsx("button",Object.assign({type:"button",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md opacity-50 transition-opacity hover:opacity-100 disabled:cursor-default disabled:opacity-30",disabled:Ut,onClick:()=>{return e=s.id,void qt((t=>K(t,e)));var e},"aria-label":`${(null==De?void 0:De["remove-queued-message"])||"Remove queued message"}: ${s.message}`},{children:t.jsx(w.default,{className:"h-4 w-4","aria-hidden":"true"})})),t.jsxs(C.default,Object.assign({id:`queued-message-menu-${s.id}`,className:"shrink-0"},{children:[t.jsx(U.default,Object.assign({className:"flex h-7 w-7 items-center justify-center rounded-md opacity-50 transition-opacity hover:opacity-100",isDisabled:Ut,role:"button",tabIndex:Ut?-1:0,"aria-haspopup":"menu","aria-label":(null==De?void 0:De["more-options"])||"More options",onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.currentTarget.click())}},{children:t.jsxs("svg",Object.assign({viewBox:"0 0 24 24",className:"h-4 w-4",fill:"currentColor","aria-hidden":"true"},{children:[t.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),t.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]}))})),t.jsx(A.default,Object.assign({role:"menu",align:Me?"bottom-start":"bottom-end",positionStrategy:Re?"absolute":"fixed",width:"auto",className:"p-1 text-sm shadow-xl",style:{backgroundColor:null!==(i=Es.backgroundColor)&&void 0!==i?i:Ae.primary,color:Ae.text,borderRadius:"12px"},border:`1px solid ${Ae.text}20`},{children:t.jsxs("button",Object.assign({type:"button",role:"menuitem",className:"flex min-w-36 items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors hover:bg-black/5 dark:hover:bg-white/10",onClick:()=>(e=>{qt((t=>K(t,e.id))),kt(e.message),requestAnimationFrame((()=>{const t=os.current;t&&(t.focus(),t.setSelectionRange(e.message.length,e.message.length))}))})(s)},{children:[t.jsx(k.default,{className:"h-4 w-4 shrink-0"}),(null==De?void 0:De["edit-message"])||"Edit message"]}))}))]}))]})]}),s.id)}))})),t.jsxs("div",Object.assign({ref:ls,className:q.default("relative z-10 flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===Ue.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Es),{maxHeight:`${ps}px`,overflowY:"auto"})},{children:[ln&&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:Es.backgroundColor?`${Es.backgroundColor}E6`:void 0,borderColor:Ae.text+"20",color:Ae.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:[sn.toLocaleString()," ",Gs?(null==De?void 0:De.credits)||"Credits":(null==De?void 0:De.uses)||"Uses"," ",(null==De?void 0:De.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[cn&&t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:Ae.accent,color:Ae.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),un)return void window.open(un,"_blank","noopener,noreferrer");if(Ye)return void Ye();const t=M.buildUpgradeUrl({baseUrl:Gt,accessGroupId:null==Ve?void 0:Ve.accessGroupId});t&&M.openAuthenticatedPricingUrl({deploymentId:Ee,pricingUrl:t,studioId:null==Ce?void 0:Ce.studioid,studioSessionToken:Qe})}},{children:pn})),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:()=>Jt(!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"})}))}))]}))]})),!nt&&dt.length>0&&t.jsx(_.default,{className:"p-4 pb-0",isDisabled:nt}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[Ls&&t.jsxs("div",Object.assign({className:q.default(Je?"top-6":"top-1/2","pointer-events-none absolute z-10 flex -translate-y-1/2 select-none items-center gap-x-2",Me?"right-4":"left-4")},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(Ie=Ae.accent)&&void 0!==Ie?Ie:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:Ae.text+"90"}},{children:(null==De?void 0:De.listening)||"Listening..."}))]})),t.jsx(E.default,Object.assign({ref:os,className:q.default(_s.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!wt.trim()&&!wt.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",Me?"text-right":"text-left",!Je&&$s&&"mb-12"),value:wt,placeholder:Ls?"":Vs,onChange:e=>{kt(e)},onKeyDown:e=>{Le||vt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ct||Ut||(nt?bn():xn())))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Ds)return;t.preventDefault(),$e(!1),yield pt(e)}}))},ee&&{onFocus:ee},te&&{onBlur:te},{dir:Me?"rtl":"ltr"})),t.jsxs("div",Object.assign({ref:as,className:Je?"relative flex w-full items-center gap-2 px-3 pb-2 [&>button]:shrink-0 [&>button]:mr-0":q.default("flex items-center gap-2 absolute z-2 transition-all duration-200 ease-in-out",$s?"bottom-3 right-2":"right-0 top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!$s&&Es.backgroundColor&&{backgroundColor:Es.backgroundColor}),{borderTopRightRadius:Ue.cornerRadius+"px",borderBottomRightRadius:Ue.cornerRadius+"px"})},{children:[!nt&&!fs&&Ds&&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:Ss?Ae.accent+"10":void 0,color:Ss?Ae.accent:Ae.accent+"80"},disabled:ct||nt,"aria-label":null!==(je=null==De?void 0:De["attach-files"])&&void 0!==je?je:"Attach files",onClick:()=>{var e;return null===(e=es.current)||void 0===e?void 0:e.click()}},Ns,{children:[t.jsx("input",{id:"file-upload",ref:es,type:"file",accept:[...x.allowedFileMimeTypes,...x.allowedImageMimeTypes,...x.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){$e(!1),yield pt(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(I.default,{className:"h-6 w-6 shrink-0"})]})),t.jsx(i.default,{compact:!0}),nt&&!Dt?t.jsxs(t.Fragment,{children:[t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["stop-response"])||"Stop response",className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const e=ns.current;e&&(vn(e),gn(e)),rt("idle")},style:{backgroundColor:Ae.accent+"10",color:Ae.accent}},{children:t.jsx(O.default,{className:"h-4 w-4 shrink-0"})})),t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["queue-message"])||"Queue message",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",disabled:Ut||ct||!wt.trim(),onClick:bn,style:{backgroundColor:wt.trim()?Ae.accent:Ae.accent+"10",color:wt.trim()?Ae.accentText:Ae.accent+"80"}},{children:t.jsx(j.default,{className:q.default("h-6 w-6 shrink-0",Me&&"scale-x-[-1] transform")})}))]}):fs||gs?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:()=>{bs()},disabled:gs,style:{backgroundColor:Ae.accent,color:Ae.accentText}},{children:t.jsx(O.default,{className:"h-4 w-4 shrink-0"})})):t.jsxs(t.Fragment,{children:[Ps&&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:fs?Ae.accent:ws?Ae.accent+"10":void 0,color:fs?Ae.accentText:ws?Ae.accent:Ae.accent+"80"},disabled:ct||nt||gs,onClick:()=>{fs?bs():(ts.current=wt,hs(Pe||"en-US"))}},ks,{children:t.jsx(S.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:ys||fn?Ae.accent:Ae.accent+"10",color:ys||fn?Ae.accentText:Ae.accent+"80"},disabled:!fn,onClick:()=>xn()},Is,{children:t.jsx(j.default,{className:q.default("h-6 w-6 shrink-0",Me&&"scale-x-[-1] transform")})}))]})]}))]}))]})),ut&&t.jsx(T.default,{error:ut,className:"mt-3"})]}))}))}));ee.displayName="Input",exports.default=ee;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),s=require("../../../common/canChat.js"),n=require("../../../hooks/pickaxe/useEndUserModel.js"),i=require("../common/EndUserModelPicker.js"),r=require("../../../common/actionApproval.js"),o=require("react"),a=require("../../../hooks/pickaxe/usePickaxeContext.js"),l=require("../../../hooks/pickaxe/useResponseContext.js"),d=require("../../../hooks/studio/useStyleInput.js"),c=require("../../../hooks/studio/useStyleFontSize.js"),u=require("../../../hooks/pickaxe/useConversation.js"),p=require("../../../hooks/pickaxe/useDimensionContext.js"),m=require("../Addons/Auth/hooks/useAuthContext.js"),f=require("../Addons/Document/hooks/useDocument.js"),g=require("../Addons/Scroll/hooks/useScroll.js"),v=require("../Addons/Artifact/hooks/useArtifactContext.js"),h=require("../../../hooks/core/useHover.js"),b=require("../../../hooks/core/useMediaQuery.js"),x=require("../../../common/documents.js"),y=require("eventsource-parser"),I=require("../../Icons/attach-vertical.svg.js"),j=require("../../Icons/arrow-right.svg.js"),S=require("../../Icons/microphone.svg.js"),N=require("../../Icons/message-clock.svg.js"),w=require("../../Icons/stop.svg.js"),O=require("../../Icons/trash.svg.js"),k=require("../../Icons/pencil.svg.js"),_=require("../Addons/Document/List.js"),T=require("../../Core/Textarea.js"),E=require("../../Core/ErrorAlert.js"),C=require("../../Core/Menu/index.js"),U=require("../../Core/Menu/Button.js"),A=require("../../Core/Menu/List.js"),D=require("../../../common/error.js"),P=require("../../../common/api/pickaxe.js"),L=require("../../../common/validation.js"),q=require("../../../common/cn.js"),M=require("../../../common/utils.js"),R=require("../../../common/pickaxeConfig.js"),F=require("../../../common/agentPrefill.js"),V=require("../../../common/deploymentWebhooks.js"),$=require("../../../hooks/studio/useStudio.js"),B=require("../../../hooks/pickaxe/useSpeechToText.js"),X=require("../common/PickaxeCommon.js");const K=(e,t)=>{const s=e.find((e=>e.id===t));return s?e.filter((e=>e.id!==t)).map((e=>e.predecessorSubmissionId===t?Object.assign(Object.assign({},e),{predecessorSubmissionId:s.predecessorSubmissionId}):e)):e},G=e=>"string"==typeof e&&e.trim().length>0,H=()=>"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`submission-${Date.now()}-${Math.random().toString(36).slice(2)}`,Y=e=>e.map((e=>Object.assign({},e))),W=e=>e instanceof Error&&("AbortError"===e.name||"BodyStreamBuffer was aborted"===e.message),z=(e,t)=>{if(e&&"object"==typeof e)return e[t]},J=(e,t)=>{const s=z(e,t);return G(s)?s:null},Q=e=>{const t=Number(e);return Number.isFinite(t)?t:void 0},Z=({studioUser:e,deploymentId:t,portalId:s})=>{var n,i;const r=Array.isArray(z(e,"uses"))?z(e,"uses"):[],o=(({deploymentId:e,portalId:t})=>G(e)?{type:"deployment",id:e}:G(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}},ee=o.forwardRef((({resubmitPrompt:z,onFocus:ee,onBlur:te,onInputHeightChange:se,initSmitheryAuthData:ne},ie)=>{var re,oe,ae,le,de,ce,ue,pe,me,fe,ge,ve,he,be,xe,ye,Ie,je;const{origin:Se,pickaxeId:Ne,sessionId:we,sender:Oe,senderType:ke,portalId:_e,deploymentId:Te,deploymentType:Ee,pickaxe:Ce,styles:Ue,colors:Ae,translations:De,locale:Pe,forceMobile:Le,isNewChat:qe,isRtl:Me,isEmbed:Re,isShowFeedbackMessage:Fe,accessGroup:Ve,setIsNewChat:$e,setIsShowIceBreaker:Be,setValidationStatus:Xe,setValidationUpgradeGroups:Ke,setValidationUpgradeUrl:Ge,setAccessGroup:He,onUpgrade:Ye,onGenerateComplete:We}=a.usePickaxeContext(),{value:ze,enabled:Je}=n.useEndUserModel(),{token:Qe,isLoggedOut:Ze,isSent:et,isPricingAuth:tt}=m.useAuthContext(),{messages:st,isGenerating:nt,setMessages:it,setStatus:rt,setLimitData:ot,setError:at,setActionApprovalToken:lt}=l.useResponseContext(),{documents:dt,isUploading:ct,documentError:ut,onFileUpload:pt,setDocuments:mt,setDocumentError:ft}=f.useDocument(),{studio:gt}=$.useStudio(),[vt]=b.useMediaQuery("(max-width: 480px)"),{scrollStartSession:ht,scrollEndSession:bt,scrollToBottom:xt}=g.useScroll({auto:!0,smooth:!(Le||vt)}),{artifacts:yt,currentPopupType:It,setArtifacts:jt,setCurrentArtifact:St}=v.useArtifactContext(),{height:Nt}=p.useDimensionContext(),wt=u.useConversation(),[Ot,kt]=o.useState((()=>F.readAgentPrefill([Te,Ne]).chatInput)),[_t,Tt]=o.useState(null),[Et,Ct]=o.useState(!1),[Ut,At]=o.useState(!1),[Dt,Pt]=o.useState(!1),[Lt,qt]=o.useState(!1),[Mt,Rt]=o.useState([]),[Ft,Vt]=o.useState(!1),[$t,Bt]=o.useState(null),[Xt,Kt]=o.useState(null),[Gt,Ht]=o.useState(null),[Yt,Wt]=o.useState(null),[zt,Jt]=o.useState(!1),[Qt,Zt]=o.useState(!1),[es,ts]=o.useState(0),ss=o.useRef(null),ns=o.useRef(""),is=o.useRef(null),rs=o.useRef(null),os=o.useRef(null),as=o.useRef([]),ls=o.useRef(null),ds=o.useRef(null),cs=o.useRef(null),us=o.useRef(null),ps=o.useRef(new Set),ms=o.useRef(null),fs=Math.max(.4*Nt,100),{speechTranscript:gs,isSpeechListening:vs,isSpeechProcessing:hs,isSpeechSupported:bs,getSpeechTranscriptSnapshot:xs,speechTranscriptRevision:ys,resetSpeechTranscript:Is,onStartListening:js,onStopListening:Ss}=B.useSpeechToText(),Ns=h.useHover(),{isHover:ws}=Ns,Os=e.__rest(Ns,["isHover"]),ks=h.useHover(),{isHover:_s}=ks,Ts=e.__rest(ks,["isHover"]),Es=h.useHover(),{isHover:Cs}=Es,Us=e.__rest(Es,["isHover"]),As=c.useStyleFontSize(),Ds=d.useStyleInput(),Ps="undefined"!=typeof window?window.location.hostname:"",Ls="undefined"!=typeof window?window.location.href:"",qs="undefined"!=typeof window&&window.self!==window.top,Ms=Ps.includes("pickaxe.co")&&!Ls.includes("https://studio.pickaxe.co/_embed")&&!qs,Rs=null!==(oe=null===(re=null==Ce?void 0:Ce.documentuploadtype)||void 0===re?void 0:re.startsWith("enduserupload"))&&void 0!==oe&&oe,Fs=bs&&(null==Ce?void 0:Ce.enablevoicetotext),Vs=vs&&!Ot.trim(),$s=G(Te),Bs="chat-input"===Ee&&qe&&!et,Xs="chat-input"===Ee&&tt&&Ze&&et,Ks=o.useCallback((e=>{const t=L.getValidationFailure(e);return!!t&&(at(""),ot(null),Xe(t.status),He(t.accessGroup),Ke(t.upgradeGroups),Ge(t.upgradeUrl),!0)}),[at,lt,ot,Xe,Ke,Ge,He]),Gs=null!==(ae=null==Ce?void 0:Ce.placeholdertext)&&void 0!==ae?ae:Me?"بماذا تريد أن تتحدث؟":(null==De?void 0:De["what-do-you-want-to-talk-about"])||"What do you want to talk about?",Hs=Et||Ut,Ys=o.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){Jt(!1);try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/user`,Object.assign(Object.assign({method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign({studioId:null==Ce?void 0:Ce.studioid},Qe?{studioSessionToken:Qe}:Oe?{sender:Oe}:{sender:M.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}})),Ms&&{credentials:"include"})),t=yield e.json();(null==t?void 0:t.studioUser)&&(Ht(t.studioUser),Wt(t.url))}catch(e){console.error("Failed to fetch studio user:",e)}finally{Jt(!0)}}))),[Ms,null==Ce?void 0:Ce.studioid,Oe,Qe]);o.useEffect((()=>{Ys()}),[Ys]);const Ws=Number(null!==(le=null==Ve?void 0:Ve.limit)&&void 0!==le?le:0),zs="string"==typeof(null==Ve?void 0:Ve.limitInterval)?Ve.limitInterval:null,Js=!!(null==gt?void 0:gt.data.usage)&>.data.usage.isCredits,Qs=o.useMemo((()=>{var e,t,s,n,i;return null!==(i=null!==(n=null!==(s=null!==(t=null!==(e=null!=_e?_e:J(Gt,"portalId"))&&void 0!==e?e:J(Gt,"portalid"))&&void 0!==t?t:J(Ve,"portalId"))&&void 0!==s?s:J(Ve,"portalid"))&&void 0!==n?n:J(Ce,"portalId"))&&void 0!==i?i:J(Ce,"portalid")}),[Ve,_e,Ce,Gt]),Zs=o.useMemo((()=>Z({studioUser:Gt,deploymentId:Te,portalId:Qs})),[Te,Qs,Gt]);o.useEffect((()=>{$s&&qe&&we&&ps.current.add(we)}),[qe,we,$s]);const en=o.useCallback((()=>{var e,t,s;return{studioId:null==Ce?void 0:Ce.studioid,userEmail:J(Gt,"email"),userId:null!==(e=J(Gt,"userId"))&&void 0!==e?e:J(Gt,"userid"),sessionId:we,deploymentId:Te,deploymentType:Ee,portalId:Qs,accessGroupId:null!==(t=null==Ve?void 0:Ve.accessGroupId)&&void 0!==t?t:null,pickaxeId:Ne,sender:Oe,senderType:ke,origin:Se,metadata:null!==(s=R.getPickaxeConfigMetadata(Te))&&void 0!==s?s:null}}),[null==Ve?void 0:Ve.accessGroupId,Te,Ee,Se,null==Ce?void 0:Ce.studioid,Ne,Qs,Oe,ke,we,Gt]),tn=o.useCallback((()=>!!($s&&zt&&we)&&(!!ps.current.has(we)&&(V.fireDeploymentSessionInitializedWebhook(en()),ps.current.delete(we),!0))),[en,zt,we,$s]);o.useEffect((()=>{if(!zt||!we)return;tn();const e=ms.current;(null==e?void 0:e.sessionId)===we&&(V.fireDeploymentFirstMessageSubmittedWebhook(Object.assign(Object.assign(Object.assign({},e),en()),{message:e.message,documentIds:e.documentIds,uploadedModelImages:e.uploadedModelImages,hasUploadedDocuments:e.hasUploadedDocuments,isHidden:e.isHidden})),ms.current=null)}),[tn,en,zt,we]);const sn={currentUses:Q(null==Gt?void 0:Gt.currentUses),extraUses:Q(null==Gt?void 0:Gt.extraUses)},nn=Zs.scope?{currentUses:null!==(ce=Q(null===(de=Zs.record)||void 0===de?void 0:de.currentUses))&&void 0!==ce?ce:0,extraUses:null!==(pe=Q(null===(ue=Zs.record)||void 0===ue?void 0:ue.extraUses))&&void 0!==pe?pe:0}:{currentUses:0,extraUses:0},rn=J(Gt,"type"),on="guest"===rn||!rn&&Ze?nn:sn;o.useEffect((()=>{let t=!0;return e.__awaiter(void 0,void 0,void 0,(function*(){var e;if(Js&&(null===(e=null==gt?void 0:gt.data)||void 0===e?void 0:e.workspaceId))try{const e=yield P.pickaxeApi2.get(`/cost_per_run?workspaceId=${gt.data.workspaceId}`,{withCredentials:!1});t&&ts(1e4*(Number(e.data.costPerRun)||0))}catch(e){console.error("Failed to fetch average cost per run:",e),t&&ts(0)}else t&&ts(0)})),()=>{t=!1}}),[Js,null===(me=null==gt?void 0:gt.data)||void 0===me?void 0:me.workspaceId]);const an=(({accessGroupType:e,currentUses:t,extraUses:s,limit:n,limitInterval:i})=>{const r=Number(null!=t?t:0),o=Number(null!=s?s:0);return"public"===e&&"one_time"===i?n===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,n-r):n===X.STUDIO_INFINITY_VALUE||o===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:"one_time"===i?Math.max(0,o):Math.max(0,n-r)+o})({accessGroupType:null==Ve?void 0:Ve.type,currentUses:on.currentUses,extraUses:on.extraUses,limit:Ws,limitInterval:zs}),ln=an===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,Math.ceil(an)),dn=(({accessGroupType:e,extraUses:t,limit:s,limitInterval:n})=>{const i=Number(null!=t?t:0);return"public"===e&&"one_time"===n?s===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(0,s):s===X.STUDIO_INFINITY_VALUE||i===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:"one_time"===n?Math.max(0,i):Math.max(0,s)+Math.max(0,i)})({accessGroupType:null==Ve?void 0:Ve.type,extraUses:on.extraUses,limit:Ws,limitInterval:zs}),cn=dn===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.ceil(.05*dn),un=Js?Math.ceil(5*es):5,pn=cn===X.STUDIO_INFINITY_VALUE?X.STUDIO_INFINITY_VALUE:Math.max(cn,un),mn=o.useMemo((()=>!!Gt&&(!Qt&&(ln!==X.STUDIO_INFINITY_VALUE&&(!(dn<=0||ln>=dn)&&ln<=pn)))),[Qt,pn,ln,Gt,dn]),fn=Boolean(null==Ve?void 0:Ve.hideUpgradeOptions),gn=Boolean(!fn&&((null===(fe=null==Ve?void 0:Ve.upgrade)||void 0===fe?void 0:fe.isBuyMoreUses)||(null===(ge=null==Ve?void 0:Ve.upgrade)||void 0===ge?void 0:ge.isLinkToCustomURL)||(null===(ve=null==Ve?void 0:Ve.upgrade)||void 0===ve?void 0:ve.isUpgradeToAnotherGroup)&&(null===(he=Ve.upgrade.accessGroupIds)||void 0===he?void 0:he.length))),vn=!fn&&(null===(be=null==Ve?void 0:Ve.upgrade)||void 0===be?void 0:be.isLinkToCustomURL)&&"string"==typeof Ve.upgrade.limitLink&&Ve.upgrade.limitLink.trim().length>0?Ve.upgrade.limitLink.trim():null,hn=vn&&"string"==typeof(null===(xe=null==Ve?void 0:Ve.upgrade)||void 0===xe?void 0:xe.limitCTA)&&Ve.upgrade.limitCTA.trim().length>0?Ve.upgrade.limitCTA:(null==De?void 0:De["pricing.upgrade"])||(null==De?void 0:De.upgrade)||"Upgrade",bn=o.useMemo((()=>{var e,t,s;return!!qe&&(!!Ce&&(!wt.isLoading&&(!((null!==(t=null===(e=wt.data)||void 0===e?void 0:e.messages.length)&&void 0!==t?t:0)>1)&&(!!(null===(s=Ce.icebreakers)||void 0===s?void 0:s.length)&&(!Fe&&!Bs)))))}),[Ce,qe,Fe,Bs,wt.data,wt.isLoading]),xn=o.useMemo((()=>{if(ct||Dt)return!1;const e=Rs&&dt.length>0&&dt.every((e=>"finished"===e.status));return!(!Ot.trim()&&!e)&&dt.every((e=>"finished"===e.status||e.isInsertedAsRaw))}),[Rs,ct,Dt,Ot,dt]);o.useImperativeHandle(ie,(()=>({onSubmit:wn}))),o.useEffect((()=>{Be(bn)}),[bn]),o.useEffect((()=>{var e;if(z){const t=Array.from(st),s=null===(e=t[t.length-2].parts.find((e=>"text"===e.type)))||void 0===e?void 0:e.content;wn(s,!0)}}),[z]),o.useEffect((()=>{if(!cs.current||!se)return;const e=new ResizeObserver((e=>{for(const t of e)se(t.contentRect.height)}));return e.observe(cs.current),()=>{e.disconnect()}}),[se]),o.useEffect((()=>{if(!vs)return;const e=ns.current?`${ns.current} `:"",t=xs();Tt(t),kt(`${e}${t.text}`)}),[gs,ys,vs,xs]);const yn=()=>{ns.current="",Is(_t),Tt(null)};o.useEffect((()=>{if(!ls.current)return;(()=>{if(!ls.current)return;let e=ls.current.scrollHeight>52;Ot.includes("\n")||dt.length?e=!0:Ot.trim()||(e=!1),Ct(e)})()}),[Ot,dt]),o.useEffect((()=>{const e=ls.current,t=ds.current;if(!e||!t||Je||Et||Ot.includes("\n"))return void At(!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=Ot||Gs,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;At(r>l)}),[Ot,Et,Gs,Je]);const In=t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!(t=null!=t?t:rs.current))return!1;const e=Y(as.current);try{return(yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/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})},Ms&&{credentials:"include"}))).ok}catch(e){return console.warn("Failed to cancel submission",e),!1}})),jn=e=>{os.current=e,us.current&&(us.current.abort(),us.current=null),is.current&&(is.current.cancel().catch((()=>{})),is.current=null)},Sn=t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Date.now()+3e4;for(;Date.now()<e;){try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/status/${t}`,Object.assign({headers:Object.assign({"Cache-Control":"no-cache"},(!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}))},Ms&&{credentials:"include"}));if(e.ok){if((yield e.json()).terminal)return!0}}catch(e){console.warn("Failed to read submission status",e)}yield new Promise((e=>setTimeout(e,250)))}return!1})),Nn=()=>{const e=rs.current;e&&!Dt&&!ct&&Ot.trim()&&(yn(),Rt((t=>{var s,n;return[...t,{id:H(),message:Ot,predecessorSubmissionId:null!==(n=null===(s=t[t.length-1])||void 0===s?void 0:s.id)&&void 0!==n?n:e}]})),kt(""))},wn=(t,n=!1,i=!1,o,a=!1)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e,l,d,c,u;if(!s.canChat(Ce))return;let p=null;try{if(nt&&!i||ct)return;const s=dt.filter((e=>"finished"===e.status&&!e.isInsertedAsRaw)),m=s.map((e=>e.documentId)).filter(Boolean),f=s.filter((e=>"image"===e.type)).map((e=>{const t=e.name.split(".").pop()||"";return{documentId:e.documentId,extension:t}})),g=null!=t?t:Ot,v=null!==(l=null===(e=null==Ce?void 0:Ce.documentuploadtype)||void 0===e?void 0:e.startsWith("enduserupload"))&&void 0!==l&&l&&m.length>0;if(!g.trim()&&!v)return;if((vs||hs)&&!g.trim())return;o||(yn(),kt("")),at(""),ft(""),ot(null),$e(!1),qt(!1),rt("fetching"),ht(),xt();const h=n?st.slice(0,st.length-1):st,b=(e=>e.reduce(((e,t)=>Math.max(e,t.id)),0)+1)(h),x=b+(n?0:1),I={id:x,role:"assistant",parts:[],documentIds:[]},j=[...h,...n?[]:[{id:b,role:"user",parts:[{type:"text",content:g,isVisible:!0}],documentIds:v?m:[]}],I];it(j),xt(),v&&mt([]);const S=R.getPickaxeConfigMetadata(Te),N=null!=o?o:H();p=N,rs.current=N,os.current=null,as.current=[];const w=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/submit`,Object.assign({method:"POST",body:JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({supportsActionConfirmation:!0,selectedModel:ze||void 0,origin:Se,pickaxeId:Ne,sessionId:we,submissionId:N},a&&{interactionType:"steer"}),{senderType:ke,value:g}),v&&{documentIds:m}),Oe&&{sender:Oe}),Qe&&{studioSessionToken:Qe}),!Qe&&!Oe&&{sender:M.initializeEmbedUserId()}),Qs&&{portalId:Qs}),Te&&{deploymentId:Te}),S&&{metadata:S}),v&&f.length>0?{uploadedModelImages:f}:{})),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()})},Ms&&{credentials:"include"})),O=yield w.json();if(!O.success){if(O.limitData){const e=new Error(O.error||O.message||(null==De?void 0:De["failed-to-start-generation"])||"Failed to start generation");throw e.limitData=O.limitData,e}if(Ks(O))return;throw new Error(O.error||O.message||(null==De?void 0:De["failed-to-start-generation"])||"Failed to start generation")}lt(null!==(d=O.actionApprovalToken)&&void 0!==d?d:null);const k=null!==(c=O.submissionId)&&void 0!==c?c:N;p=k,rs.current=k;const _=()=>os.current===k;if(_())return;$s&&qe&&we&&ps.current.add(we);const T=Object.assign(Object.assign({},en()),{message:g,documentIds:v?m:[],uploadedModelImages:v?f:[],hasUploadedDocuments:v,isHidden:n,metadata:null!=S?S:null});zt?(tn(),V.fireDeploymentFirstMessageSubmittedWebhook(T)):ms.current=T,rt("streaming"),us.current=new AbortController;const E=[];let C=[...null!=yt?yt:[]],U=0,A=!1,D="";for(;!A;)try{const e=yield fetch(`${process.env.NEXT_PUBLIC_PICKAXE_API2_URL}/response/stream/${k}?index=${U}`,{signal:null===(u=us.current)||void 0===u?void 0:u.signal,headers:{"Cache-Control":"no-cache",Connection:"keep-alive"}});if(!e.body)throw new Error("No response body");const t=e.body.getReader();is.current=t;const s=new TextDecoder,n=y.createParser({onEvent:e=>{var t,s;if(_())A=!0;else if(e.event&&"ping"!==e.event&&U++,"stop"!==e.event){if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return ot(t.limitData),at(""),void(A=!0);const s=t.error||t.message||(null==De?void 0:De["something-went-wrong"])||"Something went wrong.";return Ks(t)||at(s),void(A=!0)}if("delta"===e.event){const n=JSON.parse(e.data);if("finish"===n.type)return void qt(!0);if("data-error"===n.type&&ne){const e=n.data.error;if("string"==typeof e){const t=/['"]type['"]\s*:\s*['"]unauthorized_smithery['"]/.test(e),s=/['"]type['"]\s*:\s*['"]unauthorized_composio['"]/.test(e);if(t){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 A=!0,ne({provider:"smithery",smitheryId:t[1],serverId:s[1],name:n[1]}),new Error("STOP_STREAM")}else if(s){const t=e.match(/['"]toolkitSlug['"]\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 A=!0,ne({provider:"composio",toolkitSlug: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 A=!0,ne({provider:"smithery",smitheryId:t.qualifiedName,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM");if("unauthorized_composio"===t.type&&t.toolkitSlug&&t.serverId&&t.name)throw A=!0,ne({provider:"composio",toolkitSlug:t.toolkitSlug,serverId:t.serverId,name:t.name}),new Error("STOP_STREAM")}}else if("text-start"===n.type)D="",E.push({type:"text",content:"",isVisible:null===(t=n.isVisible)||void 0===t||t});else if("text-delta"===n.type)D+=n.delta,r.updateStreamTextPart(E,"text",D);else if("text-end"===n.type)D="";else if("reasoning-start"===n.type)D="",E.push({type:"reasoning",content:"",isVisible:null===(s=n.isVisible)||void 0===s||s});else if("reasoning-delta"===n.type)D+=n.delta,r.updateStreamTextPart(E,"reasoning",D);else if("reasoning-end"===n.type)D="";else if(n.type.startsWith("data-")){const e=n;"data-action-approval"===e.type?r.upsertActionApprovalPart(E,e.data):E.push({type:e.type,content:JSON.stringify(e.data),isVisible:!0})}as.current=Y(E);const i=Y(E);it((e=>{const t=e.findIndex((e=>e.id===x)),s=Object.assign(Object.assign({},I),{parts:i});return-1===t?[...e,s]:e.map(((e,n)=>n===t?s:e))}))}else if("artifact_created"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),jt([...C]),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_updated"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"updating"})),jt(C),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_rewrite"===e.event){const t=JSON.parse(e.data);C=C.filter((e=>!(e.id===t.id&&e.version===t.version))),C.push(Object.assign(Object.assign({},t),{content:"",status:"streaming"})),jt(C),It.startsWith("inline")||St({id:t.id,version:t.version})}else if("artifact_content"===e.event){const t=JSON.parse(e.data),s=t.token.replace(/\u200B/g,"");C=C.map((e=>e.id===t.id&&e.version===t.version?Object.assign(Object.assign({},e),{content:e.content+s,status:"streaming"}):e)),jt(C)}else if("artifact_finished"===e.event){const t=JSON.parse(e.data);jt(C.map((e=>e.id===t.id?Object.assign(Object.assign({},e),{status:"finished"}):e)))}else if("error"===e.event){const t=JSON.parse(e.data);if(t.limitData)return ot(t.limitData),at(""),void(A=!0);const s=t.error||t.message||(null==De?void 0:De["something-went-wrong-try-again"])||"Something went wrong, please try again.";if(Ks(t))return void(A=!0);at(s)}else"stop"===e.event&&(A=!0)}else A=!0}});for(;;){if(_()){A=!0,t.cancel().catch((()=>{}));break}const{value:e,done:i}=yield t.read();if(_()){A=!0,t.cancel().catch((()=>{}));break}if(i)break;n.feed(s.decode(e))}A||_()||(yield new Promise((e=>setTimeout(e,1e3))))}catch(e){if("STOP_STREAM"===e.message||W(e)||_())return void(A=!0);console.warn("Stream connection lost, retrying...",e),yield new Promise((e=>setTimeout(e,1e3)))}null==We||We(we)}catch(e){if(W(e))return;if(e.limitData)ot(e.limitData),at("");else{let t=D.default(e)||"";t&&!t.includes("Unexpected token 'A',")||(t=(null==De?void 0:De["high-traffic-try-again-later"])||"Oops! We're experiencing high traffic at the moment. Please try again later."),Ks(t)||at(t)}}finally{const e=!p||rs.current===p;xt(),e&&(rt("idle"),bt(),is.current=null),p&&e&&(rs.current=null,as.current=[]),yield Ys()}}));return o.useEffect((()=>{if(nt||Dt||Ft||0===Mt.length)return;const t=Mt[0];Vt(!0),Bt(t.id),e.__awaiter(void 0,void 0,void 0,(function*(){try{if(!(yield Sn(t.predecessorSubmissionId)))return void at((null==De?void 0:De["queued-message-waiting"])||"A queued message is waiting for the previous response to finish.");Rt((e=>e.filter((e=>e.id!==t.id)))),yield wn(t.message,!1,!0,t.id)}finally{Vt(!1),Bt(null)}}))}),[nt,Ft,Dt,Mt]),Xs?null:t.jsx("div",Object.assign({className:q.default("flex w-full flex-shrink-0 flex-col items-center",!Bs&&"px-4 pb-8"),dir:Me?"rtl":"ltr"},{children:t.jsxs("div",Object.assign({className:"flex w-full max-w-[800px] flex-col"},{children:[Mt.length>0&&t.jsx("div",Object.assign({className:"mx-3 -mb-3 overflow-hidden border pb-3",style:{borderColor:Ae.text+"18",backgroundColor:null!==(ye=Ds.backgroundColor)&&void 0!==ye?ye:Ae.text+"08",color:Ae.text,borderTopLeftRadius:Math.max(Ue.cornerRadius-4,12),borderTopRightRadius:Math.max(Ue.cornerRadius-4,12)}},{children:Mt.map(((s,n)=>{var i;return t.jsxs("div",Object.assign({className:"flex min-h-10 items-center gap-2 px-3 py-2",style:n<Mt.length-1?{borderBottom:`1px solid ${Ae.text}12`}:void 0},{children:[t.jsx(N.default,{className:"h-4 w-4 shrink-0 opacity-50","aria-hidden":"true"}),t.jsx("span",Object.assign({className:"min-w-0 flex-1 truncate text-sm",title:s.message},{children:s.message})),Xt===s.id||$t===s.id?t.jsxs("span",Object.assign({className:"flex shrink-0 items-center gap-1.5 px-2 py-1 text-xs opacity-60","aria-live":"polite"},{children:[t.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border border-current border-r-transparent","aria-hidden":"true"}),Xt===s.id?(null==De?void 0:De.steering)||"Steering...":(null==De?void 0:De.starting)||"Starting..."]})):t.jsxs(t.Fragment,{children:[t.jsxs("button",Object.assign({type:"button",className:"shrink-0 rounded-md px-2 py-1 text-xs font-medium opacity-70 transition-opacity hover:opacity-100 disabled:cursor-default disabled:opacity-40",disabled:Dt||!nt,onClick:()=>{(t=>{e.__awaiter(void 0,void 0,void 0,(function*(){const e=rs.current;if(!e||Dt)return;const s=Mt.findIndex((e=>e.id===t.id));if(-1===s)return;Pt(!0),Kt(t.id),at(""),jn(e);let n=!1;try{if(!(yield In(e)))throw new Error((null==De?void 0:De["failed-to-interrupt-current-response"])||"Failed to interrupt the current response.");if(!(yield Sn(e)))throw new Error((null==De?void 0:De["current-response-still-stopping"])||"The current response is still stopping. Please send your message again in a moment.");rt("idle"),Rt((e=>e.filter((e=>e.id!==t.id)))),n=!0,Pt(!1),Kt(null),yield wn(t.message,!1,!0,t.id,!0)}catch(e){rt("idle"),n&&Rt((e=>{if(e.some((e=>e.id===t.id)))return e;const n=[...e];return n.splice(s,0,t),n})),at(D.default(e))}finally{Pt(!1),Kt(null)}}))})(s)},"aria-label":`${(null==De?void 0:De["steer-with"])||"Steer with"}: ${s.message}`},{children:[t.jsx("span",Object.assign({"aria-hidden":"true"},{children:"↳ "})),(null==De?void 0:De.steer)||"Steer"]})),t.jsx("button",Object.assign({type:"button",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md opacity-50 transition-opacity hover:opacity-100 disabled:cursor-default disabled:opacity-30",disabled:Dt,onClick:()=>{return e=s.id,void Rt((t=>K(t,e)));var e},"aria-label":`${(null==De?void 0:De["remove-queued-message"])||"Remove queued message"}: ${s.message}`},{children:t.jsx(O.default,{className:"h-4 w-4","aria-hidden":"true"})})),t.jsxs(C.default,Object.assign({id:`queued-message-menu-${s.id}`,className:"shrink-0"},{children:[t.jsx(U.default,Object.assign({className:"flex h-7 w-7 items-center justify-center rounded-md opacity-50 transition-opacity hover:opacity-100",isDisabled:Dt,role:"button",tabIndex:Dt?-1:0,"aria-haspopup":"menu","aria-label":(null==De?void 0:De["more-options"])||"More options",onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.currentTarget.click())}},{children:t.jsxs("svg",Object.assign({viewBox:"0 0 24 24",className:"h-4 w-4",fill:"currentColor","aria-hidden":"true"},{children:[t.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),t.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]}))})),t.jsx(A.default,Object.assign({role:"menu",align:Me?"bottom-start":"bottom-end",positionStrategy:Re?"absolute":"fixed",width:"auto",className:"p-1 text-sm shadow-xl",style:{backgroundColor:null!==(i=Ds.backgroundColor)&&void 0!==i?i:Ae.primary,color:Ae.text,borderRadius:"12px"},border:`1px solid ${Ae.text}20`},{children:t.jsxs("button",Object.assign({type:"button",role:"menuitem",className:"flex min-w-36 items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors hover:bg-black/5 dark:hover:bg-white/10",onClick:()=>(e=>{Rt((t=>K(t,e.id))),kt(e.message),requestAnimationFrame((()=>{const t=ls.current;t&&(t.focus(),t.setSelectionRange(e.message.length,e.message.length))}))})(s)},{children:[t.jsx(k.default,{className:"h-4 w-4 shrink-0"}),(null==De?void 0:De["edit-message"])||"Edit message"]}))}))]}))]})]}),s.id)}))})),t.jsxs("div",Object.assign({ref:cs,className:q.default("relative z-10 flex flex-col w-full justify-end gap-y-3 py-[3px]","block"===Ue.formFieldStyle&&"shadow"),style:Object.assign(Object.assign({},Ds),{maxHeight:`${fs}px`,overflowY:"auto"})},{children:[mn&&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:Ds.backgroundColor?`${Ds.backgroundColor}E6`:void 0,borderColor:Ae.text+"20",color:Ae.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:[ln.toLocaleString()," ",Js?(null==De?void 0:De.credits)||"Credits":(null==De?void 0:De.uses)||"Uses"," ",(null==De?void 0:De.remaining)||"remaining"]})})),t.jsxs("div",Object.assign({className:"flex items-center gap-3"},{children:[gn&&t.jsx("button",Object.assign({className:"rounded-md px-3 py-1.5 text-xs font-semibold transition-opacity hover:opacity-90",style:{backgroundColor:Ae.accent,color:Ae.accentText},onClick:e=>{if(e.preventDefault(),e.stopPropagation(),vn)return void window.open(vn,"_blank","noopener,noreferrer");if(Ye)return void Ye();const t=M.buildUpgradeUrl({baseUrl:Yt,accessGroupId:null==Ve?void 0:Ve.accessGroupId});t&&M.openAuthenticatedPricingUrl({deploymentId:Te,pricingUrl:t,studioId:null==Ce?void 0:Ce.studioid,studioSessionToken:Qe})}},{children:hn})),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:()=>Zt(!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"})}))}))]}))]})),!nt&&dt.length>0&&t.jsx(_.default,{className:"p-4 pb-0",isDisabled:nt}),t.jsxs("div",Object.assign({className:"relative flex w-full flex-col"},{children:[Vs&&t.jsxs("div",Object.assign({className:q.default(Je?"top-6":"top-1/2","pointer-events-none absolute z-10 flex -translate-y-1/2 select-none items-center gap-x-2",Me?"right-4":"left-4")},{children:[t.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-c-secondary",style:{backgroundColor:null!==(Ie=Ae.accent)&&void 0!==Ie?Ie:"#ff0000"}}),t.jsx("span",Object.assign({className:"text-sm text-c-secondary font-semilight",style:{color:Ae.text+"90"}},{children:(null==De?void 0:De.listening)||"Listening..."}))]})),t.jsx(T.default,Object.assign({ref:ls,className:q.default(As.i1,"py-3.5 max-h-60 px-4 w-full border-transparent bg-transparent",!Ot.trim()&&!Ot.includes("\n")&&"overflow-hidden text-ellipsis whitespace-nowrap placeholder:whitespace-normal placeholder:overflow-visible",Me?"text-right":"text-left",!Je&&Hs&&"mb-12"),value:Ot,placeholder:Vs?"":Gs,onChange:e=>{kt(e)},onKeyDown:e=>{Le||vt||"Enter"===e.key&&(e.shiftKey||(e.preventDefault(),ct||Dt||(nt?Nn():wn())))},onPaste:t=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=Array.from(t.clipboardData.files||[]);if(e.length>0){if(!Rs)return;t.preventDefault(),$e(!1),yield pt(e)}}))},ee&&{onFocus:ee},te&&{onBlur:te},{dir:Me?"rtl":"ltr"})),t.jsxs("div",Object.assign({ref:ds,className:Je?"relative flex w-full items-center gap-2 px-3 pb-2 [&>button]:shrink-0 [&>button]:mr-0":q.default("flex items-center gap-2 absolute z-2 transition-all duration-200 ease-in-out",Hs?"bottom-3 right-2":"right-0 top-1/2 -translate-y-1/2"),style:Object.assign(Object.assign({},!Hs&&Ds.backgroundColor&&{backgroundColor:Ds.backgroundColor}),{borderTopRightRadius:Ue.cornerRadius+"px",borderBottomRightRadius:Ue.cornerRadius+"px"})},{children:[!nt&&!vs&&Rs&&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:_s?Ae.accent+"10":void 0,color:_s?Ae.accent:Ae.accent+"80"},disabled:ct||nt,"aria-label":null!==(je=null==De?void 0:De["attach-files"])&&void 0!==je?je:"Attach files",onClick:()=>{var e;return null===(e=ss.current)||void 0===e?void 0:e.click()}},Ts,{children:[t.jsx("input",{id:"file-upload",ref:ss,type:"file",accept:[...x.allowedFileMimeTypes,...x.allowedImageMimeTypes,...x.additionalAllowedFileExtensions].join(", "),multiple:!0,hidden:!0,className:"hidden",onChange:t=>e.__awaiter(void 0,void 0,void 0,(function*(){$e(!1),yield pt(Array.from(t.target.files||[])),t.target.value=""}))}),t.jsx(I.default,{className:"h-6 w-6 shrink-0"})]})),t.jsx(i.default,{compact:!0}),nt&&!Lt?t.jsxs(t.Fragment,{children:[(vs||hs)&&t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["stop-listening"])||"Stop listening",title:(null==De?void 0:De["stop-listening"])||"Stop listening",className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{Ss()},disabled:hs,style:{backgroundColor:Ae.accent,color:Ae.accentText}},{children:t.jsx(S.default,{className:"h-5 w-5 shrink-0"})})),t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["stop-response"])||"Stop response",className:"flex h-8 w-8 items-center justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{const e=rs.current;e&&(jn(e),In(e)),rt("idle")},style:{backgroundColor:Ae.accent+"10",color:Ae.accent}},{children:t.jsx(w.default,{className:"h-4 w-4 shrink-0"})})),t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["queue-message"])||"Queue message",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",disabled:Dt||ct||!Ot.trim(),onClick:Nn,style:{backgroundColor:Ot.trim()?Ae.accent:Ae.accent+"10",color:Ot.trim()?Ae.accentText:Ae.accent+"80"}},{children:t.jsx(j.default,{className:q.default("h-6 w-6 shrink-0",Me&&"scale-x-[-1] transform")})}))]}):vs||hs?t.jsxs(t.Fragment,{children:[t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["stop-listening"])||"Stop listening",className:"flex h-8 w-8 items-center mr-2 justify-center rounded-full outline-none transition-colors duration-200 ease-in-out",onClick:()=>{Ss()},disabled:hs,style:{backgroundColor:Ae.accent,color:Ae.accentText}},{children:t.jsx(w.default,{className:"h-4 w-4 shrink-0"})})),Ot.trim()&&t.jsx("button",Object.assign({"aria-label":(null==De?void 0:De["send-message"])||"Send message",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",disabled:!xn,onClick:()=>{wn()},style:{backgroundColor:Ae.accent,color:Ae.accentText}},{children:t.jsx(j.default,{className:q.default("h-6 w-6 shrink-0",Me&&"scale-x-[-1] transform")})}))]}):t.jsxs(t.Fragment,{children:[Fs&&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:vs?Ae.accent:Cs?Ae.accent+"10":void 0,color:vs?Ae.accentText:Cs?Ae.accent:Ae.accent+"80"},disabled:ct||nt||hs,onClick:()=>{vs?Ss():(Tt(null),ns.current=Ot,js(Pe||"en-US"))}},Us,{children:t.jsx(S.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:ws||xn?Ae.accent:Ae.accent+"10",color:ws||xn?Ae.accentText:Ae.accent+"80"},disabled:!xn,onClick:()=>wn()},Os,{children:t.jsx(j.default,{className:q.default("h-6 w-6 shrink-0",Me&&"scale-x-[-1] transform")})}))]})]}))]}))]})),ut&&t.jsx(E.default,{error:ut,className:"mt-3"})]}))}))}));ee.displayName="Input",exports.default=ee;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("../../../common/canChat.js"),s=require("react"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../Addons/Auth/hooks/useAuthContext.js"),r=require("../../../hooks/pickaxe/useDimensionContext.js"),a=require("../Addons/Document/hooks/useDocument.js"),l=require("../Addons/Scroll/hooks/
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),o=require("../../../common/canChat.js"),s=require("react"),i=require("../../../hooks/pickaxe/usePickaxeContext.js"),n=require("../Addons/Auth/hooks/useAuthContext.js"),r=require("../../../hooks/pickaxe/useDimensionContext.js"),a=require("../Addons/Document/hooks/useDocument.js"),l=require("../Addons/Scroll/hooks/useScroll.js"),u=require("../../../hooks/studio/useStyleFontSize.js"),c=require("../../../hooks/core/useScrollToBottomVisibility.js"),d=require("./History/index.js"),f=require("./Input.js"),m=require("../../Icons/attach-vertical.svg.js"),h=require("../../../common/cn.js"),p=require("../../../common/api/pickaxe.js"),v=require("uuid"),x=require("../../Core/StudioTip.js"),j=require("../common/ScrollToBottomButton.js"),b=require("../common/PickaxeMCPButton.js"),g=require("../../../hooks/pickaxe/useResponseContext.js"),k=require("../Addons/Navbar/NavPill.js"),y=require("../../Icons/history.svg.js");exports.default=()=>{var S,w;const{deploymentType:C,isNewChat:q,setIsNewChat:D,sessionId:I,setSessionId:N,setLastSessionId:T,pickaxeId:P,sender:A,pickaxe:O,styles:_,isEmbed:F,mcpEnabled:E,translations:R}=i.usePickaxeContext(),{isSent:z,token:B}=n.useAuthContext(),{width:H,height:G,setDimension:L}=r.useDimensionContext(),{setDocuments:M,onFileUpload:V}=a.useDocument(),{scrollContainerRef:U,scrollToBottom:W}=l.useScroll({listen:!1}),{isGenerating:J,messages:K}=g.useResponseContext(),Q=u.useStyleFontSize(),[X,Y]=s.useState(0),[Z,$]=s.useState(!1),[ee,te]=s.useState(!1),oe=s.useRef(null),se=s.useRef(null),ie=s.useRef(0),[ne,re]=s.useState(null),[ae,le]=s.useState(!1),ue=(null==R?void 0:R["new-chat"])||"New chat",ce=o.canChat(O),de=ce&&"chat-input"===C&&q&&!z,fe=ce&&null!==(w=null===(S=null==O?void 0:O.documentuploadtype)||void 0===S?void 0:S.startsWith("enduserupload"))&&void 0!==w&&w,{hasScrollableContent:me,isNearBottom:he}=c.default(U,{},[de]);s.useEffect((()=>()=>{M([])}),[]);const pe=s.useCallback((()=>{if(!P||!A&&!B)return;const t=(o=0)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;try{const t=yield p.pickaxeApi2.post("/conversation/title",Object.assign({sessionId:I},B?{studioSessionToken:B}:A?{userId:A}:{}));if(t.data&&t.data.success){const e=t.data.title;if(e&&"Conversation Title"!==e)return void xe(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()}),[P,A,I,B]);s.useEffect((()=>{J||q||!I||pe()}),[J,q,I,pe]),s.useEffect((()=>{if(!oe.current)return;const e=new ResizeObserver((e=>{for(const t of e){const{width:e,height:o}=t.contentRect;L(parseInt(e.toFixed(0)),parseInt(o.toFixed(0)))}}));return e.observe(oe.current),()=>{e.disconnect()}}),[L]);const[ve,xe]=s.useState(ue),je=(null==O?void 0:O.formtitle)||"Pickaxe",be=(null==O?void 0:O.coverphoto)||void 0,[ge,ke]=s.useState(!1);s.useEffect((()=>{const e=!de&&!F&&_.portalTheme&&(K.filter((e=>"user"===e.role)).length>0||Z||!q);ke(null!=e&&e)}),[de,F,Z,q,K,_.portalTheme]);const ye=s.useCallback((()=>{W({force:!0,behavior:"auto"})}),[W]);return t.jsxs("div",Object.assign({ref:oe,className:"relative flex h-full w-full flex-col items-center overflow-hidden",onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),fe&&(ie.current+=1,e.dataTransfer.items&&e.dataTransfer.items.length>0&&te(!0))},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),fe&&(ie.current-=1,0===ie.current&&te(!1))},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(t.preventDefault(),t.stopPropagation(),te(!1),ie.current=0,!fe)return;const e=Array.from(t.dataTransfer.files||[]);e.length>0&&(D(!1),yield V(e))}))},{children:[ee&&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(m.default,{className:"h-10 w-10"})})),t.jsx("h3",Object.assign({className:h.default(Q.h3,"mt-6 font-semibold text-c-primary text-black")},{children:(null==R?void 0:R["drop-files-to-upload"])||"Drop files to upload"})),t.jsx("p",Object.assign({className:h.default(Q.b2,"mt-2 opacity-60 text-black")},{children:(null==R?void 0:R["add-anything-to-the-conversation"])||"Add anything to the conversation"}))]})),!F&&E?t.jsx("div",Object.assign({className:"pointer-events-none absolute left-1/2 top-4 z-40 flex w-full max-w-[800px] -translate-x-1/2 justify-end px-4"},{children:t.jsx("div",Object.assign({className:"pointer-events-auto"},{children:t.jsx(b.default,{})}))})):null,de?t.jsx(f.default,{}):t.jsxs(t.Fragment,{children:[ge&&t.jsxs("div",Object.assign({className:h.default("direct-link"===C?"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"===_.portalTheme?"glass-dark ":"")},{children:[t.jsx(k.NavPill,{text:je,icon:be}),q||ve===ue?t.jsx(k.NavPill,{text:ve}):t.jsx(k.EditableNavPill,{text:ve,sessionId:I,onRename:t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(I)try{yield p.pickaxeApi2.patch("/conversation/title",Object.assign({sessionId:I,name:t},B?{studioSessionToken:B}:A?{userId:A}:{})),xe(t)}catch(e){console.error("Error renaming chat:",e),alert((null==R?void 0:R["failed-rename-chat"])||"Failed to rename chat.")}})),onDelete:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(I&&window.confirm((null==R?void 0:R["delete-confirm"])||"Are you sure you want to delete this conversation?"))try{yield p.pickaxeApi2.delete("/conversation",{data:Object.assign({sessionId:I},B?{studioSessionToken:B}:A?{userId:A}:{})}),D(!0),N(ce?v.v4():""),xe(ue)}catch(e){console.error("Error deleting chat:",e),alert((null==R?void 0:R["failed-delete-chat"])||"Failed to delete chat.")}})),isDarkGlass:"dark"===_.portalTheme}),t.jsx(x.StudioTip,Object.assign({content:R["chat-history"]||"Chat History",align:"bottom",containerClassName:"inline-flex shrink-0"},{children:t.jsx(k.HistoryPill,{icon:t.jsx(y.default,{}),onClick:()=>{N(""),T(I)}})}))]})),t.jsx(d.default,{additionalScrollHeight:X,isForceHideInfo:G<=545||H<=350||Z,isInputFocused:Z,onSubmit:t=>e.__awaiter(void 0,void 0,void 0,(function*(){ce&&se.current&&se.current.onSubmit(t)})),smitheryAuthData:ne,resubmitPrompt:()=>{re(null),le(!0)}}),t.jsx(j.default,{isVisible:me&&!he,bottom:X+65,onClick:ye}),ce&&t.jsx(f.default,{ref:se,onFocus:()=>$(!0),onBlur:()=>$(!1),onInputHeightChange:Y,initSmitheryAuthData:e=>re(e),resubmitPrompt:ae})]})]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("react"),r=require("../../common/api/pickaxe.js");const o=()=>{if("undefined"!=typeof window)return window.AudioContext||window.webkitAudioContext},
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_tslib.js"),t=require("react"),r=require("../../common/api/pickaxe.js"),n=require("../../common/speechTranscript.js");const o=e=>{var t,r;for(const n of null!==(r=null===(t=null==e?void 0:e.stream)||void 0===t?void 0:t.getTracks())&&void 0!==r?r:[])n.stop();(null==e?void 0:e.audioContext)&&"closed"!==e.audioContext.state&&e.audioContext.close()},s=()=>{if("undefined"!=typeof window)return window.AudioContext||window.webkitAudioContext},c=e=>{var t,r;e.processor&&(e.processor.onaudioprocess=null,e.processor.disconnect()),null===(t=e.source)||void 0===t||t.disconnect(),null===(r=e.silentGain)||void 0===r||r.disconnect(),e.processor=void 0,e.source=void 0,e.silentGain=void 0;for(const t of e.stream.getTracks())t.stop();"closed"!==e.audioContext.state&&e.audioContext.close()};exports.useSpeechToText=()=>{var i;const[a,u]=t.useState(""),[l,d]=t.useState(0),[m,p]=t.useState(!1),[f,v]=t.useState(!1),w=t.useRef(!0),h=t.useRef(0),k=t.useRef(null),y=t.useRef(null),g=t.useRef(new Map),S=t.useRef(new Map),C=t.useRef(-1),b=t.useRef(""),x=t.useRef(0),T=t.useCallback((()=>b.current),[]),A=t.useCallback((()=>({sessionId:x.current,text:b.current,turns:new Map(g.current)})),[]),M=t.useCallback((()=>Array.from(g.current.entries()).sort((([e],[t])=>e-t)).map((([e,t])=>{const r=S.current.get(e);return!r&&e<=C.current?"":n.getUnconsumedSpeech(t,r)})).filter(Boolean).join(" ").trim()),[]),E=t.useCallback((e=>{if(e&&e.sessionId===x.current){const t=C.current;for(const[r,o]of e.turns)r<=t&&!S.current.has(r)||(S.current.set(r,n.consumeSpeechTurn(o,S.current.get(r))),C.current=Math.max(C.current,r))}const t=M();b.current=t,u(t),d((e=>e+1))}),[M]),P=e=>{c(e),e.socket.readyState!==WebSocket.OPEN&&e.socket.readyState!==WebSocket.CONNECTING||e.socket.close(),k.current===e&&(k.current=null)};t.useEffect((()=>(w.current=!0,()=>{w.current=!1,h.current+=1,o(y.current),y.current=null;const e=k.current;e&&(e.socket.readyState===WebSocket.OPEN&&e.socket.send(JSON.stringify({type:"Terminate"})),P(e))})),[]);return{speechTranscript:a,speechTranscriptRevision:l,getSpeechTranscript:T,getSpeechTranscriptSnapshot:A,resetSpeechTranscript:E,isSpeechSupported:"undefined"!=typeof window&&Boolean(s())&&Boolean(null===(i=navigator.mediaDevices)||void 0===i?void 0:i.getUserMedia)&&"WebSocket"in window,isSpeechProcessing:f,isSpeechListening:m,onStartListening:t=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;const t=++h.current,n=s();if(!n||!(null===(e=navigator.mediaDevices)||void 0===e?void 0:e.getUserMedia))return;const i=k.current;i&&P(i),o(y.current);const a={};let l;y.current=a;try{if(x.current+=1,v(!0),p(!1),u(""),b.current="",g.current.clear(),S.current.clear(),C.current=-1,a.stream=yield navigator.mediaDevices.getUserMedia({audio:{autoGainControl:!0,channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),!w.current||t!==h.current)return;a.audioContext=new n;const{data:e}=yield r.pickaxeApi2.post("/speech/assemblyai");if(!w.current||t!==h.current)return;if(!e.success||!e.token)throw new Error(e.error||"AssemblyAI streaming token was not returned");const o=new URL("wss://streaming.assemblyai.com/v3/ws");o.searchParams.set("sample_rate",String(16e3)),o.searchParams.set("speech_model","whisper-rt"),o.searchParams.set("language_detection","true"),o.searchParams.set("format_turns","true"),o.searchParams.set("token",e.token),l={socket:new WebSocket(o),stream:a.stream,audioContext:a.audioContext,started:!1},a.stream=void 0,a.audioContext=void 0,y.current=null,k.current=l;const s=l;yield new Promise(((e,r)=>{const n=window.setTimeout((()=>{r(new Error("AssemblyAI streaming session timed out"))}),1e4),o=e=>{i.started||(window.clearTimeout(n),r(e))},i=s;i.socket.binaryType="arraybuffer",i.socket.onmessage=r=>{if(k.current===i&&w.current&&(i.started||t===h.current))try{const o=JSON.parse(String(r.data));if("Begin"!==o.type||i.started){if("Turn"===o.type)(e=>{var t;const r=(e=>{var t,r;const n=null===(t=e.transcript)||void 0===t?void 0:t.trim();if(n)return n;const o=null===(r=e.utterance)||void 0===r?void 0:r.trim();return o&&!/^(?:\[[^\]]+\]\s*)+$/.test(o)?o:""})(e),n=null!==(t=e.turn_order)&&void 0!==t?t:0;r?g.current.set(n,{text:r,words:e.words}):g.current.delete(n);const o=M();w.current&&(b.current=o,u(o))})(o);else if("Termination"===o.type)i.socket.close();else if("Error"===o.type)throw new Error(o.error||"AssemblyAI streaming failed")}else{i.started=!0,window.clearTimeout(n);const r=i.audioContext.createMediaStreamSource(i.stream),o=i.audioContext.createScriptProcessor(4096,1,1),s=i.audioContext.createGain();s.gain.value=0,o.onaudioprocess=({inputBuffer:e})=>{if(i.socket.readyState!==WebSocket.OPEN)return;const t=((e,t)=>{const r=t/16e3,n=Math.max(1,Math.round(e.length/r)),o=new Int16Array(n);let s=0;for(let t=0;t<n;t+=1){const n=Math.min(e.length,Math.round((t+1)*r));let c=0,i=0;for(;s<n;s+=1)c+=e[s],i+=1;const a=Math.max(-1,Math.min(1,i?c/i:0));o[t]=a<0?32768*a:32767*a}return o})(e.getChannelData(0),e.sampleRate);i.socket.send(t.buffer)},r.connect(o),o.connect(s),s.connect(i.audioContext.destination),i.source=r,i.processor=o,i.silentGain=s,i.audioContext.resume(),w.current&&t===h.current&&p(!0),e()}}catch(e){console.error("Could not process AssemblyAI message",e),o(e instanceof Error?e:new Error(String(e))),i.socket.close()}},i.socket.onerror=()=>{const e=new Error("Could not connect to AssemblyAI streaming");o(e),i.started&&console.error(e),i.socket.close()},i.socket.onclose=()=>{o(new Error("AssemblyAI streaming closed before it started")),(e=>{c(e),k.current===e&&(k.current=null,w.current&&p(!1))})(i)}})),w.current&&t===h.current||P(l)}catch(e){l&&k.current===l&&P(l),w.current&&t===h.current&&console.error("Could not start AssemblyAI speech recognition",e)}finally{o(a),y.current===a&&(y.current=null),w.current&&t===h.current&&v(!1)}})),onStopListening:()=>e.__awaiter(void 0,void 0,void 0,(function*(){const e=++h.current;o(y.current),y.current=null;const t=k.current;if(!t)return p(!1),void v(!1);try{v(!0),c(t),yield new Promise((e=>{const r=window.setTimeout(e,2e3),n=t.socket.onclose;t.socket.onclose=o=>{window.clearTimeout(r),null==n||n.call(t.socket,o),e()},t.socket.readyState===WebSocket.OPEN?t.socket.send(JSON.stringify({type:"Terminate"})):e()}))}catch(e){console.error("Could not stop AssemblyAI speech recognition",e)}finally{P(t),w.current&&e===h.current&&(p(!1),v(!1))}}))}};
|
|
@@ -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};
|