linkshell-cli 0.5.24 → 0.5.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/src/runtime/acp/agent-workspace.d.ts +7 -0
- package/dist/cli/src/runtime/acp/agent-workspace.js +81 -1
- package/dist/cli/src/runtime/acp/agent-workspace.js.map +1 -1
- package/dist/cli/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/runtime/acp/agent-workspace.ts +75 -1
- package/web/assets/{index-Bh3kcNhP.js → index-wEo8TBBQ.js} +1 -1
- package/web/index.html +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync, watch } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { basename, join, relative } from "node:path";
|
|
4
4
|
import {
|
|
@@ -1944,12 +1944,83 @@ export class AgentWorkspaceProxy {
|
|
|
1944
1944
|
}
|
|
1945
1945
|
|
|
1946
1946
|
stop(): void {
|
|
1947
|
+
for (const watcher of this.fsWatchers) {
|
|
1948
|
+
try { watcher.close(); } catch { /* already closed */ }
|
|
1949
|
+
}
|
|
1950
|
+
this.fsWatchers = [];
|
|
1951
|
+
if (this.fsSyncTimer) {
|
|
1952
|
+
clearTimeout(this.fsSyncTimer);
|
|
1953
|
+
this.fsSyncTimer = undefined;
|
|
1954
|
+
}
|
|
1947
1955
|
for (const client of this.clients.values()) {
|
|
1948
1956
|
client.stop();
|
|
1949
1957
|
}
|
|
1950
1958
|
this.clients.clear();
|
|
1951
1959
|
}
|
|
1952
1960
|
|
|
1961
|
+
// ── External-session live refresh ────────────────────────────────────
|
|
1962
|
+
// The console requests the session list only once, at connect. Without this,
|
|
1963
|
+
// a session another `claude`/`codex` process starts (or whose status changes)
|
|
1964
|
+
// after connect never shows up — the tree is frozen at connect time. Watch the
|
|
1965
|
+
// on-disk session stores and re-sync + push when they change, so externally-
|
|
1966
|
+
// driven sessions surface live (this is what CodeIsland does). Event-driven:
|
|
1967
|
+
// zero cost while idle, throttled to at most one re-scan per window during a
|
|
1968
|
+
// burst of writes (an active turn appends constantly).
|
|
1969
|
+
private fsWatchers: ReturnType<typeof watch>[] = [];
|
|
1970
|
+
private fsSyncTimer: ReturnType<typeof setTimeout> | undefined;
|
|
1971
|
+
private fsSyncRunning = false;
|
|
1972
|
+
private static readonly FS_SYNC_THROTTLE_MS = 1500;
|
|
1973
|
+
|
|
1974
|
+
private startSessionWatchers(): void {
|
|
1975
|
+
if (this.fsWatchers.length > 0) return; // already watching
|
|
1976
|
+
const roots = [
|
|
1977
|
+
join(homedir(), ".claude", "projects"),
|
|
1978
|
+
join(homedir(), ".codex", "sessions"),
|
|
1979
|
+
];
|
|
1980
|
+
for (const root of roots) {
|
|
1981
|
+
if (!existsSync(root)) continue;
|
|
1982
|
+
try {
|
|
1983
|
+
// recursive is supported on macOS/Windows; on Linux this throws, and we
|
|
1984
|
+
// simply don't get live updates (the connect-time scan still works).
|
|
1985
|
+
const watcher = watch(root, { recursive: true, persistent: false }, () => this.scheduleSessionSync());
|
|
1986
|
+
watcher.on("error", () => { /* transient watch error — ignore */ });
|
|
1987
|
+
this.fsWatchers.push(watcher);
|
|
1988
|
+
} catch {
|
|
1989
|
+
// recursive watch unavailable on this platform — skip silently.
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
private scheduleSessionSync(): void {
|
|
1995
|
+
if (this.fsSyncTimer) return; // a sync is already scheduled in this window
|
|
1996
|
+
this.fsSyncTimer = setTimeout(() => {
|
|
1997
|
+
this.fsSyncTimer = undefined;
|
|
1998
|
+
void this.syncAndPushSessions();
|
|
1999
|
+
}, AgentWorkspaceProxy.FS_SYNC_THROTTLE_MS);
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
private async syncAndPushSessions(): Promise<void> {
|
|
2003
|
+
if (this.fsSyncRunning) return; // don't overlap with an in-flight sync
|
|
2004
|
+
this.fsSyncRunning = true;
|
|
2005
|
+
try {
|
|
2006
|
+
await this.syncProviderSessions();
|
|
2007
|
+
// Push the conversation list (statuses) — lighter than a full snapshot and
|
|
2008
|
+
// exactly what refreshes the tree. The web handles an unsolicited
|
|
2009
|
+
// conversation.list.result the same as a requested one.
|
|
2010
|
+
this.input.send(createEnvelope({
|
|
2011
|
+
type: "agent.v2.conversation.list.result",
|
|
2012
|
+
sessionId: this.input.sessionId,
|
|
2013
|
+
payload: { conversations: [...this.conversations.values()].filter((c) => !c.archived) },
|
|
2014
|
+
}));
|
|
2015
|
+
} catch (error) {
|
|
2016
|
+
if (this.input.verbose) {
|
|
2017
|
+
process.stderr.write(`[agent:v2] fs-watch sync failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
2018
|
+
}
|
|
2019
|
+
} finally {
|
|
2020
|
+
this.fsSyncRunning = false;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
|
|
1953
2024
|
private clientForProvider(provider: AgentProvider): AcpClient | ClaudeSdkClient | ClaudeStreamJsonClient | undefined {
|
|
1954
2025
|
return this.clients.get(provider);
|
|
1955
2026
|
}
|
|
@@ -1996,6 +2067,9 @@ export class AgentWorkspaceProxy {
|
|
|
1996
2067
|
this.status = "idle";
|
|
1997
2068
|
this.error = undefined;
|
|
1998
2069
|
this.sendCapabilities();
|
|
2070
|
+
// Start watching the on-disk session stores so externally-started sessions
|
|
2071
|
+
// and status changes surface live, not just at connect time.
|
|
2072
|
+
this.startSessionWatchers();
|
|
1999
2073
|
}
|
|
2000
2074
|
|
|
2001
2075
|
private async ensureProviderClient(provider: AgentProvider): Promise<AcpClient | ClaudeSdkClient | ClaudeStreamJsonClient | undefined> {
|
|
@@ -91,4 +91,4 @@ WARNING: This link could potentially be dangerous`)){const b=window.open();if(b)
|
|
|
91
91
|
`,p.VT="\v",p.FF="\f",p.CR="\r",p.SO="",p.SI="",p.DLE="",p.DC1="",p.DC2="",p.DC3="",p.DC4="",p.NAK="",p.SYN="",p.ETB="",p.CAN="",p.EM="",p.SUB="",p.ESC="\x1B",p.FS="",p.GS="",p.RS="",p.US="",p.SP=" ",p.DEL=""})(h||(o.C0=h={})),(function(p){p.PAD="",p.HOP="",p.BPH="",p.NBH="",p.IND="",p.NEL="
",p.SSA="",p.ESA="",p.HTS="",p.HTJ="",p.VTS="",p.PLD="",p.PLU="",p.RI="",p.SS2="",p.SS3="",p.DCS="",p.PU1="",p.PU2="",p.STS="",p.CCH="",p.MW="",p.SPA="",p.EPA="",p.SOS="",p.SGCI="",p.SCI="",p.CSI="",p.ST="",p.OSC="",p.PM="",p.APC=""})(d||(o.C1=d={})),(function(p){p.ST=`${h.ESC}\\`})(m||(o.C1_ESCAPED=m={}))},7399:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.evaluateKeyboardEvent=void 0;const d=h(2584),m={48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};o.evaluateKeyboardEvent=function(p,x,S,k){const w={type:0,cancel:!1,key:void 0},_=(p.shiftKey?1:0)|(p.altKey?2:0)|(p.ctrlKey?4:0)|(p.metaKey?8:0);switch(p.keyCode){case 0:p.key==="UIKeyInputUpArrow"?w.key=x?d.C0.ESC+"OA":d.C0.ESC+"[A":p.key==="UIKeyInputLeftArrow"?w.key=x?d.C0.ESC+"OD":d.C0.ESC+"[D":p.key==="UIKeyInputRightArrow"?w.key=x?d.C0.ESC+"OC":d.C0.ESC+"[C":p.key==="UIKeyInputDownArrow"&&(w.key=x?d.C0.ESC+"OB":d.C0.ESC+"[B");break;case 8:w.key=p.ctrlKey?"\b":d.C0.DEL,p.altKey&&(w.key=d.C0.ESC+w.key);break;case 9:if(p.shiftKey){w.key=d.C0.ESC+"[Z";break}w.key=d.C0.HT,w.cancel=!0;break;case 13:w.key=p.altKey?d.C0.ESC+d.C0.CR:d.C0.CR,w.cancel=!0;break;case 27:w.key=d.C0.ESC,p.altKey&&(w.key=d.C0.ESC+d.C0.ESC),w.cancel=!0;break;case 37:if(p.metaKey)break;_?(w.key=d.C0.ESC+"[1;"+(_+1)+"D",w.key===d.C0.ESC+"[1;3D"&&(w.key=d.C0.ESC+(S?"b":"[1;5D"))):w.key=x?d.C0.ESC+"OD":d.C0.ESC+"[D";break;case 39:if(p.metaKey)break;_?(w.key=d.C0.ESC+"[1;"+(_+1)+"C",w.key===d.C0.ESC+"[1;3C"&&(w.key=d.C0.ESC+(S?"f":"[1;5C"))):w.key=x?d.C0.ESC+"OC":d.C0.ESC+"[C";break;case 38:if(p.metaKey)break;_?(w.key=d.C0.ESC+"[1;"+(_+1)+"A",S||w.key!==d.C0.ESC+"[1;3A"||(w.key=d.C0.ESC+"[1;5A")):w.key=x?d.C0.ESC+"OA":d.C0.ESC+"[A";break;case 40:if(p.metaKey)break;_?(w.key=d.C0.ESC+"[1;"+(_+1)+"B",S||w.key!==d.C0.ESC+"[1;3B"||(w.key=d.C0.ESC+"[1;5B")):w.key=x?d.C0.ESC+"OB":d.C0.ESC+"[B";break;case 45:p.shiftKey||p.ctrlKey||(w.key=d.C0.ESC+"[2~");break;case 46:w.key=_?d.C0.ESC+"[3;"+(_+1)+"~":d.C0.ESC+"[3~";break;case 36:w.key=_?d.C0.ESC+"[1;"+(_+1)+"H":x?d.C0.ESC+"OH":d.C0.ESC+"[H";break;case 35:w.key=_?d.C0.ESC+"[1;"+(_+1)+"F":x?d.C0.ESC+"OF":d.C0.ESC+"[F";break;case 33:p.shiftKey?w.type=2:p.ctrlKey?w.key=d.C0.ESC+"[5;"+(_+1)+"~":w.key=d.C0.ESC+"[5~";break;case 34:p.shiftKey?w.type=3:p.ctrlKey?w.key=d.C0.ESC+"[6;"+(_+1)+"~":w.key=d.C0.ESC+"[6~";break;case 112:w.key=_?d.C0.ESC+"[1;"+(_+1)+"P":d.C0.ESC+"OP";break;case 113:w.key=_?d.C0.ESC+"[1;"+(_+1)+"Q":d.C0.ESC+"OQ";break;case 114:w.key=_?d.C0.ESC+"[1;"+(_+1)+"R":d.C0.ESC+"OR";break;case 115:w.key=_?d.C0.ESC+"[1;"+(_+1)+"S":d.C0.ESC+"OS";break;case 116:w.key=_?d.C0.ESC+"[15;"+(_+1)+"~":d.C0.ESC+"[15~";break;case 117:w.key=_?d.C0.ESC+"[17;"+(_+1)+"~":d.C0.ESC+"[17~";break;case 118:w.key=_?d.C0.ESC+"[18;"+(_+1)+"~":d.C0.ESC+"[18~";break;case 119:w.key=_?d.C0.ESC+"[19;"+(_+1)+"~":d.C0.ESC+"[19~";break;case 120:w.key=_?d.C0.ESC+"[20;"+(_+1)+"~":d.C0.ESC+"[20~";break;case 121:w.key=_?d.C0.ESC+"[21;"+(_+1)+"~":d.C0.ESC+"[21~";break;case 122:w.key=_?d.C0.ESC+"[23;"+(_+1)+"~":d.C0.ESC+"[23~";break;case 123:w.key=_?d.C0.ESC+"[24;"+(_+1)+"~":d.C0.ESC+"[24~";break;default:if(!p.ctrlKey||p.shiftKey||p.altKey||p.metaKey)if(S&&!k||!p.altKey||p.metaKey)!S||p.altKey||p.ctrlKey||p.shiftKey||!p.metaKey?p.key&&!p.ctrlKey&&!p.altKey&&!p.metaKey&&p.keyCode>=48&&p.key.length===1?w.key=p.key:p.key&&p.ctrlKey&&(p.key==="_"&&(w.key=d.C0.US),p.key==="@"&&(w.key=d.C0.NUL)):p.keyCode===65&&(w.type=1);else{const b=m[p.keyCode],v=b==null?void 0:b[p.shiftKey?1:0];if(v)w.key=d.C0.ESC+v;else if(p.keyCode>=65&&p.keyCode<=90){const y=p.ctrlKey?p.keyCode-64:p.keyCode+32;let T=String.fromCharCode(y);p.shiftKey&&(T=T.toUpperCase()),w.key=d.C0.ESC+T}else if(p.keyCode===32)w.key=d.C0.ESC+(p.ctrlKey?d.C0.NUL:" ");else if(p.key==="Dead"&&p.code.startsWith("Key")){let y=p.code.slice(3,4);p.shiftKey||(y=y.toLowerCase()),w.key=d.C0.ESC+y,w.cancel=!0}}else p.keyCode>=65&&p.keyCode<=90?w.key=String.fromCharCode(p.keyCode-64):p.keyCode===32?w.key=d.C0.NUL:p.keyCode>=51&&p.keyCode<=55?w.key=String.fromCharCode(p.keyCode-51+27):p.keyCode===56?w.key=d.C0.DEL:p.keyCode===219?w.key=d.C0.ESC:p.keyCode===220?w.key=d.C0.FS:p.keyCode===221&&(w.key=d.C0.GS)}return w}},482:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.Utf8ToUtf32=o.StringToUtf32=o.utf32ToString=o.stringFromCodePoint=void 0,o.stringFromCodePoint=function(h){return h>65535?(h-=65536,String.fromCharCode(55296+(h>>10))+String.fromCharCode(h%1024+56320)):String.fromCharCode(h)},o.utf32ToString=function(h,d=0,m=h.length){let p="";for(let x=d;x<m;++x){let S=h[x];S>65535?(S-=65536,p+=String.fromCharCode(55296+(S>>10))+String.fromCharCode(S%1024+56320)):p+=String.fromCharCode(S)}return p},o.StringToUtf32=class{constructor(){this._interim=0}clear(){this._interim=0}decode(h,d){const m=h.length;if(!m)return 0;let p=0,x=0;if(this._interim){const S=h.charCodeAt(x++);56320<=S&&S<=57343?d[p++]=1024*(this._interim-55296)+S-56320+65536:(d[p++]=this._interim,d[p++]=S),this._interim=0}for(let S=x;S<m;++S){const k=h.charCodeAt(S);if(55296<=k&&k<=56319){if(++S>=m)return this._interim=k,p;const w=h.charCodeAt(S);56320<=w&&w<=57343?d[p++]=1024*(k-55296)+w-56320+65536:(d[p++]=k,d[p++]=w)}else k!==65279&&(d[p++]=k)}return p}},o.Utf8ToUtf32=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(h,d){const m=h.length;if(!m)return 0;let p,x,S,k,w=0,_=0,b=0;if(this.interim[0]){let T=!1,M=this.interim[0];M&=(224&M)==192?31:(240&M)==224?15:7;let N,O=0;for(;(N=63&this.interim[++O])&&O<4;)M<<=6,M|=N;const R=(224&this.interim[0])==192?2:(240&this.interim[0])==224?3:4,L=R-O;for(;b<L;){if(b>=m)return 0;if(N=h[b++],(192&N)!=128){b--,T=!0;break}this.interim[O++]=N,M<<=6,M|=63&N}T||(R===2?M<128?b--:d[w++]=M:R===3?M<2048||M>=55296&&M<=57343||M===65279||(d[w++]=M):M<65536||M>1114111||(d[w++]=M)),this.interim.fill(0)}const v=m-4;let y=b;for(;y<m;){for(;!(!(y<v)||128&(p=h[y])||128&(x=h[y+1])||128&(S=h[y+2])||128&(k=h[y+3]));)d[w++]=p,d[w++]=x,d[w++]=S,d[w++]=k,y+=4;if(p=h[y++],p<128)d[w++]=p;else if((224&p)==192){if(y>=m)return this.interim[0]=p,w;if(x=h[y++],(192&x)!=128){y--;continue}if(_=(31&p)<<6|63&x,_<128){y--;continue}d[w++]=_}else if((240&p)==224){if(y>=m)return this.interim[0]=p,w;if(x=h[y++],(192&x)!=128){y--;continue}if(y>=m)return this.interim[0]=p,this.interim[1]=x,w;if(S=h[y++],(192&S)!=128){y--;continue}if(_=(15&p)<<12|(63&x)<<6|63&S,_<2048||_>=55296&&_<=57343||_===65279)continue;d[w++]=_}else if((248&p)==240){if(y>=m)return this.interim[0]=p,w;if(x=h[y++],(192&x)!=128){y--;continue}if(y>=m)return this.interim[0]=p,this.interim[1]=x,w;if(S=h[y++],(192&S)!=128){y--;continue}if(y>=m)return this.interim[0]=p,this.interim[1]=x,this.interim[2]=S,w;if(k=h[y++],(192&k)!=128){y--;continue}if(_=(7&p)<<18|(63&x)<<12|(63&S)<<6|63&k,_<65536||_>1114111)continue;d[w++]=_}}return w}}},225:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.UnicodeV6=void 0;const d=h(1480),m=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],p=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]];let x;o.UnicodeV6=class{constructor(){if(this.version="6",!x){x=new Uint8Array(65536),x.fill(1),x[0]=0,x.fill(0,1,32),x.fill(0,127,160),x.fill(2,4352,4448),x[9001]=2,x[9002]=2,x.fill(2,11904,42192),x[12351]=1,x.fill(2,44032,55204),x.fill(2,63744,64256),x.fill(2,65040,65050),x.fill(2,65072,65136),x.fill(2,65280,65377),x.fill(2,65504,65511);for(let S=0;S<m.length;++S)x.fill(0,m[S][0],m[S][1]+1)}}wcwidth(S){return S<32?0:S<127?1:S<65536?x[S]:(function(k,w){let _,b=0,v=w.length-1;if(k<w[0][0]||k>w[v][1])return!1;for(;v>=b;)if(_=b+v>>1,k>w[_][1])b=_+1;else{if(!(k<w[_][0]))return!0;v=_-1}return!1})(S,p)?0:S>=131072&&S<=196605||S>=196608&&S<=262141?2:1}charProperties(S,k){let w=this.wcwidth(S),_=w===0&&k!==0;if(_){const b=d.UnicodeService.extractWidth(k);b===0?_=!1:b>w&&(w=b)}return d.UnicodeService.createPropertyValue(0,w,_)}}},5981:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.WriteBuffer=void 0;const d=h(8460),m=h(844);class p extends m.Disposable{constructor(S){super(),this._action=S,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this.register(new d.EventEmitter),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(S,k){if(k!==void 0&&this._syncCalls>k)return void(this._syncCalls=0);if(this._pendingData+=S.length,this._writeBuffer.push(S),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;let w;for(this._isSyncWriting=!0;w=this._writeBuffer.shift();){this._action(w);const _=this._callbacks.shift();_&&_()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(S,k){if(this._pendingData>5e7)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput)return this._didUserInput=!1,this._pendingData+=S.length,this._writeBuffer.push(S),this._callbacks.push(k),void this._innerWrite();setTimeout((()=>this._innerWrite()))}this._pendingData+=S.length,this._writeBuffer.push(S),this._callbacks.push(k)}_innerWrite(S=0,k=!0){const w=S||Date.now();for(;this._writeBuffer.length>this._bufferOffset;){const _=this._writeBuffer[this._bufferOffset],b=this._action(_,k);if(b){const y=T=>Date.now()-w>=12?setTimeout((()=>this._innerWrite(0,T))):this._innerWrite(w,T);return void b.catch((T=>(queueMicrotask((()=>{throw T})),Promise.resolve(!1)))).then(y)}const v=this._callbacks[this._bufferOffset];if(v&&v(),this._bufferOffset++,this._pendingData-=_.length,Date.now()-w>=12)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>50&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout((()=>this._innerWrite()))):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}}o.WriteBuffer=p},5941:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.toRgbString=o.parseColor=void 0;const h=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,d=/^[\da-f]+$/;function m(p,x){const S=p.toString(16),k=S.length<2?"0"+S:S;switch(x){case 4:return S[0];case 8:return k;case 12:return(k+k).slice(0,3);default:return k+k}}o.parseColor=function(p){if(!p)return;let x=p.toLowerCase();if(x.indexOf("rgb:")===0){x=x.slice(4);const S=h.exec(x);if(S){const k=S[1]?15:S[4]?255:S[7]?4095:65535;return[Math.round(parseInt(S[1]||S[4]||S[7]||S[10],16)/k*255),Math.round(parseInt(S[2]||S[5]||S[8]||S[11],16)/k*255),Math.round(parseInt(S[3]||S[6]||S[9]||S[12],16)/k*255)]}}else if(x.indexOf("#")===0&&(x=x.slice(1),d.exec(x)&&[3,6,9,12].includes(x.length))){const S=x.length/3,k=[0,0,0];for(let w=0;w<3;++w){const _=parseInt(x.slice(S*w,S*w+S),16);k[w]=S===1?_<<4:S===2?_:S===3?_>>4:_>>8}return k}},o.toRgbString=function(p,x=16){const[S,k,w]=p;return`rgb:${m(S,x)}/${m(k,x)}/${m(w,x)}`}},5770:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.PAYLOAD_LIMIT=void 0,o.PAYLOAD_LIMIT=1e7},6351:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.DcsHandler=o.DcsParser=void 0;const d=h(482),m=h(8742),p=h(5770),x=[];o.DcsParser=class{constructor(){this._handlers=Object.create(null),this._active=x,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=x}registerHandler(k,w){this._handlers[k]===void 0&&(this._handlers[k]=[]);const _=this._handlers[k];return _.push(w),{dispose:()=>{const b=_.indexOf(w);b!==-1&&_.splice(b,1)}}}clearHandler(k){this._handlers[k]&&delete this._handlers[k]}setHandlerFallback(k){this._handlerFb=k}reset(){if(this._active.length)for(let k=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;k>=0;--k)this._active[k].unhook(!1);this._stack.paused=!1,this._active=x,this._ident=0}hook(k,w){if(this.reset(),this._ident=k,this._active=this._handlers[k]||x,this._active.length)for(let _=this._active.length-1;_>=0;_--)this._active[_].hook(w);else this._handlerFb(this._ident,"HOOK",w)}put(k,w,_){if(this._active.length)for(let b=this._active.length-1;b>=0;b--)this._active[b].put(k,w,_);else this._handlerFb(this._ident,"PUT",(0,d.utf32ToString)(k,w,_))}unhook(k,w=!0){if(this._active.length){let _=!1,b=this._active.length-1,v=!1;if(this._stack.paused&&(b=this._stack.loopPosition-1,_=w,v=this._stack.fallThrough,this._stack.paused=!1),!v&&_===!1){for(;b>=0&&(_=this._active[b].unhook(k),_!==!0);b--)if(_ instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=b,this._stack.fallThrough=!1,_;b--}for(;b>=0;b--)if(_=this._active[b].unhook(!1),_ instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=b,this._stack.fallThrough=!0,_}else this._handlerFb(this._ident,"UNHOOK",k);this._active=x,this._ident=0}};const S=new m.Params;S.addParam(0),o.DcsHandler=class{constructor(k){this._handler=k,this._data="",this._params=S,this._hitLimit=!1}hook(k){this._params=k.length>1||k.params[0]?k.clone():S,this._data="",this._hitLimit=!1}put(k,w,_){this._hitLimit||(this._data+=(0,d.utf32ToString)(k,w,_),this._data.length>p.PAYLOAD_LIMIT&&(this._data="",this._hitLimit=!0))}unhook(k){let w=!1;if(this._hitLimit)w=!1;else if(k&&(w=this._handler(this._data,this._params),w instanceof Promise))return w.then((_=>(this._params=S,this._data="",this._hitLimit=!1,_)));return this._params=S,this._data="",this._hitLimit=!1,w}}},2015:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.EscapeSequenceParser=o.VT500_TRANSITION_TABLE=o.TransitionTable=void 0;const d=h(844),m=h(8742),p=h(6242),x=h(6351);class S{constructor(b){this.table=new Uint8Array(b)}setDefault(b,v){this.table.fill(b<<4|v)}add(b,v,y,T){this.table[v<<8|b]=y<<4|T}addMany(b,v,y,T){for(let M=0;M<b.length;M++)this.table[v<<8|b[M]]=y<<4|T}}o.TransitionTable=S;const k=160;o.VT500_TRANSITION_TABLE=(function(){const _=new S(4095),b=Array.apply(null,Array(256)).map(((O,R)=>R)),v=(O,R)=>b.slice(O,R),y=v(32,127),T=v(0,24);T.push(25),T.push.apply(T,v(28,32));const M=v(0,14);let N;for(N in _.setDefault(1,0),_.addMany(y,0,2,0),M)_.addMany([24,26,153,154],N,3,0),_.addMany(v(128,144),N,3,0),_.addMany(v(144,152),N,3,0),_.add(156,N,0,0),_.add(27,N,11,1),_.add(157,N,4,8),_.addMany([152,158,159],N,0,7),_.add(155,N,11,3),_.add(144,N,11,9);return _.addMany(T,0,3,0),_.addMany(T,1,3,1),_.add(127,1,0,1),_.addMany(T,8,0,8),_.addMany(T,3,3,3),_.add(127,3,0,3),_.addMany(T,4,3,4),_.add(127,4,0,4),_.addMany(T,6,3,6),_.addMany(T,5,3,5),_.add(127,5,0,5),_.addMany(T,2,3,2),_.add(127,2,0,2),_.add(93,1,4,8),_.addMany(y,8,5,8),_.add(127,8,5,8),_.addMany([156,27,24,26,7],8,6,0),_.addMany(v(28,32),8,0,8),_.addMany([88,94,95],1,0,7),_.addMany(y,7,0,7),_.addMany(T,7,0,7),_.add(156,7,0,0),_.add(127,7,0,7),_.add(91,1,11,3),_.addMany(v(64,127),3,7,0),_.addMany(v(48,60),3,8,4),_.addMany([60,61,62,63],3,9,4),_.addMany(v(48,60),4,8,4),_.addMany(v(64,127),4,7,0),_.addMany([60,61,62,63],4,0,6),_.addMany(v(32,64),6,0,6),_.add(127,6,0,6),_.addMany(v(64,127),6,0,0),_.addMany(v(32,48),3,9,5),_.addMany(v(32,48),5,9,5),_.addMany(v(48,64),5,0,6),_.addMany(v(64,127),5,7,0),_.addMany(v(32,48),4,9,5),_.addMany(v(32,48),1,9,2),_.addMany(v(32,48),2,9,2),_.addMany(v(48,127),2,10,0),_.addMany(v(48,80),1,10,0),_.addMany(v(81,88),1,10,0),_.addMany([89,90,92],1,10,0),_.addMany(v(96,127),1,10,0),_.add(80,1,11,9),_.addMany(T,9,0,9),_.add(127,9,0,9),_.addMany(v(28,32),9,0,9),_.addMany(v(32,48),9,9,12),_.addMany(v(48,60),9,8,10),_.addMany([60,61,62,63],9,9,10),_.addMany(T,11,0,11),_.addMany(v(32,128),11,0,11),_.addMany(v(28,32),11,0,11),_.addMany(T,10,0,10),_.add(127,10,0,10),_.addMany(v(28,32),10,0,10),_.addMany(v(48,60),10,8,10),_.addMany([60,61,62,63],10,0,11),_.addMany(v(32,48),10,9,12),_.addMany(T,12,0,12),_.add(127,12,0,12),_.addMany(v(28,32),12,0,12),_.addMany(v(32,48),12,9,12),_.addMany(v(48,64),12,0,11),_.addMany(v(64,127),12,12,13),_.addMany(v(64,127),10,12,13),_.addMany(v(64,127),9,12,13),_.addMany(T,13,13,13),_.addMany(y,13,13,13),_.add(127,13,0,13),_.addMany([27,156,24,26],13,14,0),_.add(k,0,2,0),_.add(k,8,5,8),_.add(k,6,0,6),_.add(k,11,0,11),_.add(k,13,13,13),_})();class w extends d.Disposable{constructor(b=o.VT500_TRANSITION_TABLE){super(),this._transitions=b,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new m.Params,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(v,y,T)=>{},this._executeHandlerFb=v=>{},this._csiHandlerFb=(v,y)=>{},this._escHandlerFb=v=>{},this._errorHandlerFb=v=>v,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this.register((0,d.toDisposable)((()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)}))),this._oscParser=this.register(new p.OscParser),this._dcsParser=this.register(new x.DcsParser),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},(()=>!0))}_identifier(b,v=[64,126]){let y=0;if(b.prefix){if(b.prefix.length>1)throw new Error("only one byte as prefix supported");if(y=b.prefix.charCodeAt(0),y&&60>y||y>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(b.intermediates){if(b.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let M=0;M<b.intermediates.length;++M){const N=b.intermediates.charCodeAt(M);if(32>N||N>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");y<<=8,y|=N}}if(b.final.length!==1)throw new Error("final must be a single byte");const T=b.final.charCodeAt(0);if(v[0]>T||T>v[1])throw new Error(`final must be in range ${v[0]} .. ${v[1]}`);return y<<=8,y|=T,y}identToString(b){const v=[];for(;b;)v.push(String.fromCharCode(255&b)),b>>=8;return v.reverse().join("")}setPrintHandler(b){this._printHandler=b}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(b,v){const y=this._identifier(b,[48,126]);this._escHandlers[y]===void 0&&(this._escHandlers[y]=[]);const T=this._escHandlers[y];return T.push(v),{dispose:()=>{const M=T.indexOf(v);M!==-1&&T.splice(M,1)}}}clearEscHandler(b){this._escHandlers[this._identifier(b,[48,126])]&&delete this._escHandlers[this._identifier(b,[48,126])]}setEscHandlerFallback(b){this._escHandlerFb=b}setExecuteHandler(b,v){this._executeHandlers[b.charCodeAt(0)]=v}clearExecuteHandler(b){this._executeHandlers[b.charCodeAt(0)]&&delete this._executeHandlers[b.charCodeAt(0)]}setExecuteHandlerFallback(b){this._executeHandlerFb=b}registerCsiHandler(b,v){const y=this._identifier(b);this._csiHandlers[y]===void 0&&(this._csiHandlers[y]=[]);const T=this._csiHandlers[y];return T.push(v),{dispose:()=>{const M=T.indexOf(v);M!==-1&&T.splice(M,1)}}}clearCsiHandler(b){this._csiHandlers[this._identifier(b)]&&delete this._csiHandlers[this._identifier(b)]}setCsiHandlerFallback(b){this._csiHandlerFb=b}registerDcsHandler(b,v){return this._dcsParser.registerHandler(this._identifier(b),v)}clearDcsHandler(b){this._dcsParser.clearHandler(this._identifier(b))}setDcsHandlerFallback(b){this._dcsParser.setHandlerFallback(b)}registerOscHandler(b,v){return this._oscParser.registerHandler(b,v)}clearOscHandler(b){this._oscParser.clearHandler(b)}setOscHandlerFallback(b){this._oscParser.setHandlerFallback(b)}setErrorHandler(b){this._errorHandler=b}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(b,v,y,T,M){this._parseStack.state=b,this._parseStack.handlers=v,this._parseStack.handlerPos=y,this._parseStack.transition=T,this._parseStack.chunkPos=M}parse(b,v,y){let T,M=0,N=0,O=0;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,O=this._parseStack.chunkPos+1;else{if(y===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");const R=this._parseStack.handlers;let L=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(y===!1&&L>-1){for(;L>=0&&(T=R[L](this._params),T!==!0);L--)if(T instanceof Promise)return this._parseStack.handlerPos=L,T}this._parseStack.handlers=[];break;case 4:if(y===!1&&L>-1){for(;L>=0&&(T=R[L](),T!==!0);L--)if(T instanceof Promise)return this._parseStack.handlerPos=L,T}this._parseStack.handlers=[];break;case 6:if(M=b[this._parseStack.chunkPos],T=this._dcsParser.unhook(M!==24&&M!==26,y),T)return T;M===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(M=b[this._parseStack.chunkPos],T=this._oscParser.end(M!==24&&M!==26,y),T)return T;M===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,O=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=15&this._parseStack.transition}for(let R=O;R<v;++R){switch(M=b[R],N=this._transitions.table[this.currentState<<8|(M<160?M:k)],N>>4){case 2:for(let F=R+1;;++F){if(F>=v||(M=b[F])<32||M>126&&M<k){this._printHandler(b,R,F),R=F-1;break}if(++F>=v||(M=b[F])<32||M>126&&M<k){this._printHandler(b,R,F),R=F-1;break}if(++F>=v||(M=b[F])<32||M>126&&M<k){this._printHandler(b,R,F),R=F-1;break}if(++F>=v||(M=b[F])<32||M>126&&M<k){this._printHandler(b,R,F),R=F-1;break}}break;case 3:this._executeHandlers[M]?this._executeHandlers[M]():this._executeHandlerFb(M),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:R,code:M,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:const L=this._csiHandlers[this._collect<<8|M];let z=L?L.length-1:-1;for(;z>=0&&(T=L[z](this._params),T!==!0);z--)if(T instanceof Promise)return this._preserveStack(3,L,z,N,R),T;z<0&&this._csiHandlerFb(this._collect<<8|M,this._params),this.precedingJoinState=0;break;case 8:do switch(M){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(M-48)}while(++R<v&&(M=b[R])>47&&M<60);R--;break;case 9:this._collect<<=8,this._collect|=M;break;case 10:const H=this._escHandlers[this._collect<<8|M];let q=H?H.length-1:-1;for(;q>=0&&(T=H[q](),T!==!0);q--)if(T instanceof Promise)return this._preserveStack(4,H,q,N,R),T;q<0&&this._escHandlerFb(this._collect<<8|M),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|M,this._params);break;case 13:for(let F=R+1;;++F)if(F>=v||(M=b[F])===24||M===26||M===27||M>127&&M<k){this._dcsParser.put(b,R,F),R=F-1;break}break;case 14:if(T=this._dcsParser.unhook(M!==24&&M!==26),T)return this._preserveStack(6,[],0,N,R),T;M===27&&(N|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let F=R+1;;F++)if(F>=v||(M=b[F])<32||M>127&&M<k){this._oscParser.put(b,R,F),R=F-1;break}break;case 6:if(T=this._oscParser.end(M!==24&&M!==26),T)return this._preserveStack(5,[],0,N,R),T;M===27&&(N|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0}this.currentState=15&N}}}o.EscapeSequenceParser=w},6242:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.OscHandler=o.OscParser=void 0;const d=h(5770),m=h(482),p=[];o.OscParser=class{constructor(){this._state=0,this._active=p,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(x,S){this._handlers[x]===void 0&&(this._handlers[x]=[]);const k=this._handlers[x];return k.push(S),{dispose:()=>{const w=k.indexOf(S);w!==-1&&k.splice(w,1)}}}clearHandler(x){this._handlers[x]&&delete this._handlers[x]}setHandlerFallback(x){this._handlerFb=x}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=p}reset(){if(this._state===2)for(let x=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;x>=0;--x)this._active[x].end(!1);this._stack.paused=!1,this._active=p,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||p,this._active.length)for(let x=this._active.length-1;x>=0;x--)this._active[x].start();else this._handlerFb(this._id,"START")}_put(x,S,k){if(this._active.length)for(let w=this._active.length-1;w>=0;w--)this._active[w].put(x,S,k);else this._handlerFb(this._id,"PUT",(0,m.utf32ToString)(x,S,k))}start(){this.reset(),this._state=1}put(x,S,k){if(this._state!==3){if(this._state===1)for(;S<k;){const w=x[S++];if(w===59){this._state=2,this._start();break}if(w<48||57<w)return void(this._state=3);this._id===-1&&(this._id=0),this._id=10*this._id+w-48}this._state===2&&k-S>0&&this._put(x,S,k)}}end(x,S=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),this._active.length){let k=!1,w=this._active.length-1,_=!1;if(this._stack.paused&&(w=this._stack.loopPosition-1,k=S,_=this._stack.fallThrough,this._stack.paused=!1),!_&&k===!1){for(;w>=0&&(k=this._active[w].end(x),k!==!0);w--)if(k instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=w,this._stack.fallThrough=!1,k;w--}for(;w>=0;w--)if(k=this._active[w].end(!1),k instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=w,this._stack.fallThrough=!0,k}else this._handlerFb(this._id,"END",x);this._active=p,this._id=-1,this._state=0}}},o.OscHandler=class{constructor(x){this._handler=x,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(x,S,k){this._hitLimit||(this._data+=(0,m.utf32ToString)(x,S,k),this._data.length>d.PAYLOAD_LIMIT&&(this._data="",this._hitLimit=!0))}end(x){let S=!1;if(this._hitLimit)S=!1;else if(x&&(S=this._handler(this._data),S instanceof Promise))return S.then((k=>(this._data="",this._hitLimit=!1,k)));return this._data="",this._hitLimit=!1,S}}},8742:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.Params=void 0;const h=2147483647;class d{static fromArray(p){const x=new d;if(!p.length)return x;for(let S=Array.isArray(p[0])?1:0;S<p.length;++S){const k=p[S];if(Array.isArray(k))for(let w=0;w<k.length;++w)x.addSubParam(k[w]);else x.addParam(k)}return x}constructor(p=32,x=32){if(this.maxLength=p,this.maxSubParamsLength=x,x>256)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(p),this.length=0,this._subParams=new Int32Array(x),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(p),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}clone(){const p=new d(this.maxLength,this.maxSubParamsLength);return p.params.set(this.params),p.length=this.length,p._subParams.set(this._subParams),p._subParamsLength=this._subParamsLength,p._subParamsIdx.set(this._subParamsIdx),p._rejectDigits=this._rejectDigits,p._rejectSubDigits=this._rejectSubDigits,p._digitIsSub=this._digitIsSub,p}toArray(){const p=[];for(let x=0;x<this.length;++x){p.push(this.params[x]);const S=this._subParamsIdx[x]>>8,k=255&this._subParamsIdx[x];k-S>0&&p.push(Array.prototype.slice.call(this._subParams,S,k))}return p}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(p){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(p<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=p>h?h:p}}addSubParam(p){if(this._digitIsSub=!0,this.length)if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength)this._rejectSubDigits=!0;else{if(p<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=p>h?h:p,this._subParamsIdx[this.length-1]++}}hasSubParams(p){return(255&this._subParamsIdx[p])-(this._subParamsIdx[p]>>8)>0}getSubParams(p){const x=this._subParamsIdx[p]>>8,S=255&this._subParamsIdx[p];return S-x>0?this._subParams.subarray(x,S):null}getSubParamsAll(){const p={};for(let x=0;x<this.length;++x){const S=this._subParamsIdx[x]>>8,k=255&this._subParamsIdx[x];k-S>0&&(p[x]=this._subParams.slice(S,k))}return p}addDigit(p){let x;if(this._rejectDigits||!(x=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;const S=this._digitIsSub?this._subParams:this.params,k=S[x-1];S[x-1]=~k?Math.min(10*k+p,h):p}}o.Params=d},5741:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.AddonManager=void 0,o.AddonManager=class{constructor(){this._addons=[]}dispose(){for(let h=this._addons.length-1;h>=0;h--)this._addons[h].instance.dispose()}loadAddon(h,d){const m={instance:d,dispose:d.dispose,isDisposed:!1};this._addons.push(m),d.dispose=()=>this._wrappedAddonDispose(m),d.activate(h)}_wrappedAddonDispose(h){if(h.isDisposed)return;let d=-1;for(let m=0;m<this._addons.length;m++)if(this._addons[m]===h){d=m;break}if(d===-1)throw new Error("Could not dispose an addon that has not been loaded");h.isDisposed=!0,h.dispose.apply(h.instance),this._addons.splice(d,1)}}},8771:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.BufferApiView=void 0;const d=h(3785),m=h(511);o.BufferApiView=class{constructor(p,x){this._buffer=p,this.type=x}init(p){return this._buffer=p,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(p){const x=this._buffer.lines.get(p);if(x)return new d.BufferLineApiView(x)}getNullCell(){return new m.CellData}}},3785:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.BufferLineApiView=void 0;const d=h(511);o.BufferLineApiView=class{constructor(m){this._line=m}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(m,p){if(!(m<0||m>=this._line.length))return p?(this._line.loadCell(m,p),p):this._line.loadCell(m,new d.CellData)}translateToString(m,p,x){return this._line.translateToString(m,p,x)}}},8285:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.BufferNamespaceApi=void 0;const d=h(8771),m=h(8460),p=h(844);class x extends p.Disposable{constructor(k){super(),this._core=k,this._onBufferChange=this.register(new m.EventEmitter),this.onBufferChange=this._onBufferChange.event,this._normal=new d.BufferApiView(this._core.buffers.normal,"normal"),this._alternate=new d.BufferApiView(this._core.buffers.alt,"alternate"),this._core.buffers.onBufferActivate((()=>this._onBufferChange.fire(this.active)))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw new Error("Active buffer is neither normal nor alternate")}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}}o.BufferNamespaceApi=x},7975:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.ParserApi=void 0,o.ParserApi=class{constructor(h){this._core=h}registerCsiHandler(h,d){return this._core.registerCsiHandler(h,(m=>d(m.toArray())))}addCsiHandler(h,d){return this.registerCsiHandler(h,d)}registerDcsHandler(h,d){return this._core.registerDcsHandler(h,((m,p)=>d(m,p.toArray())))}addDcsHandler(h,d){return this.registerDcsHandler(h,d)}registerEscHandler(h,d){return this._core.registerEscHandler(h,d)}addEscHandler(h,d){return this.registerEscHandler(h,d)}registerOscHandler(h,d){return this._core.registerOscHandler(h,d)}addOscHandler(h,d){return this.registerOscHandler(h,d)}}},7090:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.UnicodeApi=void 0,o.UnicodeApi=class{constructor(h){this._core=h}register(h){this._core.unicodeService.register(h)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(h){this._core.unicodeService.activeVersion=h}}},744:function(f,o,h){var d=this&&this.__decorate||function(_,b,v,y){var T,M=arguments.length,N=M<3?b:y===null?y=Object.getOwnPropertyDescriptor(b,v):y;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")N=Reflect.decorate(_,b,v,y);else for(var O=_.length-1;O>=0;O--)(T=_[O])&&(N=(M<3?T(N):M>3?T(b,v,N):T(b,v))||N);return M>3&&N&&Object.defineProperty(b,v,N),N},m=this&&this.__param||function(_,b){return function(v,y){b(v,y,_)}};Object.defineProperty(o,"__esModule",{value:!0}),o.BufferService=o.MINIMUM_ROWS=o.MINIMUM_COLS=void 0;const p=h(8460),x=h(844),S=h(5295),k=h(2585);o.MINIMUM_COLS=2,o.MINIMUM_ROWS=1;let w=o.BufferService=class extends x.Disposable{get buffer(){return this.buffers.active}constructor(_){super(),this.isUserScrolling=!1,this._onResize=this.register(new p.EventEmitter),this.onResize=this._onResize.event,this._onScroll=this.register(new p.EventEmitter),this.onScroll=this._onScroll.event,this.cols=Math.max(_.rawOptions.cols||0,o.MINIMUM_COLS),this.rows=Math.max(_.rawOptions.rows||0,o.MINIMUM_ROWS),this.buffers=this.register(new S.BufferSet(_,this))}resize(_,b){this.cols=_,this.rows=b,this.buffers.resize(_,b),this._onResize.fire({cols:_,rows:b})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(_,b=!1){const v=this.buffer;let y;y=this._cachedBlankLine,y&&y.length===this.cols&&y.getFg(0)===_.fg&&y.getBg(0)===_.bg||(y=v.getBlankLine(_,b),this._cachedBlankLine=y),y.isWrapped=b;const T=v.ybase+v.scrollTop,M=v.ybase+v.scrollBottom;if(v.scrollTop===0){const N=v.lines.isFull;M===v.lines.length-1?N?v.lines.recycle().copyFrom(y):v.lines.push(y.clone()):v.lines.splice(M+1,0,y.clone()),N?this.isUserScrolling&&(v.ydisp=Math.max(v.ydisp-1,0)):(v.ybase++,this.isUserScrolling||v.ydisp++)}else{const N=M-T+1;v.lines.shiftElements(T+1,N-1,-1),v.lines.set(M,y.clone())}this.isUserScrolling||(v.ydisp=v.ybase),this._onScroll.fire(v.ydisp)}scrollLines(_,b,v){const y=this.buffer;if(_<0){if(y.ydisp===0)return;this.isUserScrolling=!0}else _+y.ydisp>=y.ybase&&(this.isUserScrolling=!1);const T=y.ydisp;y.ydisp=Math.max(Math.min(y.ydisp+_,y.ybase),0),T!==y.ydisp&&(b||this._onScroll.fire(y.ydisp))}};o.BufferService=w=d([m(0,k.IOptionsService)],w)},7994:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.CharsetService=void 0,o.CharsetService=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(h){this.glevel=h,this.charset=this._charsets[h]}setgCharset(h,d){this._charsets[h]=d,this.glevel===h&&(this.charset=d)}}},1753:function(f,o,h){var d=this&&this.__decorate||function(y,T,M,N){var O,R=arguments.length,L=R<3?T:N===null?N=Object.getOwnPropertyDescriptor(T,M):N;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")L=Reflect.decorate(y,T,M,N);else for(var z=y.length-1;z>=0;z--)(O=y[z])&&(L=(R<3?O(L):R>3?O(T,M,L):O(T,M))||L);return R>3&&L&&Object.defineProperty(T,M,L),L},m=this&&this.__param||function(y,T){return function(M,N){T(M,N,y)}};Object.defineProperty(o,"__esModule",{value:!0}),o.CoreMouseService=void 0;const p=h(2585),x=h(8460),S=h(844),k={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:y=>y.button!==4&&y.action===1&&(y.ctrl=!1,y.alt=!1,y.shift=!1,!0)},VT200:{events:19,restrict:y=>y.action!==32},DRAG:{events:23,restrict:y=>y.action!==32||y.button!==3},ANY:{events:31,restrict:y=>!0}};function w(y,T){let M=(y.ctrl?16:0)|(y.shift?4:0)|(y.alt?8:0);return y.button===4?(M|=64,M|=y.action):(M|=3&y.button,4&y.button&&(M|=64),8&y.button&&(M|=128),y.action===32?M|=32:y.action!==0||T||(M|=3)),M}const _=String.fromCharCode,b={DEFAULT:y=>{const T=[w(y,!1)+32,y.col+32,y.row+32];return T[0]>255||T[1]>255||T[2]>255?"":`\x1B[M${_(T[0])}${_(T[1])}${_(T[2])}`},SGR:y=>{const T=y.action===0&&y.button!==4?"m":"M";return`\x1B[<${w(y,!0)};${y.col};${y.row}${T}`},SGR_PIXELS:y=>{const T=y.action===0&&y.button!==4?"m":"M";return`\x1B[<${w(y,!0)};${y.x};${y.y}${T}`}};let v=o.CoreMouseService=class extends S.Disposable{constructor(y,T){super(),this._bufferService=y,this._coreService=T,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._onProtocolChange=this.register(new x.EventEmitter),this.onProtocolChange=this._onProtocolChange.event;for(const M of Object.keys(k))this.addProtocol(M,k[M]);for(const M of Object.keys(b))this.addEncoding(M,b[M]);this.reset()}addProtocol(y,T){this._protocols[y]=T}addEncoding(y,T){this._encodings[y]=T}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(y){if(!this._protocols[y])throw new Error(`unknown protocol "${y}"`);this._activeProtocol=y,this._onProtocolChange.fire(this._protocols[y].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(y){if(!this._encodings[y])throw new Error(`unknown encoding "${y}"`);this._activeEncoding=y}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null}triggerMouseEvent(y){if(y.col<0||y.col>=this._bufferService.cols||y.row<0||y.row>=this._bufferService.rows||y.button===4&&y.action===32||y.button===3&&y.action!==32||y.button!==4&&(y.action===2||y.action===3)||(y.col++,y.row++,y.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,y,this._activeEncoding==="SGR_PIXELS"))||!this._protocols[this._activeProtocol].restrict(y))return!1;const T=this._encodings[this._activeEncoding](y);return T&&(this._activeEncoding==="DEFAULT"?this._coreService.triggerBinaryEvent(T):this._coreService.triggerDataEvent(T,!0)),this._lastEvent=y,!0}explainEvents(y){return{down:!!(1&y),up:!!(2&y),drag:!!(4&y),move:!!(8&y),wheel:!!(16&y)}}_equalEvents(y,T,M){if(M){if(y.x!==T.x||y.y!==T.y)return!1}else if(y.col!==T.col||y.row!==T.row)return!1;return y.button===T.button&&y.action===T.action&&y.ctrl===T.ctrl&&y.alt===T.alt&&y.shift===T.shift}};o.CoreMouseService=v=d([m(0,p.IBufferService),m(1,p.ICoreService)],v)},6975:function(f,o,h){var d=this&&this.__decorate||function(v,y,T,M){var N,O=arguments.length,R=O<3?y:M===null?M=Object.getOwnPropertyDescriptor(y,T):M;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")R=Reflect.decorate(v,y,T,M);else for(var L=v.length-1;L>=0;L--)(N=v[L])&&(R=(O<3?N(R):O>3?N(y,T,R):N(y,T))||R);return O>3&&R&&Object.defineProperty(y,T,R),R},m=this&&this.__param||function(v,y){return function(T,M){y(T,M,v)}};Object.defineProperty(o,"__esModule",{value:!0}),o.CoreService=void 0;const p=h(1439),x=h(8460),S=h(844),k=h(2585),w=Object.freeze({insertMode:!1}),_=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,origin:!1,reverseWraparound:!1,sendFocus:!1,wraparound:!0});let b=o.CoreService=class extends S.Disposable{constructor(v,y,T){super(),this._bufferService=v,this._logService=y,this._optionsService=T,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this.register(new x.EventEmitter),this.onData=this._onData.event,this._onUserInput=this.register(new x.EventEmitter),this.onUserInput=this._onUserInput.event,this._onBinary=this.register(new x.EventEmitter),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this.register(new x.EventEmitter),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=(0,p.clone)(w),this.decPrivateModes=(0,p.clone)(_)}reset(){this.modes=(0,p.clone)(w),this.decPrivateModes=(0,p.clone)(_)}triggerDataEvent(v,y=!1){if(this._optionsService.rawOptions.disableStdin)return;const T=this._bufferService.buffer;y&&this._optionsService.rawOptions.scrollOnUserInput&&T.ybase!==T.ydisp&&this._onRequestScrollToBottom.fire(),y&&this._onUserInput.fire(),this._logService.debug(`sending data "${v}"`,(()=>v.split("").map((M=>M.charCodeAt(0))))),this._onData.fire(v)}triggerBinaryEvent(v){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${v}"`,(()=>v.split("").map((y=>y.charCodeAt(0))))),this._onBinary.fire(v))}};o.CoreService=b=d([m(0,k.IBufferService),m(1,k.ILogService),m(2,k.IOptionsService)],b)},9074:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.DecorationService=void 0;const d=h(8055),m=h(8460),p=h(844),x=h(6106);let S=0,k=0;class w extends p.Disposable{get decorations(){return this._decorations.values()}constructor(){super(),this._decorations=new x.SortedList((v=>v==null?void 0:v.marker.line)),this._onDecorationRegistered=this.register(new m.EventEmitter),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this.register(new m.EventEmitter),this.onDecorationRemoved=this._onDecorationRemoved.event,this.register((0,p.toDisposable)((()=>this.reset())))}registerDecoration(v){if(v.marker.isDisposed)return;const y=new _(v);if(y){const T=y.marker.onDispose((()=>y.dispose()));y.onDispose((()=>{y&&(this._decorations.delete(y)&&this._onDecorationRemoved.fire(y),T.dispose())})),this._decorations.insert(y),this._onDecorationRegistered.fire(y)}return y}reset(){for(const v of this._decorations.values())v.dispose();this._decorations.clear()}*getDecorationsAtCell(v,y,T){let M=0,N=0;for(const O of this._decorations.getKeyIterator(y))M=O.options.x??0,N=M+(O.options.width??1),v>=M&&v<N&&(!T||(O.options.layer??"bottom")===T)&&(yield O)}forEachDecorationAtCell(v,y,T,M){this._decorations.forEachByKey(y,(N=>{S=N.options.x??0,k=S+(N.options.width??1),v>=S&&v<k&&(!T||(N.options.layer??"bottom")===T)&&M(N)}))}}o.DecorationService=w;class _ extends p.Disposable{get isDisposed(){return this._isDisposed}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=d.css.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=d.css.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}constructor(v){super(),this.options=v,this.onRenderEmitter=this.register(new m.EventEmitter),this.onRender=this.onRenderEmitter.event,this._onDispose=this.register(new m.EventEmitter),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=v.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}dispose(){this._onDispose.fire(),super.dispose()}}},4348:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.InstantiationService=o.ServiceCollection=void 0;const d=h(2585),m=h(8343);class p{constructor(...S){this._entries=new Map;for(const[k,w]of S)this.set(k,w)}set(S,k){const w=this._entries.get(S);return this._entries.set(S,k),w}forEach(S){for(const[k,w]of this._entries.entries())S(k,w)}has(S){return this._entries.has(S)}get(S){return this._entries.get(S)}}o.ServiceCollection=p,o.InstantiationService=class{constructor(){this._services=new p,this._services.set(d.IInstantiationService,this)}setService(x,S){this._services.set(x,S)}getService(x){return this._services.get(x)}createInstance(x,...S){const k=(0,m.getServiceDependencies)(x).sort(((b,v)=>b.index-v.index)),w=[];for(const b of k){const v=this._services.get(b.id);if(!v)throw new Error(`[createInstance] ${x.name} depends on UNKNOWN service ${b.id}.`);w.push(v)}const _=k.length>0?k[0].index:S.length;if(S.length!==_)throw new Error(`[createInstance] First service dependency of ${x.name} at position ${_+1} conflicts with ${S.length} static arguments`);return new x(...S,...w)}}},7866:function(f,o,h){var d=this&&this.__decorate||function(_,b,v,y){var T,M=arguments.length,N=M<3?b:y===null?y=Object.getOwnPropertyDescriptor(b,v):y;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")N=Reflect.decorate(_,b,v,y);else for(var O=_.length-1;O>=0;O--)(T=_[O])&&(N=(M<3?T(N):M>3?T(b,v,N):T(b,v))||N);return M>3&&N&&Object.defineProperty(b,v,N),N},m=this&&this.__param||function(_,b){return function(v,y){b(v,y,_)}};Object.defineProperty(o,"__esModule",{value:!0}),o.traceCall=o.setTraceLogger=o.LogService=void 0;const p=h(844),x=h(2585),S={trace:x.LogLevelEnum.TRACE,debug:x.LogLevelEnum.DEBUG,info:x.LogLevelEnum.INFO,warn:x.LogLevelEnum.WARN,error:x.LogLevelEnum.ERROR,off:x.LogLevelEnum.OFF};let k,w=o.LogService=class extends p.Disposable{get logLevel(){return this._logLevel}constructor(_){super(),this._optionsService=_,this._logLevel=x.LogLevelEnum.OFF,this._updateLogLevel(),this.register(this._optionsService.onSpecificOptionChange("logLevel",(()=>this._updateLogLevel()))),k=this}_updateLogLevel(){this._logLevel=S[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(_){for(let b=0;b<_.length;b++)typeof _[b]=="function"&&(_[b]=_[b]())}_log(_,b,v){this._evalLazyOptionalParams(v),_.call(console,(this._optionsService.options.logger?"":"xterm.js: ")+b,...v)}trace(_,...b){var v;this._logLevel<=x.LogLevelEnum.TRACE&&this._log(((v=this._optionsService.options.logger)==null?void 0:v.trace.bind(this._optionsService.options.logger))??console.log,_,b)}debug(_,...b){var v;this._logLevel<=x.LogLevelEnum.DEBUG&&this._log(((v=this._optionsService.options.logger)==null?void 0:v.debug.bind(this._optionsService.options.logger))??console.log,_,b)}info(_,...b){var v;this._logLevel<=x.LogLevelEnum.INFO&&this._log(((v=this._optionsService.options.logger)==null?void 0:v.info.bind(this._optionsService.options.logger))??console.info,_,b)}warn(_,...b){var v;this._logLevel<=x.LogLevelEnum.WARN&&this._log(((v=this._optionsService.options.logger)==null?void 0:v.warn.bind(this._optionsService.options.logger))??console.warn,_,b)}error(_,...b){var v;this._logLevel<=x.LogLevelEnum.ERROR&&this._log(((v=this._optionsService.options.logger)==null?void 0:v.error.bind(this._optionsService.options.logger))??console.error,_,b)}};o.LogService=w=d([m(0,x.IOptionsService)],w),o.setTraceLogger=function(_){k=_},o.traceCall=function(_,b,v){if(typeof v.value!="function")throw new Error("not supported");const y=v.value;v.value=function(...T){if(k.logLevel!==x.LogLevelEnum.TRACE)return y.apply(this,T);k.trace(`GlyphRenderer#${y.name}(${T.map((N=>JSON.stringify(N))).join(", ")})`);const M=y.apply(this,T);return k.trace(`GlyphRenderer#${y.name} return`,M),M}}},7302:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.OptionsService=o.DEFAULT_OPTIONS=void 0;const d=h(8460),m=h(844),p=h(6114);o.DEFAULT_OPTIONS={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"courier-new, courier, monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},rescaleOverlappingGlyphs:!1,rightClickSelectsWord:p.isMac,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRulerWidth:0};const x=["normal","bold","100","200","300","400","500","600","700","800","900"];class S extends m.Disposable{constructor(w){super(),this._onOptionChange=this.register(new d.EventEmitter),this.onOptionChange=this._onOptionChange.event;const _={...o.DEFAULT_OPTIONS};for(const b in w)if(b in _)try{const v=w[b];_[b]=this._sanitizeAndValidateOption(b,v)}catch(v){console.error(v)}this.rawOptions=_,this.options={..._},this._setupOptions(),this.register((0,m.toDisposable)((()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null})))}onSpecificOptionChange(w,_){return this.onOptionChange((b=>{b===w&&_(this.rawOptions[w])}))}onMultipleOptionChange(w,_){return this.onOptionChange((b=>{w.indexOf(b)!==-1&&_()}))}_setupOptions(){const w=b=>{if(!(b in o.DEFAULT_OPTIONS))throw new Error(`No option with key "${b}"`);return this.rawOptions[b]},_=(b,v)=>{if(!(b in o.DEFAULT_OPTIONS))throw new Error(`No option with key "${b}"`);v=this._sanitizeAndValidateOption(b,v),this.rawOptions[b]!==v&&(this.rawOptions[b]=v,this._onOptionChange.fire(b))};for(const b in this.rawOptions){const v={get:w.bind(this,b),set:_.bind(this,b)};Object.defineProperty(this.options,b,v)}}_sanitizeAndValidateOption(w,_){switch(w){case"cursorStyle":if(_||(_=o.DEFAULT_OPTIONS[w]),!(function(b){return b==="block"||b==="underline"||b==="bar"})(_))throw new Error(`"${_}" is not a valid value for ${w}`);break;case"wordSeparator":_||(_=o.DEFAULT_OPTIONS[w]);break;case"fontWeight":case"fontWeightBold":if(typeof _=="number"&&1<=_&&_<=1e3)break;_=x.includes(_)?_:o.DEFAULT_OPTIONS[w];break;case"cursorWidth":_=Math.floor(_);case"lineHeight":case"tabStopWidth":if(_<1)throw new Error(`${w} cannot be less than 1, value: ${_}`);break;case"minimumContrastRatio":_=Math.max(1,Math.min(21,Math.round(10*_)/10));break;case"scrollback":if((_=Math.min(_,4294967295))<0)throw new Error(`${w} cannot be less than 0, value: ${_}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(_<=0)throw new Error(`${w} cannot be less than or equal to 0, value: ${_}`);break;case"rows":case"cols":if(!_&&_!==0)throw new Error(`${w} must be numeric, value: ${_}`);break;case"windowsPty":_=_??{}}return _}}o.OptionsService=S},2660:function(f,o,h){var d=this&&this.__decorate||function(S,k,w,_){var b,v=arguments.length,y=v<3?k:_===null?_=Object.getOwnPropertyDescriptor(k,w):_;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")y=Reflect.decorate(S,k,w,_);else for(var T=S.length-1;T>=0;T--)(b=S[T])&&(y=(v<3?b(y):v>3?b(k,w,y):b(k,w))||y);return v>3&&y&&Object.defineProperty(k,w,y),y},m=this&&this.__param||function(S,k){return function(w,_){k(w,_,S)}};Object.defineProperty(o,"__esModule",{value:!0}),o.OscLinkService=void 0;const p=h(2585);let x=o.OscLinkService=class{constructor(S){this._bufferService=S,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(S){const k=this._bufferService.buffer;if(S.id===void 0){const T=k.addMarker(k.ybase+k.y),M={data:S,id:this._nextId++,lines:[T]};return T.onDispose((()=>this._removeMarkerFromLink(M,T))),this._dataByLinkId.set(M.id,M),M.id}const w=S,_=this._getEntryIdKey(w),b=this._entriesWithId.get(_);if(b)return this.addLineToLink(b.id,k.ybase+k.y),b.id;const v=k.addMarker(k.ybase+k.y),y={id:this._nextId++,key:this._getEntryIdKey(w),data:w,lines:[v]};return v.onDispose((()=>this._removeMarkerFromLink(y,v))),this._entriesWithId.set(y.key,y),this._dataByLinkId.set(y.id,y),y.id}addLineToLink(S,k){const w=this._dataByLinkId.get(S);if(w&&w.lines.every((_=>_.line!==k))){const _=this._bufferService.buffer.addMarker(k);w.lines.push(_),_.onDispose((()=>this._removeMarkerFromLink(w,_)))}}getLinkData(S){var k;return(k=this._dataByLinkId.get(S))==null?void 0:k.data}_getEntryIdKey(S){return`${S.id};;${S.uri}`}_removeMarkerFromLink(S,k){const w=S.lines.indexOf(k);w!==-1&&(S.lines.splice(w,1),S.lines.length===0&&(S.data.id!==void 0&&this._entriesWithId.delete(S.key),this._dataByLinkId.delete(S.id)))}};o.OscLinkService=x=d([m(0,p.IBufferService)],x)},8343:(f,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.createDecorator=o.getServiceDependencies=o.serviceRegistry=void 0;const h="di$target",d="di$dependencies";o.serviceRegistry=new Map,o.getServiceDependencies=function(m){return m[d]||[]},o.createDecorator=function(m){if(o.serviceRegistry.has(m))return o.serviceRegistry.get(m);const p=function(x,S,k){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");(function(w,_,b){_[h]===_?_[d].push({id:w,index:b}):(_[d]=[{id:w,index:b}],_[h]=_)})(p,x,k)};return p.toString=()=>m,o.serviceRegistry.set(m,p),p}},2585:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.IDecorationService=o.IUnicodeService=o.IOscLinkService=o.IOptionsService=o.ILogService=o.LogLevelEnum=o.IInstantiationService=o.ICharsetService=o.ICoreService=o.ICoreMouseService=o.IBufferService=void 0;const d=h(8343);var m;o.IBufferService=(0,d.createDecorator)("BufferService"),o.ICoreMouseService=(0,d.createDecorator)("CoreMouseService"),o.ICoreService=(0,d.createDecorator)("CoreService"),o.ICharsetService=(0,d.createDecorator)("CharsetService"),o.IInstantiationService=(0,d.createDecorator)("InstantiationService"),(function(p){p[p.TRACE=0]="TRACE",p[p.DEBUG=1]="DEBUG",p[p.INFO=2]="INFO",p[p.WARN=3]="WARN",p[p.ERROR=4]="ERROR",p[p.OFF=5]="OFF"})(m||(o.LogLevelEnum=m={})),o.ILogService=(0,d.createDecorator)("LogService"),o.IOptionsService=(0,d.createDecorator)("OptionsService"),o.IOscLinkService=(0,d.createDecorator)("OscLinkService"),o.IUnicodeService=(0,d.createDecorator)("UnicodeService"),o.IDecorationService=(0,d.createDecorator)("DecorationService")},1480:(f,o,h)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.UnicodeService=void 0;const d=h(8460),m=h(225);class p{static extractShouldJoin(S){return(1&S)!=0}static extractWidth(S){return S>>1&3}static extractCharKind(S){return S>>3}static createPropertyValue(S,k,w=!1){return(16777215&S)<<3|(3&k)<<1|(w?1:0)}constructor(){this._providers=Object.create(null),this._active="",this._onChange=new d.EventEmitter,this.onChange=this._onChange.event;const S=new m.UnicodeV6;this.register(S),this._active=S.version,this._activeProvider=S}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(S){if(!this._providers[S])throw new Error(`unknown Unicode version "${S}"`);this._active=S,this._activeProvider=this._providers[S],this._onChange.fire(S)}register(S){this._providers[S.version]=S}wcwidth(S){return this._activeProvider.wcwidth(S)}getStringCellWidth(S){let k=0,w=0;const _=S.length;for(let b=0;b<_;++b){let v=S.charCodeAt(b);if(55296<=v&&v<=56319){if(++b>=_)return k+this.wcwidth(v);const M=S.charCodeAt(b);56320<=M&&M<=57343?v=1024*(v-55296)+M-56320+65536:k+=this.wcwidth(M)}const y=this.charProperties(v,w);let T=p.extractWidth(y);p.extractShouldJoin(y)&&(T-=p.extractWidth(w)),k+=T,w=y}return k}charProperties(S,k){return this._activeProvider.charProperties(S,k)}}o.UnicodeService=p}},a={};function l(f){var o=a[f];if(o!==void 0)return o.exports;var h=a[f]={exports:{}};return r[f].call(h.exports,h,h.exports,l),h.exports}var u={};return(()=>{var f=u;Object.defineProperty(f,"__esModule",{value:!0}),f.Terminal=void 0;const o=l(9042),h=l(3236),d=l(844),m=l(5741),p=l(8285),x=l(7975),S=l(7090),k=["cols","rows"];class w extends d.Disposable{constructor(b){super(),this._core=this.register(new h.Terminal(b)),this._addonManager=this.register(new m.AddonManager),this._publicOptions={...this._core.options};const v=T=>this._core.options[T],y=(T,M)=>{this._checkReadonlyOptions(T),this._core.options[T]=M};for(const T in this._core.options){const M={get:v.bind(this,T),set:y.bind(this,T)};Object.defineProperty(this._publicOptions,T,M)}}_checkReadonlyOptions(b){if(k.includes(b))throw new Error(`Option "${b}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new Error("You must set the allowProposedApi option to true to use proposed API")}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||(this._parser=new x.ParserApi(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new S.UnicodeApi(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||(this._buffer=this.register(new p.BufferNamespaceApi(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){const b=this._core.coreService.decPrivateModes;let v="none";switch(this._core.coreMouseService.activeProtocol){case"X10":v="x10";break;case"VT200":v="vt200";break;case"DRAG":v="drag";break;case"ANY":v="any"}return{applicationCursorKeysMode:b.applicationCursorKeys,applicationKeypadMode:b.applicationKeypad,bracketedPasteMode:b.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:v,originMode:b.origin,reverseWraparoundMode:b.reverseWraparound,sendFocusMode:b.sendFocus,wraparoundMode:b.wraparound}}get options(){return this._publicOptions}set options(b){for(const v in b)this._publicOptions[v]=b[v]}blur(){this._core.blur()}focus(){this._core.focus()}input(b,v=!0){this._core.input(b,v)}resize(b,v){this._verifyIntegers(b,v),this._core.resize(b,v)}open(b){this._core.open(b)}attachCustomKeyEventHandler(b){this._core.attachCustomKeyEventHandler(b)}attachCustomWheelEventHandler(b){this._core.attachCustomWheelEventHandler(b)}registerLinkProvider(b){return this._core.registerLinkProvider(b)}registerCharacterJoiner(b){return this._checkProposedApi(),this._core.registerCharacterJoiner(b)}deregisterCharacterJoiner(b){this._checkProposedApi(),this._core.deregisterCharacterJoiner(b)}registerMarker(b=0){return this._verifyIntegers(b),this._core.registerMarker(b)}registerDecoration(b){return this._checkProposedApi(),this._verifyPositiveIntegers(b.x??0,b.width??0,b.height??0),this._core.registerDecoration(b)}hasSelection(){return this._core.hasSelection()}select(b,v,y){this._verifyIntegers(b,v,y),this._core.select(b,v,y)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(b,v){this._verifyIntegers(b,v),this._core.selectLines(b,v)}dispose(){super.dispose()}scrollLines(b){this._verifyIntegers(b),this._core.scrollLines(b)}scrollPages(b){this._verifyIntegers(b),this._core.scrollPages(b)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(b){this._verifyIntegers(b),this._core.scrollToLine(b)}clear(){this._core.clear()}write(b,v){this._core.write(b,v)}writeln(b,v){this._core.write(b),this._core.write(`\r
|
|
92
92
|
`,v)}paste(b){this._core.paste(b)}refresh(b,v){this._verifyIntegers(b,v),this._core.refresh(b,v)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(b){this._addonManager.loadAddon(this,b)}static get strings(){return o}_verifyIntegers(...b){for(const v of b)if(v===1/0||isNaN(v)||v%1!=0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...b){for(const v of b)if(v&&(v===1/0||isNaN(v)||v%1!=0||v<0))throw new Error("This API only accepts positive integers")}}f.Terminal=w})(),u})()))})(_d)),_d.exports}var TO=kO(),vd={exports:{}},qv;function AO(){return qv||(qv=1,(function(e,n){(function(r,a){e.exports=a()})(self,(()=>(()=>{var r={};return(()=>{var a=r;Object.defineProperty(a,"__esModule",{value:!0}),a.FitAddon=void 0,a.FitAddon=class{activate(l){this._terminal=l}dispose(){}fit(){const l=this.proposeDimensions();if(!l||!this._terminal||isNaN(l.cols)||isNaN(l.rows))return;const u=this._terminal._core;this._terminal.rows===l.rows&&this._terminal.cols===l.cols||(u._renderService.clear(),this._terminal.resize(l.cols,l.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;const l=this._terminal._core,u=l._renderService.dimensions;if(u.css.cell.width===0||u.css.cell.height===0)return;const f=this._terminal.options.scrollback===0?0:l.viewport.scrollBarWidth,o=window.getComputedStyle(this._terminal.element.parentElement),h=parseInt(o.getPropertyValue("height")),d=Math.max(0,parseInt(o.getPropertyValue("width"))),m=window.getComputedStyle(this._terminal.element),p=h-(parseInt(m.getPropertyValue("padding-top"))+parseInt(m.getPropertyValue("padding-bottom"))),x=d-(parseInt(m.getPropertyValue("padding-right"))+parseInt(m.getPropertyValue("padding-left")))-f;return{cols:Math.max(2,Math.floor(x/u.css.cell.width)),rows:Math.max(1,Math.floor(p/u.css.cell.height))}}}})(),r})()))})(vd)),vd.exports}var NO=AO();function os(e,n){const r=getComputedStyle(document.documentElement).getPropertyValue(e).trim();return r?`rgb(${r})`:n}function RO(e,n,r){const a=getComputedStyle(document.documentElement).getPropertyValue(e).trim();return a?`rgb(${a} / ${n})`:r}function Kv(){return{background:os("--c-canvas","#0b0d0f"),foreground:os("--c-content-primary","#e6e8eb"),cursor:os("--c-accent","#2dd4bf"),selectionBackground:RO("--c-accent",.22,"rgba(45,212,191,0.25)"),black:os("--c-content-faint","#4e535a"),brightBlack:os("--c-content-muted","#70767e"),white:os("--c-content-secondary","#9ea5ad"),brightWhite:os("--c-content-primary","#e9ebee")}}function MO(e,n){const r=re.useRef(null),a=re.useRef(null),l=re.useRef(null);return re.useEffect(()=>{if(!r.current||!e)return;const u=new TO.Terminal({fontFamily:"JetBrains Mono, ui-monospace, monospace",fontSize:13,cursorBlink:!0,theme:Kv(),scrollback:5e3}),f=new NO.FitAddon;u.loadAddon(f),u.open(r.current),f.fit(),a.current=u,l.current=f;const o=e.terminalBuffer(n);o&&u.write(o);const h=u.onData(S=>e.sendInput(n,S)),d=u.onResize(({cols:S,rows:k})=>e.sendResize(n,S,k)),m=e.onEvent(S=>{if(S.type==="terminal.reset"&&S.terminalId===n){u.reset();return}S.type==="terminal.output"&&S.terminalId===n&&u.write(S.data)}),p=new ResizeObserver(()=>{try{f.fit(),e.sendResize(n,u.cols,u.rows)}catch{}});p.observe(r.current);const x=new MutationObserver(()=>{u.options.theme=Kv()});return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),e.sendResize(n,u.cols,u.rows),()=>{h.dispose(),d.dispose(),m(),p.disconnect(),x.disconnect(),u.dispose(),a.current=null,l.current=null}},[e,n]),{containerRef:r}}function Gv(e,n){return e==="default"?"默认":n||e.slice(0,8)}const s0=e=>`linkshell:web:lastTerminal:${e}`;function OO(e){if(!e)return null;try{return localStorage.getItem(s0(e))}catch{return null}}function DO(e,n){if(e)try{localStorage.setItem(s0(e),n)}catch{}}function LO(e,n){if(e.length===0)return null;if(n&&e.includes(n))return n;const r=e.filter(a=>a!=="default");return r.length>0?r[r.length-1]:e[0]}function IO({bridge:e,terminalId:n}){const{containerRef:r}=MO(e,n);return C.jsx("div",{ref:r,className:"xterm-host min-h-0 flex-1 bg-canvas p-2"})}function BO({bridge:e,onNewTerminal:n}){const r=e==null?void 0:e.sessionId,[a,l]=re.useState([]),[u,f]=re.useState("default"),o=re.useRef(!1),h=re.useRef(!1),d=re.useCallback((x,S)=>{l(k=>k.some(w=>w.id===x)?k:[...k,{id:x,label:Gv(x,S)}])},[]);re.useEffect(()=>{if(!e)return;o.current=!1,h.current=!1;const x=OO(r);return e.requestTerminalList(),e.onEvent(k=>{if(k.type==="terminal.output"){d(k.terminalId);return}if(k.type==="terminal.list"){const w=k.envelope,_=w.payload;if(w.type==="terminal.spawned"){const b=_==null?void 0:_.terminalId;b&&(d(b,_==null?void 0:_.projectName),f(b));return}if(w.type==="terminal.list"){const y=(Array.isArray(_==null?void 0:_.terminals)?_.terminals:[]).filter(T=>typeof T.terminalId=="string"&&T.status!=="exited").map(T=>({id:T.terminalId,label:Gv(T.terminalId,T.projectName)}));if(l(y),!o.current){o.current=!0;const T=y.map(N=>N.id),M=LO(T,x);M?f(M):h.current||(h.current=!0,n==null||n())}}}})},[e,d,n]),re.useEffect(()=>{o.current&&u&&DO(r,u)},[r,u]);const m=()=>n==null?void 0:n(),p=x=>{e==null||e.killTerminal(x),l(S=>{var w;const k=S.filter(_=>_.id!==x);return x===u&&f(((w=k[k.length-1])==null?void 0:w.id)??"default"),k})};return C.jsxs("div",{className:"flex h-full flex-col bg-canvas",children:[C.jsxs("div",{className:"flex items-center gap-0.5 border-b border-border bg-surface-raised px-1.5 py-1",children:[C.jsx(Ed,{size:13,className:"mx-1 shrink-0 text-content-faint"}),C.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",children:a.map(x=>C.jsxs("div",{className:`group flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-2xs transition-colors ${x.id===u?"bg-surface-overlay text-content-primary":"text-content-muted hover:bg-surface-overlay/60"}`,children:[C.jsx("button",{onClick:()=>f(x.id),className:"cursor-pointer font-mono",children:x.label}),a.length>1&&C.jsx("button",{onClick:()=>p(x.id),className:"cursor-pointer rounded text-content-faint opacity-0 transition hover:text-danger group-hover:opacity-100","aria-label":"关闭终端",children:C.jsx(hi,{size:11})})]},x.id))}),C.jsx("button",{onClick:m,className:"ml-1 shrink-0 cursor-pointer rounded-md p-1 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent",title:"新建终端","aria-label":"新建终端",children:C.jsx(Ro,{size:14})})]}),C.jsx(IO,{bridge:e,terminalId:u},u)]})}function a0(e){if(!e||e==="—")return"(未知目录)";const n=e.replace(/\/+$/,"").split("/");return n[n.length-1]||e}function Vv(e,n){return e.status==="waiting_permission"?0:e.status==="running"?1:e.status==="error"?2:e.id===n?3:4}function PO(e){return(n,r)=>{const a=Vv(n,e)-Vv(r,e);return a!==0?a:r.lastActivityAt-n.lastActivityAt}}function zO(e){return e.status==="waiting_permission"||e.status==="running"||e.status==="error"}function jO(e){const n=new Map;for(const a of e){const l=a.cwd||"—";let u=n.get(l);u||(u={cwd:l,label:a0(l),providers:new Map},n.set(l,u));const f=u.providers.get(a.provider)??[];f.push(a),u.providers.set(a.provider,f)}for(const a of n.values())for(const l of a.providers.values())l.sort((u,f)=>f.lastActivityAt-u.lastActivityAt);const r=a=>{let l=0;for(const u of a.providers.values())for(const f of u)l=Math.max(l,f.lastActivityAt);return l};return[...n.values()].sort((a,l)=>r(l)-r(a))}function UO(e){return[...e.providers.entries()].map(([n,r])=>({provider:n,conversations:r})).sort((n,r)=>Yd(n.provider).localeCompare(Yd(r.provider)))}function Yd(e){return e==="claude"?"Claude":e==="codex"?"Codex":e}function bd(e){switch(e){case"running":return{text:"运行中",className:"border-success/30 bg-success/10 text-success",pulsing:!0};case"waiting_permission":return{text:"等待授权",className:"border-warning/40 bg-warning/10 text-warning",pulsing:!0};case"error":return{text:"异常",className:"border-danger/30 bg-danger/10 text-danger"};case"unavailable":return{text:"不可用",className:"border-border bg-surface-overlay text-content-faint"};case"idle":default:return{text:"空闲",className:"border-border bg-surface-overlay text-content-muted"}}}function Wv({deviceLabel:e,conversations:n,capabilities:r,activeConversationId:a,externalAgentStatus:l,externalAgentTitle:u,externalAgentProvider:f,store:o,onSelect:h,onNewConversation:d,onOpenExternalTerminal:m}){const x=((r==null?void 0:r.providers)??[]).filter(B=>B.enabled),[S,k]=re.useState(!1),w=re.useMemo(()=>n.filter(B=>B.archived).length,[n]),_=re.useCallback(B=>!(B.archived&&!S||B.model==="<synthetic>"),[S]),b=re.useMemo(()=>n.filter(_),[n,_]),v=re.useMemo(()=>b.filter(zO).sort(PO(a)),[b,a]),y=l==="running"||l==="waiting_permission"||l==="error",T=y||v.length>0,M=re.useMemo(()=>jO(b),[b]),[N,O]=re.useState(new Set),R=B=>O($=>{const P=new Set($);return P.has(B)?P.delete(B):P.add(B),P}),[L,z]=re.useState(null),[H,q]=re.useState(null),[F,W]=re.useState(null),[G,K]=re.useState(""),ne=re.useRef(!1),Q=()=>{z(null),q(null)},I=B=>{Q(),W(B.id),K(B.title&&B.title.trim()||"")},A=B=>{o.renameConversation(B.id,G),W(null)};return C.jsxs("div",{className:"flex h-full flex-col",children:[C.jsxs("div",{className:"flex items-center gap-2.5 border-b border-border px-3 py-3",children:[C.jsx(TS,{size:14,className:"shrink-0 text-content-faint"}),C.jsx("span",{className:"truncate font-mono text-[13px] font-semibold text-content-secondary",children:e})]}),C.jsxs("div",{className:"space-y-2 border-b border-border px-3 py-3",children:[C.jsx("p",{className:"text-2xs font-semibold uppercase tracking-wider text-content-faint",children:"新建对话"}),x.length===0?C.jsx("span",{className:"text-2xs text-content-faint",children:"等待能力…"}):C.jsx("div",{className:"flex flex-wrap gap-2",children:x.map(B=>C.jsxs("button",{onClick:()=>d(B.id),className:"codex-btn-outline text-2xs","aria-label":`新建 ${B.label} 对话`,children:[C.jsx(ea,{provider:B.id,size:13})," ",B.label]},B.id))})]}),T&&C.jsxs("div",{className:"border-b border-border px-3 py-3",children:[C.jsx("p",{className:"mb-2 text-2xs font-semibold uppercase tracking-wider text-content-faint",children:"活跃会话"}),C.jsxs("div",{className:"space-y-1",children:[y&&l&&C.jsxs("button",{onClick:m,className:"flex w-full cursor-pointer items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors duration-150 hover:bg-surface-overlay",title:"打开终端面板",children:[C.jsx(ea,{provider:f??"custom",size:14}),C.jsxs("span",{className:"min-w-0 flex-1",children:[C.jsxs("span",{className:"flex items-center gap-2",children:[C.jsx("span",{className:"truncate text-[13px] font-medium text-content-primary",children:u??"外部终端"}),(()=>{const B=bd(l);return C.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${B.className}`,children:[B.pulsing&&C.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse-dot"}),B.text]})})()]}),C.jsx("span",{className:"mt-0.5 block truncate font-mono text-2xs text-content-muted",children:e})]})]},"active:external-terminal"),v.map(B=>{const $=B.title&&B.title.trim()||B.lastMessagePreview&&B.lastMessagePreview.trim().slice(0,40)||`对话 ${B.id.slice(-6)}`,P=bd(B.status);return C.jsxs("button",{onClick:()=>h(B.id),className:`flex w-full cursor-pointer items-start gap-2 rounded-lg px-2 py-2 text-left transition-colors duration-150 hover:bg-surface-overlay ${B.id===a?"tree-row-active":""}`,title:B.cwd,children:[C.jsx(ea,{provider:B.provider,size:14}),C.jsxs("span",{className:"min-w-0 flex-1",children:[C.jsxs("span",{className:"flex items-center gap-2",children:[C.jsx("span",{className:"truncate text-[13px] font-medium text-content-primary",children:$}),C.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${P.className}`,children:[P.pulsing&&C.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse-dot"}),P.text]})]}),C.jsx("span",{className:"mt-0.5 block truncate font-mono text-2xs text-content-muted",children:a0(B.cwd)})]})]},`active:${B.id}`)})]})]}),C.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:M.length===0?C.jsx("p",{className:"px-3 py-2 text-2xs text-content-faint",children:S||w===0?"还没有对话":"没有未归档的对话"}):M.map(B=>{const $=`folder:${B.cwd}`,P=N.has($);return C.jsxs("div",{className:"py-1",children:[C.jsxs("button",{onClick:()=>R($),className:"tree-row",title:B.cwd,children:[P?C.jsx(Si,{size:12,className:"shrink-0 text-content-faint"}):C.jsx(Ir,{size:12,className:"shrink-0 text-content-faint"}),C.jsx(Lr,{size:13,className:"shrink-0 text-content-faint"}),C.jsx("span",{className:"truncate text-2xs font-semibold uppercase tracking-wider text-content-faint",children:B.label})]}),!P&&UO(B).map(({provider:oe,conversations:ye})=>{const pe=`prov:${B.cwd}:${oe}`,J=N.has(pe);return C.jsxs("div",{className:"pl-3",children:[C.jsxs("div",{className:"flex items-center gap-1",children:[C.jsxs("button",{onClick:()=>R(pe),className:"tree-row flex-1",children:[J?C.jsx(Si,{size:12,className:"shrink-0 text-content-faint"}):C.jsx(Ir,{size:12,className:"shrink-0 text-content-faint"}),C.jsx(ea,{provider:oe,size:13}),C.jsx("span",{className:"text-[13px] font-medium text-content-secondary",children:Yd(oe)}),C.jsxs("span",{className:"text-2xs text-content-faint",children:["(",ye.length,")"]})]}),C.jsx("button",{onClick:()=>d(oe,B.cwd==="—"?void 0:B.cwd),className:"cursor-pointer rounded-lg p-1.5 text-content-faint transition-colors hover:bg-surface-overlay hover:text-accent",title:"在此目录新建对话","aria-label":"新建对话",children:C.jsx(Ro,{size:13})})]}),!J&&ye.map(j=>{const me=j.title&&j.title.trim()||j.lastMessagePreview&&j.lastMessagePreview.trim().slice(0,40)||`对话 ${j.id.slice(-6)}`,ce=F===j.id,ee=L===j.id,le=bd(j.status);return C.jsxs("div",{className:"group relative",children:[ce?C.jsx("input",{autoFocus:!0,value:G,onChange:Ce=>K(Ce.target.value),onKeyDown:Ce=>{Ce.key==="Enter"?(Ce.preventDefault(),Ce.currentTarget.blur()):Ce.key==="Escape"&&(ne.current=!0,Ce.currentTarget.blur())},onBlur:()=>{if(ne.current){ne.current=!1,W(null);return}A(j)},placeholder:"对话名称",className:"block w-full rounded-lg border border-accent bg-surface py-2 pl-7 pr-3 text-[13px] text-content-primary outline-none"}):C.jsxs("button",{onClick:()=>h(j.id),className:`block w-full cursor-pointer rounded-lg py-2 pl-7 pr-9 text-left transition-colors duration-150 hover:bg-surface-overlay ${j.id===a?"tree-row-active":""}`,children:[C.jsxs("p",{className:"flex items-center gap-2",children:[C.jsx("span",{className:"truncate text-[13px] text-content-primary",children:me}),C.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${le.className}`,children:[le.pulsing&&C.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse-dot"}),le.text]}),j.archived&&C.jsx("span",{className:"shrink-0 rounded bg-surface-overlay px-1 text-2xs text-content-faint",children:"已归档"})]}),j.lastMessagePreview&&j.lastMessagePreview.trim()!==me&&C.jsx("p",{className:"mt-0.5 truncate text-2xs text-content-muted",children:j.lastMessagePreview})]}),!ce&&C.jsx("button",{onClick:Ce=>{Ce.stopPropagation(),q(null),z(ee?null:j.id)},className:`absolute right-1.5 top-1.5 cursor-pointer rounded-md p-1 text-content-faint transition-colors hover:bg-surface-overlay hover:text-content-primary ${ee?"opacity-100":"opacity-0 group-hover:opacity-100"}`,title:"更多操作","aria-label":"更多操作",children:C.jsx(IS,{size:14})}),ee&&C.jsxs(C.Fragment,{children:[C.jsx("button",{className:"fixed inset-0 z-10 cursor-default",onClick:Q,"aria-label":"关闭菜单"}),C.jsxs("div",{className:"absolute right-1.5 top-9 z-20 w-36 overflow-hidden rounded-lg border border-border bg-surface py-1 shadow-xl",children:[C.jsxs("button",{onClick:()=>I(j),className:"flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-2xs text-content-secondary transition-colors hover:bg-surface-overlay",children:[C.jsx(of,{size:13})," 改名"]}),C.jsxs("button",{onClick:()=>{o.setConversationArchived(j.id,!j.archived),Q()},className:"flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-2xs text-content-secondary transition-colors hover:bg-surface-overlay",children:[C.jsx(m_,{size:13})," ",j.archived?"取消归档":"归档"]}),C.jsxs("button",{onClick:()=>{H===j.id?(o.deleteConversation(j.id),Q()):q(j.id)},className:"flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-2xs text-danger transition-colors hover:bg-danger/10",children:[C.jsx(LS,{size:13})," ",H===j.id?"确认删除?":"删除"]})]})]})]},j.id)})]},oe)})]},B.cwd)})}),w>0&&C.jsxs("button",{onClick:()=>k(B=>!B),className:"flex items-center gap-2 border-t border-border px-3 py-2.5 text-left text-2xs text-content-faint transition-colors hover:bg-surface-overlay hover:text-content-secondary",children:[C.jsx(m_,{size:13,className:"shrink-0"}),S?"隐藏已归档":`显示已归档 (${w})`]})]})}const HO={none:"无",minimal:"极简",low:"低",medium:"中",high:"高",xhigh:"极高"},FO={read_only:"只读",workspace_write:"工作区写",full_access:"完全访问"};function yd({icon:e,value:n,options:r,render:a,onChange:l,title:u}){const[f,o]=re.useState(!1),h=re.useRef(null);if(re.useEffect(()=>{if(!f)return;const m=p=>{h.current&&!h.current.contains(p.target)&&o(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[f]),r.length===0)return null;const d=n??r[0];return C.jsxs("div",{ref:h,className:"relative",children:[C.jsxs("button",{type:"button",onClick:()=>o(m=>!m),title:u,className:"flex cursor-pointer items-center gap-1 rounded-full px-2 py-1 text-2xs font-medium text-content-secondary transition-colors hover:bg-surface-overlay hover:text-content-primary",children:[e,C.jsx("span",{className:"max-w-[7rem] truncate",children:a(d)}),C.jsx(Ir,{size:11,className:"text-content-faint"})]}),f&&C.jsx("div",{className:"codex-card-raised absolute bottom-full left-0 z-20 mb-1.5 min-w-[8rem] overflow-hidden p-1 animate-fade-in",children:r.map(m=>C.jsxs("button",{type:"button",onClick:()=>{l(m),o(!1)},className:`flex w-full cursor-pointer items-center justify-between gap-3 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors hover:bg-surface-overlay ${m===d?"text-content-primary":"text-content-secondary"}`,children:[C.jsx("span",{className:"truncate",children:a(m)}),m===d&&C.jsx(Mo,{size:13,className:"shrink-0 text-accent"})]},m))})]})}function $O({conversation:e,capability:n,onChange:r}){var d;const l=((n==null?void 0:n.models)??[]).filter(m=>m.id!=="default"),u=(n==null?void 0:n.reasoningEfforts)??[],f=(n==null?void 0:n.permissionModes)??[],o=(n==null?void 0:n.supportsPlan)??!1,h=e.collaborationMode==="plan";return C.jsxs(C.Fragment,{children:[l.length>0&&C.jsx(yd,{title:"模型",value:e.model??(n==null?void 0:n.defaultModel)??((d=l[0])==null?void 0:d.id),options:l.map(m=>m.id),render:m=>{var p;return((p=l.find(x=>x.id===m))==null?void 0:p.label)??m},onChange:m=>r({model:m})}),C.jsx(yd,{title:"推理强度",value:e.reasoningEffort,options:u,render:m=>HO[m]??m,onChange:m=>r({reasoningEffort:m})}),C.jsx(yd,{title:"权限",value:e.permissionMode,options:f,render:m=>FO[m]??m,onChange:m=>r({permissionMode:m})}),o&&C.jsxs("button",{type:"button",onClick:()=>r({collaborationMode:h?"default":"plan"}),className:`inline-flex cursor-pointer items-center gap-1 rounded-full px-2 py-1 text-2xs font-medium transition-colors ${h?"bg-accent-dim text-white":"text-content-secondary hover:bg-surface-overlay hover:text-content-primary"}`,title:"计划模式",children:[h&&C.jsx(Mo,{size:11}),"计划"]})]})}function qO({store:e,initialPath:n,onClose:r}){const[a,l]=re.useState(n||"."),[u,f]=re.useState([]),[o,h]=re.useState(!1),[d,m]=re.useState(null),[p,x]=re.useState(null),S=re.useCallback(async _=>{h(!0),m(null),x(null);try{const b=await e.browse(_,!0);b.error?m(b.error):(l(b.path),f([...b.entries].sort((v,y)=>v.isDirectory!==y.isDirectory?v.isDirectory?-1:1:v.name.localeCompare(y.name))))}catch(b){m(b.message||"浏览失败")}finally{h(!1)}},[e]);re.useEffect(()=>{S(n||".")},[S,n]);const k=async _=>{h(!0),m(null);try{const b=await e.readFile(_.path);b.error?m(b.error):x({path:b.path,content:b.content,truncated:b.truncated})}catch(b){m(b.message||"读取失败")}finally{h(!1)}},w=a.replace(/\/+$/,"").split("/").slice(0,-1).join("/")||"/";return C.jsxs("div",{className:"flex h-full flex-col bg-surface",children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[C.jsxs("span",{className:"flex items-center gap-1.5 font-mono text-2xs text-content-secondary",children:[C.jsx(Lr,{size:13,className:"text-content-faint"})," 文件"]}),C.jsx("button",{onClick:r,className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭文件面板",children:C.jsx(hi,{size:15})})]}),C.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-2 py-1.5",children:[C.jsx("button",{onClick:()=>S(w),disabled:o,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent",title:"上级目录","aria-label":"上级目录",children:C.jsx(rf,{size:14})}),C.jsx("input",{value:a,onChange:_=>l(_.target.value),onKeyDown:_=>_.key==="Enter"&&S(a),className:"flex-1 bg-transparent font-mono text-2xs text-content-primary outline-none"}),C.jsx("button",{onClick:()=>S(a),disabled:o,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent",title:"刷新","aria-label":"刷新",children:C.jsx(kc,{size:14})})]}),d&&C.jsx("p",{className:"px-3 py-1.5 text-2xs text-danger",children:d}),C.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[o&&C.jsx("p",{className:"px-3 py-2 text-2xs text-content-muted",children:"加载中…"}),!o&&p?C.jsxs("div",{children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[C.jsx("span",{className:"truncate font-mono text-2xs text-content-secondary",children:p.path}),C.jsx("button",{onClick:()=>x(null),className:"codex-btn-ghost text-2xs",children:"返回"})]}),C.jsxs("pre",{className:"whitespace-pre-wrap px-3 py-2 font-mono text-2xs leading-relaxed text-content-secondary",children:[p.content,p.truncated&&C.jsx("span",{className:"text-warning",children:`
|
|
93
93
|
…(已截断)`})]})]}):!o&&u.map(_=>C.jsxs("button",{onClick:()=>_.isDirectory?S(_.path):k(_),className:"flex w-full cursor-pointer items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-surface-overlay",children:[_.isDirectory?C.jsx(Lr,{size:13,className:"shrink-0 text-content-faint"}):C.jsx(na,{size:13,className:"shrink-0 text-content-faint"}),C.jsx("span",{className:"truncate font-mono text-2xs text-content-primary",children:_.name}),!_.isDirectory&&_.size!=null&&C.jsxs("span",{className:"ml-auto font-mono text-2xs text-content-faint",children:[_.size,"B"]})]},_.path))]})]})}function KO({store:e,initialPath:n,providerLabel:r,onCancel:a,onConfirm:l}){const[u,f]=re.useState(n||"."),[o,h]=re.useState([]),[d,m]=re.useState(!1),[p,x]=re.useState(null),S=re.useCallback(async w=>{m(!0),x(null);try{const _=await e.browse(w,!1);_.error?x(_.error):(f(_.path),h(_.entries.filter(b=>b.isDirectory).sort((b,v)=>b.name.localeCompare(v.name))))}catch(_){x(_.message||"无法读取目录")}finally{m(!1)}},[e]);re.useEffect(()=>{S(n||".")},[S,n]);const k=u.replace(/\/+$/,"").split("/").slice(0,-1).join("/")||"/";return C.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:a,children:C.jsxs("div",{className:"codex-card flex max-h-[80vh] w-full max-w-lg flex-col overflow-hidden",onClick:w=>w.stopPropagation(),children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[C.jsxs("h3",{className:"text-sm font-semibold",children:["选择工作目录 · ",r]}),C.jsx("button",{onClick:a,className:"codex-btn-ghost px-2 py-1.5","aria-label":"取消",children:C.jsx(hi,{size:15})})]}),C.jsxs("div",{className:"flex items-center gap-1 border-b border-border px-3 py-2",children:[C.jsx("button",{onClick:()=>S(k),disabled:d,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent",title:"上级目录","aria-label":"上级目录",children:C.jsx(rf,{size:14})}),C.jsx("input",{value:u,onChange:w=>f(w.target.value),onKeyDown:w=>w.key==="Enter"&&S(u),className:"flex-1 bg-transparent font-mono text-2xs text-content-primary outline-none"}),C.jsx("button",{onClick:()=>S(u),disabled:d,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent",title:"刷新","aria-label":"刷新",children:C.jsx(kc,{size:14})})]}),p&&C.jsx("p",{className:"px-4 py-2 text-2xs text-danger",children:p}),C.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:d?C.jsx("p",{className:"px-4 py-3 text-2xs text-content-muted",children:"加载中…"}):o.length===0?C.jsx("p",{className:"px-4 py-3 text-2xs text-content-faint",children:"(无子目录)"}):o.map(w=>C.jsxs("button",{onClick:()=>S(w.path),className:"flex w-full cursor-pointer items-center gap-2 px-4 py-1.5 text-left transition-colors hover:bg-surface-overlay",children:[C.jsx(Lr,{size:13,className:"shrink-0 text-content-faint"}),C.jsx("span",{className:"truncate font-mono text-2xs text-content-primary",children:w.name})]},w.path))}),C.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-border px-4 py-3",children:[C.jsxs("span",{className:"truncate font-mono text-2xs text-content-muted",title:u,children:["将在此创建:",u]}),C.jsx("button",{onClick:()=>l(u),disabled:d,className:"codex-btn-primary text-2xs",children:"在此新建"})]})]})})}const o0=[{cssProp:"color",label:"文本颜色"},{cssProp:"background-color",label:"背景"},{cssProp:"font-size",label:"字号"},{cssProp:"font-weight",label:"字重"},{cssProp:"padding",label:"内边距"},{cssProp:"border-radius",label:"圆角"}];function GO(e){var a;const n=(a=e.ownerDocument.defaultView)==null?void 0:a.getComputedStyle(e),r={};for(const{cssProp:l}of o0)r[l]=(n==null?void 0:n.getPropertyValue(l).trim())??"";return r}function VO(e){const n=/^\s*(\d{1,5})(.*)$/.exec(e);if(!n)return null;const r=n[1];if(Number(r)<1||Number(r)>65535)return null;let a=n[2]||"/";return a.startsWith("/")||(a=`/${a}`),{port:r,path:a}}function WO(e){if(e.id)return`#${CSS.escape(e.id)}`;const n=[];let r=e,a=0;for(;r&&r.nodeType===1&&a<4;){let l=r.tagName.toLowerCase();const u=(r.getAttribute("class")||"").trim().split(/\s+/).filter(Boolean).slice(0,2).map(o=>`.${CSS.escape(o)}`).join("");l+=u;const f=r.parentElement;if(f){const o=[...f.children].filter(h=>h.tagName===r.tagName);o.length>1&&(l+=`:nth-of-type(${o.indexOf(r)+1})`)}if(n.unshift(l),r.id){n[0]=`#${CSS.escape(r.id)}`;break}r=f,a+=1}return n.join(" > ")}function YO({gatewayUrl:e,sessionId:n,initialAuthToken:r,defaultPort:a,isMobile:l,onClose:u,onAnnotate:f}){const[o,h]=re.useState(a||"3000"),[d,m]=re.useState(null),[p,x]=re.useState(r??null),[S,k]=re.useState(!1),[w,_]=re.useState("desktop"),[b,v]=re.useState(0),[y,T]=re.useState(!1),[M,N]=re.useState(null),[O,R]=re.useState(null),[L,z]=re.useState(null),[H,q]=re.useState(""),[F,W]=re.useState(!1),[G,K]=re.useState({}),[ne,Q]=re.useState({}),I=re.useRef(null),A=re.useRef(null),B=re.useMemo(()=>ab(),[]);re.useEffect(()=>{let Ee=!1;return k(!1),nf().then(we=>{Ee||x((we==null?void 0:we.accessToken)??null)}).finally(()=>{Ee||k(!0)}),()=>{Ee=!0}},[r]);const $=re.useMemo(()=>{if(!d||r&&!S)return null;const Ee=`${e.replace(/\/+$/,"")}/tunnel/${encodeURIComponent(n)}/${d.port}${d.path}`,we=[];if(B&&we.push(`token=${encodeURIComponent(B)}`),p&&we.push(`auth_token=${encodeURIComponent(p)}`),we.length===0)return Ee;const ke=d.path.includes("?")?"&":"?";return`${Ee}${ke}${we.join("&")}`},[d,e,n,B,p,S]),P=()=>{const Ee=VO(o);Ee&&(m(Ee),v(we=>we+1))},oe=()=>v(Ee=>Ee+1),ye=()=>{var Ee;if(d)try{const we=(Ee=I.current)==null?void 0:Ee.contentWindow;if(!we)return;const ke=`/tunnel/${encodeURIComponent(n)}/${d.port}`;let Tt=we.location.pathname;Tt.startsWith(ke)&&(Tt=Tt.slice(ke.length)||"/");const Fe=new URLSearchParams(we.location.search);Fe.delete("token"),Fe.delete("auth_token");const At=Fe.toString();h(`${d.port}${Tt}${At?`?${At}`:""}`)}catch{}},pe=(Ee,we)=>{const ke=I.current,Tt=ke==null?void 0:ke.contentDocument;if(!ke||!Tt)return null;const Fe=ke.getBoundingClientRect();return Tt.elementFromPoint(Ee-Fe.left,we-Fe.top)},J=Ee=>{const we=Ee.getBoundingClientRect();return{top:we.top,left:we.left,width:we.width,height:we.height}},j=Ee=>{try{const we=pe(Ee.clientX,Ee.clientY);R(we?J(we):null)}catch{R(null),N("此页面跨域,无法读取元素(生产环境同源可用)"),T(!1)}},me=Ee=>{Ee.preventDefault();try{const we=pe(Ee.clientX,Ee.clientY);if(!we||!("style"in we))return;const ke=we;z({el:ke,selector:WO(ke),text:(ke.textContent||"").replace(/\s+/g," ").trim().slice(0,120),rect:J(ke)}),K(GO(ke)),Q({}),q("")}catch{N("此页面跨域,无法读取元素(生产环境同源可用)"),T(!1)}},ce=(Ee,we)=>{if(L){try{L.el.style.setProperty(Ee,we)}catch{}Q(ke=>({...ke,[Ee]:we}))}},ee=()=>Object.entries(ne).filter(([Ee,we])=>we!==(G[Ee]??"")).map(([Ee,we])=>({cssProp:Ee,from:G[Ee]??"",to:we})),le=()=>{if(!L)return;const Ee=ee(),we=["关于预览页面中的这个元素:",`- 选择器: \`${L.selector}\``,L.text?`- 文本: "${L.text}"`:"",`- 路径: localhost:${o}`,H.trim()?`- 批注: ${H.trim()}`:""];if(Ee.length>0){we.push("- 请把以下样式改动应用到源码:");for(const ke of Ee)we.push(` - ${ke.cssProp}: ${ke.from||"(默认)"} → ${ke.to}`)}f==null||f(we.filter(Boolean).join(`
|
|
94
|
-
`)),z(null),q(""),K({}),Q({}),W(!1),R(null),T(!1)},Ce=()=>{z(null),q(""),K({}),Q({}),W(!1)},He=()=>{N(null),Ce(),R(null),T(Ee=>!Ee)};return C.jsxs("div",{className:"flex h-full flex-col bg-canvas",children:[C.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-surface px-2 py-1.5",children:[l&&C.jsx("button",{onClick:u,className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭预览",children:C.jsx(hi,{size:15})}),C.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 rounded-lg border border-border bg-surface-raised px-2 py-1",children:[C.jsx("span",{className:"shrink-0 font-mono text-2xs text-content-faint",children:"localhost:"}),C.jsx("input",{value:o,onChange:Ee=>h(Ee.target.value),onKeyDown:Ee=>Ee.key==="Enter"&&P(),placeholder:"3000",spellCheck:!1,className:"min-w-0 flex-1 bg-transparent font-mono text-2xs text-content-primary outline-none","aria-label":"端口与路径"}),C.jsx("button",{onClick:P,className:"shrink-0 cursor-pointer rounded bg-accent-dim px-2 py-0.5 text-2xs font-medium text-white transition-colors hover:bg-accent",children:"前往"})]}),C.jsx("button",{onClick:He,disabled:!d,className:`shrink-0 cursor-pointer rounded-md p-1.5 transition-colors disabled:opacity-40 ${y?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-accent"}`,title:"标注元素","aria-label":"标注元素",children:C.jsx(zS,{size:14})}),C.jsxs("div",{className:"flex shrink-0 items-center rounded-lg border border-border bg-surface-raised p-0.5",children:[C.jsx("button",{onClick:()=>_("desktop"),className:`cursor-pointer rounded p-1 transition-colors ${w==="desktop"?"bg-surface-overlay text-content-primary":"text-content-muted hover:text-content-primary"}`,title:"桌面视口","aria-label":"桌面视口",children:C.jsx(tb,{size:13})}),C.jsx("button",{onClick:()=>_("mobile"),className:`cursor-pointer rounded p-1 transition-colors ${w==="mobile"?"bg-surface-overlay text-content-primary":"text-content-muted hover:text-content-primary"}`,title:"移动视口","aria-label":"移动视口",children:C.jsx(PS,{size:13})})]}),C.jsx("button",{onClick:oe,disabled:!d,className:"shrink-0 cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent disabled:opacity-40",title:"刷新","aria-label":"刷新",children:C.jsx(kc,{size:14})}),C.jsx("button",{onClick:()=>$&&window.open($,"_blank","noopener,noreferrer"),disabled:!$,className:"shrink-0 cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent disabled:opacity-40",title:"在新窗口打开","aria-label":"在新窗口打开",children:C.jsx(BS,{size:14})})]}),M&&C.jsx("p",{className:"border-b border-border bg-warning/10 px-3 py-1.5 text-2xs text-warning",children:M}),y&&!L&&C.jsx("p",{className:"border-b border-border bg-accent/10 px-3 py-1.5 text-2xs text-accent",children:"标注模式:移动鼠标高亮元素,点击选择并添加批注。"}),C.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-raised",children:$?C.jsx("div",{className:w==="mobile"?"mx-auto h-full w-[390px] max-w-full border-x border-border":"h-full w-full",children:C.jsxs("div",{className:"relative h-full w-full",children:[C.jsx("iframe",{ref:I,src:$,title:"端口预览",onLoad:ye,className:"h-full w-full bg-white"},`${$}-${b}`),y&&C.jsx("div",{className:"absolute inset-0 cursor-crosshair",onMouseMove:j,onMouseLeave:()=>R(null),onClick:me,children:O&&!L&&C.jsx("div",{className:"pointer-events-none absolute border-2 border-accent bg-accent/10",style:{top:O.top,left:O.left,width:O.width,height:O.height}})}),L&&(()=>{var Ot,wt;const ke=((Ot=A.current)==null?void 0:Ot.clientHeight)??600,Tt=L.rect.top+L.rect.height+8,Fe=L.rect.top-8,At=F?340:140,pn=Tt+At>ke&&Fe-At>0?Math.max(4,Fe-At):Tt,Nt=Math.max(4,Math.min(L.rect.left,(((wt=A.current)==null?void 0:wt.clientWidth)??800)-280-4));return C.jsxs("div",{className:"absolute z-20 flex flex-col gap-2 rounded-xl border border-accent-dim/40 bg-surface-raised px-3 py-2.5 shadow-2xl animate-fade-in",style:{top:pn,left:Nt,width:280,maxHeight:ke-pn-8},children:[C.jsx("p",{className:"truncate font-mono text-2xs text-content-faint",title:L.selector,children:L.selector}),L.text&&C.jsxs("p",{className:"-mt-1 truncate text-2xs text-content-muted",children:['"',L.text,'"']}),C.jsx("input",{value:H,onChange:ue=>q(ue.target.value),onKeyDown:ue=>ue.key==="Enter"&&le(),autoFocus:!0,placeholder:"添加批注…",className:"w-full rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-content-primary placeholder-content-muted outline-none focus:border-accent-dim"}),C.jsxs("button",{onClick:()=>W(ue=>!ue),className:`flex cursor-pointer items-center gap-1 self-start rounded-md px-1.5 py-0.5 text-2xs transition-colors ${F?"text-accent":"text-content-muted hover:text-content-secondary"}`,children:[C.jsx("svg",{width:10,height:10,viewBox:"0 0 10 10",className:`shrink-0 transition-transform ${F?"rotate-180":""}`,children:C.jsx("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})}),"调整样式"]}),F&&C.jsx("div",{className:"grid grid-cols-2 gap-x-2 gap-y-1.5 animate-fade-in",children:o0.map(({cssProp:ue,label:xe})=>{const Ie=ne[ue]??G[ue]??"",$e=ue in ne&&ne[ue]!==(G[ue]??"");return C.jsxs("label",{className:"flex flex-col gap-0.5",children:[C.jsx("span",{className:`text-2xs ${$e?"text-accent":"text-content-faint"}`,children:xe}),C.jsx("input",{value:Ie,onChange:Je=>ce(ue,Je.target.value),spellCheck:!1,className:"w-full rounded-md border border-border bg-surface px-2 py-1 font-mono text-2xs text-content-primary outline-none focus:border-accent-dim"})]},ue)})}),C.jsxs("div",{className:"flex items-center gap-2",children:[C.jsx("button",{onClick:Ce,className:"codex-btn-ghost flex-1 text-2xs",children:"取消"}),C.jsx("button",{onClick:le,className:"codex-btn-primary flex-1 text-2xs",children:"发送给 Agent"})]})]})})()]})}):C.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[C.jsx(hc,{size:34,className:"text-content-faint"}),C.jsx("p",{className:"text-sm leading-6 text-content-muted",children:d&&!S?"正在准备预览认证...":"输入主机上服务的端口号,预览远程本地服务"})]})})]})}const l0="linkshell_theme",wc=new Set;let Uc=ZO();function ZO(){try{const e=localStorage.getItem(l0);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"dark"}function XO(){return typeof window<"u"&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function QO(e=Uc){return e==="system"?XO()?"dark":"light":e}function Zd(){typeof document>"u"||document.documentElement.setAttribute("data-theme",QO())}function Yv(){return Uc}function Bf(e){Uc=e;try{localStorage.setItem(l0,e)}catch{}Zd();for(const n of wc)n()}function JO(e){return wc.add(e),()=>wc.delete(e)}function eD(){var e;if(Zd(),typeof window<"u"&&window.matchMedia){const n=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{if(Uc==="system"){Zd();for(const a of wc)a()}};(e=n.addEventListener)==null||e.call(n,"change",r)}}const xd=["light","dark","system"],Zv={light:"浅色",dark:"深色",system:"跟随系统"};function tD(){const e=re.useSyncExternalStore(JO,Yv,Yv),n=()=>Bf(xd[(xd.indexOf(e)+1)%xd.length]),r=e==="light"?RS:e==="dark"?MS:tb;return C.jsx("button",{onClick:n,className:"codex-btn-ghost px-2 py-1.5",title:`主题:${Zv[e]}(点击切换)`,"aria-label":`主题:${Zv[e]}`,children:C.jsx(r,{size:15})})}function nD(){try{const e=new URLSearchParams(window.location.search),n=e.get("embed")==="1",r=e.get("theme");return{embed:n,sessionId:e.get("session"),gateway:e.get("gateway"),token:e.get("token"),theme:r==="dark"||r==="light"?r:null}}catch{return{embed:!1,sessionId:null,gateway:null,token:null,theme:null}}}function iD(e){return!e.embed||!e.sessionId||!e.token||!e.gateway?null:(rb(e.gateway),uf(e.token),e.theme&&Bf(e.theme),Cd([{id:e.sessionId,state:"active",hasHost:!0,clientCount:1,provider:null,machineId:null,hostname:null,platform:null,projectName:null,cwd:null,lastActivity:Date.now()}]),{name:"console",sessionId:e.sessionId})}function rD(){try{const e=window.ReactNativeWebView;e==null||e.postMessage(JSON.stringify({type:"requestClose"}))}catch{}}const sD="linkshell_embed";function c0(){try{return new URLSearchParams(window.location.search).get("embed")==="1"?!0:localStorage.getItem(sD)==="1"}catch{return!1}}function aD(e,n){if(!e)return 0;const r=e.toLowerCase(),a=n.toLowerCase();let l=0,u=0,f=-1;for(let o=0;o<r.length;o++){const h=r[o],d=a.indexOf(h,l);if(d===-1)return null;f>=0?u+=d-f-1:u+=d,f=d,l=d+1}return u}function oD({open:e,onClose:n,actions:r,placeholder:a="搜索命令、对话…"}){const[l,u]=re.useState(""),[f,o]=re.useState(0),h=re.useRef(null);re.useEffect(()=>{e&&(u(""),o(0),requestAnimationFrame(()=>{var k;return(k=h.current)==null?void 0:k.focus()}))},[e]);const d=re.useMemo(()=>r.map(w=>({a:w,score:aD(l,`${w.label} ${w.hint??""} ${w.keywords??""}`)})).filter(w=>w.score!==null).sort((w,_)=>w.score-_.score).map(w=>w.a),[r,l]);if(re.useEffect(()=>{o(k=>Math.min(k,Math.max(0,d.length-1)))},[d.length]),!e)return null;const m=k=>{const w=d[k];w&&(n(),w.run())},p=k=>{k.key==="ArrowDown"?(k.preventDefault(),o(w=>Math.min(w+1,d.length-1))):k.key==="ArrowUp"?(k.preventDefault(),o(w=>Math.max(w-1,0))):k.key==="Enter"?(k.preventDefault(),m(f)):k.key==="Escape"&&(k.preventDefault(),n())};let x=-1;const S=new Map;for(const k of d){const w=k.group??"",_=S.get(w)??[];_.push(k),S.set(w,_)}return C.jsx("div",{className:"fixed inset-0 z-[60] flex items-start justify-center bg-canvas/60 px-4 pt-[12vh] backdrop-blur-sm animate-fade-in",onClick:n,children:C.jsxs("div",{className:"codex-card-raised w-full max-w-xl overflow-hidden",onClick:k=>k.stopPropagation(),children:[C.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3.5 py-3",children:[C.jsx(ls,{size:16,className:"shrink-0 text-content-faint"}),C.jsx("input",{ref:h,value:l,onChange:k=>u(k.target.value),onKeyDown:p,placeholder:a,className:"min-w-0 flex-1 bg-transparent text-[15px] text-content-primary placeholder-content-muted outline-none"}),C.jsx("kbd",{className:"shrink-0 rounded border border-border px-1.5 py-0.5 font-mono text-2xs text-content-faint",children:"esc"})]}),C.jsx("div",{className:"max-h-[50vh] overflow-y-auto p-1.5",children:d.length===0?C.jsx("p",{className:"px-3 py-6 text-center text-sm text-content-muted",children:"没有匹配项"}):[...S.entries()].map(([k,w])=>C.jsxs("div",{className:"mb-1",children:[k&&C.jsx("p",{className:"px-2.5 pb-1 pt-2 text-2xs font-semibold uppercase tracking-wider text-content-faint",children:k}),w.map(_=>{x+=1;const b=x;return C.jsxs("button",{onMouseEnter:()=>o(b),onClick:()=>m(b),className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors ${b===f?"bg-surface-overlay":"hover:bg-surface-overlay"}`,children:[_.icon&&C.jsx("span",{className:"shrink-0 text-content-muted",children:_.icon}),C.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-content-primary",children:_.label}),_.hint&&C.jsx("span",{className:"shrink-0 text-2xs text-content-faint",children:_.hint})]},_.id)})]},k||"_"))})]})})}function lD(e){return e==="connected"?{text:"已连接",color:"text-success"}:e==="connecting"||e==="reconnecting"||e==="claiming"?{text:"连接中",color:"text-warning"}:e==="host_disconnected"?{text:"主机离线",color:"text-warning"}:e.startsWith("error")?{text:"错误",color:"text-danger"}:{text:"未连接",color:"text-content-muted"}}function Xv(e){switch(e){case"running":return{text:"运行中",className:"border-success/30 bg-success/10 text-success",pulsing:!0};case"waiting_permission":return{text:"等待授权",className:"border-warning/40 bg-warning/10 text-warning",pulsing:!0};case"error":return{text:"异常",className:"border-danger/30 bg-danger/10 text-danger"};case"idle":return{text:"空闲",className:"border-border bg-surface-overlay text-content-muted"};case"unavailable":return{text:"不可用",className:"border-border bg-surface-overlay text-content-faint"};default:return null}}function uc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function cD(e){if(!e)return null;const n=e.inputTokens!=null||e.cacheReadTokens!=null?(e.inputTokens??0)+(e.cacheReadTokens??0):null,r=[];let a="";if(n!=null&&e.contextWindow&&e.contextWindow>0){const l=Math.min(100,Math.round(n/e.contextWindow*100));r.push(`${l}%`),a=`上下文 ${uc(n)} / ${uc(e.contextWindow)} tokens`}else{const l=e.totalTokens??n??e.outputTokens??null;l!=null&&(r.push(uc(l)),a=`${l.toLocaleString()} tokens`)}return typeof e.totalCostUsd=="number"&&e.totalCostUsd>0&&(r.push(`$${e.totalCostUsd.toFixed(e.totalCostUsd<1?3:2)}`),a=a?`${a} · $${e.totalCostUsd.toFixed(4)}`:`$${e.totalCostUsd.toFixed(4)}`),r.length===0?null:{text:r.join(" · "),title:a}}function uD(e){const n=Math.max(0,Math.floor(e)),r=Math.floor(n/3600),a=Math.floor(n%3600/60),l=n%60;return r>0?`${r}h ${String(a).padStart(2,"0")}m ${String(l).padStart(2,"0")}s`:a>0?`${a}m ${String(l).padStart(2,"0")}s`:`${l}s`}function hD(e){const[n,r]=re.useState(0),a=re.useRef(null);return re.useEffect(()=>{if(!e){a.current=null,r(0);return}a.current=Date.now(),r(0);const l=setInterval(()=>{a.current!=null&&r(Math.floor((Date.now()-a.current)/1e3))},1e3);return()=>clearInterval(l)},[e]),n}function dD(e,n,r){const[a,l]=re.useState(()=>({render:e,className:e?n:""})),u=re.useRef(e);re.useEffect(()=>{e&&!u.current?l({render:!0,className:n}):!e&&u.current&&l({render:!0,className:r}),u.current=e},[e,n,r]);const f=re.useCallback(()=>{u.current||l({render:!1,className:""})},[]);return{render:a.render,className:a.className,onAnimationEnd:f}}function fD(e,n){var l,u,f,o,h,d,m,p;const r=n.toLowerCase();return[e.text,(l=e.commandExecution)==null?void 0:l.command,(u=e.commandExecution)==null?void 0:u.output,(f=e.toolCall)==null?void 0:f.name,(o=e.toolCall)==null?void 0:o.input,(h=e.toolCall)==null?void 0:h.output,(d=e.fileChange)==null?void 0:d.summary,...((p=(m=e.fileChange)==null?void 0:m.entries)==null?void 0:p.map(x=>x.path))??[],e.error].some(x=>typeof x=="string"&&x.toLowerCase().includes(r))}function pD({sessionId:e,session:n,onBack:r}){var Ut,$t,De;const a=re.useMemo(()=>ib(),[]),l=re.useMemo(()=>c0(),[]),{store:u,snapshot:f}=Ww(a,e),o=i0(),[h,d]=re.useState("none"),[m,p]=re.useState(!1),[x,S]=re.useState(!1),[k,w]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_terminal_h"));return X>=120&&X<=600?X:320}),_=re.useRef(!1),b=re.useRef(k);b.current=k;const v=re.useRef(m);v.current=m;const y=re.useCallback(()=>{v.current?S(!0):p(!0)},[]),T=re.useCallback(()=>{S(!1),p(!0)},[]),[M,N]=re.useState(!1),[O,R]=re.useState(null),[L,z]=re.useState(null),[H,q]=re.useState(!1),[F,W]=re.useState(null),[G,K]=re.useState({text:"",nonce:0}),[ne,Q]=re.useState(!1),[I,A]=re.useState(""),[B,$]=re.useState(!1),P=re.useRef(null),[oe,ye]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_sidebar_w"));return X>=180&&X<=520?X:256}),[pe,J]=re.useState(()=>localStorage.getItem("linkshell_sidebar_collapsed")==="1"),[j,me]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_rightpanel_w"));return X>=320&&X<=1100?X:560}),ce=re.useRef(!1),ee=re.useRef(!1),le=re.useRef(null),Ce=()=>{J(X=>(localStorage.setItem("linkshell_sidebar_collapsed",X?"0":"1"),!X))},He=X=>{X.preventDefault(),ce.current=!0;const de=Ke=>{if(!ce.current)return;const gt=Math.min(520,Math.max(180,Ke.clientX));ye(gt)},Be=()=>{ce.current=!1,localStorage.setItem("linkshell_sidebar_w",String(Ee.current)),window.removeEventListener("pointermove",de),window.removeEventListener("pointerup",Be)};window.addEventListener("pointermove",de),window.addEventListener("pointerup",Be)},Ee=re.useRef(oe);Ee.current=oe;const we=re.useRef(j);we.current=j;const ke=X=>{X.preventDefault(),ee.current=!0;const de=Ke=>{if(!ee.current)return;const gt=Math.min(1100,Math.max(320,window.innerWidth-Ke.clientX));me(gt)},Be=()=>{ee.current=!1,localStorage.setItem("linkshell_rightpanel_w",String(we.current)),window.removeEventListener("pointermove",de),window.removeEventListener("pointerup",Be)};window.addEventListener("pointermove",de),window.addEventListener("pointerup",Be)},Tt=X=>{X.preventDefault(),_.current=!0;const de=X.clientY,Be=b.current,Ke=Nn=>{if(!_.current)return;const It=Math.min(600,Math.max(120,Be+(de-Nn.clientY)));w(It)},gt=()=>{_.current=!1,localStorage.setItem("linkshell_terminal_h",String(b.current)),window.removeEventListener("pointermove",Ke),window.removeEventListener("pointerup",gt)};window.addEventListener("pointermove",Ke),window.addEventListener("pointerup",gt)},Fe=f.activeConversationId,At=Fe?f.timelines.get(Fe)??[]:[],Me=f.conversations.find(X=>X.id===Fe),pn=((Ut=f.capabilities)==null?void 0:Ut.providers)??[],Nt=Me?pn.find(X=>X.id===Me.provider):void 0,Ot=(Me==null?void 0:Me.status)==="running",wt=Fe?f.history.get(Fe):void 0,ue=re.useMemo(()=>{for(let X=At.length-1;X>=0;X--){const de=At[X];if(de.role==="user"&&de.text)return de.text}},[At]),xe=X=>{K(de=>({text:X,nonce:de.nonce+1}))},Ie=re.useMemo(()=>{if((Me==null?void 0:Me.collaborationMode)!=="plan"||Ot||(Me==null?void 0:Me.status)==="waiting_permission")return!1;const X=[...At].reverse().find(de=>!oc(de));return X!=null&&X.role!=="user"},[Me==null?void 0:Me.collaborationMode,Me==null?void 0:Me.status,Ot,At]),$e=()=>{Fe&&u.sendPrompt({conversationId:Fe,text:"请按上面的计划开始执行。",collaborationMode:"default",model:Me==null?void 0:Me.model,reasoningEffort:Me==null?void 0:Me.reasoningEffort,permissionMode:Me==null?void 0:Me.permissionMode})};re.useEffect(()=>{const X=de=>{const Be=de.metaKey||de.ctrlKey;Be&&de.shiftKey&&de.key.toLowerCase()==="p"?(de.preventDefault(),$(Ke=>!Ke)):Be&&!de.shiftKey&&de.key.toLowerCase()==="k"?(de.preventDefault(),$(Ke=>!Ke)):Be&&!de.shiftKey&&de.key.toLowerCase()==="j"?(de.preventDefault(),y()):Be&&!de.shiftKey&&de.key.toLowerCase()==="f"?(de.preventDefault(),Q(!0),requestAnimationFrame(()=>{var Ke;return(Ke=P.current)==null?void 0:Ke.focus()})):de.key==="Escape"&&Q(!1)};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[]),re.useEffect(()=>{Q(!1),A("")},[Fe]);const Je=re.useRef(0),Gt=re.useRef(!0),ht=()=>{const X=le.current;X&&(Gt.current=X.scrollHeight-X.scrollTop-X.clientHeight<80,X.scrollTop<60&&Fe&&(wt!=null&&wt.hasMore)&&!wt.loading&&(Je.current=X.scrollHeight,u.loadOlderHistory(Fe)))};re.useLayoutEffect(()=>{const X=le.current;X&&(Je.current>0?(X.scrollTop=X.scrollHeight-Je.current,Je.current=0):Gt.current&&(X.scrollTop=X.scrollHeight))},[At.length,Fe]);const Qt=(X,de)=>{de?En(X,de):W(X)},En=(X,de)=>{const Be=pn.find(gt=>gt.id===X),Ke=u.openConversation({provider:X,cwd:de,model:Be==null?void 0:Be.defaultModel});u.setActiveConversation(Ke),W(null)},vn=(X,de)=>{Fe&&u.sendPrompt({conversationId:Fe,text:X,images:de.map(Be=>({data:Be.data,mimeType:Be.mimeType})),model:Me==null?void 0:Me.model,reasoningEffort:Me==null?void 0:Me.reasoningEffort,permissionMode:Me==null?void 0:Me.permissionMode,collaborationMode:Me==null?void 0:Me.collaborationMode})},Wt=lD(f.status),rn=f.externalAgentStatus==="running"||f.externalAgentStatus==="waiting_permission"||f.externalAgentStatus==="error",sn=Xv(rn?f.externalAgentStatus??void 0:Me==null?void 0:Me.status),Ii=rn?f.externalAgentTitle??"外部终端":Me==null?void 0:Me.provider,rr=rn?f.externalAgentStatus==="running":(Me==null?void 0:Me.status)==="running",zr=hD(rr),ei=rn?null:cD(Me==null?void 0:Me.usage),fi=`CLI 设备 · ${e.slice(0,8)}`,Z=Me==null?void 0:Me.cwd,_e=re.useCallback(()=>{u.client.spawnTerminal(Z||".")},[u,Z]),Re=pn.filter(X=>X.enabled),Ze=re.useMemo(()=>{const X=[];for(const de of Re)X.push({id:`new-${de.id}`,label:`新建 ${de.label} 对话`,group:"新建",keywords:`new conversation ${de.id}`,icon:C.jsx(Ro,{size:15}),run:()=>Qt(de.id)});for(const de of f.conversations.filter(Be=>!Be.archived)){const Be=de.title&&de.title.trim()||de.lastMessagePreview&&de.lastMessagePreview.trim().slice(0,40)||`对话 ${de.id.slice(-6)}`;X.push({id:`conv-${de.id}`,label:Be,group:"对话",hint:de.cwd?de.cwd.split("/").slice(-1)[0]:void 0,keywords:`${de.provider} ${de.cwd??""}`,icon:C.jsx(ea,{provider:de.provider,size:15}),run:()=>u.setActiveConversation(de.id)})}return Fe&&Ot&&X.push({id:"cancel",label:"停止当前回合",group:"操作",keywords:"cancel stop interrupt",icon:C.jsx(eb,{size:15}),run:()=>u.cancel(Fe)}),Fe&&X.push({id:"search",label:"在对话中搜索",group:"操作",hint:"⌘F",keywords:"search find filter",icon:C.jsx(ls,{size:15}),run:()=>{Q(!0),requestAnimationFrame(()=>{var de;return(de=P.current)==null?void 0:de.focus()})}}),X.push({id:"panel-terminal",label:"切换终端",group:"操作",hint:"⌘J",keywords:"terminal shell",icon:C.jsx(Ed,{size:15}),run:y},{id:"panel-files",label:"打开文件浏览器",group:"操作",keywords:"files browse",icon:C.jsx(Lr,{size:15}),run:()=>d(de=>de==="files"?"none":"files")},{id:"panel-preview",label:"打开端口预览",group:"操作",keywords:"preview port browser localhost tunnel",icon:C.jsx(hc,{size:15}),run:()=>d(de=>de==="preview"?"none":"preview")}),X},[Re,f.conversations,Fe,Ot]);return C.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden",children:[C.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-2",style:{paddingTop:"max(0.5rem, env(safe-area-inset-top))"},children:[C.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o&&C.jsx("button",{onClick:()=>N(!0),className:"codex-btn-ghost shrink-0 px-2 py-1.5","aria-label":"打开会话列表",children:C.jsx(AS,{size:17})}),C.jsx("button",{onClick:r,className:"codex-btn-ghost shrink-0 text-2xs","aria-label":"返回会话列表",children:"← 会话"}),C.jsxs("span",{className:`flex shrink-0 items-center gap-1 text-2xs ${Wt.color}`,children:[C.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}),!o&&Wt.text]}),sn&&C.jsxs("span",{className:`inline-flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-2xs font-medium ${sn.className}`,title:rn?"外部终端状态":"当前对话状态",children:[sn.pulsing&&C.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-current animate-pulse-dot"}),Ii&&C.jsx("span",{className:"min-w-0 truncate",children:Ii}),C.jsxs("span",{className:"shrink-0",children:[Ii?"· ":"",sn.text]}),rr&&C.jsx("span",{className:"shrink-0 font-mono tabular-nums opacity-70",children:uD(zr)})]}),ei&&C.jsx("span",{className:"inline-flex shrink-0 items-center rounded-full border border-border bg-surface-overlay px-2 py-0.5 font-mono text-2xs tabular-nums text-content-muted",title:ei.title,children:ei.text}),(($t=f.usage)==null?void 0:$t.totals)&&C.jsxs("span",{className:"inline-flex shrink-0 items-center gap-0.5 rounded-full border border-border bg-surface-overlay px-2 py-0.5 font-mono text-2xs tabular-nums text-content-muted",title:"全机用量",children:[C.jsx(g_,{size:12}),uc(f.usage.totals.totalTokens)]}),f.lastError&&C.jsx("button",{onClick:()=>u.dismissError(),className:"min-w-0 truncate rounded-full border border-danger/30 bg-danger/10 px-2 py-0.5 text-2xs text-danger",title:`${f.lastError.message}(点击关闭)`,children:f.lastError.code})]}),C.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[C.jsx("button",{onClick:()=>{Fe&&(Q(!0),requestAnimationFrame(()=>{var X;return(X=P.current)==null?void 0:X.focus()}))},disabled:!Fe,className:"codex-btn-ghost px-2 py-1.5 disabled:opacity-40",title:"在对话中搜索 (⌘/Ctrl+F)","aria-label":"在对话中搜索",children:C.jsx(ls,{size:16})}),!l&&C.jsx(tD,{}),C.jsx("button",{onClick:()=>d(X=>X==="preview"?"none":"preview"),className:`cursor-pointer rounded-md p-1.5 transition-colors ${h==="preview"?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"端口预览","aria-label":"端口预览",children:C.jsx(hc,{size:16})}),C.jsx("button",{onClick:()=>d(X=>X==="files"?"none":"files"),className:`cursor-pointer rounded-md p-1.5 transition-colors ${h==="files"?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"文件","aria-label":"文件",children:C.jsx(Lr,{size:16})}),C.jsx("button",{onClick:y,className:`cursor-pointer rounded-md p-1.5 transition-colors ${m?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"终端 (⌘J)","aria-label":"终端",children:C.jsx(Ed,{size:16})}),C.jsx("button",{onClick:()=>{u.requestUsage(),q(!0)},className:`cursor-pointer rounded-md p-1.5 transition-colors ${H?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"用量统计","aria-label":"用量统计",children:C.jsx(g_,{size:16})})]})]}),C.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[f.status==="host_disconnected"&&C.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-canvas/80 backdrop-blur-sm",children:C.jsxs("div",{className:"codex-card-raised mx-4 flex max-w-sm flex-col items-center gap-3 px-6 py-8 text-center animate-fade-in",children:[C.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-warning/15 text-warning",children:C.jsx(OS,{size:24})}),C.jsx("h2",{className:"text-base font-semibold text-content-primary",children:"主机已离线"}),C.jsxs("p",{className:"text-sm leading-relaxed text-content-muted",children:["与该会话的主机连接已断开。请确认主机上的"," ",C.jsx("code",{className:"font-mono text-accent",children:"linkshell"})," 仍在运行。正在自动尝试重新连接…"]}),C.jsx("button",{onClick:r,className:"codex-btn-outline mt-1 text-2xs",children:"返回会话列表"})]})}),o?M&&C.jsxs("div",{className:"absolute inset-0 z-30 flex animate-fade-in",children:[C.jsxs("aside",{className:"flex w-[82%] max-w-xs flex-col border-r border-border bg-surface shadow-2xl animate-drawer-in",children:[C.jsx("div",{className:"flex items-center border-b border-border px-3 py-2",children:C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"会话"})}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(Wv,{deviceLabel:fi,conversations:f.conversations,capabilities:f.capabilities,activeConversationId:Fe,externalAgentStatus:f.externalAgentStatus,externalAgentTitle:f.externalAgentTitle,externalAgentProvider:f.externalAgentProvider,store:u,onSelect:X=>{u.setActiveConversation(X),N(!1)},onNewConversation:(X,de)=>{N(!1),Qt(X,de)},onOpenExternalTerminal:()=>{var de;const X=f.externalAgentConversationId||((de=f.conversations.find(Be=>Be.status==="running"||Be.status==="waiting_permission"))==null?void 0:de.id);X?(u.setActiveConversation(X),N(!1)):(N(!1),T())}})})]}),C.jsx("button",{className:"flex-1 bg-canvas/60 backdrop-blur-sm",onClick:()=>N(!1),"aria-label":"关闭"})]}):pe?C.jsx("div",{className:"flex w-9 shrink-0 flex-col items-center border-r border-border bg-surface py-2",children:C.jsx("button",{onClick:Ce,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-content-primary",title:"展开侧边栏","aria-label":"展开侧边栏",children:C.jsx(Si,{size:16})})}):C.jsxs("aside",{className:"relative flex shrink-0 flex-col border-r border-border bg-surface",style:{width:oe},children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-2 py-1",children:[C.jsx("span",{className:"pl-1 text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"会话"}),C.jsx("button",{onClick:Ce,className:"cursor-pointer rounded-md p-1 text-content-muted transition-colors hover:bg-surface-overlay hover:text-content-primary",title:"收起侧边栏","aria-label":"收起侧边栏",children:C.jsx(NS,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(Wv,{deviceLabel:fi,conversations:f.conversations,capabilities:f.capabilities,activeConversationId:Fe,externalAgentStatus:f.externalAgentStatus,externalAgentTitle:f.externalAgentTitle,externalAgentProvider:f.externalAgentProvider,store:u,onSelect:X=>u.setActiveConversation(X),onNewConversation:Qt,onOpenExternalTerminal:()=>{var de;const X=f.externalAgentConversationId||((de=f.conversations.find(Be=>Be.status==="running"||Be.status==="waiting_permission"))==null?void 0:de.id);X?u.setActiveConversation(X):T()}})}),C.jsx("div",{onPointerDown:He,className:"absolute right-0 top-0 h-full w-1 cursor-col-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整宽度"})]}),C.jsx("main",{className:"flex min-w-0 flex-1 flex-col",children:!Fe||!Me?C.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[C.jsx(lf,{size:44,className:"opacity-40"}),C.jsx("p",{className:"text-[15px] leading-7 text-content-muted",children:o?"点击左上角菜单选择对话,或新建一个开始":"从左侧选择一个对话,或新建一个开始"})]}):C.jsxs(C.Fragment,{children:[ne&&C.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-surface px-4 py-2",children:[C.jsx(ls,{size:15,className:"shrink-0 text-content-faint"}),C.jsx("input",{ref:P,value:I,onChange:X=>A(X.target.value),onKeyDown:X=>X.key==="Escape"&&(Q(!1),A("")),placeholder:"在此对话中搜索…",className:"min-w-0 flex-1 bg-transparent text-sm text-content-primary placeholder-content-muted outline-none"}),C.jsx("button",{onClick:()=>{Q(!1),A("")},className:"codex-btn-ghost px-2 py-1","aria-label":"关闭搜索",children:C.jsx(hi,{size:14})})]}),C.jsx("div",{ref:le,onScroll:ht,className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-8",children:C.jsxs("div",{className:"mx-auto flex w-full min-w-0 max-w-3xl flex-col gap-6",children:[(wt==null?void 0:wt.loading)&&C.jsx("p",{className:"text-center text-2xs text-content-muted",children:"加载更早的消息…"}),ne&&I.trim()?(()=>{const X=I.trim(),de=At.filter(Be=>!oc(Be)&&fD(Be,X));return de.length===0?C.jsxs("p",{className:"py-12 text-center text-sm text-content-muted",children:["没有匹配「",X,"」的消息"]}):C.jsxs(C.Fragment,{children:[C.jsxs("p",{className:"text-center text-2xs text-content-faint",children:[de.length," 条匹配"]}),de.map(Be=>C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(Fv,{item:Be,canSteer:!1,onPermission:(Ke,gt,Nn)=>u.respondPermission(Fe,Ke,gt,Nn),onStructuredInput:(Ke,gt)=>u.respondStructuredInput(Fe,Ke,gt),onOpenDiff:Ke=>{R(Ke),d("none")},onOpenAgent:Ke=>{z(Ke),R(null),d("none")},onEditMessage:xe,highlightQuery:X})},Be.id))]})})():(()=>{const X=[];let de=[];const Be=()=>{de.length&&(X.push({k:"group",key:`grp-${de[0].id}`,items:de}),de=[])};for(const gt of At)oc(gt)||(yO(gt)?de.push(gt):(Be(),X.push({k:"item",item:gt})));Be();let Ke=-1;return X.forEach((gt,Nn)=>{gt.k==="group"&&(Ke=Nn)}),X.map((gt,Nn)=>gt.k==="item"?C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(Fv,{item:gt.item,canSteer:Me.provider==="codex"&&Ot,onPermission:(It,pi,Bi)=>u.respondPermission(Fe,It,pi,Bi),onStructuredInput:(It,pi)=>u.respondStructuredInput(Fe,It,pi),onSendQueued:It=>u.sendQueuedFollowUp(Fe,It,"new_turn"),onSteerQueued:It=>u.sendQueuedFollowUp(Fe,It,"steer"),onDiscardQueued:It=>u.discardQueuedFollowUp(Fe,It),onOpenDiff:It=>{R(It),d("none")},onOpenAgent:It=>{z(It),R(null),d("none")},onEditMessage:xe})},gt.item.id):C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(EO,{items:gt.items,live:Ot&&Nn===Ke,onOpenDiff:It=>{R(It),d("none")},onOpenAgent:It=>{z(It),R(null),d("none")}})},gt.key))})(),At.length===0&&(Me!=null&&Me.lastMessagePreview||wt!=null&&wt.loading?C.jsxs("div",{className:"flex flex-col items-center gap-2 py-16 text-content-muted",children:[C.jsx("span",{className:"h-5 w-5 animate-spin rounded-full border-2 border-content-faint border-t-accent"}),C.jsx("p",{className:"text-sm",children:"加载对话记录…"})]}):C.jsx("p",{className:"py-12 text-center text-sm text-content-muted",children:"发送第一条指令…"}))]})}),C.jsxs("div",{className:"mx-auto w-full min-w-0 max-w-3xl px-4 pb-4",children:[Ie&&C.jsxs("div",{className:"mb-2 flex items-center gap-3 rounded-xl border border-accent-dim/40 bg-surface px-3.5 py-2.5 animate-slide-in",children:[C.jsx("span",{className:"min-w-0 flex-1 text-sm text-content-secondary",children:"计划已就绪。执行它,或在下方继续补充。"}),C.jsx("button",{onClick:$e,className:"codex-btn-primary shrink-0 text-xs",children:"执行计划"})]}),C.jsx(xO,{items:At.filter(oc),canSteer:Me.provider==="codex"&&Ot,onSend:X=>u.sendQueuedFollowUp(Fe,X,"new_turn"),onSteer:X=>u.sendQueuedFollowUp(Fe,X,"steer"),onDiscard:X=>u.discardQueuedFollowUp(Fe,X)}),C.jsx(CO,{disabled:f.status!=="connected",running:Ot,supportsImages:Nt==null?void 0:Nt.supportsImages,commands:Nt==null?void 0:Nt.commands,conversationId:Fe,lastUserText:ue,cwd:Me.cwd,onBrowse:X=>u.browse(X,!0),seedText:G,controls:C.jsx($O,{conversation:Me,capability:Nt,onChange:X=>u.updateConversationSettings(Fe,X)}),onSend:vn,onCancel:()=>u.cancel(Fe),onExecuteCommand:(X,de)=>u.executeCommand(Fe,X,de)})]}),(m||x)&&C.jsxs("div",{className:`relative shrink-0 overflow-hidden border-t border-border bg-surface ${x?"animate-panel-out-down":"animate-panel-in-up"}`,style:{height:k},onAnimationEnd:()=>{x&&(S(!1),p(!1))},children:[C.jsx("div",{onPointerDown:Tt,className:"absolute left-0 right-0 top-0 z-10 h-1 cursor-row-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整终端高度"}),C.jsx(BO,{bridge:u.client,onNewTerminal:_e})]})]})}),(()=>{let X=null;L?X=C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"子 Agent"}),C.jsx("button",{onClick:()=>z(null),className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭",children:C.jsx(hi,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(vO,{detail:L})})]}):O?X=C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"文件差异"}),C.jsx("button",{onClick:()=>R(null),className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭差异",children:C.jsx(hi,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(cO,{item:O})})]}):h==="files"?X=C.jsx(qO,{store:u,initialPath:(Me==null?void 0:Me.cwd)||".",onClose:()=>d("none")}):h==="preview"&&(X=C.jsx(YO,{gatewayUrl:a.httpUrl,sessionId:e,initialAuthToken:(n==null?void 0:n.accessToken)??null,isMobile:o,onClose:()=>d("none"),onAnnotate:Nn=>{K(It=>({text:Nn,nonce:It.nonce+1})),o&&d("none")}}));const de=re.useRef(null);X!==null&&(de.current=X);const Be=X!==null,Ke=dD(Be,"animate-panel-in-right","animate-panel-out-right");if(!Ke.render&&!Be)return null;const gt=Be?X:de.current;return o?C.jsx("aside",{className:`absolute inset-0 z-30 flex flex-col bg-canvas ${Ke.className||"animate-fade-in"}`,onAnimationEnd:Ke.onAnimationEnd,children:gt}):C.jsxs("aside",{className:`relative flex shrink-0 flex-col border-l border-border ${Ke.className}`,style:{width:j},onAnimationEnd:Ke.onAnimationEnd,children:[C.jsx("div",{onPointerDown:ke,className:"absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整宽度"}),gt]})})()]}),F&&C.jsx(KO,{store:u,initialPath:(Me==null?void 0:Me.cwd)||".",providerLabel:((De=pn.find(X=>X.id===F))==null?void 0:De.label)??F,onCancel:()=>W(null),onConfirm:X=>En(F,X)}),f.notices.length>0&&C.jsx("div",{className:"pointer-events-none fixed bottom-4 right-4 z-50 flex w-80 flex-col gap-2",children:f.notices.map(X=>C.jsxs("button",{onClick:()=>u.dismissNotice(X.id),className:`codex-card-raised pointer-events-auto animate-fade-in cursor-pointer px-3 py-2 text-left ${X.kind==="warning"?"border-warning/40":""}`,children:[C.jsxs("p",{className:"flex items-center gap-1.5 text-xs font-medium text-content-primary",children:[C.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X.kind==="warning"?"bg-warning":"bg-accent"}`}),X.title]}),X.detail&&C.jsx("p",{className:"mt-0.5 pl-3 text-2xs text-content-muted",children:X.detail})]},X.id))}),C.jsx(oD,{open:B,onClose:()=>$(!1),actions:Ze}),H&&C.jsx(o1,{report:f.usage,onClose:()=>q(!1)})]})}eD();function mD(){const[e,n]=re.useState(null),[r,a]=re.useState(!1),[l,u]=re.useState(!1),f=re.useMemo(()=>iD(nD()),[]),o=re.useMemo(()=>c0(),[]),[h,d]=re.useState(()=>f??ZS()),m=p=>{d(p),v_(p)};return re.useEffect(()=>{const p=Cc();p&&n(p),a(!0),p&&nf().then(x=>{x&&n(x)})},[]),re.useEffect(()=>{if(!o)return;const p=window;return p.__linkshellSetTheme=x=>{(x==="dark"||x==="light")&&Bf(x)},()=>{delete p.__linkshellSetTheme}},[o]),re.useEffect(()=>yS(()=>{n(null),u(!1),d(p=>p.name==="list"?p:{name:"list"}),v_({name:"list"})}),[]),r?l?C.jsx(jS,{onLogin:p=>{n(p),u(!1)},onCancel:()=>u(!1)}):h.name==="console"?C.jsx(pD,{sessionId:h.sessionId,session:e,onBack:o?rD:()=>m({name:"list"})}):C.jsx(u1,{session:e,onLogin:()=>u(!0),onLogout:()=>{n(null),m({name:"list"})},onOpenSession:p=>m({name:"console",sessionId:p})}):null}bS.createRoot(document.getElementById("root")).render(C.jsx(mD,{}));
|
|
94
|
+
`)),z(null),q(""),K({}),Q({}),W(!1),R(null),T(!1)},Ce=()=>{z(null),q(""),K({}),Q({}),W(!1)},He=()=>{N(null),Ce(),R(null),T(Ee=>!Ee)};return C.jsxs("div",{className:"flex h-full flex-col bg-canvas",children:[C.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-surface px-2 py-1.5",children:[l&&C.jsx("button",{onClick:u,className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭预览",children:C.jsx(hi,{size:15})}),C.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 rounded-lg border border-border bg-surface-raised px-2 py-1",children:[C.jsx("span",{className:"shrink-0 font-mono text-2xs text-content-faint",children:"localhost:"}),C.jsx("input",{value:o,onChange:Ee=>h(Ee.target.value),onKeyDown:Ee=>Ee.key==="Enter"&&P(),placeholder:"3000",spellCheck:!1,className:"min-w-0 flex-1 bg-transparent font-mono text-2xs text-content-primary outline-none","aria-label":"端口与路径"}),C.jsx("button",{onClick:P,className:"shrink-0 cursor-pointer rounded bg-accent-dim px-2 py-0.5 text-2xs font-medium text-white transition-colors hover:bg-accent",children:"前往"})]}),C.jsx("button",{onClick:He,disabled:!d,className:`shrink-0 cursor-pointer rounded-md p-1.5 transition-colors disabled:opacity-40 ${y?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-accent"}`,title:"标注元素","aria-label":"标注元素",children:C.jsx(zS,{size:14})}),C.jsxs("div",{className:"flex shrink-0 items-center rounded-lg border border-border bg-surface-raised p-0.5",children:[C.jsx("button",{onClick:()=>_("desktop"),className:`cursor-pointer rounded p-1 transition-colors ${w==="desktop"?"bg-surface-overlay text-content-primary":"text-content-muted hover:text-content-primary"}`,title:"桌面视口","aria-label":"桌面视口",children:C.jsx(tb,{size:13})}),C.jsx("button",{onClick:()=>_("mobile"),className:`cursor-pointer rounded p-1 transition-colors ${w==="mobile"?"bg-surface-overlay text-content-primary":"text-content-muted hover:text-content-primary"}`,title:"移动视口","aria-label":"移动视口",children:C.jsx(PS,{size:13})})]}),C.jsx("button",{onClick:oe,disabled:!d,className:"shrink-0 cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent disabled:opacity-40",title:"刷新","aria-label":"刷新",children:C.jsx(kc,{size:14})}),C.jsx("button",{onClick:()=>$&&window.open($,"_blank","noopener,noreferrer"),disabled:!$,className:"shrink-0 cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-accent disabled:opacity-40",title:"在新窗口打开","aria-label":"在新窗口打开",children:C.jsx(BS,{size:14})})]}),M&&C.jsx("p",{className:"border-b border-border bg-warning/10 px-3 py-1.5 text-2xs text-warning",children:M}),y&&!L&&C.jsx("p",{className:"border-b border-border bg-accent/10 px-3 py-1.5 text-2xs text-accent",children:"标注模式:移动鼠标高亮元素,点击选择并添加批注。"}),C.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-raised",children:$?C.jsx("div",{className:w==="mobile"?"mx-auto h-full w-[390px] max-w-full border-x border-border":"h-full w-full",children:C.jsxs("div",{className:"relative h-full w-full",children:[C.jsx("iframe",{ref:I,src:$,title:"端口预览",onLoad:ye,className:"h-full w-full bg-white"},`${$}-${b}`),y&&C.jsx("div",{className:"absolute inset-0 cursor-crosshair",onMouseMove:j,onMouseLeave:()=>R(null),onClick:me,children:O&&!L&&C.jsx("div",{className:"pointer-events-none absolute border-2 border-accent bg-accent/10",style:{top:O.top,left:O.left,width:O.width,height:O.height}})}),L&&(()=>{var Ot,wt;const ke=((Ot=A.current)==null?void 0:Ot.clientHeight)??600,Tt=L.rect.top+L.rect.height+8,Fe=L.rect.top-8,At=F?340:140,pn=Tt+At>ke&&Fe-At>0?Math.max(4,Fe-At):Tt,Nt=Math.max(4,Math.min(L.rect.left,(((wt=A.current)==null?void 0:wt.clientWidth)??800)-280-4));return C.jsxs("div",{className:"absolute z-20 flex flex-col gap-2 rounded-xl border border-accent-dim/40 bg-surface-raised px-3 py-2.5 shadow-2xl animate-fade-in",style:{top:pn,left:Nt,width:280,maxHeight:ke-pn-8},children:[C.jsx("p",{className:"truncate font-mono text-2xs text-content-faint",title:L.selector,children:L.selector}),L.text&&C.jsxs("p",{className:"-mt-1 truncate text-2xs text-content-muted",children:['"',L.text,'"']}),C.jsx("input",{value:H,onChange:ue=>q(ue.target.value),onKeyDown:ue=>ue.key==="Enter"&&le(),autoFocus:!0,placeholder:"添加批注…",className:"w-full rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-content-primary placeholder-content-muted outline-none focus:border-accent-dim"}),C.jsxs("button",{onClick:()=>W(ue=>!ue),className:`flex cursor-pointer items-center gap-1 self-start rounded-md px-1.5 py-0.5 text-2xs transition-colors ${F?"text-accent":"text-content-muted hover:text-content-secondary"}`,children:[C.jsx("svg",{width:10,height:10,viewBox:"0 0 10 10",className:`shrink-0 transition-transform ${F?"rotate-180":""}`,children:C.jsx("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})}),"调整样式"]}),F&&C.jsx("div",{className:"grid grid-cols-2 gap-x-2 gap-y-1.5 animate-fade-in",children:o0.map(({cssProp:ue,label:xe})=>{const Ie=ne[ue]??G[ue]??"",$e=ue in ne&&ne[ue]!==(G[ue]??"");return C.jsxs("label",{className:"flex flex-col gap-0.5",children:[C.jsx("span",{className:`text-2xs ${$e?"text-accent":"text-content-faint"}`,children:xe}),C.jsx("input",{value:Ie,onChange:Je=>ce(ue,Je.target.value),spellCheck:!1,className:"w-full rounded-md border border-border bg-surface px-2 py-1 font-mono text-2xs text-content-primary outline-none focus:border-accent-dim"})]},ue)})}),C.jsxs("div",{className:"flex items-center gap-2",children:[C.jsx("button",{onClick:Ce,className:"codex-btn-ghost flex-1 text-2xs",children:"取消"}),C.jsx("button",{onClick:le,className:"codex-btn-primary flex-1 text-2xs",children:"发送给 Agent"})]})]})})()]})}):C.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[C.jsx(hc,{size:34,className:"text-content-faint"}),C.jsx("p",{className:"text-sm leading-6 text-content-muted",children:d&&!S?"正在准备预览认证...":"输入主机上服务的端口号,预览远程本地服务"})]})})]})}const l0="linkshell_theme",wc=new Set;let Uc=ZO();function ZO(){try{const e=localStorage.getItem(l0);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"dark"}function XO(){return typeof window<"u"&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!0}function QO(e=Uc){return e==="system"?XO()?"dark":"light":e}function Zd(){typeof document>"u"||document.documentElement.setAttribute("data-theme",QO())}function Yv(){return Uc}function Bf(e){Uc=e;try{localStorage.setItem(l0,e)}catch{}Zd();for(const n of wc)n()}function JO(e){return wc.add(e),()=>wc.delete(e)}function eD(){var e;if(Zd(),typeof window<"u"&&window.matchMedia){const n=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{if(Uc==="system"){Zd();for(const a of wc)a()}};(e=n.addEventListener)==null||e.call(n,"change",r)}}const xd=["light","dark","system"],Zv={light:"浅色",dark:"深色",system:"跟随系统"};function tD(){const e=re.useSyncExternalStore(JO,Yv,Yv),n=()=>Bf(xd[(xd.indexOf(e)+1)%xd.length]),r=e==="light"?RS:e==="dark"?MS:tb;return C.jsx("button",{onClick:n,className:"codex-btn-ghost px-2 py-1.5",title:`主题:${Zv[e]}(点击切换)`,"aria-label":`主题:${Zv[e]}`,children:C.jsx(r,{size:15})})}function nD(){try{const e=new URLSearchParams(window.location.search),n=e.get("embed")==="1",r=e.get("theme");return{embed:n,sessionId:e.get("session"),gateway:e.get("gateway"),token:e.get("token"),theme:r==="dark"||r==="light"?r:null}}catch{return{embed:!1,sessionId:null,gateway:null,token:null,theme:null}}}function iD(e){return!e.embed||!e.sessionId||!e.token||!e.gateway?null:(rb(e.gateway),uf(e.token),e.theme&&Bf(e.theme),Cd([{id:e.sessionId,state:"active",hasHost:!0,clientCount:1,provider:null,machineId:null,hostname:null,platform:null,projectName:null,cwd:null,lastActivity:Date.now()}]),{name:"console",sessionId:e.sessionId})}function rD(){try{const e=window.ReactNativeWebView;e==null||e.postMessage(JSON.stringify({type:"requestClose"}))}catch{}}const sD="linkshell_embed";function c0(){try{return new URLSearchParams(window.location.search).get("embed")==="1"?!0:localStorage.getItem(sD)==="1"}catch{return!1}}function aD(e,n){if(!e)return 0;const r=e.toLowerCase(),a=n.toLowerCase();let l=0,u=0,f=-1;for(let o=0;o<r.length;o++){const h=r[o],d=a.indexOf(h,l);if(d===-1)return null;f>=0?u+=d-f-1:u+=d,f=d,l=d+1}return u}function oD({open:e,onClose:n,actions:r,placeholder:a="搜索命令、对话…"}){const[l,u]=re.useState(""),[f,o]=re.useState(0),h=re.useRef(null);re.useEffect(()=>{e&&(u(""),o(0),requestAnimationFrame(()=>{var k;return(k=h.current)==null?void 0:k.focus()}))},[e]);const d=re.useMemo(()=>r.map(w=>({a:w,score:aD(l,`${w.label} ${w.hint??""} ${w.keywords??""}`)})).filter(w=>w.score!==null).sort((w,_)=>w.score-_.score).map(w=>w.a),[r,l]);if(re.useEffect(()=>{o(k=>Math.min(k,Math.max(0,d.length-1)))},[d.length]),!e)return null;const m=k=>{const w=d[k];w&&(n(),w.run())},p=k=>{k.key==="ArrowDown"?(k.preventDefault(),o(w=>Math.min(w+1,d.length-1))):k.key==="ArrowUp"?(k.preventDefault(),o(w=>Math.max(w-1,0))):k.key==="Enter"?(k.preventDefault(),m(f)):k.key==="Escape"&&(k.preventDefault(),n())};let x=-1;const S=new Map;for(const k of d){const w=k.group??"",_=S.get(w)??[];_.push(k),S.set(w,_)}return C.jsx("div",{className:"fixed inset-0 z-[60] flex items-start justify-center bg-canvas/60 px-4 pt-[12vh] backdrop-blur-sm animate-fade-in",onClick:n,children:C.jsxs("div",{className:"codex-card-raised w-full max-w-xl overflow-hidden",onClick:k=>k.stopPropagation(),children:[C.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3.5 py-3",children:[C.jsx(ls,{size:16,className:"shrink-0 text-content-faint"}),C.jsx("input",{ref:h,value:l,onChange:k=>u(k.target.value),onKeyDown:p,placeholder:a,className:"min-w-0 flex-1 bg-transparent text-[15px] text-content-primary placeholder-content-muted outline-none"}),C.jsx("kbd",{className:"shrink-0 rounded border border-border px-1.5 py-0.5 font-mono text-2xs text-content-faint",children:"esc"})]}),C.jsx("div",{className:"max-h-[50vh] overflow-y-auto p-1.5",children:d.length===0?C.jsx("p",{className:"px-3 py-6 text-center text-sm text-content-muted",children:"没有匹配项"}):[...S.entries()].map(([k,w])=>C.jsxs("div",{className:"mb-1",children:[k&&C.jsx("p",{className:"px-2.5 pb-1 pt-2 text-2xs font-semibold uppercase tracking-wider text-content-faint",children:k}),w.map(_=>{x+=1;const b=x;return C.jsxs("button",{onMouseEnter:()=>o(b),onClick:()=>m(b),className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-2 text-left transition-colors ${b===f?"bg-surface-overlay":"hover:bg-surface-overlay"}`,children:[_.icon&&C.jsx("span",{className:"shrink-0 text-content-muted",children:_.icon}),C.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-content-primary",children:_.label}),_.hint&&C.jsx("span",{className:"shrink-0 text-2xs text-content-faint",children:_.hint})]},_.id)})]},k||"_"))})]})})}function lD(e){return e==="connected"?{text:"已连接",color:"text-success"}:e==="connecting"||e==="reconnecting"||e==="claiming"?{text:"连接中",color:"text-warning"}:e==="host_disconnected"?{text:"主机离线",color:"text-warning"}:e.startsWith("error")?{text:"错误",color:"text-danger"}:{text:"未连接",color:"text-content-muted"}}function Xv(e){switch(e){case"running":return{text:"运行中",className:"border-success/30 bg-success/10 text-success",pulsing:!0};case"waiting_permission":return{text:"等待授权",className:"border-warning/40 bg-warning/10 text-warning",pulsing:!0};case"error":return{text:"异常",className:"border-danger/30 bg-danger/10 text-danger"};case"idle":return{text:"空闲",className:"border-border bg-surface-overlay text-content-muted"};case"unavailable":return{text:"不可用",className:"border-border bg-surface-overlay text-content-faint"};default:return null}}function uc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function cD(e){if(!e)return null;const n=e.inputTokens!=null||e.cacheReadTokens!=null?(e.inputTokens??0)+(e.cacheReadTokens??0):null,r=[];let a="";if(n!=null&&e.contextWindow&&e.contextWindow>0){const l=Math.min(100,Math.round(n/e.contextWindow*100));r.push(`${l}%`),a=`上下文 ${uc(n)} / ${uc(e.contextWindow)} tokens`}else{const l=e.totalTokens??n??e.outputTokens??null;l!=null&&(r.push(uc(l)),a=`${l.toLocaleString()} tokens`)}return typeof e.totalCostUsd=="number"&&e.totalCostUsd>0&&(r.push(`$${e.totalCostUsd.toFixed(e.totalCostUsd<1?3:2)}`),a=a?`${a} · $${e.totalCostUsd.toFixed(4)}`:`$${e.totalCostUsd.toFixed(4)}`),r.length===0?null:{text:r.join(" · "),title:a}}function uD(e){const n=Math.max(0,Math.floor(e)),r=Math.floor(n/3600),a=Math.floor(n%3600/60),l=n%60;return r>0?`${r}h ${String(a).padStart(2,"0")}m ${String(l).padStart(2,"0")}s`:a>0?`${a}m ${String(l).padStart(2,"0")}s`:`${l}s`}function hD(e){const[n,r]=re.useState(0),a=re.useRef(null);return re.useEffect(()=>{if(!e){a.current=null,r(0);return}a.current=Date.now(),r(0);const l=setInterval(()=>{a.current!=null&&r(Math.floor((Date.now()-a.current)/1e3))},1e3);return()=>clearInterval(l)},[e]),n}function dD(e,n,r){const[a,l]=re.useState(()=>({render:e,className:e?n:""})),u=re.useRef(e);re.useEffect(()=>{e&&!u.current?l({render:!0,className:n}):!e&&u.current&&l({render:!0,className:r}),u.current=e},[e,n,r]);const f=re.useCallback(()=>{u.current||l({render:!1,className:""})},[]);return{render:a.render,className:a.className,onAnimationEnd:f}}function fD(e,n){var l,u,f,o,h,d,m,p;const r=n.toLowerCase();return[e.text,(l=e.commandExecution)==null?void 0:l.command,(u=e.commandExecution)==null?void 0:u.output,(f=e.toolCall)==null?void 0:f.name,(o=e.toolCall)==null?void 0:o.input,(h=e.toolCall)==null?void 0:h.output,(d=e.fileChange)==null?void 0:d.summary,...((p=(m=e.fileChange)==null?void 0:m.entries)==null?void 0:p.map(x=>x.path))??[],e.error].some(x=>typeof x=="string"&&x.toLowerCase().includes(r))}function pD({sessionId:e,session:n,onBack:r}){var Ut,$t,De;const a=re.useMemo(()=>ib(),[]),l=re.useMemo(()=>c0(),[]),{store:u,snapshot:f}=Ww(a,e),o=i0(),[h,d]=re.useState("none"),[m,p]=re.useState(!1),[x,S]=re.useState(!1),[k,w]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_terminal_h"));return X>=120&&X<=600?X:320}),_=re.useRef(!1),b=re.useRef(k);b.current=k;const v=re.useRef(m);v.current=m;const y=re.useCallback(()=>{v.current?S(!0):p(!0)},[]),T=re.useCallback(()=>{S(!1),p(!0)},[]),[M,N]=re.useState(!1),[O,R]=re.useState(null),[L,z]=re.useState(null),[H,q]=re.useState(!1),[F,W]=re.useState(null),[G,K]=re.useState({text:"",nonce:0}),[ne,Q]=re.useState(!1),[I,A]=re.useState(""),[B,$]=re.useState(!1),P=re.useRef(null),[oe,ye]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_sidebar_w"));return X>=180&&X<=520?X:256}),[pe,J]=re.useState(()=>localStorage.getItem("linkshell_sidebar_collapsed")==="1"),[j,me]=re.useState(()=>{const X=Number(localStorage.getItem("linkshell_rightpanel_w"));return X>=320&&X<=1100?X:560}),ce=re.useRef(!1),ee=re.useRef(!1),le=re.useRef(null),Ce=()=>{J(X=>(localStorage.setItem("linkshell_sidebar_collapsed",X?"0":"1"),!X))},He=X=>{X.preventDefault(),ce.current=!0;const de=Ke=>{if(!ce.current)return;const gt=Math.min(520,Math.max(180,Ke.clientX));ye(gt)},Be=()=>{ce.current=!1,localStorage.setItem("linkshell_sidebar_w",String(Ee.current)),window.removeEventListener("pointermove",de),window.removeEventListener("pointerup",Be)};window.addEventListener("pointermove",de),window.addEventListener("pointerup",Be)},Ee=re.useRef(oe);Ee.current=oe;const we=re.useRef(j);we.current=j;const ke=X=>{X.preventDefault(),ee.current=!0;const de=Ke=>{if(!ee.current)return;const gt=Math.min(1100,Math.max(320,window.innerWidth-Ke.clientX));me(gt)},Be=()=>{ee.current=!1,localStorage.setItem("linkshell_rightpanel_w",String(we.current)),window.removeEventListener("pointermove",de),window.removeEventListener("pointerup",Be)};window.addEventListener("pointermove",de),window.addEventListener("pointerup",Be)},Tt=X=>{X.preventDefault(),_.current=!0;const de=X.clientY,Be=b.current,Ke=Nn=>{if(!_.current)return;const It=Math.min(600,Math.max(120,Be+(de-Nn.clientY)));w(It)},gt=()=>{_.current=!1,localStorage.setItem("linkshell_terminal_h",String(b.current)),window.removeEventListener("pointermove",Ke),window.removeEventListener("pointerup",gt)};window.addEventListener("pointermove",Ke),window.addEventListener("pointerup",gt)},Fe=f.activeConversationId,At=Fe?f.timelines.get(Fe)??[]:[],Me=f.conversations.find(X=>X.id===Fe),pn=((Ut=f.capabilities)==null?void 0:Ut.providers)??[],Nt=Me?pn.find(X=>X.id===Me.provider):void 0,Ot=(Me==null?void 0:Me.status)==="running",wt=Fe?f.history.get(Fe):void 0,ue=re.useMemo(()=>{for(let X=At.length-1;X>=0;X--){const de=At[X];if(de.role==="user"&&de.text)return de.text}},[At]),xe=X=>{K(de=>({text:X,nonce:de.nonce+1}))},Ie=re.useMemo(()=>{if((Me==null?void 0:Me.collaborationMode)!=="plan"||Ot||(Me==null?void 0:Me.status)==="waiting_permission")return!1;const X=[...At].reverse().find(de=>!oc(de));return X!=null&&X.role!=="user"},[Me==null?void 0:Me.collaborationMode,Me==null?void 0:Me.status,Ot,At]),$e=()=>{Fe&&u.sendPrompt({conversationId:Fe,text:"请按上面的计划开始执行。",collaborationMode:"default",model:Me==null?void 0:Me.model,reasoningEffort:Me==null?void 0:Me.reasoningEffort,permissionMode:Me==null?void 0:Me.permissionMode})};re.useEffect(()=>{const X=de=>{const Be=de.metaKey||de.ctrlKey;Be&&de.shiftKey&&de.key.toLowerCase()==="p"?(de.preventDefault(),$(Ke=>!Ke)):Be&&!de.shiftKey&&de.key.toLowerCase()==="k"?(de.preventDefault(),$(Ke=>!Ke)):Be&&!de.shiftKey&&de.key.toLowerCase()==="j"?(de.preventDefault(),y()):Be&&!de.shiftKey&&de.key.toLowerCase()==="f"?(de.preventDefault(),Q(!0),requestAnimationFrame(()=>{var Ke;return(Ke=P.current)==null?void 0:Ke.focus()})):de.key==="Escape"&&Q(!1)};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[]),re.useEffect(()=>{Q(!1),A("")},[Fe]);const Je=re.useRef(0),Gt=re.useRef(!0),ht=()=>{const X=le.current;X&&(Gt.current=X.scrollHeight-X.scrollTop-X.clientHeight<80,X.scrollTop<60&&Fe&&(wt!=null&&wt.hasMore)&&!wt.loading&&(Je.current=X.scrollHeight,u.loadOlderHistory(Fe)))};re.useLayoutEffect(()=>{const X=le.current;X&&(Je.current>0?(X.scrollTop=X.scrollHeight-Je.current,Je.current=0):Gt.current&&(X.scrollTop=X.scrollHeight))},[At.length,Fe]);const Qt=(X,de)=>{de?En(X,de):W(X)},En=(X,de)=>{const Be=pn.find(gt=>gt.id===X),Ke=u.openConversation({provider:X,cwd:de,model:Be==null?void 0:Be.defaultModel});u.setActiveConversation(Ke),W(null)},vn=(X,de)=>{Fe&&u.sendPrompt({conversationId:Fe,text:X,images:de.map(Be=>({data:Be.data,mimeType:Be.mimeType})),model:Me==null?void 0:Me.model,reasoningEffort:Me==null?void 0:Me.reasoningEffort,permissionMode:Me==null?void 0:Me.permissionMode,collaborationMode:Me==null?void 0:Me.collaborationMode})},Wt=lD(f.status),rn=f.externalAgentStatus==="running"||f.externalAgentStatus==="waiting_permission"||f.externalAgentStatus==="error",sn=Xv(rn?f.externalAgentStatus??void 0:Me==null?void 0:Me.status),Ii=rn?f.externalAgentTitle??"外部终端":Me==null?void 0:Me.provider,rr=rn?f.externalAgentStatus==="running":(Me==null?void 0:Me.status)==="running",zr=hD(rr),ei=rn?null:cD(Me==null?void 0:Me.usage),fi=`CLI 设备 · ${e.slice(0,8)}`,Z=Me==null?void 0:Me.cwd,_e=re.useCallback(()=>{u.client.spawnTerminal(Z||".")},[u,Z]),Re=pn.filter(X=>X.enabled),Ze=re.useMemo(()=>{const X=[];for(const de of Re)X.push({id:`new-${de.id}`,label:`新建 ${de.label} 对话`,group:"新建",keywords:`new conversation ${de.id}`,icon:C.jsx(Ro,{size:15}),run:()=>Qt(de.id)});for(const de of f.conversations.filter(Be=>!Be.archived)){const Be=de.title&&de.title.trim()||de.lastMessagePreview&&de.lastMessagePreview.trim().slice(0,40)||`对话 ${de.id.slice(-6)}`;X.push({id:`conv-${de.id}`,label:Be,group:"对话",hint:de.cwd?de.cwd.split("/").slice(-1)[0]:void 0,keywords:`${de.provider} ${de.cwd??""}`,icon:C.jsx(ea,{provider:de.provider,size:15}),run:()=>u.setActiveConversation(de.id)})}return Fe&&Ot&&X.push({id:"cancel",label:"停止当前回合",group:"操作",keywords:"cancel stop interrupt",icon:C.jsx(eb,{size:15}),run:()=>u.cancel(Fe)}),Fe&&X.push({id:"search",label:"在对话中搜索",group:"操作",hint:"⌘F",keywords:"search find filter",icon:C.jsx(ls,{size:15}),run:()=>{Q(!0),requestAnimationFrame(()=>{var de;return(de=P.current)==null?void 0:de.focus()})}}),X.push({id:"panel-terminal",label:"切换终端",group:"操作",hint:"⌘J",keywords:"terminal shell",icon:C.jsx(Ed,{size:15}),run:y},{id:"panel-files",label:"打开文件浏览器",group:"操作",keywords:"files browse",icon:C.jsx(Lr,{size:15}),run:()=>d(de=>de==="files"?"none":"files")},{id:"panel-preview",label:"打开端口预览",group:"操作",keywords:"preview port browser localhost tunnel",icon:C.jsx(hc,{size:15}),run:()=>d(de=>de==="preview"?"none":"preview")}),X},[Re,f.conversations,Fe,Ot]);return C.jsxs("div",{className:"flex h-[100dvh] flex-col overflow-hidden",children:[C.jsxs("header",{className:"flex items-center justify-between border-b border-border px-4 py-2",style:{paddingTop:"max(0.5rem, env(safe-area-inset-top))"},children:[C.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[o&&C.jsx("button",{onClick:()=>N(!0),className:"codex-btn-ghost shrink-0 px-2 py-1.5","aria-label":"打开会话列表",children:C.jsx(AS,{size:17})}),C.jsx("button",{onClick:r,className:"codex-btn-ghost shrink-0 text-2xs","aria-label":"返回会话列表",children:"← 会话"}),C.jsxs("span",{className:`flex shrink-0 items-center gap-1 text-2xs ${Wt.color}`,children:[C.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current"}),!o&&Wt.text]}),sn&&C.jsxs("span",{className:`inline-flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-2xs font-medium ${sn.className}`,title:rn?"外部终端状态":"当前对话状态",children:[sn.pulsing&&C.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-current animate-pulse-dot"}),Ii&&C.jsx("span",{className:"min-w-0 truncate",children:Ii}),C.jsxs("span",{className:"shrink-0",children:[Ii?"· ":"",sn.text]}),rr&&C.jsx("span",{className:"shrink-0 font-mono tabular-nums opacity-70",children:uD(zr)})]}),ei&&!o&&C.jsx("span",{className:"inline-flex shrink-0 items-center rounded-full border border-border bg-surface-overlay px-2 py-0.5 font-mono text-2xs tabular-nums text-content-muted",title:ei.title,children:ei.text}),(($t=f.usage)==null?void 0:$t.totals)&&!o&&C.jsxs("span",{className:"inline-flex shrink-0 items-center gap-0.5 rounded-full border border-border bg-surface-overlay px-2 py-0.5 font-mono text-2xs tabular-nums text-content-muted",title:"全机用量",children:[C.jsx(g_,{size:12}),uc(f.usage.totals.totalTokens)]}),f.lastError&&C.jsx("button",{onClick:()=>u.dismissError(),className:"min-w-0 truncate rounded-full border border-danger/30 bg-danger/10 px-2 py-0.5 text-2xs text-danger",title:`${f.lastError.message}(点击关闭)`,children:f.lastError.code})]}),C.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[C.jsx("button",{onClick:()=>{Fe&&(Q(!0),requestAnimationFrame(()=>{var X;return(X=P.current)==null?void 0:X.focus()}))},disabled:!Fe,className:"codex-btn-ghost px-2 py-1.5 disabled:opacity-40",title:"在对话中搜索 (⌘/Ctrl+F)","aria-label":"在对话中搜索",children:C.jsx(ls,{size:16})}),!l&&C.jsx(tD,{}),!o&&C.jsx("button",{onClick:()=>d(X=>X==="preview"?"none":"preview"),className:`cursor-pointer rounded-md p-1.5 transition-colors ${h==="preview"?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"端口预览","aria-label":"端口预览",children:C.jsx(hc,{size:16})}),C.jsx("button",{onClick:()=>d(X=>X==="files"?"none":"files"),className:`cursor-pointer rounded-md p-1.5 transition-colors ${h==="files"?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"文件","aria-label":"文件",children:C.jsx(Lr,{size:16})}),C.jsx("button",{onClick:y,className:`cursor-pointer rounded-md p-1.5 transition-colors ${m?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"终端 (⌘J)","aria-label":"终端",children:C.jsx(Ed,{size:16})}),C.jsx("button",{onClick:()=>{u.requestUsage(),q(!0)},className:`cursor-pointer rounded-md p-1.5 transition-colors ${H?"bg-accent-dim text-white":"text-content-muted hover:bg-surface-overlay hover:text-content-primary"}`,title:"用量统计","aria-label":"用量统计",children:C.jsx(g_,{size:16})})]})]}),C.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[f.status==="host_disconnected"&&C.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-canvas/80 backdrop-blur-sm",children:C.jsxs("div",{className:"codex-card-raised mx-4 flex max-w-sm flex-col items-center gap-3 px-6 py-8 text-center animate-fade-in",children:[C.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-warning/15 text-warning",children:C.jsx(OS,{size:24})}),C.jsx("h2",{className:"text-base font-semibold text-content-primary",children:"主机已离线"}),C.jsxs("p",{className:"text-sm leading-relaxed text-content-muted",children:["与该会话的主机连接已断开。请确认主机上的"," ",C.jsx("code",{className:"font-mono text-accent",children:"linkshell"})," 仍在运行。正在自动尝试重新连接…"]}),C.jsx("button",{onClick:r,className:"codex-btn-outline mt-1 text-2xs",children:"返回会话列表"})]})}),o?M&&C.jsxs("div",{className:"absolute inset-0 z-30 flex animate-fade-in",children:[C.jsxs("aside",{className:"flex w-[82%] max-w-xs flex-col border-r border-border bg-surface shadow-2xl animate-drawer-in",children:[C.jsx("div",{className:"flex items-center border-b border-border px-3 py-2",children:C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"会话"})}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(Wv,{deviceLabel:fi,conversations:f.conversations,capabilities:f.capabilities,activeConversationId:Fe,externalAgentStatus:f.externalAgentStatus,externalAgentTitle:f.externalAgentTitle,externalAgentProvider:f.externalAgentProvider,store:u,onSelect:X=>{u.setActiveConversation(X),N(!1)},onNewConversation:(X,de)=>{N(!1),Qt(X,de)},onOpenExternalTerminal:()=>{var de;const X=f.externalAgentConversationId||((de=f.conversations.find(Be=>Be.status==="running"||Be.status==="waiting_permission"))==null?void 0:de.id);X?(u.setActiveConversation(X),N(!1)):(N(!1),T())}})})]}),C.jsx("button",{className:"flex-1 bg-canvas/60 backdrop-blur-sm",onClick:()=>N(!1),"aria-label":"关闭"})]}):pe?C.jsx("div",{className:"flex w-9 shrink-0 flex-col items-center border-r border-border bg-surface py-2",children:C.jsx("button",{onClick:Ce,className:"cursor-pointer rounded-md p-1.5 text-content-muted transition-colors hover:bg-surface-overlay hover:text-content-primary",title:"展开侧边栏","aria-label":"展开侧边栏",children:C.jsx(Si,{size:16})})}):C.jsxs("aside",{className:"relative flex shrink-0 flex-col border-r border-border bg-surface",style:{width:oe},children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-2 py-1",children:[C.jsx("span",{className:"pl-1 text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"会话"}),C.jsx("button",{onClick:Ce,className:"cursor-pointer rounded-md p-1 text-content-muted transition-colors hover:bg-surface-overlay hover:text-content-primary",title:"收起侧边栏","aria-label":"收起侧边栏",children:C.jsx(NS,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(Wv,{deviceLabel:fi,conversations:f.conversations,capabilities:f.capabilities,activeConversationId:Fe,externalAgentStatus:f.externalAgentStatus,externalAgentTitle:f.externalAgentTitle,externalAgentProvider:f.externalAgentProvider,store:u,onSelect:X=>u.setActiveConversation(X),onNewConversation:Qt,onOpenExternalTerminal:()=>{var de;const X=f.externalAgentConversationId||((de=f.conversations.find(Be=>Be.status==="running"||Be.status==="waiting_permission"))==null?void 0:de.id);X?u.setActiveConversation(X):T()}})}),C.jsx("div",{onPointerDown:He,className:"absolute right-0 top-0 h-full w-1 cursor-col-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整宽度"})]}),C.jsx("main",{className:"flex min-w-0 flex-1 flex-col",children:!Fe||!Me?C.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[C.jsx(lf,{size:44,className:"opacity-40"}),C.jsx("p",{className:"text-[15px] leading-7 text-content-muted",children:o?"点击左上角菜单选择对话,或新建一个开始":"从左侧选择一个对话,或新建一个开始"})]}):C.jsxs(C.Fragment,{children:[ne&&C.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-surface px-4 py-2",children:[C.jsx(ls,{size:15,className:"shrink-0 text-content-faint"}),C.jsx("input",{ref:P,value:I,onChange:X=>A(X.target.value),onKeyDown:X=>X.key==="Escape"&&(Q(!1),A("")),placeholder:"在此对话中搜索…",className:"min-w-0 flex-1 bg-transparent text-sm text-content-primary placeholder-content-muted outline-none"}),C.jsx("button",{onClick:()=>{Q(!1),A("")},className:"codex-btn-ghost px-2 py-1","aria-label":"关闭搜索",children:C.jsx(hi,{size:14})})]}),C.jsx("div",{ref:le,onScroll:ht,className:"min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-8",children:C.jsxs("div",{className:"mx-auto flex w-full min-w-0 max-w-3xl flex-col gap-6",children:[(wt==null?void 0:wt.loading)&&C.jsx("p",{className:"text-center text-2xs text-content-muted",children:"加载更早的消息…"}),ne&&I.trim()?(()=>{const X=I.trim(),de=At.filter(Be=>!oc(Be)&&fD(Be,X));return de.length===0?C.jsxs("p",{className:"py-12 text-center text-sm text-content-muted",children:["没有匹配「",X,"」的消息"]}):C.jsxs(C.Fragment,{children:[C.jsxs("p",{className:"text-center text-2xs text-content-faint",children:[de.length," 条匹配"]}),de.map(Be=>C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(Fv,{item:Be,canSteer:!1,onPermission:(Ke,gt,Nn)=>u.respondPermission(Fe,Ke,gt,Nn),onStructuredInput:(Ke,gt)=>u.respondStructuredInput(Fe,Ke,gt),onOpenDiff:Ke=>{R(Ke),d("none")},onOpenAgent:Ke=>{z(Ke),R(null),d("none")},onEditMessage:xe,highlightQuery:X})},Be.id))]})})():(()=>{const X=[];let de=[];const Be=()=>{de.length&&(X.push({k:"group",key:`grp-${de[0].id}`,items:de}),de=[])};for(const gt of At)oc(gt)||(yO(gt)?de.push(gt):(Be(),X.push({k:"item",item:gt})));Be();let Ke=-1;return X.forEach((gt,Nn)=>{gt.k==="group"&&(Ke=Nn)}),X.map((gt,Nn)=>gt.k==="item"?C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(Fv,{item:gt.item,canSteer:Me.provider==="codex"&&Ot,onPermission:(It,pi,Bi)=>u.respondPermission(Fe,It,pi,Bi),onStructuredInput:(It,pi)=>u.respondStructuredInput(Fe,It,pi),onSendQueued:It=>u.sendQueuedFollowUp(Fe,It,"new_turn"),onSteerQueued:It=>u.sendQueuedFollowUp(Fe,It,"steer"),onDiscardQueued:It=>u.discardQueuedFollowUp(Fe,It),onOpenDiff:It=>{R(It),d("none")},onOpenAgent:It=>{z(It),R(null),d("none")},onEditMessage:xe})},gt.item.id):C.jsx("div",{className:"min-w-0 animate-fade-in",children:C.jsx(EO,{items:gt.items,live:Ot&&Nn===Ke,onOpenDiff:It=>{R(It),d("none")},onOpenAgent:It=>{z(It),R(null),d("none")}})},gt.key))})(),At.length===0&&(Me!=null&&Me.lastMessagePreview||wt!=null&&wt.loading?C.jsxs("div",{className:"flex flex-col items-center gap-2 py-16 text-content-muted",children:[C.jsx("span",{className:"h-5 w-5 animate-spin rounded-full border-2 border-content-faint border-t-accent"}),C.jsx("p",{className:"text-sm",children:"加载对话记录…"})]}):C.jsx("p",{className:"py-12 text-center text-sm text-content-muted",children:"发送第一条指令…"}))]})}),C.jsxs("div",{className:"mx-auto w-full min-w-0 max-w-3xl px-4 pb-4",children:[Ie&&C.jsxs("div",{className:"mb-2 flex items-center gap-3 rounded-xl border border-accent-dim/40 bg-surface px-3.5 py-2.5 animate-slide-in",children:[C.jsx("span",{className:"min-w-0 flex-1 text-sm text-content-secondary",children:"计划已就绪。执行它,或在下方继续补充。"}),C.jsx("button",{onClick:$e,className:"codex-btn-primary shrink-0 text-xs",children:"执行计划"})]}),C.jsx(xO,{items:At.filter(oc),canSteer:Me.provider==="codex"&&Ot,onSend:X=>u.sendQueuedFollowUp(Fe,X,"new_turn"),onSteer:X=>u.sendQueuedFollowUp(Fe,X,"steer"),onDiscard:X=>u.discardQueuedFollowUp(Fe,X)}),C.jsx(CO,{disabled:f.status!=="connected",running:Ot,supportsImages:Nt==null?void 0:Nt.supportsImages,commands:Nt==null?void 0:Nt.commands,conversationId:Fe,lastUserText:ue,cwd:Me.cwd,onBrowse:X=>u.browse(X,!0),seedText:G,controls:C.jsx($O,{conversation:Me,capability:Nt,onChange:X=>u.updateConversationSettings(Fe,X)}),onSend:vn,onCancel:()=>u.cancel(Fe),onExecuteCommand:(X,de)=>u.executeCommand(Fe,X,de)})]}),(m||x)&&C.jsxs("div",{className:`relative shrink-0 overflow-hidden border-t border-border bg-surface ${x?"animate-panel-out-down":"animate-panel-in-up"}`,style:{height:k},onAnimationEnd:()=>{x&&(S(!1),p(!1))},children:[C.jsx("div",{onPointerDown:Tt,className:"absolute left-0 right-0 top-0 z-10 h-1 cursor-row-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整终端高度"}),C.jsx(BO,{bridge:u.client,onNewTerminal:_e})]})]})}),(()=>{let X=null;L?X=C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"子 Agent"}),C.jsx("button",{onClick:()=>z(null),className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭",children:C.jsx(hi,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(vO,{detail:L})})]}):O?X=C.jsxs(C.Fragment,{children:[C.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-1.5",children:[C.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-content-muted",children:"文件差异"}),C.jsx("button",{onClick:()=>R(null),className:"codex-btn-ghost px-2 py-1.5","aria-label":"关闭差异",children:C.jsx(hi,{size:15})})]}),C.jsx("div",{className:"min-h-0 flex-1",children:C.jsx(cO,{item:O})})]}):h==="files"?X=C.jsx(qO,{store:u,initialPath:(Me==null?void 0:Me.cwd)||".",onClose:()=>d("none")}):h==="preview"&&(X=C.jsx(YO,{gatewayUrl:a.httpUrl,sessionId:e,initialAuthToken:(n==null?void 0:n.accessToken)??null,isMobile:o,onClose:()=>d("none"),onAnnotate:Nn=>{K(It=>({text:Nn,nonce:It.nonce+1})),o&&d("none")}}));const de=re.useRef(null);X!==null&&(de.current=X);const Be=X!==null,Ke=dD(Be,"animate-panel-in-right","animate-panel-out-right");if(!Ke.render&&!Be)return null;const gt=Be?X:de.current;return o?C.jsx("aside",{className:`absolute inset-0 z-30 flex flex-col bg-canvas ${Ke.className||"animate-fade-in"}`,onAnimationEnd:Ke.onAnimationEnd,children:gt}):C.jsxs("aside",{className:`relative flex shrink-0 flex-col border-l border-border ${Ke.className}`,style:{width:j},onAnimationEnd:Ke.onAnimationEnd,children:[C.jsx("div",{onPointerDown:ke,className:"absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize bg-transparent transition-colors hover:bg-accent-dim/50",title:"拖动调整宽度"}),gt]})})()]}),F&&C.jsx(KO,{store:u,initialPath:(Me==null?void 0:Me.cwd)||".",providerLabel:((De=pn.find(X=>X.id===F))==null?void 0:De.label)??F,onCancel:()=>W(null),onConfirm:X=>En(F,X)}),f.notices.length>0&&C.jsx("div",{className:"pointer-events-none fixed bottom-4 right-4 z-50 flex w-80 flex-col gap-2",children:f.notices.map(X=>C.jsxs("button",{onClick:()=>u.dismissNotice(X.id),className:`codex-card-raised pointer-events-auto animate-fade-in cursor-pointer px-3 py-2 text-left ${X.kind==="warning"?"border-warning/40":""}`,children:[C.jsxs("p",{className:"flex items-center gap-1.5 text-xs font-medium text-content-primary",children:[C.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${X.kind==="warning"?"bg-warning":"bg-accent"}`}),X.title]}),X.detail&&C.jsx("p",{className:"mt-0.5 pl-3 text-2xs text-content-muted",children:X.detail})]},X.id))}),C.jsx(oD,{open:B,onClose:()=>$(!1),actions:Ze}),H&&C.jsx(o1,{report:f.usage,onClose:()=>q(!1)})]})}eD();function mD(){const[e,n]=re.useState(null),[r,a]=re.useState(!1),[l,u]=re.useState(!1),f=re.useMemo(()=>iD(nD()),[]),o=re.useMemo(()=>c0(),[]),[h,d]=re.useState(()=>f??ZS()),m=p=>{d(p),v_(p)};return re.useEffect(()=>{const p=Cc();p&&n(p),a(!0),p&&nf().then(x=>{x&&n(x)})},[]),re.useEffect(()=>{if(!o)return;const p=window;return p.__linkshellSetTheme=x=>{(x==="dark"||x==="light")&&Bf(x)},()=>{delete p.__linkshellSetTheme}},[o]),re.useEffect(()=>yS(()=>{n(null),u(!1),d(p=>p.name==="list"?p:{name:"list"}),v_({name:"list"})}),[]),r?l?C.jsx(jS,{onLogin:p=>{n(p),u(!1)},onCancel:()=>u(!1)}):h.name==="console"?C.jsx(pD,{sessionId:h.sessionId,session:e,onBack:o?rD:()=>m({name:"list"})}):C.jsx(u1,{session:e,onLogin:()=>u(!0),onLogout:()=>{n(null),m({name:"list"})},onOpenSession:p=>m({name:"console",sessionId:p})}):null}bS.createRoot(document.getElementById("root")).render(C.jsx(mD,{}));
|
package/web/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
|
|
6
6
|
<link rel="icon" type="image/png" href="/logos/linkshell.png" />
|
|
7
7
|
<title>LinkShell</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-wEo8TBBQ.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-BF_KJjhI.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|