From ef131a0f80041ee10bcb189777acc0b4c4d0caf2 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 30 Oct 2023 15:52:28 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20change=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/webview/assets/index.js | 4 +- extensions/vscode/gui/assets/index.js | 4 +- gui/src/components/Layout.tsx | 7 +- gui/src/pages/gui.tsx | 4 +- server/continuedev/core/config.py | 26 ++- server/continuedev/libs/llm/anthropic.py | 4 +- server/continuedev/libs/llm/ollama.py | 4 +- server/continuedev/libs/llm/replicate.py | 4 +- server/continuedev/libs/llm/together.py | 4 +- server/continuedev/server/protocols/gui.py | 179 ++++++++---------- server/continuedev/server/protocols/ide.py | 7 - server/continuedev/server/window_manager.py | 2 +- 12 files changed, 110 insertions(+), 139 deletions(-) diff --git a/extensions/intellij/src/main/resources/webview/assets/index.js b/extensions/intellij/src/main/resources/webview/assets/index.js index 0266c81ae..b8d0a9c01 100644 --- a/extensions/intellij/src/main/resources/webview/assets/index.js +++ b/extensions/intellij/src/main/resources/webview/assets/index.js @@ -782,7 +782,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho top: 0; z-index: 100; background-color: ${Vt}; -`;function YR(e){var le,he;const t=C.useContext(Ja),n=rB(),r=Io(),i=bs(),a=kt(I=>I.sessionState),o=kt(I=>{var X;return(X=I.serverState.config.models)==null?void 0:X.default}),s=kt(I=>I.misc.serverStatusMessage),u=kt(I=>I.serverState.userInputQueue),c=kt(I=>I.sessionState.title),p=kt(I=>I.sessionState.active),[f,m]=C.useState(!1),[h,b]=C.useState([]),[y,T]=C.useState(!0),[E,v]=C.useState(!0),w=C.useRef(null),A=C.useRef(null),N=C.useRef(null),x=kt(I=>I.uiState.bottomMessage),D=kt(I=>I.misc.takenAction);C.useEffect(()=>{N.current&&r(V0e(N.current.getBoundingClientRect().top{var X;const I=()=>{var q,we;const O=((q=A.current)==null?void 0:q.scrollTop)||0,Q=((we=A.current)==null?void 0:we.scrollHeight)||0,be=window.innerHeight||0;O+be+-25>=Q?V(!1):V(!0)};return(X=A.current)==null||X.addEventListener("scroll",I),()=>{window.removeEventListener("scroll",I)}},[A.current]),C.useLayoutEffect(()=>{var I,X;B||(X=A.current)==null||X.scrollTo({top:(I=A.current)==null?void 0:I.scrollHeight,behavior:"instant"})},[(le=A.current)==null?void 0:le.scrollHeight,a.history]),C.useEffect(()=>{const I=X=>{X.key==="Backspace"&&Ig(X)&&!X.shiftKey&&p?(t==null||t.stopSession(),r(Yd(!1))):X.key==="Escape"&&r(pu(void 0))};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I)}},[t,p]),C.useEffect(()=>{if(t&&y){T(!1);for(const I of u)t.sendMainInput(I)}},[t,u,y]);const P=C.useCallback(I=>{if((o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(!I.startsWith("/")||I.startsWith("/edit"))){const Q=localStorage.getItem("ftc");if(Q){const be=parseInt(Q);if(localStorage.setItem("ftc",(be+1).toString()),be>=250){r(lc(!0)),r(k4(R.jsx(l2e,{}))),n==null||n.capture("ftc_reached");return}}else localStorage.setItem("ftc","1")}m(!0);const X=[...a.history,{name:"User Input",description:I,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:I},hide:!1,depth:0}],ae={history:X,context_items:a.context_items};for(let Q of a.context_items)r(AP({item:Q,index:X.length-1}));t.runFromState(ae),X.push({name:"Generating Response...",description:" ",observations:[],logs:[],step_type:"SimpleChatStep",params:{},hide:!1,depth:0}),r(YI(X)),r(Yd(!0));const O=localStorage.getItem("mainTextEntryCounter");if(O){let Q=parseInt(O);localStorage.setItem("mainTextEntryCounter",(Q+1).toString()),Q===300&&(r(k4(R.jsxs("div",{className:"text-center p-4",children:["👋 Thanks for using Continue. We are a beta product and love working closely with our first users. If you're interested in speaking, enter your name and email. We won't use this information for anything other than reaching out.",R.jsx("br",{}),R.jsx("br",{}),R.jsxs("form",{onSubmit:be=>{be.preventDefault(),n==null||n.capture("user_interest_form",{name:be.target.elements[0].value,email:be.target.elements[1].value}),r(k4(R.jsx("div",{className:"text-center p-4",children:"Thanks! We'll be in touch soon."})))},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"text",name:"name",placeholder:"Name",required:!0}),R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"email",name:"email",placeholder:"Email",required:!0}),R.jsx("button",{style:{padding:"10px",borderRadius:"5px",cursor:"pointer"},type:"submit",children:"Submit"})]})]}))),r(G0e(!1)),r(lc(!0)))}else localStorage.setItem("mainTextEntryCounter","1")},[t,a.history,a.context_items]);C.useEffect(()=>{const I=X=>{X.data.type==="userInput"&&P(X.data.input)};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[P]);const Z=I=>{if(r(wd(null)),w.current){let X=w.current.inputValue;if(console.log("Sending main input",X),X.trim()==="")return;if(X.startsWith("#")&&(X.length===7||X.length===4)){localStorage.setItem("continueButtonColor",X),w.current.setInputValue("");return}if(I&&Ig(I)&&(X=`/edit ${X}`),w.current.setInputValue(""),!t){r(Hge(X));return}P(X)}},$=(I,X)=>{t&&t.sendStepUserInput(I,X)},oe=C.useCallback(I=>{let X=!1;for(let ae=I+1;ae{const X=[];let ae=-1;for(let O=I;O>=0;O--)if(a.history.length>O&&a.history[O].name==="User Input"&&a.history[O].hide===!1){X.push(O),ae=O;break}if(X.length===0)return[];for(let O=ae+1;OO&&a.history[O].name==="User Input"&&a.history[O].hide===!1);O++)X.push(O);return X},[a.history]),ce=C.useCallback(I=>{const X=pe(I),ae=X[0];b(O=>{const Q=[...O];return Q[I]=!Q[I],!X.some((q,we)=>we>0&&Q[q])?Q[ae]=!1:!X.some((we,te)=>te>0&&!Q[we])&&(Q[ae]=!0),Q})},[pe]);C.useEffect(()=>{c&&se(c)},[c]);const[Le,se]=C.useState(c||"New Session");return R.jsxs(h2e,{ref:A,onKeyDown:I=>{I.key==="Enter"&&I.ctrlKey&&Z()},children:[R.jsxs(y2e,{children:[R.jsx(g2e,{onClick:I=>{I.target.setSelectionRange(0,I.target.value.length)},value:Le,onChange:I=>se(I.target.value),onBlur:I=>{I.target.value===c||typeof c>"u"&&I.target.value==="New Session"||t==null||t.setCurrentSessionTitle(I.target.value)},onKeyDown:I=>{I.key==="Enter"?(I.preventDefault(),I.target.blur()):I.key==="Escape"&&(se(c||"New Session"),I.target.blur())}}),R.jsxs("div",{className:"flex gap-2",children:[a.history.filter(I=>!I.hide).length>0&&R.jsx(Ti,{onClick:()=>{a.history.filter(I=>!I.hide).length>0&&r(M2())},text:"New Session (⌥⌘N)",children:R.jsx(xL,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{i("/history")},text:"History",children:R.jsx(kQ,{width:"1.4em",height:"1.4em"})})]})]}),(D||E)&&typeof t>"u"&&R.jsxs(R.Fragment,{children:[R.jsx($ge,{}),R.jsx("p",{style:{textAlign:"center",margin:"0px",fontSize:"14px"},children:s}),R.jsxs("div",{className:"flex mx-8 my-2",children:[R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/troubleshooting",target:"_blank",children:"Troubleshooting help"})})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},onClick:()=>{_o("toggleDevTools",{})},children:R.jsx("u",{children:"View logs"})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/walkthroughs/manually-run-continue#recommended-use-the-continuedev-pypi-package",target:"_blank",children:"Manually start server"})})})]})]}),R.jsx("br",{}),R.jsx(f2e,{onClick:I=>{t==null||t.sendMainInput(I)}}),R.jsx(m2e,{children:a.history.map((I,X)=>I.hide?null:R.jsx(C.Fragment,{children:I.name==="User Input"?I.hide||R.jsx(JI,{isMainInput:!1,value:I.description,active:p&&oe(X),onEnter:(ae,O)=>{if(O){t==null||t.stopSession();const Q=[...a.history.slice(0,X),{name:"User Input",description:O,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:O},hide:!1,depth:0}];r(YI(Q)),r(Yd(!0));const be={history:Q,context_items:a.context_items};console.log("State: ",be),t.runFromState(be)}ae==null||ae.stopPropagation(),ae==null||ae.preventDefault()},groupIndices:pe(X),onToggle:ae=>{b(O=>{const Q=[...O];return pe(X).forEach(be=>{Q[be]=ae}),Q})},onToggleAll:ae=>{b(O=>O.map(Q=>ae))},isToggleOpen:typeof h[X]>"u"?!0:h[X],index:X,onDelete:()=>{pe(X).forEach(ae=>{console.log(ae),r(A4(ae))})}}):R.jsx(Yge,{historyNode:I,iconElement:I.step_type==="DefaultModelEditCodeStep"?R.jsx(vQ,{width:"16px",height:"16px"}):I.error?R.jsx(AL,{width:"16px",height:"16px",color:"red"}):R.jsx(wL,{width:"16px",height:"16px"}),open:typeof h[X]>"u"?!I.error:h[X],onToggle:()=>ce(X),children:I.error?R.jsx(Qge,{onClose:()=>ce(X),error:I.error,onDelete:()=>{r(A4(X))}}):R.jsx(Pue,{index:X,isLast:X===a.history.length-1,isFirst:X===0,open:typeof h[X]>"u"?!0:h[X],onUserInput:ae=>{$(ae,X)},step:I,onReverse:()=>{t==null||t.reverseToIndex(X)},onRetry:()=>{t==null||t.retryAtIndex(X),m(!0)},onDelete:()=>{r(A4(X))},noUserInputParent:pe(X).length===0},X)})},X))}),R.jsx("div",{children:(he=u==null?void 0:u.map)==null?void 0:he.call(u,(I,X)=>R.jsx(b2e,{children:I},X))}),R.jsx("div",{ref:N}),R.jsx(JI,{isMainInput:!0,ref:w,onEnter:(I,X)=>{Z(I),I==null||I.stopPropagation(),I==null||I.preventDefault()},onInputValueChange:()=>{},onToggleAddContext:()=>{t==null||t.toggleAddingHighlightedCode()}})]})}const E2e=He.div` +`;function YR(e){var le,he;const t=C.useContext(Ja),n=rB(),r=Io(),i=bs(),a=kt(I=>I.sessionState),o=kt(I=>{var X;return(X=I.serverState.config.models)==null?void 0:X.default}),s=kt(I=>I.misc.serverStatusMessage),u=kt(I=>I.serverState.userInputQueue),c=kt(I=>I.sessionState.title),p=kt(I=>I.sessionState.active),[f,m]=C.useState(!1),[h,b]=C.useState([]),[y,T]=C.useState(!0),[E,v]=C.useState(!0),w=C.useRef(null),A=C.useRef(null),N=C.useRef(null),x=kt(I=>I.uiState.bottomMessage),D=kt(I=>I.misc.takenAction);C.useEffect(()=>{N.current&&r(V0e(N.current.getBoundingClientRect().top{var X;const I=()=>{var q,we;const O=((q=A.current)==null?void 0:q.scrollTop)||0,Q=((we=A.current)==null?void 0:we.scrollHeight)||0,be=window.innerHeight||0;O+be+-25>=Q?V(!1):V(!0)};return(X=A.current)==null||X.addEventListener("scroll",I),()=>{window.removeEventListener("scroll",I)}},[A.current]),C.useLayoutEffect(()=>{var I,X;B||(X=A.current)==null||X.scrollTo({top:(I=A.current)==null?void 0:I.scrollHeight,behavior:"instant"})},[(le=A.current)==null?void 0:le.scrollHeight,a.history]),C.useEffect(()=>{const I=X=>{X.key==="Backspace"&&Ig(X)&&!X.shiftKey&&p?(t==null||t.stopSession(),r(Yd(!1))):X.key==="Escape"&&r(pu(void 0))};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I)}},[t,p]),C.useEffect(()=>{if(t&&y){T(!1);for(const I of u)t.sendMainInput(I)}},[t,u,y]);const P=C.useCallback(I=>{if((o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(!I.startsWith("/")||I.startsWith("/edit"))){const Q=localStorage.getItem("ftc");if(Q){const be=parseInt(Q);if(localStorage.setItem("ftc",(be+1).toString()),be>=250){r(lc(!0)),r(k4(R.jsx(l2e,{}))),n==null||n.capture("ftc_reached");return}}else localStorage.setItem("ftc","1")}m(!0);const X=[...a.history,{name:"User Input",description:I,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:I},hide:!1,depth:0}],ae={history:X,context_items:a.context_items};for(let Q of a.context_items)r(AP({item:Q,index:X.length-1}));t.runFromState(ae),X.push({name:"Generating Response...",description:" ",observations:[],logs:[],step_type:"SimpleChatStep",params:{},hide:!1,depth:0}),r(YI(X)),r(Yd(!0));const O=localStorage.getItem("mainTextEntryCounter");if(O){let Q=parseInt(O);localStorage.setItem("mainTextEntryCounter",(Q+1).toString()),Q===300&&(r(k4(R.jsxs("div",{className:"text-center p-4",children:["👋 Thanks for using Continue. We are a beta product and love working closely with our first users. If you're interested in speaking, enter your name and email. We won't use this information for anything other than reaching out.",R.jsx("br",{}),R.jsx("br",{}),R.jsxs("form",{onSubmit:be=>{be.preventDefault(),n==null||n.capture("user_interest_form",{name:be.target.elements[0].value,email:be.target.elements[1].value}),r(k4(R.jsx("div",{className:"text-center p-4",children:"Thanks! We'll be in touch soon."})))},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"text",name:"name",placeholder:"Name",required:!0}),R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"email",name:"email",placeholder:"Email",required:!0}),R.jsx("button",{style:{padding:"10px",borderRadius:"5px",cursor:"pointer"},type:"submit",children:"Submit"})]})]}))),r(G0e(!1)),r(lc(!0)))}else localStorage.setItem("mainTextEntryCounter","1")},[t,a.history,a.context_items]);C.useEffect(()=>{const I=X=>{X.data.type==="userInput"&&P(X.data.input)};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[P]);const Z=I=>{if(r(wd(null)),w.current){let X=w.current.inputValue;if(console.log("Sending main input",X),X.trim()==="")return;if(X.startsWith("#")&&(X.length===7||X.length===4)){localStorage.setItem("continueButtonColor",X),w.current.setInputValue("");return}if(I&&Ig(I)&&(X=`/edit ${X}`),w.current.setInputValue(""),!t){r(Hge(X));return}P(X)}},$=(I,X)=>{t&&t.sendStepUserInput(I,X)},oe=C.useCallback(I=>{let X=!1;for(let ae=I+1;ae{const X=[];let ae=-1;for(let O=I;O>=0;O--)if(a.history.length>O&&a.history[O].name==="User Input"&&a.history[O].hide===!1){X.push(O),ae=O;break}if(X.length===0)return[];for(let O=ae+1;OO&&a.history[O].name==="User Input"&&a.history[O].hide===!1);O++)X.push(O);return X},[a.history]),ce=C.useCallback(I=>{const X=pe(I),ae=X[0];b(O=>{const Q=[...O];return Q[I]=!Q[I],!X.some((q,we)=>we>0&&Q[q])?Q[ae]=!1:!X.some((we,te)=>te>0&&!Q[we])&&(Q[ae]=!0),Q})},[pe]);C.useEffect(()=>{c&&se(c)},[c]);const[Le,se]=C.useState(c||"New Session");return R.jsxs(h2e,{ref:A,onKeyDown:I=>{I.key==="Enter"&&I.ctrlKey&&Z()},children:[R.jsxs(y2e,{children:[R.jsx(g2e,{onClick:I=>{I.target.setSelectionRange(0,I.target.value.length)},value:Le,onChange:I=>se(I.target.value),onBlur:I=>{I.target.value===c||typeof c>"u"&&I.target.value==="New Session"||t==null||t.setCurrentSessionTitle(I.target.value)},onKeyDown:I=>{I.key==="Enter"?(I.preventDefault(),I.target.blur()):I.key==="Escape"&&(se(c||"New Session"),I.target.blur())}}),R.jsxs("div",{className:"flex gap-2",children:[a.history.filter(I=>!I.hide).length>0&&R.jsx(Ti,{onClick:()=>{r(M2())},text:"New Session (⌥⌘N)",children:R.jsx(xL,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{i("/history")},text:"History",children:R.jsx(kQ,{width:"1.4em",height:"1.4em"})})]})]}),(D||E)&&typeof t>"u"&&R.jsxs(R.Fragment,{children:[R.jsx($ge,{}),R.jsx("p",{style:{textAlign:"center",margin:"0px",fontSize:"14px"},children:s}),R.jsxs("div",{className:"flex mx-8 my-2",children:[R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/troubleshooting",target:"_blank",children:"Troubleshooting help"})})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},onClick:()=>{_o("toggleDevTools",{})},children:R.jsx("u",{children:"View logs"})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/walkthroughs/manually-run-continue#recommended-use-the-continuedev-pypi-package",target:"_blank",children:"Manually start server"})})})]})]}),R.jsx("br",{}),R.jsx(f2e,{onClick:I=>{t==null||t.sendMainInput(I)}}),R.jsx(m2e,{children:a.history.map((I,X)=>I.hide?null:R.jsx(C.Fragment,{children:I.name==="User Input"?I.hide||R.jsx(JI,{isMainInput:!1,value:I.description,active:p&&oe(X),onEnter:(ae,O)=>{if(O){t==null||t.stopSession();const Q=[...a.history.slice(0,X),{name:"User Input",description:O,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:O},hide:!1,depth:0}];r(YI(Q)),r(Yd(!0));const be={history:Q,context_items:a.context_items};console.log("State: ",be),t.runFromState(be)}ae==null||ae.stopPropagation(),ae==null||ae.preventDefault()},groupIndices:pe(X),onToggle:ae=>{b(O=>{const Q=[...O];return pe(X).forEach(be=>{Q[be]=ae}),Q})},onToggleAll:ae=>{b(O=>O.map(Q=>ae))},isToggleOpen:typeof h[X]>"u"?!0:h[X],index:X,onDelete:()=>{pe(X).forEach(ae=>{console.log(ae),r(A4(ae))})}}):R.jsx(Yge,{historyNode:I,iconElement:I.step_type==="DefaultModelEditCodeStep"?R.jsx(vQ,{width:"16px",height:"16px"}):I.error?R.jsx(AL,{width:"16px",height:"16px",color:"red"}):R.jsx(wL,{width:"16px",height:"16px"}),open:typeof h[X]>"u"?!I.error:h[X],onToggle:()=>ce(X),children:I.error?R.jsx(Qge,{onClose:()=>ce(X),error:I.error,onDelete:()=>{r(A4(X))}}):R.jsx(Pue,{index:X,isLast:X===a.history.length-1,isFirst:X===0,open:typeof h[X]>"u"?!0:h[X],onUserInput:ae=>{$(ae,X)},step:I,onReverse:()=>{t==null||t.reverseToIndex(X)},onRetry:()=>{t==null||t.retryAtIndex(X),m(!0)},onDelete:()=>{r(A4(X))},noUserInputParent:pe(X).length===0},X)})},X))}),R.jsx("div",{children:(he=u==null?void 0:u.map)==null?void 0:he.call(u,(I,X)=>R.jsx(b2e,{children:I},X))}),R.jsx("div",{ref:N}),R.jsx(JI,{isMainInput:!0,ref:w,onEnter:(I,X)=>{Z(I),I==null||I.stopPropagation(),I==null||I.preventDefault()},onInputValueChange:()=>{},onToggleAddContext:()=>{t==null||t.toggleAddingHighlightedCode()}})]})}const E2e=He.div` display: flex; flex-direction: row; align-items: center; @@ -1080,7 +1080,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho margin-left: 8px; z-index: 200; font-size: ${ir()}; -`,u3e=()=>{const e=bs(),t=ST(),n=C.useContext(Ja),r=Io(),i=kt(p=>p.uiState.dialogMessage),a=kt(p=>p.uiState.showDialog),o=kt(p=>{var f;return(f=p.serverState.config.models)==null?void 0:f.default}),s=kt(p=>p.uiState.bottomMessage),u=kt(p=>p.uiState.displayBottomMessageOnBottom),c=kt(p=>p.sessionState.history);return C.useEffect(()=>{const p=f=>{var m;if(f.metaKey&&f.altKey&&f.code==="KeyN"&&c.filter(h=>!h.hide).length>0&&r(M2()),(f.metaKey||f.ctrlKey)&&f.code==="KeyC"){const h=(m=window.getSelection())==null?void 0:m.toString();h&&setTimeout(()=>{navigator.clipboard.writeText(h)},100)}};return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p)}},[n,c]),C.useEffect(()=>{const p=f=>{f.data.type==="addModel"?e("/models"):f.data.type==="openSettings"&&e("/settings")};return window.addEventListener("message",p),()=>{window.removeEventListener("message",p)}},[]),R.jsxs(i3e,{children:[R.jsxs("div",{style:{scrollbarGutter:"stable both-edges",minHeight:"100%",display:"grid",gridTemplateRows:"1fr auto"},children:[R.jsx(D2e,{showDialog:a,onEnter:()=>{r(lc(!1))},onClose:()=>{r(lc(!1))},message:i}),R.jsxs(s3e,{children:[R.jsx(r2e,{}),R.jsx(l3e,{id:"model-select-top-div"}),R.jsxs(o3e,{children:[R.jsxs("div",{className:"mr-auto flex gap-2 items-center",children:[localStorage.getItem("ide")==="jetbrains"||localStorage.getItem("hideFeature")==="true"||R.jsx(kL,{className:"cursor-pointer",onClick:()=>{localStorage.setItem("hideFeature","true")},onMouseEnter:()=>{r(pu("🎁 New Feature: Use ⌘⇧R automatically debug errors in the terminal (you can click the sparkle icon to make it go away)"))},onMouseLeave:()=>{r(QI(setTimeout(()=>{r(pu(void 0))},2e3)))},width:"1.3em",height:"1.3em",color:"yellow"}),R.jsx(Q5e,{}),(o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(t.pathname==="/settings"||parseInt(localStorage.getItem("ftc")||"0")>=125)&&R.jsx(n3e,{completed:parseInt(localStorage.getItem("ftc")||"0"),total:250})]}),R.jsx(Ti,{text:"Help",onClick:()=>{e("/help")},children:R.jsx(qQ,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{e("/settings")},text:"Settings",children:R.jsx(SQ,{width:"1.4em",height:"1.4em"})})]})]}),R.jsx(a3e,{displayOnBottom:u,onMouseEnter:()=>{r(QI(void 0))},onMouseLeave:p=>{p.buttons||r(pu(void 0))},hidden:!s,children:s})]}),R.jsx("div",{className:"text-sm",id:"tooltip-portal-div"})]})};class c3e{}const Co=Object.create(null);Co.open="0";Co.close="1";Co.ping="2";Co.pong="3";Co.message="4";Co.upgrade="5";Co.noop="6";const Gh=Object.create(null);Object.keys(Co).forEach(e=>{Gh[Co[e]]=e});const tE={type:"error",data:"parser error"},OB=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",DB=typeof ArrayBuffer=="function",LB=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,NT=({type:e,data:t},n,r)=>OB&&t instanceof Blob?n?r(t):aN(t,r):DB&&(t instanceof ArrayBuffer||LB(t))?n?r(t):aN(new Blob([t]),r):r(Co[e]+(t||"")),aN=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function oN(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let V4;function d3e(e,t){if(OB&&e.data instanceof Blob)return e.data.arrayBuffer().then(oN).then(t);if(DB&&(e.data instanceof ArrayBuffer||LB(e.data)))return t(oN(e.data));NT(e,!1,n=>{V4||(V4=new TextEncoder),t(V4.encode(n))})}const sN="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cd=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,i=0,a,o,s,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const c=new ArrayBuffer(t),p=new Uint8Array(c);for(r=0;r>4,p[i++]=(o&15)<<4|s>>2,p[i++]=(s&3)<<6|u&63;return c},f3e=typeof ArrayBuffer=="function",OT=(e,t)=>{if(typeof e!="string")return{type:"message",data:MB(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:h3e(e.substring(1),t)}:Gh[n]?e.length>1?{type:Gh[n],data:e.substring(1)}:{type:Gh[n]}:tE},h3e=(e,t)=>{if(f3e){const n=p3e(e);return MB(n,t)}else return{base64:!0,data:e}},MB=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},FB=String.fromCharCode(30),g3e=(e,t)=>{const n=e.length,r=new Array(n);let i=0;e.forEach((a,o)=>{NT(a,!1,s=>{r[o]=s,++i===n&&t(r.join(FB))})})},m3e=(e,t)=>{const n=e.split(FB),r=[];for(let i=0;i{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}let W4;function ch(e){return e.reduce((t,n)=>t+n.length,0)}function dh(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;iMath.pow(2,53-32)-1){s.enqueue(tE);break}i=p*Math.pow(2,32)+c.getUint32(4),r=3}else{if(ch(n)e){s.enqueue(tE);break}}}})}const PB=4;function Xn(e){if(e)return E3e(e)}function E3e(e){for(var t in Xn.prototype)e[t]=Xn.prototype[t];return e}Xn.prototype.on=Xn.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};Xn.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};Xn.prototype.off=Xn.prototype.removeListener=Xn.prototype.removeAllListeners=Xn.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;itypeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function BB(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const v3e=da.setTimeout,_3e=da.clearTimeout;function W2(e,t){t.useNativeTimers?(e.setTimeoutFn=v3e.bind(da),e.clearTimeoutFn=_3e.bind(da)):(e.setTimeoutFn=da.setTimeout.bind(da),e.clearTimeoutFn=da.clearTimeout.bind(da))}const T3e=1.33;function S3e(e){return typeof e=="string"?w3e(e):Math.ceil((e.byteLength||e.size)*T3e)}function w3e(e){let t=0,n=0;for(let r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function A3e(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function C3e(e){let t={},n=e.split("&");for(let r=0,i=n.length;r0);return t}function $B(){const e=cN(+new Date);return e!==uN?(lN=0,uN=e):e+"."+cN(lN++)}for(;ph{this.readyState="paused",t()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};m3e(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,g3e(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=$B()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Y1(this.uri(),t)}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}let Y1=class Vh extends Xn{constructor(t,n){super(),W2(this,n),this.opts=n,this.method=n.method||"GET",this.uri=t,this.data=n.data!==void 0?n.data:null,this.create()}create(){var t;const n=BB(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new HB(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this.opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=Vh.requestsCount++,Vh.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=R3e,t)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Vh.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};Y1.requestsCount=0;Y1.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",dN);else if(typeof addEventListener=="function"){const e="onpagehide"in da?"pagehide":"unload";addEventListener(e,dN,!1)}}function dN(){for(let e in Y1.requests)Y1.requests.hasOwnProperty(e)&&Y1.requests[e].abort()}const LT=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0))(),fh=da.WebSocket||da.MozWebSocket,pN=!0,D3e="arraybuffer",fN=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class L3e extends DT{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),n=this.opts.protocols,r=fN?{}:BB(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=pN&&!fN?n?new fh(t,n):new fh(t):new fh(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{const o={};try{pN&&this.ws.send(a)}catch{}i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=$B()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}check(){return!!fh}}class M3e extends DT{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(t=>{const n=y3e(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=b3e();i.readable.pipeTo(t.writable),this.writer=i.writable.getWriter();const a=()=>{r.read().then(({done:s,value:u})=>{s||(this.onPacket(u),a())}).catch(s=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then(()=>this.onOpen())})}))}write(t){this.writable=!1;for(let n=0;n{i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this.transport)===null||t===void 0||t.close()}}const F3e={websocket:L3e,webtransport:M3e,polling:O3e},P3e=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,B3e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rE(e){const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=P3e.exec(e||""),a={},o=14;for(;o--;)a[B3e[o]]=i[o]||"";return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=U3e(a,a.path),a.queryKey=$3e(a,a.query),a}function U3e(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function $3e(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(n[i]=a)}),n}let jB=class p1 extends Xn{constructor(t,n={}){super(),this.binaryType=D3e,this.writeBuffer=[],t&&typeof t=="object"&&(n=t,t=null),t?(t=rE(t),n.hostname=t.host,n.secure=t.protocol==="https"||t.protocol==="wss",n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=rE(n.host).host),W2(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=C3e(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=PB,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new F3e[t](r)}open(){let t;if(this.opts.rememberUpgrade&&p1.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else t=this.transports[0];this.readyState="opening";try{t=this.createTransport(t)}catch{this.transports.shift(),this.open();return}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(t){let n=this.createTransport(t),r=!1;p1.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;p1.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(p(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const m=new Error("probe error");m.transport=n.name,this.emitReserved("upgradeError",m)}}))};function a(){r||(r=!0,p(),n.close(),n=null)}const o=f=>{const m=new Error("probe error: "+f);m.transport=n.name,a(),this.emitReserved("upgradeError",m)};function s(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&a()}const p=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",s),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",s),this.once("close",u),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",p1.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let t=0;const n=this.upgrades.length;for(;t{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(t,n,r){return this.sendPacket("message",t,n,r),this}send(t,n,r){return this.sendPacket("message",t,n,r),this}sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:n,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}onError(t){p1.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const n=[];let r=0;const i=t.length;for(;rtypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,GB=Object.prototype.toString,G3e=typeof Blob=="function"||typeof Blob<"u"&&GB.call(Blob)==="[object BlobConstructor]",V3e=typeof File=="function"||typeof File<"u"&&GB.call(File)==="[object FileConstructor]";function MT(e){return H3e&&(e instanceof ArrayBuffer||j3e(e))||G3e&&e instanceof Blob||V3e&&e instanceof File}function Wh(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.num{delete this.acks[t];for(let o=0;o{this.io.clearTimeoutFn(a),n.apply(this,[null,...o])}}emitWithAck(t,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,a)=>{n.push((o,s)=>r?o?a(o):i(s):i(o)),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:zt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case zt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case zt.EVENT:case zt.BINARY_EVENT:this.onevent(t);break;case zt.ACK:case zt.BINARY_ACK:this.onack(t);break;case zt.DISCONNECT:this.ondisconnect();break;case zt.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:zt.ACK,id:t,data:i}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(n.apply(this,t.data),delete this.acks[t.id])}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:zt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}xc.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};xc.prototype.reset=function(){this.attempts=0};xc.prototype.setMin=function(e){this.ms=e};xc.prototype.setMax=function(e){this.max=e};xc.prototype.setJitter=function(e){this.jitter=e};class oE extends Xn{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,W2(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new xc({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const i=n.parser||Z3e;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new jB(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=Ua(n,"open",function(){r.onopen(),t&&t()}),a=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},o=Ua(n,"error",a);if(this._timeout!==!1){const s=this._timeout,u=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),n.close()},s);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ua(t,"ping",this.onping.bind(this)),Ua(t,"data",this.ondata.bind(this)),Ua(t,"error",this.onerror.bind(this)),Ua(t,"close",this.onclose.bind(this)),Ua(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){LT(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new VB(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const gd={};function qh(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=z3e(e,t.path||"/socket.io"),r=n.source,i=n.id,a=n.path,o=gd[i]&&a in gd[i].nsps,s=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let u;return s?u=new oE(r,t):(gd[i]||(gd[i]=new oE(r,t)),u=gd[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(qh,{Manager:oE,Socket:VB,io:qh,connect:qh});class WB{}class e4e extends WB{constructor(n){super();zl(this,"socket");console.log("Connecting to socket.io endpoint: ",n,window.windowId),this.socket=qh(`${n}?window_id=${window.windowId}`,{path:"/gui/socket.io",transports:["websocket","polling","flashsocket"]})}send(n,r){this.socket.emit("message",{message_type:n,data:r,message_id:Cy()})}onMessageType(n,r){this.socket.on("message",({message_type:i,data:a})=>{n===i&&r(a)})}onMessage(n){this.socket.on("message",({messageType:r,data:i})=>{n(r,i)})}onOpen(n){this.socket.on("connect",n)}onClose(n){this.socket.on("disconnect",n)}async sendAndReceive(n,r){return new Promise((i,a)=>{this.socket.emit("message",{message_type:n,data:r,message_id:Cy()},o=>{o&&o.error?a(o.error):i(o)})})}onError(n){this.socket.on("error",n)}close(){this.socket.disconnect()}}class t4e extends WB{constructor(n){super();zl(this,"serverUrl");this.serverUrl=n,_o("websocketForwardingOpen",{url:this.serverUrl})}send(n,r){_o("websocketForwardingMessage",{message:{messageType:n,data:r},url:this.serverUrl})}onMessageType(n,r){window.addEventListener("message",i=>{if(i.data.type==="websocketForwardingMessage"){const a=JSON.parse(i.data.data);a.messageType===n&&r(a.data)}})}onMessage(n){window.addEventListener("message",r=>{if(r.data.type==="websocketForwardingMessage"){const i=JSON.parse(r.data.data);n(i.messageType,i.data)}})}onError(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingError"&&n(r.data.error)})}sendAndReceive(n,r){return new Promise(i=>{const a=o=>{if(o.data.type==="websocketForwardingMessage"){const s=JSON.parse(o.data.data);s.messageType===n&&(window.removeEventListener("message",a),i(s.data))}};window.addEventListener("message",a),this.send(n,r)})}onOpen(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingOpen"&&n()})}onClose(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingClose"&&n()})}close(){_o("websocketForwardingClose",{url:this.serverUrl})}}class n4e extends c3e{constructor(n,r){super();zl(this,"messenger");zl(this,"serverUrl");zl(this,"useVscodeMessagePassing");zl(this,"onStateUpdateCallbacks",[]);this.serverUrl=n,this.useVscodeMessagePassing=r,this.serverUrl=n,this.useVscodeMessagePassing=r,this.messenger=r?new t4e(n):new e4e(n),this.messenger.onClose(()=>{console.log("GUI Connection closed: ",n)}),this.messenger.onError(i=>{console.log("GUI Connection error: ",i)}),this.messenger.onOpen(()=>{console.log("GUI Connection opened: ",n)}),this.messenger.onMessage((i,a)=>{this.handleMessage(i,a)})}onConnected(n){var r;(r=this.messenger)==null||r.onOpen(n)}handleMessage(n,r){switch(n){case"state_update":if(r.state)for(const i of this.onStateUpdateCallbacks)i(r.state);break}}loadSession(n){var r;(r=this.messenger)==null||r.send("load_session",{session_id:n})}sendMainInput(n){var r;(r=this.messenger)==null||r.send("main_input",{input:n})}runFromState(n){var r;(r=this.messenger)==null||r.send("run_from_state",{state:n})}async getSessionTitle(n){var r;return await((r=this.messenger)==null?void 0:r.sendAndReceive("get_session_title",{history:n}))}reverseToIndex(n){var r;(r=this.messenger)==null||r.send("reverse_to_index",{index:n})}sendRefinementInput(n,r){var i;(i=this.messenger)==null||i.send("refinement_input",{input:n,index:r})}sendStepUserInput(n,r){var i;(i=this.messenger)==null||i.send("step_user_input",{input:n,index:r})}onStateUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("state_update",i=>{i.state&&n(i.state)}),this.onStateUpdateCallbacks.push(n)}onSessionUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("session_update",i=>{n(i)})}onConfigUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("config_update",i=>{n(i)})}getConfig(){var n;return(n=this.messenger)==null?void 0:n.sendAndReceive("get_config",{})}onAddContextItem(n){var r;(r=this.messenger)==null||r.onMessageType("add_context_item",i=>{n(i)})}onAvailableSlashCommands(n){var r;(r=this.messenger)==null||r.onMessageType("available_slash_commands",i=>{i.commands&&n(i.commands)})}stopSession(){var n;(n=this.messenger)==null||n.send("stop_session",{})}sendClear(){var n;(n=this.messenger)==null||n.send("clear_history",{})}retryAtIndex(n){var r;(r=this.messenger)==null||r.send("retry_at_index",{index:n})}deleteContextWithIds(n,r){var i;(i=this.messenger)==null||i.send("delete_context_with_ids",{ids:n.map(a=>`${a.provider_title}-${a.item_id}`),index:r})}setEditingAtIds(n){var r;(r=this.messenger)==null||r.send("set_editing_at_ids",{ids:n})}toggleAddingHighlightedCode(){var n;(n=this.messenger)==null||n.send("toggle_adding_highlighted_code",{})}showContextVirtualFile(n){var r;(r=this.messenger)==null||r.send("show_context_virtual_file",{index:n})}selectContextItem(n,r){var i;(i=this.messenger)==null||i.send("select_context_item",{id:n,query:r})}async getContextItem(n,r){var i;return await((i=this.messenger)==null?void 0:i.sendAndReceive("get_context_item",{id:n,query:r}))}selectContextItemAtIndex(n,r,i){var a;(a=this.messenger)==null||a.send("select_context_item_at_index",{id:n,query:r,index:i})}editStepAtIndex(n,r){var i;(i=this.messenger)==null||i.send("edit_step_at_index",{user_input:n,index:r})}setSystemMessage(n){var r;(r=this.messenger)==null||r.send("set_system_message",{system_message:n})}setTemperature(n){var r;(r=this.messenger)==null||r.send("set_temperature",{temperature:n})}addModelForRole(n,r,i){var a;(a=this.messenger)==null||a.send("add_model_for_role",{role:n,model:i,model_class:r})}setModelForRoleFromIndex(n,r){var i;(i=this.messenger)==null||i.send("set_model_for_role_from_index",{role:n,index:r})}saveContextGroup(n,r){var i;(i=this.messenger)==null||i.send("save_context_group",{context_items:r,title:n})}selectContextGroup(n){var r;(r=this.messenger)==null||r.send("select_context_group",{id:n})}deleteContextGroup(n){var r;(r=this.messenger)==null||r.send("delete_context_group",{id:n})}setCurrentSessionTitle(n){var r;(r=this.messenger)==null||r.send("set_current_session_title",{title:n})}}function r4e(e=!0){const[t,n]=C.useState(void 0);return C.useEffect(()=>{const r=window.serverUrl;console.log("Creating GUI websocket",r,e);const i=new n4e(r,e);i.onConnected(()=>{n(i)})},[]),t}function i4e(){const e=EB();return console.error(e),R.jsxs("div",{id:"error-page",className:"text-center",children:[R.jsx("h1",{children:"Error in Continue React App"}),R.jsx("p",{children:R.jsx("i",{children:e.statusText||e.message})}),R.jsx("br",{}),R.jsx("pre",{className:"text-left m-4",children:e.stack})]})}const qB="28px",a4e=He.div` +`,u3e=()=>{const e=bs(),t=ST(),n=C.useContext(Ja),r=Io(),i=kt(p=>p.uiState.dialogMessage),a=kt(p=>p.uiState.showDialog),o=kt(p=>{var f;return(f=p.serverState.config.models)==null?void 0:f.default}),s=kt(p=>p.uiState.bottomMessage),u=kt(p=>p.uiState.displayBottomMessageOnBottom),c=kt(p=>p.sessionState.history);return C.useEffect(()=>{const p=f=>{var m;if(f.metaKey&&f.altKey&&f.code==="KeyN"&&r(M2()),(f.metaKey||f.ctrlKey)&&f.code==="KeyC"){const h=(m=window.getSelection())==null?void 0:m.toString();h&&setTimeout(()=>{navigator.clipboard.writeText(h)},100)}};return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p)}},[n,c]),C.useEffect(()=>{const p=f=>{f.data.type==="addModel"?e("/models"):f.data.type==="openSettings"&&e("/settings")};return window.addEventListener("message",p),()=>{window.removeEventListener("message",p)}},[]),R.jsxs(i3e,{children:[R.jsxs("div",{style:{scrollbarGutter:"stable both-edges",minHeight:"100%",display:"grid",gridTemplateRows:"1fr auto"},children:[R.jsx(D2e,{showDialog:a,onEnter:()=>{r(lc(!1))},onClose:()=>{r(lc(!1))},message:i}),R.jsxs(s3e,{children:[R.jsx(r2e,{}),R.jsx(l3e,{id:"model-select-top-div"}),R.jsxs(o3e,{children:[R.jsxs("div",{className:"mr-auto flex gap-2 items-center",children:[localStorage.getItem("ide")==="jetbrains"||localStorage.getItem("hideFeature")==="true"||R.jsx(kL,{className:"cursor-pointer",onClick:()=>{localStorage.setItem("hideFeature","true")},onMouseEnter:()=>{r(pu("🎁 New Feature: Use ⌘⇧R automatically debug errors in the terminal (you can click the sparkle icon to make it go away)"))},onMouseLeave:()=>{r(QI(setTimeout(()=>{r(pu(void 0))},2e3)))},width:"1.3em",height:"1.3em",color:"yellow"}),R.jsx(Q5e,{}),(o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(t.pathname==="/settings"||parseInt(localStorage.getItem("ftc")||"0")>=125)&&R.jsx(n3e,{completed:parseInt(localStorage.getItem("ftc")||"0"),total:250})]}),R.jsx(Ti,{text:"Help",onClick:()=>{e("/help")},children:R.jsx(qQ,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{e("/settings")},text:"Settings",children:R.jsx(SQ,{width:"1.4em",height:"1.4em"})})]})]}),R.jsx(a3e,{displayOnBottom:u,onMouseEnter:()=>{r(QI(void 0))},onMouseLeave:p=>{p.buttons||r(pu(void 0))},hidden:!s,children:s})]}),R.jsx("div",{className:"text-sm",id:"tooltip-portal-div"})]})};class c3e{}const Co=Object.create(null);Co.open="0";Co.close="1";Co.ping="2";Co.pong="3";Co.message="4";Co.upgrade="5";Co.noop="6";const Gh=Object.create(null);Object.keys(Co).forEach(e=>{Gh[Co[e]]=e});const tE={type:"error",data:"parser error"},OB=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",DB=typeof ArrayBuffer=="function",LB=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,NT=({type:e,data:t},n,r)=>OB&&t instanceof Blob?n?r(t):aN(t,r):DB&&(t instanceof ArrayBuffer||LB(t))?n?r(t):aN(new Blob([t]),r):r(Co[e]+(t||"")),aN=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function oN(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let V4;function d3e(e,t){if(OB&&e.data instanceof Blob)return e.data.arrayBuffer().then(oN).then(t);if(DB&&(e.data instanceof ArrayBuffer||LB(e.data)))return t(oN(e.data));NT(e,!1,n=>{V4||(V4=new TextEncoder),t(V4.encode(n))})}const sN="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cd=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,i=0,a,o,s,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const c=new ArrayBuffer(t),p=new Uint8Array(c);for(r=0;r>4,p[i++]=(o&15)<<4|s>>2,p[i++]=(s&3)<<6|u&63;return c},f3e=typeof ArrayBuffer=="function",OT=(e,t)=>{if(typeof e!="string")return{type:"message",data:MB(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:h3e(e.substring(1),t)}:Gh[n]?e.length>1?{type:Gh[n],data:e.substring(1)}:{type:Gh[n]}:tE},h3e=(e,t)=>{if(f3e){const n=p3e(e);return MB(n,t)}else return{base64:!0,data:e}},MB=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},FB=String.fromCharCode(30),g3e=(e,t)=>{const n=e.length,r=new Array(n);let i=0;e.forEach((a,o)=>{NT(a,!1,s=>{r[o]=s,++i===n&&t(r.join(FB))})})},m3e=(e,t)=>{const n=e.split(FB),r=[];for(let i=0;i{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}let W4;function ch(e){return e.reduce((t,n)=>t+n.length,0)}function dh(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;iMath.pow(2,53-32)-1){s.enqueue(tE);break}i=p*Math.pow(2,32)+c.getUint32(4),r=3}else{if(ch(n)e){s.enqueue(tE);break}}}})}const PB=4;function Xn(e){if(e)return E3e(e)}function E3e(e){for(var t in Xn.prototype)e[t]=Xn.prototype[t];return e}Xn.prototype.on=Xn.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};Xn.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};Xn.prototype.off=Xn.prototype.removeListener=Xn.prototype.removeAllListeners=Xn.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;itypeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function BB(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const v3e=da.setTimeout,_3e=da.clearTimeout;function W2(e,t){t.useNativeTimers?(e.setTimeoutFn=v3e.bind(da),e.clearTimeoutFn=_3e.bind(da)):(e.setTimeoutFn=da.setTimeout.bind(da),e.clearTimeoutFn=da.clearTimeout.bind(da))}const T3e=1.33;function S3e(e){return typeof e=="string"?w3e(e):Math.ceil((e.byteLength||e.size)*T3e)}function w3e(e){let t=0,n=0;for(let r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function A3e(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function C3e(e){let t={},n=e.split("&");for(let r=0,i=n.length;r0);return t}function $B(){const e=cN(+new Date);return e!==uN?(lN=0,uN=e):e+"."+cN(lN++)}for(;ph{this.readyState="paused",t()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};m3e(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,g3e(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=$B()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Y1(this.uri(),t)}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}let Y1=class Vh extends Xn{constructor(t,n){super(),W2(this,n),this.opts=n,this.method=n.method||"GET",this.uri=t,this.data=n.data!==void 0?n.data:null,this.create()}create(){var t;const n=BB(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new HB(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this.opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=Vh.requestsCount++,Vh.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=R3e,t)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Vh.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};Y1.requestsCount=0;Y1.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",dN);else if(typeof addEventListener=="function"){const e="onpagehide"in da?"pagehide":"unload";addEventListener(e,dN,!1)}}function dN(){for(let e in Y1.requests)Y1.requests.hasOwnProperty(e)&&Y1.requests[e].abort()}const LT=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0))(),fh=da.WebSocket||da.MozWebSocket,pN=!0,D3e="arraybuffer",fN=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class L3e extends DT{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),n=this.opts.protocols,r=fN?{}:BB(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=pN&&!fN?n?new fh(t,n):new fh(t):new fh(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{const o={};try{pN&&this.ws.send(a)}catch{}i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=$B()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}check(){return!!fh}}class M3e extends DT{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(t=>{const n=y3e(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=b3e();i.readable.pipeTo(t.writable),this.writer=i.writable.getWriter();const a=()=>{r.read().then(({done:s,value:u})=>{s||(this.onPacket(u),a())}).catch(s=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then(()=>this.onOpen())})}))}write(t){this.writable=!1;for(let n=0;n{i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this.transport)===null||t===void 0||t.close()}}const F3e={websocket:L3e,webtransport:M3e,polling:O3e},P3e=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,B3e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rE(e){const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=P3e.exec(e||""),a={},o=14;for(;o--;)a[B3e[o]]=i[o]||"";return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=U3e(a,a.path),a.queryKey=$3e(a,a.query),a}function U3e(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function $3e(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(n[i]=a)}),n}let jB=class p1 extends Xn{constructor(t,n={}){super(),this.binaryType=D3e,this.writeBuffer=[],t&&typeof t=="object"&&(n=t,t=null),t?(t=rE(t),n.hostname=t.host,n.secure=t.protocol==="https"||t.protocol==="wss",n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=rE(n.host).host),W2(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=C3e(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=PB,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new F3e[t](r)}open(){let t;if(this.opts.rememberUpgrade&&p1.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else t=this.transports[0];this.readyState="opening";try{t=this.createTransport(t)}catch{this.transports.shift(),this.open();return}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(t){let n=this.createTransport(t),r=!1;p1.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;p1.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(p(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const m=new Error("probe error");m.transport=n.name,this.emitReserved("upgradeError",m)}}))};function a(){r||(r=!0,p(),n.close(),n=null)}const o=f=>{const m=new Error("probe error: "+f);m.transport=n.name,a(),this.emitReserved("upgradeError",m)};function s(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&a()}const p=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",s),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",s),this.once("close",u),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",p1.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let t=0;const n=this.upgrades.length;for(;t{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(t,n,r){return this.sendPacket("message",t,n,r),this}send(t,n,r){return this.sendPacket("message",t,n,r),this}sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:n,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}onError(t){p1.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const n=[];let r=0;const i=t.length;for(;rtypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,GB=Object.prototype.toString,G3e=typeof Blob=="function"||typeof Blob<"u"&&GB.call(Blob)==="[object BlobConstructor]",V3e=typeof File=="function"||typeof File<"u"&&GB.call(File)==="[object FileConstructor]";function MT(e){return H3e&&(e instanceof ArrayBuffer||j3e(e))||G3e&&e instanceof Blob||V3e&&e instanceof File}function Wh(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.num{delete this.acks[t];for(let o=0;o{this.io.clearTimeoutFn(a),n.apply(this,[null,...o])}}emitWithAck(t,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,a)=>{n.push((o,s)=>r?o?a(o):i(s):i(o)),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:zt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case zt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case zt.EVENT:case zt.BINARY_EVENT:this.onevent(t);break;case zt.ACK:case zt.BINARY_ACK:this.onack(t);break;case zt.DISCONNECT:this.ondisconnect();break;case zt.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:zt.ACK,id:t,data:i}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(n.apply(this,t.data),delete this.acks[t.id])}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:zt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}xc.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};xc.prototype.reset=function(){this.attempts=0};xc.prototype.setMin=function(e){this.ms=e};xc.prototype.setMax=function(e){this.max=e};xc.prototype.setJitter=function(e){this.jitter=e};class oE extends Xn{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,W2(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new xc({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const i=n.parser||Z3e;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new jB(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=Ua(n,"open",function(){r.onopen(),t&&t()}),a=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},o=Ua(n,"error",a);if(this._timeout!==!1){const s=this._timeout,u=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),n.close()},s);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ua(t,"ping",this.onping.bind(this)),Ua(t,"data",this.ondata.bind(this)),Ua(t,"error",this.onerror.bind(this)),Ua(t,"close",this.onclose.bind(this)),Ua(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){LT(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new VB(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const gd={};function qh(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=z3e(e,t.path||"/socket.io"),r=n.source,i=n.id,a=n.path,o=gd[i]&&a in gd[i].nsps,s=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let u;return s?u=new oE(r,t):(gd[i]||(gd[i]=new oE(r,t)),u=gd[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(qh,{Manager:oE,Socket:VB,io:qh,connect:qh});class WB{}class e4e extends WB{constructor(n){super();zl(this,"socket");console.log("Connecting to socket.io endpoint: ",n,window.windowId),this.socket=qh(`${n}?window_id=${window.windowId}`,{path:"/gui/socket.io",transports:["websocket","polling","flashsocket"]})}send(n,r){this.socket.emit("message",{message_type:n,data:r,message_id:Cy()})}onMessageType(n,r){this.socket.on("message",({message_type:i,data:a})=>{n===i&&r(a)})}onMessage(n){this.socket.on("message",({messageType:r,data:i})=>{n(r,i)})}onOpen(n){this.socket.on("connect",n)}onClose(n){this.socket.on("disconnect",n)}async sendAndReceive(n,r){return new Promise((i,a)=>{this.socket.emit("message",{message_type:n,data:r,message_id:Cy()},o=>{o&&o.error?a(o.error):i(o)})})}onError(n){this.socket.on("error",n)}close(){this.socket.disconnect()}}class t4e extends WB{constructor(n){super();zl(this,"serverUrl");this.serverUrl=n,_o("websocketForwardingOpen",{url:this.serverUrl})}send(n,r){_o("websocketForwardingMessage",{message:{messageType:n,data:r},url:this.serverUrl})}onMessageType(n,r){window.addEventListener("message",i=>{if(i.data.type==="websocketForwardingMessage"){const a=JSON.parse(i.data.data);a.messageType===n&&r(a.data)}})}onMessage(n){window.addEventListener("message",r=>{if(r.data.type==="websocketForwardingMessage"){const i=JSON.parse(r.data.data);n(i.messageType,i.data)}})}onError(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingError"&&n(r.data.error)})}sendAndReceive(n,r){return new Promise(i=>{const a=o=>{if(o.data.type==="websocketForwardingMessage"){const s=JSON.parse(o.data.data);s.messageType===n&&(window.removeEventListener("message",a),i(s.data))}};window.addEventListener("message",a),this.send(n,r)})}onOpen(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingOpen"&&n()})}onClose(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingClose"&&n()})}close(){_o("websocketForwardingClose",{url:this.serverUrl})}}class n4e extends c3e{constructor(n,r){super();zl(this,"messenger");zl(this,"serverUrl");zl(this,"useVscodeMessagePassing");zl(this,"onStateUpdateCallbacks",[]);this.serverUrl=n,this.useVscodeMessagePassing=r,this.serverUrl=n,this.useVscodeMessagePassing=r,this.messenger=r?new t4e(n):new e4e(n),this.messenger.onClose(()=>{console.log("GUI Connection closed: ",n)}),this.messenger.onError(i=>{console.log("GUI Connection error: ",i)}),this.messenger.onOpen(()=>{console.log("GUI Connection opened: ",n)}),this.messenger.onMessage((i,a)=>{this.handleMessage(i,a)})}onConnected(n){var r;(r=this.messenger)==null||r.onOpen(n)}handleMessage(n,r){switch(n){case"state_update":if(r.state)for(const i of this.onStateUpdateCallbacks)i(r.state);break}}loadSession(n){var r;(r=this.messenger)==null||r.send("load_session",{session_id:n})}sendMainInput(n){var r;(r=this.messenger)==null||r.send("main_input",{input:n})}runFromState(n){var r;(r=this.messenger)==null||r.send("run_from_state",{state:n})}async getSessionTitle(n){var r;return await((r=this.messenger)==null?void 0:r.sendAndReceive("get_session_title",{history:n}))}reverseToIndex(n){var r;(r=this.messenger)==null||r.send("reverse_to_index",{index:n})}sendRefinementInput(n,r){var i;(i=this.messenger)==null||i.send("refinement_input",{input:n,index:r})}sendStepUserInput(n,r){var i;(i=this.messenger)==null||i.send("step_user_input",{input:n,index:r})}onStateUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("state_update",i=>{i.state&&n(i.state)}),this.onStateUpdateCallbacks.push(n)}onSessionUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("session_update",i=>{n(i)})}onConfigUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("config_update",i=>{n(i)})}getConfig(){var n;return(n=this.messenger)==null?void 0:n.sendAndReceive("get_config",{})}onAddContextItem(n){var r;(r=this.messenger)==null||r.onMessageType("add_context_item",i=>{n(i)})}onAvailableSlashCommands(n){var r;(r=this.messenger)==null||r.onMessageType("available_slash_commands",i=>{i.commands&&n(i.commands)})}stopSession(){var n;(n=this.messenger)==null||n.send("stop_session",{})}sendClear(){var n;(n=this.messenger)==null||n.send("clear_history",{})}retryAtIndex(n){var r;(r=this.messenger)==null||r.send("retry_at_index",{index:n})}deleteContextWithIds(n,r){var i;(i=this.messenger)==null||i.send("delete_context_with_ids",{ids:n.map(a=>`${a.provider_title}-${a.item_id}`),index:r})}setEditingAtIds(n){var r;(r=this.messenger)==null||r.send("set_editing_at_ids",{ids:n})}toggleAddingHighlightedCode(){var n;(n=this.messenger)==null||n.send("toggle_adding_highlighted_code",{})}showContextVirtualFile(n){var r;(r=this.messenger)==null||r.send("show_context_virtual_file",{index:n})}selectContextItem(n,r){var i;(i=this.messenger)==null||i.send("select_context_item",{id:n,query:r})}async getContextItem(n,r){var i;return await((i=this.messenger)==null?void 0:i.sendAndReceive("get_context_item",{id:n,query:r}))}selectContextItemAtIndex(n,r,i){var a;(a=this.messenger)==null||a.send("select_context_item_at_index",{id:n,query:r,index:i})}editStepAtIndex(n,r){var i;(i=this.messenger)==null||i.send("edit_step_at_index",{user_input:n,index:r})}setSystemMessage(n){var r;(r=this.messenger)==null||r.send("set_system_message",{system_message:n})}setTemperature(n){var r;(r=this.messenger)==null||r.send("set_temperature",{temperature:n})}addModelForRole(n,r,i){var a;(a=this.messenger)==null||a.send("add_model_for_role",{role:n,model:i,model_class:r})}setModelForRoleFromIndex(n,r){var i;(i=this.messenger)==null||i.send("set_model_for_role_from_index",{role:n,index:r})}saveContextGroup(n,r){var i;(i=this.messenger)==null||i.send("save_context_group",{context_items:r,title:n})}selectContextGroup(n){var r;(r=this.messenger)==null||r.send("select_context_group",{id:n})}deleteContextGroup(n){var r;(r=this.messenger)==null||r.send("delete_context_group",{id:n})}setCurrentSessionTitle(n){var r;(r=this.messenger)==null||r.send("set_current_session_title",{title:n})}}function r4e(e=!0){const[t,n]=C.useState(void 0);return C.useEffect(()=>{const r=window.serverUrl;console.log("Creating GUI websocket",r,e);const i=new n4e(r,e);i.onConnected(()=>{n(i)})},[]),t}function i4e(){const e=EB();return console.error(e),R.jsxs("div",{id:"error-page",className:"text-center",children:[R.jsx("h1",{children:"Error in Continue React App"}),R.jsx("p",{children:R.jsx("i",{children:e.statusText||e.message})}),R.jsx("br",{}),R.jsx("pre",{className:"text-left m-4",children:e.stack})]})}const qB="28px",a4e=He.div` margin-top: 16px; margin: auto; width: ${qB}; diff --git a/extensions/vscode/gui/assets/index.js b/extensions/vscode/gui/assets/index.js index 0266c81ae..b8d0a9c01 100644 --- a/extensions/vscode/gui/assets/index.js +++ b/extensions/vscode/gui/assets/index.js @@ -782,7 +782,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho top: 0; z-index: 100; background-color: ${Vt}; -`;function YR(e){var le,he;const t=C.useContext(Ja),n=rB(),r=Io(),i=bs(),a=kt(I=>I.sessionState),o=kt(I=>{var X;return(X=I.serverState.config.models)==null?void 0:X.default}),s=kt(I=>I.misc.serverStatusMessage),u=kt(I=>I.serverState.userInputQueue),c=kt(I=>I.sessionState.title),p=kt(I=>I.sessionState.active),[f,m]=C.useState(!1),[h,b]=C.useState([]),[y,T]=C.useState(!0),[E,v]=C.useState(!0),w=C.useRef(null),A=C.useRef(null),N=C.useRef(null),x=kt(I=>I.uiState.bottomMessage),D=kt(I=>I.misc.takenAction);C.useEffect(()=>{N.current&&r(V0e(N.current.getBoundingClientRect().top{var X;const I=()=>{var q,we;const O=((q=A.current)==null?void 0:q.scrollTop)||0,Q=((we=A.current)==null?void 0:we.scrollHeight)||0,be=window.innerHeight||0;O+be+-25>=Q?V(!1):V(!0)};return(X=A.current)==null||X.addEventListener("scroll",I),()=>{window.removeEventListener("scroll",I)}},[A.current]),C.useLayoutEffect(()=>{var I,X;B||(X=A.current)==null||X.scrollTo({top:(I=A.current)==null?void 0:I.scrollHeight,behavior:"instant"})},[(le=A.current)==null?void 0:le.scrollHeight,a.history]),C.useEffect(()=>{const I=X=>{X.key==="Backspace"&&Ig(X)&&!X.shiftKey&&p?(t==null||t.stopSession(),r(Yd(!1))):X.key==="Escape"&&r(pu(void 0))};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I)}},[t,p]),C.useEffect(()=>{if(t&&y){T(!1);for(const I of u)t.sendMainInput(I)}},[t,u,y]);const P=C.useCallback(I=>{if((o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(!I.startsWith("/")||I.startsWith("/edit"))){const Q=localStorage.getItem("ftc");if(Q){const be=parseInt(Q);if(localStorage.setItem("ftc",(be+1).toString()),be>=250){r(lc(!0)),r(k4(R.jsx(l2e,{}))),n==null||n.capture("ftc_reached");return}}else localStorage.setItem("ftc","1")}m(!0);const X=[...a.history,{name:"User Input",description:I,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:I},hide:!1,depth:0}],ae={history:X,context_items:a.context_items};for(let Q of a.context_items)r(AP({item:Q,index:X.length-1}));t.runFromState(ae),X.push({name:"Generating Response...",description:" ",observations:[],logs:[],step_type:"SimpleChatStep",params:{},hide:!1,depth:0}),r(YI(X)),r(Yd(!0));const O=localStorage.getItem("mainTextEntryCounter");if(O){let Q=parseInt(O);localStorage.setItem("mainTextEntryCounter",(Q+1).toString()),Q===300&&(r(k4(R.jsxs("div",{className:"text-center p-4",children:["👋 Thanks for using Continue. We are a beta product and love working closely with our first users. If you're interested in speaking, enter your name and email. We won't use this information for anything other than reaching out.",R.jsx("br",{}),R.jsx("br",{}),R.jsxs("form",{onSubmit:be=>{be.preventDefault(),n==null||n.capture("user_interest_form",{name:be.target.elements[0].value,email:be.target.elements[1].value}),r(k4(R.jsx("div",{className:"text-center p-4",children:"Thanks! We'll be in touch soon."})))},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"text",name:"name",placeholder:"Name",required:!0}),R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"email",name:"email",placeholder:"Email",required:!0}),R.jsx("button",{style:{padding:"10px",borderRadius:"5px",cursor:"pointer"},type:"submit",children:"Submit"})]})]}))),r(G0e(!1)),r(lc(!0)))}else localStorage.setItem("mainTextEntryCounter","1")},[t,a.history,a.context_items]);C.useEffect(()=>{const I=X=>{X.data.type==="userInput"&&P(X.data.input)};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[P]);const Z=I=>{if(r(wd(null)),w.current){let X=w.current.inputValue;if(console.log("Sending main input",X),X.trim()==="")return;if(X.startsWith("#")&&(X.length===7||X.length===4)){localStorage.setItem("continueButtonColor",X),w.current.setInputValue("");return}if(I&&Ig(I)&&(X=`/edit ${X}`),w.current.setInputValue(""),!t){r(Hge(X));return}P(X)}},$=(I,X)=>{t&&t.sendStepUserInput(I,X)},oe=C.useCallback(I=>{let X=!1;for(let ae=I+1;ae{const X=[];let ae=-1;for(let O=I;O>=0;O--)if(a.history.length>O&&a.history[O].name==="User Input"&&a.history[O].hide===!1){X.push(O),ae=O;break}if(X.length===0)return[];for(let O=ae+1;OO&&a.history[O].name==="User Input"&&a.history[O].hide===!1);O++)X.push(O);return X},[a.history]),ce=C.useCallback(I=>{const X=pe(I),ae=X[0];b(O=>{const Q=[...O];return Q[I]=!Q[I],!X.some((q,we)=>we>0&&Q[q])?Q[ae]=!1:!X.some((we,te)=>te>0&&!Q[we])&&(Q[ae]=!0),Q})},[pe]);C.useEffect(()=>{c&&se(c)},[c]);const[Le,se]=C.useState(c||"New Session");return R.jsxs(h2e,{ref:A,onKeyDown:I=>{I.key==="Enter"&&I.ctrlKey&&Z()},children:[R.jsxs(y2e,{children:[R.jsx(g2e,{onClick:I=>{I.target.setSelectionRange(0,I.target.value.length)},value:Le,onChange:I=>se(I.target.value),onBlur:I=>{I.target.value===c||typeof c>"u"&&I.target.value==="New Session"||t==null||t.setCurrentSessionTitle(I.target.value)},onKeyDown:I=>{I.key==="Enter"?(I.preventDefault(),I.target.blur()):I.key==="Escape"&&(se(c||"New Session"),I.target.blur())}}),R.jsxs("div",{className:"flex gap-2",children:[a.history.filter(I=>!I.hide).length>0&&R.jsx(Ti,{onClick:()=>{a.history.filter(I=>!I.hide).length>0&&r(M2())},text:"New Session (⌥⌘N)",children:R.jsx(xL,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{i("/history")},text:"History",children:R.jsx(kQ,{width:"1.4em",height:"1.4em"})})]})]}),(D||E)&&typeof t>"u"&&R.jsxs(R.Fragment,{children:[R.jsx($ge,{}),R.jsx("p",{style:{textAlign:"center",margin:"0px",fontSize:"14px"},children:s}),R.jsxs("div",{className:"flex mx-8 my-2",children:[R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/troubleshooting",target:"_blank",children:"Troubleshooting help"})})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},onClick:()=>{_o("toggleDevTools",{})},children:R.jsx("u",{children:"View logs"})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/walkthroughs/manually-run-continue#recommended-use-the-continuedev-pypi-package",target:"_blank",children:"Manually start server"})})})]})]}),R.jsx("br",{}),R.jsx(f2e,{onClick:I=>{t==null||t.sendMainInput(I)}}),R.jsx(m2e,{children:a.history.map((I,X)=>I.hide?null:R.jsx(C.Fragment,{children:I.name==="User Input"?I.hide||R.jsx(JI,{isMainInput:!1,value:I.description,active:p&&oe(X),onEnter:(ae,O)=>{if(O){t==null||t.stopSession();const Q=[...a.history.slice(0,X),{name:"User Input",description:O,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:O},hide:!1,depth:0}];r(YI(Q)),r(Yd(!0));const be={history:Q,context_items:a.context_items};console.log("State: ",be),t.runFromState(be)}ae==null||ae.stopPropagation(),ae==null||ae.preventDefault()},groupIndices:pe(X),onToggle:ae=>{b(O=>{const Q=[...O];return pe(X).forEach(be=>{Q[be]=ae}),Q})},onToggleAll:ae=>{b(O=>O.map(Q=>ae))},isToggleOpen:typeof h[X]>"u"?!0:h[X],index:X,onDelete:()=>{pe(X).forEach(ae=>{console.log(ae),r(A4(ae))})}}):R.jsx(Yge,{historyNode:I,iconElement:I.step_type==="DefaultModelEditCodeStep"?R.jsx(vQ,{width:"16px",height:"16px"}):I.error?R.jsx(AL,{width:"16px",height:"16px",color:"red"}):R.jsx(wL,{width:"16px",height:"16px"}),open:typeof h[X]>"u"?!I.error:h[X],onToggle:()=>ce(X),children:I.error?R.jsx(Qge,{onClose:()=>ce(X),error:I.error,onDelete:()=>{r(A4(X))}}):R.jsx(Pue,{index:X,isLast:X===a.history.length-1,isFirst:X===0,open:typeof h[X]>"u"?!0:h[X],onUserInput:ae=>{$(ae,X)},step:I,onReverse:()=>{t==null||t.reverseToIndex(X)},onRetry:()=>{t==null||t.retryAtIndex(X),m(!0)},onDelete:()=>{r(A4(X))},noUserInputParent:pe(X).length===0},X)})},X))}),R.jsx("div",{children:(he=u==null?void 0:u.map)==null?void 0:he.call(u,(I,X)=>R.jsx(b2e,{children:I},X))}),R.jsx("div",{ref:N}),R.jsx(JI,{isMainInput:!0,ref:w,onEnter:(I,X)=>{Z(I),I==null||I.stopPropagation(),I==null||I.preventDefault()},onInputValueChange:()=>{},onToggleAddContext:()=>{t==null||t.toggleAddingHighlightedCode()}})]})}const E2e=He.div` +`;function YR(e){var le,he;const t=C.useContext(Ja),n=rB(),r=Io(),i=bs(),a=kt(I=>I.sessionState),o=kt(I=>{var X;return(X=I.serverState.config.models)==null?void 0:X.default}),s=kt(I=>I.misc.serverStatusMessage),u=kt(I=>I.serverState.userInputQueue),c=kt(I=>I.sessionState.title),p=kt(I=>I.sessionState.active),[f,m]=C.useState(!1),[h,b]=C.useState([]),[y,T]=C.useState(!0),[E,v]=C.useState(!0),w=C.useRef(null),A=C.useRef(null),N=C.useRef(null),x=kt(I=>I.uiState.bottomMessage),D=kt(I=>I.misc.takenAction);C.useEffect(()=>{N.current&&r(V0e(N.current.getBoundingClientRect().top{var X;const I=()=>{var q,we;const O=((q=A.current)==null?void 0:q.scrollTop)||0,Q=((we=A.current)==null?void 0:we.scrollHeight)||0,be=window.innerHeight||0;O+be+-25>=Q?V(!1):V(!0)};return(X=A.current)==null||X.addEventListener("scroll",I),()=>{window.removeEventListener("scroll",I)}},[A.current]),C.useLayoutEffect(()=>{var I,X;B||(X=A.current)==null||X.scrollTo({top:(I=A.current)==null?void 0:I.scrollHeight,behavior:"instant"})},[(le=A.current)==null?void 0:le.scrollHeight,a.history]),C.useEffect(()=>{const I=X=>{X.key==="Backspace"&&Ig(X)&&!X.shiftKey&&p?(t==null||t.stopSession(),r(Yd(!1))):X.key==="Escape"&&r(pu(void 0))};return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I)}},[t,p]),C.useEffect(()=>{if(t&&y){T(!1);for(const I of u)t.sendMainInput(I)}},[t,u,y]);const P=C.useCallback(I=>{if((o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(!I.startsWith("/")||I.startsWith("/edit"))){const Q=localStorage.getItem("ftc");if(Q){const be=parseInt(Q);if(localStorage.setItem("ftc",(be+1).toString()),be>=250){r(lc(!0)),r(k4(R.jsx(l2e,{}))),n==null||n.capture("ftc_reached");return}}else localStorage.setItem("ftc","1")}m(!0);const X=[...a.history,{name:"User Input",description:I,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:I},hide:!1,depth:0}],ae={history:X,context_items:a.context_items};for(let Q of a.context_items)r(AP({item:Q,index:X.length-1}));t.runFromState(ae),X.push({name:"Generating Response...",description:" ",observations:[],logs:[],step_type:"SimpleChatStep",params:{},hide:!1,depth:0}),r(YI(X)),r(Yd(!0));const O=localStorage.getItem("mainTextEntryCounter");if(O){let Q=parseInt(O);localStorage.setItem("mainTextEntryCounter",(Q+1).toString()),Q===300&&(r(k4(R.jsxs("div",{className:"text-center p-4",children:["👋 Thanks for using Continue. We are a beta product and love working closely with our first users. If you're interested in speaking, enter your name and email. We won't use this information for anything other than reaching out.",R.jsx("br",{}),R.jsx("br",{}),R.jsxs("form",{onSubmit:be=>{be.preventDefault(),n==null||n.capture("user_interest_form",{name:be.target.elements[0].value,email:be.target.elements[1].value}),r(k4(R.jsx("div",{className:"text-center p-4",children:"Thanks! We'll be in touch soon."})))},style:{display:"flex",flexDirection:"column",gap:"10px"},children:[R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"text",name:"name",placeholder:"Name",required:!0}),R.jsx("input",{style:{padding:"10px",borderRadius:"5px"},type:"email",name:"email",placeholder:"Email",required:!0}),R.jsx("button",{style:{padding:"10px",borderRadius:"5px",cursor:"pointer"},type:"submit",children:"Submit"})]})]}))),r(G0e(!1)),r(lc(!0)))}else localStorage.setItem("mainTextEntryCounter","1")},[t,a.history,a.context_items]);C.useEffect(()=>{const I=X=>{X.data.type==="userInput"&&P(X.data.input)};return window.addEventListener("message",I),()=>window.removeEventListener("message",I)},[P]);const Z=I=>{if(r(wd(null)),w.current){let X=w.current.inputValue;if(console.log("Sending main input",X),X.trim()==="")return;if(X.startsWith("#")&&(X.length===7||X.length===4)){localStorage.setItem("continueButtonColor",X),w.current.setInputValue("");return}if(I&&Ig(I)&&(X=`/edit ${X}`),w.current.setInputValue(""),!t){r(Hge(X));return}P(X)}},$=(I,X)=>{t&&t.sendStepUserInput(I,X)},oe=C.useCallback(I=>{let X=!1;for(let ae=I+1;ae{const X=[];let ae=-1;for(let O=I;O>=0;O--)if(a.history.length>O&&a.history[O].name==="User Input"&&a.history[O].hide===!1){X.push(O),ae=O;break}if(X.length===0)return[];for(let O=ae+1;OO&&a.history[O].name==="User Input"&&a.history[O].hide===!1);O++)X.push(O);return X},[a.history]),ce=C.useCallback(I=>{const X=pe(I),ae=X[0];b(O=>{const Q=[...O];return Q[I]=!Q[I],!X.some((q,we)=>we>0&&Q[q])?Q[ae]=!1:!X.some((we,te)=>te>0&&!Q[we])&&(Q[ae]=!0),Q})},[pe]);C.useEffect(()=>{c&&se(c)},[c]);const[Le,se]=C.useState(c||"New Session");return R.jsxs(h2e,{ref:A,onKeyDown:I=>{I.key==="Enter"&&I.ctrlKey&&Z()},children:[R.jsxs(y2e,{children:[R.jsx(g2e,{onClick:I=>{I.target.setSelectionRange(0,I.target.value.length)},value:Le,onChange:I=>se(I.target.value),onBlur:I=>{I.target.value===c||typeof c>"u"&&I.target.value==="New Session"||t==null||t.setCurrentSessionTitle(I.target.value)},onKeyDown:I=>{I.key==="Enter"?(I.preventDefault(),I.target.blur()):I.key==="Escape"&&(se(c||"New Session"),I.target.blur())}}),R.jsxs("div",{className:"flex gap-2",children:[a.history.filter(I=>!I.hide).length>0&&R.jsx(Ti,{onClick:()=>{r(M2())},text:"New Session (⌥⌘N)",children:R.jsx(xL,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{i("/history")},text:"History",children:R.jsx(kQ,{width:"1.4em",height:"1.4em"})})]})]}),(D||E)&&typeof t>"u"&&R.jsxs(R.Fragment,{children:[R.jsx($ge,{}),R.jsx("p",{style:{textAlign:"center",margin:"0px",fontSize:"14px"},children:s}),R.jsxs("div",{className:"flex mx-8 my-2",children:[R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/troubleshooting",target:"_blank",children:"Troubleshooting help"})})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},onClick:()=>{_o("toggleDevTools",{})},children:R.jsx("u",{children:"View logs"})}),R.jsx("p",{style:{margin:"auto",textAlign:"center",marginTop:"4px",fontSize:"12px",cursor:"pointer",opacity:.7},children:R.jsx("u",{children:R.jsx("a",{style:{color:"inherit"},href:"https://continue.dev/docs/walkthroughs/manually-run-continue#recommended-use-the-continuedev-pypi-package",target:"_blank",children:"Manually start server"})})})]})]}),R.jsx("br",{}),R.jsx(f2e,{onClick:I=>{t==null||t.sendMainInput(I)}}),R.jsx(m2e,{children:a.history.map((I,X)=>I.hide?null:R.jsx(C.Fragment,{children:I.name==="User Input"?I.hide||R.jsx(JI,{isMainInput:!1,value:I.description,active:p&&oe(X),onEnter:(ae,O)=>{if(O){t==null||t.stopSession();const Q=[...a.history.slice(0,X),{name:"User Input",description:O,observations:[],logs:[],step_type:"UserInputStep",params:{user_input:O},hide:!1,depth:0}];r(YI(Q)),r(Yd(!0));const be={history:Q,context_items:a.context_items};console.log("State: ",be),t.runFromState(be)}ae==null||ae.stopPropagation(),ae==null||ae.preventDefault()},groupIndices:pe(X),onToggle:ae=>{b(O=>{const Q=[...O];return pe(X).forEach(be=>{Q[be]=ae}),Q})},onToggleAll:ae=>{b(O=>O.map(Q=>ae))},isToggleOpen:typeof h[X]>"u"?!0:h[X],index:X,onDelete:()=>{pe(X).forEach(ae=>{console.log(ae),r(A4(ae))})}}):R.jsx(Yge,{historyNode:I,iconElement:I.step_type==="DefaultModelEditCodeStep"?R.jsx(vQ,{width:"16px",height:"16px"}):I.error?R.jsx(AL,{width:"16px",height:"16px",color:"red"}):R.jsx(wL,{width:"16px",height:"16px"}),open:typeof h[X]>"u"?!I.error:h[X],onToggle:()=>ce(X),children:I.error?R.jsx(Qge,{onClose:()=>ce(X),error:I.error,onDelete:()=>{r(A4(X))}}):R.jsx(Pue,{index:X,isLast:X===a.history.length-1,isFirst:X===0,open:typeof h[X]>"u"?!0:h[X],onUserInput:ae=>{$(ae,X)},step:I,onReverse:()=>{t==null||t.reverseToIndex(X)},onRetry:()=>{t==null||t.retryAtIndex(X),m(!0)},onDelete:()=>{r(A4(X))},noUserInputParent:pe(X).length===0},X)})},X))}),R.jsx("div",{children:(he=u==null?void 0:u.map)==null?void 0:he.call(u,(I,X)=>R.jsx(b2e,{children:I},X))}),R.jsx("div",{ref:N}),R.jsx(JI,{isMainInput:!0,ref:w,onEnter:(I,X)=>{Z(I),I==null||I.stopPropagation(),I==null||I.preventDefault()},onInputValueChange:()=>{},onToggleAddContext:()=>{t==null||t.toggleAddingHighlightedCode()}})]})}const E2e=He.div` display: flex; flex-direction: row; align-items: center; @@ -1080,7 +1080,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho margin-left: 8px; z-index: 200; font-size: ${ir()}; -`,u3e=()=>{const e=bs(),t=ST(),n=C.useContext(Ja),r=Io(),i=kt(p=>p.uiState.dialogMessage),a=kt(p=>p.uiState.showDialog),o=kt(p=>{var f;return(f=p.serverState.config.models)==null?void 0:f.default}),s=kt(p=>p.uiState.bottomMessage),u=kt(p=>p.uiState.displayBottomMessageOnBottom),c=kt(p=>p.sessionState.history);return C.useEffect(()=>{const p=f=>{var m;if(f.metaKey&&f.altKey&&f.code==="KeyN"&&c.filter(h=>!h.hide).length>0&&r(M2()),(f.metaKey||f.ctrlKey)&&f.code==="KeyC"){const h=(m=window.getSelection())==null?void 0:m.toString();h&&setTimeout(()=>{navigator.clipboard.writeText(h)},100)}};return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p)}},[n,c]),C.useEffect(()=>{const p=f=>{f.data.type==="addModel"?e("/models"):f.data.type==="openSettings"&&e("/settings")};return window.addEventListener("message",p),()=>{window.removeEventListener("message",p)}},[]),R.jsxs(i3e,{children:[R.jsxs("div",{style:{scrollbarGutter:"stable both-edges",minHeight:"100%",display:"grid",gridTemplateRows:"1fr auto"},children:[R.jsx(D2e,{showDialog:a,onEnter:()=>{r(lc(!1))},onClose:()=>{r(lc(!1))},message:i}),R.jsxs(s3e,{children:[R.jsx(r2e,{}),R.jsx(l3e,{id:"model-select-top-div"}),R.jsxs(o3e,{children:[R.jsxs("div",{className:"mr-auto flex gap-2 items-center",children:[localStorage.getItem("ide")==="jetbrains"||localStorage.getItem("hideFeature")==="true"||R.jsx(kL,{className:"cursor-pointer",onClick:()=>{localStorage.setItem("hideFeature","true")},onMouseEnter:()=>{r(pu("🎁 New Feature: Use ⌘⇧R automatically debug errors in the terminal (you can click the sparkle icon to make it go away)"))},onMouseLeave:()=>{r(QI(setTimeout(()=>{r(pu(void 0))},2e3)))},width:"1.3em",height:"1.3em",color:"yellow"}),R.jsx(Q5e,{}),(o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(t.pathname==="/settings"||parseInt(localStorage.getItem("ftc")||"0")>=125)&&R.jsx(n3e,{completed:parseInt(localStorage.getItem("ftc")||"0"),total:250})]}),R.jsx(Ti,{text:"Help",onClick:()=>{e("/help")},children:R.jsx(qQ,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{e("/settings")},text:"Settings",children:R.jsx(SQ,{width:"1.4em",height:"1.4em"})})]})]}),R.jsx(a3e,{displayOnBottom:u,onMouseEnter:()=>{r(QI(void 0))},onMouseLeave:p=>{p.buttons||r(pu(void 0))},hidden:!s,children:s})]}),R.jsx("div",{className:"text-sm",id:"tooltip-portal-div"})]})};class c3e{}const Co=Object.create(null);Co.open="0";Co.close="1";Co.ping="2";Co.pong="3";Co.message="4";Co.upgrade="5";Co.noop="6";const Gh=Object.create(null);Object.keys(Co).forEach(e=>{Gh[Co[e]]=e});const tE={type:"error",data:"parser error"},OB=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",DB=typeof ArrayBuffer=="function",LB=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,NT=({type:e,data:t},n,r)=>OB&&t instanceof Blob?n?r(t):aN(t,r):DB&&(t instanceof ArrayBuffer||LB(t))?n?r(t):aN(new Blob([t]),r):r(Co[e]+(t||"")),aN=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function oN(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let V4;function d3e(e,t){if(OB&&e.data instanceof Blob)return e.data.arrayBuffer().then(oN).then(t);if(DB&&(e.data instanceof ArrayBuffer||LB(e.data)))return t(oN(e.data));NT(e,!1,n=>{V4||(V4=new TextEncoder),t(V4.encode(n))})}const sN="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cd=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,i=0,a,o,s,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const c=new ArrayBuffer(t),p=new Uint8Array(c);for(r=0;r>4,p[i++]=(o&15)<<4|s>>2,p[i++]=(s&3)<<6|u&63;return c},f3e=typeof ArrayBuffer=="function",OT=(e,t)=>{if(typeof e!="string")return{type:"message",data:MB(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:h3e(e.substring(1),t)}:Gh[n]?e.length>1?{type:Gh[n],data:e.substring(1)}:{type:Gh[n]}:tE},h3e=(e,t)=>{if(f3e){const n=p3e(e);return MB(n,t)}else return{base64:!0,data:e}},MB=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},FB=String.fromCharCode(30),g3e=(e,t)=>{const n=e.length,r=new Array(n);let i=0;e.forEach((a,o)=>{NT(a,!1,s=>{r[o]=s,++i===n&&t(r.join(FB))})})},m3e=(e,t)=>{const n=e.split(FB),r=[];for(let i=0;i{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}let W4;function ch(e){return e.reduce((t,n)=>t+n.length,0)}function dh(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;iMath.pow(2,53-32)-1){s.enqueue(tE);break}i=p*Math.pow(2,32)+c.getUint32(4),r=3}else{if(ch(n)e){s.enqueue(tE);break}}}})}const PB=4;function Xn(e){if(e)return E3e(e)}function E3e(e){for(var t in Xn.prototype)e[t]=Xn.prototype[t];return e}Xn.prototype.on=Xn.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};Xn.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};Xn.prototype.off=Xn.prototype.removeListener=Xn.prototype.removeAllListeners=Xn.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;itypeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function BB(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const v3e=da.setTimeout,_3e=da.clearTimeout;function W2(e,t){t.useNativeTimers?(e.setTimeoutFn=v3e.bind(da),e.clearTimeoutFn=_3e.bind(da)):(e.setTimeoutFn=da.setTimeout.bind(da),e.clearTimeoutFn=da.clearTimeout.bind(da))}const T3e=1.33;function S3e(e){return typeof e=="string"?w3e(e):Math.ceil((e.byteLength||e.size)*T3e)}function w3e(e){let t=0,n=0;for(let r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function A3e(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function C3e(e){let t={},n=e.split("&");for(let r=0,i=n.length;r0);return t}function $B(){const e=cN(+new Date);return e!==uN?(lN=0,uN=e):e+"."+cN(lN++)}for(;ph{this.readyState="paused",t()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};m3e(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,g3e(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=$B()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Y1(this.uri(),t)}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}let Y1=class Vh extends Xn{constructor(t,n){super(),W2(this,n),this.opts=n,this.method=n.method||"GET",this.uri=t,this.data=n.data!==void 0?n.data:null,this.create()}create(){var t;const n=BB(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new HB(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this.opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=Vh.requestsCount++,Vh.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=R3e,t)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Vh.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};Y1.requestsCount=0;Y1.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",dN);else if(typeof addEventListener=="function"){const e="onpagehide"in da?"pagehide":"unload";addEventListener(e,dN,!1)}}function dN(){for(let e in Y1.requests)Y1.requests.hasOwnProperty(e)&&Y1.requests[e].abort()}const LT=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0))(),fh=da.WebSocket||da.MozWebSocket,pN=!0,D3e="arraybuffer",fN=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class L3e extends DT{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),n=this.opts.protocols,r=fN?{}:BB(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=pN&&!fN?n?new fh(t,n):new fh(t):new fh(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{const o={};try{pN&&this.ws.send(a)}catch{}i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=$B()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}check(){return!!fh}}class M3e extends DT{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(t=>{const n=y3e(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=b3e();i.readable.pipeTo(t.writable),this.writer=i.writable.getWriter();const a=()=>{r.read().then(({done:s,value:u})=>{s||(this.onPacket(u),a())}).catch(s=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then(()=>this.onOpen())})}))}write(t){this.writable=!1;for(let n=0;n{i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this.transport)===null||t===void 0||t.close()}}const F3e={websocket:L3e,webtransport:M3e,polling:O3e},P3e=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,B3e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rE(e){const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=P3e.exec(e||""),a={},o=14;for(;o--;)a[B3e[o]]=i[o]||"";return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=U3e(a,a.path),a.queryKey=$3e(a,a.query),a}function U3e(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function $3e(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(n[i]=a)}),n}let jB=class p1 extends Xn{constructor(t,n={}){super(),this.binaryType=D3e,this.writeBuffer=[],t&&typeof t=="object"&&(n=t,t=null),t?(t=rE(t),n.hostname=t.host,n.secure=t.protocol==="https"||t.protocol==="wss",n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=rE(n.host).host),W2(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=C3e(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=PB,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new F3e[t](r)}open(){let t;if(this.opts.rememberUpgrade&&p1.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else t=this.transports[0];this.readyState="opening";try{t=this.createTransport(t)}catch{this.transports.shift(),this.open();return}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(t){let n=this.createTransport(t),r=!1;p1.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;p1.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(p(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const m=new Error("probe error");m.transport=n.name,this.emitReserved("upgradeError",m)}}))};function a(){r||(r=!0,p(),n.close(),n=null)}const o=f=>{const m=new Error("probe error: "+f);m.transport=n.name,a(),this.emitReserved("upgradeError",m)};function s(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&a()}const p=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",s),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",s),this.once("close",u),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",p1.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let t=0;const n=this.upgrades.length;for(;t{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(t,n,r){return this.sendPacket("message",t,n,r),this}send(t,n,r){return this.sendPacket("message",t,n,r),this}sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:n,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}onError(t){p1.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const n=[];let r=0;const i=t.length;for(;rtypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,GB=Object.prototype.toString,G3e=typeof Blob=="function"||typeof Blob<"u"&&GB.call(Blob)==="[object BlobConstructor]",V3e=typeof File=="function"||typeof File<"u"&&GB.call(File)==="[object FileConstructor]";function MT(e){return H3e&&(e instanceof ArrayBuffer||j3e(e))||G3e&&e instanceof Blob||V3e&&e instanceof File}function Wh(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.num{delete this.acks[t];for(let o=0;o{this.io.clearTimeoutFn(a),n.apply(this,[null,...o])}}emitWithAck(t,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,a)=>{n.push((o,s)=>r?o?a(o):i(s):i(o)),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:zt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case zt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case zt.EVENT:case zt.BINARY_EVENT:this.onevent(t);break;case zt.ACK:case zt.BINARY_ACK:this.onack(t);break;case zt.DISCONNECT:this.ondisconnect();break;case zt.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:zt.ACK,id:t,data:i}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(n.apply(this,t.data),delete this.acks[t.id])}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:zt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}xc.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};xc.prototype.reset=function(){this.attempts=0};xc.prototype.setMin=function(e){this.ms=e};xc.prototype.setMax=function(e){this.max=e};xc.prototype.setJitter=function(e){this.jitter=e};class oE extends Xn{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,W2(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new xc({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const i=n.parser||Z3e;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new jB(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=Ua(n,"open",function(){r.onopen(),t&&t()}),a=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},o=Ua(n,"error",a);if(this._timeout!==!1){const s=this._timeout,u=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),n.close()},s);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ua(t,"ping",this.onping.bind(this)),Ua(t,"data",this.ondata.bind(this)),Ua(t,"error",this.onerror.bind(this)),Ua(t,"close",this.onclose.bind(this)),Ua(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){LT(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new VB(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const gd={};function qh(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=z3e(e,t.path||"/socket.io"),r=n.source,i=n.id,a=n.path,o=gd[i]&&a in gd[i].nsps,s=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let u;return s?u=new oE(r,t):(gd[i]||(gd[i]=new oE(r,t)),u=gd[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(qh,{Manager:oE,Socket:VB,io:qh,connect:qh});class WB{}class e4e extends WB{constructor(n){super();zl(this,"socket");console.log("Connecting to socket.io endpoint: ",n,window.windowId),this.socket=qh(`${n}?window_id=${window.windowId}`,{path:"/gui/socket.io",transports:["websocket","polling","flashsocket"]})}send(n,r){this.socket.emit("message",{message_type:n,data:r,message_id:Cy()})}onMessageType(n,r){this.socket.on("message",({message_type:i,data:a})=>{n===i&&r(a)})}onMessage(n){this.socket.on("message",({messageType:r,data:i})=>{n(r,i)})}onOpen(n){this.socket.on("connect",n)}onClose(n){this.socket.on("disconnect",n)}async sendAndReceive(n,r){return new Promise((i,a)=>{this.socket.emit("message",{message_type:n,data:r,message_id:Cy()},o=>{o&&o.error?a(o.error):i(o)})})}onError(n){this.socket.on("error",n)}close(){this.socket.disconnect()}}class t4e extends WB{constructor(n){super();zl(this,"serverUrl");this.serverUrl=n,_o("websocketForwardingOpen",{url:this.serverUrl})}send(n,r){_o("websocketForwardingMessage",{message:{messageType:n,data:r},url:this.serverUrl})}onMessageType(n,r){window.addEventListener("message",i=>{if(i.data.type==="websocketForwardingMessage"){const a=JSON.parse(i.data.data);a.messageType===n&&r(a.data)}})}onMessage(n){window.addEventListener("message",r=>{if(r.data.type==="websocketForwardingMessage"){const i=JSON.parse(r.data.data);n(i.messageType,i.data)}})}onError(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingError"&&n(r.data.error)})}sendAndReceive(n,r){return new Promise(i=>{const a=o=>{if(o.data.type==="websocketForwardingMessage"){const s=JSON.parse(o.data.data);s.messageType===n&&(window.removeEventListener("message",a),i(s.data))}};window.addEventListener("message",a),this.send(n,r)})}onOpen(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingOpen"&&n()})}onClose(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingClose"&&n()})}close(){_o("websocketForwardingClose",{url:this.serverUrl})}}class n4e extends c3e{constructor(n,r){super();zl(this,"messenger");zl(this,"serverUrl");zl(this,"useVscodeMessagePassing");zl(this,"onStateUpdateCallbacks",[]);this.serverUrl=n,this.useVscodeMessagePassing=r,this.serverUrl=n,this.useVscodeMessagePassing=r,this.messenger=r?new t4e(n):new e4e(n),this.messenger.onClose(()=>{console.log("GUI Connection closed: ",n)}),this.messenger.onError(i=>{console.log("GUI Connection error: ",i)}),this.messenger.onOpen(()=>{console.log("GUI Connection opened: ",n)}),this.messenger.onMessage((i,a)=>{this.handleMessage(i,a)})}onConnected(n){var r;(r=this.messenger)==null||r.onOpen(n)}handleMessage(n,r){switch(n){case"state_update":if(r.state)for(const i of this.onStateUpdateCallbacks)i(r.state);break}}loadSession(n){var r;(r=this.messenger)==null||r.send("load_session",{session_id:n})}sendMainInput(n){var r;(r=this.messenger)==null||r.send("main_input",{input:n})}runFromState(n){var r;(r=this.messenger)==null||r.send("run_from_state",{state:n})}async getSessionTitle(n){var r;return await((r=this.messenger)==null?void 0:r.sendAndReceive("get_session_title",{history:n}))}reverseToIndex(n){var r;(r=this.messenger)==null||r.send("reverse_to_index",{index:n})}sendRefinementInput(n,r){var i;(i=this.messenger)==null||i.send("refinement_input",{input:n,index:r})}sendStepUserInput(n,r){var i;(i=this.messenger)==null||i.send("step_user_input",{input:n,index:r})}onStateUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("state_update",i=>{i.state&&n(i.state)}),this.onStateUpdateCallbacks.push(n)}onSessionUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("session_update",i=>{n(i)})}onConfigUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("config_update",i=>{n(i)})}getConfig(){var n;return(n=this.messenger)==null?void 0:n.sendAndReceive("get_config",{})}onAddContextItem(n){var r;(r=this.messenger)==null||r.onMessageType("add_context_item",i=>{n(i)})}onAvailableSlashCommands(n){var r;(r=this.messenger)==null||r.onMessageType("available_slash_commands",i=>{i.commands&&n(i.commands)})}stopSession(){var n;(n=this.messenger)==null||n.send("stop_session",{})}sendClear(){var n;(n=this.messenger)==null||n.send("clear_history",{})}retryAtIndex(n){var r;(r=this.messenger)==null||r.send("retry_at_index",{index:n})}deleteContextWithIds(n,r){var i;(i=this.messenger)==null||i.send("delete_context_with_ids",{ids:n.map(a=>`${a.provider_title}-${a.item_id}`),index:r})}setEditingAtIds(n){var r;(r=this.messenger)==null||r.send("set_editing_at_ids",{ids:n})}toggleAddingHighlightedCode(){var n;(n=this.messenger)==null||n.send("toggle_adding_highlighted_code",{})}showContextVirtualFile(n){var r;(r=this.messenger)==null||r.send("show_context_virtual_file",{index:n})}selectContextItem(n,r){var i;(i=this.messenger)==null||i.send("select_context_item",{id:n,query:r})}async getContextItem(n,r){var i;return await((i=this.messenger)==null?void 0:i.sendAndReceive("get_context_item",{id:n,query:r}))}selectContextItemAtIndex(n,r,i){var a;(a=this.messenger)==null||a.send("select_context_item_at_index",{id:n,query:r,index:i})}editStepAtIndex(n,r){var i;(i=this.messenger)==null||i.send("edit_step_at_index",{user_input:n,index:r})}setSystemMessage(n){var r;(r=this.messenger)==null||r.send("set_system_message",{system_message:n})}setTemperature(n){var r;(r=this.messenger)==null||r.send("set_temperature",{temperature:n})}addModelForRole(n,r,i){var a;(a=this.messenger)==null||a.send("add_model_for_role",{role:n,model:i,model_class:r})}setModelForRoleFromIndex(n,r){var i;(i=this.messenger)==null||i.send("set_model_for_role_from_index",{role:n,index:r})}saveContextGroup(n,r){var i;(i=this.messenger)==null||i.send("save_context_group",{context_items:r,title:n})}selectContextGroup(n){var r;(r=this.messenger)==null||r.send("select_context_group",{id:n})}deleteContextGroup(n){var r;(r=this.messenger)==null||r.send("delete_context_group",{id:n})}setCurrentSessionTitle(n){var r;(r=this.messenger)==null||r.send("set_current_session_title",{title:n})}}function r4e(e=!0){const[t,n]=C.useState(void 0);return C.useEffect(()=>{const r=window.serverUrl;console.log("Creating GUI websocket",r,e);const i=new n4e(r,e);i.onConnected(()=>{n(i)})},[]),t}function i4e(){const e=EB();return console.error(e),R.jsxs("div",{id:"error-page",className:"text-center",children:[R.jsx("h1",{children:"Error in Continue React App"}),R.jsx("p",{children:R.jsx("i",{children:e.statusText||e.message})}),R.jsx("br",{}),R.jsx("pre",{className:"text-left m-4",children:e.stack})]})}const qB="28px",a4e=He.div` +`,u3e=()=>{const e=bs(),t=ST(),n=C.useContext(Ja),r=Io(),i=kt(p=>p.uiState.dialogMessage),a=kt(p=>p.uiState.showDialog),o=kt(p=>{var f;return(f=p.serverState.config.models)==null?void 0:f.default}),s=kt(p=>p.uiState.bottomMessage),u=kt(p=>p.uiState.displayBottomMessageOnBottom),c=kt(p=>p.sessionState.history);return C.useEffect(()=>{const p=f=>{var m;if(f.metaKey&&f.altKey&&f.code==="KeyN"&&r(M2()),(f.metaKey||f.ctrlKey)&&f.code==="KeyC"){const h=(m=window.getSelection())==null?void 0:m.toString();h&&setTimeout(()=>{navigator.clipboard.writeText(h)},100)}};return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p)}},[n,c]),C.useEffect(()=>{const p=f=>{f.data.type==="addModel"?e("/models"):f.data.type==="openSettings"&&e("/settings")};return window.addEventListener("message",p),()=>{window.removeEventListener("message",p)}},[]),R.jsxs(i3e,{children:[R.jsxs("div",{style:{scrollbarGutter:"stable both-edges",minHeight:"100%",display:"grid",gridTemplateRows:"1fr auto"},children:[R.jsx(D2e,{showDialog:a,onEnter:()=>{r(lc(!1))},onClose:()=>{r(lc(!1))},message:i}),R.jsxs(s3e,{children:[R.jsx(r2e,{}),R.jsx(l3e,{id:"model-select-top-div"}),R.jsxs(o3e,{children:[R.jsxs("div",{className:"mr-auto flex gap-2 items-center",children:[localStorage.getItem("ide")==="jetbrains"||localStorage.getItem("hideFeature")==="true"||R.jsx(kL,{className:"cursor-pointer",onClick:()=>{localStorage.setItem("hideFeature","true")},onMouseEnter:()=>{r(pu("🎁 New Feature: Use ⌘⇧R automatically debug errors in the terminal (you can click the sparkle icon to make it go away)"))},onMouseLeave:()=>{r(QI(setTimeout(()=>{r(pu(void 0))},2e3)))},width:"1.3em",height:"1.3em",color:"yellow"}),R.jsx(Q5e,{}),(o==null?void 0:o.class_name)==="OpenAIFreeTrial"&&(o==null?void 0:o.api_key)===""&&(t.pathname==="/settings"||parseInt(localStorage.getItem("ftc")||"0")>=125)&&R.jsx(n3e,{completed:parseInt(localStorage.getItem("ftc")||"0"),total:250})]}),R.jsx(Ti,{text:"Help",onClick:()=>{e("/help")},children:R.jsx(qQ,{width:"1.4em",height:"1.4em"})}),R.jsx(Ti,{onClick:()=>{e("/settings")},text:"Settings",children:R.jsx(SQ,{width:"1.4em",height:"1.4em"})})]})]}),R.jsx(a3e,{displayOnBottom:u,onMouseEnter:()=>{r(QI(void 0))},onMouseLeave:p=>{p.buttons||r(pu(void 0))},hidden:!s,children:s})]}),R.jsx("div",{className:"text-sm",id:"tooltip-portal-div"})]})};class c3e{}const Co=Object.create(null);Co.open="0";Co.close="1";Co.ping="2";Co.pong="3";Co.message="4";Co.upgrade="5";Co.noop="6";const Gh=Object.create(null);Object.keys(Co).forEach(e=>{Gh[Co[e]]=e});const tE={type:"error",data:"parser error"},OB=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",DB=typeof ArrayBuffer=="function",LB=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,NT=({type:e,data:t},n,r)=>OB&&t instanceof Blob?n?r(t):aN(t,r):DB&&(t instanceof ArrayBuffer||LB(t))?n?r(t):aN(new Blob([t]),r):r(Co[e]+(t||"")),aN=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function oN(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let V4;function d3e(e,t){if(OB&&e.data instanceof Blob)return e.data.arrayBuffer().then(oN).then(t);if(DB&&(e.data instanceof ArrayBuffer||LB(e.data)))return t(oN(e.data));NT(e,!1,n=>{V4||(V4=new TextEncoder),t(V4.encode(n))})}const sN="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cd=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,i=0,a,o,s,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const c=new ArrayBuffer(t),p=new Uint8Array(c);for(r=0;r>4,p[i++]=(o&15)<<4|s>>2,p[i++]=(s&3)<<6|u&63;return c},f3e=typeof ArrayBuffer=="function",OT=(e,t)=>{if(typeof e!="string")return{type:"message",data:MB(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:h3e(e.substring(1),t)}:Gh[n]?e.length>1?{type:Gh[n],data:e.substring(1)}:{type:Gh[n]}:tE},h3e=(e,t)=>{if(f3e){const n=p3e(e);return MB(n,t)}else return{base64:!0,data:e}},MB=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},FB=String.fromCharCode(30),g3e=(e,t)=>{const n=e.length,r=new Array(n);let i=0;e.forEach((a,o)=>{NT(a,!1,s=>{r[o]=s,++i===n&&t(r.join(FB))})})},m3e=(e,t)=>{const n=e.split(FB),r=[];for(let i=0;i{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const a=new DataView(i.buffer);a.setUint8(0,126),a.setUint16(1,r)}else{i=new Uint8Array(9);const a=new DataView(i.buffer);a.setUint8(0,127),a.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}let W4;function ch(e){return e.reduce((t,n)=>t+n.length,0)}function dh(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;iMath.pow(2,53-32)-1){s.enqueue(tE);break}i=p*Math.pow(2,32)+c.getUint32(4),r=3}else{if(ch(n)e){s.enqueue(tE);break}}}})}const PB=4;function Xn(e){if(e)return E3e(e)}function E3e(e){for(var t in Xn.prototype)e[t]=Xn.prototype[t];return e}Xn.prototype.on=Xn.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};Xn.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};Xn.prototype.off=Xn.prototype.removeListener=Xn.prototype.removeAllListeners=Xn.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;itypeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function BB(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const v3e=da.setTimeout,_3e=da.clearTimeout;function W2(e,t){t.useNativeTimers?(e.setTimeoutFn=v3e.bind(da),e.clearTimeoutFn=_3e.bind(da)):(e.setTimeoutFn=da.setTimeout.bind(da),e.clearTimeoutFn=da.clearTimeout.bind(da))}const T3e=1.33;function S3e(e){return typeof e=="string"?w3e(e):Math.ceil((e.byteLength||e.size)*T3e)}function w3e(e){let t=0,n=0;for(let r=0,i=e.length;r=57344?n+=3:(r++,n+=4);return n}function A3e(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function C3e(e){let t={},n=e.split("&");for(let r=0,i=n.length;r0);return t}function $B(){const e=cN(+new Date);return e!==uN?(lN=0,uN=e):e+"."+cN(lN++)}for(;ph{this.readyState="paused",t()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};m3e(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,g3e(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=$B()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Y1(this.uri(),t)}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,a)=>{this.onError("xhr post error",i,a)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}let Y1=class Vh extends Xn{constructor(t,n){super(),W2(this,n),this.opts=n,this.method=n.method||"GET",this.uri=t,this.data=n.data!==void 0?n.data:null,this.create()}create(){var t;const n=BB(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new HB(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this.opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=Vh.requestsCount++,Vh.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=R3e,t)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Vh.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};Y1.requestsCount=0;Y1.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",dN);else if(typeof addEventListener=="function"){const e="onpagehide"in da?"pagehide":"unload";addEventListener(e,dN,!1)}}function dN(){for(let e in Y1.requests)Y1.requests.hasOwnProperty(e)&&Y1.requests[e].abort()}const LT=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0))(),fh=da.WebSocket||da.MozWebSocket,pN=!0,D3e="arraybuffer",fN=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class L3e extends DT{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),n=this.opts.protocols,r=fN?{}:BB(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=pN&&!fN?n?new fh(t,n):new fh(t):new fh(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{const o={};try{pN&&this.ws.send(a)}catch{}i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=$B()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}check(){return!!fh}}class M3e extends DT{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(t=>{const n=y3e(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=b3e();i.readable.pipeTo(t.writable),this.writer=i.writable.getWriter();const a=()=>{r.read().then(({done:s,value:u})=>{s||(this.onPacket(u),a())}).catch(s=>{})};a();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then(()=>this.onOpen())})}))}write(t){this.writable=!1;for(let n=0;n{i&<(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this.transport)===null||t===void 0||t.close()}}const F3e={websocket:L3e,webtransport:M3e,polling:O3e},P3e=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,B3e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rE(e){const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=P3e.exec(e||""),a={},o=14;for(;o--;)a[B3e[o]]=i[o]||"";return n!=-1&&r!=-1&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=U3e(a,a.path),a.queryKey=$3e(a,a.query),a}function U3e(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function $3e(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,a){i&&(n[i]=a)}),n}let jB=class p1 extends Xn{constructor(t,n={}){super(),this.binaryType=D3e,this.writeBuffer=[],t&&typeof t=="object"&&(n=t,t=null),t?(t=rE(t),n.hostname=t.host,n.secure=t.protocol==="https"||t.protocol==="wss",n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=rE(n.host).host),W2(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=C3e(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=PB,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new F3e[t](r)}open(){let t;if(this.opts.rememberUpgrade&&p1.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else t=this.transports[0];this.readyState="opening";try{t=this.createTransport(t)}catch{this.transports.shift(),this.open();return}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(t){let n=this.createTransport(t),r=!1;p1.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;p1.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(p(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const m=new Error("probe error");m.transport=n.name,this.emitReserved("upgradeError",m)}}))};function a(){r||(r=!0,p(),n.close(),n=null)}const o=f=>{const m=new Error("probe error: "+f);m.transport=n.name,a(),this.emitReserved("upgradeError",m)};function s(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&a()}const p=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",s),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",s),this.once("close",u),this.once("upgrading",c),this.upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",p1.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let t=0;const n=this.upgrades.length;for(;t{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(t,n,r){return this.sendPacket("message",t,n,r),this}send(t,n,r){return this.sendPacket("message",t,n,r),this}sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const a={type:t,data:n,options:r};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),i&&this.once("flush",i),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}onError(t){p1.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const n=[];let r=0;const i=t.length;for(;rtypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,GB=Object.prototype.toString,G3e=typeof Blob=="function"||typeof Blob<"u"&&GB.call(Blob)==="[object BlobConstructor]",V3e=typeof File=="function"||typeof File<"u"&&GB.call(File)==="[object FileConstructor]";function MT(e){return H3e&&(e instanceof ArrayBuffer||j3e(e))||G3e&&e instanceof Blob||V3e&&e instanceof File}function Wh(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.num{delete this.acks[t];for(let o=0;o{this.io.clearTimeoutFn(a),n.apply(this,[null,...o])}}emitWithAck(t,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,a)=>{n.push((o,s)=>r?o?a(o):i(s):i(o)),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...a)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...a)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:zt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case zt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case zt.EVENT:case zt.BINARY_EVENT:this.onevent(t);break;case zt.ACK:case zt.BINARY_ACK:this.onack(t);break;case zt.DISCONNECT:this.ondisconnect();break;case zt.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:zt.ACK,id:t,data:i}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(n.apply(this,t.data),delete this.acks[t.id])}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:zt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}xc.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};xc.prototype.reset=function(){this.attempts=0};xc.prototype.setMin=function(e){this.ms=e};xc.prototype.setMax=function(e){this.max=e};xc.prototype.setJitter=function(e){this.jitter=e};class oE extends Xn{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,W2(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new xc({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const i=n.parser||Z3e;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new jB(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=Ua(n,"open",function(){r.onopen(),t&&t()}),a=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},o=Ua(n,"error",a);if(this._timeout!==!1){const s=this._timeout,u=this.setTimeoutFn(()=>{i(),a(new Error("timeout")),n.close()},s);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ua(t,"ping",this.onping.bind(this)),Ua(t,"data",this.ondata.bind(this)),Ua(t,"error",this.onerror.bind(this)),Ua(t,"close",this.onclose.bind(this)),Ua(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){LT(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new VB(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const gd={};function qh(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=z3e(e,t.path||"/socket.io"),r=n.source,i=n.id,a=n.path,o=gd[i]&&a in gd[i].nsps,s=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let u;return s?u=new oE(r,t):(gd[i]||(gd[i]=new oE(r,t)),u=gd[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(qh,{Manager:oE,Socket:VB,io:qh,connect:qh});class WB{}class e4e extends WB{constructor(n){super();zl(this,"socket");console.log("Connecting to socket.io endpoint: ",n,window.windowId),this.socket=qh(`${n}?window_id=${window.windowId}`,{path:"/gui/socket.io",transports:["websocket","polling","flashsocket"]})}send(n,r){this.socket.emit("message",{message_type:n,data:r,message_id:Cy()})}onMessageType(n,r){this.socket.on("message",({message_type:i,data:a})=>{n===i&&r(a)})}onMessage(n){this.socket.on("message",({messageType:r,data:i})=>{n(r,i)})}onOpen(n){this.socket.on("connect",n)}onClose(n){this.socket.on("disconnect",n)}async sendAndReceive(n,r){return new Promise((i,a)=>{this.socket.emit("message",{message_type:n,data:r,message_id:Cy()},o=>{o&&o.error?a(o.error):i(o)})})}onError(n){this.socket.on("error",n)}close(){this.socket.disconnect()}}class t4e extends WB{constructor(n){super();zl(this,"serverUrl");this.serverUrl=n,_o("websocketForwardingOpen",{url:this.serverUrl})}send(n,r){_o("websocketForwardingMessage",{message:{messageType:n,data:r},url:this.serverUrl})}onMessageType(n,r){window.addEventListener("message",i=>{if(i.data.type==="websocketForwardingMessage"){const a=JSON.parse(i.data.data);a.messageType===n&&r(a.data)}})}onMessage(n){window.addEventListener("message",r=>{if(r.data.type==="websocketForwardingMessage"){const i=JSON.parse(r.data.data);n(i.messageType,i.data)}})}onError(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingError"&&n(r.data.error)})}sendAndReceive(n,r){return new Promise(i=>{const a=o=>{if(o.data.type==="websocketForwardingMessage"){const s=JSON.parse(o.data.data);s.messageType===n&&(window.removeEventListener("message",a),i(s.data))}};window.addEventListener("message",a),this.send(n,r)})}onOpen(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingOpen"&&n()})}onClose(n){window.addEventListener("message",r=>{r.data.type==="websocketForwardingClose"&&n()})}close(){_o("websocketForwardingClose",{url:this.serverUrl})}}class n4e extends c3e{constructor(n,r){super();zl(this,"messenger");zl(this,"serverUrl");zl(this,"useVscodeMessagePassing");zl(this,"onStateUpdateCallbacks",[]);this.serverUrl=n,this.useVscodeMessagePassing=r,this.serverUrl=n,this.useVscodeMessagePassing=r,this.messenger=r?new t4e(n):new e4e(n),this.messenger.onClose(()=>{console.log("GUI Connection closed: ",n)}),this.messenger.onError(i=>{console.log("GUI Connection error: ",i)}),this.messenger.onOpen(()=>{console.log("GUI Connection opened: ",n)}),this.messenger.onMessage((i,a)=>{this.handleMessage(i,a)})}onConnected(n){var r;(r=this.messenger)==null||r.onOpen(n)}handleMessage(n,r){switch(n){case"state_update":if(r.state)for(const i of this.onStateUpdateCallbacks)i(r.state);break}}loadSession(n){var r;(r=this.messenger)==null||r.send("load_session",{session_id:n})}sendMainInput(n){var r;(r=this.messenger)==null||r.send("main_input",{input:n})}runFromState(n){var r;(r=this.messenger)==null||r.send("run_from_state",{state:n})}async getSessionTitle(n){var r;return await((r=this.messenger)==null?void 0:r.sendAndReceive("get_session_title",{history:n}))}reverseToIndex(n){var r;(r=this.messenger)==null||r.send("reverse_to_index",{index:n})}sendRefinementInput(n,r){var i;(i=this.messenger)==null||i.send("refinement_input",{input:n,index:r})}sendStepUserInput(n,r){var i;(i=this.messenger)==null||i.send("step_user_input",{input:n,index:r})}onStateUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("state_update",i=>{i.state&&n(i.state)}),this.onStateUpdateCallbacks.push(n)}onSessionUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("session_update",i=>{n(i)})}onConfigUpdate(n){var r;(r=this.messenger)==null||r.onMessageType("config_update",i=>{n(i)})}getConfig(){var n;return(n=this.messenger)==null?void 0:n.sendAndReceive("get_config",{})}onAddContextItem(n){var r;(r=this.messenger)==null||r.onMessageType("add_context_item",i=>{n(i)})}onAvailableSlashCommands(n){var r;(r=this.messenger)==null||r.onMessageType("available_slash_commands",i=>{i.commands&&n(i.commands)})}stopSession(){var n;(n=this.messenger)==null||n.send("stop_session",{})}sendClear(){var n;(n=this.messenger)==null||n.send("clear_history",{})}retryAtIndex(n){var r;(r=this.messenger)==null||r.send("retry_at_index",{index:n})}deleteContextWithIds(n,r){var i;(i=this.messenger)==null||i.send("delete_context_with_ids",{ids:n.map(a=>`${a.provider_title}-${a.item_id}`),index:r})}setEditingAtIds(n){var r;(r=this.messenger)==null||r.send("set_editing_at_ids",{ids:n})}toggleAddingHighlightedCode(){var n;(n=this.messenger)==null||n.send("toggle_adding_highlighted_code",{})}showContextVirtualFile(n){var r;(r=this.messenger)==null||r.send("show_context_virtual_file",{index:n})}selectContextItem(n,r){var i;(i=this.messenger)==null||i.send("select_context_item",{id:n,query:r})}async getContextItem(n,r){var i;return await((i=this.messenger)==null?void 0:i.sendAndReceive("get_context_item",{id:n,query:r}))}selectContextItemAtIndex(n,r,i){var a;(a=this.messenger)==null||a.send("select_context_item_at_index",{id:n,query:r,index:i})}editStepAtIndex(n,r){var i;(i=this.messenger)==null||i.send("edit_step_at_index",{user_input:n,index:r})}setSystemMessage(n){var r;(r=this.messenger)==null||r.send("set_system_message",{system_message:n})}setTemperature(n){var r;(r=this.messenger)==null||r.send("set_temperature",{temperature:n})}addModelForRole(n,r,i){var a;(a=this.messenger)==null||a.send("add_model_for_role",{role:n,model:i,model_class:r})}setModelForRoleFromIndex(n,r){var i;(i=this.messenger)==null||i.send("set_model_for_role_from_index",{role:n,index:r})}saveContextGroup(n,r){var i;(i=this.messenger)==null||i.send("save_context_group",{context_items:r,title:n})}selectContextGroup(n){var r;(r=this.messenger)==null||r.send("select_context_group",{id:n})}deleteContextGroup(n){var r;(r=this.messenger)==null||r.send("delete_context_group",{id:n})}setCurrentSessionTitle(n){var r;(r=this.messenger)==null||r.send("set_current_session_title",{title:n})}}function r4e(e=!0){const[t,n]=C.useState(void 0);return C.useEffect(()=>{const r=window.serverUrl;console.log("Creating GUI websocket",r,e);const i=new n4e(r,e);i.onConnected(()=>{n(i)})},[]),t}function i4e(){const e=EB();return console.error(e),R.jsxs("div",{id:"error-page",className:"text-center",children:[R.jsx("h1",{children:"Error in Continue React App"}),R.jsx("p",{children:R.jsx("i",{children:e.statusText||e.message})}),R.jsx("br",{}),R.jsx("pre",{className:"text-left m-4",children:e.stack})]})}const qB="28px",a4e=He.div` margin-top: 16px; margin: auto; width: ${qB}; diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 812908870..1c276771c 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -126,12 +126,7 @@ const Layout = () => { useEffect(() => { const handleKeyDown = (event: any) => { - if ( - event.metaKey && - event.altKey && - event.code === "KeyN" && - timeline.filter((n) => !n.hide).length > 0 - ) { + if (event.metaKey && event.altKey && event.code === "KeyN") { dispatch(newSession()); } if ((event.metaKey || event.ctrlKey) && event.code === "KeyC") { diff --git a/gui/src/pages/gui.tsx b/gui/src/pages/gui.tsx index dc356cc95..d35224e1e 100644 --- a/gui/src/pages/gui.tsx +++ b/gui/src/pages/gui.tsx @@ -570,9 +570,7 @@ function GUI(props: GUIProps) { {sessionState.history.filter((n) => !n.hide).length > 0 && ( { - if (sessionState.history.filter((n) => !n.hide).length > 0) { - dispatch(newSession()); - } + dispatch(newSession()); }} text="New Session (⌥⌘N)" > diff --git a/server/continuedev/core/config.py b/server/continuedev/core/config.py index 590c85c86..fe5fc4638 100644 --- a/server/continuedev/core/config.py +++ b/server/continuedev/core/config.py @@ -1,6 +1,10 @@ from typing import Dict, List, Optional, Type -from ..libs.util.edit_config import edit_config_property +from ..libs.util.edit_config import ( + create_obj_node, + display_llm_class, + edit_config_property, +) from ..libs.util.paths import convertConfigImports, getConfigFilePath from pydantic import BaseModel, Field, validator @@ -192,12 +196,24 @@ class ContinueConfig(BaseModel): ) ] - def set_temperature(self, temperature: float): - self.temperature = temperature + @staticmethod + def set_temperature(temperature: float): edit_config_property(["temperature"], temperature) posthog_logger.capture_event("set_temperature", {"temperature": temperature}) - def set_system_message(self, message: str): - self.system_message = message + @staticmethod + def set_system_message(message: str): edit_config_property(["system_message"], message) posthog_logger.capture_event("set_system_message", {"message": message}) + + @staticmethod + def set_models(models: Models, role: str): + JOINER = ",\n\t\t" + models_args = { + "saved": f"[{JOINER.join([display_llm_class(llm) for llm in models.saved])}]", + ("default" if role == "*" else role): display_llm_class(models.default), + } + edit_config_property( + ["models"], + create_obj_node("Models", models_args), + ) diff --git a/server/continuedev/libs/llm/anthropic.py b/server/continuedev/libs/llm/anthropic.py index 7d0708f13..40b322d3f 100644 --- a/server/continuedev/libs/llm/anthropic.py +++ b/server/continuedev/libs/llm/anthropic.py @@ -37,8 +37,8 @@ class AnthropicLLM(LLM): class Config: arbitrary_types_allowed = True - async def start(self, **kwargs): - await super().start(**kwargs) + async def start(self, *args, **kwargs): + await super().start(*args, **kwargs) self._async_client = AsyncAnthropic(api_key=self.api_key) if self.model == "claude-2": diff --git a/server/continuedev/libs/llm/ollama.py b/server/continuedev/libs/llm/ollama.py index d0bf98b91..442b4a0dc 100644 --- a/server/continuedev/libs/llm/ollama.py +++ b/server/continuedev/libs/llm/ollama.py @@ -52,8 +52,8 @@ class Ollama(LLM): "stop": options.stop, } - async def start(self, **kwargs): - await super().start(**kwargs) + async def start(self, *args, **kwargs): + await super().start(*args, **kwargs) self._client_session = self.create_client_session() try: async with self._client_session.post( diff --git a/server/continuedev/libs/llm/replicate.py b/server/continuedev/libs/llm/replicate.py index 51ec081bd..4ac6ca82f 100644 --- a/server/continuedev/libs/llm/replicate.py +++ b/server/continuedev/libs/llm/replicate.py @@ -40,8 +40,8 @@ class ReplicateLLM(LLM): "edit": codellama_edit_prompt, } - async def start(self, **kwargs): - await super().start(**kwargs) + async def start(self, *args, **kwargs): + await super().start(*args, **kwargs) self._client = replicate.Client(api_token=self.api_key) async def _complete(self, prompt: str, options): diff --git a/server/continuedev/libs/llm/together.py b/server/continuedev/libs/llm/together.py index 234834125..efd0eb790 100644 --- a/server/continuedev/libs/llm/together.py +++ b/server/continuedev/libs/llm/together.py @@ -47,8 +47,8 @@ class TogetherLLM(LLM): "edit": codellama_edit_prompt, } - async def start(self, **kwargs): - await super().start(**kwargs) + async def start(self, *args, **kwargs): + await super().start(*args, **kwargs) self._client_session = aiohttp.ClientSession( connector=aiohttp.TCPConnector(verify_ssl=self.verify_ssl), timeout=aiohttp.ClientTimeout(total=self.timeout), diff --git a/server/continuedev/server/protocols/gui.py b/server/continuedev/server/protocols/gui.py index 1a7b68333..64c471131 100644 --- a/server/continuedev/server/protocols/gui.py +++ b/server/continuedev/server/protocols/gui.py @@ -23,6 +23,7 @@ from ...libs.util.edit_config import ( create_obj_node, create_string_node, display_llm_class, + edit_config_property, ) from ...libs.util.telemetry import posthog_logger from ..websockets_messenger import SocketIOMessenger @@ -86,20 +87,22 @@ class GUIProtocolServer: self.load_session(data.get("session_id", None)) elif msg.message_type == "set_system_message": sys_message = data["system_message"] - self.get_config().set_system_message(sys_message) + ContinueConfig.set_system_message(sys_message) posthog_logger.capture_event( "set_system_message", {"system_message": sys_message} ) await self.reload_config() await self.send_config_update() elif msg.message_type == "set_temperature": - self.get_config().set_temperature(float(data["temperature"])) + ContinueConfig.set_temperature(float(data["temperature"])) await self.reload_config() await self.send_config_update() elif msg.message_type == "add_model_for_role": - self.add_model_for_role(data["role"], data["model_class"], data["model"]) + await self.add_model_for_role( + data["role"], data["model_class"], data["model"] + ) elif msg.message_type == "set_model_for_role_from_index": - self.set_model_for_role_from_index(data["role"], data["index"]) + await self.set_model_for_role_from_index(data["role"], data["index"]) elif msg.message_type == "save_context_group": self.save_context_group( data["title"], [ContextItem(**item) for item in data["context_items"]] @@ -171,129 +174,95 @@ class GUIProtocolServer: def set_current_session_title(self, title: str): self.session.autopilot.set_current_session_title(title) - def set_model_for_role_from_index(self, role: str, index: int): - async def async_stuff(): - models = self.session.autopilot.sdk.config.models + async def set_model_for_role_from_index(self, role: str, index: int): + models = self.get_config().models + temp = models.default + models.default = models.saved[index] + models.saved[index] = temp - # Set models in SDK - temp = models.default - models.default = models.saved[index] - models.saved[index] = temp - await self.session.autopilot.sdk.start_model(models.default) + ContinueConfig.set_models(models, role) + await self.reload_config() + await self.send_config_update() - # Set models in config.py - JOINER = ",\n\t\t" - models_args = { - "saved": f"[{JOINER.join([display_llm_class(llm) for llm in models.saved])}]", - ("default" if role == "*" else role): display_llm_class(models.default), - } - - await self.session.autopilot.set_config_attr( - ["models"], - create_obj_node("Models", models_args), - ) - - for other_role in ALL_MODEL_ROLES: - if other_role != "default": - models.__setattr__(other_role, models.default) - - await self.session.autopilot.sdk.update_ui() - - create_async_task(async_stuff(), self.on_error) - - def add_model_for_role(self, role: str, model_class: str, model: Any): - models = self.session.autopilot.sdk.config.models + async def add_model_for_role(self, role: str, model_class: str, model: Any): + models = self.get_config().models model_copy = model.copy() if "api_key" in model_copy: del model_copy["api_key"] if "hf_token" in model_copy: del model_copy["hf_token"] + posthog_logger.capture_event( "select_model_for_role", {"role": role, "model_class": model_class, "model": model_copy}, ) if role == "*": + # Remove all previous models in roles and place in saved + saved_models = models.saved + existing_saved_models = set( + [display_llm_class(llm) for llm in saved_models] + ) + for role in ALL_MODEL_ROLES: + val = models.__getattribute__(role) + if ( + val is not None + and display_llm_class(val) not in existing_saved_models + ): + saved_models.append(val) + existing_saved_models.add(display_llm_class(val)) + models.__setattr__(role, None) - async def async_stuff(): - # Remove all previous models in roles and place in saved - saved_models = models.saved - existing_saved_models = set( - [display_llm_class(llm) for llm in saved_models] - ) - for role in ALL_MODEL_ROLES: - val = models.__getattribute__(role) - if ( - val is not None - and display_llm_class(val) not in existing_saved_models - ): - saved_models.append(val) - existing_saved_models.add(display_llm_class(val)) - models.__setattr__(role, None) - - # Add the requisite import to config.py - default_model_display_overrides = {} + # Add the requisite import to config.py + default_model_display_overrides = {} + add_config_import( + f"from continuedev.libs.llm.{MODEL_MODULE_NAMES[model_class]} import {model_class}" + ) + if "template_messages" in model: add_config_import( - f"from continuedev.libs.llm.{MODEL_MODULE_NAMES[model_class]} import {model_class}" + f"from continuedev.libs.llm.prompts.chat import {model['template_messages']}" ) - if "template_messages" in model: - add_config_import( - f"from continuedev.libs.llm.prompts.chat import {model['template_messages']}" - ) - sqtm = sqlcoder_template_messages("") - sqtm.__name__ = 'sqlcoder_template_messages("")' - model["template_messages"] = { - "llama2_template_messages": llama2_template_messages, - "template_alpaca_messages": template_alpaca_messages, - "sqlcoder_template_messages": sqtm, - }[model["template_messages"]] + sqtm = sqlcoder_template_messages("") + sqtm.__name__ = 'sqlcoder_template_messages("")' + model["template_messages"] = { + "llama2_template_messages": llama2_template_messages, + "template_alpaca_messages": template_alpaca_messages, + "sqlcoder_template_messages": sqtm, + }[model["template_messages"]] - if "prompt_templates" in model and "edit" in model["prompt_templates"]: - default_model_display_overrides[ - "prompt_templates" - ] = f"""{{"edit": {model["prompt_templates"]["edit"]}}}""" - add_config_import( - f"from continuedev.libs.llm.prompts.edit import {model['prompt_templates']['edit']}" - ) - model["prompt_templates"]["edit"] = { - "codellama_edit_prompt": codellama_edit_prompt, - "alpaca_edit_prompt": alpaca_edit_prompt, - }[model["prompt_templates"]["edit"]] - - # Set and start the new default model - new_model = MODEL_CLASSES[model_class](**model) - models.default = new_model - await self.session.autopilot.sdk.start_model(models.default) - - # Construct and set the new models object - JOINER = ",\n\t\t" - saved_model_strings = set( - [display_llm_class(llm) for llm in saved_models] + if "prompt_templates" in model and "edit" in model["prompt_templates"]: + default_model_display_overrides[ + "prompt_templates" + ] = f"""{{"edit": {model["prompt_templates"]["edit"]}}}""" + add_config_import( + f"from continuedev.libs.llm.prompts.edit import {model['prompt_templates']['edit']}" ) - models_args = { - "default": display_llm_class( - models.default, True, default_model_display_overrides - ), - "saved": f"[{JOINER.join(saved_model_strings)}]", - } + model["prompt_templates"]["edit"] = { + "codellama_edit_prompt": codellama_edit_prompt, + "alpaca_edit_prompt": alpaca_edit_prompt, + }[model["prompt_templates"]["edit"]] - await self.session.autopilot.set_config_attr( - ["models"], - create_obj_node("Models", models_args), - ) + # Set the new default model + new_model = MODEL_CLASSES[model_class](**model) + models.default = new_model - # Set all roles (in-memory) to the new default model - for role in ALL_MODEL_ROLES: - if role != "default": - models.__setattr__(role, models.default) + # Construct and set the new models object + JOINER = ",\n\t\t" + saved_model_strings = set([display_llm_class(llm) for llm in saved_models]) + models_args = { + "default": display_llm_class( + models.default, True, default_model_display_overrides + ), + "saved": f"[{JOINER.join(saved_model_strings)}]", + } - # Display setup help - # await self.session.autopilot.continue_sdk.run_step( - # SetupModelStep(model_class=model_class) - # ) - - create_async_task(async_stuff(), self.on_error) + edit_config_property( + ["models"], + create_obj_node("Models", models_args), + ) + await self.reload_config() + await self.send_config_update() else: # TODO pass diff --git a/server/continuedev/server/protocols/ide.py b/server/continuedev/server/protocols/ide.py index 4b8ff9de5..4f6fca7b5 100644 --- a/server/continuedev/server/protocols/ide.py +++ b/server/continuedev/server/protocols/ide.py @@ -353,13 +353,6 @@ class IdeProtocolServer(AbstractIdeProtocolServer): for callback in self._file_saved_callbacks: self.call_callback(callback, filepath, contents) - # If ~/.continue/config.py was saved, auto-update the SDK - if filepath.endswith(".continue/config.py") or filepath.endswith( - ".continue\\config.py" - ): - if autopilot := self.__get_autopilot(): - create_async_task(autopilot.reload_config(), self.on_error) - ## END Subscriptions ## # Request information. Session doesn't matter. diff --git a/server/continuedev/server/window_manager.py b/server/continuedev/server/window_manager.py index 328dea967..cc335f235 100644 --- a/server/continuedev/server/window_manager.py +++ b/server/continuedev/server/window_manager.py @@ -62,7 +62,7 @@ class Window: return self.ide is None and self.gui is None async def reload_config(self): - self.load_config() + self.config = self.load_config() await self.config.models.start( self.ide.window_info.unique_id, self.config.system_message,