@openchamber/web 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{a as fe,p as N,j as i,aE as Le,c4 as ke,c3 as De,aJ as We,bx as qe,cc as Se,bO as Be,bz as _e,K as Ge,aQ as Ke,aI as Me,c7 as Ze,D as Ye,c8 as Je,cd as Qe,aH as Xe,c2 as et,$ as Ae,aT as tt,r as nt,a0 as Fe,aq as it}from"./vendor-.bun-Byc0cUD3.js";import{c as ue,D as st,t as ye,g as ze,f as rt,r as ot,a as at,b as lt,d as ct,S as Oe,e as dt,u as ut,h as Pe,p as ft,i as Re,V as mt,j as pt,k as ht}from"./main-DKLlKgOa.js";import"./index-BvZjrpc0.js";const gt=n=>{const e="h-3.5 w-3.5 flex-shrink-0",t=n.toLowerCase();return t==="reasoning"?i.jsx(We,{className:e}):t==="image-preview"?i.jsx(qe,{className:e}):t==="mermaid-preview"?i.jsx(Se,{className:e}):t==="edit"||t==="multiedit"||t==="apply_patch"||t==="str_replace"||t==="str_replace_based_edit_tool"?i.jsx(Be,{className:e}):t==="write"||t==="create"||t==="file_write"?i.jsx(_e,{className:e}):t==="read"||t==="view"||t==="file_read"||t==="cat"?i.jsx(_e,{className:e}):t==="bash"||t==="shell"||t==="cmd"||t==="terminal"?i.jsx(Ge,{className:e}):t==="list"||t==="ls"||t==="dir"||t==="list_files"?i.jsx(Ke,{className:e}):t==="search"||t==="grep"||t==="find"||t==="ripgrep"?i.jsx(Me,{className:e}):t==="glob"?i.jsx(Ze,{className:e}):t==="fetch"||t==="curl"||t==="wget"||t==="webfetch"?i.jsx(Ye,{className:e}):t==="web-search"||t==="websearch"||t==="search_web"||t==="google"||t==="bing"||t==="duckduckgo"?i.jsx(Me,{className:e}):t==="todowrite"||t==="todoread"?i.jsx(Je,{className:e}):t==="plan_enter"?i.jsx(Se,{className:e}):t==="plan_exit"?i.jsx(Qe,{className:e}):t.startsWith("git")?i.jsx(Xe,{className:e}):i.jsx(Le,{className:e})},Ie=150,bt=40,wt=120,xt=3,yt=`
1
+ import{a as fe,p as N,j as i,aE as Le,c4 as ke,c3 as De,aJ as We,bx as qe,cc as Se,bO as Be,bz as _e,K as Ge,aQ as Ke,aI as Me,c7 as Ze,D as Ye,c8 as Je,cd as Qe,aH as Xe,c2 as et,$ as Ae,aT as tt,r as nt,a0 as Fe,aq as it}from"./vendor-.bun-Byc0cUD3.js";import{c as ue,D as st,t as ye,g as ze,f as rt,r as ot,a as at,b as lt,d as ct,S as Oe,e as dt,u as ut,h as Pe,p as ft,i as Re,V as mt,j as pt,k as ht}from"./main-BPzHzdLz.js";import"./index-BcefsbYU.js";const gt=n=>{const e="h-3.5 w-3.5 flex-shrink-0",t=n.toLowerCase();return t==="reasoning"?i.jsx(We,{className:e}):t==="image-preview"?i.jsx(qe,{className:e}):t==="mermaid-preview"?i.jsx(Se,{className:e}):t==="edit"||t==="multiedit"||t==="apply_patch"||t==="str_replace"||t==="str_replace_based_edit_tool"?i.jsx(Be,{className:e}):t==="write"||t==="create"||t==="file_write"?i.jsx(_e,{className:e}):t==="read"||t==="view"||t==="file_read"||t==="cat"?i.jsx(_e,{className:e}):t==="bash"||t==="shell"||t==="cmd"||t==="terminal"?i.jsx(Ge,{className:e}):t==="list"||t==="ls"||t==="dir"||t==="list_files"?i.jsx(Ke,{className:e}):t==="search"||t==="grep"||t==="find"||t==="ripgrep"?i.jsx(Me,{className:e}):t==="glob"?i.jsx(Ze,{className:e}):t==="fetch"||t==="curl"||t==="wget"||t==="webfetch"?i.jsx(Ye,{className:e}):t==="web-search"||t==="websearch"||t==="search_web"||t==="google"||t==="bing"||t==="duckduckgo"?i.jsx(Me,{className:e}):t==="todowrite"||t==="todoread"?i.jsx(Je,{className:e}):t==="plan_enter"?i.jsx(Se,{className:e}):t==="plan_exit"?i.jsx(Qe,{className:e}):t.startsWith("git")?i.jsx(Xe,{className:e}):i.jsx(Le,{className:e})},Ie=150,bt=40,wt=120,xt=3,yt=`
2
2
  [data-diff-header],
3
3
  [data-diff] {
4
4
  [data-separator] {
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-Byc0cUD3.js","assets/vendor--DbVqbJpV.css","assets/main-DKLlKgOa.js","assets/main-BV3KOtdA.css"])))=>i.map(i=>d[i]);
2
- import{_ as G}from"./vendor-.bun-Byc0cUD3.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))o(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const l of s.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&o(l)}).observe(document,{childList:!0,subtree:!0});function r(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function o(n){if(n.ep)return;n.ep=!0;const s=r(n);fetch(n.href,s)}})();const W=1,S=1,M="/api/terminal/input-ws",B=1200,q=1e3,z=3e4,K=250,H=2e4,Y=5e3,P="__openchamberTerminalInputWsState",V=new TextEncoder,X=new TextDecoder,D=e=>{if(/^wss?:\/\//i.test(e))return e;if(/^https?:\/\//i.test(e)){const o=new URL(e);return o.protocol=o.protocol==="https:"?"wss:":"ws:",o.toString()}if(typeof window>"u")return"";const t=e.startsWith("/")?e:`/${e}`;return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${t}`},x=e=>{const t=V.encode(JSON.stringify(e)),r=new Uint8Array(t.length+1);return r[0]=W,r.set(t,1),r},J=e=>e?((e.transports??[]).includes("ws")||e.preferred==="ws")&&typeof e.ws?.path=="string"&&e.ws.path.length>0:!1;class L{socket=null;socketUrl="";boundSessionId=null;openPromise=null;reconnectTimeout=null;reconnectAttempt=0;keepaliveInterval=null;closed=!1;configure(t){if(t){if(this.socketUrl===t){if(this.closed=!1,this.isConnectedOrConnecting())return;this.ensureConnected();return}this.socketUrl=t,this.closed=!1,this.resetConnection(),this.ensureConnected()}}async sendInput(t,r){if(!t||!r||this.closed||!this.socketUrl)return!1;const o=await this.getOpenSocket(B);if(!o||o.readyState!==S)return!1;try{return this.boundSessionId!==t&&(o.send(x({t:"b",s:t,v:1})),this.boundSessionId=t),o.send(r),!0}catch{return this.handleSocketFailure(),!1}}unbindSession(t){t&&this.boundSessionId===t&&(this.boundSessionId=null)}close(){this.closed=!0,this.clearReconnectTimeout(),this.resetConnection(),this.socketUrl=""}prime(){this.closed||!this.socketUrl||this.isConnectedOrConnecting()||this.ensureConnected()}isConnectedOrConnecting(t){return this.closed||t&&this.socketUrl!==t?!1:this.socket&&(this.socket.readyState===WebSocket.OPEN||this.socket.readyState===WebSocket.CONNECTING)?!0:this.openPromise!==null}sendControl(t){if(!this.socket||this.socket.readyState!==S)return!1;try{return this.socket.send(x(t)),!0}catch{return this.handleSocketFailure(),!1}}startKeepalive(){this.stopKeepalive(),this.keepaliveInterval=setInterval(()=>{this.closed||this.sendControl({t:"p",v:1})},H)}stopKeepalive(){this.keepaliveInterval&&(clearInterval(this.keepaliveInterval),this.keepaliveInterval=null)}scheduleReconnect(){if(this.closed||!this.socketUrl||this.reconnectTimeout)return;const t=Math.min(q*Math.pow(2,this.reconnectAttempt),z),r=Math.floor(Math.random()*K),o=t+r;this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempt+=1,this.ensureConnected()},o)}clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}async getOpenSocket(t){if(this.socket&&this.socket.readyState===S)return this.socket;if(this.ensureConnected(),this.socket&&this.socket.readyState===S)return this.socket;const r=await Promise.race([this.openPromise??Promise.resolve(null),new Promise(o=>{setTimeout(()=>o(null),t)})]);return r&&r.readyState===S?r:this.socket&&this.socket.readyState===S?this.socket:null}ensureConnected(){this.closed||!this.socketUrl||this.socket&&(this.socket.readyState===WebSocket.OPEN||this.socket.readyState===WebSocket.CONNECTING)||this.openPromise||(this.clearReconnectTimeout(),this.openPromise=new Promise(t=>{let r=!1,o=null;const n=s=>{r||(r=!0,o&&(clearTimeout(o),o=null),this.openPromise=null,t(s))};try{const s=new WebSocket(this.socketUrl);s.binaryType="arraybuffer",s.onopen=()=>{this.socket=s,this.reconnectAttempt=0,this.startKeepalive(),n(s)},s.onmessage=l=>{this.handleSocketMessage(l.data)},s.onclose=()=>{this.socket===s&&(this.socket=null,this.boundSessionId=null,this.stopKeepalive(),this.closed||this.scheduleReconnect()),n(null)},this.socket=s,o=setTimeout(()=>{s.readyState===WebSocket.CONNECTING&&(s.close(),n(null))},Y)}catch{n(null),this.closed||this.scheduleReconnect()}}))}async handleSocketMessage(t){const r=await this.asUint8Array(t);if(!(!r||r.length<2)&&r[0]===W)try{const o=JSON.parse(X.decode(r.subarray(1)));if(o.t==="po")return;o.t==="e"&&((o.c==="NOT_BOUND"||o.c==="SESSION_NOT_FOUND")&&(this.boundSessionId=null),o.f===!0&&this.handleSocketFailure())}catch{this.handleSocketFailure()}}async asUint8Array(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);if(t instanceof Uint8Array)return t;if(typeof Blob<"u"&&t instanceof Blob){const r=await t.arrayBuffer();return new Uint8Array(r)}return null}handleSocketFailure(){this.boundSessionId=null,this.resetConnection(),this.scheduleReconnect()}resetConnection(){if(this.openPromise=null,this.stopKeepalive(),this.socket){const t=this.socket;this.socket=null,t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close()}this.boundSessionId=null}}const g=()=>{const e=globalThis;return e[P]||(e[P]={capability:null,manager:null}),e[P]},U=e=>{const t=g();if(t.capability=e??null,!J(t.capability)){t.manager?.close(),t.manager=null;return}const r=t.capability?.ws?.path;if(!r)return;const o=D(r);o&&(t.manager||(t.manager=new L),t.manager.configure(o))},Q=async(e,t)=>{const r=await fetch(`/api/terminal/${e}/input`,{method:"POST",headers:{"Content-Type":"text/plain"},body:t});if(!r.ok){const o=await r.json().catch(()=>({error:"Failed to send input"}));throw new Error(o.error||"Failed to send terminal input")}};async function Z(e){const t=await fetch("/api/terminal/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e.cwd,cols:e.cols||80,rows:e.rows||24})});if(!t.ok){const o=await t.json().catch(()=>({error:"Failed to create terminal"}));throw new Error(o.error||"Failed to create terminal session")}const r=await t.json();return U(r.capabilities?.input),r}function tt(e,t,r,o={}){const{maxRetries:n=3,initialRetryDelay:s=1e3,maxRetryDelay:l=8e3,connectionTimeout:p=1e4}=o;let c=null,d=0,w=null,u=null,y=!1,T=!1,b=!1;const j=()=>{w&&(clearTimeout(w),w=null),u&&(clearTimeout(u),u=null)},O=()=>{y=!0,j(),c&&(c.close(),c=null)},C=()=>{if(!(y||b)){if(c&&c.readyState!==EventSource.CLOSED){console.warn("Attempted to create duplicate EventSource, skipping");return}T=!1,c=new EventSource(`/api/terminal/${e}/stream`),u=setTimeout(()=>{!T&&c?.readyState!==EventSource.OPEN&&(console.error("Terminal connection timeout"),c?.close(),N(new Error("Connection timeout"),!1))},p),c.onopen=()=>{T||(T=!0,d=0,j(),t({type:"connected"}))},c.onmessage=E=>{try{const m=JSON.parse(E.data);m.type==="exit"&&(g().manager?.unbindSession(e),b=!0,O()),t(m)}catch(m){console.error("Failed to parse terminal event:",m),r?.(m,!1)}},c.onerror=E=>{console.error("Terminal stream error:",E,"readyState:",c?.readyState),j();const m=b||c?.readyState===EventSource.CLOSED;c?.close(),c=null,b||N(new Error("Terminal stream connection error"),m)}}},N=(E,m)=>{if(!(y||b))if(d<n&&!m){d++;const F=Math.min(s*Math.pow(2,d-1),l);console.log(`Reconnecting to terminal stream (attempt ${d}/${n}) in ${F}ms`),t({type:"reconnecting",attempt:d,maxAttempts:n}),w=setTimeout(()=>{!y&&!b&&C()},F)}else console.error(`Terminal connection failed after ${d} attempts`),r?.(E,!0),O()};return C(),O}async function et(e,t){const r=g();r.manager&&await r.manager.sendInput(e,t)||await Q(e,t)}async function rt(e,t,r){const o=await fetch(`/api/terminal/${e}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:t,rows:r})});if(!o.ok){const n=await o.json().catch(()=>({error:"Failed to resize terminal"}));throw new Error(n.error||"Failed to resize terminal")}}async function ot(e){g().manager?.unbindSession(e);const t=await fetch(`/api/terminal/${e}`,{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({error:"Failed to close terminal"}));throw new Error(r.error||"Failed to close terminal")}}async function nt(e,t){g().manager?.unbindSession(e);const r=await fetch(`/api/terminal/${e}/restart`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd,cols:t.cols??80,rows:t.rows??24})});if(!r.ok){const n=await r.json().catch(()=>({error:"Failed to restart terminal"}));throw new Error(n.error||"Failed to restart terminal")}const o=await r.json();return U(o.capabilities?.input),o}async function st(e){const t=await fetch("/api/terminal/force-kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const r=await t.json().catch(()=>({error:"Failed to force kill terminal"}));throw new Error(r.error||"Failed to force kill terminal")}e.sessionId&&g().manager?.unbindSession(e.sessionId)}function ae(){const e=g();if(e.capability&&!J(e.capability))return;const t=e.capability?.ws?.path??M,r=D(t);r&&(e.manager||(e.manager=new L),!e.manager.isConnectedOrConnecting(r)&&(e.manager.configure(r),e.manager.prime()))}const it=e=>{const t=e?.retry;return{maxRetries:t?.maxRetries??3,initialRetryDelay:t?.initialDelayMs??1e3,maxRetryDelay:t?.maxDelayMs??8e3,connectionTimeout:e?.connectionTimeoutMs??1e4}},at=()=>({async createSession(e){return Z(e)},connect(e,t,r){const o=tt(e,t.onEvent,t.onError,it(r));return{close:()=>o()}},async sendInput(e,t){await et(e,t)},async resize(e){await rt(e.sessionId,e.cols,e.rows)},async close(e){await ot(e)},async restartSession(e,t){return nt(e,{cwd:t.cwd??"",cols:t.cols,rows:t.rows})},async forceKill(e){await st(e)}}),ct=()=>{if(typeof window>"u")return"";const e=window.__OPENCHAMBER_DESKTOP_SERVER__?.origin;return e||window.location.origin},i="/api/git";function a(e,t,r){const o=new URL(e,ct());if(t&&o.searchParams.set("directory",t),r)for(const[n,s]of Object.entries(r))s!==void 0&&o.searchParams.set(n,String(s));return o.toString()}async function lt(e){const t=await fetch(a(`${i}/check`,e));if(!t.ok)throw new Error(`Failed to check git repository: ${t.statusText}`);return(await t.json()).isGitRepository}async function ut(e){const t=await fetch(a(`${i}/status`,e));if(!t.ok)throw new Error(`Failed to get git status: ${t.statusText}`);return t.json()}async function dt(e,t){const{path:r,staged:o,contextLines:n}=t;if(!r)throw new Error("path is required to fetch git diff");const s=await fetch(a(`${i}/diff`,e,{path:r,staged:o?"true":void 0,context:n}));if(!s.ok)throw new Error(`Failed to get git diff: ${s.statusText}`);return s.json()}async function ht(e,t){const{path:r,staged:o}=t;if(!r)throw new Error("path is required to fetch git file diff");const n=await fetch(a(`${i}/file-diff`,e,{path:r,staged:o?"true":void 0}));if(!n.ok)throw new Error(`Failed to get git file diff: ${n.statusText}`);return n.json()}async function ft(e,t){if(!t)throw new Error("path is required to revert git changes");const r=await fetch(a(`${i}/revert`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to revert git changes")}}async function pt(e){if(!e)return!1;const t=await fetch(a(`${i}/worktree-type`,e));if(!t.ok)throw new Error(`Failed to detect worktree type: ${t.statusText}`);return!!(await t.json()).linked}async function wt(e){const t=await fetch(a(`${i}/branches`,e));if(!t.ok)throw new Error(`Failed to get branches: ${t.statusText}`);return t.json()}async function yt(e,t){if(!t?.branch)throw new Error("branch is required to delete a branch");const r=await fetch(a(`${i}/branches`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete branch")}return r.json()}async function mt(e,t){if(!t?.branch)throw new Error("branch is required to delete remote branch");const r=await fetch(a(`${i}/remote-branches`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete remote branch")}return r.json()}async function gt(e,t,r){if(!Array.isArray(t)||t.length===0)throw new Error("No files provided to generate commit message");const o={files:t};r?.zenModel&&(o.zenModel=r.zenModel),r?.providerId&&(o.providerId=r.providerId),r?.modelId&&(o.modelId=r.modelId);const n=await fetch(a(`${i}/commit-message`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!n.ok){const c=await n.json().catch(()=>({error:n.statusText}));console.error("[git-generation][browser] http error",{status:n.status,statusText:n.statusText,error:c});const d=typeof c?.traceId=="string"&&c.traceId?` (traceId: ${c.traceId})`:"";throw new Error(`${c.error||"Failed to generate commit message"}${d}`)}const s=await n.json();if(!s?.message||typeof s.message!="object")throw new Error("Malformed commit generation response");const l=typeof s.message.subject=="string"&&s.message.subject.trim().length>0?s.message.subject.trim():"",p=Array.isArray(s.message.highlights)?s.message.highlights.filter(c=>typeof c=="string"&&c.trim().length>0).map(c=>c.trim()):[];return{message:{subject:l,highlights:p}}}async function Tt(e,t){const{base:r,head:o,context:n,zenModel:s,providerId:l,modelId:p}=t;if(!r||!o)throw new Error("base and head are required");const c={base:r,head:o};n?.trim()&&(c.context=n.trim()),s&&(c.zenModel=s),l&&(c.providerId=l),p&&(c.modelId=p);const d=await fetch(a(`${i}/pr-description`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok){const T=await d.json().catch(()=>({error:d.statusText}));throw new Error(T.error||"Failed to generate PR description")}const w=await d.json().catch(()=>null),u=typeof w?.title=="string"?w.title:"",y=typeof w?.body=="string"?w.body:"";if(!u&&!y)throw new Error("Malformed PR description response");return{title:u,body:y}}async function I(e){const t=await fetch(a(`${i}/worktrees`,e));if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to list worktrees")}return t.json()}async function v(e,t){const r=await fetch(a(`${i}/worktrees/validate`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to validate worktree")}return r.json()}async function $(e,t){const r=await fetch(a(`${i}/worktrees`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to create worktree")}return r.json()}async function A(e,t){const r=await fetch(a(`${i}/worktrees`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete worktree")}return r.json()}async function bt(e,t,r={}){const o=await fetch(a(`${i}/commit`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,addAll:r.addAll??!1,files:r.files})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to create commit")}return o.json()}async function St(e,t={}){const r=await fetch(a(`${i}/push`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to push")}return r.json()}async function Et(e,t={}){const r=await fetch(a(`${i}/pull`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to pull")}return r.json()}async function kt(e,t={}){const r=await fetch(a(`${i}/fetch`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to fetch")}return r.json()}async function jt(e,t){const r=await fetch(a(`${i}/checkout`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to checkout branch")}return r.json()}async function Ot(e,t,r){const o=await fetch(a(`${i}/branches`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,startPoint:r})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to create branch")}return o.json()}async function Pt(e,t,r){const o=await fetch(a(`${i}/branches/rename`,e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldName:t,newName:r})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to rename branch")}return o.json()}async function Ct(e,t={}){const r=await fetch(a(`${i}/log`,e,{maxCount:t.maxCount,from:t.from,to:t.to,file:t.file}));if(!r.ok)throw new Error(`Failed to get git log: ${r.statusText}`);return r.json()}async function Nt(e,t){const r=await fetch(a(`${i}/commit-files`,e,{hash:t}));if(!r.ok)throw new Error(`Failed to get commit files: ${r.statusText}`);return r.json()}async function Ft(){const e=await fetch(a(`${i}/identities`,void 0));if(!e.ok)throw new Error(`Failed to get git identities: ${e.statusText}`);return e.json()}async function xt(e){const t=await fetch(a(`${i}/identities`,void 0),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to create git identity")}return t.json()}async function It(e,t){const r=await fetch(a(`${i}/identities/${e}`,void 0),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to update git identity")}return r.json()}async function vt(e){const t=await fetch(a(`${i}/identities/${e}`,void 0),{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to delete git identity")}}async function $t(e){if(!e)return null;const t=await fetch(a(`${i}/current-identity`,e));if(!t.ok)throw new Error(`Failed to get current git identity: ${t.statusText}`);const r=await t.json();return r?{userName:r.userName??null,userEmail:r.userEmail??null,sshCommand:r.sshCommand??null}:null}async function At(e){if(!e)return!1;const t=await fetch(a(`${i}/has-local-identity`,e));if(!t.ok)throw new Error(`Failed to check local identity: ${t.statusText}`);return(await t.json().catch(()=>null))?.hasLocalIdentity===!0}async function ce(){const e=await fetch(a(`${i}/global-identity`,void 0));if(!e.ok)throw new Error(`Failed to get global git identity: ${e.statusText}`);const t=await e.json();return!t||!t.userName&&!t.userEmail?null:{userName:t.userName??null,userEmail:t.userEmail??null,sshCommand:t.sshCommand??null}}async function Rt(e,t){const r=await fetch(a(`${i}/set-identity`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to set git identity")}return r.json()}async function le(){const e=await fetch(a(`${i}/discover-credentials`,void 0));if(!e.ok)throw new Error(`Failed to discover git credentials: ${e.statusText}`);return e.json()}async function _t(e){const t=await fetch(a(`${i}/remotes`,e));if(!t.ok)throw new Error(`Failed to get remotes: ${t.statusText}`);return t.json()}async function Gt(e,t){const r=await fetch(a(`${i}/rebase`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to rebase")}return r.json()}async function Wt(e){const t=await fetch(a(`${i}/rebase/abort`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to abort rebase")}return t.json()}async function Dt(e,t){const r=await fetch(a(`${i}/merge`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to merge")}return r.json()}async function Jt(e){const t=await fetch(a(`${i}/merge/abort`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to abort merge")}return t.json()}async function Lt(e){const t=await fetch(a(`${i}/rebase/continue`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to continue rebase")}return t.json()}async function Ut(e){const t=await fetch(a(`${i}/merge/continue`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to continue merge")}return t.json()}async function Mt(e,t){const r=await fetch(a(`${i}/stash`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to stash")}return r.json()}async function Bt(e){const t=await fetch(a(`${i}/stash/pop`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to pop stash")}return t.json()}async function qt(e){const t=await fetch(a(`${i}/conflict-details`,e));if(!t.ok)throw new Error(`Failed to get conflict details: ${t.statusText}`);return t.json()}const zt=()=>({checkIsGitRepository:lt,getGitStatus:ut,getGitDiff:dt,getGitFileDiff:ht,revertGitFile:ft,isLinkedWorktree:pt,getGitBranches:wt,deleteGitBranch:yt,deleteRemoteBranch:mt,generateCommitMessage:gt,generatePullRequestDescription:Tt,listGitWorktrees:I,validateGitWorktree:v,createGitWorktree:$,deleteGitWorktree:A,createGitCommit(e,t,r){return bt(e,t,r)},gitPush:St,gitPull:Et,gitFetch:kt,checkoutBranch:jt,createBranch:Ot,renameBranch:Pt,getGitLog(e,t){return Ct(e,t)},getCommitFiles:Nt,getCurrentGitIdentity:$t,hasLocalIdentity:At,setGitIdentity:Rt,getGitIdentities:Ft,createGitIdentity:xt,updateGitIdentity:It,deleteGitIdentity:vt,getRemotes:_t,rebase:Gt,abortRebase:Wt,continueRebase:Lt,merge:Dt,abortMerge:Jt,continueMerge:Ut,stash:Mt,stashPop:Bt,getConflictDetails:qt,worktree:{list:I,validate:v,create:$,remove:A}}),f=e=>e.replace(/\\/g,"/"),Kt=(e,t)=>{const r=f(t?.directory||t?.path||e),o=Array.isArray(t?.entries)?t.entries:[];return{directory:r,entries:o.filter(n=>!!(n&&typeof n.name=="string"&&typeof n.path=="string")).map(n=>({name:n.name,path:f(n.path),isDirectory:!!n.isDirectory}))}},Ht=()=>({async listDirectory(e){const t=f(e),r=new URLSearchParams;t&&r.set("path",t);const o=await fetch(`/api/fs/list${r.toString()?`?${r.toString()}`:""}`);if(!o.ok){const s=await o.json().catch(()=>({error:o.statusText}));throw new Error(s.error||"Failed to list directory")}const n=await o.json();return Kt(t,n)},async search(e){const t=new URLSearchParams,r=f(e.directory);r&&t.set("directory",r),t.set("q",e.query),typeof e.maxResults=="number"&&Number.isFinite(e.maxResults)&&t.set("limit",String(e.maxResults)),e.includeHidden&&t.set("includeHidden","true");const o=await fetch(`/api/fs/search?${t.toString()}`);if(!o.ok){const l=await o.json().catch(()=>({error:o.statusText}));throw new Error(l.error||"Failed to search files")}const n=await o.json();return(Array.isArray(n?.files)?n.files:[]).filter(l=>!!(l&&typeof l.path=="string")).map(l=>({path:f(l.path),preview:typeof l.relativePath=="string"&&l.relativePath.length>0?[f(l.relativePath)]:void 0}))},async createDirectory(e){const t=f(e),r=await fetch("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to create directory")}const o=await r.json();return{success:!!o?.success,path:typeof o?.path=="string"?f(o.path):t}},async readFile(e){const t=f(e),r=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}`);if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to read file")}return{content:await r.text(),path:t}},async writeFile(e,t){const r=f(e),o=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r,content:t})});if(!o.ok){const s=await o.json().catch(()=>({error:o.statusText}));throw new Error(s.error||"Failed to write file")}const n=await o.json().catch(()=>({}));return{success:!!n.success,path:typeof n.path=="string"?f(n.path):r}},async delete(e){const t=f(e),r=await fetch("/api/fs/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to delete file")}return{success:!!(await r.json().catch(()=>({}))).success}},async rename(e,t){const r=await fetch("/api/fs/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:e,newPath:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to rename file")}const o=await r.json().catch(()=>({}));return{success:!!o.success,path:typeof o.path=="string"?f(o.path):t}},async revealPath(e){const t=await fetch("/api/fs/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:f(e)})});if(!t.ok){const o=await t.json().catch(()=>({error:t.statusText}));throw new Error(o.error||"Failed to reveal path")}return{success:!!(await t.json().catch(()=>({}))).success}}}),R="/api/config/settings",Yt="/api/config/reload",_=e=>!e||typeof e!="object"?{}:e,Vt=()=>({async load(){const e=await fetch(R,{method:"GET",headers:{Accept:"application/json"}});if(!e.ok)throw new Error(`Failed to load settings: ${e.statusText}`);return{settings:_(await e.json().catch(()=>({}))),source:"web"}},async save(e){const t=await fetch(R,{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)});if(!t.ok){const o=await t.json().catch(()=>({error:t.statusText}));throw new Error(o.error||"Failed to save settings")}return _(await t.json().catch(()=>({})))},async restartOpenCode(){const e=await fetch(Yt,{method:"POST"});if(!e.ok){const t=await e.json().catch(()=>({error:e.statusText}));throw new Error(t.error||"Failed to restart OpenCode")}return{restarted:!0}}}),Xt=()=>({async requestDirectoryAccess(e){return{success:!0,path:e.path}},async startAccessingDirectory(e){return{success:!0}},async stopAccessingDirectory(e){return{success:!0}}}),Qt=async e=>{if(typeof Notification>"u")return console.info("Notifications not supported in this environment",e),!1;if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted"||Notification.permission!=="granted")return console.warn("Notification permission not granted"),!1;try{return new Notification(e?.title??"OpenChamber",{body:e?.body,tag:e?.tag}),!0}catch(t){return console.warn("Failed to send notification",t),!1}},Zt=async e=>{if(typeof window>"u")return!1;const t=window.__TAURI__;if(!t?.core?.invoke)return!1;try{return await t.core.invoke("desktop_notify",{payload:{title:e?.title,body:e?.body,tag:e?.tag}}),!0}catch(r){return console.warn("Failed to send native notification (tauri)",r),!1}},te=()=>({async notifyAgentCompletion(e){return await Zt(e)||Qt(e)},canNotify:()=>typeof window<"u"&&window.__TAURI__?.core?.invoke?!0:typeof Notification<"u"?Notification.permission==="granted":!1}),ee=()=>({async getAvailableTools(){const e=await fetch("/api/experimental/tool/ids");if(!e.ok)throw new Error(`Tools API returned ${e.status} ${e.statusText}`);const t=await e.json();if(!Array.isArray(t))throw new Error("Tools API returned invalid data format");return t.filter(r=>typeof r=="string"&&r!=="invalid").sort()}}),k=async(e,t)=>{try{const r=await fetch(e,{...t,credentials:"include",headers:{Accept:"application/json",...t?.headers??{}}});return r.ok?await r.json():null}catch{return null}},re=()=>({async getVapidPublicKey(){return k("/api/push/vapid-public-key")},async subscribe(e){return k("/api/push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},async unsubscribe(e){return k("/api/push/subscribe",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},async setVisibility(e){return k("/api/push/visibility",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0})}}),h=async e=>await e.json().catch(()=>null),oe=()=>({async authStatus(){const e=await fetch("/api/github/auth/status",{method:"GET",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok||!t)throw new Error(t?.error||e.statusText||"Failed to load GitHub status");return t},async authStart(){const e=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),t=await h(e);if(!e.ok||!t||!("deviceCode"in t))throw new Error(t?.error||e.statusText||"Failed to start GitHub auth");return t},async authComplete(e){const t=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:e})}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to complete GitHub auth");return r},async authDisconnect(){const e=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok)throw new Error(t?.error||e.statusText||"Failed to disconnect GitHub");return{removed:!!t?.removed}},async authActivate(e){const t=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:e})}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to activate GitHub account");return r},async me(){const e=await fetch("/api/github/me",{method:"GET",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok||!t)throw new Error(t?.error||e.statusText||"Failed to fetch GitHub user");return t},async prStatus(e,t,r){const o=new URLSearchParams({directory:e,branch:t,...r?{remote:r}:{}}),n=await fetch(`/api/github/pr/status?${o.toString()}`,{method:"GET",headers:{Accept:"application/json"}}),s=await h(n);if(!n.ok||!s)throw new Error(s?.error||n.statusText||"Failed to load PR status");return s},async prCreate(e){const t=await fetch("/api/github/pr/create",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to create PR");return r},async prUpdate(e){const t=await fetch("/api/github/pr/update",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to update PR");return r},async prMerge(e){const t=await fetch("/api/github/pr/merge",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to merge PR");return r},async prReady(e){const t=await fetch("/api/github/pr/ready",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to mark PR ready");return r},async prsList(e,t){const r=t?.page??1,o=await fetch(`/api/github/pulls/list?directory=${encodeURIComponent(e)}&page=${encodeURIComponent(String(r))}`,{method:"GET",headers:{Accept:"application/json"}}),n=await h(o);if(!o.ok||!n)throw new Error(n?.error||o.statusText||"Failed to load pull requests");return n},async prContext(e,t,r){const o=new URL("/api/github/pulls/context",window.location.origin);o.searchParams.set("directory",e),o.searchParams.set("number",String(t)),r?.includeDiff&&o.searchParams.set("diff","1"),r?.includeCheckDetails&&o.searchParams.set("checkDetails","1");const n=await fetch(o.toString(),{method:"GET",headers:{Accept:"application/json"}}),s=await h(n);if(!n.ok||!s)throw new Error(s?.error||n.statusText||"Failed to load pull request context");return s},async issuesList(e,t){const r=t?.page??1,o=await fetch(`/api/github/issues/list?directory=${encodeURIComponent(e)}&page=${encodeURIComponent(String(r))}`,{method:"GET",headers:{Accept:"application/json"}}),n=await h(o);if(!o.ok||!n)throw new Error(n?.error||o.statusText||"Failed to load issues");return n},async issueGet(e,t){const r=await fetch(`/api/github/issues/get?directory=${encodeURIComponent(e)}&number=${encodeURIComponent(String(t))}`,{method:"GET",headers:{Accept:"application/json"}}),o=await h(r);if(!r.ok||!o)throw new Error(o?.error||r.statusText||"Failed to load issue");return o},async issueComments(e,t){const r=await fetch(`/api/github/issues/comments?directory=${encodeURIComponent(e)}&number=${encodeURIComponent(String(t))}`,{method:"GET",headers:{Accept:"application/json"}}),o=await h(r);if(!r.ok||!o)throw new Error(o?.error||r.statusText||"Failed to load issue comments");return o}}),ne=()=>({runtime:{platform:"web",isDesktop:!1,isVSCode:!1,label:"web"},terminal:at(),git:zt(),files:Ht(),settings:Vt(),permissions:Xt(),notifications:te(),github:oe(),push:re(),tools:ee()});function se(e={}){const{immediate:t=!1,onNeedRefresh:r,onOfflineReady:o,onRegistered:n,onRegisteredSW:s,onRegisterError:l}=e;let p,c;const d=async(u=!0)=>{await c};async function w(){if("serviceWorker"in navigator){if(p=await G(async()=>{const{Workbox:u}=await import("./vendor-.bun-Byc0cUD3.js").then(y=>y.eK);return{Workbox:u}},__vite__mapDeps([0,1])).then(({Workbox:u})=>new u("/sw.js",{scope:"/",type:"classic"})).catch(u=>{l?.(u)}),!p)return;p.addEventListener("activated",u=>{(u.isUpdate||u.isExternal)&&window.location.reload()}),p.addEventListener("installed",u=>{u.isUpdate||o?.()}),p.register({immediate:t}).then(u=>{s?s("/sw.js",u):n?.(u)}).catch(u=>{l?.(u)})}}return c=w(),d}window.__OPENCHAMBER_RUNTIME_APIS__=ne();se({onRegisterError(e){console.warn("[PWA] service worker registration failed:",e)}});G(()=>import("./main-DKLlKgOa.js").then(e=>e.m),__vite__mapDeps([2,0,1,3]));export{$ as a,mt as b,lt as c,A as d,vt as e,xt as f,ut as g,le as h,ce as i,Ft as j,wt as k,I as l,_t as m,yt as n,Ct as o,Nt as p,qt as q,Pt as r,ot as s,ae as t,It as u,v};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-Byc0cUD3.js","assets/vendor--DbVqbJpV.css","assets/main-BPzHzdLz.js","assets/main-BV3KOtdA.css"])))=>i.map(i=>d[i]);
2
+ import{_ as G}from"./vendor-.bun-Byc0cUD3.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))o(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const l of s.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&o(l)}).observe(document,{childList:!0,subtree:!0});function r(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function o(n){if(n.ep)return;n.ep=!0;const s=r(n);fetch(n.href,s)}})();const W=1,S=1,M="/api/terminal/input-ws",B=1200,q=1e3,z=3e4,K=250,H=2e4,Y=5e3,P="__openchamberTerminalInputWsState",V=new TextEncoder,X=new TextDecoder,D=e=>{if(/^wss?:\/\//i.test(e))return e;if(/^https?:\/\//i.test(e)){const o=new URL(e);return o.protocol=o.protocol==="https:"?"wss:":"ws:",o.toString()}if(typeof window>"u")return"";const t=e.startsWith("/")?e:`/${e}`;return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${t}`},x=e=>{const t=V.encode(JSON.stringify(e)),r=new Uint8Array(t.length+1);return r[0]=W,r.set(t,1),r},J=e=>e?((e.transports??[]).includes("ws")||e.preferred==="ws")&&typeof e.ws?.path=="string"&&e.ws.path.length>0:!1;class L{socket=null;socketUrl="";boundSessionId=null;openPromise=null;reconnectTimeout=null;reconnectAttempt=0;keepaliveInterval=null;closed=!1;configure(t){if(t){if(this.socketUrl===t){if(this.closed=!1,this.isConnectedOrConnecting())return;this.ensureConnected();return}this.socketUrl=t,this.closed=!1,this.resetConnection(),this.ensureConnected()}}async sendInput(t,r){if(!t||!r||this.closed||!this.socketUrl)return!1;const o=await this.getOpenSocket(B);if(!o||o.readyState!==S)return!1;try{return this.boundSessionId!==t&&(o.send(x({t:"b",s:t,v:1})),this.boundSessionId=t),o.send(r),!0}catch{return this.handleSocketFailure(),!1}}unbindSession(t){t&&this.boundSessionId===t&&(this.boundSessionId=null)}close(){this.closed=!0,this.clearReconnectTimeout(),this.resetConnection(),this.socketUrl=""}prime(){this.closed||!this.socketUrl||this.isConnectedOrConnecting()||this.ensureConnected()}isConnectedOrConnecting(t){return this.closed||t&&this.socketUrl!==t?!1:this.socket&&(this.socket.readyState===WebSocket.OPEN||this.socket.readyState===WebSocket.CONNECTING)?!0:this.openPromise!==null}sendControl(t){if(!this.socket||this.socket.readyState!==S)return!1;try{return this.socket.send(x(t)),!0}catch{return this.handleSocketFailure(),!1}}startKeepalive(){this.stopKeepalive(),this.keepaliveInterval=setInterval(()=>{this.closed||this.sendControl({t:"p",v:1})},H)}stopKeepalive(){this.keepaliveInterval&&(clearInterval(this.keepaliveInterval),this.keepaliveInterval=null)}scheduleReconnect(){if(this.closed||!this.socketUrl||this.reconnectTimeout)return;const t=Math.min(q*Math.pow(2,this.reconnectAttempt),z),r=Math.floor(Math.random()*K),o=t+r;this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempt+=1,this.ensureConnected()},o)}clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}async getOpenSocket(t){if(this.socket&&this.socket.readyState===S)return this.socket;if(this.ensureConnected(),this.socket&&this.socket.readyState===S)return this.socket;const r=await Promise.race([this.openPromise??Promise.resolve(null),new Promise(o=>{setTimeout(()=>o(null),t)})]);return r&&r.readyState===S?r:this.socket&&this.socket.readyState===S?this.socket:null}ensureConnected(){this.closed||!this.socketUrl||this.socket&&(this.socket.readyState===WebSocket.OPEN||this.socket.readyState===WebSocket.CONNECTING)||this.openPromise||(this.clearReconnectTimeout(),this.openPromise=new Promise(t=>{let r=!1,o=null;const n=s=>{r||(r=!0,o&&(clearTimeout(o),o=null),this.openPromise=null,t(s))};try{const s=new WebSocket(this.socketUrl);s.binaryType="arraybuffer",s.onopen=()=>{this.socket=s,this.reconnectAttempt=0,this.startKeepalive(),n(s)},s.onmessage=l=>{this.handleSocketMessage(l.data)},s.onclose=()=>{this.socket===s&&(this.socket=null,this.boundSessionId=null,this.stopKeepalive(),this.closed||this.scheduleReconnect()),n(null)},this.socket=s,o=setTimeout(()=>{s.readyState===WebSocket.CONNECTING&&(s.close(),n(null))},Y)}catch{n(null),this.closed||this.scheduleReconnect()}}))}async handleSocketMessage(t){const r=await this.asUint8Array(t);if(!(!r||r.length<2)&&r[0]===W)try{const o=JSON.parse(X.decode(r.subarray(1)));if(o.t==="po")return;o.t==="e"&&((o.c==="NOT_BOUND"||o.c==="SESSION_NOT_FOUND")&&(this.boundSessionId=null),o.f===!0&&this.handleSocketFailure())}catch{this.handleSocketFailure()}}async asUint8Array(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);if(t instanceof Uint8Array)return t;if(typeof Blob<"u"&&t instanceof Blob){const r=await t.arrayBuffer();return new Uint8Array(r)}return null}handleSocketFailure(){this.boundSessionId=null,this.resetConnection(),this.scheduleReconnect()}resetConnection(){if(this.openPromise=null,this.stopKeepalive(),this.socket){const t=this.socket;this.socket=null,t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close()}this.boundSessionId=null}}const g=()=>{const e=globalThis;return e[P]||(e[P]={capability:null,manager:null}),e[P]},U=e=>{const t=g();if(t.capability=e??null,!J(t.capability)){t.manager?.close(),t.manager=null;return}const r=t.capability?.ws?.path;if(!r)return;const o=D(r);o&&(t.manager||(t.manager=new L),t.manager.configure(o))},Q=async(e,t)=>{const r=await fetch(`/api/terminal/${e}/input`,{method:"POST",headers:{"Content-Type":"text/plain"},body:t});if(!r.ok){const o=await r.json().catch(()=>({error:"Failed to send input"}));throw new Error(o.error||"Failed to send terminal input")}};async function Z(e){const t=await fetch("/api/terminal/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e.cwd,cols:e.cols||80,rows:e.rows||24})});if(!t.ok){const o=await t.json().catch(()=>({error:"Failed to create terminal"}));throw new Error(o.error||"Failed to create terminal session")}const r=await t.json();return U(r.capabilities?.input),r}function tt(e,t,r,o={}){const{maxRetries:n=3,initialRetryDelay:s=1e3,maxRetryDelay:l=8e3,connectionTimeout:p=1e4}=o;let c=null,d=0,w=null,u=null,y=!1,T=!1,b=!1;const j=()=>{w&&(clearTimeout(w),w=null),u&&(clearTimeout(u),u=null)},O=()=>{y=!0,j(),c&&(c.close(),c=null)},C=()=>{if(!(y||b)){if(c&&c.readyState!==EventSource.CLOSED){console.warn("Attempted to create duplicate EventSource, skipping");return}T=!1,c=new EventSource(`/api/terminal/${e}/stream`),u=setTimeout(()=>{!T&&c?.readyState!==EventSource.OPEN&&(console.error("Terminal connection timeout"),c?.close(),N(new Error("Connection timeout"),!1))},p),c.onopen=()=>{T||(T=!0,d=0,j(),t({type:"connected"}))},c.onmessage=E=>{try{const m=JSON.parse(E.data);m.type==="exit"&&(g().manager?.unbindSession(e),b=!0,O()),t(m)}catch(m){console.error("Failed to parse terminal event:",m),r?.(m,!1)}},c.onerror=E=>{console.error("Terminal stream error:",E,"readyState:",c?.readyState),j();const m=b||c?.readyState===EventSource.CLOSED;c?.close(),c=null,b||N(new Error("Terminal stream connection error"),m)}}},N=(E,m)=>{if(!(y||b))if(d<n&&!m){d++;const F=Math.min(s*Math.pow(2,d-1),l);console.log(`Reconnecting to terminal stream (attempt ${d}/${n}) in ${F}ms`),t({type:"reconnecting",attempt:d,maxAttempts:n}),w=setTimeout(()=>{!y&&!b&&C()},F)}else console.error(`Terminal connection failed after ${d} attempts`),r?.(E,!0),O()};return C(),O}async function et(e,t){const r=g();r.manager&&await r.manager.sendInput(e,t)||await Q(e,t)}async function rt(e,t,r){const o=await fetch(`/api/terminal/${e}/resize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cols:t,rows:r})});if(!o.ok){const n=await o.json().catch(()=>({error:"Failed to resize terminal"}));throw new Error(n.error||"Failed to resize terminal")}}async function ot(e){g().manager?.unbindSession(e);const t=await fetch(`/api/terminal/${e}`,{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({error:"Failed to close terminal"}));throw new Error(r.error||"Failed to close terminal")}}async function nt(e,t){g().manager?.unbindSession(e);const r=await fetch(`/api/terminal/${e}/restart`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd,cols:t.cols??80,rows:t.rows??24})});if(!r.ok){const n=await r.json().catch(()=>({error:"Failed to restart terminal"}));throw new Error(n.error||"Failed to restart terminal")}const o=await r.json();return U(o.capabilities?.input),o}async function st(e){const t=await fetch("/api/terminal/force-kill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const r=await t.json().catch(()=>({error:"Failed to force kill terminal"}));throw new Error(r.error||"Failed to force kill terminal")}e.sessionId&&g().manager?.unbindSession(e.sessionId)}function ae(){const e=g();if(e.capability&&!J(e.capability))return;const t=e.capability?.ws?.path??M,r=D(t);r&&(e.manager||(e.manager=new L),!e.manager.isConnectedOrConnecting(r)&&(e.manager.configure(r),e.manager.prime()))}const it=e=>{const t=e?.retry;return{maxRetries:t?.maxRetries??3,initialRetryDelay:t?.initialDelayMs??1e3,maxRetryDelay:t?.maxDelayMs??8e3,connectionTimeout:e?.connectionTimeoutMs??1e4}},at=()=>({async createSession(e){return Z(e)},connect(e,t,r){const o=tt(e,t.onEvent,t.onError,it(r));return{close:()=>o()}},async sendInput(e,t){await et(e,t)},async resize(e){await rt(e.sessionId,e.cols,e.rows)},async close(e){await ot(e)},async restartSession(e,t){return nt(e,{cwd:t.cwd??"",cols:t.cols,rows:t.rows})},async forceKill(e){await st(e)}}),ct=()=>{if(typeof window>"u")return"";const e=window.__OPENCHAMBER_DESKTOP_SERVER__?.origin;return e||window.location.origin},i="/api/git";function a(e,t,r){const o=new URL(e,ct());if(t&&o.searchParams.set("directory",t),r)for(const[n,s]of Object.entries(r))s!==void 0&&o.searchParams.set(n,String(s));return o.toString()}async function lt(e){const t=await fetch(a(`${i}/check`,e));if(!t.ok)throw new Error(`Failed to check git repository: ${t.statusText}`);return(await t.json()).isGitRepository}async function ut(e){const t=await fetch(a(`${i}/status`,e));if(!t.ok)throw new Error(`Failed to get git status: ${t.statusText}`);return t.json()}async function dt(e,t){const{path:r,staged:o,contextLines:n}=t;if(!r)throw new Error("path is required to fetch git diff");const s=await fetch(a(`${i}/diff`,e,{path:r,staged:o?"true":void 0,context:n}));if(!s.ok)throw new Error(`Failed to get git diff: ${s.statusText}`);return s.json()}async function ht(e,t){const{path:r,staged:o}=t;if(!r)throw new Error("path is required to fetch git file diff");const n=await fetch(a(`${i}/file-diff`,e,{path:r,staged:o?"true":void 0}));if(!n.ok)throw new Error(`Failed to get git file diff: ${n.statusText}`);return n.json()}async function ft(e,t){if(!t)throw new Error("path is required to revert git changes");const r=await fetch(a(`${i}/revert`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to revert git changes")}}async function pt(e){if(!e)return!1;const t=await fetch(a(`${i}/worktree-type`,e));if(!t.ok)throw new Error(`Failed to detect worktree type: ${t.statusText}`);return!!(await t.json()).linked}async function wt(e){const t=await fetch(a(`${i}/branches`,e));if(!t.ok)throw new Error(`Failed to get branches: ${t.statusText}`);return t.json()}async function yt(e,t){if(!t?.branch)throw new Error("branch is required to delete a branch");const r=await fetch(a(`${i}/branches`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete branch")}return r.json()}async function mt(e,t){if(!t?.branch)throw new Error("branch is required to delete remote branch");const r=await fetch(a(`${i}/remote-branches`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete remote branch")}return r.json()}async function gt(e,t,r){if(!Array.isArray(t)||t.length===0)throw new Error("No files provided to generate commit message");const o={files:t};r?.zenModel&&(o.zenModel=r.zenModel),r?.providerId&&(o.providerId=r.providerId),r?.modelId&&(o.modelId=r.modelId);const n=await fetch(a(`${i}/commit-message`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!n.ok){const c=await n.json().catch(()=>({error:n.statusText}));console.error("[git-generation][browser] http error",{status:n.status,statusText:n.statusText,error:c});const d=typeof c?.traceId=="string"&&c.traceId?` (traceId: ${c.traceId})`:"";throw new Error(`${c.error||"Failed to generate commit message"}${d}`)}const s=await n.json();if(!s?.message||typeof s.message!="object")throw new Error("Malformed commit generation response");const l=typeof s.message.subject=="string"&&s.message.subject.trim().length>0?s.message.subject.trim():"",p=Array.isArray(s.message.highlights)?s.message.highlights.filter(c=>typeof c=="string"&&c.trim().length>0).map(c=>c.trim()):[];return{message:{subject:l,highlights:p}}}async function Tt(e,t){const{base:r,head:o,context:n,zenModel:s,providerId:l,modelId:p}=t;if(!r||!o)throw new Error("base and head are required");const c={base:r,head:o};n?.trim()&&(c.context=n.trim()),s&&(c.zenModel=s),l&&(c.providerId=l),p&&(c.modelId=p);const d=await fetch(a(`${i}/pr-description`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!d.ok){const T=await d.json().catch(()=>({error:d.statusText}));throw new Error(T.error||"Failed to generate PR description")}const w=await d.json().catch(()=>null),u=typeof w?.title=="string"?w.title:"",y=typeof w?.body=="string"?w.body:"";if(!u&&!y)throw new Error("Malformed PR description response");return{title:u,body:y}}async function I(e){const t=await fetch(a(`${i}/worktrees`,e));if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to list worktrees")}return t.json()}async function v(e,t){const r=await fetch(a(`${i}/worktrees/validate`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to validate worktree")}return r.json()}async function $(e,t){const r=await fetch(a(`${i}/worktrees`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to create worktree")}return r.json()}async function A(e,t){const r=await fetch(a(`${i}/worktrees`,e),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(t??{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to delete worktree")}return r.json()}async function bt(e,t,r={}){const o=await fetch(a(`${i}/commit`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:t,addAll:r.addAll??!1,files:r.files})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to create commit")}return o.json()}async function St(e,t={}){const r=await fetch(a(`${i}/push`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to push")}return r.json()}async function Et(e,t={}){const r=await fetch(a(`${i}/pull`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to pull")}return r.json()}async function kt(e,t={}){const r=await fetch(a(`${i}/fetch`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to fetch")}return r.json()}async function jt(e,t){const r=await fetch(a(`${i}/checkout`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to checkout branch")}return r.json()}async function Ot(e,t,r){const o=await fetch(a(`${i}/branches`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,startPoint:r})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to create branch")}return o.json()}async function Pt(e,t,r){const o=await fetch(a(`${i}/branches/rename`,e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldName:t,newName:r})});if(!o.ok){const n=await o.json().catch(()=>({error:o.statusText}));throw new Error(n.error||"Failed to rename branch")}return o.json()}async function Ct(e,t={}){const r=await fetch(a(`${i}/log`,e,{maxCount:t.maxCount,from:t.from,to:t.to,file:t.file}));if(!r.ok)throw new Error(`Failed to get git log: ${r.statusText}`);return r.json()}async function Nt(e,t){const r=await fetch(a(`${i}/commit-files`,e,{hash:t}));if(!r.ok)throw new Error(`Failed to get commit files: ${r.statusText}`);return r.json()}async function Ft(){const e=await fetch(a(`${i}/identities`,void 0));if(!e.ok)throw new Error(`Failed to get git identities: ${e.statusText}`);return e.json()}async function xt(e){const t=await fetch(a(`${i}/identities`,void 0),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to create git identity")}return t.json()}async function It(e,t){const r=await fetch(a(`${i}/identities/${e}`,void 0),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to update git identity")}return r.json()}async function vt(e){const t=await fetch(a(`${i}/identities/${e}`,void 0),{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to delete git identity")}}async function $t(e){if(!e)return null;const t=await fetch(a(`${i}/current-identity`,e));if(!t.ok)throw new Error(`Failed to get current git identity: ${t.statusText}`);const r=await t.json();return r?{userName:r.userName??null,userEmail:r.userEmail??null,sshCommand:r.sshCommand??null}:null}async function At(e){if(!e)return!1;const t=await fetch(a(`${i}/has-local-identity`,e));if(!t.ok)throw new Error(`Failed to check local identity: ${t.statusText}`);return(await t.json().catch(()=>null))?.hasLocalIdentity===!0}async function ce(){const e=await fetch(a(`${i}/global-identity`,void 0));if(!e.ok)throw new Error(`Failed to get global git identity: ${e.statusText}`);const t=await e.json();return!t||!t.userName&&!t.userEmail?null:{userName:t.userName??null,userEmail:t.userEmail??null,sshCommand:t.sshCommand??null}}async function Rt(e,t){const r=await fetch(a(`${i}/set-identity`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:t})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to set git identity")}return r.json()}async function le(){const e=await fetch(a(`${i}/discover-credentials`,void 0));if(!e.ok)throw new Error(`Failed to discover git credentials: ${e.statusText}`);return e.json()}async function _t(e){const t=await fetch(a(`${i}/remotes`,e));if(!t.ok)throw new Error(`Failed to get remotes: ${t.statusText}`);return t.json()}async function Gt(e,t){const r=await fetch(a(`${i}/rebase`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to rebase")}return r.json()}async function Wt(e){const t=await fetch(a(`${i}/rebase/abort`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to abort rebase")}return t.json()}async function Dt(e,t){const r=await fetch(a(`${i}/merge`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to merge")}return r.json()}async function Jt(e){const t=await fetch(a(`${i}/merge/abort`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to abort merge")}return t.json()}async function Lt(e){const t=await fetch(a(`${i}/rebase/continue`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to continue rebase")}return t.json()}async function Ut(e){const t=await fetch(a(`${i}/merge/continue`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to continue merge")}return t.json()}async function Mt(e,t){const r=await fetch(a(`${i}/stash`,e),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})});if(!r.ok){const o=await r.json().catch(()=>({error:r.statusText}));throw new Error(o.error||"Failed to stash")}return r.json()}async function Bt(e){const t=await fetch(a(`${i}/stash/pop`,e),{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({error:t.statusText}));throw new Error(r.error||"Failed to pop stash")}return t.json()}async function qt(e){const t=await fetch(a(`${i}/conflict-details`,e));if(!t.ok)throw new Error(`Failed to get conflict details: ${t.statusText}`);return t.json()}const zt=()=>({checkIsGitRepository:lt,getGitStatus:ut,getGitDiff:dt,getGitFileDiff:ht,revertGitFile:ft,isLinkedWorktree:pt,getGitBranches:wt,deleteGitBranch:yt,deleteRemoteBranch:mt,generateCommitMessage:gt,generatePullRequestDescription:Tt,listGitWorktrees:I,validateGitWorktree:v,createGitWorktree:$,deleteGitWorktree:A,createGitCommit(e,t,r){return bt(e,t,r)},gitPush:St,gitPull:Et,gitFetch:kt,checkoutBranch:jt,createBranch:Ot,renameBranch:Pt,getGitLog(e,t){return Ct(e,t)},getCommitFiles:Nt,getCurrentGitIdentity:$t,hasLocalIdentity:At,setGitIdentity:Rt,getGitIdentities:Ft,createGitIdentity:xt,updateGitIdentity:It,deleteGitIdentity:vt,getRemotes:_t,rebase:Gt,abortRebase:Wt,continueRebase:Lt,merge:Dt,abortMerge:Jt,continueMerge:Ut,stash:Mt,stashPop:Bt,getConflictDetails:qt,worktree:{list:I,validate:v,create:$,remove:A}}),f=e=>e.replace(/\\/g,"/"),Kt=(e,t)=>{const r=f(t?.directory||t?.path||e),o=Array.isArray(t?.entries)?t.entries:[];return{directory:r,entries:o.filter(n=>!!(n&&typeof n.name=="string"&&typeof n.path=="string")).map(n=>({name:n.name,path:f(n.path),isDirectory:!!n.isDirectory}))}},Ht=()=>({async listDirectory(e){const t=f(e),r=new URLSearchParams;t&&r.set("path",t);const o=await fetch(`/api/fs/list${r.toString()?`?${r.toString()}`:""}`);if(!o.ok){const s=await o.json().catch(()=>({error:o.statusText}));throw new Error(s.error||"Failed to list directory")}const n=await o.json();return Kt(t,n)},async search(e){const t=new URLSearchParams,r=f(e.directory);r&&t.set("directory",r),t.set("q",e.query),typeof e.maxResults=="number"&&Number.isFinite(e.maxResults)&&t.set("limit",String(e.maxResults)),e.includeHidden&&t.set("includeHidden","true");const o=await fetch(`/api/fs/search?${t.toString()}`);if(!o.ok){const l=await o.json().catch(()=>({error:o.statusText}));throw new Error(l.error||"Failed to search files")}const n=await o.json();return(Array.isArray(n?.files)?n.files:[]).filter(l=>!!(l&&typeof l.path=="string")).map(l=>({path:f(l.path),preview:typeof l.relativePath=="string"&&l.relativePath.length>0?[f(l.relativePath)]:void 0}))},async createDirectory(e){const t=f(e),r=await fetch("/api/fs/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to create directory")}const o=await r.json();return{success:!!o?.success,path:typeof o?.path=="string"?f(o.path):t}},async readFile(e){const t=f(e),r=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}`);if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to read file")}return{content:await r.text(),path:t}},async writeFile(e,t){const r=f(e),o=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r,content:t})});if(!o.ok){const s=await o.json().catch(()=>({error:o.statusText}));throw new Error(s.error||"Failed to write file")}const n=await o.json().catch(()=>({}));return{success:!!n.success,path:typeof n.path=="string"?f(n.path):r}},async delete(e){const t=f(e),r=await fetch("/api/fs/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to delete file")}return{success:!!(await r.json().catch(()=>({}))).success}},async rename(e,t){const r=await fetch("/api/fs/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:e,newPath:t})});if(!r.ok){const n=await r.json().catch(()=>({error:r.statusText}));throw new Error(n.error||"Failed to rename file")}const o=await r.json().catch(()=>({}));return{success:!!o.success,path:typeof o.path=="string"?f(o.path):t}},async revealPath(e){const t=await fetch("/api/fs/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:f(e)})});if(!t.ok){const o=await t.json().catch(()=>({error:t.statusText}));throw new Error(o.error||"Failed to reveal path")}return{success:!!(await t.json().catch(()=>({}))).success}}}),R="/api/config/settings",Yt="/api/config/reload",_=e=>!e||typeof e!="object"?{}:e,Vt=()=>({async load(){const e=await fetch(R,{method:"GET",headers:{Accept:"application/json"}});if(!e.ok)throw new Error(`Failed to load settings: ${e.statusText}`);return{settings:_(await e.json().catch(()=>({}))),source:"web"}},async save(e){const t=await fetch(R,{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)});if(!t.ok){const o=await t.json().catch(()=>({error:t.statusText}));throw new Error(o.error||"Failed to save settings")}return _(await t.json().catch(()=>({})))},async restartOpenCode(){const e=await fetch(Yt,{method:"POST"});if(!e.ok){const t=await e.json().catch(()=>({error:e.statusText}));throw new Error(t.error||"Failed to restart OpenCode")}return{restarted:!0}}}),Xt=()=>({async requestDirectoryAccess(e){return{success:!0,path:e.path}},async startAccessingDirectory(e){return{success:!0}},async stopAccessingDirectory(e){return{success:!0}}}),Qt=async e=>{if(typeof Notification>"u")return console.info("Notifications not supported in this environment",e),!1;if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted"||Notification.permission!=="granted")return console.warn("Notification permission not granted"),!1;try{return new Notification(e?.title??"OpenChamber",{body:e?.body,tag:e?.tag}),!0}catch(t){return console.warn("Failed to send notification",t),!1}},Zt=async e=>{if(typeof window>"u")return!1;const t=window.__TAURI__;if(!t?.core?.invoke)return!1;try{return await t.core.invoke("desktop_notify",{payload:{title:e?.title,body:e?.body,tag:e?.tag}}),!0}catch(r){return console.warn("Failed to send native notification (tauri)",r),!1}},te=()=>({async notifyAgentCompletion(e){return await Zt(e)||Qt(e)},canNotify:()=>typeof window<"u"&&window.__TAURI__?.core?.invoke?!0:typeof Notification<"u"?Notification.permission==="granted":!1}),ee=()=>({async getAvailableTools(){const e=await fetch("/api/experimental/tool/ids");if(!e.ok)throw new Error(`Tools API returned ${e.status} ${e.statusText}`);const t=await e.json();if(!Array.isArray(t))throw new Error("Tools API returned invalid data format");return t.filter(r=>typeof r=="string"&&r!=="invalid").sort()}}),k=async(e,t)=>{try{const r=await fetch(e,{...t,credentials:"include",headers:{Accept:"application/json",...t?.headers??{}}});return r.ok?await r.json():null}catch{return null}},re=()=>({async getVapidPublicKey(){return k("/api/push/vapid-public-key")},async subscribe(e){return k("/api/push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},async unsubscribe(e){return k("/api/push/subscribe",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},async setVisibility(e){return k("/api/push/visibility",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0})}}),h=async e=>await e.json().catch(()=>null),oe=()=>({async authStatus(){const e=await fetch("/api/github/auth/status",{method:"GET",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok||!t)throw new Error(t?.error||e.statusText||"Failed to load GitHub status");return t},async authStart(){const e=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),t=await h(e);if(!e.ok||!t||!("deviceCode"in t))throw new Error(t?.error||e.statusText||"Failed to start GitHub auth");return t},async authComplete(e){const t=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:e})}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to complete GitHub auth");return r},async authDisconnect(){const e=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok)throw new Error(t?.error||e.statusText||"Failed to disconnect GitHub");return{removed:!!t?.removed}},async authActivate(e){const t=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:e})}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to activate GitHub account");return r},async me(){const e=await fetch("/api/github/me",{method:"GET",headers:{Accept:"application/json"}}),t=await h(e);if(!e.ok||!t)throw new Error(t?.error||e.statusText||"Failed to fetch GitHub user");return t},async prStatus(e,t,r){const o=new URLSearchParams({directory:e,branch:t,...r?{remote:r}:{}}),n=await fetch(`/api/github/pr/status?${o.toString()}`,{method:"GET",headers:{Accept:"application/json"}}),s=await h(n);if(!n.ok||!s)throw new Error(s?.error||n.statusText||"Failed to load PR status");return s},async prCreate(e){const t=await fetch("/api/github/pr/create",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to create PR");return r},async prUpdate(e){const t=await fetch("/api/github/pr/update",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to update PR");return r},async prMerge(e){const t=await fetch("/api/github/pr/merge",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to merge PR");return r},async prReady(e){const t=await fetch("/api/github/pr/ready",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(e)}),r=await h(t);if(!t.ok||!r)throw new Error(r?.error||t.statusText||"Failed to mark PR ready");return r},async prsList(e,t){const r=t?.page??1,o=await fetch(`/api/github/pulls/list?directory=${encodeURIComponent(e)}&page=${encodeURIComponent(String(r))}`,{method:"GET",headers:{Accept:"application/json"}}),n=await h(o);if(!o.ok||!n)throw new Error(n?.error||o.statusText||"Failed to load pull requests");return n},async prContext(e,t,r){const o=new URL("/api/github/pulls/context",window.location.origin);o.searchParams.set("directory",e),o.searchParams.set("number",String(t)),r?.includeDiff&&o.searchParams.set("diff","1"),r?.includeCheckDetails&&o.searchParams.set("checkDetails","1");const n=await fetch(o.toString(),{method:"GET",headers:{Accept:"application/json"}}),s=await h(n);if(!n.ok||!s)throw new Error(s?.error||n.statusText||"Failed to load pull request context");return s},async issuesList(e,t){const r=t?.page??1,o=await fetch(`/api/github/issues/list?directory=${encodeURIComponent(e)}&page=${encodeURIComponent(String(r))}`,{method:"GET",headers:{Accept:"application/json"}}),n=await h(o);if(!o.ok||!n)throw new Error(n?.error||o.statusText||"Failed to load issues");return n},async issueGet(e,t){const r=await fetch(`/api/github/issues/get?directory=${encodeURIComponent(e)}&number=${encodeURIComponent(String(t))}`,{method:"GET",headers:{Accept:"application/json"}}),o=await h(r);if(!r.ok||!o)throw new Error(o?.error||r.statusText||"Failed to load issue");return o},async issueComments(e,t){const r=await fetch(`/api/github/issues/comments?directory=${encodeURIComponent(e)}&number=${encodeURIComponent(String(t))}`,{method:"GET",headers:{Accept:"application/json"}}),o=await h(r);if(!r.ok||!o)throw new Error(o?.error||r.statusText||"Failed to load issue comments");return o}}),ne=()=>({runtime:{platform:"web",isDesktop:!1,isVSCode:!1,label:"web"},terminal:at(),git:zt(),files:Ht(),settings:Vt(),permissions:Xt(),notifications:te(),github:oe(),push:re(),tools:ee()});function se(e={}){const{immediate:t=!1,onNeedRefresh:r,onOfflineReady:o,onRegistered:n,onRegisteredSW:s,onRegisterError:l}=e;let p,c;const d=async(u=!0)=>{await c};async function w(){if("serviceWorker"in navigator){if(p=await G(async()=>{const{Workbox:u}=await import("./vendor-.bun-Byc0cUD3.js").then(y=>y.eK);return{Workbox:u}},__vite__mapDeps([0,1])).then(({Workbox:u})=>new u("/sw.js",{scope:"/",type:"classic"})).catch(u=>{l?.(u)}),!p)return;p.addEventListener("activated",u=>{(u.isUpdate||u.isExternal)&&window.location.reload()}),p.addEventListener("installed",u=>{u.isUpdate||o?.()}),p.register({immediate:t}).then(u=>{s?s("/sw.js",u):n?.(u)}).catch(u=>{l?.(u)})}}return c=w(),d}window.__OPENCHAMBER_RUNTIME_APIS__=ne();se({onRegisterError(e){console.warn("[PWA] service worker registration failed:",e)}});G(()=>import("./main-BPzHzdLz.js").then(e=>e.m),__vite__mapDeps([2,0,1,3]));export{$ as a,mt as b,lt as c,A as d,vt as e,xt as f,ut as g,le as h,ce as i,Ft as j,wt as k,I as l,_t as m,yt as n,Ct as o,Nt as p,qt as q,Pt as r,ot as s,ae as t,It as u,v};