@oxbit/cli 0.11.4 → 0.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -201,7 +201,7 @@ window.addEventListener("message", event => {
201
201
  window.addEventListener("load", () => send("oxbit.preview.ready"));
202
202
  `,qqe="sha256-baG6zrI9qQ7n/0Uu0tcqeYXQC5vQ8ZWJY9nJ2PK7KPs=",SY=t=>/\.html?$/i.test(t);async function Vqe(t){const{path:e,signal:i,trust:s="local",scripts:r=!1}=t,a=r?"external":s,{text:n,resource:o,warnings:l}=vY({...t,trust:a}),c=await n(e),u=r?c:aA.sanitize(c,{WHOLE_DOCUMENT:!0,ADD_TAGS:["link"],FORBID_TAGS:["script","iframe","frame","frameset","object","embed","base","meta"],FORBID_ATTR:["srcdoc","ping","action","formaction","target","autofocus","data-preview-href"]}),d=new DOMParser().parseFromString(u,"text/html");r&&await Zqe(d,e,t.signal,n,l);for(const $ of d.querySelectorAll("style"))$.textContent=await Sb($.textContent??"",(_,C)=>o(e,_,C));for(const $ of d.querySelectorAll("link")){if($.rel.toLowerCase()==="stylesheet"){const _=d.createElement("style"),C=$.getAttribute("href")??"",b=oA(C,a);if(b){$.setAttribute("href",b),$.setAttribute("referrerpolicy","no-referrer");continue}const Q=xO(e,C);if(Q.kind==="file")try{_.textContent=await Sb(await n(Q.path),(A,S)=>o(Q.path,A,S,[Q.path])),$.media&&(_.media=$.media),$.replaceWith(_);continue}catch(A){i.throwIfAborted(),l.add(`Could not load ${Q.path}: ${A instanceof Error?A.message:String(A)}`)}else l.add("External resources are blocked. Use the External resources control to allow them for this preview.")}$.remove()}for(const $ of d.querySelectorAll("[style]"))$.setAttribute("style",await Sb($.getAttribute("style"),(_,C)=>o(e,_,C)));for(const $ of d.querySelectorAll("[src], [poster], image[href], image[xlink\\:href]"))for(const _ of["src","poster","href","xlink:href"]){const C=$.getAttribute(_);C!==null&&$.setAttribute(_,await o(e,C))}for(const $ of d.querySelectorAll("[srcset]")){const _=$.getAttribute("srcset");if(!_.trim().startsWith("data:")){const C=[];for(const b of _.split(",")){const[Q,...A]=b.trim().split(/\s+/);C.push(`${await o(e,Q??"")} ${A.join(" ")}`.trim())}$.setAttribute("srcset",C.join(", "))}}for(const $ of d.querySelectorAll("a[href], area[href]"))$.setAttribute("data-preview-href",$.getAttribute("href")),$.setAttribute("href","#"),$.removeAttribute("download");const p=d.createElement("meta");p.httpEquiv="Content-Security-Policy",p.content=r?"form-action 'none'":`default-src 'none'; script-src '${qqe}'; ${jqe(a)}; base-uri 'none'; form-action 'none'`;const g=d.createElement("meta");g.name="viewport",g.content="width=device-width, initial-scale=1";const y=d.createElement("meta");y.name="referrer",y.content="no-referrer",d.head.prepend(p,g,y);const k=d.createElement("script");return k.textContent=Xqe,k.dataset.path=e,d.head.append(k),i.throwIfAborted(),{html:`<!doctype html>
203
203
  `+d.documentElement.outerHTML,warnings:[...l],trust:s,scripts:/<script\b|\son\w+\s*=/i.test(c),running:r}}async function Zqe(t,e,i,s,r){for(const a of t.querySelectorAll("script[src]")){const n=a.getAttribute("src");if(oA(n,"external"))continue;const o=xO(e,n);if(o.kind!=="file"){r.add(`Could not load script ${n}`),a.remove();continue}try{a.textContent=(await s(o.path)).replace(/<\/script/gi,"<\\/script"),a.removeAttribute("src")}catch(l){i.throwIfAborted(),r.add(`Could not load ${o.path}: ${l instanceof Error?l.message:String(l)}`),a.remove()}}}let Wqe=0;const yM=new Set;function Yqe(){const t=globalThis.__TAURI_INTERNALS__;return t?t.convertFileSrc("preview-shell.html","oxbit-preview"):new URL("preview-shell.html",document.baseURI).href}function Gqe(t){return function({path:i}){const[s,r]=L.useState([i]),a=s[s.length-1],[n,o]=L.useState(0),[l,c]=L.useState("local"),[u,d]=L.useState(),[p,g]=L.useState(""),[y,k]=L.useState(!0),[$,_]=L.useState(!1),C=L.useRef(new Set([a])),b=L.useRef({path:a,top:0}),Q=L.useRef(null),A=L.useRef(void 0),S=L.useRef(void 0),m=()=>t.kernel.context.get("trusted")===!0&&t.kernel.context.get("iosApp")!==!0,[v,E]=L.useState(m),[D,N]=L.useState(()=>yM.has(i)),Z=v||D;L.useEffect(()=>t.kernel.context.subscribe(()=>E(m())),[]),L.useEffect(()=>{let se;const re=()=>{clearTimeout(se),se=setTimeout(()=>o(q=>q+1),200)},M=t.kernel.events.on("document.change",({id:q})=>{[...C.current].some(ae=>t.documents.get(ae)?.id===q)&&re()}),j=t.filesystem.watch(q=>{C.current.has(q.path)&&re()});return()=>{clearTimeout(se),M.dispose(),j.dispose()}},[]),L.useEffect(()=>{const se=new AbortController;return C.current=new Set([a]),b.current.path!==a&&(b.current={path:a,top:0}),k(!0),g(""),Vqe({path:a,trust:l,scripts:Z,filesystem:t.filesystem,signal:se.signal,dependencies:C.current,readText:async re=>{const M=t.documents.get(re);if(M?.state==="missing")throw new Error(P("File no longer exists"));return M?M.text.toString():(await t.filesystem.read(re)).text}}).then(re=>{se.signal.aborted||(S.current=re.running?re.html:void 0,d({...re,serial:++Wqe}),k(!1))}).catch(re=>{se.signal.aborted||(g(re instanceof Error?re.message:String(re)),k(!1))}),()=>se.abort()},[a,n,l,Z]),L.useEffect(()=>{const se=()=>{Q.current?.contentWindow?.postMessage({type:"oxbit.preview.restore",top:b.current.top,anchor:A.current},"*"),A.current=void 0},re=M=>{if(M.source!==Q.current?.contentWindow||M.origin!=="null"||(M.data?.type==="oxbit.preview.shell"&&S.current!==void 0&&Q.current.contentWindow.postMessage({type:"oxbit.preview.document",html:S.current},"*"),M.data?.path!==a)||(M.data.type==="oxbit.preview.ready"&&se(),M.data.type==="oxbit.preview.scroll"&&Number.isFinite(M.data.top)&&(b.current.top=Math.max(0,M.data.top)),M.data.type!=="oxbit.preview.link"||typeof M.data.href!="string"))return;const j=xO(a,M.data.href);j.kind==="anchor"||j.kind==="file"&&j.path===a&&j.anchor?(A.current=j.kind==="anchor"?j.id:j.anchor,se()):j.kind==="file"&&SY(j.path)?(A.current=j.anchor,r(q=>[...q,j.path])):j.kind==="file"?Promise.resolve(t.workbench.openFile(j.path)).catch(q=>t.workbench.notify(String(q),"error")):j.kind==="external"?window.open(j.url,"_blank","noopener,noreferrer"):t.workbench.notify(j.reason,"warning")};return window.addEventListener("message",re),()=>window.removeEventListener("message",re)},[a]);const J=()=>{Promise.resolve(t.workbench.openFile(a,{preview:!1})).catch(se=>t.workbench.notify(String(se),"error"))};return w.jsxs("div",{className:"html-document","aria-busy":y,children:[w.jsxs("div",{className:"preview-toolbar html-preview-toolbar",children:[s.length>1&&w.jsx(Ue,{icon:"chevR",className:"icon-button html-preview-back",label:P("Back in HTML preview"),onClick:()=>r(se=>se.slice(0,-1))}),w.jsx("span",{className:"truncate",title:a,role:"status",children:y?P("Loading preview…"):a.split("/").pop()}),w.jsx(Ue,{icon:"refresh",label:P("Refresh HTML preview"),onClick:()=>o(se=>se+1)}),w.jsx(Ue,{icon:"pencil",label:P("Open source"),onClick:J}),w.jsx(Ue,{icon:"gear",className:"icon-button html-preview-options-trigger",label:P("Preview options"),"data-warning":!!u?.warnings.length,"aria-haspopup":"dialog","aria-expanded":$,onClick:se=>{se.currentTarget.focus({preventScroll:!0}),_(!0)}})]}),p&&w.jsx("div",{className:"html-preview-message error-text",role:"alert",children:p}),$&&w.jsxs(ao,{title:P("Preview options"),className:"html-preview-options",onClose:()=>_(!1),children:[w.jsx(kY,{trust:l,onChange:c}),u?.scripts&&w.jsx("p",{className:"muted",children:u.running?P("JavaScript is on"):P("HTML & CSS preview · JavaScript is disabled")}),!!u?.warnings.length&&w.jsxs("details",{className:"html-preview-warnings",children:[w.jsx("summary",{children:P("Some preview resources could not be loaded")}),u.warnings.map(se=>w.jsx("p",{children:P(se)},se))]})]}),u?.scripts&&!u.running&&!p&&w.jsxs("div",{className:"html-preview-scripts",role:"note",children:[w.jsx("span",{children:P("This page has JavaScript, which is off. Scripts you run can load content from the internet and send data to it.")}),w.jsx("button",{type:"button",className:"button",onClick:()=>{yM.add(i),N(!0)},children:P("Run JavaScript")})]}),u&&u.trust===l&&!p&&(u.running?w.jsx("iframe",{ref:Q,className:"html-preview-frame",title:P("HTML preview"),sandbox:"allow-scripts allow-forms allow-modals",referrerPolicy:"no-referrer",src:Yqe()},u.serial):w.jsx("iframe",{ref:Q,className:"html-preview-frame",title:P("HTML preview"),sandbox:"allow-scripts",referrerPolicy:"no-referrer",srcDoc:u.html}))]})}}const xY={mp3:"audio/mpeg",wav:"audio/wav",wave:"audio/wav",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg; codecs=opus",aif:"audio/aiff",aiff:"audio/aiff",weba:"audio/webm"};function bM(t,e){return function({path:s}){const[r,a]=L.useState(),[n,o]=L.useState(""),[l,c]=L.useState(0),u=s.split("/").pop()||s,d=e==="pdf"?"application/pdf":xY[u.split(".").pop().toLowerCase()],p=t.kernel.commands.list().find(y=>y.id==="desktop.reveal"),g=p&&t.kernel.contributions.list("menu").some(y=>y.id==="desktop.reveal.explorer");return L.useEffect(()=>{const y=new AbortController;let k="";return a(void 0),o(""),(async()=>{if(!t.filesystem.readBytes)throw new Error(P("This workspace cannot read media files"));const $=await t.filesystem.readBytes(s,y.signal);if(!y.signal.aborted){if(e==="pdf"&&!new TextDecoder().decode($.subarray(0,1024)).includes("%PDF-"))throw new Error(P("This file is not a PDF document."));k=URL.createObjectURL(new Blob([$],{type:d})),a({url:k,bytes:$.byteLength})}})().catch($=>{y.signal.aborted||o($ instanceof Error?$.message:String($))}),()=>{y.abort(),k&&URL.revokeObjectURL(k)}},[s,d,l]),L.useEffect(()=>{const y=t.filesystem.watch(k=>{k.path===s&&c($=>$+1)});return()=>y.dispose()},[s]),w.jsxs("div",{className:"media-document",children:[w.jsxs("div",{className:"preview-toolbar",children:[w.jsx("span",{className:"truncate",title:s,children:u}),w.jsx("span",{className:"push"}),g&&w.jsx("button",{className:"button",onClick:()=>{t.kernel.commands.execute("desktop.reveal",{path:s}).catch(y=>t.workbench.notify(String(y),"error"))},children:P(p.title)}),r&&!p&&w.jsx("a",{className:"button",href:r.url,download:u,children:P("Download")}),w.jsx(Ue,{icon:"refresh",label:"Reload preview",onClick:()=>c(y=>y+1)})]}),n?w.jsxs(Pf,{title:P(e==="pdf"?"PDF unavailable":"Audio unavailable"),children:[w.jsx("p",{role:"alert",children:n}),w.jsx("button",{className:"button",onClick:()=>c(y=>y+1),children:P("Retry")})]}):r?e==="pdf"?w.jsxs(w.Fragment,{children:[w.jsx("iframe",{className:"pdf-preview",title:P("PDF preview"),src:r.url}),!p&&w.jsx("p",{className:"media-hint",children:P("If the PDF does not display, download it to open in your PDF reader.")})]}):w.jsxs("div",{className:"audio-preview",children:[w.jsx(Te,{name:"play",size:48}),w.jsx("h2",{children:u}),w.jsx("p",{className:"muted",children:`${(r.bytes/1024/1024).toFixed(2)} MB`}),w.jsx("audio",{controls:!0,preload:"metadata",src:r.url,"aria-label":u,onError:()=>o(P("This audio file is damaged or its codec is not supported by this device."))},r.url)]}):w.jsx("p",{className:"muted",role:"status",children:P("Loading preview…")})]})}}const $Y=new On({html:!1,linkify:!0,typographer:!1});$Y.renderer.rules.heading_open=(t,e,i,s,r)=>{const a=t[e+1]?.content||"",n=wY(a),o=s.headings,l=o.get(n)||0;return o.set(n,l+1),t[e].attrSet("id",n+(l?"-"+l:"")),t[e].map&&t[e].attrSet("data-source-line",String(t[e].map[0])),r.renderToken(t,e,i)};function Hqe(t,e=!1){return aA.sanitize($Y.render(t,{headings:new Map}),{FORBID_TAGS:["style","script","iframe","object","embed","form","input","video","audio",...e?[]:["img"]],FORBID_ATTR:["style","srcset","target"],ALLOW_DATA_ATTR:!1,ADD_ATTR:["data-source-line"]})}async function Kqe(t){const{text:e,resource:i,warnings:s}=vY(t),r=document.createElement("template");r.innerHTML=Hqe(await e(t.path),!0);for(const a of r.content.querySelectorAll("img"))a.setAttribute("src",await i(t.path,a.getAttribute("src")??"")),a.setAttribute("referrerpolicy","no-referrer");return t.signal.throwIfAborted(),{html:r.innerHTML,warnings:[...s]}}function Jqe(t){const e=new Set,i=Gqe(t),s=bM(t,"pdf"),r=bM(t,"audio");function a({path:l}){const[c,u]=L.useState("local"),[d,p]=L.useState({html:"",warnings:[],trust:c}),[g,y]=L.useState(""),k=L.useRef(null),$=L.useRef(new Set([l]));return L.useEffect(()=>{let _=!1,C=0,b=0,Q,A=!1;const S=k.current;let m;const v=()=>{m?.abort(),cancelAnimationFrame(C),C=requestAnimationFrame(()=>{if(_)return;const M=new AbortController;m=M,$.current=new Set([l]),Kqe({path:l,trust:c,signal:M.signal,filesystem:t.filesystem,dependencies:$.current,readText:async j=>{const q=t.documents.get(j);if(q?.state==="missing")throw new Error(P("File no longer exists"));return q?q.text.toString():(await t.filesystem.read(j)).text}}).then(j=>{M.signal.aborted||(p({...j,trust:c}),y(""))}).catch(j=>{M.signal.aborted||y(String(j))})})};t.documents.open(l).then(v).catch(M=>{_||y(String(M))});const E=t.kernel.events.on("document.change",({id:M})=>{[...$.current].some(j=>t.documents.get(j)?.id===M)&&v()}),D=t.filesystem.watch(M=>{$.current.has(M.path)&&v()}),N=(M,j)=>{A||(A=!0,j.scrollTop=zqe(M)*Math.max(0,j.scrollHeight-j.clientHeight),cancelAnimationFrame(b),b=requestAnimationFrame(()=>{A=!1}))},Z=()=>{Q&&S&&N(Q,S)},J=()=>{Q&&S&&N(S,Q)},se=()=>{const M=t.workbench.editorForPath(l)?.scrollDOM;Q!==M&&(Q?.removeEventListener("scroll",Z),Q=M,Q?.addEventListener("scroll",Z,{passive:!0}))},re=t.kernel.events.on("editor.active",()=>requestAnimationFrame(se));return requestAnimationFrame(se),S?.addEventListener("scroll",J,{passive:!0}),()=>{_=!0,m?.abort(),cancelAnimationFrame(C),cancelAnimationFrame(b),E.dispose(),D.dispose(),re.dispose(),Q?.removeEventListener("scroll",Z),S?.removeEventListener("scroll",J)}},[l,c]),Ce.createElement("div",{className:"markdown-document"},Ce.createElement("div",{className:"preview-toolbar"},Ce.createElement("span",null,l),Ce.createElement("button",{className:"button",onClick:()=>{t.workbench.openFile(l,{preview:!1})}},P("Open source"))),Ce.createElement(kY,{trust:c,onChange:u}),d.trust===c&&d.warnings.length>0&&Ce.createElement("details",{className:"html-preview-message"},Ce.createElement("summary",null,P("Some preview resources could not be loaded")),...d.warnings.map(_=>Ce.createElement("p",{key:_},P(_)))),g&&Ce.createElement("p",{role:"alert",className:"error-text"},g),Ce.createElement("article",{ref:k,className:"markdown-preview",tabIndex:0,"aria-label":P("Markdown preview"),onClick:_=>{const C=_.target.closest("a");if(!C)return;_.preventDefault();const b=xO(l,C.getAttribute("href")||"");if(b.kind==="blocked"){t.workbench.notify(b.reason,"warning");return}if(b.kind==="external"){window.open(b.url,"_blank","noopener,noreferrer");return}if(b.kind==="anchor"){k.current?.querySelector("#"+CSS.escape(b.id))?.scrollIntoView();return}(async()=>{let Q;b.anchor&&(Q=(await t.documents.open(b.path)).text.toString().split(`
204
- `).findIndex(S=>/^#{1,6}\s/.test(S)&&wY(S.replace(/^#{1,6}\s+/,""))===b.anchor)+1,Q||(Q=void 0)),await t.workbench.openFile(b.path,{line:Q})})().catch(Q=>t.workbench.notify(String(Q),"error"))},dangerouslySetInnerHTML:{__html:d.trust===c&&!g?d.html:""}}))}const n=async(l=!1)=>{const c=t.workbench.activePath();if(!c||!/\.md$/i.test(c))throw new Error("Open a Markdown document first");let u;if(l&&(u=t.workbench.split("row"),!u))return;const d="preview:"+c;e.add(d),t.workbench.openView(d,P("{0} Preview",{0:c.split("/").pop()}),a,{path:c},{groupId:u,path:c,contributionId:"markdown.preview"})},o=(l=!1)=>{const c=t.workbench.activePath();if(!c||!SY(c))throw new Error("Open an HTML document first");const u=l?t.workbench.split("row"):void 0;if(l&&!u)return;const d="html-preview:"+c;e.add(d),t.workbench.openView(d,P("{0} Preview",{0:c.split("/").pop()}),i,{path:c},{groupId:u,path:c,contributionId:"html.preview"})};return{manifest:{manifestVersion:1,id:"oxbit.previews",name:"Document & Media Previews",description:"Markdown and HTML/CSS previews, PDF viewing, and audio playback for MP3, WAV, M4A, FLAC, Ogg, and more.",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["*"],capabilities:["filesystem.read"]},activate(l){l.own(l.contributions.register({id:"pdf.preview",kind:"documentView",title:"PDF Viewer",component:s,data:{binary:!0,extensions:["pdf"]}})),l.own(l.contributions.register({id:"audio.preview",kind:"documentView",title:"Audio Player",component:r,data:{binary:!0,extensions:Object.keys(xY)}})),l.own(l.contributions.register({id:"html.preview",kind:"documentView",title:"HTML preview",component:i})),l.own(l.commands.register({id:"preview.html",title:"Open HTML Preview",when:"html",shortcut:"Ctrl+Shift+V",run:()=>o()})),l.own(l.commands.register({id:"preview.htmlSide",title:"Open HTML Preview to the Side",when:"html",shortcut:"Ctrl+K V",run:()=>o(!0)})),l.own(l.contributions.register({id:"markdown.preview",kind:"documentView",title:"Markdown preview",component:a})),l.own(l.commands.register({id:"preview.markdown",title:"Open Markdown Preview",when:"markdown",shortcut:"Ctrl+Shift+V",run:()=>n()})),l.own(l.commands.register({id:"preview.markdownSide",title:"Open Markdown Preview to the Side",when:"markdown",shortcut:"Ctrl+K V",run:()=>n(!0)})),l.own(l.commands.register({id:"preview.toggle",title:"Toggle Markdown Preview",when:"markdown",run:()=>{const c=t.workbench.activePath();return c&&!t.workbench.activeEditor()?(t.workbench.closeView("preview:"+c),t.workbench.openFile(c,{preview:!1})):n()}})),l.subscribe(()=>{for(const c of e)t.workbench.closeView(c);e.clear()})}}}const _Y={apng:"image/apng",avif:"image/avif",bmp:"image/bmp",gif:"image/gif",ico:"image/x-icon",jfif:"image/jpeg",jpe:"image/jpeg",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"},eVe=Object.keys(_Y);function CY(t){const e=t.toLowerCase().split("/").pop()??"",i=e.lastIndexOf(".");return i>0?_Y[e.slice(i+1)]:void 0}function wM(t){return CY(t)==="image/svg+xml"}const Wm=[.1,.25,.5,.75,1,1.5,2,3,4,6,8,12,16];function tVe(t,e){const i=Wm[0],s=Wm[Wm.length-1];return e>0?Wm.find(r=>r>t+1e-6)??Math.max(t,s):[...Wm].reverse().find(r=>r<t-1e-6)??Math.min(t,i)}function iVe(t,e){return t.width<=0||t.height<=0||e.width<=0||e.height<=0?1:Math.min(1,e.width/t.width,e.height/t.height)}function sVe(t){const e=["B","KB","MB"];let i=t,s=0;for(;i>=1024&&s<e.length-1;)i/=1024,s++;return`${s===0?i:i.toFixed(i<10?1:0)} ${e[s]}`}function rVe(t){const e=t*100;return`${e<10?e.toFixed(1):Math.round(e)}%`}const nVe="oxbit.images.view";function aVe(t){const e=async s=>{t.workbench.closeView(s),await t.workbench.openFile(s,{text:!0,preview:!1})};function i({path:s}){const[r,a]=L.useState(),[n,o]=L.useState(""),[l,c]=L.useState(),[u,d]=L.useState("fit"),[p,g]=L.useState({width:0,height:0}),[y,k]=L.useState(0),$=L.useRef(null);L.useEffect(()=>{const Q=new AbortController;let A="";return a(void 0),o(""),c(void 0),(async()=>{if(!t.filesystem.readBytes)throw new Error(P("This workspace cannot read image files"));const S=await t.filesystem.readBytes(s,Q.signal);Q.signal.aborted||(A=URL.createObjectURL(new Blob([S],{type:CY(s)})),a({url:A,bytes:S.byteLength}))})().catch(S=>{Q.signal.aborted||o(S instanceof Error?S.message:String(S))}),()=>{Q.abort(),A&&URL.revokeObjectURL(A)}},[s,y]),L.useEffect(()=>{const Q=t.filesystem.watch(A=>{A.path===s&&A.kind==="changed"&&k(S=>S+1)});return()=>Q.dispose()},[s]),L.useEffect(()=>{const Q=$.current;if(!Q||typeof ResizeObserver>"u")return;const A=new ResizeObserver(([S])=>g({width:S.contentRect.width,height:S.contentRect.height}));return A.observe(Q),()=>A.disconnect()},[]);const _=l?u==="fit"?iVe(l,p):u:1,C=L.useCallback(Q=>d(tVe(_,Q)),[_]),b=[l&&`${l.width} × ${l.height}`,r&&sVe(r.bytes)].filter(Boolean);return w.jsxs("div",{className:"image-document",children:[w.jsxs("div",{className:"preview-toolbar",children:[w.jsxs("span",{className:"image-meta",children:[w.jsx("span",{className:"truncate",children:s}),b.length>0&&w.jsx("span",{children:b.join(" · ")})]}),w.jsxs("span",{className:"image-actions",children:[w.jsx(Ue,{icon:"minus",label:"Zoom out",disabled:!l,onClick:()=>C(-1)}),w.jsx("button",{className:"text-button",disabled:!l,onClick:()=>d(u===1?"fit":1),children:l?rVe(_):"—"}),w.jsx(Ue,{icon:"plus",label:"Zoom in",disabled:!l,onClick:()=>C(1)}),w.jsx(Ue,{icon:"focus",label:"Fit to window",disabled:!l,"aria-pressed":u==="fit",onClick:()=>d("fit")}),w.jsx(Ue,{icon:"refresh",label:"Reload image",onClick:()=>k(Q=>Q+1)}),wM(s)&&w.jsx("button",{className:"button",onClick:()=>{e(s)},children:P("Open source")})]})]}),w.jsx("div",{ref:$,className:`image-canvas${_>=2&&!wM(s)?" pixelated":""}`,tabIndex:0,role:"group","aria-label":P("Image preview"),onKeyDown:Q=>{if(!(Q.metaKey||Q.ctrlKey||Q.altKey)){if(Q.key==="+"||Q.key==="=")C(1);else if(Q.key==="-")C(-1);else if(Q.key==="0")d(1);else if(Q.key==="9")d("fit");else return;Q.preventDefault()}},children:n?w.jsxs(Pf,{title:P("Image unavailable"),children:[w.jsx("p",{children:s}),w.jsx("p",{role:"alert",children:n}),w.jsx("button",{className:"button",onClick:()=>k(Q=>Q+1),children:P("Retry")}),w.jsx("button",{className:"button",onClick:()=>{e(s)},children:P("Open source")})]}):r&&w.jsx("img",{className:"image-frame",src:r.url,alt:s.split("/").pop(),decoding:"async",draggable:!1,onLoad:Q=>{const A=Q.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&c({width:A.naturalWidth,height:A.naturalHeight})},onError:()=>o(P("This file is not a supported image")),...l?{width:Math.max(1,Math.round(l.width*_)),height:Math.max(1,Math.round(l.height*_))}:{}})})]})}return{manifest:{manifestVersion:1,id:"oxbit.images",name:"Image Viewer",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["*"],capabilities:["filesystem.read"],description:"Opens PNG, JPEG, GIF, WebP, AVIF, BMP, ICO and SVG files without decoding them as text."},activate(s){s.own(s.contributions.register({id:nVe,kind:"documentView",title:"Image Viewer",component:i,data:{binary:!0,extensions:eVe}})),s.own(s.commands.register({id:"image.openSource",title:"Open Image as Text",category:"Image",when:"binaryDocument",run:()=>{const r=t.workbench.activePath();if(!r)throw new Error("Open an image first");return e(r)}}))}}}const oVe=async(t,e,i)=>{i.signal?.throwIfAborted();const s=await Bn(()=>import("./standalone-Cayz_KD-.js"),[]),r=i.language??W0(e).id;let a,n;if(["typescript","typescriptreact","javascript","javascriptreact","json","jsonc"].includes(r))a=r==="json"||r==="jsonc"?r:["javascript","javascriptreact"].includes(r)?"babel":"typescript",n=[await Bn(()=>import("./typescript-cMir0TZb.js"),[]),await Bn(()=>import("./babel-BktJt1uC.js"),[]),await Bn(()=>import("./estree-DFfjoHvx.js"),[])];else if(r==="css")a="css",n=[await Bn(()=>import("./postcss-BGfBeQpW.js"),[])];else if(["html"].includes(r))a="html",n=[await Bn(()=>import("./html-DwgzGnwN.js"),[])];else if(["markdown","mdx"].includes(r))a=r,n=[await Bn(()=>import("./markdown-Bd15IfY5.js"),[]),await Bn(()=>import("./babel-BktJt1uC.js"),[]),await Bn(()=>import("./estree-DFfjoHvx.js"),[])];else throw new Error(`Prettier does not support ${e}`);const o=await s.format(t,{parser:a,plugins:n,tabWidth:i.tabSize,useTabs:!i.insertSpaces});return i.signal?.throwIfAborted(),o},lVe=async(t,e,i)=>{i.signal?.throwIfAborted();const s=i.language??W0(e).id;if(!["typescript","typescriptreact","javascript","javascriptreact","json"].includes(s))throw new Error(`TypeScript formatter does not support ${e}`);const r=await Bn(()=>import("./typescript-D7-I77zl.js").then(n=>n.t),[]),a=r.createLanguageService({getScriptFileNames:()=>[e],getScriptVersion:()=>"1",getScriptKind:()=>({typescript:r.ScriptKind.TS,typescriptreact:r.ScriptKind.TSX,javascript:r.ScriptKind.JS,javascriptreact:r.ScriptKind.JSX,json:r.ScriptKind.JSON})[s]??r.ScriptKind.Unknown,getScriptSnapshot:n=>n===e?r.ScriptSnapshot.fromString(t):void 0,getCurrentDirectory:()=>"",getCompilationSettings:()=>({allowJs:!0,jsx:r.JsxEmit.Preserve,target:r.ScriptTarget.Latest,resolveJsonModule:!0}),getDefaultLibFileName:()=>"lib.d.ts",fileExists:n=>n===e,readFile:n=>n===e?t:void 0,readDirectory:()=>[]});try{const n=a.getFormattingEditsForDocument(e,{indentSize:i.tabSize,tabSize:i.tabSize,convertTabsToSpaces:i.insertSpaces,newLineCharacter:`
204
+ `).findIndex(S=>/^#{1,6}\s/.test(S)&&wY(S.replace(/^#{1,6}\s+/,""))===b.anchor)+1,Q||(Q=void 0)),await t.workbench.openFile(b.path,{line:Q})})().catch(Q=>t.workbench.notify(String(Q),"error"))},dangerouslySetInnerHTML:{__html:d.trust===c&&!g?d.html:""}}))}const n=async(l=!1)=>{const c=t.workbench.activePath();if(!c||!/\.md$/i.test(c))throw new Error("Open a Markdown document first");let u;if(l&&(u=t.workbench.split("row"),!u))return;const d="preview:"+c;e.add(d),t.workbench.openView(d,P("{0} Preview",{0:c.split("/").pop()}),a,{path:c},{groupId:u,path:c,contributionId:"markdown.preview"})},o=(l=!1)=>{const c=t.workbench.activePath();if(!c||!SY(c))throw new Error("Open an HTML document first");const u=l?t.workbench.split("row"):void 0;if(l&&!u)return;const d="html-preview:"+c;e.add(d),t.workbench.openView(d,P("{0} Preview",{0:c.split("/").pop()}),i,{path:c},{groupId:u,path:c,contributionId:"html.preview"})};return{manifest:{manifestVersion:1,id:"oxbit.previews",name:"Document & Media Previews",description:"Markdown and HTML/CSS previews, PDF viewing, and audio playback for MP3, WAV, M4A, FLAC, Ogg, and more.",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["*"],capabilities:["filesystem.read"]},activate(l){l.own(l.contributions.register({id:"pdf.preview",kind:"documentView",title:"PDF Viewer",component:s,data:{binary:!0,extensions:["pdf"]}})),l.own(l.contributions.register({id:"audio.preview",kind:"documentView",title:"Audio Player",component:r,data:{binary:!0,extensions:Object.keys(xY)}})),l.own(l.contributions.register({id:"html.preview",kind:"documentView",title:"HTML preview",component:i})),l.own(l.commands.register({id:"preview.html",title:"Open HTML Preview",when:"html",shortcut:"Ctrl+Shift+V",run:()=>o()})),l.own(l.commands.register({id:"preview.htmlSide",title:"Open HTML Preview to the Side",when:"html",shortcut:"Ctrl+K V",run:()=>o(!0)})),l.own(l.contributions.register({id:"markdown.preview",kind:"documentView",title:"Markdown preview",component:a})),l.own(l.commands.register({id:"preview.markdown",title:"Open Markdown Preview",when:"markdown",shortcut:"Ctrl+Shift+V",run:()=>n()})),l.own(l.commands.register({id:"preview.markdownSide",title:"Open Markdown Preview to the Side",when:"markdown",shortcut:"Ctrl+K V",run:()=>n(!0)})),l.own(l.commands.register({id:"preview.toggle",title:"Toggle Markdown Preview",when:"markdown",run:()=>{const c=t.workbench.activePath();return c&&!t.workbench.activeEditor()?(t.workbench.closeView("preview:"+c),t.workbench.openFile(c,{preview:!1})):n()}})),l.subscribe(()=>{for(const c of e)t.workbench.closeView(c);e.clear()})}}}const _Y={apng:"image/apng",avif:"image/avif",bmp:"image/bmp",gif:"image/gif",ico:"image/x-icon",jfif:"image/jpeg",jpe:"image/jpeg",jpeg:"image/jpeg",jpg:"image/jpeg",png:"image/png",svg:"image/svg+xml",webp:"image/webp"},eVe=Object.keys(_Y);function CY(t){const e=t.toLowerCase().split("/").pop()??"",i=e.lastIndexOf(".");return i>0?_Y[e.slice(i+1)]:void 0}function wM(t){return CY(t)==="image/svg+xml"}const Wm=[.1,.25,.5,.75,1,1.5,2,3,4,6,8,12,16];function tVe(t,e){const i=Wm[0],s=Wm[Wm.length-1];return e>0?Wm.find(r=>r>t+1e-6)??Math.max(t,s):[...Wm].reverse().find(r=>r<t-1e-6)??Math.min(t,i)}function iVe(t,e){return t.width<=0||t.height<=0||e.width<=0||e.height<=0?1:Math.min(1,e.width/t.width,e.height/t.height)}function sVe(t){const e=["B","KB","MB"];let i=t,s=0;for(;i>=1024&&s<e.length-1;)i/=1024,s++;return`${s===0?i:i.toFixed(i<10?1:0)} ${e[s]}`}function rVe(t){const e=t*100;return`${e<10?e.toFixed(1):Math.round(e)}%`}const nVe="oxbit.images.view";function aVe(t){const e=async s=>{t.workbench.closeView(s),await t.workbench.openFile(s,{text:!0,preview:!1})};function i({path:s}){const[r,a]=L.useState(),[n,o]=L.useState(""),[l,c]=L.useState(),[u,d]=L.useState("fit"),[p,g]=L.useState({width:0,height:0}),[y,k]=L.useState(0),$=L.useRef(null);L.useEffect(()=>{const Q=new AbortController;let A="";return a(void 0),o(""),c(void 0),(async()=>{if(!t.filesystem.readBytes)throw new Error(P("This workspace cannot read image files"));const S=await t.filesystem.readBytes(s,Q.signal);Q.signal.aborted||(A=URL.createObjectURL(new Blob([S],{type:CY(s)})),a({url:A,bytes:S.byteLength}))})().catch(S=>{Q.signal.aborted||o(S instanceof Error?S.message:String(S))}),()=>{Q.abort(),A&&URL.revokeObjectURL(A)}},[s,y]),L.useEffect(()=>{const Q=t.filesystem.watch(A=>{A.path===s&&A.kind==="changed"&&k(S=>S+1)});return()=>Q.dispose()},[s]),L.useEffect(()=>{const Q=$.current;if(!Q||typeof ResizeObserver>"u")return;const A=new ResizeObserver(([S])=>g({width:S.contentRect.width,height:S.contentRect.height}));return A.observe(Q),()=>A.disconnect()},[]);const _=l?u==="fit"?iVe(l,p):u:1,C=L.useCallback(Q=>d(tVe(_,Q)),[_]),b=[l&&`${l.width} × ${l.height}`,r&&sVe(r.bytes)].filter(Boolean);return w.jsxs("div",{className:"image-document",children:[w.jsxs("div",{className:"preview-toolbar",children:[w.jsxs("span",{className:"image-meta",children:[w.jsx("span",{className:"truncate",children:s}),b.length>0&&w.jsx("span",{children:b.join(" · ")})]}),w.jsxs("span",{className:"image-actions",children:[w.jsx(Ue,{icon:"minus",label:"Zoom out",disabled:!l,onClick:()=>C(-1)}),w.jsx("button",{className:"text-button",disabled:!l,onClick:()=>d(u===1?"fit":1),children:l?rVe(_):"—"}),w.jsx(Ue,{icon:"plus",label:"Zoom in",disabled:!l,onClick:()=>C(1)}),w.jsx(Ue,{icon:"focus",label:"Fit to window",disabled:!l,"aria-pressed":u==="fit",onClick:()=>d("fit")}),w.jsx(Ue,{icon:"refresh",label:"Reload image",onClick:()=>k(Q=>Q+1)}),wM(s)&&w.jsx("button",{className:"button",onClick:()=>{e(s)},children:P("Open source")})]})]}),w.jsx("div",{ref:$,className:`image-canvas${_>=2&&!wM(s)?" pixelated":""}`,tabIndex:0,role:"group","aria-label":P("Image preview"),onKeyDown:Q=>{if(!(Q.metaKey||Q.ctrlKey||Q.altKey)){if(Q.key==="+"||Q.key==="=")C(1);else if(Q.key==="-")C(-1);else if(Q.key==="0")d(1);else if(Q.key==="9")d("fit");else return;Q.preventDefault()}},children:n?w.jsxs(Pf,{title:P("Image unavailable"),children:[w.jsx("p",{children:s}),w.jsx("p",{role:"alert",children:n}),w.jsx("button",{className:"button",onClick:()=>k(Q=>Q+1),children:P("Retry")}),w.jsx("button",{className:"button",onClick:()=>{e(s)},children:P("Open source")})]}):r&&w.jsx("img",{className:"image-frame",src:r.url,alt:s.split("/").pop(),decoding:"async",draggable:!1,onLoad:Q=>{const A=Q.currentTarget;A.naturalWidth>0&&A.naturalHeight>0&&c({width:A.naturalWidth,height:A.naturalHeight})},onError:()=>o(P("This file is not a supported image")),...l?{width:Math.max(1,Math.round(l.width*_)),height:Math.max(1,Math.round(l.height*_))}:{}})})]})}return{manifest:{manifestVersion:1,id:"oxbit.images",name:"Image Viewer",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["*"],capabilities:["filesystem.read"],description:"Opens PNG, JPEG, GIF, WebP, AVIF, BMP, ICO and SVG files without decoding them as text."},activate(s){s.own(s.contributions.register({id:nVe,kind:"documentView",title:"Image Viewer",component:i,data:{binary:!0,extensions:eVe}})),s.own(s.commands.register({id:"image.openSource",title:"Open Image as Text",category:"Image",when:"binaryDocument",run:()=>{const r=t.workbench.activePath();if(!r)throw new Error("Open an image first");return e(r)}}))}}}const oVe=async(t,e,i)=>{i.signal?.throwIfAborted();const s=await Bn(()=>import("./standalone-Cayz_KD-.js"),[]),r=i.language??W0(e).id;let a,n;if(["typescript","typescriptreact","javascript","javascriptreact","json","jsonc"].includes(r))a=r==="json"||r==="jsonc"?r:["javascript","javascriptreact"].includes(r)?"babel":"typescript",n=[await Bn(()=>import("./typescript-cMir0TZb.js"),[]),await Bn(()=>import("./babel-BktJt1uC.js"),[]),await Bn(()=>import("./estree-DFfjoHvx.js"),[])];else if(r==="css")a="css",n=[await Bn(()=>import("./postcss-BGfBeQpW.js"),[])];else if(["html"].includes(r))a="html",n=[await Bn(()=>import("./html-DwgzGnwN.js"),[])];else if(["markdown","mdx"].includes(r))a=r,n=[await Bn(()=>import("./markdown-Bd15IfY5.js"),[]),await Bn(()=>import("./babel-BktJt1uC.js"),[]),await Bn(()=>import("./estree-DFfjoHvx.js"),[])];else throw new Error(`Prettier does not support ${e}`);const o=await s.format(t,{parser:a,plugins:n,tabWidth:i.tabSize,useTabs:!i.insertSpaces});return i.signal?.throwIfAborted(),o},lVe=async(t,e,i)=>{i.signal?.throwIfAborted();const s=i.language??W0(e).id;if(!["typescript","typescriptreact","javascript","javascriptreact","json"].includes(s))throw new Error(`TypeScript formatter does not support ${e}`);const r=await Bn(()=>import("./typescript-BpDj41Lu.js").then(n=>n.t),[]),a=r.createLanguageService({getScriptFileNames:()=>[e],getScriptVersion:()=>"1",getScriptKind:()=>({typescript:r.ScriptKind.TS,typescriptreact:r.ScriptKind.TSX,javascript:r.ScriptKind.JS,javascriptreact:r.ScriptKind.JSX,json:r.ScriptKind.JSON})[s]??r.ScriptKind.Unknown,getScriptSnapshot:n=>n===e?r.ScriptSnapshot.fromString(t):void 0,getCurrentDirectory:()=>"",getCompilationSettings:()=>({allowJs:!0,jsx:r.JsxEmit.Preserve,target:r.ScriptTarget.Latest,resolveJsonModule:!0}),getDefaultLibFileName:()=>"lib.d.ts",fileExists:n=>n===e,readFile:n=>n===e?t:void 0,readDirectory:()=>[]});try{const n=a.getFormattingEditsForDocument(e,{indentSize:i.tabSize,tabSize:i.tabSize,convertTabsToSpaces:i.insertSpaces,newLineCharacter:`
205
205
  `,indentStyle:r.IndentStyle.Smart,insertSpaceAfterCommaDelimiter:!0,insertSpaceBeforeAndAfterBinaryOperators:!0,insertSpaceAfterKeywordsInControlFlowStatements:!0,insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces:!0});let o=t;for(const l of n.sort((c,u)=>u.span.start-c.span.start))o=o.slice(0,l.span.start)+l.newText+o.slice(l.span.start+l.span.length);return i.signal?.throwIfAborted(),o}finally{a.dispose()}};function AY(t,e,i,s){return{manifest:{manifestVersion:1,id:t,name:e,version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],dependencies:{"oxbit.formatters":"^1.0.0"},activation:["*"],capabilities:[]},activate(r){const a={id:t,languages:s,async format(n,o,l){const c=l.signal?AbortSignal.any([l.signal,r.signal]):r.signal;return c.throwIfAborted(),typeof Worker>"u"?(i==="typescript"?lVe:oVe)(n,o,{...l,signal:c}):new Promise((u,d)=>{const p=new Worker(new URL("/assets/format.worker-3AzMYVqW.js",import.meta.url),{type:"module"}),g=()=>{clearTimeout(k),c.removeEventListener("abort",y),p.terminate()},y=()=>{g(),d(new DOMException("Formatting cancelled","AbortError"))},k=setTimeout(()=>{g(),d(new Error("Formatting exceeded 15 seconds"))},15e3);c.addEventListener("abort",y,{once:!0}),p.onmessage=$=>{g(),$.data.error?d(new Error($.data.error)):u($.data.text)},p.onerror=$=>{g(),d(new Error($.message))},p.postMessage({provider:i,text:n,path:o,language:l.language,tabSize:l.tabSize,insertSpaces:l.insertSpaces})})}};r.contributions.register({id:t,kind:"formatter",title:e,data:a})}}}const cVe=()=>AY("oxbit.prettier","Prettier","prettier",["typescript","tsx","javascript","json","jsonc","html","css","markdown","mdx"]),uVe=()=>AY("oxbit.builtin-ts","TypeScript formatter","typescript",["typescript","tsx","javascript","json"]);class dVe{constructor(e){this.options=e}options;providers=new Map;register(e){if(this.providers.has(e.id))throw new Error(`Duplicate formatter ${e.id}`);this.providers.set(e.id,e);let i=!1;return{dispose:()=>{i||(i=!0,this.providers.delete(e.id))}}}list(e){const i=new Map(this.providers);for(const r of this.options.kernel.contributions.list("formatter")){const a=r.data;if(!(!a||typeof a.id!="string"||typeof a.format!="function"||!Array.isArray(a.languages))){if(i.has(a.id)&&i.get(a.id)!==a)throw new Error(`Duplicate formatter ${a.id}`);i.set(a.id,a)}}const s=e?Zi(this.options.kernel,e).id:void 0;return[...i.values()].filter(r=>!s||r.languages.some(a=>tc(a)===s||a==="javascript"&&s==="javascriptreact"))}choice(e){const i=Zi(this.options.kernel,e).id,s=this.options.kernel.configuration.get("editor.defaultFormatter",i)||"oxbit.prettier";return{language:i,id:s,formatter:this.list(e).find(r=>r.id===s)}}available(e){return this.choice(e).formatter}selected(e){const{language:i,id:s,formatter:r}=this.choice(e);if(!r)throw new Error(`Formatter ${s} is unavailable for ${i}`);return r}title(e){const i=this.selected(e);return this.options.kernel.contributions.list("formatter").find(s=>s.data?.id===i.id)?.title??i.id}async format(e,i,s){s?.throwIfAborted();const r=Zi(this.options.kernel,i).id,n=await this.selected(i).format(e,i,{language:r,tabSize:this.options.kernel.configuration.get("editor.tabSize",r)??2,insertSpaces:this.options.kernel.configuration.get("editor.insertSpaces",r)??!0,signal:s});return s?.throwIfAborted(),n}}function hVe(t){return{manifest:{manifestVersion:1,id:"oxbit.formatters",name:"Formatter coordination",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["*"],capabilities:[]},activate(e){const i=new dVe(t);e.services.register("formatters",i);const s=()=>{const r=t.workbench.activePath(),a=!!r&&!!e.context.get("editor")&&!!i.available(r);e.context.get("formattable")!==a&&e.context.set("formattable",a)};e.configuration.subscribe(s),e.contributions.subscribe(s),e.events.on("editor.active",s),s(),e.commands.register({id:"editor.format",title:"Format Document",shortcut:"Mod+Shift+I",when:"editor && formattable",run:async()=>{const r=t.workbench.activePath();if(!r)throw new Error("Open a document to format");const a=await t.documents.open(r),n=a.version,o=performance.now(),l=i.title(r),c=await i.format(a.text.toString(),r,e.signal);if(a.version!==n)throw new Error("Document changed during formatting");a.replace(c),t.workbench.notify(`Formatted with ${l} · ${Math.round(performance.now()-o)} ms`)}}),e.hooks.beforeSave("formatters.save",async({path:r,text:a,signal:n})=>{const o=Zi(t.kernel,r).id;if(e.configuration.get("editor.formatOnSave",o)&&i.available(r))try{a=await i.format(a,r,n)}catch(l){n.throwIfAborted(),t.workbench.notify(`Saved without formatting: ${l instanceof Error?l.message:String(l)}`,"error")}return n.throwIfAborted(),e.configuration.get("files.trimTrailingWhitespace",o)&&(a=a.replace(/[\t ]+$/gm,"")),a},10),e.subscribe(()=>e.context.set("formattable",!1))}}}var TY=Object.defineProperty,fVe=Object.getOwnPropertyDescriptor,pVe=(t,e)=>{for(var i in e)TY(t,i,{get:e[i],enumerable:!0})},Qi=(t,e,i,s)=>{for(var r=s>1?void 0:s?fVe(e,i):e,a=t.length-1,n;a>=0;a--)(n=t[a])&&(r=(s?n(e,i,r):n(r))||r);return s&&r&&TY(e,i,r),r},Be=(t,e)=>(i,s)=>e(i,s,t),vM="Terminal input",B4={get:()=>vM,set:t=>vM=t},kM="Too much output to announce, navigate to rows manually to read",ev={get:()=>kM,set:t=>kM=t};function mVe(t){return t.replace(/\r?\n/g,"\r")}function gVe(t,e){return e?`\x1B[200~${t.replace(/\x1b/g,"␛")}\x1B[201~`:t}function OVe(t,e){t.clipboardData&&t.clipboardData.setData("text/plain",e.selectionText),t.preventDefault()}function yVe(t,e,i,s){if(t.stopPropagation(),t.clipboardData){let r=t.clipboardData.getData("text/plain");PY(r,e,i,s)}}function PY(t,e,i,s){t=mVe(t),t=gVe(t,i.decPrivateModes.bracketedPasteMode&&s.rawOptions.ignoreBracketedPasteMode!==!0),i.triggerDataEvent(t,!0),e.value=""}function EY(t,e,i){let s=i.getBoundingClientRect(),r=t.clientX-s.left-10,a=t.clientY-s.top-10;e.style.width="20px",e.style.height="20px",e.style.left=`${r}px`,e.style.top=`${a}px`,e.style.zIndex="1000",e.focus()}function SM(t,e,i,s,r){EY(t,e,i),r&&s.rightClickSelect(t),e.value=s.selectionText,e.select()}function Jc(t){return t>65535?(t-=65536,String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):String.fromCharCode(t)}function vp(t,e=0,i=t.length){let s="";for(let r=e;r<i;++r){let a=t[r];a>65535?(a-=65536,s+=String.fromCharCode((a>>10)+55296)+String.fromCharCode(a%1024+56320)):s+=String.fromCharCode(a)}return s}var bVe=class{constructor(){this._interim=0}clear(){this._interim=0}decode(t,e){let i=t.length;if(!i)return 0;let s=0,r=0;if(this._interim){let a=t.charCodeAt(r++);56320<=a&&a<=57343?e[s++]=(this._interim-55296)*1024+a-56320+65536:(e[s++]=this._interim,e[s++]=a),this._interim=0}for(let a=r;a<i;++a){let n=t.charCodeAt(a);if(55296<=n&&n<=56319){if(++a>=i)return this._interim=n,s;let o=t.charCodeAt(a);56320<=o&&o<=57343?e[s++]=(n-55296)*1024+o-56320+65536:(e[s++]=n,e[s++]=o);continue}n!==65279&&(e[s++]=n)}return s}},wVe=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(t,e){let i=t.length;if(!i)return 0;let s=0,r,a,n,o,l,c=0;if(this.interim[0]){let p=!1,g=this.interim[0];g&=(g&224)===192?31:(g&240)===224?15:7;let y=0,k;for(;(k=this.interim[++y])&&y<4;)g<<=6,g|=k&63;let $=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,_=$-y;for(;c<_;){if(c>=i)return 0;if(k=t[c++],(k&192)!==128){c--,p=!0;break}else this.interim[y++]=k,g<<=6,g|=k&63}p||($===2?g<128?c--:e[s++]=g:$===3?g<2048||g>=55296&&g<=57343||g===65279||(e[s++]=g):g<65536||g>1114111||(e[s++]=g)),this.interim.fill(0)}let u=i-4,d=c;for(;d<i;){for(;d<u&&!((r=t[d])&128)&&!((a=t[d+1])&128)&&!((n=t[d+2])&128)&&!((o=t[d+3])&128);)e[s++]=r,e[s++]=a,e[s++]=n,e[s++]=o,d+=4;if(r=t[d++],r<128)e[s++]=r;else if((r&224)===192){if(d>=i)return this.interim[0]=r,s;if(a=t[d++],(a&192)!==128){d--;continue}if(l=(r&31)<<6|a&63,l<128){d--;continue}e[s++]=l}else if((r&240)===224){if(d>=i)return this.interim[0]=r,s;if(a=t[d++],(a&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=a,s;if(n=t[d++],(n&192)!==128){d--;continue}if(l=(r&15)<<12|(a&63)<<6|n&63,l<2048||l>=55296&&l<=57343||l===65279)continue;e[s++]=l}else if((r&248)===240){if(d>=i)return this.interim[0]=r,s;if(a=t[d++],(a&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=a,s;if(n=t[d++],(n&192)!==128){d--;continue}if(d>=i)return this.interim[0]=r,this.interim[1]=a,this.interim[2]=n,s;if(o=t[d++],(o&192)!==128){d--;continue}if(l=(r&7)<<18|(a&63)<<12|(n&63)<<6|o&63,l<65536||l>1114111)continue;e[s++]=l}}return s}},$O=class RY{constructor(){this.fg=0,this.bg=0,this.extended=new tv}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let e=new RY;return e.fg=this.fg,e.bg=this.bg,e.extended=this.extended.clone(),e}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},tv=class QY{constructor(e=0,i=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=i}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new QY(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0&&this.payload===void 0}},ho=class DY extends $O{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new tv,this.combinedData=""}static fromCharData(e){let i=new DY;return i.setFromCharData(e),i}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?Jc(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let i=!1;if(e[1].length>2)i=!0;else if(e[1].length===2){let s=e[1].charCodeAt(0);if(55296<=s&&s<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(s-55296)*1024+r-56320+65536|e[2]<<22:i=!0}else i=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;i&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}attributesEquals(e){if(this.getFgColorMode()!==e.getFgColorMode()||this.getFgColor()!==e.getFgColor()||this.getBgColorMode()!==e.getBgColorMode()||this.getBgColor()!==e.getBgColor()||this.isInverse()!==e.isInverse()||this.isBold()!==e.isBold()||this.isUnderline()!==e.isUnderline())return!1;if(this.isUnderline()){if(this.getUnderlineStyle()!==e.getUnderlineStyle())return!1;let i=this.isUnderlineColorDefault(),s=e.isUnderlineColorDefault();if(!(i&&s)&&(i!==s||this.getUnderlineColor()!==e.getUnderlineColor()||this.getUnderlineColorMode()!==e.getUnderlineColorMode()))return!1}return!(this.isOverline()!==e.isOverline()||this.isBlink()!==e.isBlink()||this.isInvisible()!==e.isInvisible()||this.isItalic()!==e.isItalic()||this.isDim()!==e.isDim()||this.isStrikethrough()!==e.isStrikethrough())}},y_=new Map;function vVe(t){return t.di$dependencies||[]}function Ss(t){if(y_.has(t))return y_.get(t);let e=function(i,s,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");kVe(e,i,r)};return e._id=t,y_.set(t,e),e}function kVe(t,e,i){e.di$target===e?e.di$dependencies.push({id:t,index:i}):(e.di$dependencies=[{id:t,index:i}],e.di$target=e)}var Nr=Ss("BufferService"),fk=Ss("MouseStateService"),hc=Ss("CoreService"),SVe=Ss("CharsetService"),lA=Ss("InstantiationService"),kp=Ss("LogService"),Fr=Ss("OptionsService"),NY=Ss("OscLinkService"),xVe=Ss("UnicodeService"),_O=Ss("DecorationService"),U4=class{constructor(t,e,i){this._bufferService=t,this._optionsService=e,this._oscLinkService=i,this._workCell=new ho}provideLinks(t,e){let i=this._bufferService.buffer.lines.get(t-1);if(!i){e(void 0);return}let s=[],r=this._optionsService.rawOptions.linkHandler,a=this._workCell,n=i.getTrimmedLength(),o=-1,l=-1,c=!1;for(let u=0;u<n;u++)if(!(l===-1&&!i.hasContent(u))){if(i.loadCell(u,a),a.hasExtendedAttrs()&&a.extended.urlId)if(l===-1){l=u,o=a.extended.urlId;continue}else c=a.extended.urlId!==o;else l!==-1&&(c=!0);if(c||l!==-1&&u===n-1){let d=this._oscLinkService.getLinkData(o)?.uri;if(d){let p=u+(!c&&u===n-1?1:0),g=this._getRangeWithLineWrap(t,l,p,o),y=!1;if(!r?.allowNonHttpProtocols)try{let k=new URL(d);["http:","https:"].includes(k.protocol)||(y=!0)}catch{y=!0}y||s.push({text:d,range:g,activate:(k,$)=>r?r.activate(k,$,g):$Ve(k,$),hover:(k,$)=>r?.hover?.(k,$,g),leave:(k,$)=>r?.leave?.(k,$,g)})}c=!1,a.hasExtendedAttrs()&&a.extended.urlId?(l=u,o=a.extended.urlId):(l=-1,o=-1)}}e(s)}_getRangeWithLineWrap(t,e,i,s){let r=t,a=e,n=t,o=i;for(;a===0&&this._bufferService.buffer.lines.get(r-1)?.isWrapped;){let l=this._bufferService.buffer.lines.get(r-2);if(!l)break;let c=l.getTrimmedLength();if(c===0||!this._hasUrlId(l,c-1,s))break;let u=c-1;for(;u>0&&this._hasUrlId(l,u-1,s);)u--;r--,a=u}for(;;){let l=this._bufferService.buffer.lines.get(n-1);if(!l)break;let c=l.getTrimmedLength();if(o!==c)break;let u=this._bufferService.buffer.lines.get(n);if(!u?.isWrapped)break;let d=u.getTrimmedLength();if(d===0||!this._hasUrlId(u,0,s))break;let p=1;for(;p<d&&this._hasUrlId(u,p,s);)p++;n++,o=p}return{start:{x:a+1,y:r},end:{x:o,y:n}}}_hasUrlId(t,e,i){let s=this._workCell;return t.loadCell(e,s),!!s.hasExtendedAttrs()&&s.extended.urlId===i}};U4=Qi([Be(0,Nr),Be(1,Fr),Be(2,NY)],U4);function $Ve(t,e){if(confirm(`Do you want to navigate to ${e}?
206
206
 
207
207
  WARNING: This link could potentially be dangerous`)){let i=window.open();if(i){try{i.opener=null}catch{}i.location.href=e}else console.warn("Opening link blocked as opener could not be cleared")}}var pk=Ss("CharSizeService"),gl=Ss("CoreBrowserService"),mk=Ss("MouseCoordsService"),_Ve=Ss("MouseService"),Ol=Ss("RenderService"),FY=Ss("SelectionService"),LY=Ss("CharacterJoinerService"),Sp=Ss("ThemeService"),MY=Ss("LinkProviderService"),CVe=Ss("KeyboardService");function pi(t){return{dispose:t}}function B0(t){if(!t)return t;if(Array.isArray(t)){for(let e of t)e.dispose();return[]}return t.dispose(),t}var xp=class{constructor(){this._disposables=new Set,this._isDisposed=!1}get isDisposed(){return this._isDisposed}add(t){return this._isDisposed?t.dispose():this._disposables.add(t),t}dispose(){if(!this._isDisposed){this._isDisposed=!0;for(let t of this._disposables)t.dispose();this._disposables.clear()}}clear(){for(let t of this._disposables)t.dispose();this._disposables.clear()}},Dt=class{constructor(){this._store=new xp}dispose(){this._store.dispose()}_register(t){return this._store.add(t)}};Dt.None=Object.freeze({dispose(){}});var ea=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}},gk=class{constructor(){this._token=-1,this._isDisposed=!1}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(t,e){if(this._isDisposed)throw new Error("Calling cancelAndSet on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,t()},e)}setIfNotSet(t,e){if(this._isDisposed)throw new Error("Calling setIfNotSet on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,t()},e))}},AVe=class{constructor(){this._isScheduled=!1,this._isDisposed=!1}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._isScheduled=!1}set(t){if(this._isDisposed)throw new Error("Calling set on a disposed MicrotaskTimer");this._isScheduled||(this._isScheduled=!0,queueMicrotask(()=>{this._isScheduled&&(this._isScheduled=!1,t())}))}},TVe=class{constructor(){this._isDisposed=!1}cancel(){this._disposable?.dispose(),this._disposable=void 0}cancelAndSet(t,e,i=globalThis){if(this._isDisposed)throw new Error("Calling cancelAndSet on a disposed IntervalTimer");this.cancel();let s=i.setInterval(()=>{t()},e);this._disposable={dispose:()=>{i.clearInterval(s),this._disposable=void 0}}}dispose(){this.cancel(),this._isDisposed=!0}};function no(t){let e=t;if(e?.ownerDocument?.defaultView)return e.ownerDocument.defaultView;let i=t;return i?.view?i.view:window}var PVe=class{constructor(t,e,i,s){this._node=t,this._type=e,this._handler=i,this._options=s,t.addEventListener(e,i,s)}dispose(){!this._node||!this._handler||(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function dt(t,e,i,s){return new PVe(t,e,i,s)}function xM(t,e,i,s){return dt(t,e,i,s)}var tl={CLICK:"click",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",POINTER_UP:"pointerup",MOUSE_WHEEL:"wheel"};function EVe(t){let e=t.getBoundingClientRect(),i=no(t);return{left:e.left+i.scrollX,top:e.top+i.scrollY,width:e.width,height:e.height}}var IY=class{constructor(t,e){this._runner=t,this.priority=e,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(t){console.error(t)}}static sort(t,e){return e.priority-t.priority}},$M=new Map;function jY(t){let e=$M.get(t);return e||(e={next:[],current:[],animFrameRequested:!1,inAnimationFrameRunner:!1},$M.set(t,e)),e}function RVe(t){let e=jY(t);for(e.animFrameRequested=!1,e.current=e.next,e.next=[],e.inAnimationFrameRunner=!0;e.current.length>0;)e.current.sort(IY.sort),e.current.shift().execute();e.inAnimationFrameRunner=!1}function cA(t,e,i=0){let s=jY(t),r=new IY(e,i);return s.next.push(r),s.animFrameRequested||(s.animFrameRequested=!0,t.requestAnimationFrame(()=>RVe(t))),r}var QVe=class extends TVe{constructor(t){super(),this._defaultTarget=t?no(t):void 0}cancelAndSet(t,e,i){super.cancelAndSet(t,e,i??this._defaultTarget??window)}},zg=class{constructor(t){this.domNode=t,this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._className="",this._position="",this._layerHint=!1,this._contain="none"}setWidth(t){let e=Eh(t);this._width!==e&&(this._width=e,this.domNode.style.width=this._width)}setHeight(t){let e=Eh(t);this._height!==e&&(this._height=e,this.domNode.style.height=this._height)}setTop(t){let e=Eh(t);this._top!==e&&(this._top=e,this.domNode.style.top=this._top)}setLeft(t){let e=Eh(t);this._left!==e&&(this._left=e,this.domNode.style.left=this._left)}setBottom(t){let e=Eh(t);this._bottom!==e&&(this._bottom=e,this.domNode.style.bottom=this._bottom)}setRight(t){let e=Eh(t);this._right!==e&&(this._right=e,this.domNode.style.right=this._right)}setClassName(t){this._className!==t&&(this._className=t,this.domNode.className=this._className)}toggleClassName(t,e){this.domNode.classList.toggle(t,e),this._className=this.domNode.className}setPosition(t){this._position!==t&&(this._position=t,this.domNode.style.position=this._position)}setLayerHinting(t){this._layerHint!==t&&(this._layerHint=t,t?this.domNode.style.transform="translate3d(0px, 0px, 0px)":this.domNode.style.transform="")}setContain(t){this._contain!==t&&(this._contain=t,this.domNode.style.contain=this._contain)}setAttribute(t,e){this.domNode.setAttribute(t,e)}};function Eh(t){return typeof t=="number"?`${t}px`:t}var zY={};pVe(zY,{getSafariVersion:()=>NVe,getZoomFactor:()=>BY,isChrome:()=>hA,isChromeOS:()=>UY,isFirefox:()=>iv,isLegacyEdge:()=>DVe,isLinux:()=>pA,isMac:()=>Aa,isNode:()=>uA,isSafari:()=>fA,isWindows:()=>Ok});var uA=!!(typeof process<"u"&&"title"in process&&(typeof navigator>"u"||navigator.userAgent.startsWith("Node.js/"))),$p=uA?"node":navigator.userAgent,dA=uA?"node":navigator.platform,iv=$p.includes("Firefox"),hA=$p.includes("Chrome"),DVe=$p.includes("Edge"),fA=/^((?!chrome|android).)*safari/i.test($p);function BY(t){return 1}function NVe(){if(!fA)return 0;let t=$p.match(/Version\/(\d+)/);return t===null||t.length<2?0:parseInt(t[1],10)}var Aa=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(dA),Ok=["Windows","Win16","Win32","WinCE"].includes(dA),pA=dA.indexOf("Linux")>=0,UY=/\bCrOS\b/.test($p),_M=new WeakMap;function FVe(t){if(!t.parent||t.parent===t)return null;try{let e=t.location,i=t.parent.location;if(e.origin!=="null"&&i.origin!=="null"&&e.origin!==i.origin)return null}catch{return null}return t.parent}var LVe=class{static _getSameOriginWindowChain(t){let e=_M.get(t);if(!e){e=[],_M.set(t,e);let i=t,s;do s=FVe(i),s?e.push({window:new WeakRef(i),iframeElement:i.frameElement??null}):e.push({window:new WeakRef(i),iframeElement:null}),i=s;while(i)}return e.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(t,e){if(!e||t===e)return{top:0,left:0};let i=0,s=0,r=this._getSameOriginWindowChain(t);for(let a of r){let n=a.window.deref();if(i+=n?.scrollY??0,s+=n?.scrollX??0,n===e||!a.iframeElement)break;let o=a.iframeElement.getBoundingClientRect();i+=o.top,s+=o.left}return{top:i,left:s}}},b_=class{constructor(t,e){this.timestamp=Date.now(),this.browserEvent=e,this.leftButton=e.button===0,this.middleButton=e.button===1,this.rightButton=e.button===2,this.buttons=e.buttons,this.target=e.target,this.detail=e.detail??1,e.type==="dblclick"&&(this.detail=2),this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey,typeof e.pageX=="number"?(this.posx=e.pageX,this.posy=e.pageY):(this.posx=e.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=e.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let i=LVe.getPositionOfChildWindowRelativeToAncestorWindow(t,e.view);this.posx-=i.left,this.posy-=i.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},CM=class{constructor(t,e=0,i=0){this.browserEvent=t??null,this.target=t?t.target??t.targetNode??t.srcElement??null:null,this.deltaY=i,this.deltaX=e;let s=!1;if(hA){let r=navigator.userAgent.match(/Chrome\/(\d+)/);s=(r?parseInt(r[1],10):123)<=122}if(t){let r=t,a=t,n=t.view?.devicePixelRatio??1;if(typeof r.wheelDeltaY<"u")s?this.deltaY=r.wheelDeltaY/(120*n):this.deltaY=r.wheelDeltaY/120;else if(typeof a.VERTICAL_AXIS<"u"&&a.axis===a.VERTICAL_AXIS)this.deltaY=-a.detail/3;else if(t.type==="wheel"){let o=t;o.deltaMode===o.DOM_DELTA_LINE?iv&&!Aa?this.deltaY=-t.deltaY/3:this.deltaY=-t.deltaY:this.deltaY=-t.deltaY/40}if(typeof r.wheelDeltaX<"u")fA&&Ok?this.deltaX=-(r.wheelDeltaX/120):s?this.deltaX=r.wheelDeltaX/(120*n):this.deltaX=r.wheelDeltaX/120;else if(typeof a.HORIZONTAL_AXIS<"u"&&a.axis===a.HORIZONTAL_AXIS)this.deltaX=-t.detail/3;else if(t.type==="wheel"){let o=t;o.deltaMode===o.DOM_DELTA_LINE?iv&&!Aa?this.deltaX=-t.deltaX/3:this.deltaX=-t.deltaX:this.deltaX=-t.deltaX/40}this.deltaY===0&&this.deltaX===0&&t.wheelDelta&&(s?this.deltaY=t.wheelDelta/(120*n):this.deltaY=t.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},XY=class{constructor(){this._hooks=new xp,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let e=this._onStopCallback;this._onStopCallback=null,t&&e&&e()}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(t,e,i,s,r){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=s,this._onStopCallback=r;let a=t;try{t.setPointerCapture(e),this._hooks.add(pi(()=>{try{t.releasePointerCapture(e)}catch{}}))}catch{a=no(t)}this._hooks.add(dt(a,tl.POINTER_MOVE,n=>{if(n.buttons!==i){this.stopMonitoring(!0);return}n.preventDefault(),this._pointerMoveCallback(n)})),this._hooks.add(dt(a,tl.POINTER_UP,n=>this.stopMonitoring(!0)))}},mA=class extends Dt{_onclick(t,e){this._register(dt(t,tl.CLICK,i=>e(new b_(no(t),i))))}_onmouseover(t,e){this._register(dt(t,tl.MOUSE_OVER,i=>e(new b_(no(t),i))))}_onmouseleave(t,e){this._register(dt(t,tl.MOUSE_LEAVE,i=>e(new b_(no(t),i))))}},MVe=class extends mA{constructor(t){super(),this._handleActivate=t.handleActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="xterm-arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=t.bgWidth+"px",this.bgDomNode.style.height=t.bgHeight+"px",typeof t.top<"u"&&(this.bgDomNode.style.top="0px"),typeof t.left<"u"&&(this.bgDomNode.style.left="0px"),typeof t.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof t.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=t.className,this.domNode.style.position="absolute";let e=Math.min(t.bgWidth,t.bgHeight);this.domNode.style.width=e+"px",this.domNode.style.height=e+"px",typeof t.top<"u"&&(this.domNode.style.top=t.top+"px"),typeof t.left<"u"&&(this.domNode.style.left=t.left+"px"),typeof t.bottom<"u"&&(this.domNode.style.bottom=t.bottom+"px"),typeof t.right<"u"&&(this.domNode.style.right=t.right+"px"),this._pointerMoveMonitor=this._register(new XY),this._register(xM(this.bgDomNode,tl.POINTER_DOWN,i=>this._arrowPointerDown(i))),this._register(xM(this.domNode,tl.POINTER_DOWN,i=>this._arrowPointerDown(i))),this._pointerdownRepeatTimer=this._register(new QVe),this._pointerdownScheduleRepeatTimer=this._register(new gk)}_arrowPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._handleActivate(),1e3/24,no(t))};this._handleActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(e,200),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,i=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),t.preventDefault()}},Ke=class{constructor(){this._listeners=[],this._disposed=!1}get event(){return this._event?this._event:(this._event=(e,i,s)=>{if(this._disposed)return pi(()=>{});let r={fn:e,thisArgs:i};this._listeners=this._listeners.slice(),this._listeners.push(r);let a=pi(()=>{let n=this._listeners.indexOf(r);n!==-1&&(this._listeners=this._listeners.slice(),this._listeners.splice(n,1))});return s&&(Array.isArray(s)?s.push(a):s.add(a)),a},this._event)}fire(e){if(this._disposed||!this._listeners.length)return;if(this._listeners.length===1){this._listeners[0].fn.call(this._listeners[0].thisArgs,e);return}let i=this._listeners;for(let s=0,r=i.length;s<r;++s)i[s].fn.call(i[s].thisArgs,e)}dispose(){this._disposed||(this._disposed=!0,this._listeners.length=0)}},dn;(t=>{function e(a,n){return a(o=>n.fire(o))}t.forward=e;function i(a,n){return(o,l,c)=>a(u=>o.call(l,n(u)),void 0,c)}t.map=i;function s(...a){return(n,o,l)=>{let c=new xp;for(let u of a)c.add(u(d=>n.call(o,d)));return l&&(Array.isArray(l)?l.push(c):l.add(c)),c}}t.any=s;function r(a,n,o){return n(o),a(l=>n(l))}t.runAndSubscribe=r})(dn||={});var IVe=class X4{constructor(e,i,s,r,a,n,o){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(i=i|0,s=s|0,r=r|0,a=a|0,n=n|0,o=o|0),this.rawScrollLeft=r,this.rawScrollTop=o,i<0&&(i=0),r+i>s&&(r=s-i),r<0&&(r=0),a<0&&(a=0),o+a>n&&(o=n-a),o<0&&(o=0),this.width=i,this.scrollWidth=s,this.scrollLeft=r,this.height=a,this.scrollHeight=n,this.scrollTop=o}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(e,i){return new X4(this._forceIntegerValues,typeof e.width<"u"?e.width:this.width,typeof e.scrollWidth<"u"?e.scrollWidth:this.scrollWidth,i?this.rawScrollLeft:this.scrollLeft,typeof e.height<"u"?e.height:this.height,typeof e.scrollHeight<"u"?e.scrollHeight:this.scrollHeight,i?this.rawScrollTop:this.scrollTop)}withScrollPosition(e){return new X4(this._forceIntegerValues,this.width,this.scrollWidth,typeof e.scrollLeft<"u"?e.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof e.scrollTop<"u"?e.scrollTop:this.rawScrollTop)}createScrollEvent(e,i){let s=this.width!==e.width,r=this.scrollWidth!==e.scrollWidth,a=this.scrollLeft!==e.scrollLeft,n=this.height!==e.height,o=this.scrollHeight!==e.scrollHeight,l=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:i,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:s,scrollWidthChanged:r,scrollLeftChanged:a,heightChanged:n,scrollHeightChanged:o,scrollTopChanged:l}}},qY=class extends Dt{constructor(t){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Ke),this.onScroll=this._onScroll.event,this._smoothScrollDuration=t.smoothScrollDuration,this._scheduleAtNextAnimationFrame=t.scheduleAtNextAnimationFrame,this._state=new IVe(t.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(t){this._smoothScrollDuration=t}validateScrollPosition(t){return this._state.withScrollPosition(t)}getScrollDimensions(){return this._state}setScrollDimensions(t,e){let i=this._state.withScrollDimensions(t,e);this._setState(i,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(t){let e=this._state.withScrollPosition(t);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(e,!1)}setScrollPositionSmooth(t,e){if(this._smoothScrollDuration===0){this.setScrollPositionNow(t);return}if(this._smoothScrolling){t={scrollLeft:typeof t.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:t.scrollLeft,scrollTop:typeof t.scrollTop>"u"?this._smoothScrolling.to.scrollTop:t.scrollTop};let i=this._state.withScrollPosition(t);if(this._smoothScrolling.to.scrollLeft===i.scrollLeft&&this._smoothScrolling.to.scrollTop===i.scrollTop)return;let s;e?s=new v_(this._smoothScrolling.from,i,this._smoothScrolling.startTime,this._smoothScrolling.duration):s=v_.start(this._state,i,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=s}else{let i=this._state.withScrollPosition(t);this._smoothScrolling=v_.start(this._state,i,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let t=this._smoothScrolling.tick(),e=this._state.withScrollPosition(t);if(this._setState(e,!0),!!this._smoothScrolling){if(t.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(t,e){let i=this._state;i.equals(t)||(this._state=t,this._onScroll.fire(this._state.createScrollEvent(i,e)))}},AM=class{constructor(t,e,i){this.scrollLeft=t,this.scrollTop=e,this.isDone=i}};function w_(t,e){let i=e-t;return function(s){return t+i*BVe(s)}}function jVe(t,e,i){return function(s){return s<i?t(s/i):e((s-i)/(1-i))}}var v_=class VY{constructor(e,i,s,r){this.from=e,this.to=i,this.duration=r,this.startTime=s,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this._scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this._scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,i,s){if(Math.abs(e-i)>2.5*s){let r,a;return e<i?(r=e+.75*s,a=i-.75*s):(r=e-.75*s,a=i+.75*s),jVe(w_(e,r),w_(a,i),.33)}return w_(e,i)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let i=(e-this.startTime)/this.duration;if(i<1){let s=this._scrollLeft(i),r=this._scrollTop(i);return new AM(s,r,!1)}return new AM(this.to.scrollLeft,this.to.scrollTop,!0)}static start(e,i,s){s=s+10;let r=Date.now()-10;return new VY(e,i,r,s)}};function zVe(t){return Math.pow(t,3)}function BVe(t){return 1-zVe(1-t)}var UVe=class extends Dt{constructor(t,e,i){super(),this._visibility=t,this._visibleClassName=e,this._invisibleClassName=i,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new gk)}setVisibility(t){this._visibility!==t&&(this._visibility=t,this._updateShouldBeVisible())}setShouldBeVisible(t){this._rawShouldBeVisible=t,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let t=this._applyVisibilitySetting();this._shouldBeVisible!==t&&(this._shouldBeVisible=t,this.ensureVisibility())}setIsNeeded(t){this._isNeeded!==t&&(this._isNeeded=t,this.ensureVisibility())}setDomNode(t){this._domNode=t,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(t){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(t?" xterm-fade":"")))}},XVe=140,ZY=class extends mA{constructor(t){super(),this._lazyRender=t.lazyRender,this._host=t.host,this._scrollable=t.scrollable,this._scrollByPage=t.scrollByPage,this._scrollbarState=t.scrollbarState,this._visibilityController=this._register(new UVe(t.visibility,"xterm-visible xterm-scrollbar "+t.extraScrollbarClassName,"xterm-invisible xterm-scrollbar "+t.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new XY),this._shouldRender=!0,this.domNode=new zg(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(dt(this.domNode.domNode,tl.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(t){let e=this._register(new MVe(t));return this.domNode.domNode.appendChild(e.bgDomNode),this.domNode.domNode.appendChild(e.domNode),e}_createSlider(t,e,i,s){this.slider=new zg(document.createElement("div")),this.slider.setClassName("xterm-slider"),this.slider.setPosition("absolute"),this.slider.setTop(t),this.slider.setLeft(e),typeof i=="number"&&this.slider.setWidth(i),typeof s=="number"&&this.slider.setHeight(s),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(dt(this.slider.domNode,tl.POINTER_DOWN,r=>{r.button===0&&(r.preventDefault(),this._sliderPointerDown(r))})),this._onclick(this.slider.domNode,r=>{r.leftButton&&r.stopPropagation()})}_handleElementSize(t){return this._scrollbarState.setVisibleSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_handleElementScrollSize(t){return this._scrollbarState.setScrollSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_handleElementScrollPosition(t){return this._scrollbarState.setScrollPosition(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(t){t.target===this.domNode.domNode&&this._handlePointerDown(t)}delegatePointerDown(t){let e=this.domNode.domNode.getClientRects()[0].top,i=e+this._scrollbarState.getSliderPosition(),s=e+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),r=this._sliderPointerPosition(t);i<=r&&r<=s?t.button===0&&(t.preventDefault(),this._sliderPointerDown(t)):this._handlePointerDown(t)}_handlePointerDown(t){let e,i;if(t.target===this.domNode.domNode&&typeof t.offsetX=="number"&&typeof t.offsetY=="number")e=t.offsetX,i=t.offsetY;else{let r=EVe(this.domNode.domNode);e=t.pageX-r.left,i=t.pageY-r.top}let s=this._pointerDownRelativePosition(e,i);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(s):this._scrollbarState.getDesiredScrollPositionFromOffset(s)),t.button===0&&(t.preventDefault(),this._sliderPointerDown(t))}_sliderPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=this._sliderPointerPosition(t),i=this._sliderOrthogonalPointerPosition(t),s=this._scrollbarState.clone();this.slider.toggleClassName("xterm-active",!0),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,r=>{let a=this._sliderOrthogonalPointerPosition(r),n=Math.abs(a-i);if(Ok&&n>XVe){this._setDesiredScrollPositionNow(s.getScrollPosition());return}let o=this._sliderPointerPosition(r)-e;this._setDesiredScrollPositionNow(s.getDesiredScrollPositionFromDelta(o))},()=>{this.slider.toggleClassName("xterm-active",!1),this._host.handleDragEnd()}),this._host.handleDragStart()}_setDesiredScrollPositionNow(t){let e={};this.writeScrollPosition(e,t),this._scrollable.setScrollPositionNow(e)}updateScrollbarSize(t){this._updateScrollbarSize(t),this._scrollbarState.setScrollbarSize(t),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},WY=class q4{constructor(e,i,s,r,a,n){this._scrollbarSize=Math.round(i),this._oppositeScrollbarSize=Math.round(s),this._arrowSize=Math.round(e),this._visibleSize=r,this._scrollSize=a,this._scrollPosition=n,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new q4(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let i=Math.round(e);return this._visibleSize!==i?(this._visibleSize=i,this._refreshComputedValues(),!0):!1}setScrollSize(e){let i=Math.round(e);return this._scrollSize!==i?(this._scrollSize=i,this._refreshComputedValues(),!0):!1}setScrollPosition(e){let i=Math.round(e);return this._scrollPosition!==i?(this._scrollPosition=i,this._refreshComputedValues(),!0):!1}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setArrowSize(e){let i=Math.round(e);this._arrowSize!==i&&(this._arrowSize=i,this._refreshComputedValues())}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,i,s,r,a){let n=Math.max(0,s-e),o=Math.max(0,n-2*i),l=r>0&&r>s;if(!l)return{computedAvailableSize:Math.round(n),computedIsNeeded:l,computedSliderSize:Math.round(o),computedSliderRatio:0,computedSliderPosition:0};let c=Math.round(Math.max(20,Math.floor(s*o/r))),u=(o-c)/(r-s),d=a*u;return{computedAvailableSize:Math.round(n),computedIsNeeded:l,computedSliderSize:Math.round(c),computedSliderRatio:u,computedSliderPosition:Math.round(d)}}_refreshComputedValues(){let e=q4._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=e.computedAvailableSize,this._computedIsNeeded=e.computedIsNeeded,this._computedSliderSize=e.computedSliderSize,this._computedSliderRatio=e.computedSliderRatio,this._computedSliderPosition=e.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let i=e-this._arrowSize-this._computedSliderSize/2;return Math.round(i/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let i=e-this._arrowSize,s=this._scrollPosition;return i<this._computedSliderPosition?s-=this._visibleSize:s+=this._visibleSize,s}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let i=this._computedSliderPosition+e;return Math.round(i/this._computedSliderRatio)}},qVe=class extends ZY{constructor(t,e,i){let s=t.getScrollDimensions(),r=t.getCurrentScrollPosition();if(super({lazyRender:e.lazyRender,host:i,scrollbarState:new WY(e.horizontalHasArrows?e.horizontalScrollbarSize:0,e.horizontal===2?0:e.horizontalScrollbarSize,e.vertical===2?0:e.verticalScrollbarSize,s.width,s.scrollWidth,r.scrollLeft),visibility:e.horizontal,extraScrollbarClassName:"xterm-horizontal",scrollable:t,scrollByPage:e.scrollByPage}),e.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((e.horizontalScrollbarSize-e.horizontalSliderSize)/2),0,void 0,e.horizontalSliderSize)}_updateSlider(t,e){this.slider.setWidth(t),this.slider.setLeft(e)}_renderDomNode(t,e){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setLeft(0),this.domNode.setBottom(0)}handleScroll(t){return this._shouldRender=this._handleElementScrollSize(t.scrollWidth)||this._shouldRender,this._shouldRender=this._handleElementScrollPosition(t.scrollLeft)||this._shouldRender,this._shouldRender=this._handleElementSize(t.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return t}_sliderPointerPosition(t){return t.pageX}_sliderOrthogonalPointerPosition(t){return t.pageY}_updateScrollbarSize(t){this.slider.setHeight(t)}writeScrollPosition(t,e){t.scrollLeft=e}updateOptions(t){this.updateScrollbarSize(t.horizontal===2?0:t.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._visibilityController.setVisibility(t.horizontal),this._scrollByPage=t.scrollByPage}},VVe=class extends ZY{constructor(t,e,i){let s=t.getScrollDimensions(),r=t.getCurrentScrollPosition(),a=e.verticalHasArrows;super({lazyRender:e.lazyRender,host:i,scrollbarState:new WY(a?e.verticalScrollbarSize:0,e.vertical===2?0:e.verticalScrollbarSize,0,s.height,s.scrollHeight,r.scrollTop),visibility:e.vertical,extraScrollbarClassName:"xterm-vertical",scrollable:t,scrollByPage:e.scrollByPage}),this._arrowScrollDelta=0,this._setArrows(a,e.verticalScrollbarSize),this._createSlider(0,Math.floor((e.verticalScrollbarSize-e.verticalSliderSize)/2),e.verticalSliderSize,void 0)}_updateSlider(t,e){this.slider.setHeight(t),this.slider.setTop(e)}_renderDomNode(t,e){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setRight(0),this.domNode.setTop(0)}handleScroll(t){return this._shouldRender=this._handleElementScrollSize(t.scrollHeight)||this._shouldRender,this._shouldRender=this._handleElementScrollPosition(t.scrollTop)||this._shouldRender,this._shouldRender=this._handleElementSize(t.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return e}_sliderPointerPosition(t){return t.pageY}_sliderOrthogonalPointerPosition(t){return t.pageX}_updateScrollbarSize(t){this.slider.setWidth(t)}writeScrollPosition(t,e){t.scrollTop=e}_arrowScroll(t){let e=this._scrollable.getCurrentScrollPosition();this._scrollable.setScrollPositionNow({scrollTop:e.scrollTop+t})}_setArrows(t,e){if(this._arrowScrollDelta=e,(!this._arrowUp||!this._arrowDown)&&(this._arrowUp=this._createArrow({className:"xterm-scra xterm-arrow-up",top:0,left:0,bgWidth:e,bgHeight:e,handleActivate:()=>this._arrowScroll(-this._arrowScrollDelta)}),this._arrowDown=this._createArrow({className:"xterm-scra xterm-arrow-down",bottom:0,left:0,bgWidth:e,bgHeight:e,handleActivate:()=>this._arrowScroll(this._arrowScrollDelta)})),this._updateArrowSize(this._arrowUp,e),this._updateArrowSize(this._arrowDown,e),!this._arrowUp||!this._arrowDown)return;let i=t?"":"none";this._arrowUp.bgDomNode.style.display=i,this._arrowUp.domNode.style.display=i,this._arrowDown.bgDomNode.style.display=i,this._arrowDown.domNode.style.display=i}_updateArrowSize(t,e){t&&(t.bgDomNode.style.width=`${e}px`,t.bgDomNode.style.height=`${e}px`,t.domNode.style.width=`${e}px`,t.domNode.style.height=`${e}px`)}updateOptions(t){let e=t.verticalHasArrows?t.verticalScrollbarSize:0;this._scrollbarState.setArrowSize(e),this._setArrows(t.verticalHasArrows,t.verticalScrollbarSize),this.updateScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(t.vertical),this._scrollByPage=t.scrollByPage}},ZVe=class{constructor(t,e,i){this.timestamp=t,this.deltaX=e,this.deltaY=i,this.score=0}},V4=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,i=0,s=1,r=this._rear;for(;r!==-1;){let a=r===this._front?e:Math.pow(2,-s);if(e-=a,i+=this._memory[r].score*a,r===this._front)break;r=(this._capacity+r-1)%this._capacity,s++}return i<=.5}acceptStandardWheelEvent(e){if(hA){no(e.browserEvent);let i=BY();this.accept(Date.now(),e.deltaX*i,e.deltaY*i)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,i,s){let r=null,a=new ZVe(e,i,s);this._front===-1&&this._rear===-1?(this._memory[0]=a,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=a),a.score=this._computeScore(a,r)}_computeScore(e,i){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let s=.5;if((!this._isAlmostInt(e.deltaX)||!this._isAlmostInt(e.deltaY))&&(s+=.25),i){let r=Math.abs(e.deltaX),a=Math.abs(e.deltaY),n=Math.abs(i.deltaX),o=Math.abs(i.deltaY),l=Math.max(Math.min(r,n),1),c=Math.max(Math.min(a,o),1),u=Math.max(r,n),d=Math.max(a,o);u%l===0&&d%c===0&&(s-=.5)}return Math.min(Math.max(s,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};V4.INSTANCE=new V4;var WVe=V4,YVe=class extends mA{constructor(t,e,i){super(),this._onScroll=this._register(new Ke),this.onScroll=this._onScroll.event,e=e??{};let s,r=!i;i?s=i:(e.mouseWheelSmoothScroll=!1,s=new qY({forceIntegerValues:!0,smoothScrollDuration:0,scheduleAtNextAnimationFrame:n=>cA(no(t),n)})),this._options=GVe(e),this._scrollable=s,this._register(this._scrollable.onScroll(n=>{this._handleScroll(n),this._onScroll.fire(n)})),r&&this._register(this._scrollable);let a={handleMouseWheel:n=>this._handleMouseWheel(n),handleDragStart:()=>this._handleDragStart(),handleDragEnd:()=>this._handleDragEnd()};this._verticalScrollbar=this._register(new VVe(this._scrollable,this._options,a)),this._horizontalScrollbar=this._register(new qVe(this._scrollable,this._options,a)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(t),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=new zg(document.createElement("div")),this._leftShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=new zg(document.createElement("div")),this._topShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=new zg(document.createElement("div")),this._topLeftShadowDomNode.setClassName("xterm-shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode??this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this._onmouseover(this._listenOnDomNode,n=>this._handleMouseOver(n)),this._onmouseleave(this._listenOnDomNode,n=>this._handleMouseLeave(n)),this._hideTimeout=this._register(new gk),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=B0(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(t){this._scrollable.setScrollDimensions(t,!1)}setScrollPosition(t){t.reuseAnimation?this._scrollable.setScrollPositionSmooth(t,t.reuseAnimation):this._scrollable.setScrollPositionNow(t)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}updateClassName(t){this._options.className=t,Aa&&(this._options.className+=" xterm-mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(t){typeof t.handleMouseWheel<"u"&&(this._options.handleMouseWheel=t.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof t.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=t.mouseWheelScrollSensitivity),typeof t.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=t.fastScrollSensitivity),typeof t.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=t.scrollPredominantAxis),typeof t.horizontal<"u"&&(this._options.horizontal=t.horizontal),typeof t.vertical<"u"&&(this._options.vertical=t.vertical),typeof t.horizontalHasArrows<"u"&&(this._options.horizontalHasArrows=t.horizontalHasArrows),typeof t.verticalHasArrows<"u"&&(this._options.verticalHasArrows=t.verticalHasArrows),typeof t.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=t.horizontalScrollbarSize),typeof t.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=t.verticalScrollbarSize),typeof t.scrollByPage<"u"&&(this._options.scrollByPage=t.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}delegateScrollFromMouseWheelEvent(t){this._handleMouseWheel(new CM(t))}_setListeningToMouseWheel(t){if(this._mouseWheelToDispose.length>0!==t&&(this._mouseWheelToDispose=B0(this._mouseWheelToDispose),t)){let e=i=>{this._handleMouseWheel(new CM(i))};this._mouseWheelToDispose.push(dt(this._listenOnDomNode,tl.MOUSE_WHEEL,e,{passive:!1}))}}_handleMouseWheel(t){if(t.browserEvent?.defaultPrevented)return;let e=WVe.INSTANCE;e.acceptStandardWheelEvent(t);let i=!1;if(t.deltaY||t.deltaX){let r=t.deltaY*this._options.mouseWheelScrollSensitivity,a=t.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&a+r===0?a=r=0:Math.abs(r)>=Math.abs(a)?a=0:r=0),this._options.flipAxes&&([r,a]=[a,r]);let n=!Aa&&t.browserEvent&&t.browserEvent.shiftKey;(this._options.scrollYToX||n)&&!a&&(a=r,r=0),t.browserEvent&&t.browserEvent.altKey&&(a=a*this._options.fastScrollSensitivity,r=r*this._options.fastScrollSensitivity);let o=this._scrollable.getFutureScrollPosition(),l={};if(r){let c=50*r,u=o.scrollTop-(c<0?Math.floor(c):Math.ceil(c));this._verticalScrollbar.writeScrollPosition(l,u)}if(a){let c=50*a,u=o.scrollLeft-(c<0?Math.floor(c):Math.ceil(c));this._horizontalScrollbar.writeScrollPosition(l,u)}l=this._scrollable.validateScrollPosition(l),(o.scrollLeft!==l.scrollLeft||o.scrollTop!==l.scrollTop)&&(this._options.mouseWheelSmoothScroll&&e.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(l):this._scrollable.setScrollPositionNow(l),i=!0)}let s=i;!s&&this._options.alwaysConsumeMouseWheel&&(s=!0),!s&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(s=!0),s&&(t.preventDefault(),t.stopPropagation())}_handleScroll(t){this._shouldRender=this._horizontalScrollbar.handleScroll(t)||this._shouldRender,this._shouldRender=this._verticalScrollbar.handleScroll(t)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let t=this._scrollable.getCurrentScrollPosition(),e=t.scrollTop>0,i=t.scrollLeft>0,s=i?" xterm-shadow-left":"",r=e?" xterm-shadow-top":"",a=i||e?" xterm-shadow-top-left-corner":"";this._leftShadowDomNode.setClassName(`xterm-shadow${s}`),this._topShadowDomNode.setClassName(`xterm-shadow${r}`),this._topLeftShadowDomNode.setClassName(`xterm-shadow${a}${r}${s}`)}}_handleDragStart(){this._isDragging=!0,this._reveal()}_handleDragEnd(){this._isDragging=!1,this._hide()}_handleMouseLeave(t){this._mouseIsOver=!1,this._hide()}_handleMouseOver(t){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),500)}};function GVe(t){let e={lazyRender:typeof t.lazyRender<"u"?t.lazyRender:!1,className:typeof t.className<"u"?t.className:"",useShadows:typeof t.useShadows<"u"?t.useShadows:!0,handleMouseWheel:typeof t.handleMouseWheel<"u"?t.handleMouseWheel:!0,flipAxes:typeof t.flipAxes<"u"?t.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof t.consumeMouseWheelIfScrollbarIsNeeded<"u"?t.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof t.alwaysConsumeMouseWheel<"u"?t.alwaysConsumeMouseWheel:!1,scrollYToX:typeof t.scrollYToX<"u"?t.scrollYToX:!1,mouseWheelScrollSensitivity:typeof t.mouseWheelScrollSensitivity<"u"?t.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof t.fastScrollSensitivity<"u"?t.fastScrollSensitivity:5,scrollPredominantAxis:typeof t.scrollPredominantAxis<"u"?t.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof t.mouseWheelSmoothScroll<"u"?t.mouseWheelSmoothScroll:!0,listenOnDomNode:typeof t.listenOnDomNode<"u"?t.listenOnDomNode:null,horizontal:typeof t.horizontal<"u"?t.horizontal:1,horizontalScrollbarSize:typeof t.horizontalScrollbarSize<"u"?t.horizontalScrollbarSize:10,horizontalSliderSize:typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:0,horizontalHasArrows:typeof t.horizontalHasArrows<"u"?t.horizontalHasArrows:!1,vertical:typeof t.vertical<"u"?t.vertical:1,verticalScrollbarSize:typeof t.verticalScrollbarSize<"u"?t.verticalScrollbarSize:10,verticalHasArrows:typeof t.verticalHasArrows<"u"?t.verticalHasArrows:!1,verticalSliderSize:typeof t.verticalSliderSize<"u"?t.verticalSliderSize:0,scrollByPage:typeof t.scrollByPage<"u"?t.scrollByPage:!1};return e.horizontalSliderSize=typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:e.horizontalScrollbarSize,e.verticalSliderSize=typeof t.verticalSliderSize<"u"?t.verticalSliderSize:e.verticalScrollbarSize,Aa&&(e.className+=" xterm-mac"),e}var Z4=class extends Dt{constructor(t,e,i,s,r,a,n,o,l){super(),this._bufferService=i,this._coreService=r,this._optionsService=o,this._renderService=l,this._onRequestScrollLines=this._register(new Ke),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1,this._needsSyncOnRender=!1;let c=this._register(new qY({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:u=>cA(s.window,u)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new YVe(e,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,verticalHasArrows:this._optionsService.rawOptions.scrollbar?.showArrows??!1,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","scrollbar"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(a.onProtocolChange(u=>{this._scrollableElement.updateOptions({handleMouseWheel:!(u&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(dn.runAndSubscribe(n.onChangeColors,()=>{t.style.backgroundColor=n.colors.background.css,this._scrollableElement.getDomNode().style.backgroundColor=n.colors.background.css})),t.appendChild(this._scrollableElement.getDomNode()),this._register(pi(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=s.mainDocument.createElement("style"),e.appendChild(this._styleElement),this._register(pi(()=>this._styleElement.remove())),this._register(dn.runAndSubscribe(n.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider {",` background: ${n.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider:hover {",` background: ${n.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .xterm-scrollbar > .xterm-slider.xterm-active {",` background: ${n.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
@@ -376,7 +376,7 @@ ${s}`]}const i=[];for(const s of[!0,!1]){if((s?e.index:e.working)===" ")continue
376
376
  --- ${u.path}
377
377
  ${d}`;o+p.length>i||(o+=p.length,n.push(p))}const l=`${s.length}${r?"+":""} file${s.length===1&&!r?"":"s"}`;return(`Folder ${e}: ${l}, ${n.length} with their text below
378
378
 
379
- `+a+n.join("")).slice(0,i)}const fKe=5e3,pKe="Restored files to before “{message}”",jI=t=>{const e=t.text.replace(/\s+/g," ").trim();return{kind:"notice",text:pKe,values:{message:e.length>80?`${e.slice(0,79)}…`:e}}};class mKe{constructor(e,i,s){this.request=e,this.changed=i,this.messages=s}request;changed;messages;current;restoring=!1;refreshing=!1;stale=!1;async create(){let e;try{const i=await Promise.race([this.request("acp.checkpoint.create"),new Promise(s=>e=setTimeout(()=>s(void 0),fKe))]);this.current=i&&"tree"in i?i.tree:void 0}catch{this.current=void 0}finally{clearTimeout(e)}return this.current}differs(e){return!!e.checkpoint&&!!this.current&&e.checkpoint!==this.current}refresh(){if(this.messages().some(e=>e.checkpoint)){if(this.refreshing){this.stale=!0;return}this.refreshing=!0,this.create().finally(()=>{this.refreshing=!1,this.changed(),this.stale&&(this.stale=!1,this.refresh())})}}async restore(e,i){if(!this.restoring){this.restoring=!0;try{const s=await this.request("acp.checkpoint.diff",{tree:e});if("unavailable"in s)throw new Error("This checkpoint is no longer available");this.current=s.tree;const r=s.changes.map(n=>n.path),a=r.find(i);if(a)throw new Error(`Save or revert your unsaved edits in ${a} before restoring this checkpoint.`);return r.length&&await this.request("acp.checkpoint.restore",{tree:e,paths:r}),this.current=e,r}finally{this.restoring=!1}}}}function gKe(t,e){const i=t.flatMap(r=>r.kind==="message"&&r.message.role==="user"&&r.message.checkpoint?[r.message]:[]);let s=0;for(const r of e){if(r.kind!=="message"||r.message.role!=="user")continue;const a=i.findIndex((n,o)=>o>=s&&n.text.trim()===r.message.text.trim());a<0||(r.message.checkpoint??=i[a].checkpoint,s=a+1)}}const OKe="Forked from “{title}”. The agent keeps the earlier context.",zI={name:"undo",description:"Undo the agent's edits from the latest turn"},qG="User rejected the file change",yKe=(t,e)=>(t===Wi||t===G0)&&["accept-edits","full-auto"].includes(e?._meta?.oxbit?.mode),bKe=t=>["ENOENT","NOT_FOUND"].includes(t?.code)||t instanceof DOMException&&t.name==="NotFoundError"||t instanceof Error&&/^File not found:/.test(t.message);class wKe{constructor(e){this.options=e,this.history=new $Ye(e.workbench.persistence,`acp-history:${e.filesystem.id}`),this.attention=new QYe(e),this.checkpoints=new mKe(async(r,a)=>this.request(r,a),this.changed,()=>this.messages),this.history.ready.then(()=>{for(const r of this.history.entries)io(r.provider)||P_(r.provider,r.name);this.changed(),this.resumeInApp()});const i=e.runtime;if(!i)return;const s=(r,a)=>{this.eventHandlers.set(r,a),this.subscriptions.push(i.subscribe(r,n=>{if(this.attachBuffer&&r!=="connection.change"&&r!=="workspace.trust"){this.attachBuffer.push({name:r,params:n});return}this.deliver(r,n)}))};s("acp.turnStarted",({messageId:r,text:a,context:n})=>{if(r){if(this.activeTurnId=r,!this.messages.some(o=>o.id===r)){const o={id:r,role:"user",text:a,context:n};this.messages.push(o),this.activity.push({kind:"message",message:o}),this.replaying||this.checkpoints.create().then(l=>{l&&(o.checkpoint=l,this.changed())})}this.title==="New conversation"&&(this.title=a.slice(0,100)),this.busy=!0,this.cancelling=!1,this.status="Working…"}}),s("acp.turnEnded",({stopReason:r,error:a})=>{this.activeTurnId=void 0,this.busy=this.cancelling=!1,this.rootRequestGeneration++,this.requests=this.requests.filter(n=>this.isChildRequest(n)),this.status=a?"Turn failed":r==="cancelled"?"Stopped":"Ready",a&&(this.error=dI(this.connection?.provider,String(a))),!this.replaying&&r!=="cancelled"&&this.attention.turnEnded(this.title,!!a),!this.replaying&&!a&&r!=="cancelled"&&this.nameConversation()}),s("acp.queue",({queue:r,paused:a})=>{this.queueRevision++,this.queue=r??[],this.queuePaused=a===!0}),s("acp.attachedElsewhere",()=>this.clearConnection("Opened in another window",!0)),s("acp.update",({update:r,sessionId:a,rootSessionId:n})=>{(!a||a===(n??this.connection?.sessionId))&&this.update(r)}),s("acp.subagent",r=>{if(!this.sessionStarting&&r.rootSessionId!==this.connection?.sessionId)return;const a=r.removedIds.filter(o=>this.subagents.get(o)?.toolCallIds.some(l=>r.subagent.toolCallIds.includes(l))),n=new Set;this.activity=this.activity.flatMap(o=>{if(o.kind!=="subagent")return[o];const l=r.removedIds.includes(o.id)?a.includes(o.id)?r.subagent.id:void 0:o.id;return!l||n.has(l)?[]:(n.add(l),[{kind:"subagent",id:l}])}),this.selectedSubagent&&a.includes(this.selectedSubagent)&&(this.selectedSubagent=r.subagent.id);for(const o of this.requests)o.subagentId&&a.includes(o.subagentId)&&(o.subagentId=r.subagent.id);for(const o of r.removedIds)this.subagents.delete(o);this.subagents.set(r.subagent.id,r.subagent),this.activeSubagentCount=r.activeCount,this.subagentsTruncated=r.truncated,!r.subagent.parentId&&!this.activity.some(o=>o.kind==="subagent"&&o.id===r.subagent.id)&&this.activity.push({kind:"subagent",id:r.subagent.id}),r.subagent.phase==="awaiting_input"&&(this.subagentsOpen=!0,this.expandAncestors(r.subagent.id)),this.selectedSubagent&&!this.subagents.has(this.selectedSubagent)&&(this.selectedSubagent=void 0)}),s("acp.log",({text:r})=>{this.logs=(this.logs+r).slice(-65536)}),s("acp.terminal",r=>{if(!r.subagentId)for(this.terminals.set(r.terminalId,r);this.terminals.size>32;)this.terminals.delete(this.terminals.keys().next().value)}),s("acp.request",r=>{this.clientRequest(r)}),s("acp.cancelled",()=>{this.rootRequestGeneration++,this.requests=this.requests.filter(r=>this.isChildRequest(r))}),s("acp.requestsExpired",({requestIds:r})=>{for(const a of r){const n=this.pendingClientRequests.get(a);n&&(n.expired=!0)}this.requests=this.requests.filter(a=>!r.includes(a.requestId))}),s("acp.exit",({reason:r,unexpected:a})=>{const n=a===!0?this.reconnectTarget():void 0;this.clearConnection(r),n&&this.action(()=>this.reconnect(n,r))}),s("connection.change",({state:r})=>{if(r==="connected"){const o=this.reattachOnReconnect;this.reattachOnReconnect=void 0,o&&!this.connection&&this.activeConversation?.id===o.conversationId&&(o.conversationId&&this.threadConversations.set(o.id,o.conversationId),this.attachLive(o.id).catch(()=>this.changed()));return}const a=this.local?void 0:this.connection?.id,n=this.activeConversation?.id;this.liveSessions=[],this.clearConnection("Runtime disconnected. Open Runtime sessions after reconnecting to reattach.",!0),a&&(this.reattachOnReconnect={id:a,conversationId:n})}),s("workspace.trust",({trusted:r})=>{r||this.clearConnection("Workspace trust was revoked")})}options;listeners=new Set;revision=0;subscriptions=[];disposed=!1;requestGeneration=0;rootRequestGeneration=0;pendingClientRequests=new Map;connectionGeneration=0;sessionStarting=!1;startAbort;fileActions=new Set;historyGeneration=0;historyTimer;eventHandlers=new Map;attachBuffer;lastSequence=0;queueRevision=0;activeTurnId;activeConversation;replaying=!1;threadConversations=new Map;reattachOnReconnect;reconnects=[];checkpointing=!1;autoApplyValue;titleRequested=!1;agentTitled=!1;attention;checkpoints;history;activity=[];subagents=new Map;activeSubagentCount=0;subagentsTruncated=!1;selectedSubagent;expandedSubagents=new Set;subagentsOpen=!1;title="New conversation";archived=!1;discovering=!1;sessions=[];nextCursor;changes=[];connection;launch={provider:"codex"};selection;registry;registryLoading=!1;busyValue=!1;turnStartedAt;get busy(){return this.busyValue}set busy(e){e!==this.busyValue&&(this.turnStartedAt=e?Date.now():void 0),this.busyValue=e}connecting=!1;cancelling=!1;updatingSettings=!1;error="";status="Disconnected";draft="";messages=[];requests=[];tools=new Map;terminals=new Map;commands=[];logs="";context=[];queue=[];queuePaused=!1;liveSessions=[];replayTruncated=!1;usage;deliver(e,i){if(!this.disposed&&!(i.id&&i.id!==this.connection?.id)){if(typeof i.seq=="number"){if(i.seq<=this.lastSequence)return;this.lastSequence=i.seq}this.eventHandlers.get(e)?.(i),this.changed()}}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});snapshot=()=>this.revision;changed=()=>{if(this.revision++,!this.disposed){const e=this.requests.length+NYe(this.liveSessions,this.connection?.id);this.attention.sync(e,()=>({agent:R_(this.launch),title:this.title,connected:!!this.connection,busy:this.busy,startedAt:this.turnStartedAt,pending:e,tool:this.latestToolTitle()}))}for(const e of this.listeners)e();!this.disposed&&this.activeConversation&&!this.archived&&!this.connecting&&(clearTimeout(this.historyTimer),this.historyTimer=setTimeout(()=>{this.saveConversation()},300))};async saveConversation(){if(clearTimeout(this.historyTimer),!this.activeConversation||this.archived)return;const e=JSON.parse(JSON.stringify({...this.activeConversation,title:this.title,updatedAt:new Date().toISOString(),draft:this.draft,context:this.context.filter(s=>s.kind!=="image"),activity:this.activity,tools:[...this.tools],subagents:[...this.subagents.values()],subagentsTruncated:this.subagentsTruncated,autoApplyEdits:this.autoApply,inAppAgent:this.inAppSession})),i=this.historyGeneration;await this.history.ready,i===this.historyGeneration&&await this.history.save(e)}get inAppSession(){const e=this.connection?.sessionId;return this.local&&this.connection?.provider===Wi&&!this.sessionStarting&&!!e&&e===this.activeConversation?.sessionId}resetConversation(){this.messages=[],this.activity=[],this.subagents.clear(),this.activeSubagentCount=0,this.subagentsTruncated=!1,this.selectedSubagent=void 0,this.expandedSubagents.clear(),this.subagentsOpen=!1,this.tools.clear(),this.terminals.clear(),this.requests=[],this.commands=[],this.changes=[],this.title="New conversation",this.draft="",this.context=[],this.queue=[],this.queuePaused=!1,this.replayTruncated=!1,this.usage=void 0,this.lastSequence=0,this.queueRevision=0,this.activeTurnId=void 0,this.archived=!1,this.autoApplyValue=void 0,this.titleRequested=this.agentTitled=!1}get autoApply(){return this.autoApplyValue??this.options.kernel.configuration?.get("agentACP.autoApplyEdits")===!0}setAutoApply(e){this.autoApplyValue=e,this.changed()}get documents(){return this.options.documents}clearConnection(e,i=!1){this.busy&&this.activity.push({kind:"notice",text:i?"The runtime kept this turn. Reattach to follow it.":"The agent turn ended."});for(const s of this.subagents.values())!s.historical&&["pending","running","unknown"].includes(s.state)&&(s.state="disconnected",s.phase="unknown");this.activeSubagentCount=0,this.connectionGeneration++,this.requestGeneration++,this.startAbort?.abort(),this.startAbort=void 0,this.connection=void 0,this.sessionStarting=!1,this.busy=this.connecting=this.cancelling=this.updatingSettings=!1,this.requests=[],this.queue=[],this.queuePaused=!1,this.activeTurnId=void 0,this.status=e,this.saveConversation()}reconnectTarget(e=!!this.connection?.capabilities?.loadSession){const i=this.activeConversation;if(this.archived||!i?.sessionId||!e)return;const s=Date.now();if(this.reconnects=this.reconnects.filter(a=>s-a<6e4),this.reconnects.length>=3)return;this.reconnects.push(s);const r=this.busy?this.messages.findLast(a=>a.role==="user")?.text:void 0;return{id:i.id,launch:this.launch,prompt:r}}async reconnect(e,i){await this.saveConversation();const s=this.history.entries.find(r=>r.id===e.id);!s||this.disposed||this.connection||this.connecting||this.activeConversation?.id!==e.id||(this.status="Reconnecting…",this.changed(),await this.connect(e.launch,s),!(this.activeConversation?.id!==e.id||!this.connection)&&(this.activity.push({kind:"notice",text:`${i}. The agent restarted and loaded this conversation.`}),e.prompt&&!this.draft.trim()&&this.messages.findLast(r=>r.role==="user")?.text!==e.prompt&&(this.draft=e.prompt),this.saveConversation()))}async resumeInApp(){const e=this.history.entries[0];if(e?.inAppAgent!==!0||e.provider!==Wi||!this.localRuntime)return;for(let s=0;!this.local;s+=100){if(s>=1e4||this.disposed)return;await new Promise(r=>setTimeout(r,100))}if(this.disposed||this.connection||this.connecting||this.activeConversation||this.history.entries[0]?.id!==e.id)return;this.restoreSnapshot(e),this.launch={provider:Wi};const i=this.reconnectTarget(!0);i&&(await this.action(()=>this.reconnect(i,"The app reloaded")),await this.keepReadOnly(e))}async keepReadOnly(e){this.disposed||this.activeConversation?.id!==e.id||this.connection?.sessionId||(this.connection&&await this.disconnect().catch(()=>{}),this.restoreSnapshot(e),this.archived=!0,this.status="Conversation could not be restored",this.changed())}request(e,i={}){if(!this.options.runtime?.connected)throw new Error("Connect to a runtime workspace first");return this.options.runtime.request(e,i)}async action(e){this.error="",this.changed();try{await e()}catch(i){this.disposed||(this.error=dI(this.connection?.provider??this.launch.provider,i))}finally{this.changed()}}async connect(e,i){if(this.disposed||this.connecting||this.connection)return;const s=++this.connectionGeneration;this.connecting=!0,this.launch=e,this.status="Connecting…",this.logs="",this.changed();const r=new AbortController;this.startAbort=r;try{if(!this.options.runtime||this.localRuntime&&!this.local)throw new Error("Connect to a runtime workspace first");const a=await this.options.runtime.request("acp.start",{...e,clientCapabilities:{editorTools:!0}},{signal:r.signal});if(this.disposed||s!==this.connectionGeneration){await this.request("acp.stop",{id:a.id}).catch(()=>{});return}if(this.connection=a,P_(a.provider,a.name??e.name),i&&i.root!==a.root)throw new Error("This conversation belongs to another workspace");this.status="Connected",i?await this.restoreConversation(i):await this.newSession()}catch(a){if(s!==this.connectionGeneration)return;const n=!this.connection&&DYe(a);throw this.status=this.connection?"Sign in or retry starting the conversation":n?bA:"Connection failed",n&&this.listLiveSessions().catch(()=>{}),this.connection?a:PYe(a,R_(e))}finally{s===this.connectionGeneration&&(this.startAbort=void 0,this.connecting=!1,this.changed())}}claudePlan=!1;setClaudePlan(e){this.claudePlan=e,this.changed()}async connectSelected(){if(this.local&&this.claudePlan){await this.options.kernel.commands.execute("workspace.runtime");return}await this.connect(E_(this.chosen,this.options.kernel.configuration))}get localRuntime(){return this.options.runtime?.local===!0}get local(){return this.localRuntime&&!!this.options.runtime?.connected}get chosen(){if(this.local)return{provider:Wi};const e=this.selection??{provider:this.options.kernel.configuration?.get("agentACP.provider")||"codex"};return e.provider===Wi?{provider:"codex"}:e}get displayName(){return this.connection?il(this.connection.provider,this.connection):R_(E_(this.chosen,this.options.kernel.configuration))}async select(e){const i=this.options.kernel.configuration;e.provider===Ei&&(await i.set(ys(Ei,"name"),e.name??"","user"),await i.set(ys(Ei,"command"),e.command??"","user"),await i.set(ys(Ei,"args"),JSON.stringify(e.args??[]),"user")),e.provider!==Wi&&await i.set("agentACP.provider",e.provider,"user"),this.selection=e,this.changed()}async loadRegistry(){if(!this.registryLoading){this.registryLoading=!0,this.changed();try{const e=await this.request("acp.registry");for(const i of e.agents)CYe(i.id,i.name);this.registry=e}finally{this.registryLoading=!1,this.changed()}}}markSeen(){this.attention.seen(),this.changed()}savedLaunch(e){if(e.provider===Ei)return{name:e.name,command:e.command,args:e.args};if(!io(e.provider)&&e.provider!==Wi)return{registry:e.registry??{id:e.provider}}}async call(e,i={}){if(!this.connection)throw new Error("Connect an agent first");return this.request("acp.call",{id:this.connection.id,method:e,params:i})}get canForkSession(){return!!this.connection?.sessionId&&!!this.connection.capabilities?.sessionCapabilities?.fork&&this.messages.length>0&&!this.busy&&!this.connecting&&!this.sessionStarting&&!this.updatingSettings&&!this.discovering&&!this.requests.length&&!this.queue.length&&!this.activeSubagentCount}async forkSession(){try{await this.newSession(!0)}catch(e){throw e instanceof Error&&e.message==="Unsupported ACP client method"?new Error("Update the runtime to fork conversations"):e}}async newSession(e=!1){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(!this.connection||this.busy||this.updatingSettings||this.discovering||this.sessionStarting)return;const s=this.connectionGeneration;this.sessionStarting=!0,this.connecting=!0;const r=this.draft,a=this.context;let n;this.changed();try{if(await this.saveConversation(),n=this.history.entries.find(l=>l.id===this.activeConversation?.id),s!==this.connectionGeneration)return;this.resetConversation();const o=await this.call(e?"session/fork":"session/new");s===this.connectionGeneration&&(e&&n&&(this.restoreSnapshot(n),this.draft="",this.context=[],this.activity.push({kind:"notice",text:OKe,values:{title:n.title}})),this.connection=o,this.activeConversation={id:crypto.randomUUID(),sessionId:o.sessionId,root:o.root,provider:o.provider,name:il(o.provider,o),launch:this.savedLaunch(this.launch)},this.autoApplyValue=this.autoApply,this.status="Ready")}catch(o){if(s!==this.connectionGeneration)return;throw n?this.restoreSnapshot(n):(this.draft=r,this.context=a),this.status="Sign in or retry starting the conversation",o}finally{s===this.connectionGeneration&&(this.sessionStarting=!1,this.connecting=!1,this.changed())}}async authenticate(e){if(this.connecting||!this.connection)return;const i=this.connectionGeneration;this.connecting=!0,this.changed();try{if(await this.call("authenticate",{methodId:e}),i!==this.connectionGeneration)return;this.connection?.sessionId||await this.newSession()}catch(s){if(i===this.connectionGeneration)throw s}finally{i===this.connectionGeneration&&(this.connecting=!1,this.changed())}}async disconnect(){const e=this.connection,i=this.saveConversation();this.clearConnection("Disconnected");const s=this.connectionGeneration;this.changed();try{e&&this.options.runtime?.connected&&await this.request("acp.stop",{id:e.id}),await i}catch(r){if(s===this.connectionGeneration)throw r}}async detach(){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");const e=this.connection;if(!e||this.connecting||this.sessionStarting||this.updatingSettings||this.discovering)return;const i=this.options.runtime?.connected?this.request("acp.detach").catch(()=>{}):void 0;this.activeConversation&&this.threadConversations.set(e.id,this.activeConversation.id),this.clearConnection("Disconnected",!0),await this.saveConversation(),this.activeConversation=void 0,this.resetConversation(),this.changed(),await i}async listLiveSessions(){if(!this.options.runtime?.connected||this.local)return;const e=await this.request("acp.list");JSON.stringify(e.sessions)!==JSON.stringify(this.liveSessions)&&(this.liveSessions=e.sessions,this.changed())}async attachLive(e){if(this.connection?.id===e)return;await this.saveConversation(),this.connection&&this.activeConversation&&this.threadConversations.set(this.connection.id,this.activeConversation.id);const i=++this.connectionGeneration;this.attachBuffer=[];try{const s=await this.request("acp.attach",{id:e,clientCapabilities:{editorTools:!0}});if(i!==this.connectionGeneration||this.disposed||!this.options.runtime?.connected)return;const r=this.draft,a=this.context;this.resetConversation(),this.draft=r,this.context=a,this.connection=s.connection,this.launch={provider:s.connection.provider,name:s.connection.name},P_(s.connection.provider,s.connection.name),this.activeConversation={id:this.threadConversations.get(e)??crypto.randomUUID(),sessionId:s.connection.sessionId??"",root:s.connection.root,provider:s.connection.provider,name:il(s.connection.provider,s.connection),launch:this.savedLaunch(this.launch)};const n=this.history.entries.find(o=>o.id===this.activeConversation?.id);this.autoApplyValue=n?n.autoApplyEdits===!0:this.autoApply,this.replayTruncated=s.truncated,this.status=s.busy?"Working…":"Ready",this.replaying=!0;try{for(const o of s.events)this.deliver(o.name,o.params)}finally{this.replaying=!1}n&&!this.agentTitled&&n.title!=="New conversation"&&(this.title=n.title),this.lastSequence=Math.max(this.lastSequence,s.sequence),this.queue=s.queue,this.queuePaused=s.queuePaused,this.busy=s.busy;for(const o of s.requests)this.clientRequest(o);for(const o of this.attachBuffer??[])this.deliver(o.name,o.params);this.changed()}catch(s){for(const r of this.attachBuffer??[])this.deliver(r.name,r.params);throw s}finally{this.attachBuffer=void 0}}async discover(e=!1){if(!this.connection||this.busy||this.connecting||this.discovering||this.updatingSettings)return;const i=this.connectionGeneration;this.discovering=!0,this.changed();try{const s=await this.call("session/list",e&&this.nextCursor?{cursor:this.nextCursor}:{});if(i!==this.connectionGeneration)return;this.sessions=[...new Map([...e?this.sessions:[],...s.sessions].map(r=>[r.sessionId,r])).values()],this.nextCursor=s.nextCursor===this.nextCursor&&e?void 0:s.nextCursor}finally{i===this.connectionGeneration&&(this.discovering=!1,this.changed())}}async viewConversation(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");this.busy||this.connecting||this.updatingSettings||this.discovering||(await this.disconnect(),this.restoreSnapshot(e),this.archived=!0,this.status="Saved conversation",this.changed())}async forgetConversation(e){this.historyGeneration++,this.activeConversation?.id===e&&(clearTimeout(this.historyTimer),this.activeConversation=void 0),await this.history.ready,await this.history.remove(e)}restoreSnapshot(e){this.resetConversation();const i=JSON.parse(JSON.stringify(e));this.activeConversation={id:i.id,sessionId:i.sessionId,root:i.root,provider:i.provider,name:i.name,launch:i.launch},this.title=i.title,this.titleRequested=!0,this.autoApplyValue=i.autoApplyEdits===!0,this.draft=i.draft,this.context=i.context,this.activity=i.activity,this.tools=new Map(i.tools),this.subagents=new Map((i.subagents??[]).map(s=>[s.id,{...s,historical:!0}])),this.subagentsTruncated=i.subagentsTruncated??!1,this.messages=this.activity.flatMap(s=>s.kind==="message"?[s.message]:[])}async resumeSaved(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(this.busy||this.connecting||this.updatingSettings||this.discovering)return;const i=e.provider!==Ei||this.launch.command===e.launch?.command&&JSON.stringify(this.launch.args??[])===JSON.stringify(e.launch?.args??[]);if(this.connection?.provider===e.provider&&this.connection.root===e.root&&i)return this.restoreConversation(e);await this.disconnect();const s=e.launch,r=e.provider===Ei?{provider:e.provider,name:s?.name??e.name,command:s?.command,args:s?.args}:io(e.provider)?{provider:e.provider}:{provider:e.provider,registry:s?.registry??{id:e.provider}};await this.connect(E_(r,this.options.kernel.configuration),e)}async restoreConversation(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(!this.connection||this.busy||this.updatingSettings||this.discovering||this.sessionStarting)return;if(e.root!==this.connection.root||e.provider!==this.connection.provider)throw new Error("This conversation belongs to another workspace or provider");const i=this.connection.capabilities,s=i?.loadSession?"session/load":i?.sessionCapabilities?.resume?"session/resume":void 0;if(!s)throw new Error("This agent cannot resume conversations. You can still read the saved transcript.");this.sessionStarting=this.connecting=!0;const r=this.connectionGeneration;if(await this.saveConversation(),r!==this.connectionGeneration)return;const a=this.activeConversation&&this.history.entries.find(n=>n.id===this.activeConversation.id);this.restoreSnapshot(e),s==="session/load"&&(this.activity=[],this.messages=[],this.tools.clear()),this.sessionStarting=this.connecting=!0,this.status="Restoring conversation…",this.changed();try{const n=await this.call(s,{sessionId:e.sessionId});if(r!==this.connectionGeneration)return;s==="session/load"&&gKe(e.activity,this.activity),this.connection=n,this.status="Ready",this.archived=!1}catch(n){if(r!==this.connectionGeneration)return;throw a?this.restoreSnapshot(a):(this.restoreSnapshot(e),this.archived=!0),this.status="Conversation could not be restored",n}finally{r===this.connectionGeneration&&(this.sessionStarting=this.connecting=!1,this.changed())}}importConversation(e){const i=this.connection,s=this.history.entries.find(r=>r.sessionId===e.sessionId&&r.provider===i.provider&&r.root===e.cwd);return s?this.restoreConversation(s):this.restoreConversation({id:crypto.randomUUID(),...e,root:e.cwd,provider:i.provider,title:e.title||"Saved conversation",updatedAt:e.updatedAt||new Date().toISOString(),draft:"",context:[],activity:[],tools:[]})}async setSessionControl(e,i){if(this.busy||this.connecting||this.updatingSettings||this.discovering||this.archived)return;const s=this.connection;if(!s?.sessionId)throw new Error("Start a conversation first");const r=dG(s).find(n=>n.id===e.id&&n.method===e.method);if(!r?.options.some(n=>n.value===i))throw new Error("This agent setting is no longer available");if(r.value===i)return;const a=this.connectionGeneration;this.updatingSettings=!0,this.changed();try{const n=e.method==="session/set_config_option"?{configId:e.id,value:i}:e.method==="session/set_mode"?{modeId:i}:{modelId:i},o=await this.call(e.method,n);if(a!==this.connectionGeneration)return;if(o?.configOptions)s.configOptions=o.configOptions;else if(e.method==="session/set_config_option"){const l=s.configOptions?.find(c=>c.id===e.id);l&&(l.currentValue=i)}e.method==="session/set_mode"&&s.modes&&(s.modes.currentModeId=i),e.method==="session/set_model"&&s.models&&(s.models.currentModelId=i)}catch(n){if(a===this.connectionGeneration)throw n}finally{a===this.connectionGeneration&&(this.updatingSettings=!1,this.changed())}}attach(e=!1){const i=this.options.workbench.activePath();if(!i)throw new Error("Open a file to attach context");const s=this.documents.get(i);if(!s)throw new Error("The active file is unavailable");const a=this.options.workbench.activeEditor()?.state?.selection?.main;if(e&&(!a||a.empty))throw new Error("Select text in the editor first");const n=e?s.text.toString().slice(a.from,a.to):s.text.toString();if(n.length>2e5)throw new Error("Select a smaller portion of this file (maximum 200,000 characters)");if(this.context.length>=8)throw new Error("Attach up to eight files or selections per message");const o=e?s.text.toString().slice(0,a.from).split(`
379
+ `+a+n.join("")).slice(0,i)}const fKe=5e3,pKe="Restored files to before “{message}”",jI=t=>{const e=t.text.replace(/\s+/g," ").trim();return{kind:"notice",text:pKe,values:{message:e.length>80?`${e.slice(0,79)}…`:e}}};class mKe{constructor(e,i,s){this.request=e,this.changed=i,this.messages=s}request;changed;messages;current;restoring=!1;refreshing=!1;stale=!1;async create(){let e;try{const i=await Promise.race([this.request("acp.checkpoint.create"),new Promise(s=>e=setTimeout(()=>s(void 0),fKe))]);this.current=i&&"tree"in i?i.tree:void 0}catch{this.current=void 0}finally{clearTimeout(e)}return this.current}differs(e){return!!e.checkpoint&&!!this.current&&e.checkpoint!==this.current}refresh(){if(this.messages().some(e=>e.checkpoint)){if(this.refreshing){this.stale=!0;return}this.refreshing=!0,this.create().finally(()=>{this.refreshing=!1,this.changed(),this.stale&&(this.stale=!1,this.refresh())})}}async restore(e,i){if(!this.restoring){this.restoring=!0;try{const s=await this.request("acp.checkpoint.diff",{tree:e});if("unavailable"in s)throw new Error("This checkpoint is no longer available");this.current=s.tree;const r=s.changes.map(n=>n.path),a=r.find(i);if(a)throw new Error(`Save or revert your unsaved edits in ${a} before restoring this checkpoint.`);return r.length&&await this.request("acp.checkpoint.restore",{tree:e,paths:r}),this.current=e,r}finally{this.restoring=!1}}}}function gKe(t,e){const i=t.flatMap(r=>r.kind==="message"&&r.message.role==="user"&&r.message.checkpoint?[r.message]:[]);let s=0;for(const r of e){if(r.kind!=="message"||r.message.role!=="user")continue;const a=i.findIndex((n,o)=>o>=s&&n.text.trim()===r.message.text.trim());a<0||(r.message.checkpoint??=i[a].checkpoint,s=a+1)}}const OKe="Forked from “{title}”. The agent keeps the earlier context.",zI={name:"undo",description:"Undo the agent's edits from the latest turn"},qG="User rejected the file change",yKe=(t,e)=>(t===Wi||t===G0)&&["accept-edits","full-auto"].includes(e?._meta?.oxbit?.mode),bKe=t=>["ENOENT","NOT_FOUND"].includes(t?.code)||t instanceof DOMException&&t.name==="NotFoundError"||t instanceof Error&&/^File not found:/.test(t.message);class wKe{constructor(e){this.options=e,this.history=new $Ye(e.workbench.persistence,`acp-history:${e.filesystem.id}`),this.attention=new QYe(e),this.checkpoints=new mKe(async(r,a)=>this.request(r,a),this.changed,()=>this.messages),this.history.ready.then(()=>{for(const r of this.history.entries)io(r.provider)||P_(r.provider,r.name);this.changed(),this.resumeInApp()});const i=e.runtime;if(!i)return;const s=(r,a)=>{this.eventHandlers.set(r,a),this.subscriptions.push(i.subscribe(r,n=>{if(this.attachBuffer&&r!=="connection.change"&&r!=="workspace.trust"){this.attachBuffer.push({name:r,params:n});return}this.deliver(r,n)}))};s("acp.turnStarted",({messageId:r,text:a,context:n})=>{if(r){if(this.activeTurnId=r,!this.messages.some(o=>o.id===r)){const o={id:r,role:"user",text:a,context:n};this.messages.push(o),this.activity.push({kind:"message",message:o}),this.replaying||this.checkpoints.create().then(l=>{l&&(o.checkpoint=l,this.changed())})}this.title==="New conversation"&&(this.title=a.slice(0,100)),this.busy=!0,this.cancelling=!1,this.status="Working…"}}),s("acp.turnEnded",({stopReason:r,error:a})=>{this.activeTurnId=void 0,this.busy=this.cancelling=!1,this.rootRequestGeneration++,this.requests=this.requests.filter(n=>this.isChildRequest(n)),this.status=a?"Turn failed":r==="cancelled"?"Stopped":"Ready",a&&(this.error=dI(this.connection?.provider,String(a))),!this.replaying&&r!=="cancelled"&&this.attention.turnEnded(this.title,!!a),!this.replaying&&!a&&r!=="cancelled"&&this.nameConversation()}),s("acp.queue",({queue:r,paused:a})=>{this.queueRevision++,this.queue=r??[],this.queuePaused=a===!0}),s("acp.attachedElsewhere",()=>this.clearConnection("Opened in another window",!0)),s("acp.update",({update:r,sessionId:a,rootSessionId:n})=>{(!a||a===(n??this.connection?.sessionId))&&this.update(r)}),s("acp.subagent",r=>{if(!this.sessionStarting&&r.rootSessionId!==this.connection?.sessionId)return;const a=r.removedIds.filter(o=>this.subagents.get(o)?.toolCallIds.some(l=>r.subagent.toolCallIds.includes(l))),n=new Set;this.activity=this.activity.flatMap(o=>{if(o.kind!=="subagent")return[o];const l=r.removedIds.includes(o.id)?a.includes(o.id)?r.subagent.id:void 0:o.id;return!l||n.has(l)?[]:(n.add(l),[{kind:"subagent",id:l}])}),this.selectedSubagent&&a.includes(this.selectedSubagent)&&(this.selectedSubagent=r.subagent.id);for(const o of this.requests)o.subagentId&&a.includes(o.subagentId)&&(o.subagentId=r.subagent.id);for(const o of r.removedIds)this.subagents.delete(o);this.subagents.set(r.subagent.id,r.subagent),this.activeSubagentCount=r.activeCount,this.subagentsTruncated=r.truncated,!r.subagent.parentId&&!this.activity.some(o=>o.kind==="subagent"&&o.id===r.subagent.id)&&this.activity.push({kind:"subagent",id:r.subagent.id}),r.subagent.phase==="awaiting_input"&&(this.subagentsOpen=!0,this.expandAncestors(r.subagent.id)),this.selectedSubagent&&!this.subagents.has(this.selectedSubagent)&&(this.selectedSubagent=void 0)}),s("acp.log",({text:r})=>{this.logs=(this.logs+r).slice(-65536)}),s("acp.terminal",r=>{if(!r.subagentId)for(this.terminals.set(r.terminalId,r);this.terminals.size>32;)this.terminals.delete(this.terminals.keys().next().value)}),s("acp.request",r=>{this.clientRequest(r)}),s("acp.cancelled",()=>{this.rootRequestGeneration++,this.requests=this.requests.filter(r=>this.isChildRequest(r))}),s("acp.requestsExpired",({requestIds:r})=>{for(const a of r){const n=this.pendingClientRequests.get(a);n&&(n.expired=!0)}this.requests=this.requests.filter(a=>!r.includes(a.requestId))}),s("acp.exit",({reason:r,unexpected:a})=>{const n=a===!0?this.reconnectTarget():void 0;this.clearConnection(r),n&&this.action(()=>this.reconnect(n,r))}),s("connection.change",({state:r})=>{if(r==="connected"){const o=this.reattachOnReconnect;this.reattachOnReconnect=void 0,o&&!this.connection&&this.activeConversation?.id===o.conversationId&&(o.conversationId&&this.threadConversations.set(o.id,o.conversationId),this.attachLive(o.id).catch(()=>this.changed()));return}const a=this.local?void 0:this.connection?.id,n=this.activeConversation?.id;this.liveSessions=[],this.clearConnection("Runtime disconnected. Open Runtime sessions after reconnecting to reattach.",!0),a&&(this.reattachOnReconnect={id:a,conversationId:n})}),s("workspace.trust",({trusted:r})=>{r||this.clearConnection("Workspace trust was revoked")})}options;listeners=new Set;revision=0;subscriptions=[];disposed=!1;requestGeneration=0;rootRequestGeneration=0;pendingClientRequests=new Map;connectionGeneration=0;sessionStarting=!1;startAbort;fileActions=new Set;historyGeneration=0;historyTimer;eventHandlers=new Map;attachBuffer;lastSequence=0;queueRevision=0;activeTurnId;activeConversation;replaying=!1;threadConversations=new Map;reattachOnReconnect;reconnects=[];checkpointing=!1;autoApplyValue;titleRequested=!1;agentTitled=!1;attention;checkpoints;history;activity=[];subagents=new Map;activeSubagentCount=0;subagentsTruncated=!1;selectedSubagent;expandedSubagents=new Set;subagentsOpen=!1;title="New conversation";archived=!1;discovering=!1;sessions=[];nextCursor;changes=[];connection;launch={provider:"codex"};selection;registry;registryLoading=!1;busyValue=!1;turnStartedAt;get busy(){return this.busyValue}set busy(e){e!==this.busyValue&&(this.turnStartedAt=e?Date.now():void 0),this.busyValue=e}connecting=!1;cancelling=!1;updatingSettings=!1;error="";status="Disconnected";draft="";messages=[];requests=[];tools=new Map;terminals=new Map;commands=[];logs="";context=[];queue=[];queuePaused=!1;liveSessions=[];replayTruncated=!1;usage;deliver(e,i){if(!this.disposed&&!(i.id&&i.id!==this.connection?.id)){if(typeof i.seq=="number"){if(i.seq<=this.lastSequence)return;this.lastSequence=i.seq}this.eventHandlers.get(e)?.(i),this.changed()}}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});snapshot=()=>this.revision;changed=()=>{if(this.revision++,!this.disposed){const e=this.requests.length+NYe(this.liveSessions,this.connection?.id);this.attention.sync(e,()=>({agent:R_(this.launch),title:this.title,connected:!!this.connection,busy:this.busy,startedAt:this.turnStartedAt,pending:e,tool:this.latestToolTitle()}))}for(const e of this.listeners)e();!this.disposed&&this.activeConversation&&!this.archived&&!this.connecting&&(clearTimeout(this.historyTimer),this.historyTimer=setTimeout(()=>{this.saveConversation()},300))};async saveConversation(){if(clearTimeout(this.historyTimer),!this.activeConversation||this.archived)return;const e=JSON.parse(JSON.stringify({...this.activeConversation,title:this.title,updatedAt:new Date().toISOString(),draft:this.draft,context:this.context.filter(s=>s.kind!=="image"),activity:this.activity,tools:[...this.tools],subagents:[...this.subagents.values()],subagentsTruncated:this.subagentsTruncated,autoApplyEdits:this.autoApply,inAppAgent:this.inAppSession})),i=this.historyGeneration;await this.history.ready,i===this.historyGeneration&&await this.history.save(e)}get inAppSession(){const e=this.connection?.sessionId;return this.local&&this.connection?.provider===Wi&&!this.sessionStarting&&!!e&&e===this.activeConversation?.sessionId}resetConversation(){this.messages=[],this.activity=[],this.subagents.clear(),this.activeSubagentCount=0,this.subagentsTruncated=!1,this.selectedSubagent=void 0,this.expandedSubagents.clear(),this.subagentsOpen=!1,this.tools.clear(),this.terminals.clear(),this.requests=[],this.commands=[],this.changes=[],this.title="New conversation",this.draft="",this.context=[],this.queue=[],this.queuePaused=!1,this.replayTruncated=!1,this.usage=void 0,this.lastSequence=0,this.queueRevision=0,this.activeTurnId=void 0,this.archived=!1,this.autoApplyValue=void 0,this.titleRequested=this.agentTitled=!1}get autoApply(){return this.autoApplyValue??this.options.kernel.configuration?.get("agentACP.autoApplyEdits")===!0}setAutoApply(e){this.autoApplyValue=e,this.changed()}get documents(){return this.options.documents}clearConnection(e,i=!1){this.busy&&this.activity.push({kind:"notice",text:i?"The runtime kept this turn. Reattach to follow it.":"The agent turn ended."});for(const s of this.subagents.values())!s.historical&&["pending","running","unknown"].includes(s.state)&&(s.state="disconnected",s.phase="unknown");this.activeSubagentCount=0,this.connectionGeneration++,this.requestGeneration++,this.startAbort?.abort(),this.startAbort=void 0,this.connection=void 0,this.sessionStarting=!1,this.busy=this.connecting=this.cancelling=this.updatingSettings=!1,this.requests=[],this.queue=[],this.queuePaused=!1,this.activeTurnId=void 0,this.status=e,this.saveConversation()}reconnectTarget(e=!!this.connection?.capabilities?.loadSession){const i=this.activeConversation;if(this.archived||!i?.sessionId||!e)return;const s=Date.now();if(this.reconnects=this.reconnects.filter(a=>s-a<6e4),this.reconnects.length>=3)return;this.reconnects.push(s);const r=this.busy?this.messages.findLast(a=>a.role==="user")?.text:void 0;return{id:i.id,launch:this.launch,prompt:r}}async reconnect(e,i){await this.saveConversation();const s=this.history.entries.find(r=>r.id===e.id);!s||this.disposed||this.connection||this.connecting||this.activeConversation?.id!==e.id||(this.status="Reconnecting…",this.changed(),await this.connect(e.launch,s),!(this.activeConversation?.id!==e.id||!this.connection)&&(this.activity.push({kind:"notice",text:`${i}. The agent restarted and loaded this conversation.`}),e.prompt&&!this.draft.trim()&&this.messages.findLast(r=>r.role==="user")?.text!==e.prompt&&(this.draft=e.prompt),this.saveConversation()))}async resumeInApp(){const e=this.history.entries[0];if(e?.inAppAgent!==!0||e.provider!==Wi||!this.localRuntime)return;for(let s=0;!this.local;s+=100){if(s>=1e4||this.disposed)return;await new Promise(r=>setTimeout(r,100))}if(this.disposed||this.connection||this.connecting||this.activeConversation||this.history.entries[0]?.id!==e.id)return;this.restoreSnapshot(e),this.launch={provider:Wi};const i=this.reconnectTarget(!0);i&&(await this.action(()=>this.reconnect(i,"The app reloaded")),await this.keepReadOnly(e))}async keepReadOnly(e){this.disposed||this.activeConversation?.id!==e.id||this.connection?.sessionId||(this.connection&&await this.disconnect().catch(()=>{}),this.restoreSnapshot(e),this.archived=!0,this.status="Conversation could not be restored",this.changed())}request(e,i={}){if(!this.options.runtime?.connected)throw new Error("Connect to a runtime workspace first");return this.options.runtime.request(e,i)}dismissError(){this.error="",this.changed()}async action(e){this.error="",this.changed();try{await e()}catch(i){this.disposed||(this.error=dI(this.connection?.provider??this.launch.provider,i))}finally{this.changed()}}async connect(e,i){if(this.disposed||this.connecting||this.connection)return;const s=++this.connectionGeneration;this.connecting=!0,this.launch=e,this.status="Connecting…",this.logs="",this.changed();const r=new AbortController;this.startAbort=r;try{if(!this.options.runtime||this.localRuntime&&!this.local)throw new Error("Connect to a runtime workspace first");const a=await this.options.runtime.request("acp.start",{...e,clientCapabilities:{editorTools:!0}},{signal:r.signal});if(this.disposed||s!==this.connectionGeneration){await this.request("acp.stop",{id:a.id}).catch(()=>{});return}if(this.connection=a,P_(a.provider,a.name??e.name),i&&i.root!==a.root)throw new Error("This conversation belongs to another workspace");this.status="Connected",i?await this.restoreConversation(i):await this.newSession()}catch(a){if(s!==this.connectionGeneration)return;const n=!this.connection&&DYe(a);throw this.status=this.connection?"Sign in or retry starting the conversation":n?bA:"Connection failed",n&&this.listLiveSessions().catch(()=>{}),this.connection?a:PYe(a,R_(e))}finally{s===this.connectionGeneration&&(this.startAbort=void 0,this.connecting=!1,this.changed())}}claudePlan=!1;setClaudePlan(e){this.claudePlan=e,this.changed()}async connectSelected(){if(this.local&&this.claudePlan){await this.options.kernel.commands.execute("workspace.runtime");return}await this.connect(E_(this.chosen,this.options.kernel.configuration))}get localRuntime(){return this.options.runtime?.local===!0}get local(){return this.localRuntime&&!!this.options.runtime?.connected}get chosen(){if(this.local)return{provider:Wi};const e=this.selection??{provider:this.options.kernel.configuration?.get("agentACP.provider")||"codex"};return e.provider===Wi?{provider:"codex"}:e}get displayName(){return this.connection?il(this.connection.provider,this.connection):R_(E_(this.chosen,this.options.kernel.configuration))}async select(e){const i=this.options.kernel.configuration;e.provider===Ei&&(await i.set(ys(Ei,"name"),e.name??"","user"),await i.set(ys(Ei,"command"),e.command??"","user"),await i.set(ys(Ei,"args"),JSON.stringify(e.args??[]),"user")),e.provider!==Wi&&await i.set("agentACP.provider",e.provider,"user"),this.selection=e,this.changed()}async loadRegistry(){if(!this.registryLoading){this.registryLoading=!0,this.changed();try{const e=await this.request("acp.registry");for(const i of e.agents)CYe(i.id,i.name);this.registry=e}finally{this.registryLoading=!1,this.changed()}}}markSeen(){this.attention.seen(),this.changed()}savedLaunch(e){if(e.provider===Ei)return{name:e.name,command:e.command,args:e.args};if(!io(e.provider)&&e.provider!==Wi)return{registry:e.registry??{id:e.provider}}}async call(e,i={}){if(!this.connection)throw new Error("Connect an agent first");return this.request("acp.call",{id:this.connection.id,method:e,params:i})}get canForkSession(){return!!this.connection?.sessionId&&!!this.connection.capabilities?.sessionCapabilities?.fork&&this.messages.length>0&&!this.busy&&!this.connecting&&!this.sessionStarting&&!this.updatingSettings&&!this.discovering&&!this.requests.length&&!this.queue.length&&!this.activeSubagentCount}async forkSession(){try{await this.newSession(!0)}catch(e){throw e instanceof Error&&e.message==="Unsupported ACP client method"?new Error("Update the runtime to fork conversations"):e}}async newSession(e=!1){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(!this.connection||this.busy||this.updatingSettings||this.discovering||this.sessionStarting)return;const s=this.connectionGeneration;this.sessionStarting=!0,this.connecting=!0;const r=this.draft,a=this.context;let n;this.changed();try{if(await this.saveConversation(),n=this.history.entries.find(l=>l.id===this.activeConversation?.id),s!==this.connectionGeneration)return;this.resetConversation();const o=await this.call(e?"session/fork":"session/new");s===this.connectionGeneration&&(e&&n&&(this.restoreSnapshot(n),this.draft="",this.context=[],this.activity.push({kind:"notice",text:OKe,values:{title:n.title}})),this.connection=o,this.activeConversation={id:crypto.randomUUID(),sessionId:o.sessionId,root:o.root,provider:o.provider,name:il(o.provider,o),launch:this.savedLaunch(this.launch)},this.autoApplyValue=this.autoApply,this.status="Ready")}catch(o){if(s!==this.connectionGeneration)return;throw n?this.restoreSnapshot(n):(this.draft=r,this.context=a),this.status="Sign in or retry starting the conversation",o}finally{s===this.connectionGeneration&&(this.sessionStarting=!1,this.connecting=!1,this.changed())}}async authenticate(e){if(this.connecting||!this.connection)return;const i=this.connectionGeneration;this.connecting=!0,this.changed();try{if(await this.call("authenticate",{methodId:e}),i!==this.connectionGeneration)return;this.connection?.sessionId||await this.newSession()}catch(s){if(i===this.connectionGeneration)throw s}finally{i===this.connectionGeneration&&(this.connecting=!1,this.changed())}}async disconnect(){const e=this.connection,i=this.saveConversation();this.clearConnection("Disconnected");const s=this.connectionGeneration;this.changed();try{e&&this.options.runtime?.connected&&await this.request("acp.stop",{id:e.id}),await i}catch(r){if(s===this.connectionGeneration)throw r}}async detach(){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");const e=this.connection;if(!e||this.connecting||this.sessionStarting||this.updatingSettings||this.discovering)return;const i=this.options.runtime?.connected?this.request("acp.detach").catch(()=>{}):void 0;this.activeConversation&&this.threadConversations.set(e.id,this.activeConversation.id),this.clearConnection("Disconnected",!0),await this.saveConversation(),this.activeConversation=void 0,this.resetConversation(),this.changed(),await i}async listLiveSessions(){if(!this.options.runtime?.connected||this.local)return;const e=await this.request("acp.list");JSON.stringify(e.sessions)!==JSON.stringify(this.liveSessions)&&(this.liveSessions=e.sessions,this.changed())}async attachLive(e){if(this.connection?.id===e)return;await this.saveConversation(),this.connection&&this.activeConversation&&this.threadConversations.set(this.connection.id,this.activeConversation.id);const i=++this.connectionGeneration;this.attachBuffer=[];try{const s=await this.request("acp.attach",{id:e,clientCapabilities:{editorTools:!0}});if(i!==this.connectionGeneration||this.disposed||!this.options.runtime?.connected)return;const r=this.draft,a=this.context;this.resetConversation(),this.draft=r,this.context=a,this.connection=s.connection,this.launch={provider:s.connection.provider,name:s.connection.name},P_(s.connection.provider,s.connection.name),this.activeConversation={id:this.threadConversations.get(e)??crypto.randomUUID(),sessionId:s.connection.sessionId??"",root:s.connection.root,provider:s.connection.provider,name:il(s.connection.provider,s.connection),launch:this.savedLaunch(this.launch)};const n=this.history.entries.find(o=>o.id===this.activeConversation?.id);this.autoApplyValue=n?n.autoApplyEdits===!0:this.autoApply,this.replayTruncated=s.truncated,this.status=s.busy?"Working…":"Ready",this.replaying=!0;try{for(const o of s.events)this.deliver(o.name,o.params)}finally{this.replaying=!1}n&&!this.agentTitled&&n.title!=="New conversation"&&(this.title=n.title),this.lastSequence=Math.max(this.lastSequence,s.sequence),this.queue=s.queue,this.queuePaused=s.queuePaused,this.busy=s.busy;for(const o of s.requests)this.clientRequest(o);for(const o of this.attachBuffer??[])this.deliver(o.name,o.params);this.changed()}catch(s){for(const r of this.attachBuffer??[])this.deliver(r.name,r.params);throw s}finally{this.attachBuffer=void 0}}async discover(e=!1){if(!this.connection||this.busy||this.connecting||this.discovering||this.updatingSettings)return;const i=this.connectionGeneration;this.discovering=!0,this.changed();try{const s=await this.call("session/list",e&&this.nextCursor?{cursor:this.nextCursor}:{});if(i!==this.connectionGeneration)return;this.sessions=[...new Map([...e?this.sessions:[],...s.sessions].map(r=>[r.sessionId,r])).values()],this.nextCursor=s.nextCursor===this.nextCursor&&e?void 0:s.nextCursor}finally{i===this.connectionGeneration&&(this.discovering=!1,this.changed())}}async viewConversation(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");this.busy||this.connecting||this.updatingSettings||this.discovering||(await this.disconnect(),this.restoreSnapshot(e),this.archived=!0,this.status="Saved conversation",this.changed())}async forgetConversation(e){this.historyGeneration++,this.activeConversation?.id===e&&(clearTimeout(this.historyTimer),this.activeConversation=void 0),await this.history.ready,await this.history.remove(e)}restoreSnapshot(e){this.resetConversation();const i=JSON.parse(JSON.stringify(e));this.activeConversation={id:i.id,sessionId:i.sessionId,root:i.root,provider:i.provider,name:i.name,launch:i.launch},this.title=i.title,this.titleRequested=!0,this.autoApplyValue=i.autoApplyEdits===!0,this.draft=i.draft,this.context=i.context,this.activity=i.activity,this.tools=new Map(i.tools),this.subagents=new Map((i.subagents??[]).map(s=>[s.id,{...s,historical:!0}])),this.subagentsTruncated=i.subagentsTruncated??!1,this.messages=this.activity.flatMap(s=>s.kind==="message"?[s.message]:[])}async resumeSaved(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(this.busy||this.connecting||this.updatingSettings||this.discovering)return;const i=e.provider!==Ei||this.launch.command===e.launch?.command&&JSON.stringify(this.launch.args??[])===JSON.stringify(e.launch?.args??[]);if(this.connection?.provider===e.provider&&this.connection.root===e.root&&i)return this.restoreConversation(e);await this.disconnect();const s=e.launch,r=e.provider===Ei?{provider:e.provider,name:s?.name??e.name,command:s?.command,args:s?.args}:io(e.provider)?{provider:e.provider}:{provider:e.provider,registry:s?.registry??{id:e.provider}};await this.connect(E_(r,this.options.kernel.configuration),e)}async restoreConversation(e){if(this.requests.length)throw new Error("Resolve pending requests before changing conversations");if(this.queue.length)throw new Error("Run or remove queued messages before changing conversations");if(this.activeSubagentCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(!this.connection||this.busy||this.updatingSettings||this.discovering||this.sessionStarting)return;if(e.root!==this.connection.root||e.provider!==this.connection.provider)throw new Error("This conversation belongs to another workspace or provider");const i=this.connection.capabilities,s=i?.loadSession?"session/load":i?.sessionCapabilities?.resume?"session/resume":void 0;if(!s)throw new Error("This agent cannot resume conversations. You can still read the saved transcript.");this.sessionStarting=this.connecting=!0;const r=this.connectionGeneration;if(await this.saveConversation(),r!==this.connectionGeneration)return;const a=this.activeConversation&&this.history.entries.find(n=>n.id===this.activeConversation.id);this.restoreSnapshot(e),s==="session/load"&&(this.activity=[],this.messages=[],this.tools.clear()),this.sessionStarting=this.connecting=!0,this.status="Restoring conversation…",this.changed();try{const n=await this.call(s,{sessionId:e.sessionId});if(r!==this.connectionGeneration)return;s==="session/load"&&gKe(e.activity,this.activity),this.connection=n,this.status="Ready",this.archived=!1}catch(n){if(r!==this.connectionGeneration)return;throw a?this.restoreSnapshot(a):(this.restoreSnapshot(e),this.archived=!0),this.status="Conversation could not be restored",n}finally{r===this.connectionGeneration&&(this.sessionStarting=this.connecting=!1,this.changed())}}importConversation(e){const i=this.connection,s=this.history.entries.find(r=>r.sessionId===e.sessionId&&r.provider===i.provider&&r.root===e.cwd);return s?this.restoreConversation(s):this.restoreConversation({id:crypto.randomUUID(),...e,root:e.cwd,provider:i.provider,title:e.title||"Saved conversation",updatedAt:e.updatedAt||new Date().toISOString(),draft:"",context:[],activity:[],tools:[]})}async setSessionControl(e,i){if(this.busy||this.connecting||this.updatingSettings||this.discovering||this.archived)return;const s=this.connection;if(!s?.sessionId)throw new Error("Start a conversation first");const r=dG(s).find(n=>n.id===e.id&&n.method===e.method);if(!r?.options.some(n=>n.value===i))throw new Error("This agent setting is no longer available");if(r.value===i)return;const a=this.connectionGeneration;this.updatingSettings=!0,this.changed();try{const n=e.method==="session/set_config_option"?{configId:e.id,value:i}:e.method==="session/set_mode"?{modeId:i}:{modelId:i},o=await this.call(e.method,n);if(a!==this.connectionGeneration)return;if(o?.configOptions)s.configOptions=o.configOptions;else if(e.method==="session/set_config_option"){const l=s.configOptions?.find(c=>c.id===e.id);l&&(l.currentValue=i)}e.method==="session/set_mode"&&s.modes&&(s.modes.currentModeId=i),e.method==="session/set_model"&&s.models&&(s.models.currentModelId=i)}catch(n){if(a===this.connectionGeneration)throw n}finally{a===this.connectionGeneration&&(this.updatingSettings=!1,this.changed())}}attach(e=!1){const i=this.options.workbench.activePath();if(!i)throw new Error("Open a file to attach context");const s=this.documents.get(i);if(!s)throw new Error("The active file is unavailable");const a=this.options.workbench.activeEditor()?.state?.selection?.main;if(e&&(!a||a.empty))throw new Error("Select text in the editor first");const n=e?s.text.toString().slice(a.from,a.to):s.text.toString();if(n.length>2e5)throw new Error("Select a smaller portion of this file (maximum 200,000 characters)");if(this.context.length>=8)throw new Error("Attach up to eight files or selections per message");const o=e?s.text.toString().slice(0,a.from).split(`
380
380
  `).length:void 0,l=e?s.text.toString().slice(0,Math.max(a.from,a.to-1)).split(`
381
381
  `).length:void 0;this.context.push({path:i,text:n,line:o,endLine:l,version:s.version,kind:e?"selection":"file",label:i+(e?`:${o}-${l}`:"")}),this.changed()}async attachPath(e){const i=await this.documents.open(e);if(this.context.length>=8)throw new Error("Attach up to eight files or selections per message");const s=i.text.toString();if(s.length>2e5)throw new Error("Select a smaller portion of this file (maximum 200,000 characters)");this.context.push({path:e,text:s,label:e,kind:"file",version:i.version}),this.changed()}async attachImage(e){if(!this.connection)throw new Error("Connect an agent to attach images");const i=()=>this.context.filter(o=>o.kind==="image").length,s=!!this.connection.capabilities?.promptCapabilities?.image,r=WHe(e,i(),s);if(r)throw new Error(r);if(this.context.length>=8)throw new Error("Attach up to eight files or selections per message");const{mimeType:a,data:n}=await GHe(e);if(i()>=4||this.context.length>=8)throw new Error("Attach up to 4 images per message");this.context.push(HHe(e.name,a,n)),this.changed()}async attachMention(e){if(e.kind==="changes")return this.attachChanges();if(e.kind==="symbol")return this.attachSymbol(e);if(e.kind==="thread")return this.attachThread(e.id);if(e.kind==="branch")return this.attachBranchDiff();if(e.kind==="commit")return this.attachCommit(e);if(e.kind==="folder")return this.attachFolder(e.path);if(e.kind!=="file")return e.kind==="selection"?this.attach(!0):this.attachDiagnostics();this.context.some(i=>i.kind==="file"&&i.path===e.path)||await this.attachPath(e.path)}async attachSymbol({name:e,path:i,line:s,endLine:r}){const a=await this.documents.open(i);if(this.context.length>=8)throw new Error("Attach up to eight files or selections per message");const n=a.text.toString().split(`
382
382
  `).slice(s-1,r).join(`
@@ -385,7 +385,7 @@ ${d}`;o+p.length>i||(o+=p.length,n.push(p))}const l=`${s.length}${r?"+":""} file
385
385
  `+JSON.stringify(e)).slice(-65536));for(;this.activity.length>200;)this.activity.shift()}}updatePlan(e){const i=this.activity.findLastIndex(r=>r.kind==="plan");i>=0&&!this.activity.slice(i+1).some(r=>r.kind==="message"&&r.message.role==="user")?this.activity[i]={kind:"plan",entries:e}:e.length&&this.activity.push({kind:"plan",entries:e})}async clientRequest(e){if(this.pendingClientRequests.has(e.requestId)||this.requests.some(n=>n.requestId===e.requestId))return;const i={expired:!1};this.pendingClientRequests.set(e.requestId,i);const s=this.requestGeneration,r=this.rootRequestGeneration,a=()=>!i.expired&&s===this.requestGeneration&&(this.isChildRequest(e)||r===this.rootRequestGeneration);try{if(["oxbit/workspace","oxbit/diagnostics","oxbit/open_file"].includes(e.method)){const n=e.params.path;if(n!==void 0&&(typeof n!="string"||!n||n.startsWith("/")||n.includes("\\")||n.split("/").includes("..")||n.includes("\0")))throw new Error("Choose a file inside the workspace");const o=this.options.workbench,l=[...new Set((o.state?.groups??[]).flatMap(k=>k.tabs.map($=>$.path).filter($=>!!$)))].slice(0,100),c=this.options.workbench.activePath(),u=k=>{const $=this.options.kernel.services.get("language");return(k?[k]:l).flatMap(C=>($?.diagnostics?.get(C)??[]).slice(0,100).map(b=>({path:C,line:(b.range?.start?.line??0)+1,character:(b.range?.start?.character??0)+1,message:String(b.message??"").slice(0,4e3),source:b.source,severity:b.severity}))).slice(0,200)};if(e.method==="oxbit/diagnostics"){a()&&await this.respond(e,{diagnostics:u(n)});return}if(e.method==="oxbit/open_file"){if(typeof n!="string")throw new Error("Choose a file inside the workspace");const k=e.params.line;if(k!==void 0&&(!Number.isInteger(k)||k<1))throw new Error("Line must be a positive integer");await this.openLocation(n,k===void 0?void 0:k-1),a()&&await this.respond(e,{path:n});return}const p=this.options.workbench.activeEditor()?.state?.selection?.main,g=c?this.documents.get(c):void 0,y=c&&g&&p&&!p.empty?{path:c,text:g.text.toString().slice(p.from,Math.min(p.to,p.from+2e5)),line:g.text.toString().slice(0,p.from).split(`
386
386
  `).length}:void 0;a()&&await this.respond(e,{activeFile:c,openFiles:l,selection:y,diagnostics:u(c)});return}if(e.method==="fs/read_text_file"){const o=(await this.documents.open(e.params.path)).text.toString(),l=(e.params.line??1)-1,c=e.params.line!==void 0||e.params.limit!==void 0?o.split(`
387
387
  `).slice(l,e.params.limit?l+e.params.limit:void 0).join(`
388
- `):o;a()&&await this.respond(e,{content:c});return}if(e.method==="fs/write_text_file"){let n;try{n=await this.documents.open(e.params.path)}catch(o){if(!bKe(o))throw o}if(n?.dirty)throw new Error(`Save or revert your unsaved edits in ${e.params.path} before the agent can replace the file.`);if(n&&n.state!=="ready")throw new Error(`Resolve the file's ${n.state} state before applying agent changes.`);e.before=n?.text.toString()??"",e.revision=n?.savedRevision??null,e.version=n?.version}if(!this.disposed&&a()&&this.connection?.id===e.id){if(e.method==="fs/write_text_file"&&(this.autoApply||yKe(this.connection?.provider,e.params))){await this.writeFile(e,!1).catch(n=>{this.error=String(n),this.changed()});return}this.requests.push(e),this.attention.requestArrived(this.title),this.changed()}}catch(n){if(this.disposed||!a())return;await this.respond(e,void 0,String(n)).catch(()=>{}),this.error=String(n),this.changed()}finally{this.pendingClientRequests.get(e.requestId)===i&&this.pendingClientRequests.delete(e.requestId)}}async respond(e,i,s){await this.request("acp.respond",{id:e.id,requestId:e.requestId,result:i,error:s}),this.requests=this.requests.filter(r=>r.requestId!==e.requestId),this.changed()}async applyFile(e){if(!this.requests.includes(e)||this.connection?.id!==e.id)throw new Error("File review has expired");if(this.fileActions.has(e.requestId))return!1;const i=this.documents.get(e.params.path);return i?.dirty||e.version!==void 0&&(i?.version!==e.version||i.savedRevision!==e.revision)||e.revision===null&&i?(await this.respond(e,void 0,"File changed during review. Read the latest content and retry."),!1):this.writeFile(e,!0)}async writeFile(e,i){const s=this.documents.get(e.params.path);this.fileActions.add(e.requestId);try{s?(s.replace(e.params.content),await this.documents.save(e.params.path,void 0,{skipHooks:!0})):await this.options.filesystem.write(e.params.path,e.params.content,{expectedRevision:null});const r=this.documents.get(e.params.path);for(this.changes.push({id:crypto.randomUUID(),path:e.params.path,before:e.before??"",after:e.params.content,revision:r?.savedRevision,created:e.revision===null,turn:this.activeTurnId});this.changes.length>30;)this.changes.shift();return this.activity.push({kind:"notice",text:`Applied change: ${e.params.path}`}),await this.respond(e,null),i&&!this.panelCoversEditor()&&await this.options.workbench.openFile(e.params.path,{preview:!1}),await this.options.workbench.refreshFiles(),!0}catch(r){throw await this.respond(e,void 0,String(r)).catch(()=>{}),r}finally{this.fileActions.delete(e.requestId)}}reviewingAll=!1;get pendingWrites(){return this.requests.filter(e=>e.method==="fs/write_text_file")}get undoableChanges(){return this.changes.filter(e=>!e.undone&&!e.created)}async applyAllFiles(){await this.answerWrites(async e=>{if(!await this.applyFile(e))throw new Error(`File changed during review: ${e.params.path}`)})}async rejectAllFiles(){await this.answerWrites(e=>this.respond(e,void 0,qG))}async undoAllChanges(){const e=this.undoableChanges.reverse();await this.reviewAll(e.map(i=>i.id),async()=>{for(const i of e)await this.undoChange(i.id)})}async answerWrites(e){const i=this.pendingWrites;await this.reviewAll(i.map(s=>s.requestId),async()=>{for(const s of i)this.requests.includes(s)&&await e(s)})}async reviewAll(e,i){if(!(this.reviewingAll||!e.length)){if(e.some(s=>this.fileActions.has(s)))throw new Error("Wait for the current file review to finish");this.reviewingAll=!0,this.changed();try{await i()}finally{this.reviewingAll=!1,this.changed()}}}async undoLastTurn(){const e=this.undoableChanges.at(-1);if(!e)return this.activity.push({kind:"notice",text:"No agent edits to undo."}),this.changed();const i=this.undoableChanges.filter(s=>s.turn===e.turn).reverse();await this.reviewAll(i.map(s=>s.id),async()=>{for(const s of i)await this.undoChange(s.id)})}async undoChange(e){const i=this.changes.find(s=>s.id===e);if(!i||i.undone)throw new Error("This change is no longer available to undo");if(this.busy||this.connecting||this.requests.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before undoing changes");if(i.created)throw new Error("Review newly created files in Source Control");if(!this.fileActions.has(e)){this.fileActions.add(e);try{const s=await this.documents.open(i.path),r=s.version,a=()=>!s.dirty&&s.state==="ready"&&s.text.toString()===i.after&&s.savedRevision===i.revision;if(!a())throw new Error("This file changed after the agent edit. Review it in Source Control to preserve newer work.");const n=await this.options.filesystem.read(i.path);if(n.text!==i.after||n.revision!==i.revision)throw new Error("This file changed on disk after the agent edit");if(!a()||s.version!==r||this.busy||this.connecting||this.activeSubagentCount)throw new Error("The editor changed while checking this undo");s.replace(i.before),await this.documents.save(i.path,void 0,{skipHooks:!0}),i.undone=!0,this.activity.push({kind:"notice",text:`Undid agent change: ${i.path}`})}finally{this.fileActions.delete(e),this.changed()}}}async restoreCheckpoint(e,i=!0){if(!e.checkpoint||!this.connection)return!1;if(this.busy||this.connecting||this.requests.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before restoring a checkpoint");return await this.checkpoints.restore(e.checkpoint,r=>!!this.documents.get(r)?.dirty)?(i&&this.activity.push(jI(e)),this.changed(),await this.options.workbench.refreshFiles(),!0):!1}async forkFrom(e,i=!1){const s=this.activity.findIndex(n=>n.kind==="message"&&n.message===e),r=this.activeConversation;if(s<0||!r||!this.connection)return;if(this.busy||this.connecting||this.sessionStarting||this.updatingSettings||this.discovering||this.requests.length||this.queue.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before forking");const a=oKe({...r,title:this.title,activity:this.activity},s);i&&!await this.restoreCheckpoint(e,!1)||(await this.newSession(),!(this.activeConversation?.id===r.id||!this.connection?.sessionId)&&(this.draft=e.text,this.context=a?[a]:[],i&&this.activity.push(jI(e)),this.changed()))}async nameConversation(){const e=this.options.kernel.configuration,i=this.options.kernel.services.optional(fv),s=e?.get(so.model)?.trim(),r=lv(e),a=this.messages.filter(c=>c.role==="user");if(this.titleRequested||this.agentTitled||a.length!==1||!this.connection||e?.get("agentACP.generateTitles")===!1||!i||!s||r.api==="openai-compatible"&&!r.baseUrl)return;this.titleRequested=!0;const n=this.activeConversation?.id,o=this.connectionGeneration,l=this.messages.slice(this.messages.indexOf(a[0])+1).filter(c=>c.role==="agent").map(c=>c.text).join(`
388
+ `):o;a()&&await this.respond(e,{content:c});return}if(e.method==="fs/write_text_file"){let n;try{n=await this.documents.open(e.params.path)}catch(o){if(!bKe(o))throw o}if(n?.dirty)throw new Error(`Save or revert your unsaved edits in ${e.params.path} before the agent can replace the file.`);if(n&&n.state!=="ready")throw new Error(`Resolve the file's ${n.state} state before applying agent changes.`);e.before=n?.text.toString()??"",e.revision=n?.savedRevision??null,e.version=n?.version}if(!this.disposed&&a()&&this.connection?.id===e.id){if(e.method==="fs/write_text_file"&&(this.autoApply||yKe(this.connection?.provider,e.params))){await this.writeFile(e,!1).catch(()=>{});return}this.requests.push(e),this.attention.requestArrived(this.title),this.changed()}}catch(n){if(this.disposed||!a())return;await this.respond(e,void 0,String(n)).catch(()=>{})}finally{this.pendingClientRequests.get(e.requestId)===i&&this.pendingClientRequests.delete(e.requestId)}}async respond(e,i,s){await this.request("acp.respond",{id:e.id,requestId:e.requestId,result:i,error:s}),this.requests=this.requests.filter(r=>r.requestId!==e.requestId),this.changed()}async applyFile(e){if(!this.requests.includes(e)||this.connection?.id!==e.id)throw new Error("File review has expired");if(this.fileActions.has(e.requestId))return!1;const i=this.documents.get(e.params.path);return i?.dirty||e.version!==void 0&&(i?.version!==e.version||i.savedRevision!==e.revision)||e.revision===null&&i?(await this.respond(e,void 0,"File changed during review. Read the latest content and retry."),!1):this.writeFile(e,!0)}async writeFile(e,i){const s=this.documents.get(e.params.path);this.fileActions.add(e.requestId);try{s?(s.replace(e.params.content),await this.documents.save(e.params.path,void 0,{skipHooks:!0})):await this.options.filesystem.write(e.params.path,e.params.content,{expectedRevision:null});const r=this.documents.get(e.params.path);for(this.changes.push({id:crypto.randomUUID(),path:e.params.path,before:e.before??"",after:e.params.content,revision:r?.savedRevision,created:e.revision===null,turn:this.activeTurnId});this.changes.length>30;)this.changes.shift();return this.activity.push({kind:"notice",text:`Applied change: ${e.params.path}`}),await this.respond(e,null),i&&!this.panelCoversEditor()&&await this.options.workbench.openFile(e.params.path,{preview:!1}),await this.options.workbench.refreshFiles(),!0}catch(r){throw await this.respond(e,void 0,String(r)).catch(()=>{}),r}finally{this.fileActions.delete(e.requestId)}}reviewingAll=!1;get pendingWrites(){return this.requests.filter(e=>e.method==="fs/write_text_file")}get undoableChanges(){return this.changes.filter(e=>!e.undone&&!e.created)}async applyAllFiles(){await this.answerWrites(async e=>{if(!await this.applyFile(e))throw new Error(`File changed during review: ${e.params.path}`)})}async rejectAllFiles(){await this.answerWrites(e=>this.respond(e,void 0,qG))}async undoAllChanges(){const e=this.undoableChanges.reverse();await this.reviewAll(e.map(i=>i.id),async()=>{for(const i of e)await this.undoChange(i.id)})}async answerWrites(e){const i=this.pendingWrites;await this.reviewAll(i.map(s=>s.requestId),async()=>{for(const s of i)this.requests.includes(s)&&await e(s)})}async reviewAll(e,i){if(!(this.reviewingAll||!e.length)){if(e.some(s=>this.fileActions.has(s)))throw new Error("Wait for the current file review to finish");this.reviewingAll=!0,this.changed();try{await i()}finally{this.reviewingAll=!1,this.changed()}}}async undoLastTurn(){const e=this.undoableChanges.at(-1);if(!e)return this.activity.push({kind:"notice",text:"No agent edits to undo."}),this.changed();const i=this.undoableChanges.filter(s=>s.turn===e.turn).reverse();await this.reviewAll(i.map(s=>s.id),async()=>{for(const s of i)await this.undoChange(s.id)})}async undoChange(e){const i=this.changes.find(s=>s.id===e);if(!i||i.undone)throw new Error("This change is no longer available to undo");if(this.busy||this.connecting||this.requests.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before undoing changes");if(i.created)throw new Error("Review newly created files in Source Control");if(!this.fileActions.has(e)){this.fileActions.add(e);try{const s=await this.documents.open(i.path),r=s.version,a=()=>!s.dirty&&s.state==="ready"&&s.text.toString()===i.after&&s.savedRevision===i.revision;if(!a())throw new Error("This file changed after the agent edit. Review it in Source Control to preserve newer work.");const n=await this.options.filesystem.read(i.path);if(n.text!==i.after||n.revision!==i.revision)throw new Error("This file changed on disk after the agent edit");if(!a()||s.version!==r||this.busy||this.connecting||this.activeSubagentCount)throw new Error("The editor changed while checking this undo");s.replace(i.before),await this.documents.save(i.path,void 0,{skipHooks:!0}),i.undone=!0,this.activity.push({kind:"notice",text:`Undid agent change: ${i.path}`})}finally{this.fileActions.delete(e),this.changed()}}}async restoreCheckpoint(e,i=!0){if(!e.checkpoint||!this.connection)return!1;if(this.busy||this.connecting||this.requests.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before restoring a checkpoint");return await this.checkpoints.restore(e.checkpoint,r=>!!this.documents.get(r)?.dirty)?(i&&this.activity.push(jI(e)),this.changed(),await this.options.workbench.refreshFiles(),!0):!1}async forkFrom(e,i=!1){const s=this.activity.findIndex(n=>n.kind==="message"&&n.message===e),r=this.activeConversation;if(s<0||!r||!this.connection)return;if(this.busy||this.connecting||this.sessionStarting||this.updatingSettings||this.discovering||this.requests.length||this.queue.length||this.activeSubagentCount)throw new Error("Wait for the agent to finish before forking");const a=oKe({...r,title:this.title,activity:this.activity},s);i&&!await this.restoreCheckpoint(e,!1)||(await this.newSession(),!(this.activeConversation?.id===r.id||!this.connection?.sessionId)&&(this.draft=e.text,this.context=a?[a]:[],i&&this.activity.push(jI(e)),this.changed()))}async nameConversation(){const e=this.options.kernel.configuration,i=this.options.kernel.services.optional(fv),s=e?.get(so.model)?.trim(),r=lv(e),a=this.messages.filter(c=>c.role==="user");if(this.titleRequested||this.agentTitled||a.length!==1||!this.connection||e?.get("agentACP.generateTitles")===!1||!i||!s||r.api==="openai-compatible"&&!r.baseUrl)return;this.titleRequested=!0;const n=this.activeConversation?.id,o=this.connectionGeneration,l=this.messages.slice(this.messages.indexOf(a[0])+1).filter(c=>c.role==="agent").map(c=>c.text).join(`
389
389
 
390
390
  `);try{const c=await UHe(i,r,s,a[0].text,l);if(!c||this.agentTitled||this.disposed||o!==this.connectionGeneration||n!==this.activeConversation?.id)return;this.title=c,this.changed()}catch{}}isChildRequest(e){return!!e.sessionId&&e.sessionId!==(e.rootSessionId??this.connection?.sessionId)}expandAncestors(e){const i=new Set;let s=this.subagents.get(e)?.parentId;for(;s&&!i.has(s);)i.add(s),this.expandedSubagents.add(s),s=this.subagents.get(s)?.parentId}selectSubagent(e){this.subagents.has(e)&&(this.selectedSubagent=e,this.subagentsOpen=!0,this.expandAncestors(e),this.changed())}toggleSubagent(e){if(this.expandedSubagents.has(e)){this.expandedSubagents.delete(e);const i=new Set;let s=this.subagents.get(this.selectedSubagent??"")?.parentId;for(;s&&!i.has(s);){if(s===e){this.selectedSubagent=e;break}i.add(s),s=this.subagents.get(s)?.parentId}}else this.expandedSubagents.add(e);this.changed()}openAgents(e){e&&this.selectSubagent(e),this.options.workbench.openPanel("agent-acp-agents")}panelCoversEditor(){return(globalThis.innerWidth||1440)<1100&&[lu,"agent-acp-agents"].some(e=>this.options.workbench.panelVisible?.(e)===!0)}async openLocation(e,i){const s=this.connection?.root??this.activeConversation?.root;if(!s)return;const r=e.startsWith(s+"/")?e.slice(s.length+1):e;if(r.startsWith("/")||r.split("/").includes(".."))throw new Error("This file is outside the workspace");await this.options.workbench.openFile(r,{line:i===void 0?void 0:i+1,preview:!1})}latestToolTitle(){let e;for(const i of this.tools.values())typeof i.title=="string"&&(e=i.title);return e}dispose(){this.attention.dispose(),this.saveConversation(),clearTimeout(this.historyTimer),this.disposed=!0,this.clearConnection("Disconnected");for(const e of this.subscriptions)e();this.subscriptions=[],this.listeners.clear(),this.options.runtime?.connected&&this.request("acp.disconnect").catch(()=>{}),this.connection=void 0,this.requests=[]}}const BI={"agoragentic-acp":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="7" stroke="currentColor" stroke-width="1.5"/><path d="M5.5 10.5L8 4L10.5 10.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><line x1="6.25" y1="8.75" x2="9.75" y2="8.75" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>',"amp-acp":'<svg width="16" height="16" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.9197 13.61L17.3816 26.566L14.242 27.4049L11.2645 16.2643L0.119926 13.2906L0.957817 10.15L13.9197 13.61Z" fill="currentColor"/><path d="M13.7391 16.0892L4.88169 24.9056L2.58872 22.6019L11.4461 13.7865L13.7391 16.0892Z" fill="currentColor"/><path d="M18.9386 8.58315L22.4005 21.5392L19.2609 22.3781L16.2833 11.2374L5.13879 8.26381L5.97668 5.12318L18.9386 8.58315Z" fill="currentColor"/><path d="M23.9803 3.55632L27.4422 16.5124L24.3025 17.3512L21.325 6.21062L10.1805 3.23698L11.0183 0.0963593L23.9803 3.55632Z" fill="currentColor"/></svg>',"antigravity-acp":'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14.1452 14.6818C14.9937 15.3182 16.2664 14.894 15.0997 13.7273C11.5998 10.3333 12.3421 1 7.99366 1C3.64518 1 4.3876 10.3333 0.887603 13.7273C-0.385123 15 0.993664 15.3182 1.84215 14.6818C5.13002 12.4545 4.9179 8.5303 7.99366 8.5303C11.0694 8.5303 10.8573 12.4545 14.1452 14.6818Z" fill="currentColor"/></svg>',auggie:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" d="M9.972 13.193h2.577q.187 0 .277-.09t.091-.294V10.47q0-.324.133-.59.135-.27.36-.424a1 1 0 0 1 .099-.06 1 1 0 0 1-.1-.058 1.1 1.1 0 0 1-.359-.424 1.3 1.3 0 0 1-.133-.59v-2.33q0-.202-.091-.293t-.277-.089H9.972a.38.38 0 0 1-.294-.124.4.4 0 0 1-.108-.281q.002-.176.131-.293a.46.46 0 0 1 .313-.111h2.775c.36 0 .642.097.836.288q.293.29.294.832V8.24q0 .39.152.562.148.168.555.178a.4.4 0 0 1 .27.128.41.41 0 0 1 .104.287.44.44 0 0 1-.1.282.34.34 0 0 1-.277.132c-.266.006-.452.066-.55.177q-.151.174-.152.573v2.318c0 .235-.043.44-.128.607a.85.85 0 0 1-.389.387 1.3 1.3 0 0 1-.534.124V14h-2.854a.45.45 0 0 1-.315-.118.38.38 0 0 1-.129-.286q0-.164.109-.282a.38.38 0 0 1 .293-.123zM1.103 9.108a.4.4 0 0 1 .276-.128q.4-.008.55-.177.15-.173.151-.562V5.923q.002-.543.294-.832c.195-.191.477-.288.836-.288h2.775q.188 0 .313.111a.37.37 0 0 1 .131.293.4.4 0 0 1-.108.281.38.38 0 0 1-.293.123H3.45q-.186 0-.277.09t-.092.292v2.33c0 .213-.044.413-.133.59a1.1 1.1 0 0 1-.359.424 1 1 0 0 1-.1.059 1 1 0 0 1 .1.059q.225.156.359.423t.133.59v2.34q0 .203.092.293.088.09.277.089h2.577a.38.38 0 0 1 .294.123q.108.12.108.281a.38.38 0 0 1-.13.286.45.45 0 0 1-.314.118l-2.775-.003a1.4 1.4 0 0 1-.613-.126.87.87 0 0 1-.388-.387 1.34 1.34 0 0 1-.129-.608v-2.318q0-.4-.151-.572-.151-.168-.55-.177a.35.35 0 0 1-.278-.132.42.42 0 0 1-.102-.28q0-.173.103-.287"/><path fill="currentColor" d="M5.437 10.36a.986.986 0 0 1-.994-.975c0-.538.446-.976.994-.976s.994.438.994.976a.986.986 0 0 1-.994.976M10.562 8.41c.548 0 .994.437.994.975a.986.986 0 0 1-.994.976.986.986 0 0 1-.994-.976c0-.538.446-.976.994-.976M8.74 2c.37 0 .446.15.446.275v.034q0 .034-.009.201-.01.162-.017.549-.018.378-.044 1.06c0 .106-.065.233-.375.233-.311 0-.376-.126-.376-.23l-.07-1.835v-.003c0-.13.078-.284.446-.284M7.256 2c.369 0 .446.15.446.275v.034q0 .034-.01.201-.007.162-.017.549-.017.378-.043 1.06c0 .106-.065.233-.376.233-.31 0-.375-.126-.375-.23l-.07-1.835v-.003C6.81 2.154 6.887 2 7.256 2"/></svg>',autohand:'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.66949 9.56637C4.66949 8.92122 4.13288 8.39823 3.47094 8.39823C2.809 8.39823 2.2724 8.92122 2.2724 9.56637C2.2724 10.2115 2.809 10.7345 3.47094 10.7345V11C2.65856 11 2 10.3581 2 9.56637C2 8.7746 2.65856 8.13274 3.47094 8.13274C4.28332 8.13274 4.94189 8.7746 4.94189 9.56637C4.94189 10.3581 4.28332 11 3.47094 11V10.7345C4.13288 10.7345 4.66949 10.2115 4.66949 9.56637Z" fill="currentColor"/><path d="M3.90678 9.59292C3.90678 9.81286 3.72385 9.99115 3.49818 9.99115C3.27252 9.99115 3.08959 9.81286 3.08959 9.59292C3.08959 9.37298 3.27252 9.19469 3.49818 9.19469C3.72385 9.19469 3.90678 9.37298 3.90678 9.59292Z" fill="currentColor"/><path d="M3.8523 9.59292C3.8523 9.40231 3.69376 9.24779 3.49818 9.24779C3.30261 9.24779 3.14407 9.40231 3.14407 9.59292C3.14407 9.78353 3.30261 9.93805 3.49818 9.93805V9.99115C3.27252 9.99115 3.08959 9.81286 3.08959 9.59292C3.08959 9.37298 3.27252 9.19469 3.49818 9.19469C3.72385 9.19469 3.90678 9.37298 3.90678 9.59292C3.90678 9.81286 3.72385 9.99115 3.49818 9.99115V9.93805C3.69376 9.93805 3.8523 9.78353 3.8523 9.59292Z" fill="currentColor"/><path d="M4.66949 6.43363C4.66949 5.78848 4.13288 5.26549 3.47094 5.26549C2.809 5.26549 2.2724 5.78848 2.2724 6.43363C2.2724 7.07878 2.809 7.60177 3.47094 7.60177V7.86726C2.65856 7.86726 2 7.2254 2 6.43363C2 5.64186 2.65856 5 3.47094 5C4.28332 5 4.94189 5.64186 4.94189 6.43363C4.94189 7.2254 4.28332 7.86726 3.47094 7.86726V7.60177C4.13288 7.60177 4.66949 7.07878 4.66949 6.43363Z" fill="currentColor"/><path d="M3.90678 6.46018C3.90678 6.68011 3.72385 6.85841 3.49818 6.85841C3.27252 6.85841 3.08959 6.68011 3.08959 6.46018C3.08959 6.24024 3.27252 6.06195 3.49818 6.06195C3.72385 6.06195 3.90678 6.24024 3.90678 6.46018Z" fill="currentColor"/><path d="M3.8523 6.46018C3.8523 6.26957 3.69376 6.11504 3.49818 6.11504C3.30261 6.11504 3.14407 6.26957 3.14407 6.46018C3.14407 6.65079 3.30261 6.80531 3.49818 6.80531V6.85841C3.27252 6.85841 3.08959 6.68011 3.08959 6.46018C3.08959 6.24024 3.27252 6.06195 3.49818 6.06195C3.72385 6.06195 3.90678 6.24024 3.90678 6.46018C3.90678 6.68011 3.72385 6.85841 3.49818 6.85841V6.80531C3.69376 6.80531 3.8523 6.65079 3.8523 6.46018Z" fill="currentColor"/><path d="M8.04722 9.56637C8.04722 8.92122 7.51061 8.39823 6.84867 8.39823C6.18673 8.39823 5.65012 8.92122 5.65012 9.56637C5.65012 10.2115 6.18673 10.7345 6.84867 10.7345V11C6.03629 11 5.37772 10.3581 5.37772 9.56637C5.37772 8.7746 6.03629 8.13274 6.84867 8.13274C7.66105 8.13274 8.31961 8.7746 8.31961 9.56637C8.31961 10.3581 7.66105 11 6.84867 11V10.7345C7.51061 10.7345 8.04722 10.2115 8.04722 9.56637Z" fill="currentColor"/><path d="M7.2845 9.59292C7.2845 9.81286 7.10157 9.99115 6.87591 9.99115C6.65025 9.99115 6.46731 9.81286 6.46731 9.59292C6.46731 9.37298 6.65025 9.19469 6.87591 9.19469C7.10157 9.19469 7.2845 9.37298 7.2845 9.59292Z" fill="currentColor"/><path d="M7.23002 9.59292C7.23002 9.40231 7.07148 9.24779 6.87591 9.24779C6.68033 9.24779 6.52179 9.40231 6.52179 9.59292C6.52179 9.78353 6.68033 9.93805 6.87591 9.93805V9.99115C6.65025 9.99115 6.46731 9.81286 6.46731 9.59292C6.46731 9.37298 6.65025 9.19469 6.87591 9.19469C7.10157 9.19469 7.2845 9.37298 7.2845 9.59292C7.2845 9.81286 7.10157 9.99115 6.87591 9.99115V9.93805C7.07148 9.93805 7.23002 9.78353 7.23002 9.59292Z" fill="currentColor"/><path d="M8.04722 6.43363C8.04722 5.78848 7.51061 5.26549 6.84867 5.26549C6.18673 5.26549 5.65012 5.78848 5.65012 6.43363C5.65012 7.07878 6.18673 7.60177 6.84867 7.60177V7.86726C6.03629 7.86726 5.37772 7.2254 5.37772 6.43363C5.37772 5.64186 6.03629 5 6.84867 5C7.66105 5 8.31961 5.64186 8.31961 6.43363C8.31961 7.2254 7.66105 7.86726 6.84867 7.86726V7.60177C7.51061 7.60177 8.04722 7.07878 8.04722 6.43363Z" fill="currentColor"/><path d="M7.2845 6.46018C7.2845 6.68011 7.10157 6.85841 6.87591 6.85841C6.65025 6.85841 6.46731 6.68011 6.46731 6.46018C6.46731 6.24024 6.65025 6.06195 6.87591 6.06195C7.10157 6.06195 7.2845 6.24024 7.2845 6.46018Z" fill="currentColor"/><path d="M7.23002 6.46018C7.23002 6.26957 7.07148 6.11504 6.87591 6.11504C6.68033 6.11504 6.52179 6.26957 6.52179 6.46018C6.52179 6.65079 6.68033 6.80531 6.87591 6.80531V6.85841C6.65025 6.85841 6.46731 6.68011 6.46731 6.46018C6.46731 6.24024 6.65025 6.06195 6.87591 6.06195C7.10157 6.06195 7.2845 6.24024 7.2845 6.46018C7.2845 6.68011 7.10157 6.85841 6.87591 6.85841V6.80531C7.07148 6.80531 7.23002 6.65079 7.23002 6.46018Z" fill="currentColor"/><path d="M11.207 9.56637C11.207 8.92122 10.6704 8.39823 10.0085 8.39823C9.34653 8.39823 8.80993 8.92122 8.80993 9.56637C8.80993 10.2115 9.34653 10.7345 10.0085 10.7345V11C9.19609 11 8.53753 10.3581 8.53753 9.56637C8.53753 8.7746 9.19609 8.13274 10.0085 8.13274C10.8209 8.13274 11.4794 8.7746 11.4794 9.56637C11.4794 10.3581 10.8209 11 10.0085 11V10.7345C10.6704 10.7345 11.207 10.2115 11.207 9.56637Z" fill="currentColor"/><path d="M10.4443 9.59292C10.4443 9.81286 10.2614 9.99115 10.0357 9.99115C9.81005 9.99115 9.62712 9.81286 9.62712 9.59292C9.62712 9.37298 9.81005 9.19469 10.0357 9.19469C10.2614 9.19469 10.4443 9.37298 10.4443 9.59292Z" fill="currentColor"/><path d="M10.3898 9.59292C10.3898 9.40231 10.2313 9.24779 10.0357 9.24779C9.84014 9.24779 9.6816 9.40231 9.6816 9.59292C9.6816 9.78353 9.84014 9.93805 10.0357 9.93805V9.99115C9.81005 9.99115 9.62712 9.81286 9.62712 9.59292C9.62712 9.37298 9.81005 9.19469 10.0357 9.19469C10.2614 9.19469 10.4443 9.37298 10.4443 9.59292C10.4443 9.81286 10.2614 9.99115 10.0357 9.99115V9.93805C10.2313 9.93805 10.3898 9.78353 10.3898 9.59292Z" fill="currentColor"/><path d="M11.207 6.43363C11.207 5.78848 10.6704 5.26549 10.0085 5.26549C9.34653 5.26549 8.80993 5.78848 8.80993 6.43363C8.80993 7.07878 9.34653 7.60177 10.0085 7.60177V7.86726C9.19609 7.86726 8.53753 7.2254 8.53753 6.43363C8.53753 5.64186 9.19609 5 10.0085 5C10.8209 5 11.4794 5.64186 11.4794 6.43363C11.4794 7.2254 10.8209 7.86726 10.0085 7.86726V7.60177C10.6704 7.60177 11.207 7.07878 11.207 6.43363Z" fill="currentColor"/><path d="M10.4443 6.46018C10.4443 6.68011 10.2614 6.85841 10.0357 6.85841C9.81005 6.85841 9.62712 6.68011 9.62712 6.46018C9.62712 6.24024 9.81005 6.06195 10.0357 6.06195C10.2614 6.06195 10.4443 6.24024 10.4443 6.46018Z" fill="currentColor"/><path d="M10.3898 6.46018C10.3898 6.26957 10.2313 6.11504 10.0357 6.11504C9.84014 6.11504 9.6816 6.26957 9.6816 6.46018C9.6816 6.65079 9.84014 6.80531 10.0357 6.80531V6.85841C9.81005 6.85841 9.62712 6.68011 9.62712 6.46018C9.62712 6.24024 9.81005 6.06195 10.0357 6.06195C10.2614 6.06195 10.4443 6.24024 10.4443 6.46018C10.4443 6.68011 10.2614 6.85841 10.0357 6.85841V6.80531C10.2313 6.80531 10.3898 6.65079 10.3898 6.46018Z" fill="currentColor"/><path d="M14.5847 9.56637C14.5847 8.92122 14.0481 8.39823 13.3862 8.39823C12.7243 8.39823 12.1877 8.92122 12.1877 9.56637C12.1877 10.2115 12.7243 10.7345 13.3862 10.7345V11C12.5738 11 11.9153 10.3581 11.9153 9.56637C11.9153 8.7746 12.5738 8.13274 13.3862 8.13274C14.1986 8.13274 14.8571 8.7746 14.8571 9.56637C14.8571 10.3581 14.1986 11 13.3862 11V10.7345C14.0481 10.7345 14.5847 10.2115 14.5847 9.56637Z" fill="currentColor"/><path d="M13.822 9.59292C13.822 9.81286 13.6391 9.99115 13.4134 9.99115C13.1878 9.99115 13.0048 9.81286 13.0048 9.59292C13.0048 9.37298 13.1878 9.19469 13.4134 9.19469C13.6391 9.19469 13.822 9.37298 13.822 9.59292Z" fill="currentColor"/><path d="M13.7676 9.59292C13.7676 9.40231 13.609 9.24779 13.4134 9.24779C13.2179 9.24779 13.0593 9.40231 13.0593 9.59292C13.0593 9.78353 13.2179 9.93805 13.4134 9.93805V9.99115C13.1878 9.99115 13.0048 9.81286 13.0048 9.59292C13.0048 9.37298 13.1878 9.19469 13.4134 9.19469C13.6391 9.19469 13.822 9.37298 13.822 9.59292C13.822 9.81286 13.6391 9.99115 13.4134 9.99115V9.93805C13.609 9.93805 13.7676 9.78353 13.7676 9.59292Z" fill="currentColor"/><path d="M14.5847 6.43363C14.5847 5.78848 14.0481 5.26549 13.3862 5.26549C12.7243 5.26549 12.1877 5.78848 12.1877 6.43363C12.1877 7.07878 12.7243 7.60177 13.3862 7.60177V7.86726C12.5738 7.86726 11.9153 7.2254 11.9153 6.43363C11.9153 5.64186 12.5738 5 13.3862 5C14.1986 5 14.8571 5.64186 14.8571 6.43363C14.8571 7.2254 14.1986 7.86726 13.3862 7.86726V7.60177C14.0481 7.60177 14.5847 7.07878 14.5847 6.43363Z" fill="currentColor"/><path d="M13.822 6.46018C13.822 6.68011 13.6391 6.85841 13.4134 6.85841C13.1878 6.85841 13.0048 6.68011 13.0048 6.46018C13.0048 6.24024 13.1878 6.06195 13.4134 6.06195C13.6391 6.06195 13.822 6.24024 13.822 6.46018Z" fill="currentColor"/><path d="M13.7676 6.46018C13.7676 6.26957 13.609 6.11504 13.4134 6.11504C13.2179 6.11504 13.0593 6.26957 13.0593 6.46018C13.0593 6.65079 13.2179 6.80531 13.4134 6.80531V6.85841C13.1878 6.85841 13.0048 6.68011 13.0048 6.46018C13.0048 6.24024 13.1878 6.06195 13.4134 6.06195C13.6391 6.06195 13.822 6.24024 13.822 6.46018C13.822 6.68011 13.6391 6.85841 13.4134 6.85841V6.80531C13.609 6.80531 13.7676 6.65079 13.7676 6.46018Z" fill="currentColor"/></svg>',"claude-acp":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 1200 1200"><path fill="currentColor" d="M 233.959793 800.214905 L 468.644287 668.536987 L 472.590637 657.100647 L 468.644287 650.738403 L 457.208069 650.738403 L 417.986633 648.322144 L 283.892639 644.69812 L 167.597321 639.865845 L 54.926208 633.825623 L 26.577238 627.785339 L 3.3e-05 592.751709 L 2.73832 575.27533 L 26.577238 559.248352 L 60.724873 562.228149 L 136.187973 567.382629 L 249.422867 575.194763 L 331.570496 580.026978 L 453.261841 592.671082 L 472.590637 592.671082 L 475.328857 584.859009 L 468.724915 580.026978 L 463.570557 575.194763 L 346.389313 495.785217 L 219.543671 411.865906 L 153.100723 363.543762 L 117.181267 339.060425 L 99.060455 316.107361 L 91.248367 266.01355 L 123.865784 230.093994 L 167.677887 233.073853 L 178.872513 236.053772 L 223.248367 270.201477 L 318.040283 343.570496 L 441.825592 434.738342 L 459.946411 449.798706 L 467.194672 444.64447 L 468.080597 441.020203 L 459.946411 427.409485 L 392.617493 305.718323 L 320.778564 181.932983 L 288.80542 130.630859 L 280.348999 99.865845 C 277.369171 87.221436 275.194641 76.590698 275.194641 63.624268 L 312.322174 13.20813 L 332.8591 6.604126 L 382.389313 13.20813 L 403.248352 31.328979 L 434.013519 101.71814 L 483.865753 212.537048 L 561.181274 363.221497 L 583.812134 407.919434 L 595.892639 449.315491 L 600.40271 461.959839 L 608.214783 461.959839 L 608.214783 454.711609 L 614.577271 369.825623 L 626.335632 265.61084 L 637.771851 131.516846 L 641.718201 93.745117 L 660.402832 48.483276 L 697.530334 24.000122 L 726.52356 37.852417 L 750.362549 72 L 747.060486 94.067139 L 732.886047 186.201416 L 705.100708 330.52356 L 686.979919 427.167847 L 697.530334 427.167847 L 709.61084 415.087341 L 758.496704 350.174561 L 840.644348 247.490051 L 876.885925 206.738342 L 919.167847 161.71814 L 946.308838 140.29541 L 997.61084 140.29541 L 1035.38269 196.429626 L 1018.469849 254.416199 L 965.637634 321.422852 L 921.825562 378.201538 L 859.006714 462.765259 L 819.785278 530.41626 L 823.409424 535.812073 L 832.75177 534.92627 L 974.657776 504.724915 L 1051.328979 490.872559 L 1142.818848 475.167786 L 1184.214844 494.496582 L 1188.724854 514.147644 L 1172.456421 554.335693 L 1074.604126 578.496765 L 959.838989 601.449829 L 788.939636 641.879272 L 786.845764 643.409485 L 789.261841 646.389343 L 866.255127 653.637634 L 899.194702 655.409424 L 979.812134 655.409424 L 1129.932861 666.604187 L 1169.154419 692.537109 L 1192.671265 724.268677 L 1188.724854 748.429688 L 1128.322144 779.194641 L 1046.818848 759.865845 L 856.590759 714.604126 L 791.355774 698.335754 L 782.335693 698.335754 L 782.335693 703.731567 L 836.69812 756.885986 L 936.322205 846.845581 L 1061.073975 962.81897 L 1067.436279 991.490112 L 1051.409424 1014.120911 L 1034.496704 1011.704712 L 924.885986 929.234924 L 882.604126 892.107544 L 786.845764 811.48999 L 780.483276 811.48999 L 780.483276 819.946289 L 802.550415 852.241699 L 919.087341 1027.409424 L 925.127625 1081.127686 L 916.671204 1098.604126 L 886.469849 1109.154419 L 853.288696 1103.114136 L 785.073914 1007.355835 L 714.684631 899.516785 L 657.906067 802.872498 L 650.979858 806.81897 L 617.476624 1167.704834 L 601.771851 1186.147705 L 565.530212 1200 L 535.328857 1177.046997 L 519.302124 1139.919556 L 535.328857 1066.550537 L 554.657776 970.792053 L 570.362488 894.68457 L 584.536926 800.134277 L 592.993347 768.724976 L 592.429626 766.630859 L 585.503479 767.516968 L 514.22821 865.369263 L 405.825531 1011.865906 L 320.053711 1103.677979 L 299.516815 1111.812256 L 263.919525 1093.369263 L 267.221497 1060.429688 L 287.114136 1031.114136 L 405.825531 880.107361 L 477.422913 786.52356 L 523.651062 732.483276 L 523.328918 724.671265 L 520.590698 724.671265 L 205.288605 929.395935 L 149.154434 936.644409 L 124.993355 914.01355 L 127.973183 876.885986 L 139.409409 864.80542 L 234.201385 799.570435 L 233.879227 799.8927 Z"/></svg>',cline:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 92 96" fill="currentColor"><path d="M65.45 16.3c10.89 0 19.71 8.86 19.71 19.8v6.6l5.74 11.46a4.48 4.48 0 0 1-.01 3.6L85.16 69.1v6.6c0 10.94-8.83 19.8-19.71 19.8H26.02c-10.89 0-19.71-8.86-19.71-19.8v-6.6L.45 57.8a4.48 4.48 0 0 1-.01-3.67L6.31 42.7v-6.6c0-10.94 8.83-19.8 19.71-19.8h39.43zm-2.52 5.7H29.19c-9.32 0-16.87 7.56-16.87 16.88v5.62l-4.88 9.46a4.48 4.48 0 0 0 .01 3.68l4.87 9.36v5.62c0 9.32 7.55 16.88 16.87 16.88h33.74c9.32 0 16.87-7.55 16.87-16.88V67l4.77-9.39a4.48 4.48 0 0 0 0-3.61L79.8 44.5v-5.62C79.8 29.56 72.25 22 62.93 22z" fill-rule="nonzero"/><circle cx="45.73" cy="11" r="11"/><rect stroke="currentColor" stroke-width="8" x="31" y="44.5" width="5" height="22" rx="2.5"/><rect stroke="currentColor" stroke-width="8" x="55" y="44.5" width="5" height="22" rx="2.5"/></svg>',"codebuddy-code":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M12.13 1.25c.15-.14.16-.14.28-.15.18 0 .36.08.64.34.68.62 1.61 1.89 2.2 2.97l.22.42.32.16c.3.16.81.48 1.02.65.09.08.11.08.21.04.45-.18 1.09.05 1.65.6.51.49 1 1.33 1.18 2.03.03.11.06.36.07.54.04.64-.16 1.14-.55 1.37-.08.04-.08.06-.08.26.02.95-.23 1.89-.74 2.82-.58 1.04-1.6 2.11-2.98 3.12-.74.55-2.5 1.58-3.3 1.95-1.9.86-3.43 1.2-4.76 1.03-.79-.09-1.69-.41-2.22-.77-.14-.1-.16-.1-.27-.07-.57.16-1.31-.18-1.94-.88-.25-.28-.66-.98-.79-1.35-.3-.87-.25-1.65.16-2.12.11-.12.09-.33.09-.33-.04-.33-.05-.82-.04-1.14v-.3l-.43-.79c-.68-1.23-1.12-2.25-1.28-3.04-.09-.43-.09-.62.02-.77.07-.09.28-.18.54-.22.66-.12 2.09-.01 3.69.27l.16.03.36-.32c.61-.54 1.01-.84 1.75-1.31.77-.48 1.64-.89 2.62-1.2l.32-.1.17-.46c.62-1.65 1.25-2.86 1.71-3.27h0Zm-5.19 8.45c-.7.41-1.05.61-1.3.84-1.04.93-1.43 2.39-.99 3.71.11.33.31.68.71 1.39.41.71.61 1.06.83 1.32.92 1.05 2.37 1.45 3.68 1 .32-.11.68-.31 1.38-.72l4.02-2.34c.7-.41 1.05-.61 1.3-.84 1.04-.93 1.43-2.39.99-3.71-.11-.33-.31-.68-.71-1.39s-.61-1.06-.83-1.32c-.92-1.05-2.37-1.45-3.68-1-.32.11-.67.31-1.38.72l-4.02 2.34Z"/><path fill="currentColor" fill-opacity="0.4" d="M8.02 12.13c.38-.22.87-.09 1.09.29l.86 1.5c.22.38.09.88-.29 1.09-.38.22-.86.09-1.09-.29l-.86-1.5c-.22-.38-.09-.87.29-1.09Z"/><path fill="currentColor" fill-opacity="0.4" d="M12.31 9.64c.38-.22.87-.09 1.09.29l.86 1.5c.22.38.09.87-.29 1.09s-.87.09-1.09-.29l-.86-1.5c-.22-.38-.09-.88.29-1.09Z"/></svg>',"codex-acp":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M22.282 9.821a5.985 5.985 0 0 0-.516-4.91 6.046 6.046 0 0 0-6.51-2.9A6.065 6.065 0 0 0 4.981 4.18a5.985 5.985 0 0 0-3.998 2.9 6.046 6.046 0 0 0 .743 7.097 5.98 5.98 0 0 0 .51 4.911 6.051 6.051 0 0 0 6.515 2.9A5.985 5.985 0 0 0 13.26 24a6.056 6.056 0 0 0 5.772-4.206 5.99 5.99 0 0 0 3.997-2.9 6.056 6.056 0 0 0-.747-7.073zM13.26 22.43a4.476 4.476 0 0 1-2.876-1.04l.141-.081 4.779-2.758a.795.795 0 0 0 .392-.681v-6.737l2.02 1.168a.071.071 0 0 1 .038.052v5.583a4.504 4.504 0 0 1-4.494 4.494zM3.6 18.304a4.47 4.47 0 0 1-.535-3.014l.142.085 4.783 2.759a.771.771 0 0 0 .78 0l5.843-3.369v2.332a.08.08 0 0 1-.033.062L9.74 19.95a4.5 4.5 0 0 1-6.14-1.646zM2.34 7.896a4.485 4.485 0 0 1 2.366-1.973V11.6a.766.766 0 0 0 .388.676l5.815 3.355-2.02 1.168a.076.076 0 0 1-.071 0l-4.83-2.786A4.504 4.504 0 0 1 2.34 7.872zm16.597 3.855l-5.833-3.387L15.119 7.2a.076.076 0 0 1 .071 0l4.83 2.791a4.494 4.494 0 0 1-.676 8.105v-5.678a.79.79 0 0 0-.407-.667zm2.01-3.023l-.141-.085-4.774-2.782a.776.776 0 0 0-.785 0L9.409 9.23V6.897a.066.066 0 0 1 .028-.061l4.83-2.787a4.5 4.5 0 0 1 6.68 4.66zm-12.64 4.135l-2.02-1.164a.08.08 0 0 1-.038-.057V6.075a4.5 4.5 0 0 1 7.375-3.453l-.142.08L8.704 5.46a.795.795 0 0 0-.393.681zm1.097-2.365l2.602-1.5 2.607 1.5v2.999l-2.597 1.5-2.607-1.5z"/></svg>',"cortex-code":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 362 362" overflow="hidden"><path fill="currentColor" fill-rule="evenodd" d="M1562.63,107.07h-4.18v5.15h4.18c1.94,0,3.21-.87,3.21-2.53,0-1.75-1.17-2.62-3.21-2.62ZM1553.3,102.31h9.42c5.15,0,8.55,2.82,8.55,7.19,0,2.72-1.36,4.76-3.4,6.02l3.69,5.34v1.07h-5.34l-3.59-5.15h-4.18v5.15h-5.15v-19.62ZM1579.63,112.51c0-10.49-6.99-18.46-17.68-18.46s-17.49,7.58-17.49,18.46,6.99,18.46,17.49,18.46,17.68-7.97,17.68-18.46ZM1584,112.51c0,12.34-8.26,22.63-22.05,22.63s-21.86-10.39-21.86-22.63,8.16-22.63,21.86-22.63,22.05,10.3,22.05,22.63ZM348.21,156.4l-42.55,24.61,42.55,24.54c10.75,6.22,14.42,19.9,8.21,30.67-6.2,10.7-19.92,14.37-30.63,8.18l-76.21-44c-5.08-2.96-8.61-7.59-10.18-12.8-.74-2.4-1.09-4.87-1-7.31.04-1.76.3-3.53.79-5.29,1.52-5.48,5.1-10.38,10.39-13.46l76.21-43.97c10.71-6.19,24.43-2.51,30.63,8.22,6.22,10.72,2.54,24.41-8.21,30.61ZM307.93,275.68l-76.19-43.94c-4.09-2.38-8.63-3.3-12.99-2.93-11.62.83-20.75,10.53-20.75,22.34v87.98c0,12.4,10,22.45,22.42,22.45s22.45-10.05,22.45-22.45v-49.21l42.66,24.63c10.72,6.23,24.43,2.54,30.61-8.17,6.17-10.74,2.53-24.5-8.21-30.7ZM220.01,189.61l-31.67,31.63c-.91.93-2.65,1.69-3.98,1.69h-9.31c-1.28,0-3.06-.76-3.98-1.69l-31.66-31.63c-.91-.89-1.64-2.68-1.64-3.94v-9.33c0-1.29.73-3.09,1.64-3.99l31.66-31.63c.92-.93,2.7-1.66,3.98-1.66h9.31c1.29,0,3.07.73,3.98,1.66l31.67,31.63c.9.9,1.63,2.7,1.63,3.99v9.33c0,1.26-.73,3.05-1.63,3.94ZM194.7,180.83c0-1.28-.77-3.06-1.68-4l-9.17-9.13c-.9-.9-2.68-1.65-3.96-1.65h-.36c-1.28,0-3.05.75-3.94,1.65l-9.17,9.13c-.92.95-1.62,2.73-1.62,4v.36c0,1.26.7,3.03,1.62,3.95l9.17,9.16c.9.9,2.67,1.65,3.94,1.65h.36c1.28,0,3.06-.75,3.96-1.65l9.17-9.16c.9-.92,1.68-2.68,1.68-3.95v-.36ZM51.48,86.28l76.21,43.99c4.09,2.35,8.64,3.29,13.01,2.93,11.6-.86,20.75-10.58,20.75-22.37V22.84c0-12.37-10.06-22.41-22.42-22.41s-22.45,10.05-22.45,22.41v49.23l-42.7-24.66c-10.71-6.2-24.4-2.53-30.61,8.2-6.19,10.76-2.53,24.47,8.2,30.67ZM218.75,133.19c4.36.36,8.9-.57,12.99-2.93l76.19-43.99c10.74-6.2,14.38-19.91,8.21-30.67-6.18-10.72-19.89-14.4-30.61-8.2l-42.66,24.66V22.84c0-12.37-10.03-22.41-22.45-22.41s-22.42,10.05-22.42,22.41v87.98c0,11.8,9.13,21.51,20.75,22.37ZM140.71,228.8c-4.38-.37-8.92.54-13.01,2.93l-76.21,43.94c-10.72,6.2-14.38,19.96-8.2,30.7,6.22,10.71,19.91,14.4,30.61,8.17l42.7-24.63v49.21c0,12.4,10.03,22.45,22.45,22.45s22.42-10.05,22.42-22.45v-87.98c0-11.81-9.16-21.51-20.75-22.34ZM120.04,187.6c.76-2.4,1.08-4.87,1.02-7.31-.09-1.76-.32-3.53-.82-5.29-1.51-5.48-5.08-10.38-10.44-13.46l-76.15-43.97c-10.75-6.19-24.45-2.51-30.63,8.22-6.23,10.72-2.55,24.41,8.2,30.61l42.55,24.61-42.55,24.54c-10.75,6.22-14.41,19.9-8.2,30.67,6.17,10.7,19.88,14.37,30.63,8.18l76.15-44c5.14-2.96,8.63-7.59,10.23-12.8Z"/></svg>',"corust-agent":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 12 12"><g transform="matrix(0.00160555,0,0,-0.0014599,-0.26812129,11.08482)" fill="currentColor"><path d="m 297,6493 c -4,-3 -7,-1357 -7,-3008 0,-2390 3,-3005 12,-3012 13,-10 1199,-9 1224,1 11,4 13,61 10,295 -2,159 -7,294 -10,299 -4,7 -112,11 -312,11 -168,0 -309,3 -314,6 -12,7 -13,4775 -2,4792 6,10 85,13 317,15 l 310,3 v 600 l -611,3 c -336,1 -614,-1 -617,-5 z"/><path d="m 6287,6493 c -4,-3 -7,-136 -7,-294 0,-219 3,-290 13,-296 6,-4 152,-10 322,-13 l 310,-5 3,-2394 c 1,-1545 -1,-2398 -8,-2405 -6,-6 -127,-9 -316,-7 -246,2 -309,0 -315,-11 -5,-7 -9,-145 -9,-305 V 470 l 23,-1 c 158,-4 1192,-2 1200,3 14,9 22,5964 7,6002 l -10,26 h -603 c -332,0 -607,-3 -610,-7 z"/><g transform="matrix(1.0249,0,0,1.0566,-429.39,51.322)"><path d="m 2476.7,5111.6 c -64.95,-6.2305 -71.077,-28.66 -73.528,-325.23 -3.6765,-261.68 4.9018,-351.4 36.764,-371.34 7.3528,-4.9844 583.32,-12.461 1276.9,-16.199 l 1262.2,-6.2306 73.528,-34.891 c 191.17,-90.966 300.24,-292.84 284.31,-527.1 -15.931,-223.05 -134.8,-392.52 -314.95,-449.85 -61.274,-19.938 -133.58,-21.184 -727.93,-18.692 -607.83,3.7384 -661.75,2.4922 -682.59,-17.446 -22.058,-19.938 -23.284,-43.614 -23.284,-331.47 0,-190.65 4.9019,-320.25 12.255,-335.2 11.029,-21.184 26.96,-23.676 123.77,-23.676 h 110.29 l 66.176,-63.552 c 36.764,-34.891 125,-125.86 198.53,-201.87 72.303,-76.013 322.3,-333.96 555.14,-571.96 l 424.01,-434.89 519.6,3.7383 c 390.93,2.4922 520.83,7.4767 520.83,18.692 0,7.4766 -223.04,249.22 -496.32,534.58 -562.49,589.41 -666.66,701.56 -660.53,707.79 2.451,2.4922 52.695,8.7227 111.52,13.707 322.3,24.922 593.13,194.39 790.43,495.95 129.9,199.38 187.5,391.28 196.08,660.44 8.5783,245.48 -14.706,368.85 -116.42,600.63 -123.77,286.61 -328.43,492.21 -596.8,601.87 -232.84,95.95 -167.89,92.212 -1574.7,93.458 -691.17,1.2462 -1274.5,1.2462 -1295.3,-1.2461 z"/><path d="m 2430.1,3942.7 c -24.509,-18.692 -24.509,-33.645 -24.509,-1254.8 0,-1163.9 1.2255,-1238.6 22.058,-1271 l 20.833,-33.645 h 337 c 289.21,0 338.23,2.4922 354.16,19.938 18.382,17.446 19.608,145.79 18.382,1267.3 -1.2255,1115.3 -2.4509,1251.1 -19.608,1271 -18.382,18.692 -50.244,21.184 -351.71,21.184 -276.96,-1.2461 -335.78,-3.7383 -356.61,-19.938 z"/></g></g></svg>',"crow-cli":'<svg width="16" height="16" viewBox="0 0 366 368" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="m 26,275.93574 c 0.65,-9.32 8.46,-15.43 15,-20.96 15.43,-13.04 35.67,-21.92 53,-32.71 20.67,-12.88 61.58,-40.31 80,-55.03 0,0 21,-18.39 21,-18.39 0,0 28,-23.91 28,-23.91 10,-8.33 14.1,-11.65 25,-18.92 7.42,-4.94 19.07,-12.550001 24.52,-19.330001 7.17,-8.93 4.16,-18.82 -4.53,-25.45 -5.67,-4.32 -23.5,-8.94 -30.99,-10.66 -3.1,-0.72 -11.45,-1.57 -13.38,-3.62 -3.22,-3.43 1.67,-6.99 4.38,-8.45 6.61,-3.54 17.51,-5.73 25,-5.82 0,0 4,0 4,0 16.51,-0.2 18.85,-12.47 40,-11.99 9.26,0.21 21.16,2.48 29,7.54 7.87,5.07 12.2,11.73 17.05,19.45 6.31,10.05 12.35,21.16 14.49,33 1.42,7.88 -0.45,13.62 -0.54,21.000001 -0.28,24.26 6.68,37.92 -2.44,63 -5.9,16.24 -14.87,35.36 -23.98,50 -9.34,15 -20.81,30.64 -35.58,40.64 0,0 -16,9.36 -16,9.36 -3.3,1.9 -6.18,2.94 -6.64,7.04 -0.68,2.83 -0.16,7.11 0,9.96 0,0 1.29,8 1.29,8 1.62,5.16 8.51,12.15 12.35,16 3.36,3.37 6.84,7.82 12,7.89 4.2,0.06 8.14,-2.87 12,-4.44 5.24,-2.13 11.35,-3.55 17,-3.94 6.33,-0.43 17.05,1.85 14,10.49 -2.84,-3.54 -6.09,-6.36 -11,-5.57 -2.47,0.4 -10.06,3.6 -8.09,7.08 1.19,2.08 7.67,3.01 10.09,3.88 6.26,2.25 10.83,5.76 14,11.61 0,0 -17,-6.33 -17,-6.33 -9.74,-2.08 -18.73,0.62 -28,3.33 5.49,3.71 8.06,5.51 12,11 -8.23,-1.96 -13.6,-7.46 -26,-6.96 -9.64,0.39 -11.89,4.13 -27,3.96 -9.42,-0.11 -17.78,-4.36 -27,-3.96 -9.45,0.41 -13.16,5.64 -21,8.96 3.16,-14.88 19.73,-16 32,-16 -7.31,-10.21 -20.46,-18.11 -23.28,-26 -0.7,-1.97 -0.69,-3.94 -0.71,-6 0,0 0,-14 0,-14 0.23,-2.35 1.13,-5.62 0,-7.73 -1.66,-2.77 -8.94,-4.64 -12.01,-5.55 -20.1,-5.96 -24.58,-0.84 -43,2.01 0,0 -14,2.11 -14,2.11 -9.78,1.06 -18.83,0.92 -28,5.02 0,0 -15,7.88 -15,7.88 -16.76,8.6 -42.02,22.27 -59,27.93 -9.14,3.04 -16.2,6.24 -26,6.33 0,0 5,-10 5,-10 -3.92,0.18 -15.76,3.08 -17.92,-0.51 -2.44,-4.07 5.28,-9.01 7.92,-10.91 0,0 36,-24.58 36,-24.58 0,0 -19,3.25 -19,3.25 z m 227,1.75 c -2.98,0.84 -11.45,3.61 -12.96,6.27 -0.95,1.89 -0.18,5.54 0,7.73 0.04,2.47 -0.13,4.56 0.61,7 1.52,5.07 11.84,17.33 16.35,19.88 3.38,1.91 15.93,0.11 20,-0.88 -4.12,-8.71 -16.66,-15.05 -21.99,-24 -3.43,-5.75 -0.8,-10.06 -2.01,-16 z" /></svg>',cursor:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 466.73 532.09"><path fill="currentColor" d="M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"/></svg>',deepagents:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 128 128"><path fill="currentColor" d="M40.1024 85.0722C47.6207 77.5537 51.8469 67.3453 51.8469 56.7136C51.8469 46.0818 47.617 35.8734 40.1024 28.355L11.7446 0C4.22995 7.5185 0 17.7269 0 28.3586C0 38.9903 4.22995 49.1987 11.7446 56.7172L40.0987 85.0722H40.1024Z"/><path fill="currentColor" d="M99.4385 87.698C91.9239 80.1832 81.7121 75.9531 71.0844 75.9531C60.4566 75.9531 50.2448 80.1832 42.7266 87.698L71.0844 116.057C78.599 123.571 88.8107 127.802 99.4421 127.802C110.074 127.802 120.282 123.571 127.8 116.057L99.4421 87.698H99.4385Z"/><path fill="currentColor" d="M11.8146 115.987C19.3329 123.502 29.541 127.732 40.1724 127.732V87.6289H0.0664062C0.0700559 98.2606 4.29635 108.469 11.8146 115.987Z"/><path fill="currentColor" d="M110.387 45.7684C102.869 38.2535 92.6608 34.0198 82.0258 34.0234C71.3943 34.0234 61.1863 38.2535 53.668 45.772L82.0258 74.1306L110.387 45.7684Z"/></svg>',devin:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 263 300"><path fill="currentColor" d="M1.84577e-10 100.797V38.6224C1.88813e-05 35.8899 1.45777 33.365 3.82414 31.9988L57.6539 0.920185C60.0203 -0.446051 62.9358 -0.446051 65.3022 0.920185L119.132 31.9988C121.498 33.3651 122.956 35.8899 122.956 38.6224V70.375C123.192 80.9262 128.769 91.103 138.577 96.7655C148.384 102.428 159.986 102.169 169.242 97.0979L196.74 81.2217C199.107 79.8554 202.022 79.8554 204.388 81.2217L258.218 112.3C260.585 113.667 262.042 116.191 262.042 118.924V181.081C262.042 183.814 260.585 186.339 258.218 187.705L204.388 218.783C202.022 220.15 199.107 220.15 196.74 218.783L169.464 203.036C160.173 197.847 148.465 197.536 138.579 203.244C128.772 208.906 123.195 219.083 122.959 229.634V261.378C122.959 264.111 121.501 266.635 119.135 268.002L65.3048 299.08C62.9384 300.447 60.0229 300.447 57.6566 299.08L3.82673 268.002C1.46036 266.635 0.00260562 264.111 0.00260562 261.378V199.221C0.0026245 196.488 1.46038 193.963 3.82675 192.597L57.6565 161.519C60.0229 160.152 62.9384 160.152 65.3048 161.519L92.8656 177.431C102.11 182.467 113.679 182.711 123.463 177.062C133.349 171.355 138.934 161.06 139.086 150.419C138.85 139.868 133.274 128.601 123.466 122.938C113.658 117.276 102.056 117.534 92.8007 122.606L65.1758 138.645C62.7991 140.025 59.8649 140.024 57.4894 138.642L3.80216 107.407C1.44816 106.038 -1.88809e-05 103.52 1.84577e-10 100.797Z"/></svg>',dimcode:'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.12109 11.0078H1.99902V5.49316H3.12109V11.0078ZM3.7041 5.49316C4.91979 5.49316 5.31142 5.57449 5.80762 5.7373C6.50208 5.97365 6.85299 6.40958 6.86133 7.04492V9.45605C6.86125 10.207 6.37767 10.6797 5.41016 10.874C4.95546 10.9633 4.69632 11.0078 3.7041 11.0078V10.6064C4.72131 10.6064 4.95994 10.5507 5.34863 10.4404C5.91072 10.2671 6.19576 9.93907 6.2041 9.45605V7.04492C6.20402 6.4883 5.83211 6.13886 5.08789 5.99707C4.74057 5.93405 4.58897 5.89978 3.7041 5.89453V5.49316ZM9.16797 5.49316V11.0078H8.0459V5.49316H9.16797ZM14 6.79297V11.0078H12.8779V8.0791L13.8877 6.79297H14ZM14 5.49316V5.7373L11.3594 8.97852H10.7852L9.74219 6.94531V6.07812H9.86719L11.0723 8.33203L13.4258 5.49316H14Z" fill="currentColor"/></svg>',dirac:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor"><text x="8" y="10" text-anchor="middle" font-size="10.5" font-family="Georgia, serif" font-style="italic" fill="currentColor">δ</text><line x1="1" y1="14" x2="15" y2="14" stroke="currentColor" stroke-opacity="0.4" stroke-width="1" stroke-linecap="round"/><line x1="8" y1="14" x2="8" y2="12" stroke="currentColor" stroke-width="1" stroke-linecap="round"/><circle cx="8" cy="11.5" r="0.7" fill="currentColor"/></svg>',"factory-droid":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 900 900" fill="none"><path fill="currentColor" d="M622.037 192.524a10.58 10.58 0 0 1-4.056-2.001 10.573 10.573 0 0 1-3.98-7.89 10.595 10.595 0 0 1 .804-4.452c20.214-49.194 29.134-88.555 14.74-105.033-38.123-43.716-191.004 43.219-239.75 72.663a10.596 10.596 0 0 1-10.841.041 10.576 10.576 0 0 1-4.396-5.07c-20.491-49.089-42.031-83.233-63.865-84.714-57.871-3.96-104.516 165.624-118.17 220.895a10.574 10.574 0 0 1-1.993 4.057 10.572 10.572 0 0 1-7.884 3.977 10.586 10.586 0 0 1-4.447-.802c-49.194-20.215-88.572-29.134-105.033-14.74-43.717 38.123 43.202 191.005 72.644 239.75a10.553 10.553 0 0 1 1.454 4.279 10.573 10.573 0 0 1-6.481 10.958c-49.072 20.491-83.216 42.031-84.715 63.864-3.944 57.871 165.624 104.516 220.913 118.171a10.566 10.566 0 0 1 5.658 3.601 10.57 10.57 0 0 1 2.355 6.281 10.58 10.58 0 0 1-.799 4.442c-20.214 49.194-29.134 88.572-14.739 105.033 38.121 43.717 191.021-43.202 239.767-72.644a10.566 10.566 0 0 1 15.238 5.027c20.489 49.072 42.013 83.216 63.862 84.715 57.871 3.944 104.516-165.624 118.153-220.913a10.603 10.603 0 0 1 9.895-8.021 10.566 10.566 0 0 1 4.449.808c49.193 20.214 88.553 29.116 105.032 14.738 43.718-38.121-43.219-191.022-72.663-239.767a10.602 10.602 0 0 1 1.326-12.655 10.604 10.604 0 0 1 3.703-2.582c49.089-20.49 83.233-42.031 84.714-63.863 3.96-57.871-165.624-104.516-220.895-118.153Zm-66.394-55.478c11.123 19.938-46.196 152.797-88.83 245.724a8.36 8.36 0 0 1-8.239 4.855 8.374 8.374 0 0 1-7.412-6.043c-17.219-60.42-36.899-131.411-57.957-191.675a10.557 10.557 0 0 1 4.924-12.759c52.586-28.721 142.568-66.86 157.514-40.102ZM303.635 153.49c21.953 6.233 75.365 140.709 110.92 236.564a8.364 8.364 0 0 1-2.394 9.249 8.364 8.364 0 0 1-9.504.978c-54.943-30.493-119.013-66.824-176.522-94.546a10.565 10.565 0 0 1-5.528-12.501c16.926-57.44 53.532-148.095 83.028-139.744ZM137.064 343.322c19.921-11.123 152.795 46.197 245.707 88.83a8.369 8.369 0 0 1-1.189 15.652c-60.401 17.219-131.411 36.899-191.675 57.957a10.552 10.552 0 0 1-12.742-4.925c-28.668-52.584-66.876-142.568-40.101-157.514Zm16.443 252.009c6.217-21.953 140.709-75.365 236.564-110.921a8.368 8.368 0 0 1 10.227 11.898c-30.511 54.945-66.842 119.014-94.563 176.507a10.548 10.548 0 0 1-5.229 5.075 10.544 10.544 0 0 1-7.271.468c-57.441-16.822-148.095-53.531-139.728-83.027ZM343.34 761.902c-11.14-19.922 46.197-152.796 88.829-245.707a8.383 8.383 0 0 1 5.713-4.66 8.38 8.38 0 0 1 7.182 1.664 8.371 8.371 0 0 1 2.758 4.184c17.217 60.403 36.898 131.412 57.957 191.675a10.558 10.558 0 0 1-4.942 12.743c-52.568 28.668-142.568 66.875-157.445 40.101h-.052Zm252.009-16.443c-21.971-6.216-75.383-140.709-110.939-236.564a8.37 8.37 0 0 1 11.916-10.228c54.926 30.494 119.014 66.842 176.506 94.563a10.538 10.538 0 0 1 5.527 12.502c-16.909 57.526-53.515 148.094-83.01 139.727Zm166.57-189.834c-19.938 11.141-152.796-46.197-245.724-88.83a8.367 8.367 0 0 1-2.993-12.892 8.378 8.378 0 0 1 4.182-2.759c60.419-17.218 131.41-36.899 191.675-57.958a10.577 10.577 0 0 1 12.758 4.943c28.652 52.568 66.86 142.569 40.102 157.496Zm-16.444-252.009c-6.232 21.971-140.709 75.383-236.562 110.94a8.371 8.371 0 0 1-10.229-11.917c30.495-54.926 66.825-119.012 94.547-176.505a10.555 10.555 0 0 1 12.5-5.528c57.441 16.909 148.096 53.516 139.744 83.01Z"/></svg>',"fast-agent":'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360" width="16" height="16"><g fill="currentColor"><circle cx="100.50" cy="40.50" r="4.50"/><circle cx="112.50" cy="40.50" r="4.50"/><circle cx="124.50" cy="40.50" r="4.50"/><circle cx="136.50" cy="40.50" r="4.50"/><circle cx="148.50" cy="40.50" r="4.50"/><circle cx="76.50" cy="52.50" r="4.50"/><circle cx="88.50" cy="52.50" r="4.50"/><circle cx="100.50" cy="52.50" r="4.50"/><circle cx="136.50" cy="52.50" r="4.50"/><circle cx="148.50" cy="52.50" r="4.50"/><circle cx="160.50" cy="52.50" r="4.50"/><circle cx="64.50" cy="64.50" r="4.50"/><circle cx="76.50" cy="64.50" r="4.50"/><circle cx="88.50" cy="64.50" r="4.50"/><circle cx="100.50" cy="64.50" r="4.50"/><circle cx="136.50" cy="64.50" r="4.50"/><circle cx="148.50" cy="64.50" r="4.50"/><circle cx="160.50" cy="64.50" r="4.50"/><circle cx="172.50" cy="64.50" r="4.50"/><circle cx="52.50" cy="76.50" r="4.50"/><circle cx="64.50" cy="76.50" r="4.50"/><circle cx="76.50" cy="76.50" r="4.50"/><circle cx="88.50" cy="76.50" r="4.50"/><circle cx="100.50" cy="76.50" r="4.50"/><circle cx="136.50" cy="76.50" r="4.50"/><circle cx="148.50" cy="76.50" r="4.50"/><circle cx="160.50" cy="76.50" r="4.50"/><circle cx="52.50" cy="88.50" r="4.50"/><circle cx="64.50" cy="88.50" r="4.50"/><circle cx="76.50" cy="88.50" r="4.50"/><circle cx="88.50" cy="88.50" r="4.50"/><circle cx="100.50" cy="88.50" r="4.50"/><circle cx="148.50" cy="88.50" r="4.50"/><circle cx="52.50" cy="100.50" r="4.50"/><circle cx="64.50" cy="100.50" r="4.50"/><circle cx="76.50" cy="100.50" r="4.50"/><circle cx="88.50" cy="100.50" r="4.50"/><circle cx="100.50" cy="100.50" r="4.50"/><circle cx="52.50" cy="112.50" r="4.50"/><circle cx="64.50" cy="112.50" r="4.50"/><circle cx="76.50" cy="112.50" r="4.50"/><circle cx="88.50" cy="112.50" r="4.50"/><circle cx="100.50" cy="112.50" r="4.50"/><circle cx="52.50" cy="124.50" r="4.50"/><circle cx="64.50" cy="124.50" r="4.50"/><circle cx="76.50" cy="124.50" r="4.50"/><circle cx="88.50" cy="124.50" r="4.50"/><circle cx="100.50" cy="124.50" r="4.50"/><circle cx="232.50" cy="124.50" r="4.50"/><circle cx="244.50" cy="124.50" r="4.50"/><circle cx="256.50" cy="124.50" r="4.50"/><circle cx="28.50" cy="136.50" r="4.50"/><circle cx="40.50" cy="136.50" r="4.50"/><circle cx="52.50" cy="136.50" r="4.50"/><circle cx="64.50" cy="136.50" r="4.50"/><circle cx="76.50" cy="136.50" r="4.50"/><circle cx="88.50" cy="136.50" r="4.50"/><circle cx="100.50" cy="136.50" r="4.50"/><circle cx="112.50" cy="136.50" r="4.50"/><circle cx="124.50" cy="136.50" r="4.50"/><circle cx="196.50" cy="136.50" r="4.50"/><circle cx="208.50" cy="136.50" r="4.50"/><circle cx="220.50" cy="136.50" r="4.50"/><circle cx="232.50" cy="136.50" r="4.50"/><circle cx="244.50" cy="136.50" r="4.50"/><circle cx="256.50" cy="136.50" r="4.50"/><circle cx="268.50" cy="136.50" r="4.50"/><circle cx="280.50" cy="136.50" r="4.50"/><circle cx="28.50" cy="148.50" r="4.50"/><circle cx="40.50" cy="148.50" r="4.50"/><circle cx="52.50" cy="148.50" r="4.50"/><circle cx="64.50" cy="148.50" r="4.50"/><circle cx="76.50" cy="148.50" r="4.50"/><circle cx="88.50" cy="148.50" r="4.50"/><circle cx="100.50" cy="148.50" r="4.50"/><circle cx="112.50" cy="148.50" r="4.50"/><circle cx="124.50" cy="148.50" r="4.50"/><circle cx="172.50" cy="148.50" r="4.50"/><circle cx="184.50" cy="148.50" r="4.50"/><circle cx="196.50" cy="148.50" r="4.50"/><circle cx="256.50" cy="148.50" r="4.50"/><circle cx="268.50" cy="148.50" r="4.50"/><circle cx="280.50" cy="148.50" r="4.50"/><circle cx="292.50" cy="148.50" r="4.50"/><circle cx="52.50" cy="160.50" r="4.50"/><circle cx="64.50" cy="160.50" r="4.50"/><circle cx="76.50" cy="160.50" r="4.50"/><circle cx="88.50" cy="160.50" r="4.50"/><circle cx="100.50" cy="160.50" r="4.50"/><circle cx="160.50" cy="160.50" r="4.50"/><circle cx="172.50" cy="160.50" r="4.50"/><circle cx="184.50" cy="160.50" r="4.50"/><circle cx="196.50" cy="160.50" r="4.50"/><circle cx="256.50" cy="160.50" r="4.50"/><circle cx="268.50" cy="160.50" r="4.50"/><circle cx="280.50" cy="160.50" r="4.50"/><circle cx="292.50" cy="160.50" r="4.50"/><circle cx="304.50" cy="160.50" r="4.50"/><circle cx="52.50" cy="172.50" r="4.50"/><circle cx="64.50" cy="172.50" r="4.50"/><circle cx="76.50" cy="172.50" r="4.50"/><circle cx="88.50" cy="172.50" r="4.50"/><circle cx="100.50" cy="172.50" r="4.50"/><circle cx="160.50" cy="172.50" r="4.50"/><circle cx="172.50" cy="172.50" r="4.50"/><circle cx="184.50" cy="172.50" r="4.50"/><circle cx="196.50" cy="172.50" r="4.50"/><circle cx="208.50" cy="172.50" r="4.50"/><circle cx="256.50" cy="172.50" r="4.50"/><circle cx="268.50" cy="172.50" r="4.50"/><circle cx="280.50" cy="172.50" r="4.50"/><circle cx="292.50" cy="172.50" r="4.50"/><circle cx="304.50" cy="172.50" r="4.50"/><circle cx="52.50" cy="184.50" r="4.50"/><circle cx="64.50" cy="184.50" r="4.50"/><circle cx="76.50" cy="184.50" r="4.50"/><circle cx="88.50" cy="184.50" r="4.50"/><circle cx="100.50" cy="184.50" r="4.50"/><circle cx="160.50" cy="184.50" r="4.50"/><circle cx="172.50" cy="184.50" r="4.50"/><circle cx="184.50" cy="184.50" r="4.50"/><circle cx="196.50" cy="184.50" r="4.50"/><circle cx="208.50" cy="184.50" r="4.50"/><circle cx="256.50" cy="184.50" r="4.50"/><circle cx="268.50" cy="184.50" r="4.50"/><circle cx="280.50" cy="184.50" r="4.50"/><circle cx="292.50" cy="184.50" r="4.50"/><circle cx="304.50" cy="184.50" r="4.50"/><circle cx="52.50" cy="196.50" r="4.50"/><circle cx="64.50" cy="196.50" r="4.50"/><circle cx="76.50" cy="196.50" r="4.50"/><circle cx="88.50" cy="196.50" r="4.50"/><circle cx="100.50" cy="196.50" r="4.50"/><circle cx="172.50" cy="196.50" r="4.50"/><circle cx="184.50" cy="196.50" r="4.50"/><circle cx="196.50" cy="196.50" r="4.50"/><circle cx="256.50" cy="196.50" r="4.50"/><circle cx="268.50" cy="196.50" r="4.50"/><circle cx="280.50" cy="196.50" r="4.50"/><circle cx="292.50" cy="196.50" r="4.50"/><circle cx="304.50" cy="196.50" r="4.50"/><circle cx="52.50" cy="208.50" r="4.50"/><circle cx="64.50" cy="208.50" r="4.50"/><circle cx="76.50" cy="208.50" r="4.50"/><circle cx="88.50" cy="208.50" r="4.50"/><circle cx="100.50" cy="208.50" r="4.50"/><circle cx="244.50" cy="208.50" r="4.50"/><circle cx="256.50" cy="208.50" r="4.50"/><circle cx="268.50" cy="208.50" r="4.50"/><circle cx="280.50" cy="208.50" r="4.50"/><circle cx="292.50" cy="208.50" r="4.50"/><circle cx="304.50" cy="208.50" r="4.50"/><circle cx="52.50" cy="220.50" r="4.50"/><circle cx="64.50" cy="220.50" r="4.50"/><circle cx="76.50" cy="220.50" r="4.50"/><circle cx="88.50" cy="220.50" r="4.50"/><circle cx="100.50" cy="220.50" r="4.50"/><circle cx="220.50" cy="220.50" r="4.50"/><circle cx="232.50" cy="220.50" r="4.50"/><circle cx="256.50" cy="220.50" r="4.50"/><circle cx="268.50" cy="220.50" r="4.50"/><circle cx="280.50" cy="220.50" r="4.50"/><circle cx="292.50" cy="220.50" r="4.50"/><circle cx="304.50" cy="220.50" r="4.50"/><circle cx="52.50" cy="232.50" r="4.50"/><circle cx="64.50" cy="232.50" r="4.50"/><circle cx="76.50" cy="232.50" r="4.50"/><circle cx="88.50" cy="232.50" r="4.50"/><circle cx="100.50" cy="232.50" r="4.50"/><circle cx="196.50" cy="232.50" r="4.50"/><circle cx="208.50" cy="232.50" r="4.50"/><circle cx="220.50" cy="232.50" r="4.50"/><circle cx="256.50" cy="232.50" r="4.50"/><circle cx="268.50" cy="232.50" r="4.50"/><circle cx="280.50" cy="232.50" r="4.50"/><circle cx="292.50" cy="232.50" r="4.50"/><circle cx="304.50" cy="232.50" r="4.50"/><circle cx="52.50" cy="244.50" r="4.50"/><circle cx="64.50" cy="244.50" r="4.50"/><circle cx="76.50" cy="244.50" r="4.50"/><circle cx="88.50" cy="244.50" r="4.50"/><circle cx="100.50" cy="244.50" r="4.50"/><circle cx="184.50" cy="244.50" r="4.50"/><circle cx="196.50" cy="244.50" r="4.50"/><circle cx="208.50" cy="244.50" r="4.50"/><circle cx="256.50" cy="244.50" r="4.50"/><circle cx="268.50" cy="244.50" r="4.50"/><circle cx="280.50" cy="244.50" r="4.50"/><circle cx="292.50" cy="244.50" r="4.50"/><circle cx="304.50" cy="244.50" r="4.50"/><circle cx="52.50" cy="256.50" r="4.50"/><circle cx="64.50" cy="256.50" r="4.50"/><circle cx="76.50" cy="256.50" r="4.50"/><circle cx="88.50" cy="256.50" r="4.50"/><circle cx="100.50" cy="256.50" r="4.50"/><circle cx="172.50" cy="256.50" r="4.50"/><circle cx="184.50" cy="256.50" r="4.50"/><circle cx="196.50" cy="256.50" r="4.50"/><circle cx="208.50" cy="256.50" r="4.50"/><circle cx="256.50" cy="256.50" r="4.50"/><circle cx="268.50" cy="256.50" r="4.50"/><circle cx="280.50" cy="256.50" r="4.50"/><circle cx="292.50" cy="256.50" r="4.50"/><circle cx="304.50" cy="256.50" r="4.50"/><circle cx="52.50" cy="268.50" r="4.50"/><circle cx="64.50" cy="268.50" r="4.50"/><circle cx="76.50" cy="268.50" r="4.50"/><circle cx="88.50" cy="268.50" r="4.50"/><circle cx="100.50" cy="268.50" r="4.50"/><circle cx="160.50" cy="268.50" r="4.50"/><circle cx="172.50" cy="268.50" r="4.50"/><circle cx="184.50" cy="268.50" r="4.50"/><circle cx="196.50" cy="268.50" r="4.50"/><circle cx="256.50" cy="268.50" r="4.50"/><circle cx="268.50" cy="268.50" r="4.50"/><circle cx="280.50" cy="268.50" r="4.50"/><circle cx="292.50" cy="268.50" r="4.50"/><circle cx="304.50" cy="268.50" r="4.50"/><circle cx="52.50" cy="280.50" r="4.50"/><circle cx="64.50" cy="280.50" r="4.50"/><circle cx="76.50" cy="280.50" r="4.50"/><circle cx="88.50" cy="280.50" r="4.50"/><circle cx="100.50" cy="280.50" r="4.50"/><circle cx="160.50" cy="280.50" r="4.50"/><circle cx="172.50" cy="280.50" r="4.50"/><circle cx="184.50" cy="280.50" r="4.50"/><circle cx="196.50" cy="280.50" r="4.50"/><circle cx="208.50" cy="280.50" r="4.50"/><circle cx="256.50" cy="280.50" r="4.50"/><circle cx="268.50" cy="280.50" r="4.50"/><circle cx="280.50" cy="280.50" r="4.50"/><circle cx="292.50" cy="280.50" r="4.50"/><circle cx="304.50" cy="280.50" r="4.50"/><circle cx="52.50" cy="292.50" r="4.50"/><circle cx="64.50" cy="292.50" r="4.50"/><circle cx="76.50" cy="292.50" r="4.50"/><circle cx="88.50" cy="292.50" r="4.50"/><circle cx="100.50" cy="292.50" r="4.50"/><circle cx="160.50" cy="292.50" r="4.50"/><circle cx="172.50" cy="292.50" r="4.50"/><circle cx="184.50" cy="292.50" r="4.50"/><circle cx="196.50" cy="292.50" r="4.50"/><circle cx="208.50" cy="292.50" r="4.50"/><circle cx="220.50" cy="292.50" r="4.50"/><circle cx="232.50" cy="292.50" r="4.50"/><circle cx="244.50" cy="292.50" r="4.50"/><circle cx="256.50" cy="292.50" r="4.50"/><circle cx="268.50" cy="292.50" r="4.50"/><circle cx="280.50" cy="292.50" r="4.50"/><circle cx="292.50" cy="292.50" r="4.50"/><circle cx="304.50" cy="292.50" r="4.50"/><circle cx="52.50" cy="304.50" r="4.50"/><circle cx="64.50" cy="304.50" r="4.50"/><circle cx="76.50" cy="304.50" r="4.50"/><circle cx="88.50" cy="304.50" r="4.50"/><circle cx="100.50" cy="304.50" r="4.50"/><circle cx="160.50" cy="304.50" r="4.50"/><circle cx="172.50" cy="304.50" r="4.50"/><circle cx="184.50" cy="304.50" r="4.50"/><circle cx="196.50" cy="304.50" r="4.50"/><circle cx="208.50" cy="304.50" r="4.50"/><circle cx="220.50" cy="304.50" r="4.50"/><circle cx="232.50" cy="304.50" r="4.50"/><circle cx="256.50" cy="304.50" r="4.50"/><circle cx="268.50" cy="304.50" r="4.50"/><circle cx="280.50" cy="304.50" r="4.50"/><circle cx="292.50" cy="304.50" r="4.50"/><circle cx="304.50" cy="304.50" r="4.50"/><circle cx="316.50" cy="304.50" r="4.50"/><circle cx="328.50" cy="304.50" r="4.50"/><circle cx="28.50" cy="316.50" r="4.50"/><circle cx="40.50" cy="316.50" r="4.50"/><circle cx="52.50" cy="316.50" r="4.50"/><circle cx="64.50" cy="316.50" r="4.50"/><circle cx="76.50" cy="316.50" r="4.50"/><circle cx="88.50" cy="316.50" r="4.50"/><circle cx="100.50" cy="316.50" r="4.50"/><circle cx="112.50" cy="316.50" r="4.50"/><circle cx="124.50" cy="316.50" r="4.50"/><circle cx="172.50" cy="316.50" r="4.50"/><circle cx="184.50" cy="316.50" r="4.50"/><circle cx="196.50" cy="316.50" r="4.50"/><circle cx="208.50" cy="316.50" r="4.50"/><circle cx="220.50" cy="316.50" r="4.50"/><circle cx="268.50" cy="316.50" r="4.50"/><circle cx="280.50" cy="316.50" r="4.50"/><circle cx="292.50" cy="316.50" r="4.50"/><circle cx="304.50" cy="316.50" r="4.50"/><circle cx="316.50" cy="316.50" r="4.50"/></g></svg>',gemini:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M11.04 19.32Q12 21.51 12 24q0-2.49.93-4.68.96-2.19 2.58-3.81t3.81-2.55Q21.51 12 24 12q-2.49 0-4.68-.93a12.3 12.3 0 0 1-3.81-2.58 12.3 12.3 0 0 1-2.58-3.81Q12 2.49 12 0q0 2.49-.96 4.68-.93 2.19-2.55 3.81a12.3 12.3 0 0 1-3.81 2.58Q2.49 12 0 12q2.49 0 4.68.96 2.19.93 3.81 2.55t2.55 3.81"/></svg>',"github-copilot":'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M7.99816 14.2779C12.0678 14.2779 14.9997 11.6274 14.9997 10.9574V9.3189C14.939 8.77306 14.4165 7.82349 13.6074 7.48636C13.5959 7.42498 13.5859 7.36153 13.5756 7.29542C13.5506 7.13548 13.5231 6.95977 13.4649 6.75954C13.6409 6.31508 13.6873 5.81187 13.6873 5.31135C13.6873 4.54947 13.5757 3.76321 13.0811 3.13712C12.5745 2.4959 11.7737 2.15372 10.6972 2.03411C9.64215 1.91688 8.71828 2.06409 8.12157 2.70342C8.07827 2.74981 8.0345 2.79812 7.99655 2.84746C7.95861 2.79812 7.91805 2.74981 7.87475 2.70342C7.27804 2.06409 6.35416 1.91688 5.29908 2.03411C4.22263 2.15372 3.42181 2.4959 2.91521 3.13712C2.42057 3.76321 2.30905 4.54947 2.30905 5.31135C2.30905 5.81187 2.35539 6.31508 2.53142 6.75954C2.47323 6.95977 2.44574 7.13542 2.42072 7.29536C2.41037 7.3615 2.40044 7.42496 2.38893 7.48636C1.57983 7.82349 1.05728 8.77306 0.996582 9.3189V10.9574C0.996582 11.6274 3.92849 14.2779 7.99816 14.2779ZM10.5523 3.33859C9.63863 3.23707 9.25001 3.41798 9.0811 3.59896C8.90273 3.79007 8.76738 4.19254 8.86971 5.0112C8.94909 5.64627 9.13423 6.08757 9.41018 6.36929C9.67188 6.63645 10.0966 6.8426 10.8435 6.8426C11.6506 6.8426 11.9631 6.66867 12.1051 6.51046C12.2619 6.33577 12.3748 6.00462 12.3748 5.31135C12.3748 4.64141 12.2675 4.22455 12.0513 3.95077C11.8469 3.69214 11.4446 3.43773 10.5523 3.33859ZM6.91639 3.59896C6.74748 3.41798 6.35886 3.23707 5.44518 3.33859C4.55289 3.43773 4.15058 3.69214 3.94624 3.95077C3.72994 4.22455 3.62271 4.64141 3.62271 5.31135C3.62271 6.00462 3.73563 6.33577 3.89239 6.51046C4.03436 6.66867 4.34693 6.8426 5.15396 6.8426C5.90092 6.8426 6.32561 6.63645 6.58731 6.36929C6.86326 6.08757 7.0484 5.64627 7.12778 5.0112C7.23011 4.19254 7.09476 3.79007 6.91639 3.59896ZM7.99818 12.9788C9.99307 12.9788 12.0088 12.0076 12.3748 11.7248V8.00133L12.3546 7.90026C11.9257 8.08369 11.4142 8.1551 10.8435 8.1551C9.84049 8.1551 9.04148 7.86851 8.47257 7.28773C8.28092 7.09208 8.12536 6.87308 7.99978 6.6378C7.8742 6.87308 7.71544 7.09208 7.52378 7.28773C6.95488 7.86851 6.15587 8.1551 5.15283 8.1551C4.58212 8.1551 4.07068 8.08369 3.6418 7.90026L3.62158 8.00133V11.7248C3.98755 12.0076 6.00329 12.9788 7.99818 12.9788Z" fill="currentColor"/><path d="M6.46854 9.0301C6.83097 9.0301 7.12479 9.32391 7.12479 9.68635V10.9988C7.12479 11.3613 6.83097 11.6551 6.46854 11.6551C6.1061 11.6551 5.81229 11.3613 5.81229 10.9988V9.68635C5.81229 9.32391 6.1061 9.0301 6.46854 9.0301Z" fill="currentColor"/><path d="M10.1873 9.68635C10.1873 9.32391 9.89347 9.0301 9.53104 9.0301C9.1686 9.0301 8.87479 9.32391 8.87479 9.68635V10.9988C8.87479 11.3613 9.1686 11.6551 9.53104 11.6551C9.89347 11.6551 10.1873 11.3613 10.1873 10.9988V9.68635Z" fill="currentColor"/></svg>',"github-copilot-cli":'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M7.99816 14.2779C12.0678 14.2779 14.9997 11.6274 14.9997 10.9574V9.3189C14.939 8.77306 14.4165 7.82349 13.6074 7.48636C13.5959 7.42498 13.5859 7.36153 13.5756 7.29542C13.5506 7.13548 13.5231 6.95977 13.4649 6.75954C13.6409 6.31508 13.6873 5.81187 13.6873 5.31135C13.6873 4.54947 13.5757 3.76321 13.0811 3.13712C12.5745 2.4959 11.7737 2.15372 10.6972 2.03411C9.64215 1.91688 8.71828 2.06409 8.12157 2.70342C8.07827 2.74981 8.0345 2.79812 7.99655 2.84746C7.95861 2.79812 7.91805 2.74981 7.87475 2.70342C7.27804 2.06409 6.35416 1.91688 5.29908 2.03411C4.22263 2.15372 3.42181 2.4959 2.91521 3.13712C2.42057 3.76321 2.30905 4.54947 2.30905 5.31135C2.30905 5.81187 2.35539 6.31508 2.53142 6.75954C2.47323 6.95977 2.44574 7.13542 2.42072 7.29536C2.41037 7.3615 2.40044 7.42496 2.38893 7.48636C1.57983 7.82349 1.05728 8.77306 0.996582 9.3189V10.9574C0.996582 11.6274 3.92849 14.2779 7.99816 14.2779ZM10.5523 3.33859C9.63863 3.23707 9.25001 3.41798 9.0811 3.59896C8.90273 3.79007 8.76738 4.19254 8.86971 5.0112C8.94909 5.64627 9.13423 6.08757 9.41018 6.36929C9.67188 6.63645 10.0966 6.8426 10.8435 6.8426C11.6506 6.8426 11.9631 6.66867 12.1051 6.51046C12.2619 6.33577 12.3748 6.00462 12.3748 5.31135C12.3748 4.64141 12.2675 4.22455 12.0513 3.95077C11.8469 3.69214 11.4446 3.43773 10.5523 3.33859ZM6.91639 3.59896C6.74748 3.41798 6.35886 3.23707 5.44518 3.33859C4.55289 3.43773 4.15058 3.69214 3.94624 3.95077C3.72994 4.22455 3.62271 4.64141 3.62271 5.31135C3.62271 6.00462 3.73563 6.33577 3.89239 6.51046C4.03436 6.66867 4.34693 6.8426 5.15396 6.8426C5.90092 6.8426 6.32561 6.63645 6.58731 6.36929C6.86326 6.08757 7.0484 5.64627 7.12778 5.0112C7.23011 4.19254 7.09476 3.79007 6.91639 3.59896ZM7.99818 12.9788C9.99307 12.9788 12.0088 12.0076 12.3748 11.7248V8.00133L12.3546 7.90026C11.9257 8.08369 11.4142 8.1551 10.8435 8.1551C9.84049 8.1551 9.04148 7.86851 8.47257 7.28773C8.28092 7.09208 8.12536 6.87308 7.99978 6.6378C7.8742 6.87308 7.71544 7.09208 7.52378 7.28773C6.95488 7.86851 6.15587 8.1551 5.15283 8.1551C4.58212 8.1551 4.07068 8.08369 3.6418 7.90026L3.62158 8.00133V11.7248C3.98755 12.0076 6.00329 12.9788 7.99818 12.9788Z" fill="currentColor"/><path d="M6.46854 9.0301C6.83097 9.0301 7.12479 9.32391 7.12479 9.68635V10.9988C7.12479 11.3613 6.83097 11.6551 6.46854 11.6551C6.1061 11.6551 5.81229 11.3613 5.81229 10.9988V9.68635C5.81229 9.32391 6.1061 9.0301 6.46854 9.0301Z" fill="currentColor"/><path d="M10.1873 9.68635C10.1873 9.32391 9.89347 9.0301 9.53104 9.0301C9.1686 9.0301 8.87479 9.32391 8.87479 9.68635V10.9988C8.87479 11.3613 9.1686 11.6551 9.53104 11.6551C9.89347 11.6551 10.1873 11.3613 10.1873 10.9988V9.68635Z" fill="currentColor"/></svg>',"glm-acp-agent":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" fill-rule="evenodd"><title>Z.ai</title><path d="M8.07 1.333L6.618 3.302H.435L1.887 1.333h6.184zM15.503 12.699L14.052 14.667h-6.161l1.449-1.968h6.163zM16 1.333L6.176 14.667H0L9.824 1.333H16z"/></svg>',goose:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M20.9093 19.3861L19.5185 18.2413C18.7624 17.619 18.1189 16.8713 17.6157 16.0313C16.9205 14.8706 15.9599 13.8912 14.8133 13.1735L14.2533 12.8475C14.0614 12.7141 13.9276 12.5062 13.9086 12.2716C13.8963 12.1204 13.9326 11.9852 14.0171 11.8662C14.3087 11.4553 15.896 9.74698 16.1722 9.51845C16.528 9.22442 16.9243 8.97987 17.2921 8.69986C17.3443 8.66 17.3968 8.62035 17.4485 8.57989C17.4503 8.57808 17.4529 8.57668 17.4545 8.57508C17.5725 8.48195 17.6838 8.383 17.7724 8.26563C18.2036 7.76631 18.195 7.3443 18.195 7.3443C18.195 7.3443 18.1954 7.3439 18.1956 7.3437C18.1497 7.23133 17.9847 6.88163 17.6492 6.71759C17.9458 6.71178 18.2805 6.82294 18.4323 6.97156C18.6148 6.68534 18.7328 6.49967 18.9162 6.18762C18.9599 6.11352 18.9831 5.97652 18.8996 5.89981C18.8996 5.89981 18.8992 5.89981 18.8988 5.89981C18.8988 5.89981 18.8988 5.8994 18.8988 5.899C18.8972 5.8974 18.8952 5.8962 18.8936 5.8946C18.892 5.893 18.891 5.89119 18.8892 5.88939C18.8892 5.88939 18.8888 5.88939 18.8884 5.88939C18.8884 5.88939 18.8884 5.88899 18.8884 5.88859C18.885 5.88518 18.8812 5.88258 18.8776 5.87938C18.8754 5.87717 18.8736 5.87457 18.8716 5.87217C18.8692 5.87016 18.8665 5.86836 18.8643 5.86616C18.8609 5.86275 18.8587 5.85855 18.8551 5.85534C18.8551 5.85534 18.8545 5.85514 18.8543 5.85534C18.8543 5.85534 18.8543 5.85494 18.8543 5.85454C18.8527 5.85294 18.8507 5.85174 18.8491 5.85013C18.8475 5.84853 18.8463 5.84653 18.8447 5.84493C18.8447 5.84493 18.8441 5.84473 18.8439 5.84493C18.8439 5.84493 18.8439 5.84453 18.8439 5.84413C18.7672 5.7606 18.6302 5.78384 18.5561 5.8275C18.1503 6.06625 17.7555 6.32322 17.3996 6.54855C17.3996 6.54855 16.9778 6.53973 16.4783 6.97116C16.3607 7.05989 16.2618 7.17125 16.1688 7.28902C16.167 7.29082 16.1654 7.29322 16.164 7.29503C16.1234 7.3465 16.0837 7.39898 16.0441 7.45145C15.7639 7.81939 15.5195 8.21556 15.2255 8.57128C14.9971 8.84768 13.2887 10.4348 12.8777 10.7264C12.7587 10.8109 12.6237 10.8474 12.4723 10.835C12.2379 10.8161 12.0298 10.6821 11.8965 10.4903L11.5704 9.93024C10.8527 8.78318 9.87332 7.82299 8.71264 7.12778C7.87262 6.62466 7.12514 5.98092 6.50264 5.22503L5.35778 3.83421C5.3013 3.76571 5.19314 3.77693 5.15268 3.85585C5.02249 4.10941 4.77393 4.64479 4.58346 5.36483C4.57885 5.38186 4.58286 5.39988 4.59407 5.4135C4.83082 5.69952 5.37901 6.32983 6.03196 6.863C6.07742 6.90005 6.04017 6.97336 5.98369 6.95774C5.42047 6.80432 4.87288 6.55796 4.46308 6.34805C4.42964 6.33103 4.38918 6.35226 4.38437 6.38951C4.32068 6.89985 4.30425 7.46027 4.37155 8.05112C4.37355 8.07035 4.38577 8.08697 4.4036 8.09479C4.87088 8.29808 5.61816 8.59311 6.40269 8.78078C6.45958 8.7944 6.45777 8.87632 6.40029 8.88733C5.78941 9.0023 5.14968 9.02794 4.62973 9.02113C4.59327 9.02073 4.56643 9.05518 4.57625 9.09023C4.6806 9.45896 4.822 9.8339 5.00847 10.2115C5.08559 10.3811 5.16951 10.5475 5.25944 10.7104C5.27486 10.7382 5.3047 10.7548 5.33655 10.7534C5.76577 10.7324 6.28452 10.6871 6.80608 10.595C6.89501 10.5794 6.94268 10.6964 6.86757 10.7466C6.51345 10.9834 6.13571 11.1873 5.7844 11.3551C5.73733 11.3777 5.72211 11.4378 5.75315 11.4797C5.96186 11.7625 6.19139 12.0301 6.44075 12.2794C6.44075 12.2794 7.66853 13.5441 7.70198 13.6432C8.41841 12.9096 9.59612 12.0964 10.8966 11.3864C9.15488 12.8036 8.18387 13.8499 7.69517 14.4444L7.35447 14.9225C7.17742 15.1708 7.02379 15.4346 6.89541 15.7112C6.46579 16.6356 5.75756 18.5051 5.75756 18.5051C5.70328 18.6515 5.74754 18.7959 5.84168 18.89C5.84388 18.8922 5.84609 18.8944 5.84849 18.8964C5.85069 18.8986 5.8527 18.901 5.8549 18.9032C5.94924 18.9976 6.09345 19.0416 6.23986 18.9874C6.23986 18.9874 8.10897 18.2791 9.03371 17.8495C9.31031 17.7211 9.57429 17.5673 9.82245 17.3905L10.349 17.0153C10.6278 16.8166 11.0096 16.8483 11.2517 17.0904L12.4655 18.3042C12.7148 18.5535 12.9824 18.7831 13.2652 18.9918C13.3073 19.0226 13.3672 19.0076 13.3898 18.9605C13.5579 18.6094 13.7618 18.2313 13.9983 17.8774C14.0486 17.8022 14.1657 17.8501 14.1499 17.9388C14.0576 18.4606 14.0127 18.9794 13.9915 19.4084C13.9899 19.44 14.0067 19.4701 14.0345 19.4855C14.1972 19.5756 14.3636 19.6595 14.5335 19.7364C14.911 19.9229 15.2862 20.0645 15.6547 20.1687C15.6897 20.1785 15.7242 20.1516 15.7238 20.1152C15.7168 19.595 15.7424 18.9553 15.8576 18.3446C15.8684 18.2869 15.9503 18.2851 15.9641 18.3422C16.1516 19.127 16.4466 19.8742 16.6501 20.3413C16.6579 20.3591 16.6744 20.3712 16.6938 20.3734C17.2847 20.4407 17.8451 20.4242 18.3554 20.3606C18.3929 20.3559 18.4141 20.3155 18.3969 20.2818C18.187 19.872 17.9406 19.3241 17.7872 18.7612C17.7718 18.7046 17.8449 18.6675 17.8819 18.713C18.4151 19.3659 19.0454 19.9141 19.3314 20.1508C19.345 20.1621 19.3633 20.1659 19.3801 20.1615C20.1003 19.9712 20.6357 19.7226 20.8891 19.5922C20.968 19.5518 20.9792 19.4436 20.9107 19.3871L20.9093 19.3861Z"/></svg>',"grok-build":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M0.58392448,14.9254204 L0.8326,14.66295 C2.004465,13.42985 3.1678,12.2082 2.45814,10.48105 C1.50813,8.1701 2.061355,5.4619 3.820575,3.70057 C5.6495,1.8709 8.3431,1.40957 10.59295,2.336505 C11.0907,2.52161 11.5245,2.785025 11.86295,3.02993 L9.98425,3.89849 C8.235,3.163775 6.23115,3.66355 5.0081,4.88809 C3.354105,6.5426 3.019895,9.4117 4.95835,11.2656 L-0.335,15.99995 C-0.066496,15.62975 0.2538896,15.275934 0.58392448,14.9254204 Z M14.0391,2.288155 L16.33165,2.57749377e-12 L16.20795,0.172288 C14.4658,2.574355 13.6153,3.749045 14.29795,6.6879 C14.76445,8.68415 14.261,10.90255 12.63545,12.53005 C10.5861,14.58325 7.3066,15.0403 4.6059,13.19215 L6.48885,12.3193 C8.2125,12.99705 10.0983,12.69945 11.4536,11.34255 C12.80895,9.9856 13.1133,8.00925 12.4321,6.3647 C12.30265,6.05285 11.9144,5.97455 11.64275,6.1753 L6.102,10.27035 L14.0391,2.288155 Z"/></svg>',harn:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M11.2 1.4 14.6 4.8a1 1 0 0 1 0 1.4l-1.5 1.5-4.8-4.8 1.5-1.5a1 1 0 0 1 1.4 0ZM7.6 3.6l4.8 4.8-6.9 6.9a1 1 0 0 1-.5.27l-3.4.73a.6.6 0 0 1-.71-.71l.73-3.4a1 1 0 0 1 .27-.5l5.6-5.6Zm-4.5 8.1-.4 1.9 1.9-.4-1.5-1.5Z"/></svg>',junie:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 40 40" fill="none"><path d="M25 15H35V16.75C35 29 30.5001 35 16.5001 35H15V25H16.5001C22.6251 25 25 22.875 25 16.75V15Z" fill="currentColor"/><rect x="5" y="15" width="10" height="10" fill="currentColor"/><rect x="15" y="5" width="10" height="10" fill="currentColor"/></svg>',kilo:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 40 40"><path fill="currentColor" d="M27.9998324,34.6666921h6.6666279v5.3333023h-8.3809037l-3.6190266-3.6190266v-8.3809037h5.3333023v6.6666279ZM39.9997627,26.2857884l-3.6190266-3.6190266h-8.3809037v5.3333023h6.6666279v6.6666279h5.3333023v-8.3809037ZM17.3332326,22.6667578h-5.3333023v5.3333023h5.3333023v-5.3333023ZM0,36.3809638l3.6190266,3.6190266h13.714206v-5.3333023H5.3333023v-11.9999302H0v13.714206ZM33.9600959,11.9999247V3.619021L30.3410693-.0000056h-7.6745392v5.3333023h5.9602634v6.6666279h-5.9602634v5.3333023h17.3332326v-5.3333023h-6.0396668ZM5.3333023,0H0v17.3332326h5.3333023v-5.9999651h6.6666279v5.9999651h5.3333023v-5.9999651l-5.3333023-5.3333023h-6.6666279V0ZM17.3332326,0h-5.3333023v5.9999651h5.3333023V0Z"/></svg>',kimchi:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M3 1h2.5v5.5L9 1h3L8.5 6.5 12.5 13H9.5L6 8v5H3V1z"/></svg>',kimi:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M19.514 7.342C19.711 7.862 19.814 8.413 19.816 8.969C19.816 12.494 15.998 14.697 12.946 12.934C11.529 12.116 10.657 10.605 10.657 8.969C10.657 5.646 14.085 3.431 17.115 4.793C15.26 3.373 12.99 2.607 10.655 2.612C4.772 2.614 0.005 7.381 0 13.265C0.002 19.148 4.772 23.918 10.655 23.92C16.538 23.916 21.306 19.147 21.31 13.265C21.312 11.155 20.687 9.095 19.514 7.342ZM14.841 4.666C14.841 8.191 18.657 10.395 21.709 8.632C23.127 7.814 24 6.302 24 4.666C24 1.14 20.184-1.061 17.13 0.699C15.714 1.519 14.841 3.03 14.841 4.666"/></svg>',"minimax-code":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M2 3h3l3 5 3-5h3v10h-2V6.5l-4 6-4-6V13H2V3Z"/></svg>',"minion-code":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><rect fill="none" stroke="currentColor" stroke-width="1.1" x="4.5" y="2.5" width="7" height="10" rx="3.5"/><line stroke="currentColor" stroke-width="1" x1="3" y1="5.5" x2="13" y2="5.5"/><circle fill="none" stroke="currentColor" stroke-width="1" cx="6.5" cy="5.5" r="1.6"/><circle fill="none" stroke="currentColor" stroke-width="1" cx="9.5" cy="5.5" r="1.6"/><circle fill="currentColor" cx="6.8" cy="5.6" r="0.55"/><circle fill="currentColor" cx="9.8" cy="5.6" r="0.55"/><path fill="none" stroke="currentColor" stroke-width="0.6" stroke-linecap="round" d="M7 8.3 Q8 9 9 8.3"/><path fill="none" stroke="currentColor" stroke-width="0.9" stroke-linecap="round" d="M4.5 8 L3 9.5"/><path fill="none" stroke="currentColor" stroke-width="0.9" stroke-linecap="round" d="M11.5 8 L13 9.5"/><line stroke="currentColor" stroke-width="0.7" x1="5" y1="9.5" x2="11" y2="9.5"/><line stroke="currentColor" stroke-width="0.9" x1="6.5" y1="12.5" x2="6.5" y2="14"/><line stroke="currentColor" stroke-width="0.9" x1="9.5" y1="12.5" x2="9.5" y2="14"/><line stroke="currentColor" stroke-width="0.9" stroke-linecap="round" x1="6.5" y1="14" x2="5.5" y2="14"/><line stroke="currentColor" stroke-width="0.9" stroke-linecap="round" x1="9.5" y1="14" x2="10.5" y2="14"/><line stroke="currentColor" stroke-width="0.7" stroke-linecap="round" x1="8" y1="2.5" x2="7.3" y2="0.8"/><line stroke="currentColor" stroke-width="0.7" stroke-linecap="round" x1="8" y1="2.5" x2="8" y2="0.5"/><line stroke="currentColor" stroke-width="0.7" stroke-linecap="round" x1="8" y1="2.5" x2="8.7" y2="0.8"/></svg>',"mistral-vibe":'<svg width="16" height="16" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.8147 5.35803H5.35791V8.46914H8.8147V5.35803Z" fill="currentColor"/><path d="M22.6419 5.35803H19.1851V8.46914H22.6419V5.35803Z" fill="currentColor"/><path d="M15.7283 15.7284H12.2715V18.8395H15.7283V15.7284Z" fill="currentColor"/><path d="M8.8147 15.7284H5.35791V18.8395H8.8147V15.7284Z" fill="currentColor"/><path d="M22.6419 15.7284H19.1851V18.8395H22.6419V15.7284Z" fill="currentColor"/><path d="M12.2715 8.81482H5.35791V11.9259H12.2715V8.81482Z" fill="currentColor"/><path d="M12.2718 19.1852H1.90137V22.2963H12.2718V19.1852Z" fill="currentColor"/><path d="M26.0989 19.1852H15.7285V22.2963H26.0989V19.1852Z" fill="currentColor"/><path d="M22.6419 12.2716H5.35791V15.3827H22.6419V12.2716Z" fill="currentColor"/><path d="M22.6421 8.81482H15.7285V11.9259H22.6421V8.81482Z" fill="currentColor"/></svg>',nova:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><circle cx="8" cy="8" r="6" fill="none" stroke="currentColor" stroke-width="1"/><circle cx="8" cy="8" r="4.5" fill="none" stroke="currentColor" stroke-width="0.3" opacity="0.5"/><line x1="8" y1="8" x2="13.5" y2="13.5" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/><polygon points="14.5,14.5 12.3,13.5 13.5,12.3" fill="currentColor"/><line x1="8" y1="8" x2="2.5" y2="2.5" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/><polygon points="1.5,1.5 3.7,2.5 2.5,3.7" fill="currentColor"/><circle cx="8" cy="8" r="1.3" fill="currentColor"/><circle cx="8" cy="8" r="0.6" fill="none" stroke="currentColor" stroke-width="0.5" opacity="0.7"/></svg>',opencode:'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M13 14H3V2H13V14ZM10.5 4.4H5.5V11.6H10.5V4.4Z" fill="currentColor"/></svg>',"pi-acp":'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1H11.7692V7.9999H8.17942V11.4999H4.58982V15H1V1ZM4.58982 4.50005V7.9999H8.17942V4.50005H4.58982Z" fill="currentColor"/><path d="M11.7692 7.46154H15V15H11.7692V7.46154Z" fill="currentColor"/></svg>',poolside:'<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.63653 5.50522L2.18735 5.28559C2.09852 5.46726 2.12787 5.68456 2.26172 5.83616C2.39558 5.98775 2.60757 6.04379 2.79884 5.97814L2.63653 5.50522ZM5.83578 6.94285L5.3732 7.13265L5.5645 7.59886L6.02919 7.40392L5.83578 6.94285ZM10.7441 9.44034L10.2614 9.57083L10.393 10.0573L10.8784 9.92198L10.7441 9.44034ZM2.5 8.24963C2.4998 7.97349 2.27577 7.74979 1.99963 7.75C1.72349 7.75021 1.4998 7.97423 1.5 8.25037L2.5 8.24963ZM13.4143 10.7751C12.0197 13.6273 8.57701 14.8089 5.72485 13.4143L5.28559 14.3126C8.63389 15.9498 12.6754 14.5627 14.3126 11.2144L13.4143 10.7751ZM3.08571 5.72485C4.48031 2.87269 7.92299 1.69111 10.7751 3.08571L11.2144 2.18735C7.86611 0.550151 3.82455 1.93728 2.18735 5.28559L3.08571 5.72485ZM10.7751 3.08571C13.6273 4.48031 14.8089 7.92299 13.4143 10.7751L14.3126 11.2144C15.9498 7.86611 14.5627 3.82455 11.2144 2.18735L10.7751 3.08571ZM2.79884 5.97814C3.02201 5.90155 3.54835 5.84926 4.09141 6.00587C4.61256 6.15616 5.10736 6.48476 5.3732 7.13265L6.29835 6.75304C5.89213 5.76303 5.11508 5.26032 4.3685 5.04503C3.64385 4.83605 2.9066 4.8839 2.47422 5.0323L2.79884 5.97814ZM6.02919 7.40392C6.25314 7.30998 6.55771 7.25841 6.85281 7.36034C7.13062 7.45631 7.49214 7.72014 7.78743 8.4398L8.71257 8.0602C8.3358 7.14195 7.79046 6.62626 7.17931 6.41515C6.58544 6.21001 6.01893 6.32381 5.64236 6.48177L6.02919 7.40392ZM6.26827 7.19375C6.80493 6.26869 8.18817 4.18684 11.1653 3.10654L10.8242 2.16652C7.53166 3.36127 5.99463 5.67263 5.40329 6.69195L6.26827 7.19375ZM14.3364 10.8325C14.1845 10.39 13.7564 9.79897 13.14 9.37995C12.504 8.94759 11.6302 8.67426 10.6099 8.9587L10.8784 9.92198C11.5634 9.73102 12.1368 9.90713 12.5779 10.207C13.0385 10.5201 13.3174 10.9441 13.3905 11.1571L14.3364 10.8325ZM11.2268 9.30984C11.1236 8.92833 10.8783 8.39265 10.3638 8.02453C9.82769 7.6409 9.08331 7.49864 8.11574 7.76836L8.38426 8.73164C9.1221 8.52595 9.53979 8.66454 9.78189 8.83777C10.0457 9.02651 10.1946 9.32371 10.2614 9.57083L11.2268 9.30984ZM11.216 9.60556C11.6225 8.44463 12.4244 5.47936 11.4712 2.48487L10.5183 2.78819C11.3726 5.47172 10.6545 8.18331 10.2722 9.27512L11.216 9.60556ZM7.80082 8.03037L5.05604 13.6438L5.9544 14.0831L8.69918 8.46963L7.80082 8.03037ZM5.72485 13.4143C3.68742 12.4181 2.50158 10.3763 2.5 8.24963L1.5 8.25037C1.50185 10.7441 2.89229 13.1424 5.28559 14.3126L5.72485 13.4143Z" fill="currentColor"/></svg>',qoder:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M8 1C4.134 1 1 4.134 1 8s3.134 7 7 7c1.5 0 2.9-.47 4.05-1.28l1.12 1.12a.75.75 0 1 0 1.06-1.06l-1.12-1.12A6.97 6.97 0 0 0 15 8c0-3.866-3.134-7-7-7Zm0 2c2.761 0 5 2.239 5 5s-2.239 5-5 5-5-2.239-5-5 2.239-5 5-5Z"/></svg>',"qwen-code":'<svg xmlns="http://www.w3.org/2000/svg" data-name="图层 2" viewBox="0 0 141.38 140" width="16" height="16"><path fill="currentColor" d="m140.93 85-16.35-28.33-1.93-3.34 8.66-15a3.323 3.323 0 0 0 0-3.34l-9.62-16.67c-.3-.51-.72-.93-1.22-1.22s-1.07-.45-1.67-.45H82.23l-8.66-15a3.33 3.33 0 0 0-2.89-1.67H51.43c-.59 0-1.17.16-1.66.45-.5.29-.92.71-1.22 1.22L32.19 29.98l-1.92 3.33H12.96c-.59 0-1.17.16-1.66.45-.5.29-.93.71-1.22 1.22L.45 51.66a3.323 3.323 0 0 0 0 3.34l18.28 31.67-8.66 15a3.32 3.32 0 0 0 0 3.34l9.62 16.67c.3.51.72.93 1.22 1.22s1.07.45 1.67.45h36.56l8.66 15a3.35 3.35 0 0 0 2.89 1.67h19.25a3.34 3.34 0 0 0 2.89-1.67l18.28-31.67h17.32c.6 0 1.17-.16 1.67-.45s.92-.71 1.22-1.22l9.62-16.67a3.323 3.323 0 0 0 0-3.34ZM51.44 3.33 61.07 20l-9.63 16.66h76.98l-9.62 16.66H45.67l-11.54-20zM57.21 120H22.58l9.63-16.67h19.25l-38.5-66.67h19.25l9.62 16.67L68.78 100l-11.55 20Zm61.59-33.34-9.62-16.67-38.49 66.67-9.63-16.67 9.63-16.66 26.94-46.67h23.1l17.32 30z" data-name="图层 1"/></svg>',sigit:'<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 1024 1024" preserveAspectRatio="xMidYMid meet" ><g transform="translate(0,1024) scale(0.1,-0.1)" fill="currentColor" stroke="none" ><path d="M6428 6358 c-104 -8 -227 -38 -314 -78 -73 -33 -196 -115 -239 -160 -18 -19 -39 -30 -56 -30 -26 0 -27 1 -18 32 5 18 9 52 9 76 0 34 -6 49 -34 80 l-34 37 -319 3 c-412 3 -383 18 -447 -236 -20 -78 -36 -154 -36 -168 0 -14 -5 -35 -12 -47 -6 -12 -21 -60 -33 -107 l-22 -85 -22 43 c-47 91 -179 184 -310 218 -146 37 -375 34 -536 -7 -203 -51 -365 -175 -443 -339 -68 -143 -109 -304 -114 -445 l-2 -70 -127 5 c-70 3 -125 2 -123 -1 5 -8 -27 -21 -34 -14 -3 3 0 5 7 5 7 0 9 5 6 10 -4 6 -11 8 -16 5 -5 -4 -15 -3 -21 2 -7 4 -17 8 -23 8 -5 0 -10 7 -10 15 0 13 -142 15 -1205 18 -663 1 -1212 -1 -1220 -5 -8 -3 -19 -5 -25 -4 -5 1 1 -8 15 -21 13 -13 29 -22 34 -20 5 2 3 -4 -4 -14 -13 -15 -15 -14 -24 5 -5 13 -15 20 -24 16 -7 -3 -157 -5 -333 -5 l-319 0 0 -2540 0 -2540 5120 0 5120 0 0 2540 0 2540 -685 1 c-377 1 -689 2 -694 3 -16 2 -25 16 -10 16 11 0 11 2 -1 10 -8 5 -10 10 -4 10 5 0 16 -6 23 -12 11 -10 13 -10 7 0 -5 8 1 12 18 12 14 0 27 -1 29 -2 1 -2 13 7 27 20 13 12 30 22 37 22 8 0 11 5 8 10 -3 6 -2 10 2 10 5 0 9 8 9 18 1 9 18 82 38 161 20 79 36 158 36 176 0 42 -38 97 -75 109 -17 6 -31 11 -32 11 -1 1 5 23 13 50 20 68 20 137 -2 169 -27 43 -64 56 -155 56 -73 0 -80 2 -74 18 4 9 9 42 12 72 3 44 0 62 -17 88 -38 61 -57 63 -396 60 l-304 -3 0 38 c0 29 -8 46 -34 75 l-34 37 -313 3 c-215 2 -321 -1 -340 -8 -50 -21 -68 -52 -100 -177 l-31 -121 -28 16 c-16 9 -35 30 -43 47 -23 48 -102 130 -168 174 -132 88 -315 126 -531 109z m296 -148 c43 -11 101 -32 129 -47 67 -37 145 -115 170 -172 41 -92 33 -253 -25 -493 l-21 -88 -275 0 -274 0 4 23 c3 12 22 91 42 175 25 102 36 170 34 205 -3 51 -4 52 -39 61 -57 14 -98 -15 -128 -89 -36 -89 -321 -1238 -328 -1321 -5 -66 -4 -72 18 -88 54 -38 118 -7 159 78 28 58 122 403 113 419 -2 4 -27 7 -54 7 -43 0 -50 3 -46 18 3 9 20 79 38 154 l33 137 75 7 c79 7 558 1 566 -8 3 -3 -58 -260 -136 -572 l-141 -566 -174 0 -174 0 0 29 c0 15 -3 49 -6 74 l-7 46 -61 -55 c-33 -30 -94 -72 -135 -92 -74 -37 -76 -37 -201 -37 -126 0 -126 0 -202 38 -203 100 -254 266 -179 592 66 287 235 944 271 1050 72 215 132 298 289 403 144 97 262 130 462 131 95 1 145 -4 203 -19z m-1046 -37 c-3 -10 -18 -71 -33 -135 l-29 -118 -273 0 c-213 0 -271 3 -268 13 2 6 13 50 25 97 11 46 25 101 31 122 l10 38 271 0 c253 0 270 -1 266 -17z m2240 0 c-3 -10 -18 -71 -33 -135 l-29 -118 -273 0 c-213 0 -271 3 -268 13 2 6 13 50 25 97 11 46 25 101 31 122 l10 38 271 0 c253 0 270 -1 266 -17z m722 -139 c0 -3 -13 -59 -30 -124 -16 -65 -30 -126 -30 -134 0 -13 13 -16 65 -16 45 0 65 -4 65 -12 0 -13 -31 -146 -51 -220 l-10 -38 -72 0 -73 0 -132 -532 c-73 -293 -132 -552 -132 -574 0 -47 11 -54 93 -54 26 0 47 -3 47 -7 0 -5 -15 -66 -33 -138 l-33 -130 -165 -3 c-326 -6 -421 26 -459 155 -17 55 2 146 155 761 69 277 125 508 125 513 0 5 -25 9 -55 9 l-55 0 7 28 c3 15 18 74 33 132 l26 105 59 5 59 5 34 138 34 137 264 0 c145 0 264 -3 264 -6z m-4147 -223 c137 -36 218 -93 257 -183 27 -63 24 -128 -12 -278 l-24 -95 -232 -3 c-143 -1 -232 1 -232 7 0 5 9 47 20 93 35 145 26 178 -49 178 -65 0 -117 -79 -128 -195 -9 -104 10 -126 222 -252 211 -127 273 -191 290 -305 14 -94 -44 -332 -112 -458 -105 -195 -319 -301 -607 -300 -253 1 -438 89 -476 225 -17 61 -8 193 21 318 l22 97 234 0 233 0 -5 -22 c-3 -13 -14 -61 -25 -108 -11 -47 -20 -106 -20 -132 0 -40 4 -50 25 -64 31 -20 85 -12 120 19 32 28 64 120 72 203 8 82 7 82 -202 224 -178 120 -243 177 -277 242 -72 138 33 532 175 650 70 59 97 75 175 105 101 38 184 51 328 52 99 1 149 -4 207 -18z m1087 -20 c0 -7 -408 -1652 -426 -1718 l-6 -23 -269 0 c-173 0 -269 4 -269 10 0 6 97 399 216 875 l216 865 269 0 c148 0 269 -4 269 -9z m2240 -1 c0 -5 -97 -397 -215 -871 -118 -474 -215 -863 -215 -865 0 -2 -121 -4 -270 -4 -174 0 -270 4 -270 10 0 6 97 399 216 875 l216 865 269 0 c166 0 269 -4 269 -10z m1040 -742 c0 -5 -5 -6 -11 -2 -8 4 -9 -1 -4 -17 4 -13 4 -21 0 -17 -4 4 -9 21 -11 39 -3 27 -2 30 11 19 8 -7 15 -17 15 -22z m-8192 4 c2 -7 -5 -12 -15 -11 -12 0 -14 2 -4 6 11 5 11 7 0 15 -12 8 -12 9 0 6 8 -3 17 -10 19 -16z m1840 -1329 c-311 -2 -824 -2 -1140 0 -315 1 -60 2 567 2 627 0 885 -1 573 -2z m619 1 c-3 -3 -12 -4 -19 -1 -8 3 -5 6 6 6 11 1 17 -2 13 -5z" /><path d="M900 6270 c0 -11 6 -20 14 -20 7 0 16 -9 19 -20 5 -20 12 -20 1803 -18 1731 3 1799 4 1802 21 3 12 -4 20 -17 24 -12 3 -21 12 -21 19 0 12 -274 14 -1800 14 -1793 0 -1800 0 -1800 -20z" /><path d="M900 6005 c0 -15 6 -25 14 -25 7 0 16 -9 19 -20 5 -20 12 -20 1334 -18 l1328 3 3 23 c3 17 -2 22 -17 22 -14 0 -21 6 -21 20 0 20 -7 20 -1330 20 l-1330 0 0 -25z" /><path d="M737 5713 c-12 -12 -7 -43 7 -43 7 0 16 -9 19 -20 5 -20 12 -20 1323 -18 1248 3 1319 4 1322 21 2 9 -4 20 -14 24 -10 3 -26 15 -35 24 -17 17 -83 18 -1317 19 -714 0 -1302 -3 -1305 -7z" /><path d="M1953 5412 c-1265 -2 -1273 -2 -1273 -22 0 -11 6 -20 14 -20 7 0 16 -9 19 -20 5 -20 12 -20 1298 -18 1242 3 1294 4 1297 21 3 12 -4 20 -17 24 -12 3 -21 11 -21 18 0 7 -10 14 -22 16 -13 2 -596 3 -1295 1z" /><path d="M9010 5130 c-12 -7 -10 -9 7 -7 12 0 19 5 17 9 -6 10 -6 10 -24 -2z" /><path d="M3180 5109 c0 -5 5 -7 10 -4 6 3 10 8 10 11 0 2 -4 4 -10 4 -5 0 -10 -5 -10 -11z" /></g></svg>',stakpak:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M6.53 4.412h5.883v3.587H9.471v3.588H3.588V7.999H6.53Z"/></svg>',vtcode:`<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M0.5 5.5L2.5 8 0.5 10.5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><text x="3.2" y="11.5" font-family="'SF Mono', 'Fira Code', 'Consolas', monospace" font-size="10" font-weight="600" letter-spacing="-0.5" fill="currentColor">VT</text></svg>`},UI=new Map;function vKe(t){if(t===Wi||t===G0)return'url("/brand/oxbit-mark.svg")';const e=io(t)?.registryId??t;if(!Object.hasOwn(BI,e))return;let i=UI.get(e);return i||UI.set(e,i=`url("data:image/svg+xml,${encodeURIComponent(BI[e])}")`),i}function op({provider:t,size:e=16}){const i=vKe(t);return i?w.jsx("span",{className:"acp-agent-logo","aria-hidden":"true","data-agent":t,style:{width:e,height:e,WebkitMaskImage:i,maskImage:i}}):w.jsx(Te,{name:"agent",size:e})}const kKe={"oxbit-cli":"Ships with Oxbit. Uses ~/.oxbit/agent settings.",codex:"Runs with npx. Uses your Codex sign-in.",claude:"Runs with npx. Uses your Claude plan through Claude Code's sign-in on the runtime.",gemini:"Runs with npx. Sign in or set GEMINI_API_KEY.",copilot:"Runs with npx. Sign in with GitHub.",cursor:"Needs Cursor CLI and agent login.",amp:"Needs Amp CLI and amp login."},U_="Needs a runtime workspace",SKe={claude:"Needs a runtime workspace. Uses your Claude plan through Claude Code's sign-in on the runtime."};function xKe({agent:t,enabled:e,onChoose:i}){const s=t.chosen.provider,r=t.local,a=!!t.options.kernel.services.optional(fv)?.chatgpt,n=c=>{t.action(()=>t.select({provider:c}))},o=(c,u,d,p=d)=>{const g=OG(c,r),y=P(SKe[c]??U_);return w.jsxs("button",{type:"button",role:"radio","aria-checked":s===c,className:"acp-agent-option",disabled:t.connecting||!g,onClick:()=>n(c),children:[w.jsx(op,{provider:c}),w.jsxs("span",{children:[w.jsx("strong",{children:u}),w.jsx("small",{title:g?p:y,children:g?d:y})]})]},c)},l=!io(s)&&s!==Wi;return w.jsxs("section",{className:"acp-agent-picker","aria-label":P("Choose an agent"),children:[w.jsx("h2",{children:P("Choose an agent")}),w.jsxs("div",{role:"radiogroup","aria-label":P("Agent"),children:[r&&o(Wi,gG,P(a?"Runs in Oxbit with your API key or ChatGPT plan":"Runs in Oxbit with your API key")),hv.map(c=>o(c.id,c.name,P(kKe[c.id]??c.setup),P(c.setup))),l&&o(s,t.displayName,P(s===Ei?"Custom agent":"ACP Registry agent"))]}),w.jsxs("div",{className:"acp-agent-more",children:[w.jsxs("button",{type:"button",className:"acp-agent-option",disabled:r,onClick:()=>i("registry"),children:[w.jsx(Te,{name:"package",size:14}),w.jsxs("span",{children:[w.jsx("strong",{children:P("More agents…")}),w.jsx("small",{children:P(r?U_:"Browse the ACP Registry")})]})]}),w.jsxs("button",{type:"button",className:"acp-agent-option",disabled:r,onClick:()=>i("custom"),children:[w.jsx(Te,{name:"pencil",size:14}),w.jsxs("span",{children:[w.jsx("strong",{children:P("Custom agent…")}),w.jsx("small",{children:P(r?U_:"Run any ACP executable")})]})]})]}),w.jsx("button",{type:"button",className:"button primary acp-agent-start",disabled:!e||t.connecting,onClick:()=>{t.action(()=>t.connectSelected())},children:r&&t.claudePlan?P("Runtime connection"):P("Start {0}",{0:t.displayName})})]})}function VG({value:t,disabled:e,onChange:i}){return w.jsxs("label",{children:[P("Arguments"),w.jsx("input",{"aria-label":P("Agent arguments"),value:t,disabled:e,spellCheck:!1,onChange:s=>i(s.target.value)}),w.jsx("small",{className:"muted",children:P("Separate arguments with spaces. Quote an argument that contains spaces.")})]})}function ZG({agent:t,onDone:e,embedded:i=!1}){const s=t.options.kernel.configuration,[r,a]=L.useState(s.get(ys(Ei,"name"))??""),[n,o]=L.useState(s.get(ys(Ei,"command"))??""),[l,c]=L.useState(fG(cv(s.get(ys(Ei,"args")))??[]));return w.jsxs("form",{className:i?"acp-custom-agent":"acp-setup acp-custom-agent","aria-label":P("Custom agent"),onSubmit:u=>{u.preventDefault(),t.action(async()=>{if(!n.trim())throw new Error(P("Enter the agent executable"));await t.select({provider:Ei,name:r.trim()||P("Custom agent"),command:n.trim(),args:hG(l)}),e()})},children:[!i&&w.jsx("h2",{children:P("Custom agent")}),w.jsxs("label",{children:[P("Name"),w.jsx("input",{"aria-label":P("Agent name"),value:r,placeholder:P("Custom agent"),onChange:u=>a(u.target.value)})]}),w.jsxs("label",{children:[P("Executable"),w.jsx("input",{"aria-label":P("Agent executable"),value:n,spellCheck:!1,onChange:u=>o(u.target.value)})]}),w.jsx(VG,{value:l,onChange:c}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{type:"submit",className:"button primary",children:P(i?"Save":"Use custom agent")}),!i&&w.jsx("button",{type:"button",className:"button",onClick:e,children:P("Cancel")})]})]})}const $6=6,XI=2*Math.PI*$6,$Ke=.85;function _Ke({usage:t}){const e=Math.min(1,t.used/t.size),i=Math.round(e*100),s=`${t.used.toLocaleString()}/${t.size.toLocaleString()}`,r=t.cost?`${t.cost.amount.toLocaleString()} ${t.cost.currency}`:"";return w.jsxs("div",{className:"acp-usage",role:"meter","aria-label":P("Context usage"),"aria-valuemin":0,"aria-valuemax":t.size,"aria-valuenow":Math.min(t.used,t.size),"aria-valuetext":P("{0}% of context used",{0:i}),"data-level":e>=$Ke?"high":void 0,"data-tooltip":P("{0} tokens",{0:s}),children:[w.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16","aria-hidden":"true",children:[w.jsx("circle",{className:"acp-usage-track",cx:"8",cy:"8",r:$6}),w.jsx("circle",{className:"acp-usage-fill",cx:"8",cy:"8",r:$6,strokeDasharray:XI,strokeDashoffset:XI*(1-e),transform:"rotate(-90 8 8)"})]}),w.jsx("span",{children:P("{0}% context",{0:i})}),w.jsxs("span",{className:"acp-usage-detail",children:[s,r&&` · ${r}`]})]})}function CKe(t=globalThis){const e=t;return e.SpeechRecognition??e.webkitSpeechRecognition}const AKe={"not-allowed":"Allow microphone access for Oxbit to dictate","service-not-allowed":"Allow speech recognition for Oxbit to dictate","audio-capture":"No microphone is available",network:"Dictation needs a network connection","language-not-supported":"Dictation does not support this language","no-speech":"No speech was detected"};function TKe(t){const e=AKe[t.error];if(e)return P(e);if(t.error==="unknown")return t.message?P("Dictation failed: {0}",{0:t.message}):P("Dictation failed")}function PKe(t){let e="";for(let i=0;i<t.results.length;i++)e+=t.results[i]?.[0]?.transcript??"";return e.trim()}function EKe(t,e){return e?t&&!/\s$/.test(t)?`${t} ${e}`:t+e:t}function RKe({value:t,onChange:e,onError:i}){const[s,r]=L.useState(!1),a=L.useRef(null),n=L.useRef({value:t,onChange:e,onError:i});n.current={value:t,onChange:e,onError:i},L.useEffect(()=>()=>a.current?.recognition.abort(),[]),L.useEffect(()=>{a.current&&t!==a.current.written&&a.current.recognition.abort()},[t]);const o=CKe();if(!o)return null;const l=()=>{const u=new o,d=n.current.value,p={recognition:u,written:d};u.lang=navigator.language,u.continuous=!0,u.interimResults=!0,u.onresult=g=>{a.current===p&&(p.written=EKe(d,PKe(g)),n.current.onChange(p.written))},u.onerror=g=>{const y=TKe(g);y&&n.current.onError(y)},u.onend=()=>{a.current===p&&(a.current=null,r(!1))};try{u.start()}catch(g){i(g instanceof Error?g.message:String(g));return}a.current=p,r(!0)},c=P(s?"Stop dictation":"Dictate");return w.jsx("button",{type:"button",className:"icon-button acp-mic","aria-label":c,"aria-pressed":s,"data-tooltip":c,onMouseDown:u=>u.preventDefault(),onClick:()=>s?a.current?.recognition.stop():l(),children:w.jsx(Te,{name:"mic"})})}function QKe({agent:t,onDone:e}){const[i,s]=L.useState("");L.useEffect(()=>{t.registry||t.action(()=>t.loadRegistry())},[]);const r=i.trim().toLowerCase(),a=(t.registry?.agents??[]).filter(o=>!r||`${o.name} ${o.id} ${o.description}`.toLowerCase().includes(r)),n=o=>{t.action(async()=>{await t.select(o.builtin?{provider:o.builtin}:{provider:o.id,registry:{id:o.id}}),e()})};return w.jsxs("section",{className:"acp-registry","aria-label":P("ACP Registry"),children:[w.jsxs("div",{className:"acp-registry-heading",children:[w.jsx("h2",{children:P("ACP Registry")}),w.jsx("button",{type:"button",className:"button",onClick:e,children:P("Done")})]}),w.jsxs("label",{className:"search-input",children:[w.jsx(Te,{name:"search",size:14}),w.jsx("input",{"aria-label":P("Search agents"),placeholder:P("Search agents"),value:i,autoFocus:!0,onChange:o=>s(o.target.value)})]}),t.registry?.error&&w.jsx("p",{className:"muted",children:P("Showing a cached list. The registry could not be reached.")}),t.registryLoading&&!t.registry&&w.jsx("p",{className:"muted",role:"status",children:P("Loading agents…")}),t.registry&&!a.length&&w.jsx("p",{className:"muted",children:P("No agents match your search")}),w.jsx("div",{className:"acp-registry-list",children:a.map(o=>{const l=o.builtin?io(o.builtin):void 0;return w.jsxs("button",{type:"button",className:"acp-registry-entry","aria-pressed":t.chosen.provider===(o.builtin??o.id),disabled:!o.available||t.connecting,onClick:()=>n(o),children:[w.jsxs("span",{className:"acp-registry-title",children:[w.jsx(op,{provider:o.builtin??o.id,size:14}),w.jsx("strong",{children:o.name}),w.jsx("small",{children:o.version}),w.jsx("small",{className:"acp-registry-tag",children:o.distribution}),l&&w.jsx("small",{className:"acp-registry-tag",children:P("Built-in")}),!o.available&&w.jsx("small",{className:"acp-registry-tag",children:P("Unavailable")})]}),w.jsx("small",{className:"acp-registry-description",children:o.description}),!o.available&&w.jsx("small",{className:"acp-registry-reason",children:P(o.reason??"Not available for the runtime's platform")})]},o.id)})})]})}const _6="The sign-in code expired. Sign in again.",DKe=5;function NKe(t,e){return new Promise((i,s)=>{if(e.aborted)return s(e.reason);const r=setTimeout(()=>{e.removeEventListener("abort",a),i()},t),a=()=>{clearTimeout(r),s(e.reason)};e.addEventListener("abort",a,{once:!0})})}async function FKe(t,e,i,s={now:Date.now,sleep:NKe}){let r=e.interval;for(;;){if(await s.sleep(r*1e3,i),s.now()>=e.expiresAt)throw new Error(_6);const a=await t.poll(e,i);if(a==="complete")return;a==="slow_down"&&(r+=DKe)}}function LKe({agent:t}){const e=t.options.kernel.configuration,i=t.connection?.provider??t.chosen.provider,s=io(i),r=!!t.connection||t.connecting,[a,n]=L.useState(e.get(ys(i,"command"))||s?.command||""),[o,l]=L.useState(fG(cv(e.get(ys(i,"args")))??[...s?.args??[]])),[c,u]=L.useState("");if(i===Wi)return w.jsx(MKe,{agent:t});const d=w.jsx("p",{className:"muted",children:P("Connecting may download the adapter. Agents run with the trusted runtime's privileges and use its existing credentials.")});if(i===Ei&&!r)return w.jsxs("div",{className:"acp-setup",children:[w.jsx(ZG,{agent:t,embedded:!0,onDone:()=>{}}),d]});if(!s){const p=t.registry?.agents.find(g=>g.id===i);return w.jsxs("div",{className:"acp-setup",children:[w.jsxs("p",{children:[w.jsx("strong",{children:t.displayName}),p&&` · ${p.version} · ${p.distribution}`]}),p?.description&&w.jsx("p",{children:p.description}),w.jsx("p",{className:"muted",children:P(i===Ei?"Custom agent":"The runtime installs this agent from the ACP Registry and keeps its pinned version.")}),d]})}return w.jsxs("div",{className:"acp-setup",children:[w.jsxs("p",{children:[P(s.setup)," ",w.jsx("a",{href:s.url,target:"_blank",rel:"noreferrer",children:P("Setup guide")})]}),w.jsxs("label",{children:[P("Executable"),w.jsx("input",{"aria-label":P("Agent executable"),value:a,disabled:r,spellCheck:!1,onChange:p=>{n(p.target.value),e.set(ys(i,"command"),p.target.value,"user")}})]}),w.jsx(VG,{value:o,disabled:r,onChange:p=>{l(p);try{e.set(ys(i,"args"),JSON.stringify(hG(p)),"user"),u("")}catch(g){u(g instanceof Error?g.message:String(g))}}}),c&&w.jsx("p",{className:"error-text",role:"alert",children:c}),d]})}const By="claude-plan";function MKe({agent:t}){const e=t.options.kernel.configuration,i=t.options.kernel.services.optional(fv),s=!!t.connection||t.connecting,[r,a]=L.useState(()=>lv(e).api),[n,o]=L.useState(()=>e.get(so.baseUrl)??""),[l,c]=L.useState(""),[u,d]=L.useState(),[p,g]=L.useState(!1),y=r==="openai-compatible"?{api:r,baseUrl:n.trim()}:{api:r},k=r==="openai-compatible"&&!n.trim(),$=JSON.stringify(y),_=()=>i&&!k?i.keys.has(y):Promise.resolve(!1);L.useEffect(()=>{let b=!0;return d(void 0),_().then(Q=>b&&d(Q),()=>b&&d(!1)),()=>{b=!1}},[i,$]);const C=b=>{t.action(async()=>{if(i){g(!0);try{await b(i),d(await _())}finally{g(!1)}}})};return w.jsxs("form",{className:"acp-setup","aria-label":P("Oxbit Agent setup"),onSubmit:b=>{b.preventDefault(),!(t.claudePlan||!l.trim()||k)&&C(async Q=>{await Q.keys.save(y,l.trim()),c("")})},children:[w.jsx("p",{children:P(t.claudePlan?"Claude Agent runs on a connected runtime with that computer's Claude Code sign-in.":r==="chatgpt"?"Oxbit Agent runs in the app and calls the Codex models in your ChatGPT plan. The sign-in tokens are stored in the system keychain.":"Oxbit Agent runs in the app and calls the model API with your key. The key is stored in the system keychain.")}),w.jsxs("div",{className:"acp-setting",children:[w.jsx("span",{className:"acp-setting-label",children:P("API")}),w.jsx(fn,{label:P("API"),value:t.claudePlan?By:r,options:[{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"openai-compatible",label:P("OpenAI-compatible")},...i?.chatgpt||r==="chatgpt"?[{value:"chatgpt",label:P("ChatGPT plan")}]:[],{value:By,label:P("Claude plan")}],disabled:s,onChange:b=>{t.setClaudePlan(b===By),b!==By&&(a(b),e.set(so.api,b,"user"))}})]}),t.claudePlan?w.jsx("div",{className:"acp-actions",children:w.jsx("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.options.kernel.commands.execute("workspace.runtime"))},children:P("Runtime connection")})}):r==="openai-compatible"&&w.jsxs("label",{children:[P("Base URL"),w.jsx("input",{"aria-label":P("Base URL"),value:n,disabled:s,spellCheck:!1,inputMode:"url",placeholder:"https://openrouter.ai/api",onChange:b=>{o(b.target.value),e.set(so.baseUrl,b.target.value.trim(),"user")}}),w.jsx("small",{className:"muted",children:P("Origin and path prefix of a Chat Completions API.")})]}),t.claudePlan?null:r==="chatgpt"?w.jsx(IKe,{models:i,saved:u,refresh:()=>t.action(async()=>d(await _()))}):w.jsxs(w.Fragment,{children:[w.jsxs("label",{children:[P("API key"),w.jsx("input",{type:"password","aria-label":P("API key"),value:l,autoComplete:"off",spellCheck:!1,onChange:b=>c(b.target.value)}),w.jsx("small",{className:"muted","aria-live":"polite",children:u===void 0?"":P(u?"Key saved":"No key saved")})]}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{type:"submit",className:"button primary",disabled:p||!l.trim()||k,children:P("Save")}),w.jsx("button",{type:"button",className:"button",disabled:p||!u,onClick:()=>C(b=>b.keys.remove(y)),children:P("Remove")})]})]})]})}const X_=t=>{const e=t instanceof Error?t.message:String(t);return e===_6?P(_6):e};function IKe({models:t,saved:e,refresh:i}){const s=t?.chatgpt,[r,a]=L.useState(),[n,o]=L.useState(!1),[l,c]=L.useState(!1),[u,d]=L.useState(""),p=L.useRef(void 0);L.useEffect(()=>()=>p.current?.abort(),[]);const g=async()=>{if(!s)return;const _=new AbortController;p.current=_,o(!0),c(!1),d("");try{const C=await s.start(_.signal);_.signal.throwIfAborted(),a(C),await FKe(s,C,_.signal),await i()}catch(C){_.signal.aborted||d(X_(C))}finally{p.current===_&&(p.current=void 0,a(void 0),o(!1))}},y=()=>{p.current?.abort(),p.current=void 0,a(void 0),o(!1)},k=async()=>{if(t){o(!0),d("");try{await t.keys.remove({api:"chatgpt"}),await i()}catch(_){d(X_(_))}finally{o(!1)}}},$=async _=>{try{await navigator.clipboard.writeText(_),c(!0)}catch(C){d(X_(C))}};return w.jsxs("div",{className:"acp-chatgpt",children:[r?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:P("Open the sign-in page and enter this code.")}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("output",{className:"acp-device-code","aria-label":P("ChatGPT sign-in code"),children:r.userCode}),w.jsx("button",{type:"button",className:"button",onClick:()=>{$(r.userCode)},children:P(l?"Copied":"Copy code")})]}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("a",{className:"button primary",href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:P("Open sign-in page")}),w.jsx("button",{type:"button",className:"button",onClick:y,children:P("Cancel")})]}),w.jsx("p",{className:"muted",role:"status",children:P("Waiting for you to sign in")})]}):w.jsxs(w.Fragment,{children:[w.jsx("p",{className:"muted",role:"status",children:e===void 0?"":P(e?"Signed in with ChatGPT":"Not signed in")}),w.jsx("div",{className:"acp-actions",children:e?w.jsx("button",{type:"button",className:"button",disabled:n,onClick:()=>{k()},children:P("Sign out")}):w.jsx("button",{type:"button",className:"button primary",disabled:n||!s,onClick:()=>{g()},children:P("Sign in with ChatGPT")})})]}),u&&w.jsx("p",{className:"error-text",role:"alert",children:u})]})}function WG({label:t,items:e}){const i=L.useId(),s=L.useRef(null),r=L.useRef(null),[a,n]=L.useState(!1),o=()=>Array.from(r.current?.querySelectorAll('[role="menuitem"]')??[]),l=(u=!1)=>{r.current?.hidePopover(),u&&s.current?.focus()},c=(u=!1)=>{const d=r.current,p=s.current,g=p?.ownerDocument.defaultView;if(!d||!p||!g)return;const y=p.getBoundingClientRect(),k=Math.min(260,g.innerWidth-16),$=g.innerHeight-y.bottom-8,_=y.top-8,C=$<200&&_>$;Object.assign(d.style,{width:`${k}px`,left:`${Math.max(8,Math.min(y.right-k,g.innerWidth-k-8))}px`,top:C?"auto":`${y.bottom+4}px`,bottom:C?`${g.innerHeight-y.top+4}px`:"auto",maxHeight:`${Math.max(60,C?_:$)}px`}),d.showPopover();const b=o();(u?b.at(-1):b[0])?.focus()};return L.useEffect(()=>{const u=s.current?.ownerDocument.defaultView,d=()=>r.current?.hidePopover();return u?.addEventListener("resize",d),()=>{d(),u?.removeEventListener("resize",d)}},[]),w.jsxs(w.Fragment,{children:[w.jsx("button",{ref:s,type:"button",className:"icon-button","aria-label":P(t),"data-tooltip":P(t),"aria-haspopup":"menu","aria-expanded":a,"aria-controls":i,onClick:u=>{u.preventDefault(),r.current?.matches(":popover-open")?l():c()},onKeyDown:u=>{(u.key==="ArrowDown"||u.key==="ArrowUp")&&(u.preventDefault(),c(u.key==="ArrowUp"))},children:w.jsx(Te,{name:"more"})}),w.jsx("div",{ref:r,id:i,className:"command-menu panel-menu acp-menu",popover:"auto",role:"menu","aria-label":P(t),onToggle:u=>n(u.newState==="open"),onKeyDown:u=>{if(["ArrowDown","ArrowUp","Home","End"].includes(u.key)){u.preventDefault();const d=o(),p=d.indexOf(u.currentTarget.ownerDocument.activeElement),g=u.key==="Home"?0:u.key==="End"?d.length-1:(p+(u.key==="ArrowDown"?1:d.length-1))%d.length;d[g]?.focus()}else(u.key==="Escape"||u.key==="Tab")&&(u.key==="Escape"&&u.preventDefault(),l(!0))},children:e.map(u=>w.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!0),u.run()},children:[w.jsx(Te,{name:u.icon,size:14}),w.jsx("span",{children:P(u.label)})]},u.id))})]})}function jKe(t,e){return t.key!=="Enter"||t.isComposing||t.keyCode===229?!1:t.ctrlKey||t.metaKey?!0:t.shiftKey||t.altKey?!1:!e.coarse&&!e.modifierOnly}function zKe(t){if(!t.coarse)return t.modifierOnly?"Ctrl/Cmd+Enter to send":"Enter to send · Shift+Enter for new line"}const YG="(pointer: coarse)",BKe=t=>{const e=globalThis.matchMedia?.(YG);return e?.addEventListener("change",t),()=>e?.removeEventListener("change",t)},UKe=()=>L.useSyncExternalStore(BKe,()=>!!globalThis.matchMedia?.(YG).matches,()=>!1);function GG(t){const e=UKe(),i=L.useSyncExternalStore(t.subscribe,()=>t.get("agentACP.useModifierToSend")===!0);return{coarse:e,modifierOnly:i}}function XKe({configuration:t}){const e=zKe(GG(t));return e?w.jsx("span",{className:"muted acp-hint",children:P(e)}):null}function qKe(t,e){const i=/^\/([^\s/]*)$/.exec(t.slice(0,e));return i&&!/^\S/.test(t.slice(e))?i[1]:void 0}function VKe({value:t,commands:e,inputRef:i,actionsRef:s,configuration:r,onChange:a,onSend:n,onEscape:o,onMention:l,onImages:c,findFiles:u,findSymbols:d,findThreads:p,findCommits:g,branchDiff:y,onMentionOpen:k}){const $=L.useId(),_=GG(r),C=L.useRef(null),[b,Q]=L.useState(!1),[A,S]=L.useState(!1),[m,v]=L.useState(0),[E,D]=L.useState(0),[N,Z]=L.useState({query:"",paths:[],symbols:[],commits:[]}),J=(U,te)=>{a(U),v(te),i.current?.focus(),i.current?.ownerDocument.defaultView?.requestAnimationFrame(()=>{i.current?.setSelectionRange(te,te)})},se=m>=0?qKe(t,m):void 0,re=se===void 0&&m>=0?iKe(t,m):void 0;let M=[];if(se!==void 0)M=e.filter(U=>U.name.toLowerCase().startsWith(se.toLowerCase())).map(U=>({key:U.name,label:w.jsxs("strong",{children:["/",U.name]}),detail:U.description,choose:()=>{const te=t.slice(m).replace(/^\s+/,""),oe=`/${U.name} `;J(oe+te,oe.length),S(!0)}}));else if(re){const U=V=>{if(V.kind==="file"||V.kind==="symbol"||V.kind==="folder"){const ie=V.kind==="symbol"?V.name:V.kind==="folder"?`${V.path}/`:V.path,W=sKe(t,re.start,m,ie);J(W.value,W.caret)}else{const ie=re.start+re.query.length+1;J(t.slice(0,re.start)+t.slice(ie),re.start)}S(!0),l(V)},te=re.query.toLowerCase(),oe=N.query===re.query;M=[["selection","Selection","focus","Attach the editor selection"],["diagnostics","Diagnostics","warning","Attach the active file's diagnostics"],["changes","Changes","git","Attach uncommitted changes"],["branch","Branch diff","git","Attach this branch's changes since its base"]].filter(([V])=>V!=="branch"||y).filter(([,V])=>P(V).toLowerCase().includes(te)||V.toLowerCase().includes(te)).map(([V,ie,W,Y])=>({key:V,label:w.jsxs("strong",{children:[w.jsx(Te,{name:W,size:14})," ",P(ie)]}),detail:P(Y),choose:()=>U({kind:V})})).concat(oe?cKe(N.paths,re.query).map(V=>({key:`folder:${V}`,label:w.jsxs("strong",{children:[w.jsx(Te,{name:"folder",size:14})," ",V.slice(V.lastIndexOf("/")+1)]}),detail:`${V}/`,choose:()=>U({kind:"folder",path:V})})):[]).concat(oe?N.paths.map(V=>({key:V,label:w.jsx("strong",{children:V.slice(V.lastIndexOf("/")+1)}),detail:V,choose:()=>U({kind:"file",path:V})})):[]).concat(oe?N.symbols.map(V=>({key:`${V.path}:${V.line}:${V.name}`,label:w.jsxs("strong",{children:[w.jsx(Te,{name:"symbol",size:14})," ",V.name]}),detail:`${V.path}:${V.line}`,choose:()=>U(V)})):[]).concat(oe?N.commits.map(V=>({key:`commit:${V.id}`,label:w.jsxs("strong",{children:[w.jsx(Te,{name:"git",size:14})," ",V.subject]}),detail:`${V.id.slice(0,7)} · ${V.author} · ${new Date(V.date).toLocaleDateString()}`,choose:()=>U(V)})):[]).concat(p(re.query).map(V=>({key:`thread:${V.id}`,label:w.jsxs("strong",{children:[w.jsx(Te,{name:"clock",size:14})," ",V.title]}),detail:`${V.agent} · ${new Date(V.updatedAt).toLocaleDateString()}`,choose:()=>U(V)})))}const j=re?.query,q=L.useRef({findFiles:u,findSymbols:d,findCommits:g,onMentionOpen:k});q.current={findFiles:u,findSymbols:d,findCommits:g,onMentionOpen:k};const ae=re!==void 0;L.useEffect(()=>{ae&&q.current.onMentionOpen?.()},[ae]),L.useEffect(()=>{if(!j)return;const U=new AbortController,te=setTimeout(()=>{Promise.all([q.current.findFiles(j,U.signal).catch(()=>[]),q.current.findSymbols(j,U.signal).catch(()=>[]),q.current.findCommits(j,U.signal).catch(()=>[])]).then(([oe,V,ie])=>{U.signal.aborted||Z({query:j,paths:oe,symbols:V,commits:ie})},()=>{})},120);return()=>{clearTimeout(te),U.abort()}},[j]),L.useImperativeHandle(s,()=>({insertSlash(){const U=t.replace(/^\s+/,"");S(!1),D(0),J(U?`/ ${U}`:"/",1)}}));const F=b&&!A&&M.length>0,B=Math.min(E,M.length-1);return L.useEffect(()=>{const U=C.current,te=i.current,oe=te?.ownerDocument.defaultView;if(!F||!U||!te||!oe)return;const V=()=>{Object.assign(U.style,{left:"0px",top:"0px",bottom:"auto"});const ie=U.getBoundingClientRect();Object.assign(U.style,{top:"auto",bottom:"0px"});const W=U.getBoundingClientRect().bottom,Y=te.getBoundingClientRect(),le=oe.visualViewport,Pe=ie.top+(le?.offsetTop??0),we=ie.left+(le?.offsetLeft??0),be=le?.width??oe.innerWidth,Me=Math.min(W,Pe+(le?.height??oe.innerHeight)),je=Y.top-Pe>=Me-Y.bottom,Xe=je?`${Y.top-Pe-12}px - var(--safe-area-top)`:`${Me-Y.bottom-12}px`;Object.assign(U.style,{width:`${Math.min(Y.width,be-16)}px`,maxHeight:`max(0px, min(240px, ${Xe}))`,left:`${Math.max(we+8,Math.min(Y.left,we+be-Y.width-8))-ie.left}px`,top:je?"auto":`${Y.bottom+4-ie.top}px`,bottom:je?`${W-Y.top+4}px`:"auto"})};return U.showPopover(),V(),oe.addEventListener("resize",V),oe.addEventListener("scroll",V,!0),oe.visualViewport?.addEventListener("resize",V),oe.visualViewport?.addEventListener("scroll",V),()=>{U.isConnected&&U.matches(":popover-open")&&U.hidePopover(),oe.removeEventListener("resize",V),oe.removeEventListener("scroll",V,!0),oe.visualViewport?.removeEventListener("resize",V),oe.visualViewport?.removeEventListener("scroll",V)}},[F,i]),L.useEffect(()=>{F&&C.current?.children[B]?.scrollIntoView({block:"nearest"})},[F,B]),w.jsxs(w.Fragment,{children:[w.jsx("textarea",{ref:i,"data-local-submit":!0,"aria-label":P("Message agent"),"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":F?$:void 0,"aria-activedescendant":F?`${$}-${B}`:void 0,enterKeyHint:_.coarse?"enter":"send",placeholder:P("Ask your agent to help with this workspace…"),value:t,onFocus:()=>{Q(!0),S(!1)},onBlur:()=>Q(!1),onSelect:U=>v(U.currentTarget.selectionStart===U.currentTarget.selectionEnd?U.currentTarget.selectionStart:-1),onChange:U=>{a(U.target.value),v(U.target.selectionStart),D(0),S(!1)},onPaste:U=>{const te=jG(U.clipboardData);te.length&&(U.preventDefault(),c(te))},onKeyDown:U=>{if(!(U.nativeEvent.isComposing||U.keyCode===229)){if(F&&!U.metaKey&&!U.ctrlKey&&!U.altKey&&!U.shiftKey&&["ArrowDown","ArrowUp","Enter","Tab","Escape"].includes(U.key)){U.preventDefault(),U.stopPropagation(),U.key==="Escape"?S(!0):U.key==="ArrowDown"||U.key==="ArrowUp"?D((B+(U.key==="ArrowDown"?1:M.length-1))%M.length):M[B].choose();return}if(U.key==="Escape"&&o?.()){U.preventDefault(),U.stopPropagation();return}jKe(U,_)&&(U.preventDefault(),n())}},rows:2}),w.jsx("div",{ref:C,id:$,popover:"manual",className:"acp-slash-commands",role:"listbox","aria-label":P(se!==void 0?"Agent slash commands":"Mention files and context"),children:F&&M.map((U,te)=>w.jsxs("button",{id:`${$}-${te}`,type:"button",role:"option",tabIndex:-1,"aria-selected":te===B,onMouseDown:oe=>oe.preventDefault(),onClick:U.choose,children:[U.label,U.detail&&w.jsx("span",{children:U.detail})]},U.key))})]})}class ZKe{diff(e,i,s={}){let r;typeof s=="function"?(r=s,s={}):"callback"in s&&(r=s.callback);const a=this.castInput(e,s),n=this.castInput(i,s),o=this.removeEmpty(this.tokenize(a,s)),l=this.removeEmpty(this.tokenize(n,s));return this.diffWithOptionsObj(o,l,s,r)}diffWithOptionsObj(e,i,s,r){var a;const n=C=>{if(C=this.postProcess(C,s),r){setTimeout(function(){r(C)},0);return}else return C},o=i.length,l=e.length;let c=1,u=o+l;s.maxEditLength!=null&&(u=Math.min(u,s.maxEditLength));const d=(a=s.timeout)!==null&&a!==void 0?a:1/0,p=Date.now()+d,g=[{oldPos:-1,lastComponent:void 0}];let y=this.extractCommon(g[0],i,e,0,s);if(g[0].oldPos+1>=l&&y+1>=o)return n(this.buildValues(g[0].lastComponent,i,e));let k=-1/0,$=1/0;const _=()=>{for(let C=Math.max(k,-c);C<=Math.min($,c);C+=2){let b;const Q=g[C-1],A=g[C+1];Q&&(g[C-1]=void 0);let S=!1;if(A){const v=A.oldPos-C;S=A&&0<=v&&v<o}const m=Q&&Q.oldPos+1<l;if(!S&&!m){g[C]=void 0;continue}if(!m||S&&Q.oldPos<A.oldPos?b=this.addToPath(A,!0,!1,0,s):b=this.addToPath(Q,!1,!0,1,s),y=this.extractCommon(b,i,e,C,s),b.oldPos+1>=l&&y+1>=o)return n(this.buildValues(b.lastComponent,i,e))||!0;g[C]=b,b.oldPos+1>=l&&($=Math.min($,C-1)),y+1>=o&&(k=Math.max(k,C+1))}c++};if(r)(function C(){setTimeout(function(){if(c>u||Date.now()>p)return r(void 0);_()||C()},0)})();else for(;c<=u&&Date.now()<=p;){const C=_();if(C)return C}}addToPath(e,i,s,r,a){const n=e.lastComponent;return n&&!a.oneChangePerToken&&n.added===i&&n.removed===s?{oldPos:e.oldPos+r,lastComponent:{count:n.count+1,added:i,removed:s,previousComponent:n.previousComponent}}:{oldPos:e.oldPos+r,lastComponent:{count:1,added:i,removed:s,previousComponent:n}}}extractCommon(e,i,s,r,a){const n=i.length,o=s.length;let l=e.oldPos,c=l-r,u=0;for(;c+1<n&&l+1<o&&this.equals(s[l+1],i[c+1],a);)c++,l++,u++,a.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return u&&!a.oneChangePerToken&&(e.lastComponent={count:u,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=l,c}equals(e,i,s){return s.comparator?s.comparator(e,i):e===i||!!s.ignoreCase&&e.toLowerCase()===i.toLowerCase()}removeEmpty(e){const i=[];for(let s=0;s<e.length;s++)e[s]&&i.push(e[s]);return i}castInput(e,i){return e}tokenize(e,i){return Array.from(e)}join(e){return e.join("")}postProcess(e,i){return e}get useLongestToken(){return!1}buildValues(e,i,s){const r=[];let a;for(;e;)r.push(e),a=e.previousComponent,delete e.previousComponent,e=a;r.reverse();const n=r.length;let o=0,l=0,c=0;for(;o<n;o++){const u=r[o];if(u.removed)u.value=this.join(s.slice(c,c+u.count)),c+=u.count;else{if(!u.added&&this.useLongestToken){let d=i.slice(l,l+u.count);d=d.map(function(p,g){const y=s[c+g];return y.length>p.length?y:p}),u.value=this.join(d)}else u.value=this.join(i.slice(l,l+u.count));l+=u.count,u.added||(c+=u.count)}}return r}}class WKe extends ZKe{constructor(){super(...arguments),this.tokenize=GKe}equals(e,i,s){return s.ignoreWhitespace?((!s.newlineIsToken||!e.includes(`
391
391
  `))&&(e=e.trim()),(!s.newlineIsToken||!i.includes(`
@@ -405,7 +405,7 @@ ${d}`;o+p.length>i||(o+=p.length,n.push(p))}const l=`${s.length}${r?"+":""} file
405
405
  ${e.newText??""}`:JSON.stringify(e))).join(`
406
406
  `):t.content}function gJe(t,e){const i=Ua(e.rawInput),s=Ua(e._meta?.codex),r=Ua(e._meta?.oxbit),a=e.toolCallId;if(!hr(a))return[];if(t==="codex"){const n=Ua(s.collaboration),o=Ua(s.subagent);if(hr(o.threadId))return[{providerId:o.threadId,toolId:a,name:rs(rs(o.path)?.split("/").filter(Boolean).at(-1),200),state:xg(o.activity==="started"?"running":o.activity),evidence:"provider",spawn:o.activity==="started"}];if(!hr(n.tool))return[];const l=Array.isArray(n.receiverThreadIds)?n.receiverThreadIds.filter(hr):[],c=Ua(i.agentsStates),u=[...new Set([...l,...Object.keys(c).filter(hr)])];return!u.length&&n.tool==="spawnAgent"?[{toolId:a,task:rs(i.prompt),state:e.status==="failed"?"failed":"unknown",evidence:"tool",spawn:!0}]:u.map(d=>({providerId:d,toolId:a,parent:rs(n.senderThreadId,512),task:rs(i.prompt),model:rs(i.model,200),state:xg(c[d]?.status)??(n.tool==="spawnAgent"&&e.status==="failed"?"failed":void 0),result:rs(c[d]?.message,16384),evidence:"provider",spawn:n.tool==="spawnAgent",reopen:["resumeAgent","sendInput","followupTask"].includes(n.tool)&&["running","pendingInit"].includes(c[d]?.status)}))}if(t==="cursor"&&e.taskMeta){const n=Ua(e.taskMeta),o=Ua(e.rawOutput),l=Ua(n.outcome??o.outcome),c=typeof(n.outcome??o.outcome)=="string"?n.outcome??o.outcome:l.outcome;return[{toolId:a,providerId:hr(n.agentId??l.agentId)?n.agentId??l.agentId:void 0,name:rs(n.description,200),task:rs(n.prompt),model:rs(n.model,200),durationMs:Number.isFinite(n.durationMs??l.durationMs)&&(n.durationMs??l.durationMs)>=0?n.durationMs??l.durationMs:void 0,state:xg(c),result:Eb(n.result??l.result??o.result),evidence:xg(c)?"provider":"tool",spawn:!0}]}if(t==="amp"&&e.kind==="think"&&/^Task(?:: |$)/.test(e.title??"")&&(typeof i.prompt=="string"||typeof i.description=="string"||typeof i.subagent_type=="string"))return[{toolId:a,name:rs(i.description??i.subagent_type,200),task:rs(i.prompt),model:rs(i.model,200),state:e.status==="failed"?"failed":"unknown",evidence:"tool",spawn:!0}];if(JG.has(t)&&r.subagent){const n=Ua(r.subagent),o=mJe.has(n.state)?n.state:void 0;return[{toolId:a,providerId:hr(n.sessionId)?n.sessionId:void 0,name:rs(n.name,200),task:rs(n.task),model:rs(n.model,200),state:o&&Br(o)?o:e.status==="completed"||e.status==="failed"?e.status:o??"pending",evidence:"provider",spawn:!0}]}return[]}class OJe{constructor(e,i,s){this.provider=e,this.root=i,this.emit=s}provider;root;emit;records=new Map;sessions=new Map;fallbackStates=new Map;tools=new Map;aliases=new Map;waits=new Map;early=new Map;earlyStates=new Map;serial=0;truncated=!1;replaying=!1;accepts(e){return e===this.root||hr(e)&&this.sessions.has(e)}acceptsRequest(e){return e===this.root||this.sessions.has(e)&&!Br(this.sessions.get(e).state)}get activeCount(){return[...this.sessions.values()].filter(i=>!i.historical&&["pending","running"].includes(i.state)).length+[...this.fallbackStates.values()].filter(i=>!i.historical&&["pending","running"].includes(i.state)).length}idForSession(e){return this.sessions.has(e)?`${this.provider}:${e}`:void 0}idForTool(e,i){return this.aliases.get(`tool:${Uy(e,i)}`)}create(e,i){const s=new Date().toISOString();return{id:e,parentId:i,rootSessionId:this.root,provider:this.provider,name:"Subagent",task:"",toolCallIds:[],state:"unknown",phase:"unknown",evidence:"tool",visibility:"limited",order:++this.serial,observedAt:s,updatedAt:s,activity:[],historical:this.replaying}}publish(e,i=[],s=!1){for(e.updatedAt=new Date().toISOString(),e.historical=s?!1:this.replaying,e.activity.length>32&&(e.activity.splice(0,e.activity.length-32),e.truncated=!0),this.records.set(e.id,e);this.records.size>256;){const n=[...this.records.values()].find(o=>o.id!==e.id&&Br(o.state))??[...this.records.values()].find(o=>o.id!==e.id);this.records.delete(n.id),i.push(n.id),this.truncated=!0}let r=[...this.records.values()].reduce((n,o)=>n+JSON.stringify(o.activity).length,0);const a=[];for(const n of this.records.values()){if(r<=512e3)break;n.activity.length&&(r-=JSON.stringify(n.activity).length,n.activity=[],n.truncated=!0,a.push(n))}for(const n of a)n!==e&&this.emit({subagent:structuredClone(n),activeCount:this.activeCount,removedIds:[],truncated:this.truncated});this.emit({subagent:structuredClone(e),activeCount:this.activeCount,removedIds:i,truncated:this.truncated})}transition(e,i){!i||Br(e.state)||(e.state=i,Br(i)&&(e.endedAt=new Date().toISOString(),e.phase="unknown"))}observe(e,i){if(!this.accepts(e)){if(Z_.has(this.provider)&&hr(e)&&this.early.size<32&&JSON.stringify(i).length<=16384){const a=this.early.get(e)??[];a.length<8&&a.push(structuredClone(i)),this.early.set(e,a)}return!1}if(Z_.has(this.provider)&&i.sessionUpdate==="subagent_spawned"){const a=i.subagentSessionId;if(!hr(a)||a===this.root||a===e)return!1;const n=this.sessions.get(a);if(n&&n.parent!==e)return!1;if(!n&&this.sessions.size>=1024)throw new Error("Too many registered subagent sessions");this.sessions.set(a,n??{parent:e,state:"running",historical:this.replaying});const o=`${this.provider}:${a}`;this.fallbackStates.delete(o);const l=this.records.get(o)??this.create(o,this.idForSession(e));l.evidence!=="native"&&(l.state="unknown",l.phase="unknown",l.endedAt=void 0),Object.assign(l,{parentId:this.idForSession(e),sessionId:a,providerId:a,name:rs(i.name,200)||l.name,task:rs(i.task)??l.task,evidence:"native",visibility:"full"}),this.transition(l,n?.state??"running");const c=this.earlyStates.get(a);c?.parent===e&&(this.transition(l,c.state),this.sessions.get(a).state=l.state,this.earlyStates.delete(a)),this.publish(l);for(const u of this.early.get(a)??[])this.observe(a,u);return this.early.delete(a),!0}if(Z_.has(this.provider)&&i.sessionUpdate==="subagent_state_update"){const a=i.subagentSessionId,n=xg(i.state),o=this.sessions.get(a);if(!hr(a)||!n||!Br(n))return!1;if(!o)return this.earlyStates.size<64&&this.earlyStates.set(a,{parent:e,state:n}),!1;if(o.parent!==e)return!1;Br(o.state)||(o.state=n),o.historical=this.replaying;const l=this.records.get(`${this.provider}:${a}`)??this.create(`${this.provider}:${a}`,this.idForSession(e));return Object.assign(l,{sessionId:a,providerId:a,evidence:"native",visibility:"full"}),this.transition(l,o.state),this.publish(l),!0}const s=this.idForSession(e);s&&this.activity(e,i);const r=Ua(i._meta?.oxbit).subagentOf;if(JG.has(this.provider)&&hr(r)&&hr(i.toolCallId)&&["tool_call","tool_call_update"].includes(i.sessionUpdate))return this.forwarded(e,r,i),!0;if(["tool_call","tool_call_update","cursor/task"].includes(i.sessionUpdate)&&hr(i.toolCallId)){const a=Uy(e,i.toolCallId),n=this.tools.get(a)??{},o=i.sessionUpdate==="cursor/task"?{...n,toolCallId:i.toolCallId,taskMeta:{...n.taskMeta,...i}}:{...n,...i};for(["completed","failed"].includes(n.status)&&(o.status=n.status),JSON.stringify(o).length<=65536&&this.tools.set(a,o);this.tools.size>256;)this.tools.delete(this.tools.keys().next().value);for(const l of gJe(this.provider,o)){if(l.providerId===this.root||l.providerId===e)continue;let c=l.providerId?`${this.provider}:${l.providerId}`:`tool:${a}`;const u=l.providerId&&this.aliases.get(`provider:${l.providerId}`);u&&(c=u);const d=this.records.get(c),p=this.fallbackStates.get(c);l.reopen&&!this.sessions.has(l.providerId??"")&&Br(p?.state??d?.state??"unknown")&&p?.reopenToolId!==l.toolId&&(c=`generation:${JSON.stringify([this.provider,l.providerId,l.toolId])}`);const g=`tool:${a}`,y=this.records.get(g),k=l.spawn&&l.parent?this.aliases.get(`provider:${l.parent}`)??this.idForSession(l.parent):s,$=this.records.get(c)??(y?{...y,id:c,parentId:k??y.parentId}:this.create(c,k)),_=l.providerId&&this.sessions.get(l.providerId);if(_)Object.assign($,{sessionId:l.providerId,parentId:this.idForSession(_.parent),evidence:"native",visibility:"full"}),this.transition($,_.state);else{const b=this.fallbackStates.get(c);b&&this.transition($,b.state)}const C=[];for(y&&g!==c&&(this.records.delete(g),this.fallbackStates.delete(g),C.push(g)),l.providerId&&this.aliases.set(`provider:${l.providerId}`,c),this.aliases.set(`tool:${Uy(e,l.toolId)}`,c);this.aliases.size>2048;)this.aliases.delete(this.aliases.keys().next().value);if($.toolCallIds.includes(l.toolId)||($.toolCallIds=[...$.toolCallIds,l.toolId].slice(-32)),$.providerId=l.providerId??$.providerId,$.name=l.name||$.name,l.spawn&&($.task=l.task??$.task),$.model=l.model??$.model,$.durationMs=l.durationMs??$.durationMs,$.result=l.result??$.result,$.evidence!=="native"){if($.evidence!=="provider"&&($.evidence=l.evidence),this.transition($,l.state),!this.fallbackStates.has(c)&&this.fallbackStates.size>=1024)throw new Error("Too many tracked subagents");this.fallbackStates.set(c,{state:$.state,historical:this.replaying,reopenToolId:l.reopen?l.toolId:this.fallbackStates.get(c)?.reopenToolId})}!$.result&&["completed","failed"].includes(o.status)&&($.result=Eb(WI(o),16384)),this.toolActivity($,o),this.publish($,C)}}return!0}forwarded(e,i,s){const r=this.idForTool(e,i),a=r&&this.records.get(r);if(a){for(this.aliases.set(`tool:${Uy(e,s.toolCallId)}`,r);this.aliases.size>2048;)this.aliases.delete(this.aliases.keys().next().value);if(this.toolActivity(a,s),!Br(a.state)){const n=a.activity.find(o=>o.id===`tool:${s.toolCallId}`)?.status;a.phase=this.waits.get(r)?.size?"awaiting_input":["pending","in_progress"].includes(n??"")?"executing_tools":"unknown"}this.publish(a)}}toolActivity(e,i){const s=`tool:${i.toolCallId}`;let r=e.activity.find(a=>a.id===s);r||(r={id:s,kind:"tool"},e.activity.push(r)),r.title=rs(i.title,200)??r.title??"Delegated task",["completed","failed"].includes(r.status??"")||(r.status=rs(i.status,40)??r.status),r.input=Eb(i.rawInput)??r.input,r.output=Eb(WI(i))??r.output,r.locations=Array.isArray(i.locations)?i.locations.filter(a=>typeof a.path=="string").slice(0,16).map(a=>({path:a.path.slice(0,4096),line:Number.isSafeInteger(a.line)?a.line:void 0})):r.locations}activity(e,i){const s=this.idForSession(e),r=this.sessions.get(e),a=this.records.get(s)??this.create(s,this.idForSession(r.parent));Object.assign(a,{sessionId:e,evidence:"native",visibility:"full"}),this.transition(a,r.state);let n;if(["agent_message_chunk","agent_thought_chunk","user_message_chunk"].includes(i.sessionUpdate)){const o=i.sessionUpdate==="agent_thought_chunk"?"thought":i.sessionUpdate==="user_message_chunk"?"user":"agent",l=rs(i.content?.text??i.content?.resource?.text,16384)??"",c=a.activity.at(-1);let u=hr(i.messageId)?a.activity.find(d=>d.kind==="message"&&d.id===`message:provider:${i.messageId}`):c?.kind==="message"&&c.role===o?c:void 0;u||(u={id:hr(i.messageId)?`message:provider:${i.messageId}`:`message:local:${++this.serial}`,kind:"message",role:o,text:""},a.activity.push(u)),u.text.length+l.length>16384&&(a.truncated=!0),u.text=(u.text+l).slice(-16384),o==="agent"?(a.result=u.text,n="responding"):o==="thought"&&(n="thinking")}else if(["tool_call","tool_call_update"].includes(i.sessionUpdate)&&hr(i.toolCallId))this.toolActivity(a,i),n=a.activity.some(o=>o.kind==="tool"&&["pending","in_progress"].includes(o.status??""))?"executing_tools":"unknown";else return;Br(r.state)||(r.state="running",r.historical=this.replaying,a.state="running",a.phase=this.waits.get(e)?.size?"awaiting_input":n??a.phase),this.publish(a)}waiting(e,i,s,r){const a=this.idForSession(e)??(r?this.idForTool(e,r):void 0);if(!a)return;const n=this.idForSession(e)?e:a,o=this.waits.get(n)??new Set;s?o.add(i):o.delete(i),o.size?this.waits.set(n,o):this.waits.delete(n);const l=this.records.get(a);if(l&&!Br(l.state)){const c=this.sessions.get(e);c&&(c.historical=!1),l.phase=o.size?"awaiting_input":"unknown",this.publish(l,[],!0)}}terminal(e,i,s,r,a){const n=this.idForSession(e),o=n&&this.records.get(n);if(!o)return;const l=`terminal:${i}`,c=o.activity.find(u=>u.id===l)??{id:l,kind:"terminal"};o.activity.includes(c)||o.activity.push(c),Object.assign(c,{title:s.slice(0,200),text:r.slice(-8192),status:a?"completed":"in_progress"}),r.length>8192&&(o.truncated=!0),!Br(o.state)&&!this.waits.get(e)?.size&&(o.phase=a?"unknown":"executing_tools"),this.publish(o)}disconnect(){for(const e of this.fallbackStates.values())Br(e.state)||(e.state="disconnected");for(const e of this.sessions.values())Br(e.state)||(e.state="disconnected");for(const e of this.records.values())Br(e.state)||(this.transition(e,"disconnected"),this.publish(e))}}const yJe=[{value:"on",name:"On"},{value:"off",name:"Off"}],ig=(t,e)=>t.update({sessionUpdate:"agent_message_chunk",content:{type:"text",text:e}});function bJe(t){const e=()=>t.get(ef.auto)!==!1,i=()=>{const o=String(t.get(ef.at)??"");return vg.includes(o)?o:"default"},s=()=>[{id:"auto-compact",name:"Auto-compact",type:"select",currentValue:e()?"on":"off",options:yJe},{id:"compact-at",name:"Compact at",type:"select",currentValue:i(),options:[{value:"default",name:"Default"},...vg.map(o=>({value:o,name:`${o}%`}))]}];async function r(o,l){const c=l.trim().toLowerCase().replace(/%$/,"");if(o==="auto-compact"&&(c==="on"||c==="off"))await t.set(ef.auto,c==="on","user");else if(o==="compact-at"&&(c==="default"||vg.includes(c)))await t.set(ef.at,c,"user");else return!1;return!0}return{compaction:new XGe({get auto(){return e()},get percent(){const o=Number(i());return Number.isFinite(o)?o:void 0}}),options:s,set:r,config:{name:"config",description:"Show or change agent settings",hint:"<setting> <value>",run:async(o,l)=>{const[c="",u=""]=o.trim().split(/\s+/,2),d=Vl.find(p=>p.id===l.session.meta.mode)??Vl[0];if(!c)ig(l,["## Config",`1. Permission mode \`mode\`: ${d.id} (${Vl.map(p=>p.id).join(", ")})`,`2. Auto-compact \`auto-compact\`: ${e()?"on":"off"} (on, off)`,`3. Compact at \`compact-at\`: ${i()} (default, ${vg.join(", ")})`,"","Usage: `/config <setting> <value>`, for example `/config auto-compact off`, `/config compact-at 80` or `/config mode full-auto`."].join(`
407
407
  `));else if(c==="mode"){const p=Vl.find(g=>g.id===u);p?(l.session.meta.mode=p.id,l.update({sessionUpdate:"current_mode_update",currentModeId:p.id}),ig(l,`Permission mode: ${p.name}`)):ig(l,`Unknown mode ${u||"(none)"}. Use one of: ${Vl.map(g=>g.id).join(", ")}`)}else await r(c,u)?ig(l,c==="auto-compact"?`Auto-compact is ${e()?"on":"off"}`:i()==="default"?"Auto-compact uses the default threshold":`Auto-compact starts at ${i()}% of the context window`):ig(l,`Unknown setting or value: ${o.trim()}. Run /config to list the settings.`);return{done:"end_turn"}}}}}function wJe({filesystem:t,root:e,configuration:i,sessions:s,update:r}){const a=QHe(t,e),n=new RHe({files:a}),o=new zHe({files:a,roots:[]}),l=_He({update:r}),c=bJe(i);return{extensions:{context:[n,...l.context,o],tools:[...l.tools,o],commands:[c.compaction,...l.commands,{commands:()=>[c.config]},{commands:async d=>(await o.discover(d.cwd),o.commands(d).filter(p=>p.name!=="config"))}],continuations:l.continuations,compactor:c.compaction,sessions:s},settings:c}}const vJe=16,W_=2*1024*1024,A6=/^[\w.-]{1,128}$/,Y_=t=>JSON.stringify(t).length;function kJe(t){const e=t.findLastIndex(i=>i.role==="user");return t.map((i,s)=>i.role==="tool"&&s<e?{role:"tool",results:i.results.map(r=>({...r,output:v6}))}:i)}function SJe(t){if(Y_(t)<=W_)return t;const e=PG(t).turns;if(Y_(e)<=W_)return e;const i=kJe(e);if(Y_(i)<=W_)return i;throw new Error("This conversation is over 2 MiB, so it was not saved. Run /compact to save it again.")}const YI=t=>t&&typeof t=="object"&&typeof t.id=="string"&&A6.test(t.id)&&typeof t.cwd=="string"?{id:t.id,cwd:t.cwd,title:String(t.title??""),model:String(t.model??""),meta:t.meta&&typeof t.meta=="object"?t.meta:{},updatedAt:String(t.updatedAt??"")}:void 0;function xJe(){const t=new Map;return{get:async e=>structuredClone(t.get(e)),set:async(e,i)=>{t.set(e,structuredClone(i))},delete:async e=>{t.delete(e)}}}class $Je{constructor(e,i,s){this.storage=e,this.scope=i,this.root=s}storage;scope;root;index;writes=Promise.resolve();key(e){return`oxbit-agent-session:${this.scope}:${e}`}summaries(){return this.index??=this.storage.get(`oxbit-agent-sessions:${this.scope}`).then(e=>(Array.isArray(e)?e:[]).map(YI).filter(i=>!!i),()=>[])}save(e){const i=this.writes.then(async()=>{if(!A6.test(e.id))throw new Error("Invalid session ID");const{turns:s,...r}=e;await this.storage.set(this.key(e.id),{...e,turns:SJe(s)});const a=[r,...(await this.summaries()).filter(n=>n.id!==e.id)].sort((n,o)=>o.updatedAt.localeCompare(n.updatedAt));for(const n of a.splice(vJe))await this.storage.delete(this.key(n.id));this.index=Promise.resolve(a),await this.storage.set(`oxbit-agent-sessions:${this.scope}`,a)});return this.writes=i.catch(()=>{}),i}async load(e){if(!A6.test(e))return;await this.writes;const i=await this.storage.get(this.key(e)),s=YI(i);return s?.id===e&&Array.isArray(i?.turns)?{...s,cwd:this.root,turns:i.turns}:void 0}async list(e){return await this.writes,e===this.root?(await this.summaries()).map(i=>({...i,cwd:e})):[]}}const _Je=1024*1024,CJe=t=>JSON.parse(JSON.stringify(t??[],(e,i)=>e==="data"?void 0:i)),sn=(t,e,i=_Je)=>{const s=t[e];if(typeof s!="string"||s.length>i)throw new Error(`Invalid ${e}`);return s},G_=t=>t.toolCallId??t.toolCall?.toolCallId,GI=t=>t.messageId===void 0?crypto.randomUUID():sn(t,"messageId",256);function AJe(t){const e=t.root;return typeof e=="string"&&e.startsWith("/")?e.replace(/\/+$/,"")||"/":`/${t.id}`}class TJe{constructor(e,i,s){this.options=e,this.models=i,this.retry=s,this.root=AJe(e.filesystem);const r=e.workbench?.persistence;this.sessions=new $Je(r??xJe(),e.filesystem.id,this.root)}options;models;retry;local=!0;listeners=new Map;connections=new Map;root;sessions;get connected(){return!!this.models()}subscribe(e,i){const s=this.listeners.get(e)??new Set;return this.listeners.set(e,s),s.add(i),()=>s.delete(i)}async request(e,i={},s={}){return e.startsWith("git.")&&e!=="git.branchDiff"&&this.options.git?this.options.git.request(e,i,s):await this.handle(e,i,s.signal)}async handle(e,i,s){switch(e){case"acp.start":if(i.provider!==Wi)break;return this.start(s);case"acp.call":return this.call(this.get(i.id),sn(i,"method"),i.params??{});case"acp.cancel":return this.cancel(this.get(i.id));case"acp.respond":return this.respond(this.get(i.id),sn(i,"requestId"),i.result,i.error);case"acp.stop":return this.stop(this.get(i.id),"Agent disconnected");case"acp.enqueue":case"acp.interrupt":return this.enqueue(this.get(i.id),i,e==="acp.interrupt");case"acp.dequeue":return this.dequeue(this.get(i.id),sn(i,"promptId"));case"acp.moveQueued":return this.moveQueued(this.get(i.id),sn(i,"promptId"),i.index);case"acp.resumeQueue":{const r=this.get(i.id);return r.queuePaused=!1,this.publishQueue(r),queueMicrotask(()=>this.runQueue(r)),{}}case"acp.detach":case"acp.disconnect":return{};case"acp.registry":return{agents:[],fetchedAt:new Date().toISOString(),error:"The ACP Registry needs a runtime workspace"};case"acp.checkpoint.create":return{unavailable:"failed"}}throw new Error(`${e} needs a runtime workspace`)}get(e){const i=typeof e=="string"?this.connections.get(e):void 0;if(!i||i.stopped)throw new Error("Agent connection has ended");return i}publish(e,i,s){const r={id:e.connection.id,...s,seq:++e.seq};for(const a of[...this.listeners.get(i)??[]])try{a(r)}catch(n){console.error(n)}}publishQueue(e){return this.publish(e,"acp.queue",{queue:e.queue,paused:e.queuePaused}),{queue:[...e.queue],paused:e.queuePaused}}async start(e){const i=this.models();if(!i)throw new Error("Connect to a runtime workspace first");const s=lv(this.options.kernel.configuration);if(!await i.keys.has(s))throw new Error(s.api==="chatgpt"?nj:rj);if(e?.aborted)throw new Error("Agent connection cancelled");const r=crypto.randomUUID(),a=()=>this.connections.get(r),n=this.options.kernel.configuration,o=(g,y)=>{const k=a(),$=k?.subagents;!k||!$?.observe(g,y)||(g===$.root&&y.sessionUpdate==="current_mode_update"&&k.connection.modes&&(k.connection.modes.currentModeId=y.currentModeId),this.publish(k,"acp.update",{rootSessionId:$.root,sessionId:g,update:y}),y.sessionUpdate==="subagent_state_update"&&!$.acceptsRequest(y.subagentSessionId)&&this.expire(k,y.subagentSessionId))},{extensions:l,settings:c}=wJe({filesystem:this.options.filesystem,root:this.root,configuration:n,sessions:this.sessions,update:o}),u=new gHe({models:this.models,endpoint:()=>lv(n),capabilities:{fs:!0,terminal:!1,childSessions:!0},subagents:{},model:()=>n.get(so.model),saveModel:g=>n.set(so.model,g,"user"),filesystem:this.options.filesystem,root:this.root,generateTitles:!1,update:o,request:(g,y)=>{const k=a();return k?this.clientRequest(k,g,y):Promise.reject(new Error("Agent connection has ended"))},configOptions:()=>c.options(),setConfigOption:(g,y,k)=>c.set(y,k),extensions:l,retry:this.retry}),d=u.initialize(),p={connection:{id:r,provider:Wi,name:"Oxbit Agent",root:this.root,authMethods:[],agentInfo:d.agentInfo,capabilities:d.agentCapabilities},agent:u,settings:c,seq:0,busy:!1,stopped:!1,queue:[],queuePaused:!1,queueRunning:!1,approvals:new Map};return this.connections.set(p.connection.id,p),structuredClone(p.connection)}async call(e,i,s){if(e.busy)throw new Error("Wait for the current agent operation or stop it first");if(i==="session/list")return{sessions:(await e.agent.listSessions({cwd:this.root})).sessions.slice(0,200)};if(i==="session/new"||i==="session/fork"||i==="session/load"){if(e.subagents?.activeCount)throw new Error("Wait for active subagents or disconnect before changing conversations");if(e.approvals.size)throw new Error("Resolve pending requests before changing conversations");if(e.queue.length)throw new Error("Remove queued messages before changing conversations");const a=e.connection.sessionId;if(i==="session/fork"&&!a)throw new Error("Start a conversation first");const{sessionId:n,modes:o,models:l,configOptions:c}=e.connection,u=e.subagents;e.busy=!0;try{let d;return i==="session/load"?(e.connection.sessionId=sn(s,"sessionId",128),e.subagents=this.registry(e,e.connection.sessionId,!0),d=await e.agent.loadSession({sessionId:e.connection.sessionId,cwd:this.root}),e.subagents.replaying=!1):(e.subagents=void 0,d=i==="session/fork"?e.agent.forkSession(a):await e.agent.newSession(),e.subagents=this.registry(e,d.sessionId)),Object.assign(e.connection,d),e.queuePaused=!1,structuredClone(e.connection)}catch(d){throw Object.assign(e.connection,{sessionId:n,modes:o,models:l,configOptions:c}),e.subagents=u,d}finally{e.busy=!1}}const r=e.connection.sessionId;if(!r)throw new Error("Start a conversation first");if(i==="session/set_mode"){const a=e.agent.setMode(r,sn(s,"modeId"));return e.connection.modes&&(e.connection.modes.currentModeId=s.modeId),a}if(i==="session/set_model"||i==="session/set_config_option"){const a=i==="session/set_model"?e.agent.setModel(r,sn(s,"modelId")):await e.agent.setConfigOption(r,sn(s,"configId"),sn(s,"value"));e.connection.configOptions=a.configOptions;const n=a.configOptions.find(l=>l.id==="model")?.currentValue;e.connection.models&&n&&(e.connection.models.currentModelId=n);const o=a.configOptions.find(l=>l.id==="mode")?.currentValue;return e.connection.modes&&o&&(e.connection.modes.currentModeId=o),structuredClone(a)}if(i!=="session/prompt")throw new Error("Unsupported ACP client method");return this.prompt(e,r,s)}contextBlocks(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>8)throw new Error("Attach up to eight context items");return e.map(i=>{if(i?.kind==="image")throw new Error("This agent does not accept images");const s=sn(i??{},"text",2e5),{relative:r,absolute:a}=Cp(this.root,sn(i,"path")),n=typeof i.label=="string"?i.label.slice(0,1024):r||".";return{type:"resource",resource:{uri:encodeURI(`file://${a}`)+(Number.isSafeInteger(i.line)?`#L${i.line}`:""),mimeType:"text/plain",text:`Editor snapshot: ${n}
408
- ${s}`}}})}async prompt(e,i,s){const r=sn(s,"text");if(!r.trim())throw new Error("Enter a message");const a=[{type:"text",text:r},...this.contextBlocks(s.context)],n=GI(s);e.busy=!0,e.queuePaused&&(e.queuePaused=!1,this.publishQueue(e)),this.publish(e,"acp.turnStarted",{messageId:n,text:r,context:CJe(s.context)});let o,l;try{const c=await e.agent.prompt(i,a);return o=c.stopReason,o!=="end_turn"&&o!=="cancelled"&&(e.queuePaused=!0),c}catch(c){throw l=c instanceof Error?c.message:String(c),e.queuePaused=!0,c}finally{this.expire(e,i),e.busy=!1,e.stopped||(this.refreshOptions(e,i),this.publish(e,"acp.turnEnded",{stopReason:o,error:l}),this.publishQueue(e),queueMicrotask(()=>this.runQueue(e)))}}refreshOptions(e,i){const s=e.connection.configOptions;if(!s||e.connection.sessionId!==i)return;const r=new Map(e.settings.options().map(o=>[o.id,o])),a=e.connection.modes?.currentModeId,n=s.map(o=>r.get(o.id)??(o.id==="mode"&&a?{...o,currentValue:a}:o));JSON.stringify(n)!==JSON.stringify(s)&&(e.connection.configOptions=n,this.publish(e,"acp.update",{sessionId:i,update:{sessionUpdate:"config_option_update",configOptions:n}}))}registry(e,i,s=!1){const r=new OJe(Wi,i,a=>this.publish(e,"acp.subagent",{rootSessionId:i,...a}));return r.replaying=s,r}settle(e,i,s){e.subagents?.waiting(s.sessionId,i,!1,G_(s))}clientRequest(e,i,s){const r=e.subagents;if(!r?.acceptsRequest(s.sessionId))return Promise.reject(new Error("Unknown ACP session"));if(e.approvals.size>=32)return Promise.reject(new Error("Too many pending agent requests"));const a={...s};try{i.startsWith("fs/")&&(a.path=iGe(this.root,s.path))}catch(n){return Promise.reject(n)}for(const n of Object.keys(a))a[n]===void 0&&delete a[n];return new Promise((n,o)=>{const l=crypto.randomUUID(),c=a.sessionId;e.approvals.set(l,{method:i,params:a,resolve:n,reject:o}),i!=="fs/read_text_file"&&!i.startsWith("oxbit/")&&r.waiting(c,l,!0,G_(a)),this.publish(e,"acp.request",{requestId:l,sessionId:c,rootSessionId:r.root,subagentId:r.idForSession(c)??r.idForTool(c,G_(a)),method:i,params:a})})}respond(e,i,s,r){const a=e.approvals.get(i);if(!a)throw new Error("Agent request has expired");return e.approvals.delete(i),this.settle(e,i,a.params),r!=null?a.reject(new Error(String(r).slice(0,4096))):a.resolve(s),{}}expire(e,i){const s=[];for(const[r,a]of e.approvals)a.params.sessionId===i&&(e.approvals.delete(r),this.settle(e,r,a.params),a.reject(new Error("Session turn ended")),s.push(r));s.length&&this.publish(e,"acp.requestsExpired",{requestIds:s})}cancel(e,i=!1){const s=e.connection.sessionId;e.queuePaused=!i,this.publishQueue(e),s&&e.agent.cancel(s);for(const[r,a]of e.approvals)a.params.sessionId===s&&(e.approvals.delete(r),this.settle(e,r,a.params),a.reject(new Error("Cancelled")));return this.publish(e,"acp.cancelled",{sessionId:s}),{}}dispose(){for(const e of[...this.connections.values()])this.stop(e,"Workspace closed");this.listeners.clear()}stop(e,i){if(e.stopped)return{};e.stopped=!0,e.agent.cancel();for(const s of e.approvals.values())s.reject(new Error(i));return e.approvals.clear(),e.subagents?.disconnect(),this.connections.delete(e.connection.id),this.publish(e,"acp.exit",{reason:i}),{}}enqueue(e,i,s){if(!e.connection.sessionId)throw new Error("Start a conversation first");const r=sn(i,"text").trim();if(!r)throw new Error("Enter a message");const a=GI(i);if(this.contextBlocks(i.context),e.queue.some(l=>l.id===a))return this.publishQueue(e);if(e.queue.length>=16)throw new Error("Queued messages exceed the limit; remove a message first");const n={id:a,text:r,...i.context?{context:structuredClone(i.context)}:{}};s?(e.queue.unshift(n),e.queuePaused=!1,e.busy&&this.cancel(e,!0)):e.queue.push(n);const o=this.publishQueue(e);return queueMicrotask(()=>this.runQueue(e)),o}dequeue(e,i){const s=e.queue.findIndex(a=>a.id===i);if(s<0)throw new Error("The queued message has already started or was removed");const[r]=e.queue.splice(s,1);return this.publishQueue(e),{prompt:r}}moveQueued(e,i,s){if(!Number.isInteger(s))throw new Error("Invalid index");const r=e.queue.findIndex(n=>n.id===i);if(r<0)throw new Error("The queued message has already started or was removed");const[a]=e.queue.splice(r,1);return e.queue.splice(Math.max(0,Math.min(s,e.queue.length)),0,a),this.publishQueue(e)}runQueue(e){if(e.busy||e.queueRunning||e.stopped||e.queuePaused||!e.queue.length)return;e.queueRunning=!0;const i=e.queue.shift();this.publishQueue(e),this.call(e,"session/prompt",{text:i.text,context:i.context,messageId:i.id}).catch(()=>{e.stopped||(e.queuePaused=!0,e.queue.unshift(i),this.publishQueue(e))}).finally(()=>{e.queueRunning=!1,this.runQueue(e)})}}const HI=[rj,nj];function xA({request:t,agent:e,full:i=!1}){const[s,r]=L.useState(!1),[a,n]=L.useState({}),o=async u=>{r(!0),await e.action(u),r(!1)},{params:l,method:c}=t;return w.jsxs("section",{className:"acp-approval","aria-label":P("Agent approval"),children:[w.jsxs("strong",{children:[w.jsx(Te,{name:"warning",size:14})," ",P(c==="fs/write_text_file"?"Review file change":c==="cursor/ask_question"?"Agent needs your input":c==="cursor/create_plan"?"Review plan":"Permission required")]}),t.subagentId&&w.jsxs("p",{className:"acp-request-agent",children:[P("From subagent"),":"," ",e.subagents.get(t.subagentId)?.name??t.subagentId]}),c==="fs/write_text_file"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.path}),w.jsx(dv,{path:l.path,before:t.before??"",after:l.content}),!i&&w.jsx("button",{className:"button",onClick:()=>e.options.workbench.openView(`acp-review:${t.requestId}`,l.path+" · Agent review",PJe,{agent:e,requestId:t.requestId}),children:P("Review in editor")}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{className:"button primary",disabled:s||e.reviewingAll||!e.requests.includes(t),onClick:()=>{o(()=>e.applyFile(t))},children:P("Apply change")}),w.jsx("button",{className:"button",disabled:s||e.reviewingAll||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,void 0,qG))},children:P("Reject")})]})]}):c==="session/request_permission"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.toolCall?.title||P("Agent tool")}),l.toolCall?.rawInput&&w.jsxs("details",{children:[w.jsx("summary",{children:P("Tool input")}),w.jsx("pre",{children:JSON.stringify(l.toolCall.rawInput,null,2)})]}),l.toolCall?.content?.map((u,d)=>u.type==="diff"?w.jsxs("div",{className:"acp-request-diff",children:[w.jsx("p",{children:u.path}),w.jsx(dv,{path:u.path,before:u.oldText??"",after:u.newText??""})]},d):u.content?.text?w.jsx("pre",{children:u.content.text},d):null),w.jsxs("div",{className:"acp-actions",children:[(l.options??[]).map(u=>w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"selected",optionId:u.optionId}}))},children:u.name},u.optionId)),w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"cancelled"}}))},children:P("Cancel")})]})]}):c==="cursor/create_plan"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.name}),w.jsx("pre",{children:l.plan}),w.jsx("div",{className:"acp-actions",children:["accepted","rejected"].map(u=>w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:u}}))},children:P(u==="accepted"?"Approve plan":"Reject plan")},u))})]}):w.jsxs(w.Fragment,{children:[(l.questions??[]).map(u=>w.jsxs("fieldset",{children:[w.jsx("legend",{children:u.prompt}),(u.options??[]).map(d=>w.jsxs("label",{className:"acp-choice",children:[w.jsx("input",{type:u.allowMultiple?"checkbox":"radio",name:t.requestId+u.id,checked:(a[u.id]??[]).includes(d.id),onChange:p=>n({...a,[u.id]:u.allowMultiple?p.target.checked?[...a[u.id]??[],d.id]:(a[u.id]??[]).filter(g=>g!==d.id):[d.id]})}),d.label]},d.id))]},u.id)),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{className:"button primary",disabled:s||(l.questions??[]).some(u=>!a[u.id]?.length),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"answered",answers:Object.entries(a).map(([u,d])=>({questionId:u,selectedOptionIds:d}))}}))},children:P("Submit answers")}),w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"skipped"}}))},children:P("Skip")})]})]})]})}function PJe({agent:t,requestId:e}){L.useSyncExternalStore(t.subscribe,t.snapshot);const i=t.requests.find(s=>s.requestId===e);return w.jsx("div",{className:"acp-panel acp-review-editor",children:i?w.jsx(xA,{request:i,agent:t,full:!0}):w.jsx("p",{role:"status",children:P("This review is complete or has expired.")})})}function EJe({agent:t}){L.useSyncExternalStore(t.subscribe,t.snapshot);const{kernel:e,runtime:i}=t.options,[s,r]=L.useState(!1),[a,n]=L.useState(),[o,l]=L.useState(()=>typeof Notification>"u"?void 0:Notification.permission),c=L.useRef(null),u=L.useRef(null),[d,p]=L.useState(!1),[g,y]=L.useState(!1),[k,$]=L.useState(!1),[_,C]=L.useState(!0),b=L.useId(),Q=L.useRef(null),A=L.useRef(null),S=L.useRef(null),m=L.useRef(null),v=L.useRef(null),E=L.useRef(null),D=L.useRef(!0),N=L.useRef(0),Z=t.connection,J=!!i?.connected,se=t.local,re=dG(Z),M=t.busy||t.connecting||t.updatingSettings||t.discovering||t.archived;L.useEffect(()=>{const V=m.current;if(!k||!V||!S.current)return;const ie=S.current.getBoundingClientRect(),W=Math.min(320,innerWidth-16),Y=ie.top>innerHeight-ie.bottom;Object.assign(V.style,{width:`${W}px`,maxHeight:`${Math.max(80,(Y?ie.top:innerHeight-ie.bottom)-12)}px`,left:`${Math.max(8,Math.min(ie.left,innerWidth-W-8))}px`,top:Y?"auto":`${ie.bottom+4}px`,bottom:Y?`${innerHeight-ie.top+4}px`:"auto"}),V.showPopover(),V.querySelector("button")?.focus();const le=()=>$(!1);return window.addEventListener("resize",le),()=>{V.hidePopover(),window.removeEventListener("resize",le)}},[k]),L.useEffect(()=>{m.current?.matches(":popover-open")&&($(!1),S.current?.focus())},[t.context.length]),L.useEffect(()=>{if(M)return;const V=E.current;E.current=null,V?.isConnected&&document.activeElement===document.body&&V.focus()},[M]);const j=Z?.id;L.useEffect(()=>{j&&r(!1)},[j]),L.useEffect(()=>{D.current&&v.current&&t.messages.length&&(v.current.scrollTop=v.current.scrollHeight)},[t.snapshot()]),L.useEffect(()=>{const V=v.current;if(!V||typeof ResizeObserver>"u")return;const ie=new ResizeObserver(()=>{D.current&&t.messages.length&&(V.scrollTop=V.scrollHeight)}),W=()=>{ie.observe(V);for(const le of V.children)ie.observe(le)};W();const Y=new MutationObserver(W);return Y.observe(V,{childList:!0}),()=>{ie.disconnect(),Y.disconnect()}},[t]),L.useEffect(()=>{const V=c.current;if(t.markSeen(),!V||typeof IntersectionObserver>"u")return;const ie=new IntersectionObserver(W=>{W.some(Y=>Y.isIntersecting)&&t.markSeen()});return ie.observe(V),()=>ie.disconnect()},[]),fJe(t,c);const q=()=>{n(void 0),t.action(()=>t.detach())},ae=L.useRef(null),F=(V,ie,W)=>{const Y=!!ae.current?.contains(document.activeElement);t.action(async()=>{await t.moveQueued(V,ie),Y&&requestAnimationFrame(()=>{const le=ae.current?.querySelector(`[data-queue-id="${CSS.escape(V)}"]`);(le?.querySelector(`[data-move="${W}"]`)??le?.querySelector("[data-move]"))?.focus()})})},B=t.chosen.provider;L.useEffect(()=>{J&&!se&&!t.registry&&!io(B)&&B!==Ei&&B!==Wi&&t.loadRegistry().catch(()=>{})},[J,se,B]),L.useEffect(()=>{a&&u.current?.scrollIntoView({block:"nearest"})},[a]);const U=t.requests.length?"attention":t.busy||t.connecting?"working":/failed/i.test(t.status)?"error":Z?"ready":"off",te=[...J&&!se?[{id:"live",label:"Runtime sessions",icon:"agentChat",run:()=>{y(!g),g||t.action(()=>t.listLiveSessions())}}]:[],{id:"agents",label:"Open Agents",icon:"agent",run:()=>t.openAgents()},{id:"setup",label:"Agent setup",icon:"gear",run:()=>r(!s)},...Z&&!se?[{id:"thread",label:"New thread",icon:"plus",run:q}]:[],...t.canForkSession?[{id:"fork",label:"Fork conversation",icon:"git",run:()=>{t.action(()=>t.forkSession())}}]:[],...Z?[{id:"disconnect",label:"Disconnect",icon:"power",run:()=>{t.action(()=>t.disconnect())}}]:[],...o==="default"?[{id:"notifications",label:"Enable notifications",icon:"bell",run:()=>{Notification.requestPermission().then(l)}}]:[]],oe=a==="registry"?w.jsx(QKe,{agent:t,onDone:()=>n(void 0)}):a==="custom"?w.jsx(ZG,{agent:t,onDone:()=>n(void 0)}):void 0;return w.jsxs("div",{className:"acp-panel",ref:c,children:[w.jsx(pJe,{agent:t,onNew:q}),w.jsxs("div",{className:"acp-header",children:[w.jsxs("div",{className:"acp-thread-heading",children:[w.jsx(op,{provider:Z?.provider??B,size:14}),w.jsx("strong",{title:t.title,children:P(t.title)}),w.jsxs("div",{className:"acp-status",role:"status","data-state":U,title:P(t.status),children:[w.jsx("span",{className:t.busy?"acp-dot working":"acp-dot","data-state":U}),w.jsx("span",{className:"acp-status-text",children:P(t.status)})]}),!Z&&(t.messages.length>0||t.archived)&&w.jsx("button",{className:"button acp-connect","data-tooltip":P("Start {0}",{0:t.displayName}),disabled:!J||t.connecting,onClick:()=>{t.action(()=>t.connectSelected())},children:P(t.connecting?"Connecting…":"Connect")}),t.connecting&&w.jsx(Ue,{icon:"x",label:"Cancel",onClick:()=>{t.action(()=>t.disconnect())}}),Z?.sessionId&&w.jsx(Ue,{icon:"plus",label:"New conversation",disabled:t.busy||t.connecting||t.updatingSettings||t.discovering||t.queue.length>0||t.activeSubagentCount>0,onClick:()=>{t.action(()=>t.newSession())}}),w.jsx(Ue,{icon:"clock",label:"History","aria-expanded":d,onClick:()=>p(!d)}),w.jsx(WG,{label:"More agent actions",items:te})]}),!J&&w.jsxs("p",{className:"muted",children:[P("Connect to a runtime workspace to use agents.")," ",w.jsx("button",{className:"button",onClick:()=>{t.action(()=>e.commands.execute("workspace.runtime"))},children:P("Runtime connection")})]}),s&&w.jsx(LKe,{agent:t},Z?.provider??B),Z&&!Z.sessionId&&w.jsxs("div",{className:"acp-actions",children:[Z.authMethods.map(V=>w.jsxs("button",{className:"button",disabled:t.connecting,onClick:()=>{t.action(()=>t.authenticate(V.id))},children:[P("Sign in"),": ",V.name]},V.id)),w.jsx("button",{className:"button",disabled:t.connecting,onClick:()=>{t.action(()=>t.newSession())},children:P("Retry conversation")})]}),d&&w.jsx(oJe,{agent:t}),g&&w.jsxs("section",{className:"acp-live-sessions","aria-label":P("Runtime sessions"),children:[t.liveSessions.length===0&&w.jsx("p",{className:"muted",children:P("No running conversations")}),t.liveSessions.map(V=>w.jsxs("div",{className:"acp-live-session",children:[w.jsx(op,{provider:V.connection.provider}),w.jsxs("span",{children:[w.jsx("strong",{children:V.title||P("New conversation")}),w.jsxs("small",{className:"muted",children:[il(V.connection.provider,V.connection)," · ",V.busy?P("Working…"):P("Ready"),V.queued?` · ${V.queued} ${P("queued")}`:""]})]}),w.jsx("button",{type:"button",className:"button",disabled:t.connection?.id===V.connection.id,onClick:()=>{t.action(async()=>{await t.attachLive(V.connection.id),y(!1)})},children:P(t.connection?.id===V.connection.id?"Current":"Open")})]},V.connection.id))]}),t.error&&w.jsx("p",{role:"alert",className:"error-text",children:HI.includes(t.error)?P(t.error):t.error}),HI.includes(t.error)&&!s&&w.jsx("div",{className:"acp-actions",children:w.jsx("button",{className:"button",onClick:()=>r(!0),children:P("Agent setup")})})]}),w.jsxs("div",{className:"acp-content",ref:v,onScroll:()=>{const V=v.current;V&&(V.scrollHeight-V.scrollTop-V.clientHeight<80?D.current=!0:V.scrollTop<N.current&&(D.current=!1),N.current=V.scrollTop,C(D.current))},children:[!t.messages.length&&oe,!t.messages.length&&!oe&&!Z&&!t.archived&&w.jsx(xKe,{agent:t,enabled:J,onChoose:n}),!t.messages.length&&!oe&&(Z||t.archived)&&w.jsxs("div",{className:"acp-welcome",children:[w.jsx(Te,{name:"agentChat",size:28}),w.jsx("h2",{children:P("Work with your agent")}),w.jsx("p",{children:P("Ask a question, plan a change, or attach code from your editor. Follow tool calls and review approvals here.")})]}),t.replayTruncated&&w.jsx("p",{className:"acp-turn-note",role:"status",children:P("Earlier activity was trimmed by the runtime.")}),t.subagents.size>0&&w.jsx(KG,{agent:t,compact:!0}),w.jsx(aJe,{agent:t}),Array.from(t.terminals.entries()).map(([V,ie])=>w.jsxs("details",{className:"acp-card",children:[w.jsxs("summary",{children:[P("Terminal"),": ",ie.command," ·"," ",ie.exitStatus?P("Ended"):P("Running")]}),w.jsx("pre",{children:ie.output}),ie.truncated&&w.jsx("p",{className:"muted",children:P("Earlier output was truncated")})]},V)),w.jsx(cJe,{agent:t}),w.jsx(uJe,{agent:t}),t.requests.map(V=>w.jsx(xA,{request:V,agent:t},V.requestId)),t.logs&&w.jsxs("details",{className:"acp-card",children:[w.jsx("summary",{children:P("Agent logs")}),w.jsx("pre",{children:t.logs})]}),t.messages.length>0&&oe&&w.jsx("div",{ref:u,children:oe})]}),!_&&w.jsx("button",{className:"button acp-jump",onClick:()=>{D.current=!0,C(!0),v.current&&(v.current.scrollTop=v.current.scrollHeight)},children:P("Jump to latest")}),t.requests.length>0&&w.jsxs("button",{className:"button acp-attention",onClick:()=>{v.current?.querySelector(".acp-approval")?.scrollIntoView({block:"center"}),v.current?.querySelector(".acp-approval button")?.focus()},children:[P("Agent needs your input")," · ",t.requests.length]}),t.queue.length>0&&w.jsxs("section",{className:"acp-queue",ref:ae,"aria-label":P("Queued messages"),children:[w.jsxs("div",{className:"acp-queue-heading",children:[w.jsxs("strong",{children:[P("Queued messages")," · ",t.queue.length]}),t.queuePaused&&w.jsx("button",{className:"button",type:"button",onClick:()=>{t.action(()=>t.resumeQueue())},children:P("Run queue")})]}),t.queue.map((V,ie)=>w.jsxs("div",{className:"acp-queue-item","data-queue-id":V.id,onKeyDown:W=>{const Y=W.altKey?W.key==="ArrowUp"?ie-1:W.key==="ArrowDown"?ie+1:-1:-1;!t.canMoveQueued||Y<0||Y>=t.queue.length||(W.preventDefault(),F(V.id,Y,Y<ie?"up":"down"))},children:[w.jsxs("span",{title:V.text,children:[ie+1,". ",V.text]}),t.busy&&!t.cancelling&&w.jsx(Ue,{icon:"play",label:P("Send queued message now"),onClick:()=>{t.action(()=>t.sendQueuedNow(V.id))}}),t.canMoveQueued&&ie>0&&w.jsx(Ue,{icon:"arrowUp",label:"Move queued message up","data-move":"up",onClick:()=>F(V.id,ie-1,"up")}),t.canMoveQueued&&ie<t.queue.length-1&&w.jsx(Ue,{icon:"arrowDown",label:"Move queued message down","data-move":"down",onClick:()=>F(V.id,ie+1,"down")}),w.jsx(Ue,{icon:"pencil",label:P("Edit queued message"),onClick:()=>{t.action(()=>t.editQueued(V.id))}}),w.jsx(Ue,{icon:"x",label:P("Remove queued message"),onClick:()=>{t.action(()=>t.removeQueued(V.id))}})]},V.id))]}),w.jsxs("form",{className:"acp-composer",onSubmit:V=>{V.preventDefault(),t.action(()=>t.send())},onDragOver:V=>{V.dataTransfer.types.includes("Files")&&V.preventDefault()},onDrop:V=>{const ie=jG(V.dataTransfer);ie.length&&(V.preventDefault(),t.action(async()=>{for(const W of ie)await t.attachImage(W)}))},children:[w.jsxs("div",{id:b,ref:m,popover:"auto",className:"acp-context-menu",role:"region","aria-label":P("Add context"),onToggle:V=>{V.newState==="closed"&&$(!1)},children:[w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attachDiagnostics())},children:[w.jsx(Te,{name:"warning",size:14}),P("Attach diagnostics")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attachChanges())},children:[w.jsx(Te,{name:"git",size:14}),P("Attach changes")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attach())},children:[w.jsx(Te,{name:"files",size:14}),P("Attach file")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attach(!0))},children:[w.jsx(Te,{name:"focus",size:14}),P("Attach selection")]}),k&&w.jsx(lJe,{agent:t})]}),t.context.length>0&&w.jsxs("div",{className:"acp-attachments",children:[t.context.map((V,ie)=>w.jsxs("div",{className:"acp-context-chip",children:[w.jsx(HG,{item:V}),w.jsx(Ue,{icon:"x",label:P("Remove attachment {0}",{0:V.kind==="changes"?P("Uncommitted changes"):["thread","branch","commit","folder"].includes(V.kind)?V.label??V.path:V.path}),onClick:()=>{t.context.splice(ie,1),t.changed()}})]},ie)),w.jsxs("p",{className:"acp-context-budget muted",children:[t.context.length,"/8 ",P("attachments")," ·"," ",(t.draft.length+t.context.reduce((V,ie)=>V+ie.text.length,0)).toLocaleString()," ",P("characters")]})]}),t.archived&&w.jsx("p",{className:"muted",children:P("Saved transcript. Choose Resume in History to continue this conversation.")}),w.jsx(VKe,{inputRef:Q,actionsRef:A,configuration:e.configuration,commands:t.commands,value:t.draft,onChange:V=>{t.draft=V,t.changed()},onSend:()=>{t.action(()=>t.send())},onEscape:()=>!t.busy||t.cancelling?!1:(t.action(()=>t.cancel()),!0),onMention:V=>{t.action(()=>t.attachMention(V))},onImages:V=>{t.action(async()=>{for(const ie of V)await t.attachImage(ie)})},findFiles:(V,ie)=>rKe(t.options.filesystem,V,ie),findSymbols:(V,ie)=>nKe(t.options.kernel.services.optional("language"),V,ie),findThreads:V=>t.mentionThreads(V),findCommits:V=>t.mentionCommits(V),branchDiff:t.branchDiffAvailable,onMentionOpen:()=>t.probeBranchDiff()}),w.jsxs("div",{className:"acp-composer-toolbar",children:[w.jsx("button",{ref:S,type:"button",className:"icon-button","aria-label":P("Add context"),"data-tooltip":P("Add context"),"aria-controls":b,"aria-expanded":k,onClick:()=>$(!k),children:w.jsx(Te,{name:"plus"})}),t.commands.length>0&&w.jsx("button",{type:"button",className:"icon-button acp-slash-button","aria-label":P("Slash commands"),"data-tooltip":P("Slash commands"),onMouseDown:V=>V.preventDefault(),onClick:()=>A.current?.insertSlash(),children:w.jsx("span",{"aria-hidden":"true",children:"/"})}),w.jsx(RKe,{value:t.draft,onChange:V=>{t.draft=V,t.changed()},onError:V=>{t.error=V,t.changed()}}),t.autoApply&&!t.archived&&w.jsxs("span",{className:"acp-auto-apply-on",title:P("Agent edits save without review"),children:[w.jsx(Te,{name:"check",size:12}),P("Auto-apply on")]}),w.jsx(XKe,{configuration:e.configuration}),t.busy&&w.jsx(Ue,{icon:"stop",label:t.cancelling?"Stopping…":"Stop",disabled:t.cancelling,onClick:()=>{t.action(()=>t.cancel())}}),t.busy&&t.draft.trim()&&w.jsx("button",{type:"button",className:"button acp-interrupt",disabled:t.cancelling,onClick:()=>{t.action(()=>t.interruptAndSend())},children:P("Interrupt & send")}),w.jsx(Ue,{icon:"arrowUp",label:t.busy?"Queue message":"Send",className:"icon-button acp-send",type:"submit",disabled:!!Z&&!Z.sessionId||!t.draft.trim()||!J||t.connecting||t.updatingSettings||t.discovering||t.archived})]})]}),w.jsxs("div",{className:"acp-footer",children:[t.usage&&w.jsx(_Ke,{usage:t.usage}),Z||se&&(t.messages.length>0||t.archived)?w.jsxs("div",{className:"acp-provider",title:t.displayName,children:[w.jsx(Te,{name:"agent",size:14}),w.jsx("span",{children:t.displayName})]}):(t.messages.length>0||t.archived)&&w.jsx(fn,{label:P("ACP provider"),icon:"agent",value:B,options:[...hv.map(V=>({value:V.id,label:V.name})),...io(B)?[]:[{value:B,label:t.displayName}],{value:"#registry",label:P("More agents…")},{value:"#custom",label:P("Custom agent…")}],disabled:t.connecting,onChange:V=>{V==="#registry"?n("registry"):V==="#custom"?n("custom"):t.action(()=>t.select({provider:V}))}}),!t.archived&&w.jsxs("label",{className:"acp-auto-apply",title:P("Save agent file changes without review. Permission prompts still ask."),children:[w.jsx("input",{type:"checkbox",role:"switch",className:"setting-switch",checked:t.autoApply,onChange:V=>t.setAutoApply(V.target.checked)}),w.jsx("span",{children:P("Auto-apply edits")})]}),re.length>0&&w.jsxs("details",{className:"acp-session-options",children:[w.jsxs("summary",{children:[P("Session settings"),w.jsx(Te,{name:"chevD",size:12})]}),w.jsx("div",{className:"acp-settings","aria-busy":t.updatingSettings,children:re.map(V=>w.jsxs("div",{className:"acp-setting",children:[w.jsx("span",{className:"acp-setting-label",title:V.description,children:P(V.name)}),w.jsx(fn,{label:P(V.name),value:V.value,options:V.options,disabled:M,onChange:ie=>{E.current=document.activeElement instanceof HTMLElement?document.activeElement:null,t.action(()=>t.setSessionControl(V,ie))}})]},`${V.method}:${V.id}`))})]})]})]})}function RJe({agent:t}){if(L.useSyncExternalStore(t.subscribe,t.snapshot),!t.connection)return null;const[e,i]=t.requests.length?["attention","Agent needs input"]:t.busy?["working","Agent working"]:["ready","Agent ready"];return w.jsxs("button",{type:"button",className:"acp-status-item","data-state":e,title:P("Open Agent"),onClick:()=>{t.options.kernel.commands.execute("agentACP.open")},children:[w.jsx(Te,{name:"agentChat",size:13}),w.jsx("span",{children:P(i)})]})}function QJe(t){return{manifest:{manifestVersion:1,id:"oxbit.agent-acp",name:"Agent ACP",version:"1.0.0",sdk:"^1.0.0",description:"Codex, Claude Agent, Gemini CLI, GitHub Copilot, Cursor, Amp, and ACP Registry agents with conversations, editor context, tool activity, and approvals.",enabledByDefault:!1,environments:["browser","embedded"],activation:["*"],capabilities:["extensions","filesystem.read","filesystem.write","terminal"],configuration:_Ye},activate(e){const i=t.runtime?void 0:new TJe(t,()=>t.kernel.services.optional(fv)),s=new wKe({...t,runtime:t.runtime??i});e.own(s),i&&e.own(i),e.own(IYe(s,()=>t.workbench.panelVisible?.(lu)===!0)),e.own(e.services.register("agentACP",s)),e.own(e.contributions.register({id:lu,kind:"activityView",title:"Agent ACP",order:45,data:{icon:"agentChat",dock:"right",phoneBar:!0,phoneLabel:"Agent"},component:()=>w.jsx(EJe,{agent:s})})),e.own(e.contributions.register({id:"agent-acp-agents",kind:"activityView",title:"Agents",order:46,data:{icon:"agent",dock:"right"},component:()=>w.jsx(KG,{agent:s,renderRequest:r=>w.jsx(xA,{request:r,agent:s},r.requestId)})})),e.own(e.contributions.register({id:"agent-acp.status",kind:"statusItem",title:"Agent status",component:()=>w.jsx(RJe,{agent:s})})),e.own(e.commands.register({id:"agentACP.openAgents",title:"Open Agents",category:"Agent ACP",run:()=>s.openAgents()})),e.own(e.commands.register({id:"agentACP.open",title:"Open Agent ACP",category:"Agent ACP",run:()=>{t.workbench.openPanel(lu),s.markSeen()}}));for(const[r,a,n]of[["agentACP.attachFile","Attach Active File",()=>s.attach()],["agentACP.attachSelection","Attach Selection",()=>s.attach(!0)],["agentACP.stop","Stop Agent",()=>s.cancel()]])e.own(e.commands.register({id:r,title:a,category:"Agent ACP",run:async()=>{await t.kernel.commands.execute("agentACP.open"),await s.action(n)}}))}}}const Fh=t=>`${(t/1e3).toFixed(1)} kB`,Xy=["#818cf8","#34d399","#fbbf24","#f472b6","#60a5fa","#fb923c"],DJe=t=>{const e=t.eol==="CRLF"?t.text.replace(/\r\n/g,`
408
+ ${s}`}}})}async prompt(e,i,s){const r=sn(s,"text");if(!r.trim())throw new Error("Enter a message");const a=[{type:"text",text:r},...this.contextBlocks(s.context)],n=GI(s);e.busy=!0,e.queuePaused&&(e.queuePaused=!1,this.publishQueue(e)),this.publish(e,"acp.turnStarted",{messageId:n,text:r,context:CJe(s.context)});let o,l;try{const c=await e.agent.prompt(i,a);return o=c.stopReason,o!=="end_turn"&&o!=="cancelled"&&(e.queuePaused=!0),c}catch(c){throw l=c instanceof Error?c.message:String(c),e.queuePaused=!0,c}finally{this.expire(e,i),e.busy=!1,e.stopped||(this.refreshOptions(e,i),this.publish(e,"acp.turnEnded",{stopReason:o,error:l}),this.publishQueue(e),queueMicrotask(()=>this.runQueue(e)))}}refreshOptions(e,i){const s=e.connection.configOptions;if(!s||e.connection.sessionId!==i)return;const r=new Map(e.settings.options().map(o=>[o.id,o])),a=e.connection.modes?.currentModeId,n=s.map(o=>r.get(o.id)??(o.id==="mode"&&a?{...o,currentValue:a}:o));JSON.stringify(n)!==JSON.stringify(s)&&(e.connection.configOptions=n,this.publish(e,"acp.update",{sessionId:i,update:{sessionUpdate:"config_option_update",configOptions:n}}))}registry(e,i,s=!1){const r=new OJe(Wi,i,a=>this.publish(e,"acp.subagent",{rootSessionId:i,...a}));return r.replaying=s,r}settle(e,i,s){e.subagents?.waiting(s.sessionId,i,!1,G_(s))}clientRequest(e,i,s){const r=e.subagents;if(!r?.acceptsRequest(s.sessionId))return Promise.reject(new Error("Unknown ACP session"));if(e.approvals.size>=32)return Promise.reject(new Error("Too many pending agent requests"));const a={...s};try{i.startsWith("fs/")&&(a.path=iGe(this.root,s.path))}catch(n){return Promise.reject(n)}for(const n of Object.keys(a))a[n]===void 0&&delete a[n];return new Promise((n,o)=>{const l=crypto.randomUUID(),c=a.sessionId;e.approvals.set(l,{method:i,params:a,resolve:n,reject:o}),i!=="fs/read_text_file"&&!i.startsWith("oxbit/")&&r.waiting(c,l,!0,G_(a)),this.publish(e,"acp.request",{requestId:l,sessionId:c,rootSessionId:r.root,subagentId:r.idForSession(c)??r.idForTool(c,G_(a)),method:i,params:a})})}respond(e,i,s,r){const a=e.approvals.get(i);if(!a)throw new Error("Agent request has expired");return e.approvals.delete(i),this.settle(e,i,a.params),r!=null?a.reject(new Error(String(r).slice(0,4096))):a.resolve(s),{}}expire(e,i){const s=[];for(const[r,a]of e.approvals)a.params.sessionId===i&&(e.approvals.delete(r),this.settle(e,r,a.params),a.reject(new Error("Session turn ended")),s.push(r));s.length&&this.publish(e,"acp.requestsExpired",{requestIds:s})}cancel(e,i=!1){const s=e.connection.sessionId;e.queuePaused=!i,this.publishQueue(e),s&&e.agent.cancel(s);for(const[r,a]of e.approvals)a.params.sessionId===s&&(e.approvals.delete(r),this.settle(e,r,a.params),a.reject(new Error("Cancelled")));return this.publish(e,"acp.cancelled",{sessionId:s}),{}}dispose(){for(const e of[...this.connections.values()])this.stop(e,"Workspace closed");this.listeners.clear()}stop(e,i){if(e.stopped)return{};e.stopped=!0,e.agent.cancel();for(const s of e.approvals.values())s.reject(new Error(i));return e.approvals.clear(),e.subagents?.disconnect(),this.connections.delete(e.connection.id),this.publish(e,"acp.exit",{reason:i}),{}}enqueue(e,i,s){if(!e.connection.sessionId)throw new Error("Start a conversation first");const r=sn(i,"text").trim();if(!r)throw new Error("Enter a message");const a=GI(i);if(this.contextBlocks(i.context),e.queue.some(l=>l.id===a))return this.publishQueue(e);if(e.queue.length>=16)throw new Error("Queued messages exceed the limit; remove a message first");const n={id:a,text:r,...i.context?{context:structuredClone(i.context)}:{}};s?(e.queue.unshift(n),e.queuePaused=!1,e.busy&&this.cancel(e,!0)):e.queue.push(n);const o=this.publishQueue(e);return queueMicrotask(()=>this.runQueue(e)),o}dequeue(e,i){const s=e.queue.findIndex(a=>a.id===i);if(s<0)throw new Error("The queued message has already started or was removed");const[r]=e.queue.splice(s,1);return this.publishQueue(e),{prompt:r}}moveQueued(e,i,s){if(!Number.isInteger(s))throw new Error("Invalid index");const r=e.queue.findIndex(n=>n.id===i);if(r<0)throw new Error("The queued message has already started or was removed");const[a]=e.queue.splice(r,1);return e.queue.splice(Math.max(0,Math.min(s,e.queue.length)),0,a),this.publishQueue(e)}runQueue(e){if(e.busy||e.queueRunning||e.stopped||e.queuePaused||!e.queue.length)return;e.queueRunning=!0;const i=e.queue.shift();this.publishQueue(e),this.call(e,"session/prompt",{text:i.text,context:i.context,messageId:i.id}).catch(()=>{e.stopped||(e.queuePaused=!0,e.queue.unshift(i),this.publishQueue(e))}).finally(()=>{e.queueRunning=!1,this.runQueue(e)})}}const HI=[rj,nj];function xA({request:t,agent:e,full:i=!1}){const[s,r]=L.useState(!1),[a,n]=L.useState({}),o=async u=>{r(!0),await e.action(u),r(!1)},{params:l,method:c}=t;return w.jsxs("section",{className:"acp-approval","aria-label":P("Agent approval"),children:[w.jsxs("strong",{children:[w.jsx(Te,{name:"warning",size:14})," ",P(c==="fs/write_text_file"?"Review file change":c==="cursor/ask_question"?"Agent needs your input":c==="cursor/create_plan"?"Review plan":"Permission required")]}),t.subagentId&&w.jsxs("p",{className:"acp-request-agent",children:[P("From subagent"),":"," ",e.subagents.get(t.subagentId)?.name??t.subagentId]}),c==="fs/write_text_file"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.path}),w.jsx(dv,{path:l.path,before:t.before??"",after:l.content}),!i&&w.jsx("button",{className:"button",onClick:()=>e.options.workbench.openView(`acp-review:${t.requestId}`,l.path+" · Agent review",PJe,{agent:e,requestId:t.requestId}),children:P("Review in editor")}),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{className:"button primary",disabled:s||e.reviewingAll||!e.requests.includes(t),onClick:()=>{o(()=>e.applyFile(t))},children:P("Apply change")}),w.jsx("button",{className:"button",disabled:s||e.reviewingAll||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,void 0,qG))},children:P("Reject")})]})]}):c==="session/request_permission"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.toolCall?.title||P("Agent tool")}),l.toolCall?.rawInput&&w.jsxs("details",{children:[w.jsx("summary",{children:P("Tool input")}),w.jsx("pre",{children:JSON.stringify(l.toolCall.rawInput,null,2)})]}),l.toolCall?.content?.map((u,d)=>u.type==="diff"?w.jsxs("div",{className:"acp-request-diff",children:[w.jsx("p",{children:u.path}),w.jsx(dv,{path:u.path,before:u.oldText??"",after:u.newText??""})]},d):u.content?.text?w.jsx("pre",{children:u.content.text},d):null),w.jsxs("div",{className:"acp-actions",children:[(l.options??[]).map(u=>w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"selected",optionId:u.optionId}}))},children:u.name},u.optionId)),w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"cancelled"}}))},children:P("Cancel")})]})]}):c==="cursor/create_plan"?w.jsxs(w.Fragment,{children:[w.jsx("p",{children:l.name}),w.jsx("pre",{children:l.plan}),w.jsx("div",{className:"acp-actions",children:["accepted","rejected"].map(u=>w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:u}}))},children:P(u==="accepted"?"Approve plan":"Reject plan")},u))})]}):w.jsxs(w.Fragment,{children:[(l.questions??[]).map(u=>w.jsxs("fieldset",{children:[w.jsx("legend",{children:u.prompt}),(u.options??[]).map(d=>w.jsxs("label",{className:"acp-choice",children:[w.jsx("input",{type:u.allowMultiple?"checkbox":"radio",name:t.requestId+u.id,checked:(a[u.id]??[]).includes(d.id),onChange:p=>n({...a,[u.id]:u.allowMultiple?p.target.checked?[...a[u.id]??[],d.id]:(a[u.id]??[]).filter(g=>g!==d.id):[d.id]})}),d.label]},d.id))]},u.id)),w.jsxs("div",{className:"acp-actions",children:[w.jsx("button",{className:"button primary",disabled:s||(l.questions??[]).some(u=>!a[u.id]?.length),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"answered",answers:Object.entries(a).map(([u,d])=>({questionId:u,selectedOptionIds:d}))}}))},children:P("Submit answers")}),w.jsx("button",{className:"button",disabled:s||!e.requests.includes(t),onClick:()=>{o(()=>e.respond(t,{outcome:{outcome:"skipped"}}))},children:P("Skip")})]})]})]})}function PJe({agent:t,requestId:e}){L.useSyncExternalStore(t.subscribe,t.snapshot);const i=t.requests.find(s=>s.requestId===e);return w.jsx("div",{className:"acp-panel acp-review-editor",children:i?w.jsx(xA,{request:i,agent:t,full:!0}):w.jsx("p",{role:"status",children:P("This review is complete or has expired.")})})}function EJe({agent:t}){L.useSyncExternalStore(t.subscribe,t.snapshot);const{kernel:e,runtime:i}=t.options,[s,r]=L.useState(!1),[a,n]=L.useState(),[o,l]=L.useState(()=>typeof Notification>"u"?void 0:Notification.permission),c=L.useRef(null),u=L.useRef(null),[d,p]=L.useState(!1),[g,y]=L.useState(!1),[k,$]=L.useState(!1),[_,C]=L.useState(!0),b=L.useId(),Q=L.useRef(null),A=L.useRef(null),S=L.useRef(null),m=L.useRef(null),v=L.useRef(null),E=L.useRef(null),D=L.useRef(!0),N=L.useRef(0),Z=t.connection,J=!!i?.connected,se=t.local,re=dG(Z),M=t.busy||t.connecting||t.updatingSettings||t.discovering||t.archived;L.useEffect(()=>{const V=m.current;if(!k||!V||!S.current)return;const ie=S.current.getBoundingClientRect(),W=Math.min(320,innerWidth-16),Y=ie.top>innerHeight-ie.bottom;Object.assign(V.style,{width:`${W}px`,maxHeight:`${Math.max(80,(Y?ie.top:innerHeight-ie.bottom)-12)}px`,left:`${Math.max(8,Math.min(ie.left,innerWidth-W-8))}px`,top:Y?"auto":`${ie.bottom+4}px`,bottom:Y?`${innerHeight-ie.top+4}px`:"auto"}),V.showPopover(),V.querySelector("button")?.focus();const le=()=>$(!1);return window.addEventListener("resize",le),()=>{V.hidePopover(),window.removeEventListener("resize",le)}},[k]),L.useEffect(()=>{m.current?.matches(":popover-open")&&($(!1),S.current?.focus())},[t.context.length]),L.useEffect(()=>{if(M)return;const V=E.current;E.current=null,V?.isConnected&&document.activeElement===document.body&&V.focus()},[M]);const j=Z?.id;L.useEffect(()=>{j&&r(!1)},[j]),L.useEffect(()=>{D.current&&v.current&&t.messages.length&&(v.current.scrollTop=v.current.scrollHeight)},[t.snapshot()]),L.useEffect(()=>{const V=v.current;if(!V||typeof ResizeObserver>"u")return;const ie=new ResizeObserver(()=>{D.current&&t.messages.length&&(V.scrollTop=V.scrollHeight)}),W=()=>{ie.observe(V);for(const le of V.children)ie.observe(le)};W();const Y=new MutationObserver(W);return Y.observe(V,{childList:!0}),()=>{ie.disconnect(),Y.disconnect()}},[t]),L.useEffect(()=>{const V=c.current;if(t.markSeen(),!V||typeof IntersectionObserver>"u")return;const ie=new IntersectionObserver(W=>{W.some(Y=>Y.isIntersecting)&&t.markSeen()});return ie.observe(V),()=>ie.disconnect()},[]),fJe(t,c);const q=()=>{n(void 0),t.action(()=>t.detach())},ae=L.useRef(null),F=(V,ie,W)=>{const Y=!!ae.current?.contains(document.activeElement);t.action(async()=>{await t.moveQueued(V,ie),Y&&requestAnimationFrame(()=>{const le=ae.current?.querySelector(`[data-queue-id="${CSS.escape(V)}"]`);(le?.querySelector(`[data-move="${W}"]`)??le?.querySelector("[data-move]"))?.focus()})})},B=t.chosen.provider;L.useEffect(()=>{J&&!se&&!t.registry&&!io(B)&&B!==Ei&&B!==Wi&&t.loadRegistry().catch(()=>{})},[J,se,B]),L.useEffect(()=>{a&&u.current?.scrollIntoView({block:"nearest"})},[a]);const U=t.requests.length?"attention":t.busy||t.connecting?"working":/failed/i.test(t.status)?"error":Z?"ready":"off",te=[...J&&!se?[{id:"live",label:"Runtime sessions",icon:"agentChat",run:()=>{y(!g),g||t.action(()=>t.listLiveSessions())}}]:[],{id:"agents",label:"Open Agents",icon:"agent",run:()=>t.openAgents()},{id:"setup",label:"Agent setup",icon:"gear",run:()=>r(!s)},...Z&&!se?[{id:"thread",label:"New thread",icon:"plus",run:q}]:[],...t.canForkSession?[{id:"fork",label:"Fork conversation",icon:"git",run:()=>{t.action(()=>t.forkSession())}}]:[],...Z?[{id:"disconnect",label:"Disconnect",icon:"power",run:()=>{t.action(()=>t.disconnect())}}]:[],...o==="default"?[{id:"notifications",label:"Enable notifications",icon:"bell",run:()=>{Notification.requestPermission().then(l)}}]:[]],oe=a==="registry"?w.jsx(QKe,{agent:t,onDone:()=>n(void 0)}):a==="custom"?w.jsx(ZG,{agent:t,onDone:()=>n(void 0)}):void 0;return w.jsxs("div",{className:"acp-panel",ref:c,children:[w.jsx(pJe,{agent:t,onNew:q}),w.jsxs("div",{className:"acp-header",children:[w.jsxs("div",{className:"acp-thread-heading",children:[w.jsx(op,{provider:Z?.provider??B,size:14}),w.jsx("strong",{title:t.title,children:P(t.title)}),w.jsxs("div",{className:"acp-status",role:"status","data-state":U,title:P(t.status),children:[w.jsx("span",{className:t.busy?"acp-dot working":"acp-dot","data-state":U}),w.jsx("span",{className:"acp-status-text",children:P(t.status)})]}),!Z&&(t.messages.length>0||t.archived)&&w.jsx("button",{className:"button acp-connect","data-tooltip":P("Start {0}",{0:t.displayName}),disabled:!J||t.connecting,onClick:()=>{t.action(()=>t.connectSelected())},children:P(t.connecting?"Connecting…":"Connect")}),t.connecting&&w.jsx(Ue,{icon:"x",label:"Cancel",onClick:()=>{t.action(()=>t.disconnect())}}),Z?.sessionId&&w.jsx(Ue,{icon:"plus",label:"New conversation",disabled:t.busy||t.connecting||t.updatingSettings||t.discovering||t.queue.length>0||t.activeSubagentCount>0,onClick:()=>{t.action(()=>t.newSession())}}),w.jsx(Ue,{icon:"clock",label:"History","aria-expanded":d,onClick:()=>p(!d)}),w.jsx(WG,{label:"More agent actions",items:te})]}),!J&&w.jsxs("p",{className:"muted",children:[P("Connect to a runtime workspace to use agents.")," ",w.jsx("button",{className:"button",onClick:()=>{t.action(()=>e.commands.execute("workspace.runtime"))},children:P("Runtime connection")})]}),s&&w.jsx(LKe,{agent:t},Z?.provider??B),Z&&!Z.sessionId&&w.jsxs("div",{className:"acp-actions",children:[Z.authMethods.map(V=>w.jsxs("button",{className:"button",disabled:t.connecting,onClick:()=>{t.action(()=>t.authenticate(V.id))},children:[P("Sign in"),": ",V.name]},V.id)),w.jsx("button",{className:"button",disabled:t.connecting,onClick:()=>{t.action(()=>t.newSession())},children:P("Retry conversation")})]}),d&&w.jsx(oJe,{agent:t}),g&&w.jsxs("section",{className:"acp-live-sessions","aria-label":P("Runtime sessions"),children:[t.liveSessions.length===0&&w.jsx("p",{className:"muted",children:P("No running conversations")}),t.liveSessions.map(V=>w.jsxs("div",{className:"acp-live-session",children:[w.jsx(op,{provider:V.connection.provider}),w.jsxs("span",{children:[w.jsx("strong",{children:V.title||P("New conversation")}),w.jsxs("small",{className:"muted",children:[il(V.connection.provider,V.connection)," · ",V.busy?P("Working…"):P("Ready"),V.queued?` · ${V.queued} ${P("queued")}`:""]})]}),w.jsx("button",{type:"button",className:"button",disabled:t.connection?.id===V.connection.id,onClick:()=>{t.action(async()=>{await t.attachLive(V.connection.id),y(!1)})},children:P(t.connection?.id===V.connection.id?"Current":"Open")})]},V.connection.id))]}),t.error&&w.jsxs("div",{className:"acp-error",children:[w.jsx("p",{role:"alert",className:"error-text",children:HI.includes(t.error)?P(t.error):t.error}),w.jsx(Ue,{icon:"x",label:"Close",onClick:()=>t.dismissError()})]}),HI.includes(t.error)&&!s&&w.jsx("div",{className:"acp-actions",children:w.jsx("button",{className:"button",onClick:()=>r(!0),children:P("Agent setup")})})]}),w.jsxs("div",{className:"acp-content",ref:v,onScroll:()=>{const V=v.current;V&&(V.scrollHeight-V.scrollTop-V.clientHeight<80?D.current=!0:V.scrollTop<N.current&&(D.current=!1),N.current=V.scrollTop,C(D.current))},children:[!t.messages.length&&oe,!t.messages.length&&!oe&&!Z&&!t.archived&&w.jsx(xKe,{agent:t,enabled:J,onChoose:n}),!t.messages.length&&!oe&&(Z||t.archived)&&w.jsxs("div",{className:"acp-welcome",children:[w.jsx(Te,{name:"agentChat",size:28}),w.jsx("h2",{children:P("Work with your agent")}),w.jsx("p",{children:P("Ask a question, plan a change, or attach code from your editor. Follow tool calls and review approvals here.")})]}),t.replayTruncated&&w.jsx("p",{className:"acp-turn-note",role:"status",children:P("Earlier activity was trimmed by the runtime.")}),t.subagents.size>0&&w.jsx(KG,{agent:t,compact:!0}),w.jsx(aJe,{agent:t}),Array.from(t.terminals.entries()).map(([V,ie])=>w.jsxs("details",{className:"acp-card",children:[w.jsxs("summary",{children:[P("Terminal"),": ",ie.command," ·"," ",ie.exitStatus?P("Ended"):P("Running")]}),w.jsx("pre",{children:ie.output}),ie.truncated&&w.jsx("p",{className:"muted",children:P("Earlier output was truncated")})]},V)),w.jsx(cJe,{agent:t}),w.jsx(uJe,{agent:t}),t.requests.map(V=>w.jsx(xA,{request:V,agent:t},V.requestId)),t.logs&&w.jsxs("details",{className:"acp-card",children:[w.jsx("summary",{children:P("Agent logs")}),w.jsx("pre",{children:t.logs})]}),t.messages.length>0&&oe&&w.jsx("div",{ref:u,children:oe})]}),!_&&w.jsx("button",{className:"button acp-jump",onClick:()=>{D.current=!0,C(!0),v.current&&(v.current.scrollTop=v.current.scrollHeight)},children:P("Jump to latest")}),t.requests.length>0&&w.jsxs("button",{className:"button acp-attention",onClick:()=>{v.current?.querySelector(".acp-approval")?.scrollIntoView({block:"center"}),v.current?.querySelector(".acp-approval button")?.focus()},children:[P("Agent needs your input")," · ",t.requests.length]}),t.queue.length>0&&w.jsxs("section",{className:"acp-queue",ref:ae,"aria-label":P("Queued messages"),children:[w.jsxs("div",{className:"acp-queue-heading",children:[w.jsxs("strong",{children:[P("Queued messages")," · ",t.queue.length]}),t.queuePaused&&w.jsx("button",{className:"button",type:"button",onClick:()=>{t.action(()=>t.resumeQueue())},children:P("Run queue")})]}),t.queue.map((V,ie)=>w.jsxs("div",{className:"acp-queue-item","data-queue-id":V.id,onKeyDown:W=>{const Y=W.altKey?W.key==="ArrowUp"?ie-1:W.key==="ArrowDown"?ie+1:-1:-1;!t.canMoveQueued||Y<0||Y>=t.queue.length||(W.preventDefault(),F(V.id,Y,Y<ie?"up":"down"))},children:[w.jsxs("span",{title:V.text,children:[ie+1,". ",V.text]}),t.busy&&!t.cancelling&&w.jsx(Ue,{icon:"play",label:P("Send queued message now"),onClick:()=>{t.action(()=>t.sendQueuedNow(V.id))}}),t.canMoveQueued&&ie>0&&w.jsx(Ue,{icon:"arrowUp",label:"Move queued message up","data-move":"up",onClick:()=>F(V.id,ie-1,"up")}),t.canMoveQueued&&ie<t.queue.length-1&&w.jsx(Ue,{icon:"arrowDown",label:"Move queued message down","data-move":"down",onClick:()=>F(V.id,ie+1,"down")}),w.jsx(Ue,{icon:"pencil",label:P("Edit queued message"),onClick:()=>{t.action(()=>t.editQueued(V.id))}}),w.jsx(Ue,{icon:"x",label:P("Remove queued message"),onClick:()=>{t.action(()=>t.removeQueued(V.id))}})]},V.id))]}),w.jsxs("form",{className:"acp-composer",onSubmit:V=>{V.preventDefault(),t.action(()=>t.send())},onDragOver:V=>{V.dataTransfer.types.includes("Files")&&V.preventDefault()},onDrop:V=>{const ie=jG(V.dataTransfer);ie.length&&(V.preventDefault(),t.action(async()=>{for(const W of ie)await t.attachImage(W)}))},children:[w.jsxs("div",{id:b,ref:m,popover:"auto",className:"acp-context-menu",role:"region","aria-label":P("Add context"),onToggle:V=>{V.newState==="closed"&&$(!1)},children:[w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attachDiagnostics())},children:[w.jsx(Te,{name:"warning",size:14}),P("Attach diagnostics")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attachChanges())},children:[w.jsx(Te,{name:"git",size:14}),P("Attach changes")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attach())},children:[w.jsx(Te,{name:"files",size:14}),P("Attach file")]}),w.jsxs("button",{type:"button",className:"button",onClick:()=>{t.action(()=>t.attach(!0))},children:[w.jsx(Te,{name:"focus",size:14}),P("Attach selection")]}),k&&w.jsx(lJe,{agent:t})]}),t.context.length>0&&w.jsxs("div",{className:"acp-attachments",children:[t.context.map((V,ie)=>w.jsxs("div",{className:"acp-context-chip",children:[w.jsx(HG,{item:V}),w.jsx(Ue,{icon:"x",label:P("Remove attachment {0}",{0:V.kind==="changes"?P("Uncommitted changes"):["thread","branch","commit","folder"].includes(V.kind)?V.label??V.path:V.path}),onClick:()=>{t.context.splice(ie,1),t.changed()}})]},ie)),w.jsxs("p",{className:"acp-context-budget muted",children:[t.context.length,"/8 ",P("attachments")," ·"," ",(t.draft.length+t.context.reduce((V,ie)=>V+ie.text.length,0)).toLocaleString()," ",P("characters")]})]}),t.archived&&w.jsx("p",{className:"muted",children:P("Saved transcript. Choose Resume in History to continue this conversation.")}),w.jsx(VKe,{inputRef:Q,actionsRef:A,configuration:e.configuration,commands:t.commands,value:t.draft,onChange:V=>{t.draft=V,t.changed()},onSend:()=>{t.action(()=>t.send())},onEscape:()=>!t.busy||t.cancelling?!1:(t.action(()=>t.cancel()),!0),onMention:V=>{t.action(()=>t.attachMention(V))},onImages:V=>{t.action(async()=>{for(const ie of V)await t.attachImage(ie)})},findFiles:(V,ie)=>rKe(t.options.filesystem,V,ie),findSymbols:(V,ie)=>nKe(t.options.kernel.services.optional("language"),V,ie),findThreads:V=>t.mentionThreads(V),findCommits:V=>t.mentionCommits(V),branchDiff:t.branchDiffAvailable,onMentionOpen:()=>t.probeBranchDiff()}),w.jsxs("div",{className:"acp-composer-toolbar",children:[w.jsx("button",{ref:S,type:"button",className:"icon-button","aria-label":P("Add context"),"data-tooltip":P("Add context"),"aria-controls":b,"aria-expanded":k,onClick:()=>$(!k),children:w.jsx(Te,{name:"plus"})}),t.commands.length>0&&w.jsx("button",{type:"button",className:"icon-button acp-slash-button","aria-label":P("Slash commands"),"data-tooltip":P("Slash commands"),onMouseDown:V=>V.preventDefault(),onClick:()=>A.current?.insertSlash(),children:w.jsx("span",{"aria-hidden":"true",children:"/"})}),w.jsx(RKe,{value:t.draft,onChange:V=>{t.draft=V,t.changed()},onError:V=>{t.error=V,t.changed()}}),t.autoApply&&!t.archived&&w.jsxs("span",{className:"acp-auto-apply-on",title:P("Agent edits save without review"),children:[w.jsx(Te,{name:"check",size:12}),P("Auto-apply on")]}),w.jsx(XKe,{configuration:e.configuration}),t.busy&&w.jsx(Ue,{icon:"stop",label:t.cancelling?"Stopping…":"Stop",disabled:t.cancelling,onClick:()=>{t.action(()=>t.cancel())}}),t.busy&&t.draft.trim()&&w.jsx("button",{type:"button",className:"button acp-interrupt",disabled:t.cancelling,onClick:()=>{t.action(()=>t.interruptAndSend())},children:P("Interrupt & send")}),w.jsx(Ue,{icon:"arrowUp",label:t.busy?"Queue message":"Send",className:"icon-button acp-send",type:"submit",disabled:!!Z&&!Z.sessionId||!t.draft.trim()||!J||t.connecting||t.updatingSettings||t.discovering||t.archived})]})]}),w.jsxs("div",{className:"acp-footer",children:[t.usage&&w.jsx(_Ke,{usage:t.usage}),Z||se&&(t.messages.length>0||t.archived)?w.jsxs("div",{className:"acp-provider",title:t.displayName,children:[w.jsx(Te,{name:"agent",size:14}),w.jsx("span",{children:t.displayName})]}):(t.messages.length>0||t.archived)&&w.jsx(fn,{label:P("ACP provider"),icon:"agent",value:B,options:[...hv.map(V=>({value:V.id,label:V.name})),...io(B)?[]:[{value:B,label:t.displayName}],{value:"#registry",label:P("More agents…")},{value:"#custom",label:P("Custom agent…")}],disabled:t.connecting,onChange:V=>{V==="#registry"?n("registry"):V==="#custom"?n("custom"):t.action(()=>t.select({provider:V}))}}),!t.archived&&w.jsxs("label",{className:"acp-auto-apply",title:P("Save agent file changes without review. Permission prompts still ask."),children:[w.jsx("input",{type:"checkbox",role:"switch",className:"setting-switch",checked:t.autoApply,onChange:V=>t.setAutoApply(V.target.checked)}),w.jsx("span",{children:P("Auto-apply edits")})]}),re.length>0&&w.jsxs("details",{className:"acp-session-options",children:[w.jsxs("summary",{children:[P("Session settings"),w.jsx(Te,{name:"chevD",size:12})]}),w.jsx("div",{className:"acp-settings","aria-busy":t.updatingSettings,children:re.map(V=>w.jsxs("div",{className:"acp-setting",children:[w.jsx("span",{className:"acp-setting-label",title:V.description,children:P(V.name)}),w.jsx(fn,{label:P(V.name),value:V.value,options:V.options,disabled:M,onChange:ie=>{E.current=document.activeElement instanceof HTMLElement?document.activeElement:null,t.action(()=>t.setSessionControl(V,ie))}})]},`${V.method}:${V.id}`))})]})]})]})}function RJe({agent:t}){if(L.useSyncExternalStore(t.subscribe,t.snapshot),!t.connection)return null;const[e,i]=t.requests.length?["attention","Agent needs input"]:t.busy?["working","Agent working"]:["ready","Agent ready"];return w.jsxs("button",{type:"button",className:"acp-status-item","data-state":e,title:P("Open Agent"),onClick:()=>{t.options.kernel.commands.execute("agentACP.open")},children:[w.jsx(Te,{name:"agentChat",size:13}),w.jsx("span",{children:P(i)})]})}function QJe(t){return{manifest:{manifestVersion:1,id:"oxbit.agent-acp",name:"Agent ACP",version:"1.0.0",sdk:"^1.0.0",description:"Codex, Claude Agent, Gemini CLI, GitHub Copilot, Cursor, Amp, and ACP Registry agents with conversations, editor context, tool activity, and approvals.",enabledByDefault:!1,environments:["browser","embedded"],activation:["*"],capabilities:["extensions","filesystem.read","filesystem.write","terminal"],configuration:_Ye},activate(e){const i=t.runtime?void 0:new TJe(t,()=>t.kernel.services.optional(fv)),s=new wKe({...t,runtime:t.runtime??i});e.own(s),i&&e.own(i),e.own(IYe(s,()=>t.workbench.panelVisible?.(lu)===!0)),e.own(e.services.register("agentACP",s)),e.own(e.contributions.register({id:lu,kind:"activityView",title:"Agent ACP",order:45,data:{icon:"agentChat",dock:"right",phoneBar:!0,phoneLabel:"Agent"},component:()=>w.jsx(EJe,{agent:s})})),e.own(e.contributions.register({id:"agent-acp-agents",kind:"activityView",title:"Agents",order:46,data:{icon:"agent",dock:"right"},component:()=>w.jsx(KG,{agent:s,renderRequest:r=>w.jsx(xA,{request:r,agent:s},r.requestId)})})),e.own(e.contributions.register({id:"agent-acp.status",kind:"statusItem",title:"Agent status",component:()=>w.jsx(RJe,{agent:s})})),e.own(e.commands.register({id:"agentACP.openAgents",title:"Open Agents",category:"Agent ACP",run:()=>s.openAgents()})),e.own(e.commands.register({id:"agentACP.open",title:"Open Agent ACP",category:"Agent ACP",run:()=>{t.workbench.openPanel(lu),s.markSeen()}}));for(const[r,a,n]of[["agentACP.attachFile","Attach Active File",()=>s.attach()],["agentACP.attachSelection","Attach Selection",()=>s.attach(!0)],["agentACP.stop","Stop Agent",()=>s.cancel()]])e.own(e.commands.register({id:r,title:a,category:"Agent ACP",run:async()=>{await t.kernel.commands.execute("agentACP.open"),await s.action(n)}}))}}}const Fh=t=>`${(t/1e3).toFixed(1)} kB`,Xy=["#818cf8","#34d399","#fbbf24","#f472b6","#60a5fa","#fb923c"],DJe=t=>{const e=t.eol==="CRLF"?t.text.replace(/\r\n/g,`
409
409
  `).replace(/\n/g,`\r
410
410
  `):t.text;if(t.encoding==="latin1")return Uint8Array.from(e,r=>r.charCodeAt(0));if(t.encoding==="utf-16le"){const r=new Uint8Array(e.length*2+2);r.set([255,254]);for(let a=0;a<e.length;a++)r[a*2+2]=e.charCodeAt(a)&255,r[a*2+3]=e.charCodeAt(a)>>8;return r}const i=new TextEncoder().encode(e);if(t.encoding!=="utf-8-bom")return i;const s=new Uint8Array(i.length+3);return s.set([239,187,191]),s.set(i,3),s},NJe={manifest:{manifestVersion:1,id:"orbitlabs.bundle-inspector",name:"Bundle Inspector",version:"1.0.0",sdk:"^1.0.0",environments:["browser","embedded"],activation:["onStartup","onCommand:bundle.analyze","onCommand:bundle.openReport"],commands:[{id:"bundle.analyze",title:"Bundle Inspector: Analyze",category:"Bundle Inspector",when:"workspace"},{id:"bundle.openReport",title:"Bundle Inspector: Open Report",category:"Bundle Inspector",when:"workspace"}],capabilities:["filesystem.read"],description:"Measure workspace file sizes and gzip sizes through the public extension SDK.",configuration:[{id:"bundle.outputDirectory",title:"Bundle output directory",type:"string",default:"dist",category:"Bundle Inspector"},{id:"bundle.budgetKB",title:"Bundle size budget (kB)",type:"number",default:500,min:1,max:1e6,category:"Bundle Inspector"}]},activate(t){let e={directory:"",files:[],total:0,gzip:0,truncated:!1,running:!1};const i=new Set,s={lines:[]},r=()=>{for(const $ of i)$()};let a;const n=()=>t.services.optional("workbench"),o=()=>a?.abort();t.signal.addEventListener("abort",o);const l=async()=>{a?.abort(),a=new AbortController;const $=a.signal,_=t.services.get("filesystem");e={directory:t.configuration.get("bundle.outputDirectory"),files:[],total:0,gzip:0,truncated:!1,running:!0};const C=e;n()?.openPanel("bundle"),r();const b=()=>{if($.aborted||t.signal.aborted)throw new DOMException("Analysis cancelled","AbortError")};try{let Q;try{Q=await _.list(C.directory)}catch(S){if(!/ENOENT|not found|missing|does not exist/i.test(S instanceof Error?S.message:String(S)))throw S;C.directory="",Q=await _.list("")}b(),Q.length===0&&C.directory&&(C.directory="",Q=await _.list(""));const A=async S=>{for(const m of S){if(b(),C.files.length>=2e3){C.truncated=!0;return}if(m.kind==="directory"){["node_modules",".git",".oxbit"].includes(m.name)||await A(await _.list(m.path));continue}const v={path:m.path,bytes:m.size??0};if(!m.size||m.size<=2e6)try{const E=await _.read(m.path),D=DJe(E);if(v.bytes=D.length,typeof CompressionStream<"u"&&(v.gzip=(await new Response(new Blob([D]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer()).byteLength),/\.[cm]?js$/.test(m.name))try{const N=JSON.parse((await _.read(`${m.path}.map`)).text);Array.isArray(N.sources)&&(v.modules=N.sources.length)}catch{}}catch(E){v.error=E instanceof Error?E.message:String(E)}b(),C.files.push(v),C.total+=v.bytes,C.gzip+=v.gzip??0}};await A(Q),C.files.sort((S,m)=>m.bytes-S.bytes||S.path.localeCompare(m.path))}catch(Q){if($.aborted||t.signal.aborted)return;C.error=Q instanceof Error?Q.message:String(Q)}finally{C.running=!1,!$.aborted&&!t.signal.aborted&&(s.lines.push(`${new Date().toISOString()} ${C.directory||"workspace"}: ${C.files.length} files, ${C.total} bytes${C.error?`, ${C.error}`:""}`),s.lines.length>200&&s.lines.shift(),r())}return C},c=()=>n()?.openView("bundle.report","Bundle report",y,{},{contributionId:"bundle.report"});function u(){const[,$]=L.useState(0);return L.useEffect(()=>{const _=()=>$(b=>b+1);i.add(_);const C=t.configuration.subscribe(_);return()=>{i.delete(_),C()}},[]),e}function d(){const $=u();return L.createElement("div",{style:{display:"flex",height:14,gap:2,borderRadius:4,overflow:"hidden",margin:"12px 0"},"aria-label":"File size distribution"},...$.files.slice(0,40).map((_,C)=>L.createElement("span",{key:_.path,title:`${_.path}: ${_.bytes} bytes`,style:{background:Xy[C%Xy.length],width:`${$.total?_.bytes/$.total*100:0}%`}})))}function p(){const $=u();return L.createElement("div",{style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"}},L.createElement("strong",null,Fh($.total)),L.createElement("span",{className:"muted"},`${$.files.length} files · ${$.directory||"workspace"}/ · budget ${t.configuration.get("bundle.budgetKB")} kB`),L.createElement("button",{className:"button",disabled:$.running,onClick:()=>{t.commands.execute("bundle.analyze")}},$.running?"Analyzing…":"Analyze"),L.createElement("button",{className:"button",onClick:c},"Open report"))}function g(){const $=u();return L.createElement("section",{className:"bundle-inspector",style:{padding:16},"aria-label":"Bundle Inspector"},L.createElement(p),L.createElement(d),$.error?L.createElement("p",{role:"alert"},$.error):L.createElement("p",{className:"muted"},$.files.length?`${Fh($.gzip)} measured gzip${$.truncated?" · First 2,000 files":""}`:"Run Analyze to measure files in the output directory."))}function y(){const $=u(),_=t.configuration.get("bundle.budgetKB")*1e3,C=L.createElement("thead",null,L.createElement("tr",null,...["File","Size","Gzip","Modules","Share"].map(A=>L.createElement("th",{key:A,style:{padding:8}},A)))),b=$.files.map((A,S)=>L.createElement("tr",{key:A.path,title:A.error},L.createElement("td",{style:{padding:8,fontFamily:"var(--font-mono)"}},A.path),L.createElement("td",null,Fh(A.bytes)),L.createElement("td",null,A.gzip===void 0?"Not measured":Fh(A.gzip)),L.createElement("td",null,A.modules===void 0?"No source map":String(A.modules)),L.createElement("td",null,L.createElement("span",{style:{display:"block",height:8,background:Xy[S%Xy.length],width:`${$.total?A.bytes/$.total*100:0}%`,minWidth:2}})))),Q=L.createElement("table",{style:{width:"100%",borderCollapse:"collapse",textAlign:"left",fontSize:12}},C,L.createElement("tbody",null,...b));return L.createElement("article",{style:{padding:20,overflow:"auto",height:"100%",maxWidth:880,margin:"0 auto",boxSizing:"border-box"},"aria-label":"Bundle report"},L.createElement("h2",null,"Bundle report"),L.createElement(p),L.createElement(d),Q,L.createElement("p",{className:"muted"},`Budget ${Fh(_)} · ${$.total<=_?"Within budget":"Over budget"}${$.truncated?" · First 2,000 files":""}`))}function k(){const $=u();return L.createElement("span",null,$.running?"Analyzing…":`Bundle ${$.total>=1e9?`${($.total/1e9).toFixed(1)} GB`:$.total>=1e6?`${($.total/1e6).toFixed(1)} MB`:Fh($.total)}`)}t.commands.register({id:"bundle.analyze",title:"Bundle Inspector: Analyze",category:"Bundle Inspector",when:"workspace && bundleExt",run:l}),t.commands.register({id:"bundle.openReport",title:"Bundle Inspector: Open Report",category:"Bundle Inspector",when:"workspace && bundleExt",run:c}),t.contributions.register({id:"bundle",kind:"panel",title:"Bundle Inspector",order:90,component:g}),t.contributions.register({id:"bundle.status",kind:"statusItem",title:"Bundle Inspector",order:90,command:"bundle.analyze",component:k,data:{label:"Bundle"}}),t.contributions.register({id:"bundle.output",kind:"outputChannel",title:"Bundle Inspector",data:s}),t.contributions.register({id:"bundle.report",kind:"documentView",title:"Bundle report",component:y,command:"bundle.openReport",data:{matches:$=>$.split("/").pop()==="package.json"}}),t.context.set("bundleExt",!0),t.subscribe(()=>{o(),t.signal.removeEventListener("abort",o),n()?.closeView("bundle.report"),i.clear(),s.lines.length=0,t.context.set("bundleExt",!1)})}},qy=()=>T6({},{}),KI=t=>t instanceof Error?t.message:String(t),FJe={ttl:0,actions:[{title:"Save Local Settings",command:"settings.saveWorkspace"},{title:"Reload from Disk",command:"settings.reloadWorkspace"}]};function H_(t,e){const i={user:Rb(t,"user"),workspace:Rb(t,"workspace")},s=e.map(r=>{let a=i[r.scope];for(const l of r.path.slice(0,-1))wd(a[l])||(a[l]={}),a=a[l];const n=r.path.at(-1),o=a[n];return r.value===void 0?delete a[n]:a[n]=r.value,{scope:r.scope,path:r.path,...o===void 0?{}:{before:o},...r.value===void 0?{}:{value:r.value}}});return{layers:T6(i.user,i.workspace),changes:s}}class LJe{constructor(e,i,s){this.storage=e,this.filesystem=i,this.runtime=s,this.key="workspace-settings:"+i.id,this.recoveryKey=this.key+":files",this.fileSettings=!!s&&s.session?.owner!==!1}storage;filesystem;runtime;key;recoveryKey;loaded;snapshot;local=qy();pending=[];queue=Promise.resolve();kernel;notify;errors=[];reported=new Set;subscriptions=[];disposed=!1;fileSettings;async get(e){return e!=="settings"?this.storage.get(e):(this.loaded??=this.load(),structuredClone(await this.loaded))}async load(){const e=await this.storage.get("settings"),i=await this.storage.get("profile-settings"),s=await this.storage.get(this.key);if(this.local={...qy(),...e,...i,...s},!this.fileSettings)return this.local;const r=await this.storage.get(this.recoveryKey);let a=structuredClone(this.local);if(r)this.snapshot=r.snapshot,this.local=r.local,this.pending=r.pending;else{const n=await this.storage.get(this.key+":pending");if(n){const o=T6({},n.lastText?pJ(JSON.parse(n.lastText)):{});a={...a,workspace:o.workspace,workspaceLanguages:o.workspaceLanguages},this.local={...this.local,...n.value},this.pending=Sm(a,this.local)}this.snapshot={layers:a,files:[]}}try{const n=await this.runtime.request("settings.read",{legacy:r?.snapshot.layers??a});this.snapshot=n,this.pending.length||(this.local=n.layers),this.reportFiles(n),await this.flush(),await this.cache()}catch(n){this.failed("Settings are retained locally",n)}return await this.cache(),this.local}async set(e,i){if(e!=="settings")return this.storage.set(e,i);const s=structuredClone(i);if(!this.fileSettings){this.local=s,await this.storage.set("profile-settings",{user:s.user,userLanguages:s.userLanguages}),await this.storage.set(this.key,{workspace:s.workspace,workspaceLanguages:s.workspaceLanguages});return}const r=Sm(this.local,s);this.local=s,this.pending.push(...r),this.snapshot&&!Sm(this.snapshot.layers,this.local).length&&(this.pending=[]),this.queue=this.queue.catch(()=>{}).then(async()=>{await this.cache();try{await this.flush()}catch(a){this.failed("Settings are retained locally",a)}}),await this.queue}async cache(){this.snapshot&&(await this.storage.set(this.recoveryKey,{snapshot:this.snapshot,local:this.local,pending:this.pending}),await this.storage.delete(this.key+":pending"))}async flush(){if(!this.pending.length||this.disposed)return;if(!this.runtime?.connected)throw new Error("Reconnect to save settings to disk.");this.snapshot?.files.length||(this.snapshot=await this.runtime.request("settings.read",{legacy:this.snapshot?.layers??qy()}));const e=[...this.pending],i=structuredClone(this.local);let s,r=[],a;try{s=await this.runtime.request("settings.patch",{changes:e})}catch(n){if(n.code!=="CONFLICT")throw n;const o=await this.runtime.request("settings.read");r=e.filter(c=>o.files.some(u=>u.scope===c.scope&&u.error));const l=H_(o.layers,e.filter(c=>!r.includes(c))).changes;s=l.length?await this.runtime.request("settings.patch",{changes:l}):o,r.length&&(a=Object.assign(new Error("Fix invalid settings JSON before saving this scope"),{code:"CONFLICT"}))}if(this.pending.splice(0,e.length,...r),this.snapshot=s,this.pending.length===r.length&&(!this.kernel||!Sm(i,this.kernel.configuration.export()).length)&&this.apply(s,r),await this.cache(),a)throw a}apply(e,i=[]){this.snapshot=e,this.local=i.length?H_(e.layers,i).layers:structuredClone(e.layers),this.kernel?.configuration.import(this.local,{persist:!1}),this.reportFiles(e),!this.pending.length&&!e.files.some(s=>s.error)&&this.reported.clear()}reportFiles(e){for(const i of e.files)i.error&&this.report(`${i.path}: ${i.error}. Keeping the last valid settings.`)}failed(e,i){this.report(`${e}: ${KI(i)}`,KI(i),i.code==="CONFLICT"?FJe:void 0)}report(e,i=e,s){this.reported.has(i)||(this.reported.add(i),this.notify?this.notify(e,"error",s):this.errors.push([e,"error",s]))}attach(e,i){this.kernel=e,this.notify=i;for(const r of this.errors)i(...r);if(this.errors=[],!this.fileSettings)return;const s=()=>{this.queue=this.queue.catch(()=>{}).then(async()=>{if(!this.disposed)try{if(await this.flush(),this.pending.length||Sm(this.local,e.configuration.export()).length)return;this.apply(await this.runtime.request("settings.read")),await this.cache()}catch(r){this.failed("Settings reload failed",r)}})};this.subscriptions.push(this.runtime.subscribe("settings.changed",s)),this.subscriptions.push(this.runtime.subscribe("connection.change",r=>{r.state==="connected"&&s()}))}async resolveWorkspaceSettings(e){if(!this.runtime?.connected||!this.kernel||!this.fileSettings)throw new Error("Connect to the workspace owner runtime first");await this.queue;const i=await this.runtime.request("settings.read");e==="disk"?(this.pending=[],this.apply(i)):(this.pending=H_(i.layers,this.pending).changes,this.pending.length?await this.flush():this.apply(i)),await this.cache()}async delete(e){e==="settings"?await this.set(e,qy()):await this.storage.delete(e)}async dispose(){this.disposed=!0;for(const e of this.subscriptions)e();await this.queue.catch(()=>{})}}const JI="oxbit.iconPack.seeded",MJe=()=>typeof localStorage>"u"?void 0:localStorage;async function IJe(t){for(const e of[d4,l4])try{const i=MJe(),s=e.id===d4.id?JI:`${JI}.${e.id}`;if(i?.getItem(s)===e.revision)continue;const r=(await t.read()).find(a=>a.id===e.id);r?.revision!==e.revision&&(await t.put(e),!r&&!e.enabled&&await t.enable(e.id,!1)),i?.setItem(s,e.revision)}catch{}}async function jJe({filesystem:t,runtime:e,git:i,persistence:s,active:r=!0,protectUnload:a=!0,preserveFilesystem:n=!1,additionalExtensionOrigins:o,iconPackStore:l,runtimeConnector:c}){const u=new LJe(s,t,e);await u.get("settings");const d=u5e({environment:"browser",persistence:u,additionalExtensionOrigins:o}),p=new PCe(t,s,d),g=new Mke(d,p,t,s);u.attach(d,($,_,C)=>g.notify($,_,C)),e&&(d.commands.register({id:"settings.reloadWorkspace",title:"Reload Settings from Disk",run:async()=>{await g.ask(P("Reload settings?"),P("Discard pending user and workspace changes and reload the merged settings files?"),[P("Reload"),P("Cancel")])===P("Reload")&&await u.resolveWorkspaceSettings("disk")}}),d.commands.register({id:"settings.saveWorkspace",title:"Save Local Settings to Disk",run:async()=>{await g.ask(P("Save local settings?"),P("Apply pending user and workspace changes over the current disk settings?"),[P("Save"),P("Cancel")])===P("Save")&&await u.resolveWorkspaceSettings("local")}})),d.services.register("workbench",g),d.services.register("documents",p),d.services.register("filesystem",t),d.services.register("persistence",s),e&&d.services.register("runtime",e),c&&d.services.register(Z6,c),d.context.set("workspace",!0),d.context.set("connected",!!e?.connected),d.context.set("trusted",!!e?.session?.trusted),d.context.set("editor",!1);const y=l??new N3e,k=new F3e(d,y,$=>g.notify($,"warning",{source:"Icon Packs",actions:[{title:"Manage Icon Packs",command:"iconPacks.manage"}]}));d.services.register("iconThemes",k);try{await IJe(y),await k.initialize().catch(j=>g.notify(`Icon packs could not be loaded: ${String(j)}`,"warning")),await p.restore();const $={kernel:d,documents:p,filesystem:t,runtime:e,git:i,workbench:g},_=e?.subscribe("connection.change",({state:j})=>{j==="connected"&&g.scheduleRefreshFiles(),d.context.set("connected",j==="connected"),d.context.set("trusted",j==="connected"&&!!e.session?.trusted),d.events.emit("connection.change",{state:j})}),C=e?.subscribe("workspace.trust",({trusted:j})=>{d.context.set("trusted",j===!0),g.touch()}),b=[sMe($),SMe($),mje($),BIe($),UIe($),pje($),xje($),qke(g),ILe($),BLe($),_Me($),hVe($),cVe(),uVe(),iqe($),nqe($),Jqe($),aVe($),nYe($),uYe($),yYe($),vYe($),QJe($),NJe];for(const j of b)d.extensions.register(j);await fje(s,d.configuration.get("workbench.colorTheme"));const Q=await s.get("extension-disabled")||[],A=await s.get("extension-enabled")||[];for(const j of b)(Q.includes(j.manifest.id)||j.manifest.enabledByDefault===!1&&!A.includes(j.manifest.id))&&await d.extensions.disable(j.manifest.id);e&&await LXe(d,Q);for(const[j,q]of Object.entries(await s.get("extension-artifacts")||{}))try{if(d.extensions.list().some(ae=>ae.manifest.id===j)){const ae=await import(q);await d.extensions.update(ae.default||ae.extension)}else await d.extensions.load(q,{activate:!1});Q.includes(j)&&await d.extensions.disable(j)}catch(ae){g.notify(`Extension recovery failed: ${String(ae)}`,"error")}await d.extensions.trigger("onStartup"),await d.extensions.trigger("onWorkspace");for(const j of p.documents.values())await d.extensions.trigger("onLanguage:"+Zi(d,j.path).id);for(const j of d.extensions.list())j.state==="failed"&&g.notify(`${j.manifest.name}: ${j.error}`,"error");const S=p.subscribe(g.documentChanged);await g.restore();const m=t.id==="browser";if(g.set({projectName:e?e.session?.workspaceName??"Runtime workspace":m?"orbit-dash":"Directory workspace"}),!g.state.groups.some(j=>j.tabs.length)){const j=m?["src/hooks/useTelemetry.ts","src/App.tsx","src/components/Chart.tsx","README.md"]:[g.state.files.find(q=>q.kind==="file"&&/\.(tsx?|jsx?|md)$/.test(q.path))?.path].filter(Boolean);for(const q of j)try{await g.openFile(q,{preview:!1})}catch(ae){g.notify(String(ae),"error")}m&&(g.set({groups:g.state.groups.map(q=>({...q,tabs:q.tabs.map(ae=>ae.path==="src/App.tsx"?{...ae,pinned:!0}:ae)})),panel:!0,panelId:"terminal"}),await g.openFile("src/hooks/useTelemetry.ts"))}const v=new Map,E=async j=>{try{p.get(j)?.dirty&&await p.save(j)}catch(q){g.notify(String(q),"error")}},D=d.events.on("document.change",({id:j})=>{const q=[...p.documents.values()].find(ae=>ae.id===j);q&&(clearTimeout(v.get(q.path)),d.configuration.get("files.autoSave",Zi(d,q.path).id)==="afterDelay"&&v.set(q.path,setTimeout(()=>{E(q.path)},d.configuration.get("files.autoSaveDelay",Zi(d,q.path).id)??1e3)))}),N=d.configuration.subscribe(()=>{for(const j of v.values())clearTimeout(j);v.clear();for(const j of p.documents.values())j.dirty&&d.configuration.get("files.autoSave",Zi(d,j.path).id)==="afterDelay"&&v.set(j.path,setTimeout(()=>{E(j.path)},d.configuration.get("files.autoSaveDelay",Zi(d,j.path).id)??1e3))}),Z=j=>{if(!r)return;const q=j.target?.closest(".cm-editor");if(!(!q||j.relatedTarget instanceof Node&&q.contains(j.relatedTarget)))for(const ae of p.documents.values())d.configuration.get("files.autoSave",Zi(d,ae.path).id)==="onFocusChange"&&E(ae.path)},J=()=>{if(r)for(const j of p.documents.values())d.configuration.get("files.autoSave",Zi(d,j.path).id)==="onWindowChange"&&E(j.path)},se=()=>{p.persist(),g.persist()},re=j=>{se(),a&&[...p.documents.values()].some(q=>q.dirty)&&(j.preventDefault(),j.returnValue="")};document.addEventListener("focusout",Z),window.addEventListener("blur",J),window.addEventListener("pagehide",se),window.addEventListener("beforeunload",re);const M={kernel:d,documents:p,filesystem:t,workbench:g,runtime:e,setActive(j){r=j},async persist(){await d.configuration.flush?.(),await u.set("settings",d.configuration.export()),await p.persist(),await g.persist()},async dispose(){await M.persist(),document.removeEventListener("focusout",Z),window.removeEventListener("blur",J),window.removeEventListener("pagehide",se),window.removeEventListener("beforeunload",re);for(const j of v.values())clearTimeout(j);D.dispose(),N(),_?.(),C?.(),S(),k.dispose(),await u.dispose(),g.dispose(),d.dispose(),p.dispose(),e?.dispose(),n||t.dispose?.()}};return d.events.emit("workspace.change",{id:t.id,state:"opened"}),d.events.emit("connection.change",{state:e?.connected?"connected":"disconnected"}),M}catch($){throw k.dispose(),await u.dispose(),g.dispose(),d.dispose(),p.dispose(),e?.dispose(),n||t.dispose?.(),$}}const K_="runtimes",zJe=12,Vy=(t,e)=>e?"url:"+e:"url:"+t;async function eH(t,e){const i=e instanceof Error?e.message:String(e);if(!/cannot connect|connection closed|timed out|failed to fetch/i.test(i))return i;try{const s=await fetch(t+"/api/health",{signal:AbortSignal.timeout(4e3)});return s.ok?P("The runtime at {0} is running but refused this browser. Pair it again with its pairing code.",{0:t}):P("{0} answered HTTP {1}; it is not an Oxbit runtime.",{0:t,1:s.status})}catch{return await fetch(t+"/api/health",{mode:"no-cors",signal:AbortSignal.timeout(4e3)}).then(()=>!0,()=>!1)?P("{0} is reachable but did not accept this page. Open Oxbit from the address the runtime prints, or pair it again.",{0:t}):P("No runtime answered at {0}. Start one with oxbit and check the address.",{0:t})}}class BJe{constructor(e){this.host=e}host;store=new uMe;startCommand="oxbit --no-open";session;detach=[];status=this.store.get;subscribe=this.store.subscribe;attach(e){for(const a of this.detach)a();this.session=e;const i=e.runtime;if(!i){this.detach=[],this.store.replace({state:"disconnected",error:this.store.get().error});return}const s=()=>this.store.replace({state:i.connected?"connected":this.store.get().state==="failed"?"failed":"reconnecting",...dMe(i,"url"),targetKey:Vy(i.url,i.identity?.id)}),r=()=>{i.autoReconnect=e.kernel.configuration.get(Bw)!==!1};r(),s(),this.detach=[i.subscribe("connection.change",({state:a})=>a==="disconnected"?this.store.set({state:"disconnected"}):s()),i.subscribe("workspace.trust",({trusted:a})=>this.store.set({trusted:a===!0})),e.kernel.configuration.subscribe(r)]}quickTarget(){const e=this.session?.runtime;return e?{key:Vy(e.url,e.identity?.id),kind:"url",name:e.identity?.name??new URL(e.url).host,url:e.url,runtimeId:e.identity?.id}:this.saved[0]}saved=[];async load(){const e=await this.host.persistence.get(K_),i=await this.host.persistence.get("last-host");return this.saved=Array.isArray(e)?e:[],!this.saved.length&&i?.url&&(this.saved=[{key:Vy(i.url,i.runtimeId),kind:"url",name:new URL(i.url).host,url:i.url,runtimeId:i.runtimeId}]),this.saved}recents=()=>this.load();async forget(e){this.saved=(await this.load()).filter(i=>i.key!==e.key&&i.url!==e.url),await this.host.persistence.set(K_,this.saved)}async remember(e){const i=e.identity?.id,s={key:Vy(e.url,i),kind:"url",runtimeId:i,url:e.url,lastConnected:Date.now(),name:e.identity?.name??new URL(e.url).host,detail:e.session?.workspaceName?`${e.session.workspaceName} · ${e.url}`:e.url};this.saved=[s,...(await this.load()).filter(r=>r.key!==s.key&&r.url!==s.url&&(!i||r.runtimeId!==i))].slice(0,zJe),await this.host.persistence.set(K_,this.saved),await this.host.persistence.set("last-host",{url:e.url,runtimeId:i})}async establish(e,i,s,r){this.store.replace({...this.store.get(),state:"connecting",progress:P("Connecting to {0}…",{0:i}),error:void 0});const a=new r3(e.replace(/\/$/,""),"default",{runtimeId:r});try{await s(a),this.store.progress(P("Opening the workspace…")),await this.host.open(a),await this.remember(a)}catch(n){throw a.dispose(),this.store.fail(await eH(a.url,n)),n}}connect(e){return e.url?this.establish(e.url,e.name,i=>i.connect(),e.runtimeId):Promise.reject(new Error(P("This runtime has no address. Pair it again.")))}pair(e,i){let s;try{s=new URL(e)}catch{return Promise.reject(new Error(P("Enter the runtime's http:// or https:// address.")))}return this.establish(s.origin,s.host,async r=>{await r.pair(i),await r.connect()})}async disconnect(){this.session?.runtime?.disconnect(),this.store.set({state:"disconnected",progress:void 0}),this.session?.workbench.touch()}async trust(e){const i=this.session?.runtime;i&&(await i.trust(e),this.store.set({trusted:!!i.session?.trusted}),this.session.kernel.context.set("trusted",!!i.session?.trusted),this.session.workbench.touch())}}globalThis.__OXBIT_REACT__=tve;uj(document);const No=new dve;let J_,ej=Promise.resolve();const jl=new fj(No,"browser");let tH=()=>{};const $g=new BJe({persistence:No,open:async t=>tH(await Xh(new gj(t),t))});function UJe(){const t=new URLSearchParams(location.hash.replace(/^#/,"")),e=t.get("pair")||void 0,i=t.get("open")||void 0;return(e||i)&&history.replaceState(null,"",location.pathname+location.search),{pair:e,open:i}}async function XJe(t,e,i){const s=new r3(t,"default",{runtimeId:i});try{if(await s.connect(),!e||s.session?.owner)return s}catch(a){if(!e)throw s.dispose(),a}s.dispose();const r=new r3(t);try{return await r.pair(e),await r.connect(),r}catch(a){throw r.dispose(),a}}function Xh(t,e){const i=ej.then(()=>qJe(t,e));return ej=i.then(()=>{},()=>{}),i}async function qJe(t,e){await J_?.persist();const i=await jJe({filesystem:t,runtime:e,persistence:No,preserveFilesystem:t===jl,runtimeConnector:$g});return await J_?.dispose(),J_=i,i}function VJe(){const[t,e]=L.useState(),[i,s]=L.useState(""),[r,a]=L.useState(),[n,o]=L.useState(!0),l=L.useCallback(d=>{$g.attach(d),e(d),o(!1),globalThis.__oxbit={...d,ready:!0,connectRuntime:u,runtimeConnector:$g,useBrowserWorkspace:c,openFile:(p,g)=>d.workbench.openFile(p,g),runCommand:(p,g)=>d.workbench.run(p,g)}},[]),c=L.useCallback(async()=>{o(!0);try{(await jl.list()).length||await jl.import(TE);const d=await Xh(jl);await No.set("last-host","browser"),l(d),a(void 0)}catch(d){s(String(d)),o(!1)}},[l]);tH=d=>{l(d),a(void 0)};const u=L.useCallback((d,p)=>$g.pair(d,p),[]);return L.useEffect(()=>{let d=!1;return(async()=>{const{pair:g,open:y}=UJe();let k=await No.get("last-host"),$,_="",C="";if(g||k?.url)try{$=await XJe(g?location.origin:k.url,g,g?void 0:k.runtimeId),(g||$.identity?.id!==k?.runtimeId)&&(k={url:$.url,runtimeId:$.identity?.id},await No.set("last-host",k))}catch(S){const m=g?location.origin:k.url,v=await eH(m,S);g?_=v:C=v,$g.store.fail(v)}const b=k==="directory"?await fve(No):void 0,Q=$?new gj($):b??jl;Q===jl&&!(await jl.list()).length&&await jl.import(TE);let A=await Xh(Q,$);if((_||C)&&A.workbench.notify(_?P("Runtime pairing failed: {0}",{0:_}):P("Could not reconnect to the runtime: {0}",{0:C}),"error",{actions:[{title:P("Open Runtime"),command:"runtime.open"}]}),k==="directory"&&!b&&A.workbench.notify(P("Directory access needs permission. Open the directory again; drafts remain stored.")),k?.providerId){const S=A.kernel.contributions.list("filesystem").find(v=>v.id===k.providerId),m=S?.data;if(m&&typeof m.open=="function")try{A=await Xh(await m.open()),A.workbench.set({projectName:S.title})}catch(v){A.workbench.notify(String(v),"error")}else A.workbench.notify(P("The saved filesystem provider is unavailable. Enable its extension to reopen the workspace."))}if(y)try{await A.workbench.openFile(y,{preview:!1})}catch(S){A.workbench.notify(P("Could not open {0}: {1}",{0:y,1:String(S)}),"error")}d||l(A)})().catch(g=>{s(String(g)),o(!1)}),()=>{d=!0}},[l]),L.useEffect(()=>{if(!t)return;const d=(g,y,k)=>t.kernel.commands.register({id:g,title:y,category:"Workspace",run:k}),p=[d("workspace.open","Open Folder…",()=>a("workspace")),d("workspace.switch","Switch Workspace…",()=>a("workspace")),d("workspace.close","Close Workspace",()=>{t.kernel.context.set("workspace",!1),t.workbench.set({workspaceOpen:!1}),t.kernel.events.emit("workspace.change",{id:t.filesystem.id,state:"closed"})}),d("workspace.browser","Open Browser Workspace",c),d("workspace.runtime","Connect Runtime",()=>t.workbench.run("runtime.cloud")),d("workspace.export","Export Browser Workspace",async()=>{const g=[],y=[];for await(const C of D6(t.filesystem))if(C.kind==="file"){const b=t.documents.get(C.path),Q=b?{text:b.text.toString(),encoding:b.encoding,eol:b.eol}:await t.filesystem.read(C.path);g.push({path:C.path,...Q})}else y.push(C.path);const k=new Blob([JSON.stringify({version:1,files:g,directories:y},null,2)],{type:"application/json"}),$=URL.createObjectURL(k),_=document.createElement("a");_.href=$,_.download="oxbit-workspace.json",_.click(),setTimeout(()=>URL.revokeObjectURL($),1e3)})];return t.workbench.touch(),()=>p.forEach(g=>g.dispose())},[t,c]),t?w.jsx(ZJe,{session:t,overlay:r,close:()=>a(void 0),useBrowserWorkspace:c,onConnect:()=>{t.workbench.run("runtime.cloud")},onOpenWorkspace:()=>a("workspace"),openProvider:async d=>{const p=t.kernel.contributions.list("filesystem").find(y=>y.id===d),g=p?.data;try{if(!g||typeof g.open!="function")throw new Error("Filesystem provider is unavailable");const y=await Xh(await g.open());y.workbench.set({projectName:p.title}),await No.set("last-host",{providerId:d}),l(y),a(void 0)}catch(y){t.workbench.notify(String(y),"error")}},openDirectory:async()=>{try{const d=await pve(No),p=await Xh(d);await No.set("last-host",d.id.startsWith("directory:")?"directory":"browser"),l(p),a(void 0)}catch(d){t.workbench.notify(String(d),"error")}},importWorkspace:async d=>{try{const p=JSON.parse(await d.text());await jl.import(p),await c()}catch(p){t.workbench.notify(String(p),"error")}}}):w.jsx("div",{className:"workbench","data-theme":"dark","data-density":"compact",children:w.jsxs("div",{className:"empty-state",style:{height:"100%"},children:[w.jsx(E6,{}),w.jsx("strong",{children:P(n?"Opening workspace…":"Workspace failed to open")}),i&&w.jsx("p",{role:"alert",children:i}),i&&w.jsx("button",{className:"button",onClick:()=>{c()},children:P("Retry")})]})})}function ZJe({session:t,overlay:e,close:i,useBrowserWorkspace:s,onConnect:r,onOpenWorkspace:a,openDirectory:n,openProvider:o,importWorkspace:l}){L.useSyncExternalStore(t.workbench.subscribe,t.workbench.snapshot),lj(t.kernel.configuration.get("workbench.locale"));const c=J0(t.kernel);return w.jsxs(w.Fragment,{children:[w.jsx(Zke,{workbench:t.workbench,runtime:t.runtime,onConnect:r,onOpenWorkspace:a}),e&&w.jsx("div",{className:"runtime-connect","data-theme":c,"data-theme-pack":bs(t.kernel).packId,"data-density":"compact",style:{...B6(t.kernel),color:"var(--fg)",fontFamily:"var(--font-body-font-family)",fontSize:"var(--font-body-font-size)"},children:w.jsx(n2e,{session:t,close:i,useBrowserWorkspace:s,openDirectory:n,onConnect:()=>{i(),t.workbench.run("runtime.open")},openProvider:o,importWorkspace:l})})]})}uve.createRoot(document.getElementById("root")).render(w.jsx(VJe,{}));export{sJ as a,WJe as c,YJe as g};
411
- //# sourceMappingURL=index-klUZpu8m.js.map
411
+ //# sourceMappingURL=index-BxpGWZaW.js.map